3 # memory handlers with banking support for SSF II - The New Challengers
4 # mostly based on Gens code
6 # (c) Copyright 2007, Grazvydas "notaz" Ignotas
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
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
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
121 # #############################################################################
137 # #############################################################################
146 .global PicoWriteRomHW_SSF2
148 .global m_read8_def_table
149 .global m_read8_table
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)
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)
177 beq $t2, $t4, 1b # do not touch the SRAM area
186 lui $v1, %hi(Pico+0x22204)
187 lw $v1, %lo(Pico+0x22204)($v1) # romsize
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
197 # update memhandlers according to ROM size
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
206 # #############################################################################
208 .macro PicoReadJump table
212 lw $t0, %lo(\table)($t0)
219 PicoReadJump m_read8_table
222 PicoReadJump m_read16_table
225 PicoReadJump m_read32_table
227 # #############################################################################
235 addiu $v0, $0, 0xffff
237 # loads &Pico.rom to $t3
238 .macro m_read_rom_try_sram is200000 size
241 lui $t3, %hi(Pico+0x22200)
242 lw $t1, 8($t2) # SRam.end
250 addiu $t3, %lo(Pico+0x22200)
251 lw $t1, 4($t2) # SRam.start
255 lb $t1, 0x11($t3) # Pico.m.sram_reg
289 .macro m_read8_rom sect
290 lui $t0, %hi(Pico+0x22200)
291 lw $t0, %lo(Pico+0x22200)($t0) # rom
304 m_read8_rom0: # 0x000000 - 0x07ffff
307 m_read8_rom1: # 0x080000 - 0x0fffff
310 m_read8_rom2: # 0x100000 - 0x17ffff
313 m_read8_rom3: # 0x180000 - 0x1fffff
316 m_read8_rom4: # 0x200000 - 0x27ffff, SRAM area
317 m_read_rom_try_sram 1 8
318 lw $t1, 4($t3) # romsize
320 blez $t4, m_read_null
327 m_read8_rom5: # 0x280000 - 0x2fffff
330 m_read8_rom6: # 0x300000 - 0x37ffff
333 m_read8_rom7: # 0x380000 - 0x3fffff
336 m_read8_rom8: # 0x400000 - 0x47ffff
339 m_read8_rom9: # 0x480000 - 0x4fffff
342 m_read8_romA: # 0x500000 - 0x57ffff
345 m_read8_romB: # 0x580000 - 0x5fffff
348 m_read8_romC: # 0x600000 - 0x67ffff
351 m_read8_romD: # 0x680000 - 0x6fffff
354 m_read8_romE: # 0x700000 - 0x77ffff
357 m_read8_romF: # 0x780000 - 0x7fffff
360 m_read8_rom10: # 0x800000 - 0x87ffff
363 m_read8_rom11: # 0x880000 - 0x8fffff
366 m_read8_rom12: # 0x900000 - 0x97ffff
369 m_read8_rom13: # 0x980000 - 0x9fffff
377 bne $t0, $t1, m_read8_misc2
380 beqz $t0, m_read8_misc_hwreg
382 bgtz $t1, m_read8_misc_ioports
390 lui $v0, %hi(Pico+0x2220f)
392 lb $v0, %lo(Pico+0x2220f)($v0)
394 m_read8_misc_ioports:
395 lui $v0, %hi(Pico+0x22000)
398 lb $v0, %lo(Pico+0x22000)($v0)
403 bne $a0, $t0, m_read8_misc3
408 addiu $t0, 0xff60 # expecting 0xa0 to get 0
409 bnez $t0, m_read8_misc4
412 andi $t0, $a0, 0x4000
413 bnez $t0, m_read8_z80_misc
414 andi $t0, $a0, 0x6000
418 addiu $t0, 0xc000 # expecting 0x4000 to get 0
419 bnez $t0, m_read_neg1 # invalid
421 j ym2612_read_local_68k
425 lb $v0, %lo(Pico+0x22208)($t0) # Pico.m.rotate
428 sb $t1, %lo(Pico+0x22208)($t0)
430 # delay slot friendly
431 .macro m_read8_call16 funcname is_func_ptr=0
433 lui $t1, %hi(\funcname)
434 lw $t1, %lo(\funcname)($t1)
438 li $a1, 8 # not always needed, but shouln't cause problems
442 j \funcname # odd address
461 # if everything else fails, use generic handler
462 m_read8_call16 OtherRead16
468 bnez $t0, m_read_null # invalid address
478 lb $v0, %lo(Pico)($t0)
481 # might still be SRam (Micro Machines, HardBall '95)
482 m_read_rom_try_sram 0 8
483 m_read8_call16 PicoRead16Hook 1
485 # #############################################################################
487 .macro m_read16_rom sect
488 lui $t0, %hi(Pico+0x22200)
489 lw $t0, %lo(Pico+0x22200)($t0) # rom
502 m_read16_rom0: # 0x000000 - 0x07ffff
505 m_read16_rom1: # 0x080000 - 0x0fffff
508 m_read16_rom2: # 0x100000 - 0x17ffff
511 m_read16_rom3: # 0x180000 - 0x1fffff
514 m_read16_rom4: # 0x200000 - 0x27ffff, SRAM area
515 m_read_rom_try_sram 1 16
516 lw $t1, 4($t3) # romsize
518 blez $t4, m_read_null
525 m_read16_rom5: # 0x280000 - 0x2fffff
528 m_read16_rom6: # 0x300000 - 0x37ffff
531 m_read16_rom7: # 0x380000 - 0x3fffff
534 m_read16_rom8: # 0x400000 - 0x47ffff
537 m_read16_rom9: # 0x480000 - 0x4fffff
540 m_read16_romA: # 0x500000 - 0x57ffff
543 m_read16_romB: # 0x580000 - 0x5fffff
546 m_read16_romC: # 0x600000 - 0x67ffff
549 m_read16_romD: # 0x680000 - 0x6fffff
552 m_read16_romE: # 0x700000 - 0x77ffff
555 m_read16_romF: # 0x780000 - 0x7fffff
558 m_read16_rom10: # 0x800000 - 0x87ffff
561 m_read16_rom11: # 0x880000 - 0x8fffff
564 m_read16_rom12: # 0x900000 - 0x97ffff
567 m_read16_rom13: # 0x980000 - 0x9fffff
579 bnez $t0, m_read_null # invalid address
589 lh $v0, %lo(Pico)($t0)
592 # might still be SRam
593 m_read_rom_try_sram 0 16
594 lui $t1, %hi(PicoRead16Hook)
595 lw $t1, %lo(PicoRead16Hook)($t1)
599 # #############################################################################
601 .macro m_read32_rom sect
602 lui $t0, %hi(Pico+0x22200)
603 lw $t0, %lo(Pico+0x22200)($t0) # rom
618 m_read32_rom0: # 0x000000 - 0x07ffff
621 m_read32_rom1: # 0x080000 - 0x0fffff
624 m_read32_rom2: # 0x100000 - 0x17ffff
627 m_read32_rom3: # 0x180000 - 0x1fffff
630 m_read32_rom4: # 0x200000 - 0x27ffff, SRAM area
631 m_read_rom_try_sram 1 32
632 lw $t1, 4($t3) # romsize
634 blez $t4, m_read_null
643 m_read32_rom5: # 0x280000 - 0x2fffff
646 m_read32_rom6: # 0x300000 - 0x37ffff
649 m_read32_rom7: # 0x380000 - 0x3fffff
652 m_read32_rom8: # 0x400000 - 0x47ffff
655 m_read32_rom9: # 0x480000 - 0x4fffff
658 m_read32_romA: # 0x500000 - 0x57ffff
661 m_read32_romB: # 0x580000 - 0x5fffff
664 m_read32_romC: # 0x600000 - 0x67ffff
667 m_read32_romD: # 0x680000 - 0x6fffff
670 m_read32_romE: # 0x700000 - 0x77ffff
673 m_read32_romF: # 0x780000 - 0x7fffff
676 m_read32_rom10: # 0x800000 - 0x87ffff
679 m_read32_rom11: # 0x880000 - 0x8fffff
682 m_read32_rom12: # 0x900000 - 0x97ffff
685 m_read32_rom13: # 0x980000 - 0x9fffff
688 .macro m_read32_call16 func need_a1=0
714 m_read32_call16 OtherRead16, 1
720 bnez $t0, m_read_null # invalid address
722 m_read32_call16 PicoVideoRead
728 lh $v1, %lo(Pico)($t0)
729 lh $v0, %lo(Pico+2)($t0)
734 # might still be SRam
735 m_read_rom_try_sram 0 32
737 lui $t1, %hi(PicoRead16Hook)
738 lw $t1, %lo(PicoRead16Hook)($t1)
757 # #############################################################################
759 .macro PicoWriteRomHW_SSF2_ls def_table table
760 lui $t3, %hi(\def_table)
762 lw $t0, %lo(\def_table)($t3)
765 sw $t0, %lo(\table)($t2)
768 PicoWriteRomHW_SSF2: # u32 a, u32 d
770 bnez $a0, pwr_banking
773 lui $t0, %hi(Pico+0x22211)
774 lb $t1, %lo(Pico+0x22211)($t0) # Pico.m.sram_reg
777 sb $t1, %lo(Pico+0x22211)($t0)
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