# Handoff: build `a2600-python`, the Atari 2600 board > **Restart, 2026-11-14.** Milestones 1 to 4 stand. Milestones 5 to 7 are > rebuilt under [restart.md](restart.md), whose rules override anything below. ## Context you are inheriting The family's shape is **chips are cores, boards compose cores**. Each core is certified on its own against its oracles and pinned by the boards that use it; each board is validated against hardware-tier evidence, with emulators as detectors only. `famicom-python` (`/data/emu/famicom-python`, on 6502-python) is the closest sibling and the board to model this one on; `sms-python` and `megadrive-python` set the conventions. `6502-python` (`/data/emu/6502-python`, github alewman/6502-python, import name `sixfiveohtwo`) is the core: every CPU cycle is one bus callback in chip order, dummy reads included, bus-exact against SingleStepTests. The 2600 is the smallest board in the family and the most timing-sensitive: no frame buffer, no interrupts, no DMA; the program draws each line as the beam crosses it, and the TIA must be right to the colour clock. Its unusual advantage: **a transistor-level simulation of the real TIA (Sim2600) runs here**, and tia-fpga has already recorded every TIA pin at every half clock for eleven test cartridges from it. So the TIA can be built against the die, not against an emulator. Read, in order, before writing code: 1. `README.md`: scope, what is fetched. 2. `docs/start-here.md`: the machine, clocks, memory map, data bus, RIOT, controllers, the TIA's picture model, output format, module shape. 3. `docs/timing.md`: the one timeline, WSYNC as a stretched read, the horizontal counter, objects, HMOVE, playfield, audio, the RIOT timer. 4. `docs/cartridge.md`: the 24-pin connector with no R/W, the protocol, the measured scheme coverage. 5. `docs/undocumented-behavior.md`: the bus, TIA revisions as data, **contradictions C1–C18**, open items. 6. `docs/validation.md`: every oracle with tier and pin; Sim2600 and the die traces; Stella and Gopher2600 headless; licences. 7. `docs/mame-oracle.md`: MAME 0.285 as a CPU-only detector, recipe, traps. 8. Towers' *TIA Hardware Notes* (`reference/docs/TIA_HW_Notes.txt`) in full, and tia-fpga's `README.md` and `sim/README.md` (trace format, the two wirings). 9. 6502-python's `README.md`, `docs/validation.md` ("Limits"), `cpu.py`; famicom-python's `src/famicom_python/board.py` (one cycle per callback, DMA inside `read_byte`) and its milestone records. Then `python scripts/fetch_references.py` (or `--verify`): 256 pinned files and 8 pinned repositories (MAME's sparse files added, MiSTer and Gopher2600-Dev-Docs removed in the restart). Building the detectors and Sim2600 is described in validation.md; the builds live under `reference/build-*` (ignored). ## Decisions already made (the user, 2026-10-21) - **Name `a2600-python`** (the user's choice, 2026-10-21), package `a2600_python`. **NTSC first**; PAL and SECAM exist from the start as machine rows marked "not certified". - **Python floor 3.11** (the newest PyPy supports), CPython and PyPy; `requires-python = ">=3.11"`, ruff `target-version = "py311"`, ruff pinned as in famicom-python. - **No core PR is needed.** The 6507 is `MOS6502` with the board masking to 13 bits and never requesting interrupts (define `class MOS6507(MOS6502)` in the board if a name is wanted); WSYNC is a stretched read inside `read_byte` ([timing.md](timing.md)). If the board finds a corner of the core, it goes to the core as a PR (family rule); the user merges. Pin a 6502-python git revision in `pyproject.toml`, never a local path. - **The board stays dependency-free** apart from its core; the frontend (pygame-ce) is an optional extra; headless, frames and audio as data. - **The TIA is modelled as a circuit**: LFSR counters with their decode tables, two-phase clocks, the HMOVE ripple counter, latches and comparators, START latches; not a lookup of fitted windows. It runs colour clock by colour clock (half-clock where the die needs it), and exposes a **pin-level adapter** (Φ0, Φ2, address, data in/out, R/W, CS, RDY, SYNC, BLK, LUM0–2, COL, AUD0/1) so it can be driven by a recorded die trace. - **The TIA (video, audio) and the RIOT stay in this repository behind pin-shaped interfaces**, with import-boundary tests, extracted with history into cores when a second consumer appears (the 7800 board uses both; the RIOT also appears in arcade and pinball boards). Family rule: never copy a chip file between repos. - **Bankswitching schemes live in this repository**, in `a2600_python/cartridge/`, behind the connector protocol of [cartridge.md](cartridge.md), with a test forbidding imports from the board. ARM schemes (DPC+, CDF, BUS) are out of scope. - **The reference TIA is the visual6502-photographed 10444D**, the only chip with a die judge; other revisions are fields on the machine row, added only when a photo or capture shows the reference model differs. - **Visibility**: local git until milestone 2 passes, then a private GitHub repository (created only when the user asks). - **The Supercharger** takes its BIOS as BYOR data and loads from tape, and also offers the "fast load" path every emulator uses, labelled as such. - **No hardware.** There is no console, logic analyser or capture rig: every claim rests on evidence already published (pinned in `scripts/pinned_files.json`), the die simulation, and emulators as detectors. Where nothing settles a question, record it as undecidable here rather than guess. - **No GPL logic in this repository, even in scripts**: the census runs the Stella binary and reads its output. - **Reference boards are correct, not fast.** ## Your task Build the board as `src/a2600_python/`. The module shape in [start-here.md](start-here.md) is a suggestion; the requirements are: - **Machines as data**: NTSC, PAL, SECAM rows; fields for the colour clock, palette, the TIA revision quirks (each defaulting to the reference chip, each with its source and tier), and power-on parameters (CPU registers, RAM fill, TIA latches, horizontal counter state, CPU/TIA phase, cartridge start bank, RIOT state per C8). - **One colour-clock timeline.** The board advances the TIA and RIOT inside the CPU's bus callbacks (3 CLK and 1 cycle each), never adding `step()`'s count on top; WSYNC stretches the next read; the cartridge receives every CPU cycle with its time. - **The data bus latch** and the TIA's two driven bits ([start-here.md](start-here.md)). - **Output**: per line, 228 values (colour or blank) plus SYNC/VBLANK levels; a separate `television` stage cuts frames on VSYNC; palettes in the frontend, each labelled with its origin. Audio as `take_samples()` floats at the TIA's tick rate, then resampled. - **Tooling at the family bar**: `state.py` (whole machine including the cartridge), a debugger reusing 6502-python's `DebugSession` with TIA/RIOT watchpoints and beam position, a JSONL trace in 6502-python's schema plus bus events with colour-clock times and halted cycles, `py.typed`, `python -m a2600_python ROM --frames N --png out.png --wav out.wav`, and harnesses for: die-trace replay, ale-79's serial protocol (SWCHA D7, 57,600 baud 7N1 = 20.7 CPU cycles per bit on NTSC, 20.5 on PAL; decode from the write times), and picture compare. ### Milestones, each with its acceptance test, in oracle-tier order 1. **The CPU on the board: bus, RIOT, data bus, WSYNC, simple carts.** 13-bit decode and mirrors, RIOT RAM/ports/timer (data-sheet rules; C6/C7 recorded, not decided), the data-bus latch, WSYNC as a stretched read, power-on parameters, the connector with 2K, 4K, F8, F6, F4 and Super Chip, both identification sources. The TIA may be a register stub that keeps the horizontal counter and RDY. **Acceptance**: instruction-level lockstep with MAME's trace (PC masked $1FFF, A/X/Y, P masked $CF, S, cycle count with the stated offset from trap 2) on Combat, Pitfall!, Adventure, River Raid and one F6SC title for 60 s each, N instructions stated; cycles per frame match mame-oracle.md's table; the same against Stella's `-dbg.logtrace`. Seed a fault (drop a dummy read; WSYNC one cycle late) and show the gate fails. 2. **The TIA picture against the die.** Horizontal counter, objects, START latches, scan counters, NUSIZ, VDEL, REFP, playfield, priority, score mode, collisions, HMOVE (all of timing.md), VSYNC/VBLANK, RSYNC. First settle open item 1 (the write edge) from the console-wired traces. **Acceptance**: the board's TIA, driven by the recorded inputs, matches **every video, sync, blank, RDY and data-bus pin at every half clock** on the nine non-audio tia-fpga traces in `sim/traces/phi2/` (and the Sim2600-wiring set, to show the edge is the only difference); then a Donkey Kong boot-to-picture trace regenerated locally with `sim/roms/make.py` (or the equivalent for any cartridge in the local romset) matches as well. C3, C4, C16 and C17 are recorded as settled with the trace that settled them. Write **new** die-trace cartridges with tia-fpga's generator for anything the eleven do not cover (RESBL retrigger at 18/33/66/162 CLK, late HMOVE at cycles 73–75, HMOVE mid-line, RESMP), record them on Sim2600 (25 min a frame: keep them short), commit the generator inputs, not third-party ROMs. Then picture compare against console photos: 6502.ts carts, Stella issue ROMs, "2 or 3", Cosmic Ark (reference-chip pattern per C9), stating which photo and which console. 3. **Audio, inputs and the RIOT's edges.** Both channels as the die wires them, the volume DAC, the mix (labelled fit), INPT0–5 (latch, dump, RC paddle model labelled fit), keypads. **Acceptance**: the `audio` and `audio_modes` die traces match on both audio pads at every half clock; the timer ROMs show the recorded hardware values (`test1.bas` 128246, `testTIMINT_withDelay` 0/80/0, the #606 set against its thread's console results), deciding C6/C7 by them; ale-79's seven serial tests decoded and compared with the six consoles' tables (on the PAL row; on NTSC, every entry where all six agree). 4. **Detectors at the board level, then a sweep.** Gopher2600's per-colour-clock TIA state (`QUANTUM CLOCK`, `ONSTEP TIA`) against the board on five games for at least 600 frames each, first divergence diagnosed to a higher tier before a run is extended; Stella frame digests from frame 5 on (frames 1–4 randomise). Then every licensed dump whose scheme is implemented, read in place, for N frames, frame-compared with Stella; publish the divergence table with causes. 5. **The remaining schemes in coverage order**: E0, AR (Supercharger: BIOS as BYOR data, tape input, the write sequence; plus the "fast load" every emulator uses, labelled as such), 3F, FE (reset's own stack reads switch banks), E7, F8SC/F4SC, FA, CV, UA (settle C18), FC, then DPC (Pitfall II, with its music on the cartridge audio pin), F0, 32IN1. **Sources, under [restart.md](restart.md)**: Horton's bankswitching and Supercharger documents, nocash's 2600 specifications, Stolberg's guide, Crane's DPC patent and posts, the dumps' own code, MAME's BSD-3 `bus/vcs` files (header checked first, notice kept), closed-box runs. Every scheme detail carries its evidence tag; where no permitted source decides a detail, the simplest documented behaviour, tagged HYPOTHESIS with the experiment that would settle it. **Judges**: the dumps boot and match Stella and Gopher2600 frames (detectors: frames, not source); the board's cartridge detector counted against Stella's `-rominfo` (closed box); MAME's CC0 `a2600.xml` for scheme identity. Each scheme with its claim ("specification + runs, detector-compared") in `docs/claims.md`. 6. **Controllers and the frontend**: joystick, paddles and keypads (milestone 3), the Driving controller, the Booster Grip, SaveKey (a 24LC256 on the port; saves under `~/.local/share/a2600-python/`, never beside a ROM); the `a2600-play` window on pygame-ce in the PyPy venv; NTSC/PAL/SECAM palettes, each labelled with its origin; phosphor blending as a frontend option. Device behaviour from device documentation (the makers' and the chips' data sheets) and closed-box runs, each detail tagged. 7. **PAL and SECAM rows; revision fields.** PAL and SECAM on their own clocks; certify PAL against the #699 serial tables (the six PAL/SECAM consoles) and Stella as a detector. The TIA revision fields are derived from the #699 tables themselves (where the consoles split, the split is the field), each defaulting to the reference 10444D; a field is added only where the tables or a photo show the reference chip differs. After milestone 7, before the Rust tiers are rebuilt: **the sockets the Atari 7800 board needs** (a7800-python's `docs/handoff-brief.md`, section on a2600-python): a stated public surface (`docs/api.md` with a test), `Board` accepting existing TIA and RIOT objects (and handing over the RIOT's pulse count), the CPU/TIA phase as a machine-row parameter, 7800 rows kept out of the 2600's listings, and the gates callable from outside with `root=`; the 2600's behaviour unchanged, proven by frame hashes before and after. Do not skip a rung. Later, not in this brief: the 7800 board (MARIA, SALLY's HALT, POKEY; extracts the TIA and RIOT), ARM schemes, Rust and `-fast` forks, a browser build. ## Constraints - **Oracle tiers are not negotiable.** Stella, Gopher2600 and MAME are detectors; tia-fpga's RTL and the FPGA cores are emulator tier; Sim2600 and the die traces judge the TIA. A disagreement with a detector is a question for a higher tier. - **Never commit ROMs, test ROMs, traces of commercial games, fetched documents or databases.** `reference/`, `tests/test_roms/`, `tests/mame_traces/`, `tests/detector_runs/` are ignored. Commercial cartridges are read in place from the directories `NO_INTRO_DIR` names (never a machine path here). - **Never read GPL, LGPL, CERN-OHL-S or unlicensed source** ([restart.md](restart.md), 2026-11-14, replacing "read, cite, never copy"): Stella (GPL-2+), Gopher2600 (GPL-3+), MAME's GPL files, MiSTer A2601, tia-fpga's RTL are run, never opened. MAME's BSD-3 files (header checked first) and CC0 software lists, Sim2600 and 6502.ts's test cartridges are permissive; cite them and keep their notices. - **Pins in every claim**: 6502-python revision, trace file SHA-256, Sim2600 and tia-fpga revisions, Stella/Gopher2600/MAME versions, Python versions, wall time, instruction, half-clock and frame counts. A gate that cannot fail proves nothing: seed a fault and show it fails. - **CI minimal** (private Actions minutes cost money): PyPy only, pushes to `main` and pull requests, `concurrency` cancel, a job timeout. The die-trace replays are cheap enough for CI if the traces are fetched by the pinned script; Sim2600 runs by hand. - **The machine is shared**: `nice`, at most 16 parallel processes, check `uptime` before long runs (Sim2600 especially). - **Do not touch other directories under `/data/emu`.** Commit in reviewable units with `git -c user.name=alewman -c user.email=alewman@gmail.com commit` and the session's attribution lines. Do not push or create the GitHub repository until the user asks; it will be private. ## Size and speed, honestly - **Code**: the TIA is the bulk: about 1,500–2,500 lines for the picture, 400 for audio, 200 for inputs; RIOT 300; board and bus 500; the cartridge package 600 for the first dozen schemes, the Supercharger and DPC 300 each; tooling about as much again. - **Speed**: the CPU runs 1.19 M cycles/s (~0.4 M instructions/s), easy for 6502-python on PyPy. The TIA runs 3.58 M colour clocks/s with work on every one (eight objects' clocks, decodes, a pixel), more than the NES PPU's 5.37 M dots/s once per-clock work is counted. **Full speed on CPython is not expected; on PyPy it is plausible** with an idle fast path (famicom-python's lesson: a per-cycle 3-iteration loop is what PyPy's JIT hates most). Record frames per second on both at every milestone. The die-trace harness runs at half-clock resolution and may be slower than the board; that is fine. ## What done looks like `README.md` states which milestones pass, with counts and pins; `docs/validation.md` turns into the certification record; `docs/claims.md` says per subsystem and per scheme what is strong (die-matched), provisional (photo or detector) or undecidable here; the project has a manifest in `/data/emu/emulator-lineage/projects/` with its `[[depends]]` on 6502-python.