So one of the games I'm working on has compressed code, which is unpacked and executed from RAM. Most of this is text pointers, but I've uncovered a much more complex bit of code that needs some major retooling - in this case, tilemapping code. Rather than have to rebuild the compressed binary into the game every time I change the code, stuck the code at DBFA00 (lorom addr) in the game binary, and a JML $DBFA00 in the compressed binary. The JML gets loaded into RAM at $7E8D4C.

The issue is that while the code works in SNES9X, it's crashing the game in ZSNES and I don't have immediate access to that area of the game in BSNES.

Here's the code I wrote, with the original code commented out above it. Note that if I remove the comments at the top of the file, essentially replicating the original functionality just with the JML hooks, the code STILL crashes ZSNES, so it's not necessarily any of my actual code. My guess is that it's an architecture quirk with JMLs out of and back into RAM.

(Just as a bit of background, the text was originally 16-bit. My version is 8-bit with DTE support at A>=0x50. The adjustments to the tilemapping reflect that.)

`lorom`

;$7E/8D4C: B7 A0 LDA [$A0],Y [$7E:7A86] A:75BE X:004B Y:0006 D:0200 DB:00 S:01FA P:envMXdizc HC:776 VC:239

;$7E/8D4E: C9 20 CMP #$20 A:755D X:004B Y:0006 D:0200 DB:00 S:01FA P:envMXdizc HC:864 VC:239

;$7E/8D50: F0 31 BEQ $31 [$8D83] A:755D X:004B Y:0006 D:0200 DB:00 S:01FA P:envMXdizC HC:920 VC:239

;$7E/8D52: 5A PHY A:755D X:004B Y:0006 D:0200 DB:00 S:01FA P:envMXdizC HC:976 VC:239

;$7E/8D53: AD F2 0F LDA $0FF2 [$00:0FF2] A:755D X:004B Y:0006 D:0200 DB:00 S:01F9 P:envMXdizC HC:1038 VC:239

;$7E/8D56: EB XBA A:7521 X:004B Y:0006 D:0200 DB:00 S:01F9 P:envMXdizC HC:1110 VC:239

;$7E/8D57: AD F9 0F LDA $0FF9 [$00:0FF9] A:2175 X:004B Y:0006 D:0200 DB:00 S:01F9 P:envMXdizC HC:1170 VC:239

;$7E/8D5A: C2 20 REP #$20 A:2100 X:004B Y:0006 D:0200 DB:00 S:01F9 P:envMXdiZC HC:1242 VC:239

;$7E/8D5C: 87 3D STA [$3D] [$7F:75BE] A:2100 X:004B Y:0006 D:0200 DB:00 S:01F9 P:envmXdiZC HC:1328 VC:239

;$7E/8D5E: 1A INC A A:2100 X:004B Y:0006 D:0200 DB:00 S:01F9 P:envmXdiZC HC:056 VC:240

;$7E/8D5F: A0 02 LDY #$02 A:2101 X:004B Y:0006 D:0200 DB:00 S:01F9 P:envmXdizC HC:110 VC:240

;$7E/8D61: 97 3D STA [$3D],Y [$7F:75C0] A:2101 X:004B Y:0002 D:0200 DB:00 S:01F9 P:envmXdizC HC:190 VC:240

;$7E/8D63: 1A INC A A:2101 X:004B Y:0002 D:0200 DB:00 S:01F9 P:envmXdizC HC:286 VC:240

;$7E/8D64: A0 40 LDY #$40 A:2102 X:004B Y:0002 D:0200 DB:00 S:01F9 P:envmXdizC HC:340 VC:240

;$7E/8D66: 97 3D STA [$3D],Y [$7F:75FE] A:2102 X:004B Y:0040 D:0200 DB:00 S:01F9 P:envmXdizC HC:420 VC:240

;$7E/8D68: 1A INC A A:2102 X:004B Y:0040 D:0200 DB:00 S:01F9 P:envmXdizC HC:516 VC:240

;$7E/8D69: A0 42 LDY #$42 A:2103 X:004B Y:0040 D:0200 DB:00 S:01F9 P:envmXdizC HC:570 VC:240

;$7E/8D6B: 97 3D STA [$3D],Y [$7F:7600] A:2103 X:004B Y:0042 D:0200 DB:00 S:01F9 P:envmXdizC HC:650 VC:240

;$7E/8D6D: E2 20 SEP #$20 A:2103 X:004B Y:0042 D:0200 DB:00 S:01F9 P:envmXdizC HC:746 VC:240

;$7E/8D6F: 1A INC A A:2103 X:004B Y:0042 D:0200 DB:00 S:01F9 P:envMXdizC HC:808 VC:240

;$7E/8D70: 8D F9 0F STA $0FF9 [$00:0FF9] A:2104 X:004B Y:0042 D:0200 DB:00 S:01F9 P:envMXdizC HC:862 VC:240

;$7E/8D73: A5 3D LDA $3D [$00:023D] A:2104 X:004B Y:0042 D:0200 DB:00 S:01F9 P:envMXdizC HC:934 VC:240

;$7E/8D75: 18 CLC A:21BE X:004B Y:0042 D:0200 DB:00 S:01F9 P:eNvMXdizC HC:998 VC:240

;$7E/8D76: 69 04 ADC #$04 A:21BE X:004B Y:0042 D:0200 DB:00 S:01F9 P:eNvMXdizc HC:1052 VC:240

;$7E/8D78: 90 02 BCC $02 [$8D7C] A:21C2 X:004B Y:0042 D:0200 DB:00 S:01F9 P:eNvMXdizc HC:1108 VC:240

;$7E/8D7A: E6 3E INC $3E [$00:023E] A:2100 X:003F Y:0042 D:0200 DB:00 S:01F9 P:envMXdiZC HC:940 VC:244

;$7E/8D7C: 85 3D STA $3D [$00:023D] A:21C2 X:004B Y:0042 D:0200 DB:00 S:01F9 P:eNvMXdizc HC:1170 VC:240

;$7E/8D7E: 7A PLY A:21C2 X:004B Y:0042 D:0200 DB:00 S:01F9 P:eNvMXdizc HC:1234 VC:240

;$7E/8D7F: C8 INY A:21C2 X:004B Y:0006 D:0200 DB:00 S:01FA P:envMXdizc HC:1302 VC:240

;$7E/8D80: C8 INY A:21C2 X:004B Y:0007 D:0200 DB:00 S:01FA P:envMXdizc HC:1356 VC:240

;$7E/8D81: 80 C9 BRA $C9 [$8D4C] A:21C2 X:004B Y:0008 D:0200 DB:00 S:01FA P:envMXdizc HC:042 VC:241

org $DBFA00

;LDA [$A0],Y

;CMP #$20

;JMP $7E8D50

RomAddr:

LDA [$A0],Y

CMP #$50

BCS TilemapDTE

CMP #$20

BNE TilemapRegular

BRL Exit

TilemapDTE:

PHY

LDA $0FF2

XBA

LDA $0FF9

REP #$20

STA [$3D]

INC A

LDY #$40

STA [$3D],Y

INC A

LDY #$02

STA [$3D],Y

INC A

LDY #$42

STA [$3D],Y

SEP #$20

INC A

STA $0FF9

LDA $3D

CLC

ADC #$04

BCC $02

INC $3D

STA $3D

PLY

INY

BRA RomAddr

TilemapRegular:

PHY

LDA $0FF2

XBA

LDA $0FF9

REP #$20

STA [$3D]

INC A

LDY #$40

STA [$3D],Y

SEP #$20

INC A

STA $0FF9

LDA $3D

CLC

ADC #$02

BCC $02

INC $3D

STA $3D

PLY

INY

BRA RomAddr

Exit:

JMP $7E8D83