# Cartridges, formats and the loader Source keys are in [start-here.md](start-here.md). Census numbers are measured by `scripts/count_carts.py` on 2026-11-11 (`tests/detectors/census-2026-11-11.txt`, one row per dump in the `.tsv`). ## The connector, and why the classes exist The 36-pin cartridge connector carries D0-D7, **A0-A13**, two decoded enables, **"Enable 40-7F"** and **"Enable 80-BF"**, power and two interlock pins that switch the console's power ([FAQ] 4.6 pinout; [AHRM] 13.2 "Power control"). There is no A14, no A15, no R/W and (on the 4-port) no clock. The 2-port board redefines three pins for the 2600 adapter (phi2 out, video in, audio in; [FAQ] 4.8); not modelled. Every stock cartridge class is just which ROM chips hang on which enable: | Class | Chips | $4000-$7FFF | $8000-$BFFF | | --- | --- | --- | --- | | 32K | two 16K ROMs | first 16K | second 16K | | 16K, two chips | two 8K ROMs (A13 unused) | first 8K, twice | second 8K, twice | | 16K, one chip | one 16K ROM | the same 16K again, or nothing (C4) | the 16K | | 8K | one 8K ROM on Enable 80-BF | nothing | the 8K, twice | | 4K | one 4K ROM on Enable 80-BF | nothing | the 4K, four times | A raw dump of a two-chip 16K cartridge and of a one-chip 16K cartridge are both 16,384 bytes with nothing in them to say which they are. The two readings agree at $4000-$5FFF and $A000-$BFFF and differ at $6000-$9FFF. This is "the 16K problem". Start vectors in the local sets agree with the table: every 4K and 8K dump starts at $8000-$BFFF (4K: $9000 and $B000 both occur, so the four-fold repeat is needed; 8K: $8000 occurs, so the two-fold repeat is needed); 32K dumps start anywhere in $4000-$BFFF. ### Bank switching | Scheme | Where | Rule | Source | | --- | --- | --- | --- | | Bounty Bob Strikes Back (40K) | one licensed title | $4000-$4FFF shows one of four 4K banks, chosen by an **access** (read or write: the connector has no R/W) to $4FF6-$4FF9; $5000-$5FFF one of four more, chosen by $5FF6-$5FF9; the last 8K of the image sits at $8000-$9FFF and again at $A000-$BFFF | [A800] `DOC/cart.txt` type 7; [MAME] `bus/a800/bbsb.cpp` | | Bounty Bob, alternative image order | same board | the fixed 8K comes first in the file | [A800] type 159 | | "Super Cart" 64K/128K/256K/512K | homebrew board by Bryan Edewaard, 2005 (M.U.L.E. 64K, Bosconian 128K) | 32K banks over the whole window; a read of $BFD0-$BFDF sets bank bits 0-1 from address bits 2-3, a read of $BFC0-$BFCF sets bits 2-3; a read of $BFE0-$BFFF selects the last bank, which the BIOS's own reads of the trailer do at power-on | [A800] `DOC/cart.txt` types 71-74 (it cites the designer's AtariAge post); [MAME] `a5200_supercart.cpp` | Bounty Bob's power-on banks are not stated in the sources (U9b). What $6000-$7FFF shows on the Bounty Bob board is not stated either; [MAME] marks the title "partial" for GTIA glitches unrelated to the mapper. The local sets hold **no Super Cart image** and nothing larger than 40K (measured). MAME's list has one (`bosco`, unsupported there). ### The trailer Read by the BIOS from the top of the window ([DANB] `5200BIOS.txt`; bytes checked in both ROMs): | Address | Use | | --- | --- | | $BFE7 | revision A BIOS only, and only when GTIA reports PAL: must be $15, $30, or have bit 1 set, or the BIOS hangs (C1) | | $BFE8-$BFFB | 20 title characters (screen codes) copied to the logo screen | | $BFFC, $BFFD | two "year" characters. **$BFFD = $FF: skip the logo and jump through $BFFE at once** | | $BFFE, $BFFF | start vector | ## Census Read in place; nothing extracted. | | No-Intro `Atari - Atari 5200` (`$NO_INTRO_DIR`) | "retrobat", a front-end copy (now `$A5200_EXTRA_DIRS`, optional) | | --- | --- | --- | | Archives | 183 zip (one is the BIOS) | 104 7z at the top level (+ `gamelist.xml`, `media`, and `Best Games` (28), `By Genre`, `Other`: hard links to the same files) | | Cartridge images | 182 | 104, **all also in the No-Intro set** (by SHA-1) | | Extension inside | `.a52` | `.a52` | | `.car` files | 0 | 0 | | 4K / 8K / 16K / 32K / 40K | 4 / 27 / 101 / 49 / 1 | 4 / 20 / 61 / 18 / 1 | | Prototypes, betas, demos, unlicensed, alt | 58 Proto, 34 Beta, 6 Demo, 3 Unl, 5 Alt, 1 Rev | 26, 1, 4, 3, 0, 1 | | Trailer $BFFD = $FF (no logo) | 50 of 181 | 41 of 103 | | In MAME 0.285 `a5200.xml` (by SHA-1) | 103 (65 `a5200_rom`, 37 `a5200_2chips`, 1 `a5200_bbsb`) | 86 (55, 30, 1) | | BIOS present | 4-port CO19156 only | none | Both BIOS revisions are in the MAME set under `$MAME_ROMPATH` (merged: `a5200.zip` holds `co19156.u8` and `a5200a/co19156a.a8`; non-merged: `a5200a.zip` holds revision A), found by SHA-1. There is no PAL dump (there was no PAL console); one prototype is tagged `(Europe)` (Missile Command, 1982-04-04, 8K). Atari's own diagnostics are in the No-Intro set: `Atari PAM Diagnostics` v1.1 (8K), v2.0 and v2.3 (16K), `Atari PAM System Test` v1.02 and `Atari PAM - Pete's Test` (8K). ### The 16K question, measured 101 of the 182 No-Intro images are 16K. Who can say which reading is right: | Source of the answer | No-Intro (182) | retrobat (104) | | --- | --- | --- | | Size alone settles the class (4K, 8K, 32K) | 80 | 42 | | 40K, Bounty Bob, SHA-1 in MAME's `a5200.xml` | 1 | 1 | | 16K, SHA-1 in MAME's `a5200.xml` | 60 | 49 | | 16K, CRC-32 in MAME's `a5200.hsi` only | 2 | 1 | | 16K, both halves identical (reading does not matter) | 0 | 0 | | **16K with no public answer** | **39** | **11** | So public data gives the mirroring class with certainty for **143 of 182** No-Intro images (79 %) and **93 of 104** retrobat images (89 %). All 39 unknowns are prototypes, betas, demos or alternates except `Gyruss (USA) (Rev 1)`; the list is in the `.tsv` (class `16k-?`). For those, `count_carts.py` has a static walk of its own (described in the script: follow the program from the start vector under both readings; the wrong reading soon runs into data). Against the 60 16K images whose class MAME's list states, the walk agrees on 48, says "either" on 12 and **contradicts none**. (A first version that compared fault counts instead of reach was wrong on 9; kept as a warning in the script.) On the 39 unknowns it says two-chip 25, one-chip 12, either 2 (two Millipede prototypes). **Measured 2026-11-12** by booting each under both readings: 26 two-chip, 13 one-chip; the walk agreed on 36, abstained on the 2 Millipede prototypes (one chip) and was wrong once (RealSports Soccer (Beta) 1982-08-26: walk one chip, boots only as two). The 39 now load from observed-boot rows. `a5200.xml` and `a5200.hsi` disagree on nothing definite: the three 16K images where they differ are ones the `.hsi` itself marks with a question mark or leaves blank (`Star Wars - The Arcade Game`, `Atari PAM Diagnostics v2.0`: "A13MIRRORING?"; `Stargate (Proto 3)`: no flag, list says two chips). How emulators decide (none of their code is used; how each row was learned is given in it, see also [provenance.md](provenance.md) "Wave 2"): | Emulator | Rule | | --- | --- | | MAME 0.285 | software-list items carry the slot. A loose file: a `.car` header if `length % 4096 == 16`, else by size, with 16K one-chip unless `a5200.hsi` flags the CRC `A13MIRRORING` (read from `bus/a800/a800_slot.cpp`, a BSD-3-Clause file, copyright Fabio Priuli and Angelo Salese: see NOTICE). **Run with `-noreadconfig` and no `-hashpath`, the hash file is not found and every loose 16K image is mapped one-chip** (measured: Pac-Man black screen) | | Atari800 | a raw 16K image has no type: the UI asks, and the library reports "unidentified cartridge type"; `.car` files carry it. HYPOTHESIS as a statement about Atari800: Phase 0 read this from its GPL source (2026-11-11), which the charter no longer allows as a source; it has not been re-established by a closed-box run (every run here passes `-cart-type`, so nothing depends on it) | | Altirra 4.40 | **not established here.** Phase 0 (2026-11-11) recorded one fact about Altirra's detection, read from its GPL source (the archive was in the ignored `reference/`, never committed, not opened since, and moved out unopened on 2026-11-24); no document states it and Altirra cannot be run here (Windows only, no Wine: U12), so the fact is withdrawn (wave 2, 2026-11-13). Nothing in this repository depends on it. The walk here (`cartridge/walk.py`, `count_carts.py`) is this repository's own algorithm: it follows documented opcodes, branches, JSR and JMP from the start vector under each reading and compares how far each gets (reach), with no scores; its opcode-length table is from the 6502's documented instruction set. It is judged by its results, not by any emulator: it contradicts none of the 60 16K images MAME's CC0 list classifies, and was wrong once against the 39 observed boots (above). A provenance audit (2026-11-12) found the walk independent | ## Formats and the loader's front door Requirement: the board loads every form people actually have. One function, `load_cartridge(path_or_bytes) -> Cart`, is the only way in; everything downstream sees the same description. ### What arrives | Form | Recognised by | Handling | | --- | --- | --- | | Raw dump (`.a52`, `.bin`, `.rom`, any name) | length is 4,096 x n and the bytes do not start with `CART` + a plausible header | payload = the file | | Atari800 CART (`.car`) | bytes 0-3 = `CART`; length - 16 is a multiple of 4,096 | strip 16 bytes; bytes 4-7 = type (big-endian), bytes 8-11 = sum of the payload bytes (big-endian), bytes 12-15 zero. A wrong checksum is reported, not fatal | | Either, inside `.zip` | standard library `zipfile` | exactly one candidate member, else the caller names it | | Either, inside `.7z` | no pure-Python reader in the standard library: optional `py7zr` if installed, else the `7z` program through a pipe, else a clear error saying which is missing | same | Detection is by content, never by extension. Nothing is ever written next to the source. 5200 type numbers in the CART header ([A800] `DOC/cart.txt`; the numbering is Atari800's and is a fact about the format): | Type | Meaning | Size | | --- | --- | --- | | 4 | standard 32K | 32K | | 6 | two-chip 16K | 16K | | 7 | Bounty Bob Strikes Back | 40K | | 16 | one-chip 16K | 16K | | 19 | standard 8K | 8K | | 20 | standard 4K | 4K | | 71, 72, 73, 74 | Super Cart, 32K banks | 64K, 128K, 256K, 512K | | 159 | Bounty Bob, alternative image order | 40K | Any other type number is an 8-bit-computer cartridge: refused with that message. ### The one internal description ``` Cart: payload bytes, header stripped, in canonical order (type 159 is reordered to type 7's order so both hash alike) size len(payload) sha1, crc32 of the payload mapping "4k" | "8k" | "16k-one" | "16k-two" | "32k" | "bbsb" | "supercart" mapping_from "size" | "car-header" | "table" | "caller" | "guess" controllers set of {"stick", "keypad", "trakball"}; ports used (1-4) bios_notes e.g. "calls 4-port BIOS addresses" title from the table, else the trailer's 20 characters ``` ### Identification: by payload hash, from public data The key is the **SHA-1 of the payload**, so a `.car` and the matching raw dump are the same entry. Order of authority for `mapping`: 1. the caller's explicit choice; 2. the size, where it settles the class (4K, 8K, 32K; 40K = Bounty Bob; 64K-512K = Super Cart); 3. this repository's table, `a5200_python/cartridge/table.json`, keyed by payload SHA-1: the CC0 seed rows, and for 16K the observed-boot rows measured here (see "Measured rows" below for how the two rank); 4. a CART header's type; 5. for a 16K image none of these knows: see "Unknown 16K" below. A header that contradicts the table is reported; the table wins (headers are hand-made and wrong ones circulate). Seeds for the table, all checked for licence: | Seed | Licence | Gives | Entries | | --- | --- | --- | --- | | MAME `hash/a5200.xml` | **CC0-1.0** (file header) | SHA-1, CRC-32, size, slot (one-chip/two-chip/bbsb/supercart), title, year, publisher, per-title emulation notes | 112 | | MAME `hash/a5200.hsi` | **CC0-1.0** (file header; "based on a generated one from Cowering's Good databases") | CRC-32 only, `A13MIRRORING` and size hints, GoodTools-style names | 222 | | No-Intro DAT | names and hashes are facts; the DAT's own terms are not stated in the file names we hold and the DAT was not fetched | names; **no mapping information** | - | | CART headers found in the wild | type bytes are facts | a mapping per payload | none held locally | | [FAQ] 2.7 | prose list | trak-ball titles (12) | - | | milestone 6 runs (measured here); [AHRM] F.2 for the mechanism | own; document | the three titles that depend on the 4-port BIOS | 3 | | this repository's walk | ours | a labelled guess for 16K | - | The table is built by a script from the two CC0 files plus hand-entered rows for controllers and BIOS notes, each row carrying its `source`. No emulator's detection code is ported: Altirra's and MAME's are GPL. **Coverage, measured** (payload = file for every local dump, since there are no `.car` files): mapping certain for 143/182 and 93/104 as above. Title: every dump (trailer or table). Controllers: no public table states them per dump; the default is "stick + keypad on port 1", with `trakball` added for the 12 [FAQ] titles as "supported", and nothing is known with certainty about ports 3-4 beyond Super Breakout (U4). So **every field with certainty: 0 dumps if controller needs are held to that standard; mapping, size, title and hashes: 143 and 93.** Milestone 5 measures port and keypad use by running each dump (which CONSOL port values it writes, which POT/TRIG registers it reads) and adds the result to the table as "measured here". ### Unknown 16K Options when a 16K payload is in no table and has no header: - (a) refuse, and ask for `--mapping one|two`; - (b) load with the walk's answer, `mapping_from = "guess"`, say so loudly once, and refuse only when the walk says "either"; - (c) always assume two-chip (the commoner class: 37 of the 60 listed) or one-chip (MAME's fallback). Recommended: **(b)**. The walk has contradicted the public list on none of 60 known images (it abstained on 12), the 39 unknown local dumps are exactly the prototypes people want to try, and a wrong guess shows up at once as a crash or a blank screen. The guess is never written into the table; a dump enters the table only when a run confirms it (reaches its title screen under one reading and not the other), marked "measured here". This is open decision 3. ### Measured rows (observed boot) `table.json` has a `measured` section, keyed by payload SHA-1, entered by hand from `scripts/observed_boot.py` runs (which boot a 16K dump under both readings and keep the two pictures side by side) and kept by `scripts/build_cart_table.py` when the CC0 seed is rebuilt. Each row says `kind: "observed-boot"`, the `reading` that reached a sensible picture (`16k-one`, `16k-two`, or `both` / `neither`), what the other reading did, the frame, and the PNG as `evidence` (in the ignored run directory: rerun the script to see it again). Only a row whose `reading` is a single class carries a `mapping`. These rows are detector-level evidence about the dump (the board's own run), labelled as such. How the loader ranks them (decided policy, applied as the brief states it): - **The CC0 seed is silent** (no `a5200.xml` row, no definite `.hsi` flag): a single-reading measured row decides, `mapping_from = "measured"`; a `both` / `neither` row leaves the walk's guess (decision 3) and says so. - **The seed agrees**: the seed row stands (`mapping_from = "table"`); the agreement is noted. - **The seed contradicts a measured row**: the measured row wins, and the loader reports the conflict in `Cart.notes` ("CONFLICT: ..."). The reason is the brief's, not a new rule: the brief makes open decision 3's confirmation ("reaches its title screen under one reading and not the other") the way a 16K class enters the table "measured here", and "oracle tiers are not negotiable": MAME's list is a detector's data (tier 5), never a judge. The one case so far is PAM Diagnostics v2.0, which MAME's list gives as two chips (its `.hsi` row says "A13MIRRORING?", MAME marks the item unsupported and crashes on it, Atari800 garbles the same title line under two chips) and which shows its title only as one chip. ## The cartridge port protocol The cartridge object sees every bus cycle that asserts one of its enables, with no read/write distinction for bank selection (the connector has no R/W; a write to a hotspot address switches too, and a write to ROM is otherwise ignored): ``` access(address) -> None every cycle with the address in $4000-$BFFF read(address) -> int | None None = nothing drives the bus (8K at $4000-$7FFF) ``` ANTIC's DMA reads go through the same port (ANTIC reads cartridge ROM directly for display lists, character sets and P/M data; whether an ANTIC read of a Bounty Bob hotspot switches banks follows from the wiring: it must, since the cartridge cannot tell who drives the address). A test forbids `cartridge/` from importing the board.