z80/ym2612 reset handling improved
[picodrive.git] / Pico / Memory_amips.s
... / ...
CommitLineData
1# vim:filetype=mips
2
3# memory handlers with banking support for SSF II - The New Challengers
4# mostly based on Gens code
5
6# (c) Copyright 2007, Grazvydas "notaz" Ignotas
7# All Rights Reserved
8
9
10.set noreorder
11.set noat
12
13.text
14.align 4
15
16# default jump tables
17
18m_read8_def_table:
19 .long m_read8_rom0 # 0x000000 - 0x07FFFF
20 .long m_read8_rom1 # 0x080000 - 0x0FFFFF
21 .long m_read8_rom2 # 0x100000 - 0x17FFFF
22 .long m_read8_rom3 # 0x180000 - 0x1FFFFF
23 .long m_read8_rom4 # 0x200000 - 0x27FFFF
24 .long m_read8_rom5 # 0x280000 - 0x2FFFFF
25 .long m_read8_rom6 # 0x300000 - 0x37FFFF
26 .long m_read8_rom7 # 0x380000 - 0x3FFFFF
27 .long m_read8_rom8 # 0x400000 - 0x47FFFF - for all those large ROM hacks
28 .long m_read8_rom9 # 0x480000 - 0x4FFFFF
29 .long m_read8_romA # 0x500000 - 0x57FFFF
30 .long m_read8_romB # 0x580000 - 0x5FFFFF
31 .long m_read8_romC # 0x600000 - 0x67FFFF
32 .long m_read8_romD # 0x680000 - 0x6FFFFF
33 .long m_read8_romE # 0x700000 - 0x77FFFF
34 .long m_read8_romF # 0x780000 - 0x7FFFFF
35 .long m_read8_rom10 # 0x800000 - 0x87FFFF
36 .long m_read8_rom11 # 0x880000 - 0x8FFFFF
37 .long m_read8_rom12 # 0x900000 - 0x97FFFF
38 .long m_read8_rom13 # 0x980000 - 0x9FFFFF
39 .long m_read8_misc # 0xA00000 - 0xA7FFFF
40 .long m_read_null # 0xA80000 - 0xAFFFFF
41 .long m_read_null # 0xB00000 - 0xB7FFFF
42 .long m_read_null # 0xB80000 - 0xBFFFFF
43 .long m_read8_vdp # 0xC00000 - 0xC7FFFF
44 .long m_read8_vdp # 0xC80000 - 0xCFFFFF
45 .long m_read8_vdp # 0xD00000 - 0xD7FFFF
46 .long m_read8_vdp # 0xD80000 - 0xDFFFFF
47 .long m_read8_ram # 0xE00000 - 0xE7FFFF
48 .long m_read8_ram # 0xE80000 - 0xEFFFFF
49 .long m_read8_ram # 0xF00000 - 0xF7FFFF
50 .long m_read8_ram # 0xF80000 - 0xFFFFFF
51
52m_read16_def_table:
53 .long m_read16_rom0 # 0x000000 - 0x07FFFF
54 .long m_read16_rom1 # 0x080000 - 0x0FFFFF
55 .long m_read16_rom2 # 0x100000 - 0x17FFFF
56 .long m_read16_rom3 # 0x180000 - 0x1FFFFF
57 .long m_read16_rom4 # 0x200000 - 0x27FFFF
58 .long m_read16_rom5 # 0x280000 - 0x2FFFFF
59 .long m_read16_rom6 # 0x300000 - 0x37FFFF
60 .long m_read16_rom7 # 0x380000 - 0x3FFFFF
61 .long m_read16_rom8 # 0x400000 - 0x47FFFF
62 .long m_read16_rom9 # 0x480000 - 0x4FFFFF
63 .long m_read16_romA # 0x500000 - 0x57FFFF
64 .long m_read16_romB # 0x580000 - 0x5FFFFF
65 .long m_read16_romC # 0x600000 - 0x67FFFF
66 .long m_read16_romD # 0x680000 - 0x6FFFFF
67 .long m_read16_romE # 0x700000 - 0x77FFFF
68 .long m_read16_romF # 0x780000 - 0x7FFFFF
69 .long m_read16_rom10 # 0x800000 - 0x87FFFF
70 .long m_read16_rom11 # 0x880000 - 0x8FFFFF
71 .long m_read16_rom12 # 0x900000 - 0x97FFFF
72 .long m_read16_rom13 # 0x980000 - 0x9FFFFF
73 .long m_read16_misc # 0xA00000 - 0xA7FFFF
74 .long m_read_null # 0xA80000 - 0xAFFFFF
75 .long m_read_null # 0xB00000 - 0xB7FFFF
76 .long m_read_null # 0xB80000 - 0xBFFFFF
77 .long m_read16_vdp # 0xC00000 - 0xC7FFFF
78 .long m_read16_vdp # 0xC80000 - 0xCFFFFF
79 .long m_read16_vdp # 0xD00000 - 0xD7FFFF
80 .long m_read16_vdp # 0xD80000 - 0xDFFFFF
81 .long m_read16_ram # 0xE00000 - 0xE7FFFF
82 .long m_read16_ram # 0xE80000 - 0xEFFFFF
83 .long m_read16_ram # 0xF00000 - 0xF7FFFF
84 .long m_read16_ram # 0xF80000 - 0xFFFFFF
85
86m_read32_def_table:
87 .long m_read32_rom0 # 0x000000 - 0x07FFFF
88 .long m_read32_rom1 # 0x080000 - 0x0FFFFF
89 .long m_read32_rom2 # 0x100000 - 0x17FFFF
90 .long m_read32_rom3 # 0x180000 - 0x1FFFFF
91 .long m_read32_rom4 # 0x200000 - 0x27FFFF
92 .long m_read32_rom5 # 0x280000 - 0x2FFFFF
93 .long m_read32_rom6 # 0x300000 - 0x37FFFF
94 .long m_read32_rom7 # 0x380000 - 0x3FFFFF
95 .long m_read32_rom8 # 0x400000 - 0x47FFFF
96 .long m_read32_rom9 # 0x480000 - 0x4FFFFF
97 .long m_read32_romA # 0x500000 - 0x57FFFF
98 .long m_read32_romB # 0x580000 - 0x5FFFFF
99 .long m_read32_romC # 0x600000 - 0x67FFFF
100 .long m_read32_romD # 0x680000 - 0x6FFFFF
101 .long m_read32_romE # 0x700000 - 0x77FFFF
102 .long m_read32_romF # 0x780000 - 0x7FFFFF
103 .long m_read32_rom10 # 0x800000 - 0x87FFFF
104 .long m_read32_rom11 # 0x880000 - 0x8FFFFF
105 .long m_read32_rom12 # 0x900000 - 0x97FFFF
106 .long m_read32_rom13 # 0x980000 - 0x9FFFFF
107 .long m_read32_misc # 0xA00000 - 0xA7FFFF
108 .long m_read_null # 0xA80000 - 0xAFFFFF
109 .long m_read_null # 0xB00000 - 0xB7FFFF
110 .long m_read_null # 0xB80000 - 0xBFFFFF
111 .long m_read32_vdp # 0xC00000 - 0xC7FFFF
112 .long m_read32_vdp # 0xC80000 - 0xCFFFFF
113 .long m_read32_vdp # 0xD00000 - 0xD7FFFF
114 .long m_read32_vdp # 0xD80000 - 0xDFFFFF
115 .long m_read32_ram # 0xE00000 - 0xE7FFFF
116 .long m_read32_ram # 0xE80000 - 0xEFFFFF
117 .long m_read32_ram # 0xF00000 - 0xF7FFFF
118 .long m_read32_ram # 0xF80000 - 0xFFFFFF
119
120
121# #############################################################################
122
123.bss
124.align 4
125
126# used tables
127m_read8_table:
128 .skip 32*4
129
130m_read16_table:
131 .skip 32*4
132
133m_read32_table:
134 .skip 32*4
135
136
137# #############################################################################
138
139.text
140.align 4
141
142.global PicoMemReset
143.global PicoRead8
144.global PicoRead16
145.global PicoRead32
146.global PicoWriteRomHW_SSF2
147
148.global m_read8_def_table
149.global m_read8_table
150
151.macro PicoMemResetCopyDef dst_table src_table
152 lui $t0, %hi(\dst_table)
153 addiu $t0, %lo(\dst_table)
154 lui $t1, %hi(\src_table)
155 addiu $t1, %lo(\src_table)
156 li $t2, 32
1571:
158 lw $t3, 0($t1)
159 sw $t3, 0($t0)
160 addiu $t2, -1
161 addiu $t1, 4
162 bnez $t2, 1b
163 addiu $t0, 4
164.endm
165
166# $t4 = 4
167.macro PicoMemResetRomArea dst_table ar_label
168 lui $t0, %hi(\dst_table)
169 addiu $t0, %lo(\dst_table)
170 lui $t1, %hi(\ar_label)
171 addiu $t1, %lo(\ar_label)
172 li $t2, 20
1731:
174 beq $t2, $v1, 2f
175 addiu $t2, -1
176 sll $t3, $t2, 2
177 beq $t2, $t4, 1b # do not touch the SRAM area
178 addu $t3, $t0
179 j 1b
180 sw $t1, 0($t3)
1812:
182.endm
183
184
185PicoMemReset:
186 lui $v1, %hi(Pico+0x22204)
187 lw $v1, %lo(Pico+0x22204)($v1) # romsize
188 lui $t0, 8
189 addu $v1, $t0
190 addiu $v1, -1
191 srl $v1, 19
192
193 PicoMemResetCopyDef m_read8_table m_read8_def_table
194 PicoMemResetCopyDef m_read16_table m_read16_def_table
195 PicoMemResetCopyDef m_read32_table m_read32_def_table
196
197 # update memhandlers according to ROM size
198 li $t4, 4
199 PicoMemResetRomArea m_read8_table m_read8_above_rom
200 PicoMemResetRomArea m_read16_table m_read16_above_rom
201 PicoMemResetRomArea m_read32_table m_read32_above_rom
202
203 jr $ra
204 nop
205
206# #############################################################################
207
208.macro PicoReadJump table
209 lui $t0, %hi(\table)
210 srl $t1, $a0, 19
211 ins $t0, $t1, 2, 5
212 lw $t0, %lo(\table)($t0)
213 ins $a0, $0, 24, 8
214 jr $t0
215 nop
216.endm
217
218PicoRead8: # u32 a
219 PicoReadJump m_read8_table
220
221PicoRead16: # u32 a
222 PicoReadJump m_read16_table
223
224PicoRead32: # u32 a
225 PicoReadJump m_read32_table
226
227# #############################################################################
228
229m_read_null:
230 jr $ra
231 li $v0, 0
232
233m_read_neg1:
234 jr $ra
235 addiu $v0, $0, 0xffff
236
237# loads &Pico.rom to $t3
238.macro m_read_rom_try_sram is200000 size
239 lui $t2, %hi(SRam)
240 addiu $t2, %lo(SRam)
241 lui $t3, %hi(Pico+0x22200)
242 lw $t1, 8($t2) # SRam.end
243.if \is200000
244 ins $a0, $0, 19, 13
245 lui $t4, 0x20
246 or $a0, $t4
247.endif
248 subu $t4, $a0, $t1
249 bgtz $t4, 1f
250 addiu $t3, %lo(Pico+0x22200)
251 lw $t1, 4($t2) # SRam.start
252 subu $t4, $t1, $a0
253 bgtz $t4, 1f
254 nop
255 lb $t1, 0x11($t3) # Pico.m.sram_reg
256 andi $t4, $t1, 5
257 beqz $t4, 1f
258 nop
259.if \size == 8
260 j SRAMRead
261 nop
262.elseif \size == 16
263 sw $ra, -4($sp)
264 jal SRAMRead16
265 addiu $sp, -4
266 lw $ra, 0($sp)
267 jr $ra
268 addiu $sp, 4
269.else
270 addiu $sp, -8
271 sw $ra, 0($sp)
272 sw $a0, 4($sp)
273 jal SRAMRead16
274 nop
275 lw $a0, 4($sp)
276 sw $v0, 4($sp)
277 jal SRAMRead16
278 addiu $a0, 2
279 lw $v1, 4($sp)
280 lw $ra, 0($sp)
281 addiu $sp, 8
282 jr $ra
283 ins $v0, $v1, 16, 16
284.endif
285# m_read_nosram:
2861:
287.endm
288
289.macro m_read8_rom sect
290 lui $t0, %hi(Pico+0x22200)
291 lw $t0, %lo(Pico+0x22200)($t0) # rom
292 xori $a0, 1
293 ins $a0, $0, 19, 13
294.if \sect
295 lui $t1, 8*\sect
296 addu $a0, $t1
297.endif
298 addu $t0, $a0
299 jr $ra
300 lb $v0, 0($t0)
301.endm
302
303
304m_read8_rom0: # 0x000000 - 0x07ffff
305 m_read8_rom 0
306
307m_read8_rom1: # 0x080000 - 0x0fffff
308 m_read8_rom 1
309
310m_read8_rom2: # 0x100000 - 0x17ffff
311 m_read8_rom 2
312
313m_read8_rom3: # 0x180000 - 0x1fffff
314 m_read8_rom 3
315
316m_read8_rom4: # 0x200000 - 0x27ffff, SRAM area
317 m_read_rom_try_sram 1 8
318 lw $t1, 4($t3) # romsize
319 subu $t4, $t1, $a0
320 blez $t4, m_read_null
321 lw $t1, 0($t3) # rom
322 xori $a0, 1
323 addu $t1, $a0
324 jr $ra
325 lb $v0, 0($t1)
326
327m_read8_rom5: # 0x280000 - 0x2fffff
328 m_read8_rom 5
329
330m_read8_rom6: # 0x300000 - 0x37ffff
331 m_read8_rom 6
332
333m_read8_rom7: # 0x380000 - 0x3fffff
334 m_read8_rom 7
335
336m_read8_rom8: # 0x400000 - 0x47ffff
337 m_read8_rom 8
338
339m_read8_rom9: # 0x480000 - 0x4fffff
340 m_read8_rom 9
341
342m_read8_romA: # 0x500000 - 0x57ffff
343 m_read8_rom 0xA
344
345m_read8_romB: # 0x580000 - 0x5fffff
346 m_read8_rom 0xB
347
348m_read8_romC: # 0x600000 - 0x67ffff
349 m_read8_rom 0xC
350
351m_read8_romD: # 0x680000 - 0x6fffff
352 m_read8_rom 0xD
353
354m_read8_romE: # 0x700000 - 0x77ffff
355 m_read8_rom 0xE
356
357m_read8_romF: # 0x780000 - 0x7fffff
358 m_read8_rom 0xF
359
360m_read8_rom10: # 0x800000 - 0x87ffff
361 m_read8_rom 0x10
362
363m_read8_rom11: # 0x880000 - 0x8fffff
364 m_read8_rom 0x11
365
366m_read8_rom12: # 0x900000 - 0x97ffff
367 m_read8_rom 0x12
368
369m_read8_rom13: # 0x980000 - 0x9fffff
370 m_read8_rom 0x13
371
372
373m_read8_misc:
374 srl $t0, $a0, 5
375 sll $t0, $t0, 5
376 lui $t1, 0xa1
377 bne $t0, $t1, m_read8_misc2
378 andi $t0, $a0, 0x1e
379m_read8_misc_io:
380 beqz $t0, m_read8_misc_hwreg
381 sub $t1, $t0, 4
382 bgtz $t1, m_read8_misc_ioports
383 nop
384 slti $a0, $t0, 4
385 xori $a0, 1
386 j PadRead
387 nop
388
389m_read8_misc_hwreg:
390 lui $v0, %hi(Pico+0x2220f)
391 jr $ra
392 lb $v0, %lo(Pico+0x2220f)($v0)
393
394m_read8_misc_ioports:
395 lui $v0, %hi(Pico+0x22000)
396 ins $v0, $t0, 0, 5
397 jr $ra
398 lb $v0, %lo(Pico+0x22000)($v0)
399
400m_read8_misc2:
401 lui $t0, 0xa1
402 ori $t0, 0x1100
403 bne $a0, $t0, m_read8_misc3
404 srl $t0, $a0, 16
405 j z80ReadBusReq
406
407m_read8_misc3:
408 addiu $t0, 0xff60 # expecting 0xa0 to get 0
409 bnez $t0, m_read8_misc4
410
411 # z80 area
412 andi $t0, $a0, 0x4000
413 bnez $t0, m_read8_z80_misc
414 andi $t0, $a0, 0x6000
415 j z80Read8 # z80 RAM
416
417m_read8_z80_misc:
418 addiu $t0, 0xc000 # expecting 0x4000 to get 0
419 bnez $t0, m_read_neg1 # invalid
420 nop
421 j ym2612_read_local_68k
422 nop
423
424m_read8_fake_ym2612:
425 lb $v0, %lo(Pico+0x22208)($t0) # Pico.m.rotate
426 addiu $t1, $v0, 1
427 jr $ra
428 sb $t1, %lo(Pico+0x22208)($t0)
429
430# delay slot friendly
431.macro m_read8_call16 funcname is_func_ptr=0
432.if \is_func_ptr
433 lui $t1, %hi(\funcname)
434 lw $t1, %lo(\funcname)($t1)
435.endif
436 andi $t0, $a0, 1
437 beqz $t0, 1f
438 li $a1, 8 # not always needed, but shouln't cause problems
439.if \is_func_ptr
440 jr $t1
441.else
442 j \funcname # odd address
443.endif
444 nop
4451:
446 addiu $sp, -4
447 sw $ra, 0($sp)
448.if \is_func_ptr
449 jalr $t1
450.else
451 jal \funcname
452.endif
453 xori $a0, 1
454 lw $ra, 0($sp)
455 addiu $sp, 4
456 jr $ra
457 srl $v0, 8
458.endm
459
460m_read8_misc4:
461 # if everything else fails, use generic handler
462 m_read8_call16 OtherRead16
463
464m_read8_vdp:
465 ext $t0, $a0, 16, 3
466 andi $t1, $a0, 0xe0
467 or $t0, $t1
468 bnez $t0, m_read_null # invalid address
469 nop
470 j PicoVideoRead8
471 nop
472
473m_read8_ram:
474 lui $t0, %hi(Pico)
475 ins $t0, $a0, 0, 16
476 xori $t0, 1
477 jr $ra
478 lb $v0, %lo(Pico)($t0)
479
480m_read8_above_rom:
481 # might still be SRam (Micro Machines, HardBall '95)
482 m_read_rom_try_sram 0 8
483 m_read8_call16 PicoRead16Hook 1
484
485# #############################################################################
486
487.macro m_read16_rom sect
488 lui $t0, %hi(Pico+0x22200)
489 lw $t0, %lo(Pico+0x22200)($t0) # rom
490 ins $a0, $0, 0, 1
491 ins $a0, $0, 19, 13
492.if \sect
493 lui $t1, 8*\sect
494 addu $a0, $t1
495.endif
496 addu $t0, $a0
497 jr $ra
498 lh $v0, 0($t0)
499.endm
500
501
502m_read16_rom0: # 0x000000 - 0x07ffff
503 m_read16_rom 0
504
505m_read16_rom1: # 0x080000 - 0x0fffff
506 m_read16_rom 1
507
508m_read16_rom2: # 0x100000 - 0x17ffff
509 m_read16_rom 2
510
511m_read16_rom3: # 0x180000 - 0x1fffff
512 m_read16_rom 3
513
514m_read16_rom4: # 0x200000 - 0x27ffff, SRAM area
515 m_read_rom_try_sram 1 16
516 lw $t1, 4($t3) # romsize
517 subu $t4, $t1, $a0
518 blez $t4, m_read_null
519 lw $t1, 0($t3) # rom
520 ins $a0, $0, 0, 1
521 addu $t1, $a0
522 jr $ra
523 lh $v0, 0($t1)
524
525m_read16_rom5: # 0x280000 - 0x2fffff
526 m_read16_rom 5
527
528m_read16_rom6: # 0x300000 - 0x37ffff
529 m_read16_rom 6
530
531m_read16_rom7: # 0x380000 - 0x3fffff
532 m_read16_rom 7
533
534m_read16_rom8: # 0x400000 - 0x47ffff
535 m_read16_rom 8
536
537m_read16_rom9: # 0x480000 - 0x4fffff
538 m_read16_rom 9
539
540m_read16_romA: # 0x500000 - 0x57ffff
541 m_read16_rom 0xA
542
543m_read16_romB: # 0x580000 - 0x5fffff
544 m_read16_rom 0xB
545
546m_read16_romC: # 0x600000 - 0x67ffff
547 m_read16_rom 0xC
548
549m_read16_romD: # 0x680000 - 0x6fffff
550 m_read16_rom 0xD
551
552m_read16_romE: # 0x700000 - 0x77ffff
553 m_read16_rom 0xE
554
555m_read16_romF: # 0x780000 - 0x7fffff
556 m_read16_rom 0xF
557
558m_read16_rom10: # 0x800000 - 0x87ffff
559 m_read16_rom 0x10
560
561m_read16_rom11: # 0x880000 - 0x8fffff
562 m_read16_rom 0x11
563
564m_read16_rom12: # 0x900000 - 0x97ffff
565 m_read16_rom 0x12
566
567m_read16_rom13: # 0x980000 - 0x9fffff
568 m_read16_rom 0x13
569
570m_read16_misc:
571 ins $a0, $0, 0, 1
572 j OtherRead16
573 li $a1, 16
574
575m_read16_vdp:
576 ext $t0, $a0, 16, 3
577 andi $t1, $a0, 0xe0
578 or $t0, $t1
579 bnez $t0, m_read_null # invalid address
580 ins $a0, $0, 0, 1
581 j PicoVideoRead
582 nop
583
584m_read16_ram:
585 lui $t0, %hi(Pico)
586 ins $a0, $0, 0, 1
587 ins $t0, $a0, 0, 16
588 jr $ra
589 lh $v0, %lo(Pico)($t0)
590
591m_read16_above_rom:
592 # might still be SRam
593 m_read_rom_try_sram 0 16
594 lui $t1, %hi(PicoRead16Hook)
595 lw $t1, %lo(PicoRead16Hook)($t1)
596 jr $t1
597 ins $a0, $0, 0, 1
598
599# #############################################################################
600
601.macro m_read32_rom sect
602 lui $t0, %hi(Pico+0x22200)
603 lw $t0, %lo(Pico+0x22200)($t0) # rom
604 ins $a0, $0, 0, 1
605 ins $a0, $0, 19, 13
606.if \sect
607 lui $t1, 8*\sect
608 addu $a0, $t1
609.endif
610 addu $t0, $a0
611 lh $v1, 0($t0)
612 lh $v0, 2($t0)
613 jr $ra
614 ins $v0, $v1, 16, 16
615.endm
616
617
618m_read32_rom0: # 0x000000 - 0x07ffff
619 m_read32_rom 0
620
621m_read32_rom1: # 0x080000 - 0x0fffff
622 m_read32_rom 1
623
624m_read32_rom2: # 0x100000 - 0x17ffff
625 m_read32_rom 2
626
627m_read32_rom3: # 0x180000 - 0x1fffff
628 m_read32_rom 3
629
630m_read32_rom4: # 0x200000 - 0x27ffff, SRAM area
631 m_read_rom_try_sram 1 32
632 lw $t1, 4($t3) # romsize
633 subu $t4, $t1, $a0
634 blez $t4, m_read_null
635 lw $t1, 0($t3) # rom
636 ins $a0, $0, 0, 1
637 addu $t1, $a0
638 lh $v1, 0($t1)
639 lh $v0, 2($t1)
640 jr $ra
641 ins $v0, $v1, 16, 16
642
643m_read32_rom5: # 0x280000 - 0x2fffff
644 m_read32_rom 5
645
646m_read32_rom6: # 0x300000 - 0x37ffff
647 m_read32_rom 6
648
649m_read32_rom7: # 0x380000 - 0x3fffff
650 m_read32_rom 7
651
652m_read32_rom8: # 0x400000 - 0x47ffff
653 m_read32_rom 8
654
655m_read32_rom9: # 0x480000 - 0x4fffff
656 m_read32_rom 9
657
658m_read32_romA: # 0x500000 - 0x57ffff
659 m_read32_rom 0xA
660
661m_read32_romB: # 0x580000 - 0x5fffff
662 m_read32_rom 0xB
663
664m_read32_romC: # 0x600000 - 0x67ffff
665 m_read32_rom 0xC
666
667m_read32_romD: # 0x680000 - 0x6fffff
668 m_read32_rom 0xD
669
670m_read32_romE: # 0x700000 - 0x77ffff
671 m_read32_rom 0xE
672
673m_read32_romF: # 0x780000 - 0x7fffff
674 m_read32_rom 0xF
675
676m_read32_rom10: # 0x800000 - 0x87ffff
677 m_read32_rom 0x10
678
679m_read32_rom11: # 0x880000 - 0x8fffff
680 m_read32_rom 0x11
681
682m_read32_rom12: # 0x900000 - 0x97ffff
683 m_read32_rom 0x12
684
685m_read32_rom13: # 0x980000 - 0x9fffff
686 m_read32_rom 0x13
687
688.macro m_read32_call16 func need_a1=0
689 addiu $sp, -8
690 sw $ra, 0($sp)
691 sw $s0, 4($sp)
692.if \need_a1
693 li $a1, 16
694.endif
695 jal \func
696 move $s0, $a0
697
698 addu $a0, $s0, 2
699.if \need_a1
700 li $a1, 16
701.endif
702 jal \func
703 move $s0, $v0
704
705 ins $v0, $s0, 16, 16
706 lw $ra, 0($sp)
707 lw $s0, 4($sp)
708 jr $ra
709 addiu $sp, 8
710.endm
711
712m_read32_misc:
713 ins $a0, $0, 0, 1
714 m_read32_call16 OtherRead16, 1
715
716m_read32_vdp:
717 ext $t0, $a0, 16, 3
718 andi $t1, $a0, 0xe0
719 or $t0, $t1
720 bnez $t0, m_read_null # invalid address
721 ins $a0, $0, 0, 1
722 m_read32_call16 PicoVideoRead
723
724m_read32_ram:
725 lui $t0, %hi(Pico)
726 ins $a0, $0, 0, 1
727 ins $t0, $a0, 0, 16
728 lh $v1, %lo(Pico)($t0)
729 lh $v0, %lo(Pico+2)($t0)
730 jr $ra
731 ins $v0, $v1, 16, 16
732
733m_read32_above_rom:
734 # might still be SRam
735 m_read_rom_try_sram 0 32
736 ins $a0, $0, 0, 1
737 lui $t1, %hi(PicoRead16Hook)
738 lw $t1, %lo(PicoRead16Hook)($t1)
739 addiu $sp, -4*3
740 sw $ra, 0($sp)
741 sw $s0, 4($sp)
742 sw $t1, 8($sp)
743 jalr $t1
744 move $s0, $a0
745
746 lw $t1, 8($sp)
747 addu $a0, $s0, 2
748 jalr $t1
749 move $s0, $v0
750
751 ins $v0, $s0, 16, 16
752 lw $ra, 0($sp)
753 lw $s0, 4($sp)
754 jr $ra
755 addiu $sp, 4*3
756
757# #############################################################################
758
759.macro PicoWriteRomHW_SSF2_ls def_table table
760 lui $t3, %hi(\def_table)
761 ins $t3, $a1, 2, 5
762 lw $t0, %lo(\def_table)($t3)
763 lui $t2, %hi(\table)
764 ins $t2, $a0, 2, 3
765 sw $t0, %lo(\table)($t2)
766.endm
767
768PicoWriteRomHW_SSF2: # u32 a, u32 d
769 ext $a0, $a0, 1, 3
770 bnez $a0, pwr_banking
771
772 # sram register
773 lui $t0, %hi(Pico+0x22211)
774 lb $t1, %lo(Pico+0x22211)($t0) # Pico.m.sram_reg
775 ins $t1, $a1, 0, 2
776 jr $ra
777 sb $t1, %lo(Pico+0x22211)($t0)
778
779pwr_banking:
780 andi $a1, 0x1f
781
782 PicoWriteRomHW_SSF2_ls m_read8_def_table m_read8_table
783 PicoWriteRomHW_SSF2_ls m_read16_def_table m_read16_table
784 PicoWriteRomHW_SSF2_ls m_read32_def_table m_read32_table
785
786 jr $ra
787 nop
788