# Handoff: build `lynx-python`, the Atari Lynx board > **Restart (2026-11-14).** This brief stands under [restart.md](restart.md), > whose rules win where they differ: no GPL, LGPL or unlicensed source is read > (MAME, Holani and Gearlynx are run as closed boxes only); every rule in the > code names its evidence. The CPU core is now `w65c02-python` (package > `w65c02_python`). The scrub that made this brief and its companions fit the > rules is recorded in [provenance.md](provenance.md). ## Context you are inheriting The family's shape is **chips are cores, boards compose cores**. Python repos are the readable reference (correct, not fast). Each board is validated against hardware-tier evidence, with emulators as detectors only. `a2600-python` and `pcengine-python` are the boards to model this one on; `famicom-python`'s `board.py` shows one bus callback per CPU cycle with DMA inside the callback. The Lynx is two custom chips sharing one bus on a 16 MHz tick. Three things make it unlike the other boards: - **A CPU cycle has no fixed length** (4, 5 or more ticks), and the CPU stops entirely while the sprite engine owns the bus. - **There is no die-level judge** and no console here. The judges are the manufacturer's specification, one author's logic-analyser captures of a Lynx II, and **drhelius' Lynx Hardware Tests** (127 cases whose expected values were taken on consoles; 122 usable by one machine). Build to those. - **The cart format problem**: every user has `.lnx` or `.lyx`, rarely both, and a headerless dump does not say its rotation or EEPROM. The loader is a milestone of its own. Read, in order, before writing code: 1. `README.md`. 2. `docs/start-here.md`: the machine, memory map, the CPU cell, Suzy's bus handshake, the interface request to `w65c02-python`, module shape. 3. `docs/timing.md`: tick costs, page mode, bus ownership, timers, display, sprite engine evidence, math, UART, audio. 4. `docs/cartridge.md`: hardware, boot path, formats, the one front door, the table and its sources, the census. 5. `docs/undocumented-behavior.md`: the documented defects, C1-C16, the known-hard table, U1-U16. 6. `docs/validation.md`: every oracle with tier, pin, licence; detector runs. 7. `docs/mame-oracle.md`: recipe, traps, what MAME cannot tell you. 8. The Epyx specification in full (`reference/docs/epyx-html/`, start at `lynxdoc.html`; `hardware.html` is the register appendix), then `reference/src/lynx-tests/*.md` (four guides) and its `README.md`. 9. `w65c02-python`'s README and `docs/handoff-brief.md` ("The bus contract", "The contract as built"). Then `python scripts/fetch_references.py` (or `--verify`). ## Decisions already made (defaults; see "Open decisions") - Name `lynx-python`, package `lynx_python` (confirmed). Python floor 3.11, CPython and PyPy. Dependency-free apart from its CPU core, pinned by git commit; the frontend is an optional extra. - **Mikey and Suzy stay in this repository** (Lynx-only chips), as modules that do not import the board. The CPU is `w65c02-python`. - **Two machine rows from the start**: `lynx1` and `lynx2`, differing in data only (CPU variant C1, MAPCTL readback C3, stereo C8). - **One tick timeline.** No per-instruction time accounting. - The boot ROM is bring-your-own by hash; the no-ROM path is host decryption. No replacement ROM is shipped. - The cart table is built from data (MAME's CC0 software list, the No-Intro DAT, our own headers). No GPL table, no ported detection code. - ComLynx between consoles is out of the first build; the UART with its own echo is in. ## What this board needs from sibling repositories **From `w65c02-python`** (a request, answered by its bus contract; this repository changes nothing there): 1. A bus callback for **every** cycle in chip order, dummy cycles included, that distinguishes instruction-byte fetches (opcode and operands) from data accesses. 2. No time inside the core: the board charges ticks in the callback. 3. The CPU must tolerate the callback taking arbitrarily long in machine time (Suzy runs to a wake condition inside the CPUSLEEP write). 4. Variant rows: Lynx I (65SC02: `$x7`/`$xF` are NOPs with the lengths lynx-tests `cpu` test 7 expects) and Lynx II (RMB/SMB/BBR/BBS). WAI/STP switchable, default off. 5. Level-sensitive IRQ; CMOS interrupt and decimal behaviour as lynx-tests `cpu` tests 1-6 and 8 check them. 6. That core's own ladder should include running lynx-tests `cpu.lnx` on this board as its board-level rung once milestone 2 here passes. Nothing is needed from `6502-python`, `pokey-python`, `a5200-python` or `a7800-python`. ## Your task Build `src/lynx_python/` (shape in start-here.md). Requirements: - **Machines as data**; power-on values with their source. - **The bus**: ownership (video, refresh, CPU, Suzy), MAPCTL overlays for the CPU only, the open "last value" behaviour where the spec gives none recorded as an unknown rather than invented. - **Tooling at the family bar**: whole-machine state including cart and EEPROM; debugger with Mikey/Suzy register names and tick position; JSONL trace (instruction lines in the core's schema plus bus-ownership events with tick stamps); `python -m lynx_python CART --frames N --png out.png --wav out.wav`; a **test-ROM harness** that runs a lynx-tests ROM to its result screen and prints the result bytes next to the expected table. ### Milestones, each with its exit criterion and judge **M0. The loader front door** ([cartridge.md](cartridge.md)). `.lnx`, `.lyx`, BLL, each loose or in `.zip`/`.7z`, normalised to one `CartDescription` with per-field provenance; `cart/table.json` generated by a script from the software list, the DAT and local headers; the converter tool. *Exit*: all 840 local images load without error, read in place; every `.lnx` and its `.lyx` resolve to the same SHA-1 and the same description (22 of 22 today); the census numbers reproduce (129 fully tabled, 290 size-rule only, 2 neither); the two block-size conflicts (C14) are reported, not hidden; round-trip LNX → LYX → LNX is byte-identical for the 20 headers that agree with the table. *Judge*: the data sources themselves (tier 5 data, tier 2 for the size rule via HandyROM). **M1. CPU on the bus through the boot ROM.** RAM, overlays, boot ROM, the cart port (shift register, counter, RCART0), enough Mikey/Suzy registers to boot, host decryption as the second path. *Exit*: instruction-level lockstep with MAME's trace (PC, A, X, Y, P under `$CF`, S) from `$FF80` through the decrypt into the cart's stage-2 loader on five titles, N instructions stated, first divergence explained as time-dependent; the host-decryption path reaches the same RAM contents at `$0200` as the real ROM for all 128 distinct frames in the library; seed a fault (wrong counter increment edge) and show the gate fails. *Judge*: MAME (tier 5 detector) for flow; the spec (tier 2) for the port. **M2. Tick costs, timers, interrupts, sleep.** 4/5-tick cycles and page mode, register waits, the shared prescaler, eight timers with links, DONE defects, the interrupt controller, CPUSLEEP/SDONEACK with a stub Suzy that is "busy" for a programmed time, the math unit. *Exit*: lynx-tests `cpu` (for the row in use), `page-mode` (6), `memio` (3), `timers` (7), `timers2` (10), `math` (8) and `sdoneack` (10) show their expected result bytes on both machine rows, every miss listed with its bytes; C5 demonstrated. *Judge*: lynx-tests (tier 3, console-derived values); LA page-mode capture (tier 1) for the fetch pattern. The test ROMs are **built from their MIT sources** with cc65 (`scripts/build_lynx_tests.py`), not taken from the release zip, so no binary shipped by a reference is run. **M3. The display.** DMA bursts, the line and frame from timers 0 and 2, DISPADR latch, palette at transfer time, flip, variable frame period. *Exit*: line and frame structure match LT video-timing's numbers for the 22 captured `T0_PBKUP_T2` settings (ticks from Timer 0 borrow to first group, group spacing, lines per frame); frame period reported in ticks for Lemmings, Batman Returns, Krazy Ace and Crystal Mines II equals 16 MHz / the captured rate within the capture's resolution. *Judge*: LA captures (tier 1; decoded by this repository's own `.dsl` reader, since `sigrok-cli` is not installed; if a capture cannot be decoded, LT's stated numbers, tier 3, and say so). **M4. Suzy's sprite engine, function first.** SCB walk, all eight types, packed and literal data, scaling, stretch, tilt, quadrants, clipping, collision buffer and depository, EVERON, the documented defects. *Exit*: the video and collision CRCs of `sprites3` (8 types) and the output checks of `sprites1`, `2`, `4`, `5` match with timing checks ignored; the 29 smoke games reach their title screens; picture compare with Holani on the smoke list at a stated frame, differences listed. *Judge*: lynx-tests CRCs (tier 3); Holani and MAME as detectors. **M5. Suzy's time.** Per-access bus cycles, the pipeline's overlap, cold and warm rows, yielding to Mikey. *Exit*: the Timer 6 durations of `sprites1-5` (40 cases) match their expected bytes, misses listed. (SuzyTiming has unlicensed source: no longer fetched, dropped from this exit, 2026-11-14.) *Judge*: lynx-tests (tier 3). **M6. Audio and UART.** Four channels (timer, LFSR, integrate, volume), link ring with timers, PWM nibble defect as an option, Lynx II stereo and attenuation; UART with its echo, parity, break, level interrupt. *Exit*: `audio` (6), `audio2` (7), `uart` (6), `uart2` (5), `uart3` (6) expected bytes on both rows; a WAV of one title compared by ear and spectrum with Holani (detector). *Judge*: lynx-tests (tier 3). **M7. Carts beyond plain ROM, then a sweep.** EEPROM 93C46-86 (file-backed), AUDIN banking, bank 1, cart writes; rotation delivered to the frontend. *Exit*: Alpine Games boots and saves; an EEPROM title keeps a high score across runs; then the smoke list, then (once, at a commit point) every distinct payload for N frames, frame-compared with Holani, the divergence table published with causes. *Judge*: detectors; behaviour claims labelled "detector-compared". **M8. Frontend.** pygame-ce window on PyPy, rotation, flip, the measured refresh rate, audio out. Do not skip a rung. M0 has no dependency on the CPU core and can start before the CPU core is ready. ## Proposed smoke list (29 games + 8 loader cases; all present locally, read in place) Classics: California Games; Chip's Challenge; Blue Lightning; Electrocop; Todd's Adventures in Slime World; Xenophobe; Ms. Pac-Man; Shanghai; Robotron 2084; Joust; Rampart; Warbirds; Checkered Flag. Known-hard, with the reason ([undocumented-behavior.md](undocumented-behavior.md)): S.T.U.N. Runner (math sign, C7); Hard Drivin' and Dirty Larry (sprite time); Steel Talons (math, candidate); QIX (end-of-line packet); Fat Bobby and Block Out (quadrants); Lemmings (50 Hz); Batman Returns (75 Hz); Krazy Ace Miniature Golf (52 Hz); Crystal Mines II (60 Hz capture exists); Awesome Golf and Scrapyard Dog (hang in Felix per its MIT changelog; EVERON candidates); Klax and Gauntlet - The Third Encounter (rotation RIGHT); NFL Football (rotation LEFT). Formats and carts: Alpine Games (aftermarket: AUDIN, EEPROM, protection SCB); Championship Rally (aftermarket: timer IRQ); Zaku (512 KiB) and Zaku (Beta) (block-size conflict); Raiden (USA) (Beta) (header rotation wrong); Xump (Songbird digital, trimmed image); Mines 2 (demo) as `.lnx` and as BLL; T-Tris (BLL). (The last group is loader and cart-hardware cases; most cost a few frames each.) ## Constraints - Oracle tiers are not negotiable. A disagreement with Holani, MAME, Felix or Gearlynx is a question for the specification or a test ROM. - Never commit ROMs, the boot ROM, test-ROM binaries, fetched documents or traces of commercial games. Carts are read in place. - Never read GPL, LGPL or unlicensed source (MAME, Holani, Gearlynx, Handy and its descendants, the MiSTer core): run the emulators as closed boxes, write differences down, never fix toward them (restart.md rules 1, 5, 6). - Pins in every claim: core revision, lynx-tests version (1.4.9), emulator versions, tick and frame counts. A gate that cannot fail proves nothing: seed a fault and show it fails. - CI minimal: PyPy only, main and pull requests, concurrency cancel. - The machine is shared: `nice`, check `uptime`, smoke lists while iterating, full sweeps only at commit points. - Local git until told otherwise; commit in reviewable units. ## Size and speed, honestly - Code: Suzy's sprite engine is the bulk (1,500-2,500 lines with timing); Mikey about 1,500 (timers 300, audio 300, display 400, UART 300, rest); board and bus 500; cart package 600; tooling as much again. - Speed: 16 M ticks/s, but work happens per CPU cycle (about 3.5 M/s) and per Suzy bus access, not per tick. Suzy draws most of the frame's pixels with the CPU stopped, so the cost per frame is dominated by sprite bus accesses. Real time on PyPy is plausible only with an event-driven timeline (next timer borrow, next DMA burst) rather than a per-tick loop; CPython will be well under real time. Record frames per second on both at each milestone. ## What done looks like `README.md` states which milestones pass, with counts and pins; `docs/validation.md` becomes the certification record; `docs/claims.md` says per subsystem what is test-ROM-matched, capture-matched, detector-compared or unknown; a manifest in `/data/emu/emulator-lineage/projects/` with its dependency on `w65c02-python`. ## Open decisions for Aubrey > **Decided 2026-11-12.** Aubrey answered "yes to all the recommendations". > For every item below, the option marked as recommended is now the decision. > The options are kept as written, as the record of what was asked. 1. **Which machine is the default row.** Options: Lynx II (the console the captures and most test development used; has stereo and the bit opcodes) or Lynx I (what MAME and the manufacturer's text describe). *Recommend Lynx II*, with Lynx I certified by the same test ROMs. 2. **No-boot-ROM path.** Options: (a) real ROM only; (b) real ROM, plus host decryption written from the published description of the scheme; (c) also embed Spruck's free ROM. *Recommend (b)*: it boots every cart without a BIOS file, and (c) has an unknown licence (U9) and covers only recognised loader frames. 3. **Header against table.** When an `.lnx` header contradicts the table: table wins, header wins, or refuse. *Recommend table > header > size rule > default, user override above all, with a warning*; for block size specifically, when table and header disagree (Zaku Beta), try the table's value and fall back to the header's if the loader's directory read fails, and record which booted. 4. **Seeding rotation/EEPROM for the 290 aftermarket payloads no free table covers.** Options: (a) defaults + user overrides only; (b) ask the authors of Handy's `cart_db.h` (zlib tree) or Atari Gamer for permission to derive a table; (c) collect `.lnx` headers from Aubrey's other sources and derive entries from those. *Recommend (a) now and (c) as files turn up*: a header we hold is our own observation. (b) means posting outside; not for Phase 0. 5. **Should the board write the other format.** *Recommend a separate converter command* (`python -m lynx_python.cart convert`) that refuses to invent rotation or EEPROM for LYX → LNX; the emulator core never writes carts. 6. **Gearlynx as third detector.** Its build was refused by the permission system in Phase 0. *Recommend allowing it*: it is the emulator the judge ROMs are developed against, so it localises failures faster than Holani. 7. **ComLynx between two machines.** Out of the first build (default); the UART echo is in. Revisit after M7. 8. **WAI/STP.** Unknown on the cell (C1). *Recommend reserved NOPs*, a core variant switch, and no claim. 9. **Visibility.** Local git until M2 passes, then private GitHub (as the other boards).