# Cartridges, formats and the loader's one front door Measured 2026-11-11 by `scripts/count_carts.py` (output committed as `tests/detectors/census-2026-11-11.txt`). Citations: **Spec §9** = "ROM Cart" in the Epyx specification; **HandyROM** = `reference/src/handy-docs/docs/handyrom-specification.md`. ## The hardware - **Addressing** (Spec §9.1): an 8-bit shift register (the *page*) and an 11-bit counter (the offset in the page). A cart is wired so that its top 8 address bits come from the shift register and the rest from the low bits of the counter: a 64 KiB cart uses 8 counter bits, 128 KiB 9, 256 KiB 10, 512 KiB 11. So a cart is **256 pages of 256, 512, 1024 or 2048 bytes**. HandyROM states the same from the tool side: "256 pages ... bytes per page is derived by dividing ROM size by 256". - **Loading the page**: CartAddressData (IODAT bit 1) is the shift register's data input; CartAddressStrobe (SYSCTL1 bit 0) clocks it, and while the strobe is high the counter is held at 0 (Appx 2, `$FD87`, `$FD8B`). Software shifts 8 bits MSB first, then reads. - **Reading** (Spec §9.2): two chip enables, CART0 and CART1, driven by Suzy on a read of RCART0 (`$FCB2`) / RCART1 (`$FCB3`). The trailing edge of either strobe increments the one shared counter. The read costs the CPU 15 ticks. The cart's data lines are Suzy's switch lines. - **Two strobes** give 2 x 512 KiB. Bank 1 (CART1) is unused by every licensed dump here (22 of 22 LNX headers say bank 1 = 0). - **Writes** (Spec §9.3): the cart can be written with the same addressing; a blind 562.5 ns strobe. Used by flash/SRAM carts. - **Power** (Spec §9.4): CartAddressData low also switches the cart's power pin on. - **AUDIN** (IODAT bit 4, Spec §12.8): an input from the cart connector that software can also drive as an output. Large homebrew wires it as a 20th address line, selecting one of two 512 KiB halves on the same strobe ("AUDIN bank switching": 1 MiB per strobe). MAME's software list (CC0 data) marks one title with `audin_offset` (Alpine Games). - **EEPROM** (homebrew and some late titles): a 93C46/56/66/76/86 serial EEPROM (1, 2, 4, 8, 16 kbit) on the cart, clocked through the cart address counter lines with data out on AUDIN. The wiring is a community convention, not an Atari document (U8). Permitted sources for it: the cc65 Lynx EEPROM driver (zlib; the program a cart runs, so it shows the wiring from the software side) and the 93Cxx data sheets. (Two emulators' EEPROM files cited here earlier were struck.) ## The boot path The 512-byte ROM in Mikey reads the cart's first bytes, decrypts them and runs the result (Spec §4.2). The first byte of an encrypted frame is `256 - n` for `n` blocks of 51 bytes; each block is one modular exponentiation with public exponent 3 against a fixed 51-byte modulus, the output accumulated into RAM at `$0200` (`reference/src/hamlet`, MIT; `lynx-encryption-tools` has no licence and is no longer fetched). The decrypted stage then loads a title picture and the game through the cart directory (`reference/src/handy-docs/docs/cartridge-boot.md`). **Every cart needs the boot ROM on a console.** "Needs no boot ROM" is a property of an *emulator path*, and there are three: | Path | What it does | Who uses it | | --- | --- | --- | | Real ROM | runs `lynxboot.img` (BYO, SHA-1 `e4ed47fa...`) | MAME (`-bios a`), Holani when `lynxboot.img` is given (observed) | | Host decryption | the loader does the modular arithmetic itself, then starts the CPU at `$0200` | Felix (MIT; its "bootrom HLE" option) | | Free replacement ROM | 512 bytes by Björn Spruck said to recognise known loader frames instead of decrypting | Holani without a ROM (observed: a different picture); licence not found: U9; not used | Measured over our 421 distinct payloads: the first byte is `$FF` on 193, `$FD` on 134, `$FB` on 93 (1, 3 and 5 blocks), `$38` on one (Xump, which is a trimmed image). There are **128 distinct encrypted frames**. Two cover 196 payloads (`e4c1d84609b9`, 111 payloads; `b130f3bbf57b`, 85); six frames cover 289 payloads, almost all aftermarket: the homebrew toolchains reuse a few standard loaders. The 127 licensed dumps mostly carry one frame each. Host decryption therefore covers everything; frame recognition covers the homebrew majority only. ## Formats | Format | Recognised by | Contents | | --- | --- | --- | | `.lnx` | bytes 0-3 = `LYNX` | 64-byte header + payload | | `.lyx` | none of the others | payload only (what No-Intro hashes; its DAT names a header skipper `No-Intro_LNX.xml`) | | BLL `.o` (also `.bll`, some `.com`) | bytes 0-1 = `$80 $08`, bytes 6-9 = `BS93` | a RAM image: big-endian load address (2-3) and length including the 10-byte header (4-5). Not a cart: it is loaded into RAM and jumped to | | `.zip` / `.7z` | container | one of the above inside | No other variant was found locally: all 840 cart images are `LYNX`-headed or raw, and the three "BLL" files are `BS93`. (Notes on two emulators' handling of `.com` were struck.) EPYX development `.rom` files are raw payloads. ### The LNX header (64 bytes) | Offset | Size | Field | | ---: | ---: | --- | | 0 | 4 | `LYNX` | | 4 | 2 | bank 0 block size (little-endian): 256, 512, 1024, 2048 | | 6 | 2 | bank 1 block size (0 = none) | | 8 | 2 | version (1) | | 10 | 32 | cart name, NUL-padded | | 42 | 16 | manufacturer, NUL-padded | | 58 | 1 | rotation: 0 none, 1 left, 2 right | | 59 | 1 | AUDIN used: bit 0 | | 60 | 1 | EEPROM: bits 0-2 type (1 = 93C46 ... 5 = 93C86), `$40` 8-bit organisation, `$80` save on SD card instead | | 61 | 3 | spare | Offsets 0-58 were defined by Handy's author (K. Wilkins); the layout is re-sourced to our own 22 headers (magic, block sizes, version 1, NUL-padded name and manufacturer, rotation byte, all observed) and to cc65's `exehdr.s` (zlib, a toolchain that writes the header; permitted under restart rule 4). Bytes 59 and 60 are a later community extension (Karri Kaksonen / LX.NET, cc65's `exehdr.s` and the Atari Gamer header tool). The header is not an Atari format and has no checksum. The EEPROM size formula in cc65's source carries its own "please recheck" note (C13). ### One front door `cart.loader.load(path_or_bytes) -> CartDescription`. Steps, each a small pure function: 1. **Unwrap** `.zip` / `.7z` (one cart member; ignore other files). 2. **Sniff** by content, never by extension: `LYNX` → LNX; `BS93` → BLL; else raw. 3. **Strip** the header; keep it as *claims*. 4. **Hash the payload** (SHA-1; also CRC-32 for display). An `.lnx` and its `.lyx` now have the same key. 5. **Look the key up** in the board's cart table (`cart/table.json`, built from data: see below). 6. **Resolve each field** by the precedence in "Which source wins". 7. Return one description: ``` CartDescription: payload bytes (bank 0, then bank 1 if any) sha1, crc32 bank0_block, bank1_block 256/512/1024/2048 or 0 audin bool (20th address line) rotation none / left / right eeprom none or (type, 8-or-16-bit organisation) boot "encrypted" (frame at offset 0) / "ram" (BLL) name table name, else header name, else file name provenance per field: table / header / size-rule / default / user ``` `needs-boot-ROM` is not a cart property (above); the description says `boot = encrypted` and the machine decides between the real ROM and host decryption. A BLL image is booted the BLL kit's way (2026-11-19, `lynx_python.cart.bll`): the kit's cart loader (`uloader/bll.enc`, Apache-2.0, vendored as `src/lynx_python/cart/bll_loader.enc`), then the whole BLL file, then `$FF` to 256 KiB with 1024-byte blocks, exactly as the kit's `uloader/Makefile` builds a cart from a `.o`. The real boot ROM decrypts the loader, which copies the program to its load address and jumps there, so no hand-over state is invented. (The earlier plan, "reset the machine as the boot ROM would leave it, copy the image, start at its load address", would have needed that state; it was not taken.) ### Headerless dumps: where each field comes from | Field | Source | Certainty | | --- | --- | --- | | block size | **size rule**: payload of exactly 64/128/256/512 KiB → size ÷ 256 | certain *if* the dump is a full 256-page image. 419 of 421 payloads have a rule size | | | hash table | certain where present | | bank 1 | none of ours uses it | default 0 | | AUDIN | hash table; a payload of exactly 1 MiB with a rule-sized half suggests it | table: certain; guess: labelled | | rotation | hash table only; nothing in the image says | unknown without a table entry → default none, provenance "default" | | EEPROM | hash table only | as rotation | **Dumps that break the size rule** (measured): - `Xump - The Final Run (World) (Songbird) (Digital)`: 224,433 bytes (a trimmed image; its first byte `$38` is not a frame count either). - `Mines 2 (World) (Demo) (Unl)` and `Zaku (World) (Beta) (Unl)`: 262,144 bytes but their LNX headers say **2048-byte** blocks, i.e. 128 pages. The size rule says 1024. For Zaku (Beta) MAME's software list also says 1024, so two sources disagree about the same payload (C14). The correct value is whichever lets the loader find its directory; the build session settles it by booting both ways. **Settled 2026-11-19:** booted both ways, Mines 2 plays with 1024 and stays black with 2048 (OBSERVED, MAME 0.285: the same split between its `.lnx` and `.lyx`). The loader now lets the size rule beat a header's block size (read from the file or recorded in the table as `lnx-header`) that gives other than 256 pages of a full-size payload; the header's value stays in `bank0_alternatives`. A curated table entry (softlist) keeps its precedence (Alpine Games: softlist 1024 on 512 KiB, unchanged). Of the local images only Mines 2 changes. Its LNX -> LYX -> LNX round trip now writes 1024 in the rebuilt header, so it is no longer byte-identical. - The `[BIOS]` entry (512 bytes) is the boot ROM, not a cart; the loader refuses it as a cart and accepts it as a boot ROM by hash. - Homebrew that uses fewer than 256 pages (the lynx-tests ROMs themselves: build-progress.md) is the general case of the same break. ### The table: seeded from data, never from ported detection code | Source | Licence | Gives | Covers (of 421 distinct local payloads) | | --- | --- | --- | --- | | No-Intro DAT "Atari - Atari Lynx (LYX)" 20241112 | facts (names, sizes, hashes); No-Intro publishes DATs freely, no formal licence | name only | 392 | | MAME `hash/lynx.xml` | **CC0-1.0** (stated in the file's header) | block size (`granularity`, 119 entries), rotation (7), AUDIN (1) | 116 | | LNX headers of our own files with the same payload | our observation of files we hold | block sizes, rotation, AUDIN, EEPROM | 22 | | Tables inside emulators (Holani, Gearlynx, Handy) | GPL-3 / GPL-3 / zlib-with-libretro additions | | **not used and not read** (restart rules; open decision 4) | Result: **129 of 421** headerless payloads get every field from a table; **290** get block size from the size rule and nothing certain for rotation, EEPROM or AUDIN; **2** not even that. The 290 are almost entirely the aftermarket set (282 files), where rotation and EEPROM matter most. Our 22 LNX headers all say rotation none, no AUDIN, no EEPROM, so they add no positive entry. Where the sources overlap (9 payloads have both a softlist entry and a local header) they disagree twice: Zaku (Beta) block size (above) and `Raiden (USA) (Beta)`: softlist rotation LEFT, header none. Raiden is a vertical game; the header is wrong. The honest position: for commercial titles the softlist is enough (rotation is needed by 7 of them). For aftermarket titles there is **no free table**; the fields come from an `.lnx` header when the user has one, and otherwise from defaults plus a user override (`--rotation`, `--eeprom`, `--block`), which the board records in a local overrides file keyed by payload SHA-1. ### LNX against LYX, measured All 22 `.lnx` images we hold (17 in No-Intro "LNX", 5 in `source/extra/lynx (headered)`; the retrobat set is 317 headerless `.lyx` in 7z, and 80 of the 85 files in the "headered" folder are in fact raw) were stripped and hashed: **22 of 22 payloads match a No-Intro LYX entry** and a local `.lyx`. No misses, so no miss reasons to report from this library; the miss classes the loader must still expect from files in the wild are padding to a rule size, trimming (Xump), a wrong block size in the header (128 pages of 2048), and homebrew absent from No-Intro. ### Which source wins For a field where the header and the table disagree, the recommendation is **table > header > size rule > default**, with the user override above all, and a logged warning naming both values. Reason: both measured disagreements have a wrong or doubtful header, and headers are hand-written. This is open decision 3 in the brief, because one of the two cases (Zaku Beta) has the table as the doubtful side. One exception for block size (2026-11-19, above under "Dumps that break the size rule"): a header-sourced block size that contradicts the size rule on a full-size payload ranks below the size rule. ### Writing the other format Recommended: a small tool, `python -m lynx_python.cart convert IN OUT`, not a board feature. LNX → LYX is stripping 64 bytes. LYX → LNX writes a header from the resolved description and **refuses when a field's provenance is "default"** unless the user supplies it, so the tool never manufactures a wrong header. It never writes next to the source ROM unless asked for a path there. Open decision 5. ## Census 840 cart images in seven folders, 421 distinct payloads, 3 BLL programs. | Set | Images | | --- | --- | | No-Intro LNX | 17 lnx | | No-Intro LYX | 127 lyx (126 carts + the BIOS) | | No-Intro LYX (Aftermarket) | 282 lyx | | No-Intro LYX (Private) | 12 lyx | | No-Intro BLL | 3 BLL | | roms-retrobat/lynx | 317 lyx in 7z | | source/extra/lynx (headered) | 5 lnx, 80 lyx | | Payload size | Distinct payloads | Block size by rule | | ---: | ---: | --- | | 131,072 | 47 | 512 | | 262,144 | 334 | 1024 | | 524,288 | 38 | 2048 | | 224,433 | 1 | none (Xump) | | 512 | 1 | the boot ROM | No 64 KiB and no 1 MiB payload is present. LNX headers (22): bank 0 block 512 x 5, 1024 x 13, 2048 x 4; bank 1 always 0; rotation, AUDIN and EEPROM bytes always 0. Software list: 119 entries, 7 with rotation (4 LEFT, 3 RIGHT), 1 with AUDIN. Boot ROM: `lynxboot.img`, 512 bytes, SHA-1 `e4ed47fae31693e016b081c6bda48da5b70d7ccb`, SHA-256 `c26a36c1990bcf841155e5a6fea4d2ee1a4d53b3cc772e70f257a962ad43b383`, found as `lynxa.bin` in MAME's `lynx.zip` under `$MAME_ROMPATH` (the board looks it up by hash there; no machine path is kept). MAME's other image `lynx.bin` (SHA-1 `de60f226...`) differs only in the byte at `$FFF9`, which a running machine cannot read back from ROM because MAPCTL answers there (Appx 2); MAME flags both BAD_DUMP (`-listroms`, observed). Whether a Lynx II ROM differs is U10.