Usually you would do this by having a group of labels either at the beginning or end of each bank, one for each address in other banks that you want to be able to jump to from that bank. To switch banks, you jump to the label you want, which selects the bank, and then after it is switched, jumps to the actual address you want to get to. You have to make sure the bank switching instructions line up with the following instructions on the next bank, because the program counter doesn't change when the bank switches, it marches on from wherever it was.

Another option, if you can use a couple bytes of temp RAM, is to use an indirect jump. Load the desired final address into a pointer, and jump to the label that switches to the desired bank. From there do an indirect jump to the pointer.

Thanks again! So F6 looks pretty much the same as F8, but for 4- 4K banks. I think that one looks good. To your earlier post- I'm writing up a routine right now that uses a lot of indirect jumps so that would work nicely here..

The way I did it in Medieval Mayhem seemed like a logical way to do it. I used macros JUMP_TABLE and BANKS_AND_VECTORS at the start and end of every bank. MM's a 32K game so there's 8 banks, the same technique will work work fewer banks.

I do recommend changing those to NOP instead of CMP as the CMP will set various flags which can cause unintended results to occur in your code. I wasn't aware of the illegal opcode variations of NOP at the time.

I managed to turn my "framework" code into a 32k bin with the help of the Medieval Mayhem blog. I put all of it in bank 5. Its not working yet though. It looks like its running through the reset routine, then pointing to a RAM address then resetting again. These labels look wrong too, Its adding "Game" to some of them, "InitSystem" Isn't my label for that routine, and labels are missing for SelectBank1 and SelectBank2 in MAC BANKS_AND_VECTORS. Also, my VerticalSync routine isn't there.

I managed to turn my "framework" code into a 32k bin with the help of the Medieval Mayhem blog. I put all of it in bank 5. Its not working yet though. It looks like its running through the reset routine, then pointing to a RAM address then resetting again. These labels look wrong too, Its adding "Game" to some of them, "InitSystem" Isn't my label for that routine, and labels are missing for SelectBank1 and SelectBank2 in MAC BANKS_AND_VECTORS. Also, my VerticalSync routine isn't there.

The code didn't compile correctly. You need to use ORG to define where the code goes in the physical rom, an RORG to give it a valid ROM space address.

So I'm curious how this works.. Is there a little bit of extra hardware in the cartridge that "listens" in on those addresses and then directs the bus to a bank? Perhaps a simple set of transistors turned high by the read? (I'm not an electronics whiz)

So I'm curious how this works.. Is there a little bit of extra hardware in the cartridge that "listens" in on those addresses and then directs the bus to a bank? Perhaps a simple set of transistors turned high by the read? (I'm not an electronics whiz)

The way I did it in Medieval Mayhem seemed like a logical way to do it. I used macros JUMP_TABLE and BANKS_AND_VECTORS at the start and end of every bank. MM's a 32K game so there's 8 banks, the same technique will work work fewer banks.

Depends upon the bankswitch scheme. I've not kept up with board developments, just checked and see UnoCart supports 3F, EF and F0 for 64K. I checked Stella's source to see how they work:

3F - Has thirty-two 2K banks. The first 2K of cartridge space ($F000-F7FF) get swapped, last 2K is always mapped to the last 2K bank. Bankswitch is done by writing the desired bank to address $3F.

EF - has sixteen 4K banks. Uses $1FE0 - $1FEF to select bank, so would need to adjust the BANKS_AND_VECTORS.

F0 - has sixteen 4K banks. Accessing $1FF0 switches to next bank, so you don't get to arbitrarily select a bank.

So of those EF could be made to work with my example. As Thomas mentions, if you do it this way the overhead increases (as more of each 4K bank is dedicated to bank switching code) so finding a better way to do it would be in your best interesting.

One side affect of my switching to ARM support for my games is they only use 1 bank of 6507 code, and the ARM sees everything without needing to bankswitch, so I've not looked into better ways to do it.