Jump to content

Photo

Convenient bankswitching using macros

Bankswitching Macros

4 replies to this topic

#1 Thomas Jentzsch OFFLINE  

Thomas Jentzsch

    Thrust, Jammed, SWOOPS!, Boulder Dash, THREE·S, Star Castle

  • 23,544 posts
  • Always left from right here!
  • Location:Düsseldorf, Germany, Europe, Earth

Posted Sat May 5, 2018 1:45 PM

I suppose everyone who ever had to use standard Atari bankswitching sooner or later developed some kind of pattern how to use it. And there are numerous ways to do it. But most of have to be used very carefully and are often not easy to maintain.

 

So I came up with the idea of using macros to make things as convenient as possible. The price for that convenience are more CPU cycles and destroyed registers and flags.
 
So here they are: 

BANK_SIZE = $1000

; Use at the start of each bank, required by JMP_LBL macro
  MAC START_BANK ; bank number
BANK_NUM    SET {1}

; this is not related to bankswitching, but nevertheless useful 
BANK_ORG    SET $8000 + BANK_NUM*BANK_SIZE
BANK_RORG   SET $1000 + BANK_NUM*BANK_SIZE*2

    SEG     code
    ORG     BANK_ORG, $55
    RORG    BANK_RORG

    ECHO    "  start of bank", [BANK_NUM]d, ", ORG", BANK_ORG, ", RORG", BANK_RORG
  ENDM

; Insert code for executing the bankswitch,
; should be put at the very end of each bank, right before the hotspots
  MAC SWITCH_BANK
    ORG  BANK_ORG + $ff4 - BANKSWITCH_SIZE
    RORG BANK_RORG + $ff4 - BANKSWITCH_SIZE, "before bankswitching code"

SwitchBank  = (. & $fff) | $1000
    pha
    txa
    pha
    lda     BANK0,y   ; e.g $fff8
    rts

BANKSWITCH_SIZE = ((. & $fff) | $1000) - SwitchBank
  ENDM

; Define a label which can be used by JMP_LBL macro
; Example:
;    DEF_LBL Foo
  MAC DEF_LBL ; address
{1}
{1}_BANK    = BANK_NUM
  ENDM

; Jump to a label in other or same bank. The assembler will take care if the
; code has to bankswitch or not.
; Example:
;    JMP_LBL Foo
  MAC JMP_LBL ; address
   IF {1}_BANK != BANK_NUM      ; convenience IF :)
    ldy     #{1}_BANK
    lda     #>({1}-1)
    ldx     #<({1}-1)
    jmp     SwitchBank          ; always at the same address in each bank
   ELSE
    jmp     {1}
   ENDIF
  ENDM 

As of now only JMP is supported, but macros for JSR could be created that way too.


Edited by Thomas Jentzsch, Sat May 5, 2018 1:47 PM.


#2 JeremiahK OFFLINE  

JeremiahK

    Chopper Commander

  • 187 posts
  • Location:Indiana, USA

Posted Sun May 6, 2018 4:11 PM

Thank you, I am in the process of upgrading my 4K project to a 16K one, and this will be very helpful.

#3 Kylearan OFFLINE  

Kylearan

    Chopper Commander

  • 210 posts

Posted Fri May 11, 2018 1:43 PM

In TIM1T, I used the ARPM bankswitching macros found here and found them very helpful - you might take a look at them for inspiration or comparison. Just note that the original macros have a small bug - see my post in that thread for details.



#4 Thomas Jentzsch OFFLINE  

Thomas Jentzsch

    Thrust, Jammed, SWOOPS!, Boulder Dash, THREE·S, Star Castle

  • Topic Starter
  • 23,544 posts
  • Always left from right here!
  • Location:Düsseldorf, Germany, Europe, Earth

Posted Fri May 11, 2018 2:30 PM

Those macros look very interesting. I will check them for sure. Maybe they are even easier to use than mine.



#5 JeremiahK OFFLINE  

JeremiahK

    Chopper Commander

  • 187 posts
  • Location:Indiana, USA

Posted Fri May 11, 2018 3:06 PM

And for reference, here is how SpiceWare has done it.  It's intended to be used after manually setting the ORG rather than automating that process for you.  For my case, I will probably just take ideas from these concepts for my own method.


Edited by JeremiahK, Fri May 11, 2018 3:16 PM.






Also tagged with one or more of these keywords: Bankswitching, Macros

0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users