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 lui $t0, %hi(PicoOpt)
422 lw $t0, %lo(PicoOpt)($t0)
424 bnez $t0, ym2612_read_local_68k
428 lb $v0, %lo(Pico+0x22208)($t0) # Pico.m.rotate
431 sb $t1, %lo(Pico+0x22208)($t0)
433 # delay slot friendly
434 .macro m_read8_call16 funcname is_func_ptr=0
436 lui $t1, %hi(\funcname)
437 lw $t1, %lo(\funcname)($t1)
441 li $a1, 8 # not always needed, but shouln't cause problems
445 j \funcname # odd address
464 # if everything else fails, use generic handler
465 m_read8_call16 OtherRead16
471 bnez $t0, m_read_null # invalid address
472 m_read8_call16 PicoVideoRead
479 lb $v0, %lo(Pico)($t0)
482 # might still be SRam (Micro Machines, HardBall '95)
483 m_read_rom_try_sram 0 8
484 m_read8_call16 PicoRead16Hook 1
486 # #############################################################################
488 .macro m_read16_rom sect
489 lui $t0, %hi(Pico+0x22200)
490 lw $t0, %lo(Pico+0x22200)($t0) # rom
503 m_read16_rom0: # 0x000000 - 0x07ffff
506 m_read16_rom1: # 0x080000 - 0x0fffff
509 m_read16_rom2: # 0x100000 - 0x17ffff
512 m_read16_rom3: # 0x180000 - 0x1fffff
515 m_read16_rom4: # 0x200000 - 0x27ffff, SRAM area
516 m_read_rom_try_sram 1 16
517 lw $t1, 4($t3) # romsize
519 blez $t4, m_read_null
526 m_read16_rom5: # 0x280000 - 0x2fffff
529 m_read16_rom6: # 0x300000 - 0x37ffff
532 m_read16_rom7: # 0x380000 - 0x3fffff
535 m_read16_rom8: # 0x400000 - 0x47ffff
538 m_read16_rom9: # 0x480000 - 0x4fffff
541 m_read16_romA: # 0x500000 - 0x57ffff
544 m_read16_romB: # 0x580000 - 0x5fffff
547 m_read16_romC: # 0x600000 - 0x67ffff
550 m_read16_romD: # 0x680000 - 0x6fffff
553 m_read16_romE: # 0x700000 - 0x77ffff
556 m_read16_romF: # 0x780000 - 0x7fffff
559 m_read16_rom10: # 0x800000 - 0x87ffff
562 m_read16_rom11: # 0x880000 - 0x8fffff
565 m_read16_rom12: # 0x900000 - 0x97ffff
568 m_read16_rom13: # 0x980000 - 0x9fffff
580 bnez $t0, m_read_null # invalid address
590 lh $v0, %lo(Pico)($t0)
593 # might still be SRam
594 m_read_rom_try_sram 0 16
595 lui $t1, %hi(PicoRead16Hook)
596 lw $t1, %lo(PicoRead16Hook)($t1)
600 # #############################################################################
602 .macro m_read32_rom sect
603 lui $t0, %hi(Pico+0x22200)
604 lw $t0, %lo(Pico+0x22200)($t0) # rom
619 m_read32_rom0: # 0x000000 - 0x07ffff
622 m_read32_rom1: # 0x080000 - 0x0fffff
625 m_read32_rom2: # 0x100000 - 0x17ffff
628 m_read32_rom3: # 0x180000 - 0x1fffff
631 m_read32_rom4: # 0x200000 - 0x27ffff, SRAM area
632 m_read_rom_try_sram 1 32
633 lw $t1, 4($t3) # romsize
635 blez $t4, m_read_null
644 m_read32_rom5: # 0x280000 - 0x2fffff
647 m_read32_rom6: # 0x300000 - 0x37ffff
650 m_read32_rom7: # 0x380000 - 0x3fffff
653 m_read32_rom8: # 0x400000 - 0x47ffff
656 m_read32_rom9: # 0x480000 - 0x4fffff
659 m_read32_romA: # 0x500000 - 0x57ffff
662 m_read32_romB: # 0x580000 - 0x5fffff
665 m_read32_romC: # 0x600000 - 0x67ffff
668 m_read32_romD: # 0x680000 - 0x6fffff
671 m_read32_romE: # 0x700000 - 0x77ffff
674 m_read32_romF: # 0x780000 - 0x7fffff
677 m_read32_rom10: # 0x800000 - 0x87ffff
680 m_read32_rom11: # 0x880000 - 0x8fffff
683 m_read32_rom12: # 0x900000 - 0x97ffff
686 m_read32_rom13: # 0x980000 - 0x9fffff
689 .macro m_read32_call16 func need_a1=0
715 m_read32_call16 OtherRead16, 1
721 bnez $t0, m_read_null # invalid address
723 m_read32_call16 PicoVideoRead
729 lh $v1, %lo(Pico)($t0)
730 lh $v0, %lo(Pico+2)($t0)
735 # might still be SRam
736 m_read_rom_try_sram 0 32
738 lui $t1, %hi(PicoRead16Hook)
739 lw $t1, %lo(PicoRead16Hook)($t1)
758 # #############################################################################
760 .macro PicoWriteRomHW_SSF2_ls def_table table
761 lui $t3, %hi(\def_table)
763 lw $t0, %lo(\def_table)($t3)
766 sw $t0, %lo(\table)($t2)
769 PicoWriteRomHW_SSF2: # u32 a, u32 d
771 bnez $a0, pwr_banking
774 lui $t0, %hi(Pico+0x22211)
775 lb $t1, %lo(Pico+0x22211)($t0) # Pico.m.sram_reg
778 sb $t1, %lo(Pico+0x22211)($t0)
783 PicoWriteRomHW_SSF2_ls m_read8_def_table m_read8_table
784 PicoWriteRomHW_SSF2_ls m_read16_def_table m_read16_table
785 PicoWriteRomHW_SSF2_ls m_read32_def_table m_read32_table