Jump to content
IGNORED

Bankswitching help


Recommended Posts

I'm not sure what you mean by, "fixed bank" in this context.

 

The usual Atari (brand) -style bankswitching does not have a "fixed" bank. Each bank completely replaces the memory at $f000 (and mirrors) with a different 4kiB bank.

 

To swap between 2 4kiB banks using Atari F8 bankswitching, you strobe the address at $fff8 or $fff9 (thus the name). The usual way to do this is `nop $fff8`, which uses an "undocumented" nop mode; you can instead use `bit` or any other read operation if you want to avoid "undocumented" instructions for some reason, but it's quite reliable on the 6507. (Write operations like `sta` can work too, but they will stroke the register twice, since every write is preceded by a read also.)

 

Basically you're turning the page on the cartridge, but the CPU has no idea, so the Program Counter is just going to roll up to the next address in line after the bank switch. If the bank switch occurs at $f120, and takes a 3 byte instruction, then the next instruction is fetched from $f123 in whatever bank it happens to have switched into. The trickiest thing is to make sure that the next line of code, in that other bank, is where you need it to be.

 

For example: At startup, any bank might be active (depending on a lot of things). Usually, your Cold Start code will be something that triggers a bank switch to a certain bank (e.g. bank 0) and then jumps to your startup sequence.

 

RES vector $fffd => .word ColdStart

 

In Bank 1:

ColdStart:
          nop $fff8 ; switch to bank 0
          ;; the next line will never be reached,
          ;; the CPU will fetch its next instruction from Bank 0

 

In Bank 0:

ColdStart:
          nop ; skip over the bank switch code in bank 1
          nop
          nop

          ;; OK, this is where Bank 1 joins us, now do actual start up work
          sei ; whatever

 

It's important that ColdStartVector must be the same address in each bank. eg, $ff00 or so.

 

What I personally do with these sort of "all or nothing" bank switching schemes is to create a small region in high ROM that is included into each bank (I call mine EndBank.s, e.g. this one in Grizzards) which always starts at a known, fixed address and has functions that are aligned between all the banks. For example, the above ColdStart routine could be at $ff00 in each bank. The $fffd RES vector could point to $ff00. the $fffe BRK vector could also point to something in the shared region, if you use it.

 

You then can add other routines to pass control between one bank and the next. Each of these routines needs to have at least a tiny stub in the common area, so that when the bank switch occurs, the Program Counter is pointing to the next instruction.

 

e.g. again:

 

Suppose your DrawScore routine is in Bank 1.

 

;;; in Bank 0

GoDrawScore:
          nop $fff9             ; switch to bank 1
          nop                   ; never reached, padding
          nop
          brk

;;; in Bank 1

GoDrawScore:
          nop                    ; no need to switch banks, but
          nop                    ; we do need to align the next jmp
          nop                    ; with the PC when the bank is switched
          jmp DrawScore

 

Of course there are lots of ways to arrange something like this, but perhaps that helps shed a little light on things.

Link to comment
Share on other sites

12 hours ago, atari2600land said:

It seems so complicated. You have to line things up exactly within each bank?

Yes, when the bank switch command is issued , the whole 4K bank switches. It's like the code execution falls off a cliff, since the program counter moves onto whatever is next in the bank. It could be anything and may get stuck between an operand series. The alignment of the two banks makes a safe area for bankswitching.

  • Thanks 1
Link to comment
Share on other sites

  • 3 weeks later...

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