Platform:Game Boy/Memory bank controllers
How the cartridge mappers (MBC1, MBC2, MBC3, MBC5 and others) of the Game Boy switch ROM and RAM banks, by cartridge type byte at header offset 0x0147, with the quirks that show up in disassemblies.
Cartridge type byte
Header byte 0x0147 (see Format:Game Boy ROM image):
| Value | Hardware |
|---|---|
0x00 |
ROM only (32 KiB, no mapper) |
0x01–0x03 |
MBC1, +RAM, +RAM+battery |
0x05, 0x06 |
MBC2, +battery (512 x 4-bit RAM inside the MBC) |
0x08, 0x09 |
ROM+RAM(+battery), no licensed game known |
0x0B–0x0D |
MMM01 multi-game mapper |
0x0F–0x13 |
MBC3 with or without timer (RTC), RAM, battery |
0x19–0x1E |
MBC5, +RAM, +battery, +rumble |
0x20 |
MBC6 |
0x22 |
MBC7 (accelerometer, EEPROM, rumble) |
0xFC |
Pocket Camera |
0xFD |
Bandai TAMA5 |
0xFE |
HuC3 |
0xFF |
HuC1+RAM+battery |
Common register scheme
All MBCs are programmed by writing to the ROM area; the address range selects the register, the value is the setting:
| Write to | MBC1 | MBC3 | MBC5 |
|---|---|---|---|
0x0000–0x1FFF |
RAM enable (0x0A in low nibble) |
RAM + RTC enable | RAM enable |
0x2000–0x3FFF |
ROM bank, 5 bits | ROM bank, 7 bits | 0x2000–0x2FFF bank bits 0–7, 0x3000–0x3FFF bank bit 8
|
0x4000–0x5FFF |
RAM bank or ROM bank bits 5–6 | RAM bank 0x00–0x07 or RTC register 0x08–0x0C |
RAM bank 0x00–0x0F (bit 3 = rumble motor on rumble carts)
|
0x6000–0x7FFF |
banking mode (0 simple, 1 advanced) | RTC latch (write 0 then 1) | — |
In a disassembly, ld [0x2000], a (EA 00 20) or ld [0x2100], a (EA 00 21) is the bank switch. Both addresses are in the low-bank register range of every MBC listed here, which is why one bank-switch routine runs unchanged on MBC1, MBC3 and MBC5 carts.
MBC1
- Bank register value 0 is read as 1, and the check uses the full 5-bit register, so banks
0x20,0x40,0x60cannot appear at0x4000; selecting them gives0x21,0x41,0x61. In mode 1 they can be mapped at0x0000instead. - Carts with 1 MiB ROM or more use the 2-bit register as ROM bank bits 5–6 and then have at most 8 KiB RAM; carts with 32 KiB RAM have at most 512 KiB ROM.
- MBC1M multi-game carts wire the second register to bank bits 4–5 instead, so the bank formula differs.
MBC3
Up to 2 MiB ROM (bank 0 again maps to 1, but banks 0x20/0x40/0x60 work) and 32 KiB RAM. The RTC registers are selected by writing 0x08–0x0C to 0x4000 and read at 0xA000: seconds, minutes, hours, day low 8 bits, and a control byte (bit 0 day bit 8, bit 6 halt, bit 7 day-counter overflow). Writing 0 then 1 to 0x6000 latches the time. Emulator save files of RTC games append RTC state after the RAM; that layout is emulator-specific.
The MBC30 variant with 64 KiB RAM (8 banks) is used only by the Japanese Pokemon Crystal.
MBC5
Up to 8 MiB ROM (9-bit bank number) and 128 KiB RAM. Bank 0 written to the ROM bank register really maps bank 0 at 0x4000. Guaranteed to work in CGB double-speed mode, so most CGB-only games use it.
Evidence & references
Summarized from the Pan Docs pages MBCs, MBC1, MBC3 and MBC5 (gbdev/pandocs, CC0-1.0, commit abeda621759a8e2b322b368eacf4d31ec48eb4df). Unverified: which commercial games use 0x2100 rather than 0x2000 for bank switching was not surveyed; test by searching ROMs for EA 00 21 versus EA 00 20.