Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The Basics (Hexadecimal)

One of the most basic things to understand how the system works is understanding what hexadecimal is and how it works. Hexadecimal is basically a base 16 numbering system, using digits 0-9 and letters A-F. In Rust, we write hex values with the 0x prefix (for example 0x8000)

  • 1 byte = 8 bits
  • Each byte is represented with 2 hex characters
  • Example: 0xFF = 11111111 in binary = 255 in decimal
HexadecimalBinaryDecimal
0x00000000000
0x01000000011
0x0F0000111115
0x100001000016
0xFF11111111255

Game Boy Memory Map

The Game Boy has a 16-bit address space, which means it can address up to 2^16 = 65536 bytes (64 KB) of memory.

Here’s how the Game Boy’s memory is organized:

Address RangeSizeDescription
0x0000 - 0x3FFF16 KBCartridge ROM (bank 0)
0x4000 - 0x7FFF16 KBCartridge ROM (switchable bank)
0x8000 - 0x9FFF8 KBVRAM (Video RAM)
0xA000 - 0xBFFF8 KBExternal cartridge RAM
0xC000 - 0xDFFF8 KBWRAM (Work RAM)
0xE000 - 0xFDFF7.5 KBEcho RAM (mirror of WRAM)
0xFE00 - 0xFE9F160 BOAM (Object Attribute Memory)
0xFEA0 - 0xFEFF96 BUnusable
0xFF00 - 0xFF7F128 BI/O Registers
0xFF80 - 0xFFFE127 BHRAM (High RAM)
0xFFFF1 BInterrupt register

Addressing Examples

When you see ranges like 0x00-0x0F in the code, it means:

  • Start: 0x00 (0 in decimal)
  • End: 0x0F (15 in decimal)
  • Size: 16 possible values (0-15), which is 1 byte range

Another example:

  • 0x8000 - 0x9FFF: VRAM range
  • Size calculation: 0x9FFF - 0x8000 + 1 = 0x2000 = 8192 bytes = 8 KB