Skip to content
firelight.flagboy edited this page Aug 3, 2021 · 9 revisions

Memory Bank Controllers

The Gameboy has a limited spaced with his 16-bit address bus.
To overcome this limitation many Games are using Memory Bank Controllers (MBC).
A MBC allow to expand the available address space by bank switching.


No MBC

Cartridge with no MBC or ROM only (i.e.: with a rom size <32Kib or <0x8000) are directly load into the Rom Address Space.
Optionally up to 8KiB of RAM could be connected at

MBC1

MCB1 cartridge are limited to 2MByte ROM and/or 32 KiB RAM

Architecture

Name Upper Bound Lower Bound Description
ROM Bank 0 0x0000 0x3FFF contain the first 16 KiB of Cartridge ROM (READONLY)
ROM Bank n 0x4000 0x7FFF Contain the 16 KiB of the Cartridge ROM Bank n (READONLY)
RAM Bank n 0xA000 0xBFFF Contain the Cartridge RAM Bank n

Enable RAM

Before reading or writting to the external RAM, the game must enable it before (to prevent loose of data on expected shutdown).

To enable the RAM the game MUST write 0x0A in the range of 0x0000-0x1FFF, to disable he MUST write 0x00 in the same range

Change ROM Bank Number

To change the selected ROM Bank the game must write a byte in the range of 0x2000-0x3FFF.

The bank number can be in the range 0x01-0x1F so only the first 5-bits are taken in account.

The game write 0xE1 into 0x2000, 0xE1 = 0b1110_0001.
We kept the first 5 bits : n = (0xE1 & 0x1F) = 0x1, so the bank 1 is selected

when the game need to use a bank number > 0x1f see banking mode

Special 2-bit register

When writing in the range of 0x4000-0x5FFF set a 2-bit register that will be used for the banking mode

Change Banking Mode

MBC1 have 2 banking modes: ROM and RAM. These modes determine how the secondary 2-bit register is used.

You can change the mode by writing in the range of 0x6000-0x7FFF the following value:

  • 0x00 to enable ROM mode
  • 0x01 to enable RAM mode
Rom Mode

When ROM mode is enable, the ROM bank n is the concatenation of the special 2-bit register and the 5-bit rom number register

Ram Mode

When RAM mode is enable, the RAM bank number is the value of the special 2-bit register

Sources

Clone this wiki locally