Jump to content

Photo

F4 bank switching with STA?

bank switching f4

9 replies to this topic

#1 Kylearan OFFLINE  

Kylearan

    Chopper Commander

  • 210 posts

Posted Fri Jun 5, 2015 8:06 AM

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

 



#2 ZackAttack OFFLINE  

ZackAttack

    Dragonstomper

  • 761 posts
  • Location:Orlando, FL US

Posted Fri Jun 5, 2015 9:17 AM

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.



#3 SpiceWare OFFLINE  

SpiceWare

    Draconian

  • 12,699 posts
  • Medieval Mayhem
  • Location:Planet Houston

Posted Fri Jun 5, 2015 10:08 AM

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  5cd6
which works just fine.

Attached Files



#4 Kylearan OFFLINE  

Kylearan

    Chopper Commander

  • Topic Starter
  • 210 posts

Posted Fri Jun 5, 2015 10:18 AM

Thank you, SpiceWare! That's a very nice solution.

#5 SpiceWare OFFLINE  

SpiceWare

    Draconian

  • 12,699 posts
  • Medieval Mayhem
  • Location:Planet Houston

Posted Fri Jun 5, 2015 10:22 AM

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.



#6 Omegamatrix OFFLINE  

Omegamatrix

    Quadrunner

  • 6,233 posts
  • Location:Canada

Posted Fri Jun 5, 2015 10:30 PM

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  5cd6
which 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


#7 Kosmic Stardust OFFLINE  

Kosmic Stardust

    Princess Rescuer

  • 18,399 posts
  • Location:Milky Way Galaxy

Posted Sat Jun 6, 2015 2:55 AM


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?

#8 Omegamatrix OFFLINE  

Omegamatrix

    Quadrunner

  • 6,233 posts
  • Location:Canada

Posted Sat Jun 6, 2015 10:11 AM

Isn't it these same undocumented commands that cause issues with 7800 and Jr compatability?

No.



#9 Crispy OFFLINE  

Crispy

    Star Raider

  • 65 posts

Posted Sun Jun 7, 2015 12:46 AM

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.



#10 Kylearan OFFLINE  

Kylearan

    Chopper Commander

  • Topic Starter
  • 210 posts

Posted Sun Jun 7, 2015 5:54 AM

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. :-)





Also tagged with one or more of these keywords: bank switching, f4

0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users