Going beyond 4MB

Normally the console can only see up to 4MB on the cartridge. If you use a mapper however you can use more than that through a technique known as "bank switching" (where the console sees a chunk of those 4MB at once).

The Sega mapper has only been used by one official game (Super Street Fighter II), but Overdrive II uses a similar mapper and the Mega Everdrive provides an extended variant. The maximum size depends on the particular chip used.

ROM header

Before getting started, you need to tell the emulator or flashcart that your game uses the mapper or you won't be able to try it! You should replace the system field of the ROM header ($000100) with "SEGA SSF" (pad with spaces), instead of the usual "SEGA MEGA DRIVE" or "SEGA GENESIS". This will enable the mapper on Mega Everdrive, Mega SD, BlastEm, and possibly more.

In some cases emulators will try to autodetect the mapper when they spot the game writing to the mapper registers (e.g. Kega Fusion). May want to make sure to write to the mapper as early as possible.

How it works

First some explanation on bank switching.

The console can only see 4MB at once. What we do here is that the ROM is split into 512KB chunks (called pages). Meanwhile, the console still sees 4MB, also split into 512KB areas (called banks). Each bank is pointed to a page, letting us see up to 4MB at once. By switching the bank to another page, we can access other parts of the ROM as needed.

(in case it's not clear: "page" comes from the ROM, "bank" is what the console sees)

The first bank is always pointed to the first page (so the game can boot safely on reset), the other banks can be pointed to any page we want at any moment. Each bank has its own register and to switch them we just write the page to the relevant register (going over this in the next section).

The registers for each bank are these:

List of bank switching registers
RegisterAddress range
$000000-$07FFFF
$A130F3$080000-$0FFFFF
$A130F5$100000-$17FFFF
$A130F7$180000-$1FFFFF
$A130F9$200000-$27FFFF
$A130FB$280000-$2FFFFF
$A130FD$300000-$37FFFF
$A130FF$380000-$3FFFFF

Putting it into use

First let's come up with some prettier names for the registers:

MapperBank1: equ $A130F3 ; bank for $080000-$0FFFFF
MapperBank2: equ $A130F5 ; bank for $100000-$17FFFF
MapperBank3: equ $A130F7 ; bank for $180000-$1FFFFF
MapperBank4: equ $A130F9 ; bank for $200000-$27FFFF
MapperBank5: equ $A130FB ; bank for $280000-$2FFFFF
MapperBank6: equ $A130FD ; bank for $300000-$37FFFF
MapperBank7: equ $A130FF ; bank for $380000-$3FFFFF

Now it's time to use the mapper. When the game starts you'll want to do something like this, it will make the first 4MB of the ROM show up as usual:

    move.b  #1, (MapperBank1)
    move.b  #2, (MapperBank2)
    move.b  #3, (MapperBank3)
    move.b  #4, (MapperBank4)
    move.b  #5, (MapperBank5)
    move.b  #6, (MapperBank6)
    move.b  #7, (MapperBank7)

Now if, say, your game is 5MB and want to use the remaining 1MB, you could make them show up in the upper MB of the cartridge by doing this:

    move.b  #8, (MapperBank6)
    move.b  #9, (MapperBank7)

You can do the above as many times as you need.

Things to watch out for