# The Game Pak: ROM, header, save chips, GPIO GBATEK sections "GBA Cartridges", "GBA Cartridge Header", "GBA Cart Backup IDs", "... SRAM/FRAM", "... EEPROM", "... Flash ROM", "GBA Cart I/O Port (GPIO)", "GBA Cart Real-Time Clock (RTC)" and the sensor chapters after it. Unlike the Game Boy there are no mappers: the ROM is linear up to 32 MiB, and what varies is the save chip and, on a few games, a GPIO port. ## The ROM - Linear at `8000000` (WS0), mirrored at `A000000` (WS1) and `C000000` (WS2); each mirror only changes the wait states. ROM is read-only to the CPU and to DMA0–2; DMA3 may write (flash carts; nothing here models that). - **Reads past the end** of a ROM smaller than 32 MiB return the address bus, because the Game Pak multiplexes the low 16 address bits with the data: `(address / 2) & FFFF` as a halfword (GBATEK "GBA Unpredictable Things", "Reading from GamePak ROM when no Cartridge is inserted"). jsmolka `memory.gba` and the mGBA suite's memory group check the empty-cartridge pattern. - The bus latches an address on an N access and increments it on S accesses; that is why a 128 KiB boundary forces N (the counter on the cartridge is 16 bits wide). The prefetch buffer ([start-here.md](start-here.md)) is on the GBA side of this bus. - Sizes in the local No-Intro set ([below](#census)): 1,492 ROMs of 8 MiB, 1,130 of 4 MiB, 578 of 16 MiB, 89 of 32 MiB; **138 are not a power of two** (trimmed dumps, video and e-Reader items). Reads past the end answer with the address pattern above, never zeros (mGBA does the same, `src/gba/memory.c`). ## The header `8000000`–`80000BF` (GBATEK "GBA Cartridge Header"): a 32-bit branch at `000`, the compressed Nintendo logo at `004`–`09F` (the BIOS compares it and hangs on a mismatch; bits 2 and 7 of `09C` unlock the BIOS's FIQ/undefined handlers for debugging), title `0A0`, game code `0AC`, maker `0B0`, fixed `96` at `0B2`, the complement check at `0BD` (the BIOS checks it). Multiboot images use the same header in EWRAM at `2000000`. Neither the logo nor the checksum is checked when the board skips the BIOS (user decision 2 in [handoff-brief.md](handoff-brief.md)); with the real BIOS a bad logo hangs, as on hardware. ## Save chips There is no save-type field. Nintendo's libraries link an ID string into the ROM and every emulator detects the chip from it (GBATEK "GBA Cart Backup IDs"): | ID | Chip | Size | At | Width | Notes | | --- | --- | --- | --- | --- | --- | | `SRAM_V`, `SRAM_F_V` | SRAM or FRAM | 32 KiB | `E000000`, mirrored | 8 | 16/32-bit reads return the byte replicated; writes store the addressed byte of the rotated value | | `FLASH_V`, `FLASH512_V` | Flash 512 Kbit | 64 KiB | `E000000` | 8 | command protocol at `E005555`/`E002AAA`; chip IDs from Panasonic, Sanyo, SST, Macronix, Atmel (128-byte page writes) | | `FLASH1M_V` | Flash 1 Mbit | 128 KiB | `E000000` | 8 | two 64 KiB banks, `B0` command selects | | `EEPROM_V` | EEPROM 4 Kbit or 64 Kbit | 512 B or 8 KiB | `D000000`–`DFFFFFF` (≤ 16 MiB ROM) or `DFFFF00`+ | 1 | serial on data bit 0, driven by DMA3 with 8-cycle WS2; 6- or 14-bit addresses; the size is not in the ID | | (none) | no save | | | | 26.8 % of the set | Behaviours the tests check and the board must have: - **Flash**: ID mode (`90`), chip erase (`80`,`10`), sector erase (`80`,`30`), byte program (`A0`), bank switch (`B0`), Atmel's page program, erased bytes read `FF`. The device ID returned decides what the game does, and the detectors disagree on the default: NBA reports SST 39LVF512 (`D4BF`) for 64K and Macronix MX29L010 (`09C2`) for 128K; mGBA reports Panasonic (`1B32`) and Sanyo LE26FV10N1TS (`1362`). Keep it one table of data ([undocumented-behavior.md](undocumented-behavior.md) C7). Judged by jsmolka `save/flash64.gba` and `flash128.gba` (mGBA fails test 10 of both here; NBA passes). - **EEPROM**: the size is detected from the first DMA's length (9 or 17 bits for a read request) or from a game database. Busy/ready after a write (bit 0 reads 0 until done). A command lives within one transfer: a non-sequential access (/CS high, then low) drops one still being shifted in (GBATEK; C24). jsmolka's `save/` has no EEPROM test; the AGS aging cartridges are the check (all five local revisions name `EEPROM_V`; on a fresh save they first show "CHECK SUM ERROR! DEFAULT IS SAVED", i.e. they write their settings to it), then commercial games. The 512 B/8 KiB split in the local set is not known from the IDs alone: a census by DMA length needs a running board. - **SRAM**: byte-wide; jsmolka `save/sram.gba`. - Save files are the raw chip contents, sized to the chip, so they load in mGBA and NBA (both accept that layout). `.sav` is never committed. ## GPIO: the real-time clock and sensors A 4-bit port at `80000C4` (data), `80000C6` (direction), `80000C8` (control: bit 0 makes the port readable; otherwise reads return ROM), GBATEK "GBA Cart I/O Port (GPIO)". Devices on it: | Device | Games | ID in ROM | | --- | --- | --- | | Seiko S-3511 RTC | Pokémon Ruby/Sapphire/Emerald, Boktai 1–3, *Rockman EXE 4.5*, ... | `SIIRTC_V` (60 ROMs in the local set) | | Solar sensor | Boktai 1–3 | none: by game code | | Tilt (KXP84), gyro, rumble | Yoshi's Universal Gravitation, WarioWare Twisted!, Drill Dozer | none: by game code | The first build models the RTC only (it gates Pokémon's clock events and Boktai); the sensors are game-database entries for later. ## Census `python scripts/count_saves.py` reads every licensed ROM in place from Aubrey's No-Intro mirror (`/data/emu/source/myrient.erista.me/files/No-Intro/Nintendo - Game Boy Advance`, override with `GBA_NOINTRO_DIR`) and counts the ID strings. Run 2026-10-21 on 3,487 ROMs (every zip except the `[BIOS]` entries), 0 unreadable: | First ID found (Flash, then EEPROM, then SRAM) | ROMs | Share | | --- | --- | --- | | `EEPROM_V` | 1,553 | 44.5 % | | none | 934 | 26.8 % | | `SRAM_V` | 497 | 14.3 % | | `SRAM_F_V` | 194 | 5.6 % | | `FLASH_V` | 123 | 3.5 % | | `FLASH512_V` | 99 | 2.8 % | | `FLASH1M_V` | 87 | 2.5 % | - 60 ROMs name `SIIRTC_V` (40 of them with `FLASH1M_V`: the Pokémon games). - 46 ROMs name two families (20 EEPROM+SRAM, 12 EEPROM+FLASH, ...): a library linked but unused. Emulators pick by a fixed order or a database; which chip the cartridge really has is a database question, recorded per game when a game fails. - So: SRAM + EEPROM + Flash 64K/128K + the RTC covers every save-carrying licensed game; none of the four can be left out of the first playable milestone.