The fields
The header is 112 bytes ($70). Every number of two bytes is little-endian
(least-significant byte first). The data starts at offset $70.
| Offset | Size | Field | Meaning |
|---|---|---|---|
$00 | 3 | Magic | The letters G B S ($47 $42 $53). |
$03 | 1 | Version | 1. It is the only version of the format. |
$04 | 1 | Songs | The number of songs, 1 to 255. |
$05 | 1 | First song | The song to start with, counted from 1 (usually 1). The number given to INIT is this minus one. |
$06 | 2 | Load address | $0400 to $7FFF: where the first byte of the data goes in the Game Boy’s memory. The restart instructions and the 16 KB pages are counted from it (Pages and RST). |
$08 | 2 | Init address | $0400 to $7FFF: the routine called with the song number in A (INIT). |
$0A | 2 | Play address | $0400 to $7FFF: the routine called at the timer or v-blank rate (PLAY). |
$0C | 2 | Stack pointer | The value of SP at INIT. A Game Boy starts with $FFFE, but many ROMs put the stack elsewhere, and it must not run over memory the routines use; ideally it is where the original ROM has it. |
$0E | 1 | Timer modulo (TMA) | The value TMA starts with; the timer period is 256 minus this many counts (Timing). |
$0F | 1 | Timer control (TAC) | Bits 1-0 the counter rate; bit 2 the interrupt type (0 v-blank, 1 timer); bits 6-3 reserved (0); bit 7 the CPU speed (1: the Game Boy Color’s double speed). |
$10 | 32 | Title | Text, null-filled on the right. All 32 bytes can be used, without a terminating zero. A single ? says the text is not known. |
$30 | 32 | Author | The composer. It is not the person who ripped the file. Same rules as the title. |
$50 | 32 | Copyright | The copyright line. Same rules. |
$70 | to the end | Code and data | The program and the music (Pages and RST). |
The addresses have a lower bound of $0400 in the specification so that a
hardware-based player (a cartridge that holds the file) has room for its own code at the start
of the ROM. A well-made file hardly approaches the lower addresses.
The stack pointer and the timer bytes are only initial values: INIT and PLAY can change the registers afterwards, and sound routines sometimes change the timer modulo to pick another tempo.
What the explorer checks
The structure tree names every field above and lists a problem on the field for a version other
than 1, no songs, a first song outside 1 to the number of songs, a load, init or play address
outside $0400 to $7FFF, reserved bits of TAC set, and a file that ends
inside the header. The strings show a question mark as “unknown”. A file shorter than 112 bytes
has no tune to play.