Sega Master System / Mark III / Game Gear
SMS Power! 17th Anniversary Competitions voting now in progress!
Because the Z80 CPU only has a 64KB address space, and only 48KB of this is mapped to the cartridge on the Master System and Game Gear, "mappers" are used to allow the use of larger ROMs, as well as on-cartridge RAM. Smaller games (typically 32KB for released software) do not need a mapper.
The terminology can be confusing. In this document the word "paging", which usually means the same as "mapping", is not used. "Mapping", of course, refers to the act of presenting some range of a chip's address space at some, usually mismatching, range of the Z80's address space. "Mapper" refers to the hardware that performs mapping. "Slot" refers to an area of the Z80 address space into which various areas of ROM or RAM can be mapped. "Bank" refers to the area of ROM or RAM thus mapped.
There are several revisions of the Sega mapper, which was sometimes produced as a discrete chip but integrated into the ROM chip in most cases. It defines four 16KB slots in the memory map. Any 16KB bank of ROM may be mapped into any of the first three slots; additionally, up to two 16KB RAM banks can be mapped into the last two slots. The mapper hardware is controlled by writes to memory addresses $fffc-$ffff.
This is the mapper used in 99% of software, and is assumed to be there (for games larger than 48KB) by the BIOS.
The only difference between revisions is that unused functionality is removed from some of them, for example some versions only support ROM banking in slot 2 and some only support 128KB ROMs. Emulating a "full" mapper in all cases does not cause any problems.
Information about certain mapper chips can be found on the SMS Paging Chips page.
Address $fffc: RAM mapping and miscellaneous functions
|7||"ROM write" enable|
|4||RAM enable ($c000-$ffff)|
|3||RAM enable ($8000-$bfff)|
|2||RAM bank select|
Addresses $fffd-$ffff: ROM mapping
|Control register||ROM bank select for slot|
The registers are thought to be undefined after a reset for games using the 831001 and 832011 ROMs and 315-5208 mapper. The 315-5235 mapper is reset to FFFC=00, FFFD=00, FFFE=01, FFFF=02 after a power-up reset.
The ROM may be considered as an array of 16KB banks. The 8-bit value written to a ROM mapping control register from $fffd to $ffff selects which of these is mapped to the relevant slot.
Depending on the mapper revision, the number of significant bits in the bank selection register may vary - for example, some revisions have 3 significant bits (supporting 8 banks, 128KB total size), others have 5 (512KB), with the largest known supporting 6 bits (1MB). Some software may also set higher-order bits than those that are relevant to its ROM size. Provided the ROM is a power-of-two size, these issues do not cause problems, because ROM mirroring will nullify the effect.
When mapping in slot 0, the first 1KB is unaffected, in order to preserve the interrupt vectors. The remaining 15KB is mapped with the last 15KB of the relevant bank.
Most games only use slot 2; very few use slot 0.
Because the control registers overlap in the memory map with a RAM mirror, this mirrored RAM allows the last value written to each register to be read back (from the RAM copy). The registers are, however, strictly write-only. Overwriting the RAM mirror at another address will not affect mapping.
Note also the bank shifting feature described below.
The control register at $fffc enables mapping of on-cartridge RAM to the address space used by the in-console RAM ($c000-$ffff) or to slot 2 (region $8000-$bfff).
When bit 3 is
1, RAM will be mapped into slot 2, overriding any ROM banking via the control register at $ffff. When
0, ROM banking is effective.
When bit 4 is
1, RAM will be mapped into the address range used by the (mirrored) on-board RAM. To avoid bus contention, this should therefore be disabled using port $3E. No known software uses this feature.
The bank select bit chooses between the first 16KB bank of SRAM (
0) and the second (
1), but only for slot 2. Thus, if the register were set to
%---111--, 32KB of cartridge RAM would be exposed to the Z80 address bus between $8000 and $ffff (with the second 16KB mapped as the first and vice versa).
It is worth noting that most games with on-cartridge RAM have less than 32KB; most seem to have just 8KB, which is mirrored to fill both 16KB slots.
Bits 1-0 of the control register at $fffc define a shift value that is added to any bank number written to $fffd-f:
|Bit 1||Bit 0||Shift||Banks $00-$1F map to|
|$00||$00-$07, $08-$0F, $10-$17, $18-$1F|
|$18||$18-$1F, $00-$07, $08-$0F, $10-$17|
|$10||$10-$17, $18-$1F, $00-$07, $08-$0F|
|$08||$08-$0F, $10-$17, $18-$1F, $00-$07|
If only these bits are changed, there is no effect until one of the registers at $fffd-f is written to, at which point all three will have the shift applied. The $0000-$03ff region remains unmapped as before. No known software uses this feature. Because it is only featured on one type of 512KB mapper chip, its behaviour with other ROM sizes is undefined.
Bit 7 of the control register at $fffc controls write protection for the "ROM" (which may be emulated using RAM in development hardware). Setting this bit to
0 write protects it. This feature is not known to be used by any software.
This mapper presents three 16KB slots to the address bus as before. However, the control registers are mapped to the first byte of each bank and the first 1KB is no longer protected.
The mapper is initialised with banks 0, 1 and 0 in slots 0, 1 and 2 respectively.
When using slot 0, care must be taken to replace interrupt vectors appropriately. Also note that there is no RAM mirroring of mapper writes so there is no way to retrieve the last value written.
Most games seem to only use slot 2.
Due to the similarities with the Sega mapper, it is generally possible to patch Codemasters software to work with a Sega mapper.
One Codemasters game, Ernie Els Golf, features on-cart RAM. If the byte written to $4000 or $8000 has the high bit set then the upper 8KB of the corresponding bank is mapped to this on-cart RAM, with the lower 8KB being mapped to ROM as if the high bit were unset.
Some Korean original software (eg. Run! Dodgeball King) uses an alternative mapper system which is a further simplification of the above. Slots 0 and 1 are fixed to banks 0 and 1 of ROM respectively, while the bank mapped to slot 2 is selected by a byte written to address $a000.