Hamtaro126 wrote:
EDIT: If you have the code for your NES Port, Can you please share? (Without the actual game code, of course.)
Yeah, in case this ever yields something presentable, I'll release the full sourcecode.
Regarding the topic of bankswitching and long jumps:
IMHO, the only correct way to do this is to replace all instances of bankswitching with native long jumps, i.e. remove all traces of the bankswitching interface.
This requires quite some effort, mainly because you'd not only have to modify all callers, but all callees aswell.
If, for some reason, you'd want to take the route of least possible modification,
preserving the bankswitching interface, possibly using static patches even (which probably would be a gigantic nightmare to maintain), the following would be one possible way to do that.
It's far from pretty though:
original nes bankswitching code, AOROM game:
Code:
/**
* switch bank, jump to subroutine
*
* @param a return bank with mirror flag
* @param x (target routine number + 1) * 3
* @param y target bank with mirror flag
*/
Lbl_00_ffcd:
ora #$00
sta $2d
lda $13
pha
stx $13
lda.w AOROM_BANK_PPU_MIRROR_2000,y
sta.w AOROM_BANK_PPU_MIRROR_2000,y
jsr Lbl_00_8000
ldy $2d
pla
sta $13
lda.w AOROM_BANK_PPU_MIRROR_2000,y
sta.w AOROM_BANK_PPU_MIRROR_2000,y
rts
/**
* bank LUT (avoids bus conflict on bank select), also with/out ppu mirroring flag
*/
AOROM_BANK_PPU_MIRROR_2000:
.byte $00,$01,$02,$03,$04,$05,$06,$07,$08,$09,$0a,$0b,$0c,$0d,$0e,$0f
AOROM_BANK_PPU_MIRROR_2400:
.byte $10,$11,$12,$13,$14,$15,$16,$17
/**
* trampoline bank 0
*/
Lbl_00_8000:
jmp ($0013)
/**
* jump table bank 0
*/
Lbl_00_8003:
jmp Lbl_00_e7b2
Lbl_00_8006:
jmp Lbl_00_8326
etc.
/**
* trampoline bank 1
*/
Lbl_01_8000:
jmp ($0013)
/**
* jump table bank 1
*/
Lbl_01_8003:
jmp Lbl_01_80a2
Lbl_01_8006:
jmp Lbl_01_8719
etc.
/**
* sample routine, bank 1
*/
Lbl_01_8719:
lda #$17
sta $b3
lda #$d0
sta $b4
lda #$86
sta $95
lda $b5
ror a
ror a
ror a
and #$c0
tay
ldx #$60
Lbl_01_872f:
lda.w Lbl_01_8619,y
sta $0100,x
iny
inx
cpx #$a0
bne Lbl_01_872f
rts
relevant routines modified to use long jumps instead while preserving interface (minus ppu mirror flags, which would probably best be handled in the graphics subsystem instead):
Code:
/**
* jump to subroutine, long (no ppu mirror flag handling here)
*
* @param x (target routine number + 1) * 3
* @param y target bank
*/
Lbl_00_ffcd:
;save previous jump target for whatever reason
php
pei ($13)
;prepare pointer to target bank
rep #$30
lda #Lbl_00_8000
sta $13
sep #$20
tya
sta $15
;execute jump
jsl longJump
;restore previous jump target
rep #$30
pla
sta $13
plp
rts
longJump:
jml [$13]
/**
* trampoline bank 0
*/
Lbl_00_8000:
dex
dex
jsr (Lbl_00_8003,x)
rtl
/**
* jump table bank 0
*/
Lbl_00_8003:
jmp Lbl_00_e7b2
Lbl_00_8006:
jmp Lbl_00_8326
etc.
/**
* trampoline bank 1
*/
Lbl_01_8000:
dex
dex
jsr (Lbl_01_8003,x)
rtl
/**
* jump table bank 1
*/
Lbl_01_8003:
jmp Lbl_01_80a2
Lbl_01_8006:
jmp Lbl_01_8719
etc.
To be honest, I don't think this example is terribly useful, because these modifications highly depend on the games actual implementation, but maybe it will give you some ideas.
As already hinted at earlier, I'm not actually using the above code snippet, because it feels hackish and not very maintainable to me.