# Handoff: build `atarist-python`, the Atari ST board ## Context you are inheriting The family's shape: chips are cores, boards compose cores; CPUs always get their own core; a non-CPU chip used by one machine stays in its board and is extracted when a second family project needs it; never copy a file between repositories, pin the sibling by commit. Read the charter first (emulator-lineage `docs/charter.md`), then [start-here.md](start-here.md). The ST is era 2 in the charter's table by its single CPU but behaves like era 1 for timing: one tightly coupled bus, cycle level everywhere, Python runs the tests, Rust plays. Boards to model this one on: **amiga-python** (Phase 0: a 68000 under a custom chip set's slot table, the same `step_clocks` stall mechanism), **megadrive-python** (an m68000-python board in production), **bbcmicro-python** and **msx-python** (Phase 0s that met the WD177x/279x and the MC6850), **namcos1-python** (Phase 0: the HD6301-family variant request). Cores it embeds, read and not touched by this phase: **m68000-python** `55d3d60`, **ay8910-python** `76cace3`, **m6800-python** `96302c2`. Read in order before writing code: 1. [README.md](../README.md), [start-here.md](start-here.md), [machines.md](machines.md), [bus-and-memory.md](bus-and-memory.md). 2. The chips: [video.md](video.md), [mfp.md](mfp.md), [acia-and-ikbd.md](acia-and-ikbd.md), [dma-and-floppy.md](dma-and-floppy.md), [sound.md](sound.md), [ste-and-mega.md](ste-and-mega.md), [tos.md](tos.md). 3. [cpu-cores.md](cpu-cores.md), [domains-and-speed.md](domains-and-speed.md). 4. [sources.md](sources.md), [validation.md](validation.md), [mame-oracle.md](mame-oracle.md), [census.md](census.md), [provenance.md](provenance.md). Then `python -I scripts/fetch_references.py` (25 files, about 132 MB, and a sparse Clock Signal checkout; `--verify` to check). Text versions land in `reference/text/`; the ASIC archive unpacks to `reference/docs/ZIETZ-ASICs-new/`. ## Decided by Aubrey (standing rules that apply here) - Name `atarist-python`, package `atarist_python` (the x-python naming rule). - Local, no remote, until he says otherwise. Bring your own TOS, IKBD ROM and disks; nothing of Atari's in the repository; romsets by `NO_INTRO_DIR` / `MAME_ROMPATH`. - Python floor = PyPy's (3.11), PyPy must work; modern over compat; reference boards are correct, not fast; sound may be less exact than pictures; smoke lists before sweeps. - Technical choices are made, marked provisional and reported; policy waits for him. - No GPL source read or kept (Hatari, Steem, EmuTOS's source); author and site wishes respected (atari-forum.com, cpcwiki.eu, atarimagazines.com set aside: robots.txt). ## Proposed by this Phase 0 - **The 520ST/1040ST first** with TOS 1.04 (US and UK rows), colour and mono monitors, 512 KB and 1 MB; the STE, Mega ST and Mega STE as rows afterwards ([machines.md](machines.md)). - **One timeline in 32 MHz ticks** (the Shifter's mono pixel clock, four per CPU clock), with the MFP's 2.4576 MHz timers and the IKBD's clock converted at their channels; the domains and channels of [domains-and-speed.md](domains-and-speed.md) first-class from milestone 1. - **The 68000 placed in GLUE/MMU's 4-clock slots access by access** through `step_clocks` and a running stall total (as amiga-python plans), every alignment rule a named constant with its evidence tag. - **The IKBD as the real HD6301V1 running the player's ROM** by SHA-1, its own domain (open decision 2). - **TOS and the IKBD ROM identified by SHA-1** ([census.md](census.md)), never by file name (a BIOS pack's `tos.img` is a Falcon TOS). - **Disks at track level** from the start (the library is all IPF), with ST/MSA as simple sources for test programs. ## Package and classes (proposed) ``` atarist_python/ machine.py # rows: CPU clock, crystal (PAL/NTSC), RAM banks, TOS SHA-1s, monitor, chips present console.py # build(machine, tos=..., ikbd_rom=..., floppies=(), cartridge=None) -> AtariST bus.py # the map, GLUE's decode and BERR rules, the 4-clock slot alignment, open bus glue.py # Glue: sync mode, video counters and comparisons, DE/blank/sync, IPL encoding mmu.py # Mmu: bank configuration, video address counter, slot table, refresh, DMA address shifter.py # Shifter: modes, palette, the per-pixel pipeline, border output dma.py # DmaChip: mode/status, sector count, FIFO, FDC/HDC routing mfp.py # Mfp68901: pin-shaped, ST wiring outside the class (GPIP map, clocks) acia.py # Acia6850: pin-shaped; two instances ikbd.py # Ikbd: the HD6301V1 (m6800-python variant), matrix, mouse, joysticks, SCI link fdc.py # Wd1772 + Drive: pin-shaped, track model with MFM cells disk/ # ipf.py, st.py, msa.py (stx.py later): track sources sound.py # the YM2149 (ay8910-python) with port A/B wiring; mixing ste/ # gstmcu.py, shifter_ste.py, dmasound.py, microwire.py (LMC1992), joypads.py blitter.py # Blitter (Mega ST, STE, Mega STE) sockets.py # cartridge, ACSI, MIDI, RS-232, printer: Protocols and test-only fakes savestate.py # whole-machine states naming TOS, ROM and disks by hash; wakestate recorded ``` ## What the board needs from its cores (the embedding contracts) From **m68000-python** ([cpu-cores.md](cpu-cores.md) in full): `step_clocks` per access (have); **request 1**: an optional VPA/E-clock data-cycle hook (shared with amiga-python's request 1); **request 2**: bus-error frames inside the claim (claims.md itself names the ST); `acknowledge(level)` for GLUE's autovectors and the MFP's vector (have); `reset_devices()` (have). From **m6800-python**: an HD6301 variant (the Hitachi op-codes, cycle table and traps) and a peripheral module (ports, 16-bit timer, SCI), one request shared with namcos1-python (open decision 3). From **ay8910-python**: the YM2149 with port callbacks at 2 MHz (have). ## The gate (defined at milestone 1) TOS 1.04's instruction stream against MAME's 68000 trace from reset (`0 unexplained` over a fixed instruction count, every difference named), the documented facts as unit tests (HWSPEC's map, bus errors, the RAM-sizing algorithm, MFP register behaviour), and from milestone 3 the HD6301's stream against MAME's IKBD trace. The base ST row must not move these when the STE or Mega rows land. ## Milestones | # | Milestone | Judge (tier) | Exit | | --- | --- | --- | --- | | M1 | **Bus, map and GLUE decode with bus errors; MMU bank configuration; 68000 with slot alignment; MFP registers, timers and interrupts; GLUE's VBL/HBL and DE→Timer B skeleton; ACIA register files; the PSG wired; sockets and fakes** | HWSPEC, SVC, MK68901 (2); MAME trace (5) as detector | TOS 1.04 from reset through the RAM probe, the MFP set-up (Timer C at 200 Hz) and its first VBL handler, the 68000 stream equal to MAME's for the first 500,000 instructions or a named reason for each difference; every bus error TOS takes logged with its address | | M2 | **Video**: GLUE counters and the Shifter per pixel for the ST row, the palette, three modes, borders | HWSPEC (2); ASIC GSTMCU sheets (2) read for the counters; Clock Signal (5) | TOS 1.04's desktop drawn in low, medium and mono; every GLUE constant tagged with its evidence; differences from Clock Signal triaged | | M3 | **IKBD**: the HD6301 variant pinned, Atari's ROM, the ACIA bit timing, keyboard/mouse/joystick inputs | U07, IKBD (2); MAME's HD6301 trace (5) | the IKBD answers F0h after reset; the desktop's mouse moves and keys type; one second of the HD6301 stream equals MAME's or each difference is named | | M4 | **Floppy**: DMA chip, WD1772 and drive, ST/MSA sources, then IPF at track level | WD177X, WD86, HWSPEC (2); MAME, Clock Signal (5) | a public-domain ST/MSA disk boots; 5 IPF titles of a smoke list (protected and plain) reach their title screens | | M5 | **Sound**: the YM2149's output, digi playback timing | ay8910-python's ladder; detectors (5) | TOS's key click and a smoke-list game's music; audio compared, differences named | | M6 | **STE row**: GSTMCU, STE Shifter (palette, scroll registers), DMA sound, Microwire/LMC1992, joypads, Blitter | STEADD, BLIT, ASIC (2) | TOS 1.62 and 2.06 boot to the desktop; STEADD's documented scroll and DMA-sound behaviours as unit tests | | M7 | **Mega ST, Mega STE rows**, ACSI hard-disk socket, save states | HWSPEC 5.6, TTHRM (2) | TOS 2.06 on the Mega STE; a save state loads into a fresh machine and continues identically | | M8 | **Demo-level timing** (mid-line sync and mode writes: borders, sync scrolling), wakestates as a parameter | the best evidence then in hand (ASIC for the STE; open decision 14) | a smoke list of demos grown from failures, each effect's behaviour tagged with its evidence | Full sweeps only when the board might be ready (Aubrey's smoke-sweep rule). ## The chip rule | Chip | Users in or near the family | Proposal | | --- | --- | --- | | MC68000 | many | the existing core, m68000-python | | HD6301V1 | Atari ST (IKBD); Namco System 1's HD63701V0 is the same family | a variant in m6800-python (decision 3) | | YM2149 | ST, MSX, CPC, Spectrum 128, NES 5B | the existing core, ay8910-python | | MC68901 MFP | ST, X68000 (its Phase 0 agrees: decision 5 there) | `mc68901-python` when the second of the two starts (decision 4) | | MC6850 ACIA | ST (two), BBC Micro | `mc6850-python` on the second board (decision 5) | | WD1772 | ST, BBC Micro (WD1770/1772), MSX (WD2793) | `wd177x-python` with 179x/279x rows (decision 6) | | GLUE, MMU, Shifter, DMA chip, GSTMCU, Blitter, LMC1992 | ST family only | the board | | RP5C15, Z8530 | Mega rows (others not surveyed) | the board | ## Unknowns (U) and conflicts (C) | # | Unknown | Best source now | Status | | --- | --- | --- | --- | | U1 | The ST's crystal on NTSC machines (STEADD gives the STE's) | SCH520/SCH1040 (image only, to read) | follow STEADD's figures per row, HYPOTHESIS for the ST | | U2 | The ST's GLUE and MMU logic (no design files known); the MMU's clock input | the STE's GSTMCU design (ASIC), schematics | the STE design as the best evidence, marked | | U3 | Line and frame structure per mode: cycles a line, lines a frame, DE/blank/sync positions, when the 50/60 Hz bit and the mode are sampled | ASIC (STE); MAME and Clock Signal (5) | read the GSTMCU sheets at M2 | | U4 | Which accesses align to the 4-clock slot and how (RAM, Shifter, GLUE registers, ROM?) | Clock Signal's rule (5) | HYPOTHESIS until ASIC or a hardware result | | U5 | The ACIAs' E-clock access cost | MC68000 manual's VPA cycle; m68000-python's E-clock rule | request 1 | | U6 | PSG and MFP access wait states | none | HYPOTHESIS, one table | | U7 | Wakestates: which GLUE/MMU phases exist at power-up and what each changes | community knowledge on set-aside sites and GPL emulators | a machine parameter; decision 14 | | U8 | Shifter pipeline delays, mid-line mode changes, the STE HSCROLL prefetch | STEADD (STE, partial) | detectors; M8 | | U9 | MFP input-to-pending and time-out-to-interrupt delays | MK68901/MC68901 (to read at M1) | DOC once read | | U10 | MFP timer data reads and writes while counting | the data sheets | DOC once read | | U11 | The MFP's vectored acknowledge cycle cost | MC68901 | DOC once read | | U12 | The DMA chip's FIFO drain (burst size, slots) and the high-speed rate | HWSPEC, SVC (C4) | FITTED until evidence | | U13 | How TOS detects a disk change (write-protect line?) | HWSPEC says no hardware detection | HYPOTHESIS | | U14 | Which WD1772 revision (-00, -02) each ST row has | WD86; board photographs not in hand | WD86's rates (C3) | | U15 | What a YM2149 returns when a port set as output is read | ay8910-python's claims | ask upstream if TOS depends on it | | U16 | STE DMA-sound rate divisors | ASIC SOUND sheets | read at M6 | | U17 | Mega STE 16 MHz mode, its cache, VME | none pinned | row 4, later | | U18 | Blitter cycle cost per word | ASIC Blitter designs | read at M6 | | U19 | Which chips the 68000's RESET instruction resets | schematics | read at M1 | | U20 | GLUE's BERR time-out and the exact set of faulting I/O addresses | SVC (description only) | detectors; log | | U21 | IPF layout details (weak bits, timing blocks) and the WD1772's data separator on them | Clock Signal's IPF reader (MIT, 5); a third-party layout document (not fetched) | decision 7 | | # | Conflict | Sides | Proposal | | --- | --- | --- | --- | | C1 | The system tick | HWSPEC 10 names Timer A "System Clock"; TOS 1.04 programs Timer C at 200 Hz (OBSERVED, MAME trace) | follow the wiring and the firmware; HWSPEC's label is an early plan | | C2 | The crystal on US machines | STEADD: 32.215905 MHz NTSC; MAME's US `st` and `ste` run at the PAL 32.084988 MHz (8,021,247 Hz CPU) | per-row crystal from STEADD; MAME's choice noted as a detector simplification | | C3 | WD1772 step rates | WD177X (preliminary, Atari's toolkit): 2/3/5/6 ms; WD86: 6/12/2/3 ms (-00 and -02), the -02 settling 15 ms not 30 | WD86, the production sheet; the preliminary figures in a comment | | C4 | DMA high-speed rate | HWSPEC 2.3: up to 12 Mbit/s; SVC: up to 8 Mbit/s | neither decides the chip's timing; U12 | | C5 | Clock Signal's licence | its LICENCE: MIT; its files' headers: "All rights reserved" (Xcode's template) | the repository's LICENCE governs; keep its notice with anything taken | ## Domains and speed Domains (in full in [domains-and-speed.md](domains-and-speed.md)): **C** main (68000, GLUE, MMU, Shifter, RAM, DMA chip, Blitter, MFP with its 2.4576 MHz timers as a second clock inside C), **K** keyboard (HD6301V1, own crystal; channel: the 7812.5 bit/s serial line and reset), **F** floppy (WD1772 and drives; channels: FF8604, DRQ, INTRQ, PSG port A), **S** PSG synthesis and **A** STE audio output (pure producers from timestamped logs). Steps per emulated second: the 68000 0.58-1.0 M instructions (MAME's TOS boot: 579,685 instructions in 8,016,226 cycles, 13.8 clocks each); the HD6301 0.34 M (337,571 in 999,367 E cycles); GLUE/MMU 8.0 M cycle steps; the Shifter 8-32 M pixels; the YM2149 2.0 M input clocks; the WD1772 0.5 M MFM cells while the motor runs. About **1.3 M CPU instructions and 10-12 M chip steps**: the CPUs are the small part. The no-JIT path: atarist-python on PyPy is a reference board (1-10 s per emulated second, HYPOTHESIS: the 68000 core alone runs ~33 M instructions a second on PyPy, the per-cycle chips are the bound); atarist-rust is expected real time on a desktop core; atarist-rust-fast (word-at-a-time Shifter, event-scheduled MFP and GLUE counters, K and F threads, S and A producers, m68000-rust-fast) is expected to reach real time on phones and in the browser with **`recompile: none`**: no cached interpreter or JIT is needed for a 1 M instruction a second 68000. All of it is to be measured; none of these costs is an ST workload yet. ## Open decisions for Aubrey (each with a recommendation) 1. **Scope and first machine.** Recommend the 520ST/1040ST with TOS 1.04 (US and UK rows) first, then the STE, Mega ST and Mega STE as rows; STacy, ST Book, TT and Falcon out of scope (the last two need a 68030 core). 2. **The IKBD: real MCU or functional.** Recommend the real HD6301V1 running the player's ROM as the specification (programs upload and run code in it: IKBD 9.24-9.26), with a functional protocol model only as a downstream convenience. 3. **The HD6301 variant in m6800-python**, shared with namcos1-python's HD63701V0, plus a peripheral module (ports, timer, SCI) there. Recommend yes: one request from two boards, raised once, before this board's milestone 3. 4. **`mc68901-python`.** Recommend extracting the MFP as its own core when the second of the two boards (ST, X68000) starts building; until then `Mfp68901` in whichever board is first, behind a pin-shaped class with the machine's wiring outside it. The x68000-python Phase 0 (`c092694`, its decision 5) proposes the same from its side. 5. **`mc6850-python`.** Recommend the same with the BBC Micro (its Phase 0 proposes it on a second user; the ST is that user). 6. **`wd177x-python`** with WD1770, WD1772 (-00, -02), WD1773 and FD179x/WD279x rows, the drive included, image formats excluded. Recommend extracting when the second of ST/BBC/MSX is built. 7. **IPF.** Recommend our own IPF reader in this board's `disk/`, written from Clock Signal's MIT reader as a readable reference (its notice kept beside anything adapted) and checked against MAME's BSD-3 reader as a detector; the SPS library excluded (non-commercial). 8. **EmuTOS images.** Recommend allowing a pinned EmuTOS release image (GPL, freely redistributable with its source, not a console maker's firmware) in the git-ignored `reference/` as a test program, fetched by the script and never committed; TOS stays bring-your-own. 9. **MAME's BSD-3 ST files** (atarist.cpp, stmmu, stvideo, mc68901, wd_fdc, m6801 ...): recommend keeping them run-only, consistent with the BBC Phase 0's same open question; decide once for both. 10. **Mirrors of set-aside sites** (temlib.org's copy of the Atari-Forum wiki). Recommend treating a mirror as the original's wish (not fetched), and recording that rule in sources.md. 11. **TOSEC ST sets** (not on this machine). Recommend fetching only the public-domain and demo subsets when milestone 4 needs ST/MSA test disks; the No-Intro IPF set serves the smoke list. 12. **Upstream requests to m68000-python**: request 1 (VPA data cycles, with amiga-python) and request 2 (bus-error frames in the claim). Recommend raising both now, so they land before this board's milestone 1 (fixes start upstream). 13. **sources.md rows** (nine, listed in [sources.md](sources.md)): recommend adding them, especially the three "set aside (site's wishes)" rows. 14. **The GLUE/MMU evidence gap.** The ST's per-cycle video knowledge (Jorge Cwik's reverse engineering, the wakestate studies) lives on atari-forum.com, which refuses AI crawlers, and in GPL emulators. Recommend asking whether Aubrey wants to seek the authors' permission (as with Titan's demos) or bring the facts himself (sources.md: "Aubrey may read such a site himself; facts he brings are cited as his"); meanwhile the STE's GSTMCU design files (Atari's own) are the board's evidence, marked as the STE's.