1
ROM Hacking Discussion / Zelda 1 Bank Swapping?
« on: February 06, 2022, 09:23:15 pm »
So far I've managed to keep my hacks confined to the free space in whatever bank is being hacked so I haven't had to use any bank swapping. At this point I've largely filled up bank 5 of the Legend of Zelda but I could use more data space, possibly in bank 6. The problem seems to be that the relevant code to process that data is already in bank 5 and bank swapping doesn't really help unless I duplicate that code.
Here's my understanding, please correct as needed.
1) Bank 7 is the fixed bank and is always available in memory at C000-FFFF.
2) A bank swap makes the given bank available at 8000-BFFF.
3) Bank swapping is generally only used from the fixed bank.
4) Code and the data which it references are usually in the same bank (or in the fixed bank); e.g. bank 5 cannot access data from bank 6 unless that data is written somewhere to system RAM at 0000-1FFF.
I noticed something confusing in the Zelda code which makes me question my assumptions:
1) Why do banks 0, 1, 2, 5, and 6 all duplicate a portion of code that's already in bank 7 * (ISR reset, MMC1 control, and the bank swap routine)? I notice that they're always loaded into the same RAM location so the code can always be called reliably, but why not call the code in the fixed bank instead?
2) Why does said code perform a bank swap to bank 7? Does this result in the same code/data both in 8000-BFFF and C000-FFFF?
4) Do banks beside the fixed bank typically use bank swapping?
* Duplicated code in banks 0, 1, 5, 6 and 7 (ROM locations 3F50, 7F50, 17F50, 1BF50, and 1FF50):
Here's my understanding, please correct as needed.
1) Bank 7 is the fixed bank and is always available in memory at C000-FFFF.
2) A bank swap makes the given bank available at 8000-BFFF.
3) Bank swapping is generally only used from the fixed bank.
4) Code and the data which it references are usually in the same bank (or in the fixed bank); e.g. bank 5 cannot access data from bank 6 unless that data is written somewhere to system RAM at 0000-1FFF.
I noticed something confusing in the Zelda code which makes me question my assumptions:
1) Why do banks 0, 1, 2, 5, and 6 all duplicate a portion of code that's already in bank 7 * (ISR reset, MMC1 control, and the bank swap routine)? I notice that they're always loaded into the same RAM location so the code can always be called reliably, but why not call the code in the fixed bank instead?
2) Why does said code perform a bank swap to bank 7? Does this result in the same code/data both in 8000-BFFF and C000-FFFF?
Code: [Select]
1FF90: A9 07 LDA #$07 ; A = 07
1FF92: 20 ACFF JSR $FFAC ; Switch to Bank A (7)
3) Can the duplicate code in those banks be removed and the relevant calls be redirected to bank 7 instead?4) Do banks beside the fixed bank typically use bank swapping?
* Duplicated code in banks 0, 1, 5, 6 and 7 (ROM locations 3F50, 7F50, 17F50, 1BF50, and 1FF50):
Code: [Select]
1FF50: 78 SEI
1FF51: D8 CLD
1FF52: A9 00 LDA #$00 ; A = 00
1FF54: 8D 0020 STA $2000
1FF57: A2 FF LDX #$FF ; X = FF
1FF59: 9A TXS
1FF5A: AD 0220 LDA $2002
1FF5D: 29 80 AND #$80 ; keep bits x... ....
1FF5F: F0 F9 BEQ $1FF5A
1FF61: AD 0220 LDA $2002
1FF64: 29 80 AND #$80 ; keep bits x... ....
1FF66: F0 F9 BEQ $1FF61
1FF68: 09 FF ORA #$FF ; set bits xxxx xxxx
1FF6A: 8D 0080 STA $8000
1FF6D: 8D 00A0 STA $A000
1FF70: 8D 00C0 STA $C000
1FF73: 8D 00E0 STA $E000
1FF76: A9 0F LDA #$0F ; A = 0F
1FF78: 20 98FF JSR $FF98
1FF7B: A9 00 LDA #$00 ; A = 00
1FF7D: 8D 00A0 STA $A000
1FF80: 4A LSR
1FF81: 8D 00A0 STA $A000
1FF84: 4A LSR
1FF85: 8D 00A0 STA $A000
1FF88: 4A LSR
1FF89: 8D 00A0 STA $A000
1FF8C: 4A LSR
1FF8D: 8D 00A0 STA $A000
1FF90: A9 07 LDA #$07 ; A = 07
1FF92: 20 ACFF JSR $FFAC ; Switch to Bank A (7)
1FF95: 4C 40E4 JMP $E440
----
1FF98: 8D 0080 STA $8000
1FF9B: 4A LSR
1FF9C: 8D 0080 STA $8000
1FF9F: 4A LSR
1FFA0: 8D 0080 STA $8000
1FFA3: 4A LSR
1FFA4: 8D 0080 STA $8000
1FFA7: 4A LSR
1FFA8: 8D 0080 STA $8000
1FFAB: 60 RTS
----
Bank Switch (Switch to Bank A)
1FFAC: 8D 00E0 STA $E000
1FFAF: 4A LSR
1FFB0: 8D 00E0 STA $E000
1FFB3: 4A LSR
1FFB4: 8D 00E0 STA $E000
1FFB7: 4A LSR
1FFB8: 8D 00E0 STA $E000
1FFBB: 4A LSR
1FFBC: 8D 00E0 STA $E000
1FFBF: 60 RTS