# Handoff: build `a5200-python`, the Atari 5200 board ## Context you are inheriting The family's shape is **chips are cores, boards compose cores**. Python repositories are the readable reference (correct, not fast); each core is certified alone and pinned by commit; each board is validated against hardware-tier evidence with emulators as detectors only. The closest siblings are `a2600-python` (`/data/emu/a2600-python`: same CPU core, a board built from a Phase 0 like this one) and `famicom-python` (one cycle per bus callback, DMA inside `read_byte`, `note_stall`). `6502-python` (`/data/emu/6502-python`, import name `sixfiveohtwo`) is the CPU: every cycle is one bus callback in chip order, dummy cycles included. The 5200 is an Atari 400 in a console: SALLY (an NMOS 6502 with a HALT pin), ANTIC, GTIA, POKEY, 16K RAM, a 2K BIOS, analog controllers. Phase 0 (this commit range) wrote documents, pinned references, two detector drivers and a census. **There is no emulator code.** What is unusual about this board, good and bad: - The reference literature is excellent (the Altirra Hardware Reference Manual) and there is a test suite for exactly this machine (**Acid5200**: 48 tests, MIT, sources included) by the same author. - There is **no executable hardware-tier judge**: no die simulation, no bus capture, no recorded real-console test run. ANTIC has a schematic drawn from the die; GTIA has a die photograph and a data sheet. Everything else is tier 3 or below. Claims must say so. - POKEY is not yours: it is `pokey-python`, built in parallel. Read, in order, before writing code: 1. `README.md`, then `docs/README.md` (the findings list). 2. `docs/start-here.md`: the machine, rows, clocks, memory map, BIOS, controllers, module shape. 3. `docs/sally-halt.md`: HALT and RDY, and why the CPU core needs no change. 4. `docs/timing.md`: the timeline, DMA cycles, WSYNC, NMI, GTIA delays, what POKEY needs from the board. 5. `docs/cartridge.md`: connector, classes, the 16K problem, formats and the loader, the table. 6. `docs/undocumented-behavior.md`: C1-C10, U1-U14. 7. `docs/validation.md`, `docs/mame-oracle.md`: oracles by tier; detector recipes and traps. 8. **The Altirra Hardware Reference Manual chapters 2.3, 3.3-3.5, 4 (all), 6 (all), 13, and 5.7-5.9** (`reference/docs/`). This is the working specification for ANTIC and GTIA; these documents do not restate it. 9. `reference/die/AnticReSchemLayout.zip` (`AnticReSchem.pdf`): ijor's ANTIC schematic from the die, for anything [AHRM] leaves open (NMI pulse, HALT generation, counters). 10. Acid5200's sources in `reference/test-roms/Acid800-1.2.7z` (`src/Acid5200`, shared test sources under `src/`): how a test reports. 11. `6502-python` at `origin/main` (`741419a`): `README.md`, `docs/validation.md` "Limits", `src/sixfiveohtwo/frame.py` (`note_stall`), `cpu.py` (`dma_stalled`). **The local branch `main` there is stale; use `origin/main`.** Then `famicom-python`'s `src/famicom_python/board.py` and `a2600-python`'s board for the pattern. Then `python scripts/fetch_references.py --verify`. ## Decisions already made (defaults; see "Open decisions" for the unconfirmed ones) - **Name `a5200-python`, package `a5200_python`** (confirmed). - **Python floor 3.11**, CPython and PyPy; `requires-python = ">=3.11"`, ruff `target-version = "py311"`. Watch PyPy's 80-attribute limit on the chip objects (`len(vars(obj))`). - **No CPU core change is needed** ([sally-halt.md](sally-halt.md)). Pin `6502-python @ git+https://github.com/alewman/6502-python@741419a33d1de400a63f7c24c7916bb600694ca2` (or newer `origin/main`), never a local path. A core corner found by the board goes to the core as a PR. - **HALT cycles run at the top of both bus callbacks; WSYNC is an RDY stall in `read_byte` only, with `note_stall()`.** - **ANTIC and GTIA live in this repository behind pin-shaped interfaces** with import-boundary tests (open decision 2). - **POKEY is `pokey-python`**, pinned by commit; this board writes no POKEY logic. Until that core has a first release the board uses a register stub behind the same interface, and milestone 4 swaps it. - **Cartridge mappings and the loader live here**, behind the port protocol of [cartridge.md](cartridge.md); identification by payload SHA-1 from a table seeded from CC0 data; no GPL detection code. - **BIOS is bring-your-own**, located by SHA-1; never committed. - **One television standard (NTSC)**; PAL exists only as chip fields. - **Reference boards are correct, not fast.** ## Interface to sibling cores ### 6502-python: no request See [sally-halt.md](sally-halt.md), "Core request". The board uses `MOS6502(read_byte, write_byte)`, `request_nmi()`/the IRQ line API, `note_stall()` and `dma_stalled` as they are at `741419a`. ### pokey-python: what the 5200 board needs (a request, not a change) Stated as pins and time, so that the core stays machine-neutral: 1. **Clock**: one call per machine cycle (phi2, 1.7897875 MHz on this board), or `run(n)` with n >= 1, with register reads and writes placed on exact cycles. The board never skips POKEY while the CPU is halted or stalled: POKEY is clocked on **every** machine cycle, ANTIC's included. 2. **Reset/initialisation state** such that the phase of the 15.7 kHz and 64 kHz dividers against the board's cycle counter is defined and observable (the pot scan and keypad scan step on the 15.7 kHz tick, which is not ANTIC's line; Acid5200 `pokey_inittiming` tests it). 3. **Pot inputs P0-P7 as levels**, sampled by the core whenever it looks (each 15.7 kHz tick in slow scan, each cycle in fast scan), through a board-supplied callable `pot_level(n) -> bool` (above threshold or not). The board computes it from an RC model: the level is high once enough cycles have passed since the dump transistors released. For that the core must **tell the board when it dumps and when it releases** (POTGO write, end of scan, SKCTL fast-scan bit): a callback or a readable `dump_active` state. With CONSOL bit 2 low the board never reports a crossing. The 2-port row ties P4-P7 low (ground). 4. **Keyboard scan**: a board-supplied callable from the 6-bit scan counter value to the /KR1 level, and the /KR2 level (the selected port's upper fire button), consulted at each scan step. K0 and K5 are unconnected on the 5200: the board's function ignores those two bits, so each key answers twice per scan; the core must not assume a 1:1 matrix. Debounce on/off as the chip does it ([AHRM] 13.3, 5.8). 5. **/IRQ as a level** the board can read after every cycle, and the IRQST semantics for the keyboard, BREAK (the upper fire button arrives as BREAK through /KR2) and timer interrupts. 6. **RANDOM** readable on any cycle. 7. **Audio**: the per-cycle (or per-tick) output of the four channels in a form the board can mix with GTIA's speaker bit and resample: either raw channel levels per cycle or a filled sample buffer with its rate stated. The board does not need stereo or the high-pass detail beyond what the core defines. 8. **Serial pins** (SID, SOD, BCLK, OCLK) may be left idle; the 5200 exposes them on the expansion connector and no stock software uses them. PAM Diagnostics v2.3's POKEY test wants a loopback board: out of scope. 9. **State**: a snapshot/restore pair, and no more than 79 instance attributes on the hot object (PyPy). ## Your task Build the board as `src/a5200_python/` (shape in [start-here.md](start-here.md)). Requirements: - **Machines as data**: the 4-port and 2-port rows, every difference a field with its source. - **One timeline** in machine cycles, advanced only inside the CPU's bus callbacks; ANTIC decides HALT before each cycle; GTIA produces two colour clocks per cycle; POKEY is clocked every cycle; a data-bus latch updated on every cycle (U5). - **ANTIC and GTIA as circuits, not lookups** where [IJOR] or the data sheets show the circuit (counters, the DMA clock, the shift registers, the priority logic as its truth table derived from the logic, not 64 fitted cases), with pin-level adapters so that a future bus capture or die simulation could drive them. - **The loader front door** of [cartridge.md](cartridge.md). - **Tooling at the family bar**: `state.py` (whole machine including the cartridge), a debugger on 6502-python's `DebugSession` with ANTIC beam position and chip-register watchpoints, a JSONL trace in 6502-python's schema plus bus events with machine-cycle times and halted cycles, `py.typed`, and `python -m a5200_python ROM --frames N --png out.png --wav out.wav`. - **An Acid5200 harness**: run a standalone test ROM headless and return pass/fail and the failure text from memory or the screen. ### Milestones, each with its exit criterion and judge 1. **The CPU on the board.** Bus and memory map, BIOS by hash, RAM, the cartridge port with 4K/8K/16K (both)/32K, ANTIC reduced to its counters, HALT/RDY/NMI/VCOUNT skeleton and DMA accounting (no picture), GTIA and POKEY as register stubs. **Exit**: (a) instruction-order lockstep with `scripts/mame_trace.py` from reset to the first 10,000 cartridge instructions on Pac-Man (logo path) and River Raid ($BFFD = $FF path), comparing PC, A, X, Y, P & $CF, S; divergences that come from where MAME puts stolen cycles are listed, not fixed ([mame-oracle.md](mame-oracle.md)); (b) 29,868 cycles per frame; (c) Acid5200 `cpu_bugs`, `cpu_clisei`, `cpu_decimal`, `cpu_flags`, `cpu_illegal`, `cpu_insn` pass. Seed a fault (drop a dummy read; steal one cycle too few) and show the gate fails. **Judges**: Acid5200 (tier 3) for (c); MAME is a detector for (a). 2. **ANTIC's time.** The DMA pattern for every mode, width and HSCROL; HALT placement; WSYNC with its three delay cases; NMI timing and the NMI pulse from [IJOR]; NMIST/NMIRES; VCOUNT; vertical scrolling's effect on mode line length and DLIs; virtual DMA. **Exit**: all 20 Acid5200 `antic_*` tests and `cpu_timing` pass; U2 and U6 are recorded as settled, each with the test that settled it, or stay open with the failing test named; the DMA charts of [AHRM] 4.14 p. 90-93 are reproduced by a script from the model and compared by eye once. **Judges**: Acid5200 (tier 3); [IJOR] (tier 1 document) for the NMI and HALT logic; [HM]/[DS-A] (tier 2) where they speak. 3. **The picture.** ANTIC modes 2-F with character sets, scrolling, the line buffer; GTIA playfield colours, players and missiles from DMA and from direct writes, sizes, retrigger, priority (all PRIOR values), fifth player, collisions, GTIA modes 9-11, the register write delays of [AHRM] 6.10, VDELAY, triggers and latching, CONSOL. **Exit**: all 11 Acid5200 `gtia_*` tests pass; the BIOS logo screen and the smoke list's title screens match Atari800's frame (colour-register values) at a named frame, with every difference explained to [AHRM] or recorded as open; PAM Diagnostics v2.3's ANTIC and GTIA pages show no error (MAME shows "soft error 34 01" there: the board should not). **Judges**: Acid5200 (tier 3); Atari's diagnostic cartridge (tier 2 test program, result read from the screen); Atari800 and MAME are detectors. 4. **POKEY adopted, controllers.** Replace the stub with `pokey-python` at a pinned commit; sticks through the RC model, CONSOL bit 2, keypads with the double scan and debounce rule, upper button as BREAK, Start/Pause/Reset, audio out with the GTIA speaker bit. **Exit**: all 10 Acid5200 `pokey_*` tests pass (or the failing ones are filed on `pokey-python` with the test name: the core's certification is its own); the full `acid5200.rom` runs unattended to its summary with no failure; PAM Diagnostics' controller, keypad and RAM/ROM pages behave as [FSM] describes under scripted input; a WAV of the BIOS-to-title sequence of two games is produced. **Judges**: Acid5200 (tier 3), [FSM] procedure (tier 2). 5. **Every format, every dump.** The loader front door for raw and CART files, loose or in zip/7z; the table built by script from the two CC0 hash files plus hand rows; Bounty Bob (both image orders) and Super Cart; the unknown-16K policy of open decision 3. **Exit**: (a) every one of the 182 No-Intro and 104 retrobat images loads through the front door, read in place, with `mapping` and `mapping_from` recorded; a `.car` built in a test from each class's payload resolves to the same table entry as the raw dump (same payload SHA-1), and a type-159 image to the same entry as its type-7 twin; (b) each image runs 900 frames without a CPU jam and leaves the BIOS; (c) for the 39 16K images with no public class, the run under the chosen reading reaches a non-blank screen and the other reading is recorded too, and confirmed ones enter the table as "measured here"; (d) per-dump port, keypad and trak-ball use is logged (CONSOL values, POT/TRIG reads) and added to the table (U4). This is a commit-point sweep, not an iteration loop: iterate on the smoke list. **Judges**: none above detector tier; the claim is "loads and runs", not "correct". 6. **The 2-port row and BIOS revision A.** The row's fields; `a5200a` lockstep as in milestone 1. **Exit**: K-Razy Shoot-Out, Mountain King and Pitfall! run on the 4-port BIOS and fail on revision A in the way the 22-byte shift predicts (the call target is named for each); a cartridge with $BFE7 = 0 still boots on revision A with the NTSC GTIA (C1); Super Breakout's four-player mode reads ports 3-4 on the 4-port row and not on the 2-port row. **Judges**: the ROM bytes (measured), [AHRM] F.2 (tier 3). 7. **Trak-ball, frontend, sweep.** The CX53 model (U11) for the 12 [FAQ] titles; a pygame-ce window on PyPy with an analog stick mapping, keypad keys and a labelled palette; frames-per-second recorded on CPython and PyPy; then one full sweep against Atari800 frame digests at fixed frames with the divergence table published and the failures kept as the next smoke list. **Judges**: detectors only; divergences are questions for [AHRM] and Acid5200. Do not skip a rung. A gate that cannot fail proves nothing: seed a fault at each milestone and show it fails. ### Smoke list (32; read in place from the No-Intro folder) Classics, expected to work early: Pac-Man; Ms. Pac-Man; Galaxian (8K; MAME's own list marks it unsupported: P/M offsets and collisions); Centipede; Missile Command (8K); Defender; Dig Dug; Joust; Pole Position; QIX; Moon Patrol (one-chip 16K); Pengo; BerZerk (speech); Star Raiders (keypad); Super Breakout (4K, pack-in, four players); Kaboom! (4K, no logo). Harder or special: Robotron 2084 and Space Dungeon (two sticks, ports 1+2); Ballblazer and Rescue on Fractalus! (32K, split screens, heavy DLIs); David Crane's Pitfall II and H.E.R.O. (Activision, no logo); Carol Shaw's River Raid (8K, no logo: the short boot path); Bounty Bob Strikes Back! (40K bank switching); Miner 2049er (MAME: wrong colours on the score screen); Quest for Quintana Roo (MAME: Start not recognised); RealSports Soccer (MAME: analog range); Pitfall!, K-Razy Shoot-Out and Mountain King (BIOS revision dependence); Star Wars - The Arcade Game (16K class contested, C5); Gyruss (Rev 1) (16K class unknown); Castle Crisis (unlicensed; MAME: playfield height wrong). Tests: Atari PAM Diagnostics v2.3 and v2.0 (MAME crashes on v2.0), PAM System Test v1.02, and `acid5200.rom` (fetched). ## Constraints - **Oracle tiers are not negotiable.** MAME, Atari800 and Altirra are detectors; the MiSTer core is a second opinion; Acid5200 is a tier-3 judge whose own correctness can be questioned with [IJOR] and the manufacturer documents. Say the tier in every claim. - **Never commit ROMs, BIOSes, test ROMs, traces of commercial games or fetched documents.** `reference/`, `tests/test_roms/`, `tests/mame_traces/`, `tests/detector_runs/` are ignored. Cartridges are read in place from `$NO_INTRO_DIR/Atari - Atari 5200` and the front-end copy now named by `$A5200_EXTRA_DIRS` (scripts/romsets.py; machine paths replaced 2026-11-13); never written next to. - **No GPL logic in the repository**, scripts included: MAME, Atari800 and Altirra are run or read, cited by file, and never copied. The MiSTer a8core is non-commercial-only: read only. The two MAME hash files are CC0. - **Pins in every claim**: 6502-python and pokey-python revisions, Acid800 archive SHA-256, MAME and Atari800 versions, Python versions, counts. - **The machine is shared**: `nice`, few processes, short runs; full sweeps only at milestones 5 and 7. - **No shell one-liners that look dangerous** (`rm -rf`, `sed -i`, `ln -sfn`, `pkill -f`); edit with the editor tools. - **Local git only** until the user says otherwise; small commits; do not touch other directories under `/data/emu`. - **CI, when there is a remote**: PyPy only, pushes to `main` and pull requests, `concurrency` cancel, a job timeout. - No console exists here and none will be bought: do not plan work that needs one. ## Size and speed, honestly - **Code**: ANTIC about 1,200-1,800 lines, GTIA 1,000-1,500, board and bus 400, controllers 250, cartridge package and loader 500, tooling about as much again. POKEY is elsewhere. - **Speed**: 1.79 M cycles/s with ANTIC, GTIA (two colour clocks) and POKEY work on every one. Full speed on CPython is not expected; on PyPy it is plausible with idle fast paths (blank lines, no P/M, POKEY idle). Record frames per second on both at every 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 strong (test-suite matched, with the tier), provisional (detector-compared) or undecidable here; a manifest in `/data/emu/emulator-lineage/projects/` with `[[depends]]` on 6502-python and pokey-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. Defaults above apply until answered. 1. **Acid5200 as the working judge.** It is tier 3 (author-stated hardware results, no recorded 5200 run), and it is all there is. Options: (a) accept it as the gate for milestones 2-4, with [IJOR] and manufacturer documents overruling it where they speak; (b) also require agreement with Atari800 before a milestone closes; (c) hold milestones open until someone with a console publishes a run. **Recommend (a).** (b) turns a detector into a judge; (c) never ends. 2. **Where ANTIC and GTIA live.** They are also the video chips of the Atari 400/800/XL/XE, which the family does not have. Options: (a) in this board behind pin-shaped interfaces with import-boundary tests, extracted with history when an 8-bit-computer board starts; (b) `antic-python` and `gtia-python` repositories now; (c) one board repository with machine rows for the 5200 and the 400/800. For (a): it is the family rule (second consumer extracts) and what `a2600-python` did with the TIA; one repository, one CI, no premature API. Against (a): POKEY already got its own core because a second consumer exists, so the 5200 will be split across two styles. For (b): cores get certified alone, and Acid800's ANTIC/GTIA tests could run on a thin harness. Against (b): the chips cannot be exercised without a CPU, a bus and each other, so "certified alone" has no judge to run against; two more repositories with no second user. For (c): the full Acid800 suite (more tests than Acid5200, same author) would judge the shared chips on the 800 row, and the 800 row is small once the chips exist (PIA, OS ROMs, keyboard). Against (c): it is a second machine with SIO, disk and cassette behind it, which is scope this batch did not ask for, and the repository would be misnamed. **Recommend (a)**, keeping PAL and CTIA as chip fields from the start so that extraction is a move, not a rewrite; revisit as (c)-by-extraction the day an 8-bit computer board is wanted. 3. **An unknown 16K dump.** Options: (a) refuse without `--mapping`; (b) load with the static walk's answer, labelled a guess, refuse only when the walk abstains; (c) fixed assumption. **Recommend (b)** ([cartridge.md](cartridge.md): no contradiction on 60 known images, 39 local dumps need it). 4. **The cartridge table's seed.** Options: (a) MAME's two CC0 hash files plus hand rows, each row with its source; (b) hand-built only. **Recommend (a)**; the licence was checked in both file headers. 5. **A replacement BIOS.** Atari800 embeds Altirra's 5200 kernel so that it runs with no Atari ROM. Options: (a) bring-your-own Atari BIOS only; (b) also accept a third-party kernel as a labelled, uncertified row. **Recommend (a)** for now: the Atari ROMs are in the local MAME set, and three titles depend on the exact 4-port code. 6. **The clock value** (C2): [FSM]'s 3.579575 MHz crystal against [AHRM]'s computer-derived figure. **Recommend the [FSM] value** as a field; it changes pitch by 8 ppm and nothing else. 7. **7z input.** The standard library cannot read 7z. Options: (a) call the `7z` program; (b) optional `py7zr` dependency; (c) both, in that order of preference reversed. **Recommend (c)**: `py7zr` if importable, else `7z`, else a clear error; the board itself stays dependency-free. 8. **Visibility.** Local git until milestone 2 passes, then a private GitHub repository like the other boards. **Recommend that.** 9. **A netlist from ijor's ANTIC layout** (U10): extracting one would give the family a die-level ANTIC judge. It is a research project of unknown size, and the layout's licence is not stated. **Recommend not now**; note it as the one path to a tier-1 executable judge.