Bankswitching - nonarkitten/monkeymonkeyjit GitHub Wiki

We'll support three bankswitch modes -- disabled (no support for bankswitching), absolute (bankswitching is detected by the JIT only) and indirect (all address modes can cause a bankswtich).

Absolute Bankswitching

When the addressing mode indicates an absolute memory location, then it's possible for the JIT to know that a bankswitch will occur and terminate the compiled block at that point with a special bankswitch handler call at the end. This is the fastest bankswitching mode and is probably the most common.

Indirect Bankswitching

To handle indirect bankswitching we need to test any write that does not have a fixed address; this is done with a MASK (AND) and TEST (CMP). If the address match is successful, then we need to jump to a special exit handler which will call the bankswitch subroutine and immediately exit at the specified address. I'm honestly not certain any program would use this method of bankswitching, so it should suffice to use absolute banckswitching.

Bankswitch Mask

Amiga, Atari ST and X68000 -- did not use bankswitching.

Sega Genesis/Mega Drive -- few games used bankswtiching until Super Street Figher II which used a 40Mbit ROM. The SSF2 mapper breaks the base 4MB of RAM into eight, 512KB regions. Region 0 ($000000-$07FFFF) is fixed and cannot be changed. The remaining seven regions are mapped to addresses $A130F3, $A130F5, $A130F7, $A130F9, $A130FB, $A130FD and $A130FF. The low six bits written set the 'page' within the ROM that each of these pagges address.

MASK: #$00FFFFF1
TEST: #$00A130F1

SNK NEO-GEO -- the NEO-GEO has two separate memory regions and was designed with bankswitching in-mind. The first region from $000000-$0FFFFF is fixed while $200000-$2FFFFF can be bank switched. To switch the bank, the program simply writes a byte to ANYWHERE in this address range, specifying the upper bits of the address. That is, writing $1 to $2xxxxx maps the 68000's physical memory from $200000-$2FFFFF to the ROM's $300000-$3FFFFF. In theory, this provides 28-bits of ROM space, or 256MB (2 gigabits), but in practice, all ROMs are much smaller than this.

MASK: #$00F00000
TEST: #$00200000