# The cartridge: maps, header, coprocessors, coverage ## Where cartridge logic lives Memory maps, SRAM, and the address-decoding glue of every board live in `snes_python/cartridge/`, behind the connector protocol below, with a test that forbids imports from the rest of the board (the famicom-python and gameboy-python rule). **Coprocessors that are programmable processors are cores** (family rule: "chips are cores, boards compose cores; extract on the second consumer"), and the cartridge module composes them; decoders without a program (S-DD1, SPC7110's decompressor, OBC1, S-RTC) are cartridge code here. ## The connector (what a cartridge sees) 62 pins (fullsnes "SNES Cartridge Slot Pinouts", `wiki/Cartridge connector`): the **A bus** (A0-A23, D0-D7, /RD, /WR), **/ROMSEL** (the S-CPU's decode of "cartridge ROM space": `$00-3F,$80-BF:8000-FFFF` and `$40-7D,$C0-FF:any`), **/WRAMSEL** (seen, not driven), the **B bus address** PA0-PA7 with /PARD, /PAWR (so a cartridge can own B-bus registers: MSU-1 at `$2000-$2007` is on the A bus, but the Satellaview base unit and the expansion port use PA), the **master clock** (21.477 MHz), **/IRQ** (wired-OR with the S-CPU's timer IRQ), /RESET, the CIC lines, and the two audio inputs mixed after the S-DSP (the Super Game Boy and MSU-1 use these). [doc] ### Protocol (proposed; settled in milestone 4, changed only with a reason recorded here) ```python class Cartridge(Protocol): def read(self, address: int, romsel: bool, open_bus: int) -> int: ... def write(self, address: int, value: int, romsel: bool) -> None: ... def read_b(self, port: int, open_bus: int) -> int | None: ... # $21xx, None = not ours def write_b(self, port: int, value: int) -> bool: ... def access_cycles(self, address: int) -> int | None: ... # override the 6/8/12 table (SA-1 BW-RAM, none on plain carts) def advance(self, master_clocks: int) -> None: ... # coprocessor time, called by the board's clock irq: bool # the cartridge's /IRQ, ORed by the board def audio(self) -> tuple[float, float] | None: ... # SGB, MSU-1 def battery(self) -> bytes | None: ... # SRAM for saving ``` The board calls `read`/`write` for every cartridge-space access in the cycle it happens, with `open_bus` (the CPU MDR) so an unmapped hole returns it. `advance` is called with the master clocks elapsed since the last call, before every cartridge access and at the end of each line, so a coprocessor running in its own clock domain catches up exactly at shared-register accesses. ## Memory maps | Map | ROM | SRAM | Header at (file offset) | `$xxD5` | | --- | --- | --- | --- | --- | | **LoROM** (Mode 20) | 32 KiB banks at `$00-7D/$80-FF:8000-FFFF` | `$70-7D/$F0-FF:0000-7FFF` (some boards `0000-FFFF`) | `$7FC0` | `$20` / `$30` (FastROM) | | **HiROM** (Mode 21) | 64 KiB banks at `$C0-FF:0000-FFFF`, mirrored at `$40-7D` and upper halves of `$00-3F/$80-BF` | `$20-3F/$A0-BF:6000-7FFF` | `$FFC0` | `$21` / `$31` | | **ExHiROM** (Mode 25) | up to 8 MiB: `$C0-FF` = first 4 MiB, `$40-7D` = second | HiROM's, in `$80-BF` | `$40FFC0` | `$35` (`$25`) | | SA-1 (Mode 23), Super FX, SPC7110, S-DD1 | own maps, in their chapters | | `$7FC0` or `$FFC0` | `$23`, `$20`, `$3A`, `$32` | fullsnes "SNES Cartridge ROM Header", "SNES Cart LoROM/HiROM Mapping" [doc]; `wiki/LoROM`, `wiki/HiROM`, `wiki/ExHiROM` [doc]; MAME's `bus/snes/rom.cpp`, `rom21.cpp` [emu]. Real boards differ from the idealised maps in mirroring of small ROMs and SRAM, which a few games test as copy protection (the "SRAM-mirror check" in `wiki/Tricky-to-emulate games`). The board decodes by board class, not by header byte alone. ## Header detection The header (fullsnes, `wiki/ROM header`) is 64 bytes: title (21), map mode, chipset (`$xxD6`), ROM size, SRAM size, region, licensee, version, checksum complement and checksum, then the vectors. Bit 4 of the map mode is FastROM. Chipset `$xxD6`: low nibble 0 ROM, 1 +RAM, 2 +RAM+battery, 3-6 +coprocessor (+RAM, +battery, ...); high nibble names the coprocessor (0 DSP, 1 GSU, 2 OBC1, 3 SA-1, 4 S-DD1, 5 S-RTC, E other, F custom with the subtype at `$xxBF`: 0 SPC7110, 1 ST010/011, 2 ST018, 10 Cx4). Headers lie: copier headers add 512 bytes (file size mod 1024 = 512), some early games have bad checksums, a few have map-mode bytes that contradict their board. **Detection order** (proposed): a 512-byte copier header is stripped; then the three candidate headers are scored (checksum + complement = `$FFFF`, map mode consistent with the candidate's position, reset vector `>= $8000`, printable title, plausible size byte; `scripts/count_carts.py` `score()`); then **MAME's `hash/snes.xml` software list** is the secondary source when the image's hash is in it (its `slot` feature names the board exactly: `lorom`, `hirom`, `lorom_sa1`, `hirom_dsp`, ...), read at runtime from `/usr/share/games/mame/hash/`, as gameboy-python reads `gameboy.xml`; nothing copied. ### Header census (milestone 4, 2026-11-23) `python -I scripts/header_census.py` scores every licensed image in `$NO_INTRO_DIR/Nintendo - Super Nintendo Entertainment System` (3,322 after skipping Beta, Proto, Pirate, Unl, Sample, Demo, Program and Aftermarket dumps) with `cartridge.find_header` and checks the map against MAME's software list `hash/snes.xml` (CC0-1.0; its `slot` feature records each cartridge's board, matched by SHA-1, split ROMs chunk by chunk). 3,000 images are in the list; 322 are not (later dumps: Virtual Console, Switch Online, re-releases). | | Count | | --- | ---: | | plain boards (`lorom`/`hirom`) in the list | 2,854 | | map family right | **2,852** (1 ExHiROM) | | map family wrong | 2 | | coprocessor and special boards, map family right | 141 of 141 | | SRAM size: header $FFD8 equals the list's `nvram` | 2,844 of 2,854 | - **The two wrong**: *Battle Racers (Japan)* and *Undercover Cops (USA) (Retro-Bit)*: the list says `lorom`, but each image has a believable header only at `$FFC0` (map `$31`, checksum pair valid) and nothing at `$7FC0`; as LoROM both jump to `$0000` at once, as HiROM both run (2026-11-23, 600 frames). Recorded as probable list errors, not changed. - **Rule added** (DESIGN, provisional): an image with no believable header (no candidate names its own map or has a valid checksum pair) is LoROM. Before it the score put two headerless images on HiROM by one point from stray bytes: *Burn-in - Test Cartridge (USA) (Rev D)* and *Mechanoids 2 (Europe) (Auto Demo)*; both are `lorom` in the list, run as LoROM (picture at frame 600) and not as HiROM. - **Two rules added by the full sweep** (2026-11-24, docs/status.md "The full sweep"; DESIGN, provisional; the census above is unchanged by both, 2,852/2,854 and 141/141): - the LoROM fallback needs LoROM's reset vector in `$8000-$FFFE` (fullsnes: "valid entrypoints"). Prototypes whose only header is a title and vectors at `$FFC0` (map mode, sizes and checksum zero) ran from a LoROM "vector" like `$0480` into a blank screen: the betas of *Earthworm Jim*, *Final Fight 3*, *Hungry Dinosaurs*, *Killer Instinct*, *The Lion King* (3), *Rise of the Robots* and *Wolfenstein 3D* (2), and *Super Noah's Ark 3D* x 2 now run as HiROM; and the fallback also gives way when only the HiROM vector lands on start-up code (next rule): *Marvel Super Heroes in War of the Gems (USA) (Beta)*, *Noughts & Crosses (USA) (Possible Proto) (Nintendo Gateway System)*; - a tie in score goes to the candidate whose reset vector lands on SEI (`$78`) or CLC (`$18`), the usual start-up (SEI; CLC; XCE leaves emulation mode), then to LoROM: *Mortal Kombat II (USA) (Beta)* has a believable developer's header at `$7FC0` ("LEINGANG WAS HERE") beside its HiROM one, both scoring 16. Over the main set's 4,078 images with an image file, the two rules change these 12 maps and no other (`find_header` before and after, compared image by image). *Final Fight 3 (USA) (Beta)*, *Rise of the Robots (USA) (Beta)* and *Mortal Kombat II (USA) (Beta)* were blank at frame 300 and are now equal to Mesen2's frame (OBSERVED); *Marvel Super Heroes (Beta)* now draws its title, mid-fade (one 5-bit step from Mesen2's frame). - **Not changed**: *Batman - Revenge of the Joker (USA) (Proto)* has a believable HiROM header (title "BATMAN--REVENGE JOKER", map `$31`, checksum pair valid) and nothing at `$7FC0`, but MAME's list files it as `lorom` (a note there calls its internal name "possibly hacked"); as HiROM the S-CPU loops at `$00:8021` comparing `$2140` in an upload handshake that never completes, where Mesen2 shows a picture at frame 300. Not run as LoROM yet; a lead, like the two list errors above but the other way round. - **SRAM sizes that differ** (10): modem and betting carts with their own RAM (*JRA PAT* x 4, *SPAT4-Wide*, *XBAND*), three kiosk demos, and *Joe & Mac (Retro-Bit)* (header 32 KiB, list none). The board follows the header. A game that tests for SRAM mirroring or absence (wiki "Tricky-to-emulate games") would show it in the smoke list. ## Measured coverage **Local No-Intro set** (`$NO_INTRO_DIR/Nintendo - Super Nintendo Entertainment System`, 4,089 zips; `--licensed` skips Beta/Proto/Pirate/Unl/Sample/Demo/Program/Aftermarket: 3,322 images), `scripts/count_carts.py`, measured 2026-10-21 (3 min 58 s, reading every zip in place) [measured]: | Board class / coprocessor | Images | Share | | --- | ---: | ---: | | LoROM | 2,602 | 78.3 % | | HiROM | 719 | 21.6 % | | ExHiROM | 1 | 0.0 % (the heuristic undercounts: open item U6) | | **no coprocessor** | **3,165** | **95.3 %** | | SA-1 | 49 | 1.5 % | | DSP (uPD7725/96050: DSP-1..4) | 35 | 1.1 % | | GSU (Super FX) | 34 | 1.0 % | | Cx4 | 10 | 0.3 % | | S-DD1 | 5 | 0.2 % | | SPC7110 | 4 | 0.1 % | | ST010/ST011 | 3 | 0.1 % | | other (SGB, Satellaview) | 3 | 0.1 % | | OBC1 | 2 | 0.1 % | | S-RTC, ST018 | 1 + 1 | | | chipset byte not decoded | 10 | 0.3 % | These are dumps (regions and revisions count separately). **MAME's software list** (`snes.xml`, 1,913 parent entries, clones excluded), measured 2026-10-21 by its `slot` feature: `lorom` 73.3 %, `hirom` 20.9 %, `lorom_sa1` 34, `hirom_dsp` 13, `lorom_poke` 10 (pirate), `lorom_gsu1` 6 + `lorom_gsu2` 4, `lorom_dsp` 5, `lorom_cx4` 2, `lorom_sdd1` 2, `hirom_spc7110` 2 (+ `hirom_spcrtc` 1), `lorom_obc1`, `hirom_srtc`, `lorom_st010`, `lorom_st011`, `lorom_st018`, `lorom_dsp4`, `lorom_sgb`, `lorom_sgb2` 1 each. Both agree: **plain LoROM/HiROM is 95 % of the library**; every coprocessor is under 2 %. ## Coprocessors, in recommended order | # | Chip | Games | What it is | Where it lives | Judges | | --- | --- | --- | --- | --- | --- | | 1 | **DSP-1** (also 2, 3, 4) | 35 dumps: Pilotwings, Super Mario Kart, ... | NEC uPD7725 running a mask program (and data ROM) | **a uPD7725 core** (`upd7725-python`, new), the board loads Nintendo's program ROM (BYOR, MAME `sns_dsp1*` sets read in place); DSP-2/3/4 and ST010/011 (uPD96050) are the same core with more ROM | the games; the uPD7725 core run with the real program ROM against bsnes/ares's LLE (`processor/upd96050`, `coprocessor/necdsp`) [emu]; no hardware capture known (U7) | | 2 | **SA-1** | 49 dumps: Super Mario RPG, Kirby Super Star, ... | a second 65C816 at 10.74 MHz, with DMA, character conversion, mul/div/sum, timers, BW-RAM, I-RAM | **`65816-python` is its core: the SA-1 is the second consumer of 65816-python** (no extraction needed; the core is already a core). The SA-1's own registers and bus conflicts are cartridge code here | krom has no SA-1 tests; SnesSpeedTest measures SA-1 speed [probe]; games | | 3 | **Super FX (GSU-1/2)** | 34 dumps: Star Fox, Yoshi's Island, Doom | a 16-bit RISC CPU with a pixel cache and plot circuit | **a future core** (`gsu-python`), first consumer is this board; extract on the second consumer only if one appears (none known) | **krom's 116 GSU ROMs** (per-opcode `GSUTest/*` with PASS/FAIL, plus plot/fill demos) [hc-ish, see validation.md]; MAME scored 0 of the GSU pictures exact (measured) | | 4 | **Cx4** | 10 dumps: Mega Man X2/X3 | Hitachi HG51B169 DSP + mask ROM | a future core (`hg51b-python`) | the games' **built-in Cx4 test** (Mega Man X2/X3, controller 2 B at boot; TASVideos "SNES accuracy tests") [hw-designed self-test] | | 5 | **S-DD1** | 5: Star Ocean, Street Fighter Alpha 2 | decompression on DMA | cartridge code | the game | | 6 | **SPC7110** (+RTC) | 4: Far East of Eden Zero, Momotarou Dentetsu Happy | decompression, data port, mul/div, Epson RTC | cartridge code | the games' **built-in "SPC7110 Check Program"** (TASVideos page) [hw-designed self-test] | | 7 | **OBC1**, **S-RTC** | 2 + 1 | OAM helper; Sharp RTC (Daikaijuu Monogatari II) | cartridge code | the games | | 8 | **ST010/ST011** (uPD96050), **ST018** (ARMv3 + ROM) | 3 + 1 | Japanese shogi/racing | uPD96050 core (as DSP); ST018 needs an ARM core (`arm-python`, shared with any future GBA board: extract on that second consumer) | the games | | 9 | **MSU-1** | homebrew / hacks | streaming data + PCM audio from files beside the ROM (byuu's spec) | cartridge code | krom's `MSU/` demos (excluded from the sparse pin; add when needed); ares 9408cb4 (ISC) `sfc/coprocessor/msu1` [emu] | | 10 | **Super Game Boy** (SGB, SGB2) | 2 | a whole Game Boy (SGB-CPU = SM83 SoC) on the cartridge, its LCD output read by the SNES, commands through P1 | **embeds `gameboy-python`** (which embeds `sm83-python`), which deferred SGB to this board (gameboy-python `docs/start-here.md` "SGB, SGB2 ... later, on a SNES board"); the SGB's ICD2 interface chip is cartridge code here | Mooneye's S-group tests (SGB, SGB2 rows) run on gameboy-python with an SGB machine row; Pan Docs `SGB_*.md` [doc]; SameBoy's `Core/sgb.c` [emu] | | later | Satellaview (BS-X), Sufami Turbo, Nintendo Power, Event/Campus Challenge carts | | | cartridge code | | **Recommendation**: milestone 4 does plain LoROM/HiROM/ExHiROM/SRAM (95 %), then **DSP-1** (a small, well-documented core; the commonest coprocessor in famous games), then **SA-1** (the most dumps, and it costs no new core). The Super FX and Cx4 are their own core projects, each with a Phase 0. The Super Game Boy comes after a stable PPU and APU (milestone 7), because it exercises the cartridge audio path and mid-frame VRAM transfers. ## Save data Battery SRAM (header SRAM size byte: 2^n KiB), SA-1 BW-RAM, Super FX backup RAM, S-RTC/SPC7110 RTC state; written by the frontend to a `.srm` beside the ROM (raw SRAM, the common format: `wiki/Save file formats`), never committed (`.gitignore` has `*.srm`, `*.sav`). Built for the plain boards (2026-11-23): `Cartridge.battery()` returns the SRAM when the chipset byte says it has a battery (`$xxD6` low nibble 2, 5 or 6: wiki "ROM header"), else None; `Cartridge.load_battery(data)` loads a `.srm` (a file of another size is taken as far as both reach). With no save loaded the SRAM reads zeros (HYPOTHESIS; MAME reads `$FF`). The frontend that writes the file beside the ROM is milestone 8. ## BYOR No cartridge ROM, coprocessor program ROM or IPL ROM is ever committed or fetched. The board reads them from paths the user gives (`--rom`, `--ipl`, `--coprocessor-rom DIR`), with defaults from the environment: `NO_INTRO_DIR` (zips read in place) and `MAME_ROMPATH` for `snes.zip` (IPL) and `sns_dsp1*.zip` etc. (coprocessor programs), each checked by SHA-1 against MAME's ROM tables.