|
| 1 | +macro remap_wram_base(addr, old, new, size) |
| 2 | + assert read1(<addr>+0) == $A9 |
| 3 | + |
| 4 | + if !strict == 1 |
| 5 | + assert read<size>(<addr>+1) == <old> |
| 6 | + endif |
| 7 | + |
| 8 | + org <addr> |
| 9 | + LDA<new> |
| 10 | +endmacro |
| 11 | + |
| 12 | +macro remap_wram(addr) |
| 13 | + %remap_wram_base(<addr>, $7E, ".B #$40", 1) |
| 14 | +endmacro |
| 15 | + |
| 16 | +macro remap_wram_local(addr) |
| 17 | + %remap_wram_base(<addr>, $00, ".B #$40", 1) |
| 18 | +endmacro |
| 19 | + |
| 20 | +macro remap_wram_16(addr) |
| 21 | + %remap_wram_base(<addr>, $007E, ".W #$0040", 2) |
| 22 | +endmacro |
| 23 | + |
| 24 | +; Bank 7E |
| 25 | +%remap_wram($008010) |
| 26 | +%remap_wram($0080A8) |
| 27 | +%remap_wram($008406) |
| 28 | +%remap_wram($008514) |
| 29 | +%remap_wram($00916F) |
| 30 | +%remap_wram($0091B6) |
| 31 | +%remap_wram($009206) |
| 32 | +%remap_wram($00982F) |
| 33 | +%remap_wram($009858) |
| 34 | +%remap_wram($009881) |
| 35 | +%remap_wram($0098A9) |
| 36 | +%remap_wram($0098FA) |
| 37 | + |
| 38 | +; Indirect pointers building |
| 39 | +%remap_wram($00A1A6) |
| 40 | +%remap_wram_16($00A1CF) |
| 41 | + |
| 42 | +; Indirect pointers that uses local RAM |
| 43 | +macro remap_indirect(orig, addr) |
| 44 | + assert read1(<addr>+0) == $A0 |
| 45 | + |
| 46 | + if !strict == 1 |
| 47 | + assert read2(<addr>+1) == <orig> |
| 48 | + endif |
| 49 | + |
| 50 | + org <addr> |
| 51 | + LDY.W #$6000|<orig> |
| 52 | + |
| 53 | +endmacro |
| 54 | + |
| 55 | +%remap_wram_local($008936) |
| 56 | +%remap_wram_local($0089AF) |
| 57 | + |
| 58 | +;these below doesn't work because the game often uses the pointers with DB set to $7E, |
| 59 | +;I made TLR remap differently the indexes by consequence. |
| 60 | +;%remap_indirect($189A, $008933) |
| 61 | +;%remap_indirect($189A, $0089AC) |
| 62 | +;%remap_indirect($1892, $009651) |
| 63 | +;%remap_indirect($1832, $009647) |
| 64 | +;%remap_indirect($1862, $00964C) |
| 65 | + |
| 66 | +; DMA parameters |
| 67 | +; Other DMA are either static, ROM-only or unused... |
| 68 | +%remap_wram($008329) |
| 69 | +%remap_wram($00834F) |
| 70 | +%remap_wram($00838C) |
| 71 | +%remap_wram_local($0083C2) |
| 72 | + |
| 73 | +macro remap_mvn(b1, b2, addr) |
| 74 | + if !strict == 1 |
| 75 | + assert read1(<addr>+0) == $54 |
| 76 | + assert read1(<addr>+1) == <b1> |
| 77 | + assert read1(<addr>+2) == <b2> |
| 78 | + endif |
| 79 | + |
| 80 | + !sb1 = <b1> |
| 81 | + !sb2 = <b2> |
| 82 | + |
| 83 | + if !sb1&$FE == $7E |
| 84 | + !sb1 #= !sb1-$7E+$40 |
| 85 | + endif |
| 86 | + |
| 87 | + if !sb2&$FE == $7E |
| 88 | + !sb2 #= !sb2-$7E+$40 |
| 89 | + endif |
| 90 | + |
| 91 | + assert !sb1 == $40 || !sb1 == $41 || !sb2 == $40 || !sb2 == $41 |
| 92 | + assert !sb1 != $7E && !sb2 != $7E && !sb1 != $7F && !sb2 != $7F |
| 93 | + |
| 94 | + org <addr> |
| 95 | + MVN !sb1, !sb2 |
| 96 | +endmacro |
| 97 | + |
| 98 | +%remap_mvn($7E, $7E, $008720) |
| 99 | +%remap_mvn($7E, $7E, $008744) |
| 100 | +%remap_mvn($7E, $05, $009B81) |
| 101 | +%remap_mvn($7E, $05, $009BA4) |
| 102 | +%remap_mvn($7E, $05, $009BB6) |
| 103 | +%remap_mvn($7E, $05, $00A183) |
| 104 | + |
| 105 | +macro remap_indirect_jump(dest, addr) |
| 106 | + assert read1(<addr>+0) == $DC |
| 107 | + |
| 108 | + if !strict == 1 |
| 109 | + assert read2(<addr>+1) == <dest> |
| 110 | + endif |
| 111 | + |
| 112 | + !res #= <dest>|$6000 |
| 113 | + |
| 114 | + assert !res >= $6000 && !res <= $7FFF |
| 115 | + |
| 116 | + org <addr> |
| 117 | + JMP.W [!res] |
| 118 | +endmacro |
| 119 | + |
| 120 | +%remap_indirect_jump($0010, $008253) |
| 121 | +%remap_indirect_jump($1801, $0084D4) |
| 122 | +%remap_indirect_jump($1801, $00872D) |
| 123 | +%remap_indirect_jump($00F5, $008758) |
| 124 | +%remap_indirect_jump($00F5, $008791) |
| 125 | +%remap_indirect_jump($00F5, $0087D7) |
| 126 | +%remap_indirect_jump($00F5, $00881A) |
| 127 | + |
| 128 | +; Format: <address to store>, <value to store> |
| 129 | +; Remap the WRAM specific to BWRAM. |
| 130 | + |
| 131 | +; It's worth commenting that the address is incremented by 5, |
| 132 | +; while the code only read the first four values. It's suggestive |
| 133 | +; that the table was supposed to be incremented by 4. |
| 134 | + |
| 135 | +; It's very likely a bug, but we have to remain the original behavior |
| 136 | +org $0480BC |
| 137 | + db $02,$21,$00,$00,$07 |
| 138 | + db $42,$60,$00,$09,$42 |
| 139 | + db $00,$00,$16,$21,$00 |
| 140 | + db $00,$00,$00 |
| 141 | + |
| 142 | + |
0 commit comments