Jump to content
IGNORED

Convenient bankswitching using macros


Recommended Posts

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
  • Like 7
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...