The 16 KB pages
A Game Boy ROM is made of 16 KB pages, numbered from 0. The first half of the
address space is the ROM: bank 0 ($0000 to $3FFF) always shows page 0,
and bank 1 ($4000 to $7FFF) shows a page the program selects by
writing the page number as a byte anywhere in $2000 to $3FFF. A small
ROM of 32 KB has page 1 in bank 1 for good, without switching.
A GBS file has the structure of a ROM, but it is loaded from the load address on, so its pages
are counted from that address, not from the start of the data. With a load address of
$3F80, page 1 starts at memory address $4000, which is data offset
$80; page 2 is at data offset $4080, page 3 at $8080.
In general page n starts at data offset n × $4000 minus the load
address. The page numbers in the bank-switch code of the program have been changed to the
numbers the pages have in the GBS file.
The last page need not be a whole 16 KB: a player treats the missing bytes as null-filled.
Loading goes on until the end of the file or address $7FFF. After loading, page 0 is
in bank 0 and page 1 in bank 1.
| Memory | What a player puts there |
|---|---|
$0000 to $3FFF | Page 0: the data from the load address on, to the end of the page. |
$4000 to $7FFF | The selected page; at the start page 1. |
$A000 to $DFFF | RAM (cleared before INIT). |
$FF80 to $FFFE | High RAM, where the default stack is. |
Restart vectors
The Game Boy CPU has eight one-byte instructions that call a fixed address: RST $00
is CALL $0000, RST $08 is CALL $0008, and so on up to
RST $38. A GBS player sends them to an address relative to the load address: with a
load address of $3F00, RST $28 is CALL $3F28. A patch area
holding the routines for the restarts that are used is therefore put at the start of the data;
if the sound code uses none, it is not needed. The disassembly in the explorer names the targets
RST_00 to RST_38.
RAM banks
Some cartridges can switch 8 KB of RAM at $A000 to $BFFF or 4 KB at
$D000 to $DFFF, but sound routines do not need that much memory: a
player implements the main RAM from $A000 to $DFFF and disregards
writes to $4000 to $5FFF and to $FF70. A ripper removes
such writes from the code.
In the explorer
The structure tree shows the data as pages, each with its address in the Game Boy’s memory and its offset in the file, and the Code tab disassembles each page at the address it is seen at. The player selects the page with the low five bits of the byte written (a write of 0 selects page 1), as the MBC1 cartridge controller does and as Game_Music_Emu does, and gives the Tune tab’s count of pages.