Skip to content

Part 11 Memory Bank Controllers

Shane DeSeranno edited this page Nov 4, 2015 · 18 revisions

Go Home

Part 11 - Memory Bank Controllers (MBC)

The entire available memory space the Gameboy can access is limited to a 2-byte address (0xFFFF or 65,535 addresses). When you divide this space up between all the devices, it leaves a pretty limited amount of space to be able to access the cartridge ROM.

0x0000 - 0x7FFF = 32,767 bytes = 32KB

So, what happens when the game is bigger than 32KB? Well, then the cartridge would have a specialized piece of hardware that manages pieces of this memory and allowed the game to swap out sections of this addressable memory space for different chunks. These is called switchable banks.

0x0000 - 0x3FFF: 16KB ROM Bank 00, this is non-switchable
0x4000 - 0x7FFF: 16KB ROM Bank 01..NN (in cartridge, switchable bank number)
0xA000 - 0xBFFF:  8KB External RAM    (in cartridge, switchable bank, if any)

The problem with this magic? Because it was a piece of hardware in the cartridge, it was common for different games to have different types of MBCs. This makes it difficult for emulators because it means that we need to write multiple MBCs. Fortunately, most of them behaved very similar to each other and according to the documentation, there seem to be five core mappers on the Gameboy. By comparison, the NES had hundreds of mappers!

These MBCs are:

ROM Only

Small games that are smaller than 32KB ROM do not require a MBC chip for ROM banking. The ROM is directly mapped to memory at 0x0000-0x7FFF. Optionally up to 8KB of RAM could be connected at 0xA000-0xBFFF.

MBC 1 (Maximum 2MB ROM and 32KB RAM)

This is the first MBC chip for the Gameboy. Any newer MBC chips are similar, so that is relative easy to upgrade a program from one MBC chip to another, or even to make it compatible to several different types of MBCs. The game controls which banks are active by writing to the ROM address space (0x0000-0x7FFF). This doesn't store the value since it is read-only, but activates switched in the MBC.

0x4000 - 0x7FFF - ROM Bank 0x01-0x7F (Read Only)

This area contains any of the 16KB banks of the ROM. This allows to address up to 125 ROM banks (almost 2MB). As described below, bank numbers 0x20, 0x40, and 0x60 cannot be used, resulting in the odd amount of 125 banks.

0xA000-0xBFFF - RAM Bank 0x00-0x03, if any (Read/Write)

This area is used to address external RAM in the cartridge. It can support up to 32KB, in form of four 8KB banks at 0xA000-0xBFFF.

0x0000-0x1FFF - RAM Enable (Write Only)

Before external RAM can be read or written, it must be enabled by writing to this address space. It is recommended to disable external RAM after accessing it, in order to protect its contents from damage during power down of the Gameboy. Usually the following values are used:

0x00: Disable RAM (default)
0x0A: Enable RAM

However, any value with 0x0A in the lower 4 bits enables RAM, and any other value disables RAM.

0x2000-0x3FFF - ROM Bank Number (Write Only)

Writing to this address space selects the lower 5 bits of the ROM Bank Number (in range 0x01-0x1F). When 0x00 is written, the MBC translates that to bank 0x01. That doesn't cause any issues so far, because ROM Bank 0x00 can be always directly accessed by reading from 0x0000-0x3FFF, but the same happens for banks 0x20, 0x40, and 0x60. Any attempt to address these ROM Banks will select banks 0x21, 0x41, and 0x61 instead.

0x4000-0x5FFF - RAM Bank Number - or - Upper Bits of ROM Bank Number (Write Only)

This 2-bit register can be used to select a RAM bank in range from 0x00-0x03, or to specify the upper two bits (Bit 5-6) of the ROM bank number, depending on the current ROM/RAM Mode. (See below.)

0x6000-0x7FFF - ROM/RAM Mode Select (Write Only)

This 1-bit register selects whether the two bits of the above register should be used as upper two bits of the ROM bank, or as RAM bank Number.

0x00: ROM Banking Mode (up to 8KByte RAM, 2MByte ROM) (default)
0x01: RAM Banking Mode (up to 32KByte RAM, 512KByte ROM)

The program may freely switch between both modes, the only limitation is that only RAM Bank 0x00 can be used during mode 0 (ROM Banking), and only ROM Banks 0x00-0x1F can be used during mode 1 (RAM Banking).

MBC 2 (Maximum 256KB ROM and 512 4-bits RAM)

0x0000-0x3FFF - ROM Bank 0x00 (Read Only)

Same as for MBC1.

0x4000-0x7FFF - ROM Bank 0x01-0x0F (Read Only)

Same as for MBC1, but only a total of 16 ROM banks are supported.

0xA000-0xA1FF - 512 4-bits RAM, built-in into the MBC2 chip (Read/Write)

The MBC2 doesn't support external RAM, instead it includes 512 4-bits of built-in RAM. As the data consists of 4-bit values, only the lower 4 bits of the bytes in this memory area are used.

0x0000-0x1FFF - RAM Enable (Write Only)

The least significant bit of the upper address byte must be zero to enable/disable RAM. For example, the following addresses can be used to enable/disable cart RAM: 0x0000-0x00FF, 0x0200-0x02FF, ..., 0x1E00-0x1EFF. The suggested address range to use for MBC2 RAM enable/disable is 0x0000-0x00FF.

0x2000-0x3FFF - ROM Bank Number (Write Only)

Writing a value (XXXXBBBB - X = Don't cares, B = bank select bits) into 0x2000-0x3FFF area will select an appropriate ROM bank at 0x4000-0x7FFF. The least significant bit of the upper address byte must be one to select a ROM bank. For example the following addresses can be used to select a ROM bank: 0x2100-0x21FF, 0x2300-0x23FF, ..., 0x3F00-0x3FFF. The suggested address range to use for MBC2 ROM bank selection is 0x2100-0x21FF.

MBC 3

Clone this wiki locally