Kylearan Posted June 5, 2015 Share Posted June 5, 2015 Hi, when searching for F4 bank switching, most sources I found use the BIT or LDA instruction to switch banks, e.g. BIT 1FF4 or LDA 1FF4,x. However, the BIT instruction doesn't preserve flags. Will it also work (reliably) with STA, e.g. STA 1FF4? It works with Stella, but does it work also on real hardware? If it works, what's the reason for people using BIT or LDA instead? Thanks, -Kylearan Quote Link to comment Share on other sites More sharing options...
ZackAttack Posted June 5, 2015 Share Posted June 5, 2015 My guess would be that STA would cause bus contention on real hardware and possibly damage or crash the system. But, that's just a guess. Quote Link to comment Share on other sites More sharing options...
+SpiceWare Posted June 5, 2015 Share Posted June 5, 2015 use an "illegal" NOP. DASM will compile SwitchBanks: nop SelectBank4 ; after switching to bank 4 the JMP will be OSwaitMenu jmp OSwaitGame as 809 5cd0 SwitchBanks 810 5cd0 0c fa ff nop SelectBank4 ; after switching to bank 4 the JMP will be OSwaitMenu 811 5cd3 4c 01 f1 jmp OSwaitGame 812 5cd6which works just fine.collect2.bin Quote Link to comment Share on other sites More sharing options...
Kylearan Posted June 5, 2015 Author Share Posted June 5, 2015 Thank you, SpiceWare! That's a very nice solution. Quote Link to comment Share on other sites More sharing options...
+SpiceWare Posted June 5, 2015 Share Posted June 5, 2015 No problem. Collect2 originally used CMP SelectBank#, but I did a quick change to confirm it worked. Collect2 is the simple game I'm creating for my DPC+ ARM Development series. Using DPC+ bankswitching with ARM support is how I write games like Space Rocks and Stay Frosty 2. Quote Link to comment Share on other sites More sharing options...
Omegamatrix Posted June 6, 2015 Share Posted June 6, 2015 use an "illegal" NOP. DASM will compile SwitchBanks: nop SelectBank4 ; after switching to bank 4 the JMP will be OSwaitMenu jmp OSwaitGame as 809 5cd0 SwitchBanks 810 5cd0 0c fa ff nop SelectBank4 ; after switching to bank 4 the JMP will be OSwaitMenu 811 5cd3 4c 01 f1 jmp OSwaitGame 812 5cd6which works just fine. Yeah, a lot of homebrewers seem to favour the illegal NOP's for bankswitching. For the Doctor Who hack we went with some quick and easy routines to bankswitch. We had lots of rom and not much ram so we just jumped to a function and jumped back using a macro we made to BANKSWITCH_TO_CODE. It obviously uses more bytes than other routines, but worked well for what we needed. ;F4 bankswitching macros ;usage: ;{1} = destination address ;{2} = bank number (0 to 7) ;example: ; BANKSWITCH_TO_CODE MovePlayerLogic, OVERSCAN_LOGIC_BANK MAC BANKSWITCH_TO_CODE ldy #{2} lda #>({1}-1) pha lda #<({1}-1) jmp $FFEE ENDM ;place this macro in every bank at $xFEE MAC BANKSWITCH_ROUTINE pha lda BANK_0,Y rts .byte 0 ; Buffer for RTS .word 0,0,0,0 ; Hotpots .word $F000,$F000 ENDM Quote Link to comment Share on other sites More sharing options...
Andromeda Stardust Posted June 6, 2015 Share Posted June 6, 2015 Yeah, a lot of homebrewers seem to favour the illegal NOP's for bankswitching. Isn't it these same undocumented commands that cause issues with 7800 and Jr compatability? Quote Link to comment Share on other sites More sharing options...
Omegamatrix Posted June 6, 2015 Share Posted June 6, 2015 Isn't it these same undocumented commands that cause issues with 7800 and Jr compatability? No. 1 Quote Link to comment Share on other sites More sharing options...
Crispy Posted June 7, 2015 Share Posted June 7, 2015 It looks like the OP's question has been answered, but just to add to the discussion, Centipede uses STA to do its bank switching. It made me nervous when I first discovered what they were doing, but apparently it's OK since I haven't heard of masses of 2600 consoles melting down into piles of sculptured plastic after running Centipede. Quote Link to comment Share on other sites More sharing options...
Kylearan Posted June 7, 2015 Author Share Posted June 7, 2015 Good to know that STA is safe, too! I've already changed my STAs to NOPs though since I'm not afraid of undocumented/illegal opcodes, and the preservation of flags has saved me 160 cycles during overscan. :-) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.