2 #* memory handlers with banking support
3 #* (C) notaz, 2007-2008
5 #* This work is licensed under the terms of MAME license.
6 #* See COPYING file in the top-level directory.
20 .long m_read8_rom0 # 0x000000 - 0x07FFFF
21 .long m_read8_rom1 # 0x080000 - 0x0FFFFF
22 .long m_read8_rom2 # 0x100000 - 0x17FFFF
23 .long m_read8_rom3 # 0x180000 - 0x1FFFFF
24 .long m_read8_rom4 # 0x200000 - 0x27FFFF
25 .long m_read8_rom5 # 0x280000 - 0x2FFFFF
26 .long m_read8_rom6 # 0x300000 - 0x37FFFF
27 .long m_read8_rom7 # 0x380000 - 0x3FFFFF
28 .long m_read8_rom8 # 0x400000 - 0x47FFFF - for all those large ROM hacks
29 .long m_read8_rom9 # 0x480000 - 0x4FFFFF
30 .long m_read8_romA # 0x500000 - 0x57FFFF
31 .long m_read8_romB # 0x580000 - 0x5FFFFF
32 .long m_read8_romC # 0x600000 - 0x67FFFF
33 .long m_read8_romD # 0x680000 - 0x6FFFFF
34 .long m_read8_romE # 0x700000 - 0x77FFFF
35 .long m_read8_romF # 0x780000 - 0x7FFFFF
36 .long m_read8_rom10 # 0x800000 - 0x87FFFF
37 .long m_read8_rom11 # 0x880000 - 0x8FFFFF
38 .long m_read8_rom12 # 0x900000 - 0x97FFFF
39 .long m_read8_rom13 # 0x980000 - 0x9FFFFF
40 .long m_read8_misc # 0xA00000 - 0xA7FFFF
41 .long m_read_null # 0xA80000 - 0xAFFFFF
42 .long m_read_null # 0xB00000 - 0xB7FFFF
43 .long m_read_null # 0xB80000 - 0xBFFFFF
44 .long m_read8_vdp # 0xC00000 - 0xC7FFFF
45 .long m_read8_vdp # 0xC80000 - 0xCFFFFF
46 .long m_read8_vdp # 0xD00000 - 0xD7FFFF
47 .long m_read8_vdp # 0xD80000 - 0xDFFFFF
48 .long m_read8_ram # 0xE00000 - 0xE7FFFF
49 .long m_read8_ram # 0xE80000 - 0xEFFFFF
50 .long m_read8_ram # 0xF00000 - 0xF7FFFF
51 .long m_read8_ram # 0xF80000 - 0xFFFFFF
54 .long m_read16_rom0 # 0x000000 - 0x07FFFF
55 .long m_read16_rom1 # 0x080000 - 0x0FFFFF
56 .long m_read16_rom2 # 0x100000 - 0x17FFFF
57 .long m_read16_rom3 # 0x180000 - 0x1FFFFF
58 .long m_read16_rom4 # 0x200000 - 0x27FFFF
59 .long m_read16_rom5 # 0x280000 - 0x2FFFFF
60 .long m_read16_rom6 # 0x300000 - 0x37FFFF
61 .long m_read16_rom7 # 0x380000 - 0x3FFFFF
62 .long m_read16_rom8 # 0x400000 - 0x47FFFF
63 .long m_read16_rom9 # 0x480000 - 0x4FFFFF
64 .long m_read16_romA # 0x500000 - 0x57FFFF
65 .long m_read16_romB # 0x580000 - 0x5FFFFF
66 .long m_read16_romC # 0x600000 - 0x67FFFF
67 .long m_read16_romD # 0x680000 - 0x6FFFFF
68 .long m_read16_romE # 0x700000 - 0x77FFFF
69 .long m_read16_romF # 0x780000 - 0x7FFFFF
70 .long m_read16_rom10 # 0x800000 - 0x87FFFF
71 .long m_read16_rom11 # 0x880000 - 0x8FFFFF
72 .long m_read16_rom12 # 0x900000 - 0x97FFFF
73 .long m_read16_rom13 # 0x980000 - 0x9FFFFF
74 .long m_read16_misc # 0xA00000 - 0xA7FFFF
75 .long m_read_null # 0xA80000 - 0xAFFFFF
76 .long m_read_null # 0xB00000 - 0xB7FFFF
77 .long m_read_null # 0xB80000 - 0xBFFFFF
78 .long m_read16_vdp # 0xC00000 - 0xC7FFFF
79 .long m_read16_vdp # 0xC80000 - 0xCFFFFF
80 .long m_read16_vdp # 0xD00000 - 0xD7FFFF
81 .long m_read16_vdp # 0xD80000 - 0xDFFFFF
82 .long m_read16_ram # 0xE00000 - 0xE7FFFF
83 .long m_read16_ram # 0xE80000 - 0xEFFFFF
84 .long m_read16_ram # 0xF00000 - 0xF7FFFF
85 .long m_read16_ram # 0xF80000 - 0xFFFFFF
88 .long m_read32_rom0 # 0x000000 - 0x07FFFF
89 .long m_read32_rom1 # 0x080000 - 0x0FFFFF
90 .long m_read32_rom2 # 0x100000 - 0x17FFFF
91 .long m_read32_rom3 # 0x180000 - 0x1FFFFF
92 .long m_read32_rom4 # 0x200000 - 0x27FFFF
93 .long m_read32_rom5 # 0x280000 - 0x2FFFFF
94 .long m_read32_rom6 # 0x300000 - 0x37FFFF
95 .long m_read32_rom7 # 0x380000 - 0x3FFFFF
96 .long m_read32_rom8 # 0x400000 - 0x47FFFF
97 .long m_read32_rom9 # 0x480000 - 0x4FFFFF
98 .long m_read32_romA # 0x500000 - 0x57FFFF
99 .long m_read32_romB # 0x580000 - 0x5FFFFF
100 .long m_read32_romC # 0x600000 - 0x67FFFF
101 .long m_read32_romD # 0x680000 - 0x6FFFFF
102 .long m_read32_romE # 0x700000 - 0x77FFFF
103 .long m_read32_romF # 0x780000 - 0x7FFFFF
104 .long m_read32_rom10 # 0x800000 - 0x87FFFF
105 .long m_read32_rom11 # 0x880000 - 0x8FFFFF
106 .long m_read32_rom12 # 0x900000 - 0x97FFFF
107 .long m_read32_rom13 # 0x980000 - 0x9FFFFF
108 .long m_read32_misc # 0xA00000 - 0xA7FFFF
109 .long m_read_null # 0xA80000 - 0xAFFFFF
110 .long m_read_null # 0xB00000 - 0xB7FFFF
111 .long m_read_null # 0xB80000 - 0xBFFFFF
112 .long m_read32_vdp # 0xC00000 - 0xC7FFFF
113 .long m_read32_vdp # 0xC80000 - 0xCFFFFF
114 .long m_read32_vdp # 0xD00000 - 0xD7FFFF
115 .long m_read32_vdp # 0xD80000 - 0xDFFFFF
116 .long m_read32_ram # 0xE00000 - 0xE7FFFF
117 .long m_read32_ram # 0xE80000 - 0xEFFFFF
118 .long m_read32_ram # 0xF00000 - 0xF7FFFF
119 .long m_read32_ram # 0xF80000 - 0xFFFFFF
122 # #############################################################################
138 # #############################################################################
147 .global PicoWriteRomHW_SSF2
149 .global m_read8_def_table
150 .global m_read8_table
152 .macro PicoMemResetCopyDef dst_table src_table
153 lui $t0, %hi(\dst_table)
154 addiu $t0, %lo(\dst_table)
155 lui $t1, %hi(\src_table)
156 addiu $t1, %lo(\src_table)
168 .macro PicoMemResetRomArea dst_table ar_label
169 lui $t0, %hi(\dst_table)
170 addiu $t0, %lo(\dst_table)
171 lui $t1, %hi(\ar_label)
172 addiu $t1, %lo(\ar_label)
178 beq $t2, $t4, 1b # do not touch the SRAM area
187 lui $v1, %hi(Pico+0x22204)
188 lw $v1, %lo(Pico+0x22204)($v1) # romsize
194 PicoMemResetCopyDef m_read8_table m_read8_def_table
195 PicoMemResetCopyDef m_read16_table m_read16_def_table
196 PicoMemResetCopyDef m_read32_table m_read32_def_table
198 # update memhandlers according to ROM size
200 PicoMemResetRomArea m_read8_table m_read8_above_rom
201 PicoMemResetRomArea m_read16_table m_read16_above_rom
202 PicoMemResetRomArea m_read32_table m_read32_above_rom
207 # #############################################################################
209 .macro PicoReadJump table
213 lw $t0, %lo(\table)($t0)
220 PicoReadJump m_read8_table
223 PicoReadJump m_read16_table
226 PicoReadJump m_read32_table
228 # #############################################################################
236 addiu $v0, $0, 0xffff
238 # loads &Pico.rom to $t3
239 .macro m_read_rom_try_sram is200000 size
242 lui $t3, %hi(Pico+0x22200)
243 lw $t1, 8($t2) # SRam.end
251 addiu $t3, %lo(Pico+0x22200)
252 lw $t1, 4($t2) # SRam.start
256 lb $t1, 0x11($t3) # Pico.m.sram_reg
290 .macro m_read8_rom sect
291 lui $t0, %hi(Pico+0x22200)
292 lw $t0, %lo(Pico+0x22200)($t0) # rom
305 m_read8_rom0: # 0x000000 - 0x07ffff
308 m_read8_rom1: # 0x080000 - 0x0fffff
311 m_read8_rom2: # 0x100000 - 0x17ffff
314 m_read8_rom3: # 0x180000 - 0x1fffff
317 m_read8_rom4: # 0x200000 - 0x27ffff, SRAM area
318 m_read_rom_try_sram 1 8
319 lw $t1, 4($t3) # romsize
321 blez $t4, m_read_null
328 m_read8_rom5: # 0x280000 - 0x2fffff
331 m_read8_rom6: # 0x300000 - 0x37ffff
334 m_read8_rom7: # 0x380000 - 0x3fffff
337 m_read8_rom8: # 0x400000 - 0x47ffff
340 m_read8_rom9: # 0x480000 - 0x4fffff
343 m_read8_romA: # 0x500000 - 0x57ffff
346 m_read8_romB: # 0x580000 - 0x5fffff
349 m_read8_romC: # 0x600000 - 0x67ffff
352 m_read8_romD: # 0x680000 - 0x6fffff
355 m_read8_romE: # 0x700000 - 0x77ffff
358 m_read8_romF: # 0x780000 - 0x7fffff
361 m_read8_rom10: # 0x800000 - 0x87ffff
364 m_read8_rom11: # 0x880000 - 0x8fffff
367 m_read8_rom12: # 0x900000 - 0x97ffff
370 m_read8_rom13: # 0x980000 - 0x9fffff
378 bne $t0, $t1, m_read8_misc2
381 beqz $t0, m_read8_misc_hwreg
383 bgtz $t1, m_read8_misc_ioports
391 lui $v0, %hi(Pico+0x2220f)
393 lb $v0, %lo(Pico+0x2220f)($v0)
395 m_read8_misc_ioports:
396 lui $v0, %hi(Pico+0x22000)
399 lb $v0, %lo(Pico+0x22000)($v0)
404 bne $a0, $t0, m_read8_misc3
409 addiu $t0, 0xff60 # expecting 0xa0 to get 0
410 bnez $t0, m_read8_misc4
413 andi $t0, $a0, 0x4000
414 bnez $t0, m_read8_z80_misc
415 andi $t0, $a0, 0x6000
419 addiu $t0, 0xc000 # expecting 0x4000 to get 0
420 bnez $t0, m_read_neg1 # invalid
422 j ym2612_read_local_68k
426 lb $v0, %lo(Pico+0x22208)($t0) # Pico.m.rotate
429 sb $t1, %lo(Pico+0x22208)($t0)
431 # delay slot friendly
432 .macro m_read8_call16 funcname is_func_ptr=0
434 lui $t1, %hi(\funcname)
435 lw $t1, %lo(\funcname)($t1)
439 li $a1, 8 # not always needed, but shouln't cause problems
443 j \funcname # odd address
462 # if everything else fails, use generic handler
463 m_read8_call16 OtherRead16
469 bnez $t0, m_read_null # invalid address
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