Files
Eliran Zachandmorluto 208b81d724 feat(artifacts): inspect Game Boy and GBA ROM headers (#16249)
* feat(artifacts): inspect Game Boy and GBA ROM headers

Game Boy and Game Boy Color images (game-boy-rom) are claimed when at
least the first 24 bytes of the boot logo at 0x104 match, the half every
boot ROM compares. Root metadata reports the entry code and its JP
target, full or top-half logo match, title and manufacturer code, CGB
and SGB flags, mapper and features, declared ROM and RAM sizes,
destination, licensee codes, version, and declared and computed header
and global checksums. The global checksum is summed over the file in
bounded reads.

Game Boy Advance images (gba-rom) are claimed from an ARM branch at 0,
the fixed 0x96 at 0xB2, and the boot logo or a matching complement
check. Root metadata reports the entry branch target, logo match, title,
game and maker codes, fixed value, unit and device type, version, the
complement check, and the multiboot fields when that layout could apply.

Both serve header.bin and program.bin as stored ranges. Logos are
compared by SHA-256 digest, so no logo bytes are carried. Checksum,
logo and size disagreements leave coverage unknown; a header cut short
is refused as truncated with the offset where the file ends.

* fix(artifacts): keep missing GBA multiboot fields unknown and pin checksum vectors

A GBA file that ends inside the multiboot fields reported boot_mode and
slave_id as zero. They are now null, with a limitation naming where the
file ends. The Game Boy reader charges artifact_limits.expanded_bytes
from the file size before it sums the file for the global checksum.
Checksum tests now use hand-derived vectors instead of copying the
parser's own result.

* refactor(artifacts): read Game Boy and GBA header fields through BinaryReader

The GBA parser decoded words with a local reader that read missing bytes
as zero. Both parsers now read header fields through BinaryReader, as the
tool-design guide requires, after their length checks. The fixtures write
literal offsets instead of the parsers' field constants, and the guides
say inventory reads the stored members to hash them.

* fix(artifacts): read documented GB size codes and MBC4, refuse truncated GBA headers

* style(artifacts): format the handheld ROM test

---------

Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
2026-12-04 12:08:57 -05:00

4.9 KiB

Game Boy ROMs

inspect-artifact and extract-artifact read a Game Boy or Game Boy Color cartridge ROM (.gb, .gbc) offline. The file name does not matter. Recognition reads the boot logo at 0x104: at least its first 24 bytes, the half every boot ROM compares, must match. REA compares SHA-256 digests and does not carry the logo bytes. A file that has those logo bytes but ends before the header does (0x150) is refused as truncated, and the refusal names the offset where the file ends.

Nothing is executed, decompressed or patched. A checksum, logo or size disagreement is reported and left unchanged.

What the root reports

Root format_metadata (kind: "game-boy-rom") holds the header at 0x100..0x150:

  • rom_bytes: the file length.
  • entry_hex: the four bytes at 0x100, where the boot ROM hands over. entry_jump_target is the address of a JP a16 there, after an optional NOP, or null.
  • nintendo_logo: match, top-half or mismatch. top-half means the first 24 bytes match and the rest do not. The Game Boy Color boot ROM compares only the first half; the original Game Boy compares all 48 bytes.
  • title_raw_hex (the 16 bytes at 0x134) and title. When the CGB flag is set and 0x13F..0x143 holds four uppercase letters or digits, those bytes are manufacturer_code and the title stops before them. Otherwise the title runs to 0x143 (CGB flag set) or 0x144. title keeps printable ASCII before the first NUL and shows other bytes as ?.
  • cgb_flag and cgb: compatible (0x80), required (0xC0), none (bit 7 clear) or other.
  • sgb_flag and sgb_supported. Super Game Boy functions need flag 0x03 and old licensee code 0x33.
  • cartridge_type, mapper (none, mbc1, mbc2, mmm01, mbc3, mbc4, mbc5, mbc6, mbc7, pocket-camera, tama5, huc3, huc1, or null for an undocumented byte) and features (ram, battery, timer, rumble, sensor).
  • rom_size_code and declared_rom_bytes (32 KiB shifted by codes 0x00..0x08; codes 0x52, 0x53 and 0x54 declare 72, 80 and 96 banks of 16 KiB; otherwise null).
  • ram_size_code and declared_ram_bytes (2 KiB for code 0x01; null for undocumented codes). MBC2 has built-in RAM that the header does not declare.
  • destination_code and destination (japan, overseas or null).
  • old_licensee_code and new_licensee_code (two characters at 0x144, meaningful when the old code is 0x33). REA does not map licensee codes to publisher names.
  • version.
  • header_checksum: declared byte at 0x14D and the value computed over 0x134..0x14C, with status match or mismatch.
  • global_checksum: the big-endian word at 0x14E and the 16-bit sum of every other byte in the file, with status match or mismatch. The boot ROM does not check this value.

Members

Path Holds
header.bin The 80-byte header at 0x100..0x150
program.bin The whole file, as stored

Each member's format_metadata (kind: "game-boy-rom-entry") records role (header or program). Both are stored ranges and are counted separately toward artifact_limits.expanded_bytes.

Limitations

Coverage is complete only when nothing below applies. Otherwise coverage is unknown and a limitation names the cause:

  • The logo matches only in its first half, or not at all.
  • The declared header or global checksum differs from the computed one.
  • The file is shorter than the declared ROM size (the limitation names the offset where the file ends) or longer (it names the offset where the bytes outside the declared size begin).
  • The cartridge type, ROM size code or RAM size code is outside the documented table.

There is no fixed size ceiling. The header is parsed and the global checksum is summed in bounded reads, so the file is not held in memory. Inventory still reads the stored members, including program.bin, to hash them.

CLI

rea inspect-artifact ./game.gb --detail summary --json
rea extract-artifact ./game.gbc --json

Opening the program image

REA does not disassemble SM83 code. raw-binary does not admit SM83, and routing a console image through an installed Ghidra language is the open design in #5657. Bank 0 maps at 0x0000..0x3FFF and the switchable bank at 0x4000..0x7FFF; the mapper decides which file range is visible there.

Verification scope

Synthetic images cover header facts, every CGB flag form, matching and mismatched header and global checksums, a top-half and a full logo mismatch, short and long files against the declared size, undocumented type and size codes, a truncated header, a 2 MiB image summed in more than one read, and the expanded-bytes allowance. The fixtures carry a test logo pattern that tests register, not the boot logo. No commercial ROM was used.