# Handoff: build `williams-python`, the Williams 6809 arcade 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 only 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). These boards are era 1 in the charter's table in all but name: one main clock domain at cycle level, plus an independent sound board. Read in order before writing code: 1. [start-here.md](start-here.md), [memory-map.md](memory-map.md), [defender.md](defender.md). 2. [video.md](video.md), [blitter.md](blitter.md), [pia-cmos-watchdog.md](pia-cmos-watchdog.md), [sound-speech.md](sound-speech.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` (54 files, 93 MB including a 40 MB Harris data book; `--verify` to check). The Williams scans have no text layer: grep the pinned archive OCR in `reference/text-ia/`, then read the page as a picture (`pdftoppm -r 150 -f N -l N`). The drawing sets are two-page spreads (Sinistar's sound board is PDF page 17). ## Decided by Aubrey (standing rules that apply here) - Name `williams-python`, package `williams_python`. Local, no remote, until he says otherwise. Romsets by `$MAME_ROMPATH`, read in place, identified by SHA-1; nothing of Williams's in the repository. - 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. - MAME is a closed box (tonight's brief), whatever its files' licences. - Technical choices are made, marked provisional and reported; policy waits for him. ## Proposed by this Phase 0 - **First machine: Robotron** (SC1; the best evidence: Riddle's tier-1 blitter data is from the same board family, m6809-python's trace is Robotron's), then Joust, Stargate, Bubbles, Sinistar, Splat, Defender, Blaster as rows. - **Defender as a machine row** with its own map module (open decision 2). - **One timeline** in a common unit with two crystals (12 MHz main, 3.58 MHz sound), converted at the one channel (the sound command). - **The decoder PROMs run as data** from the romset, never hand-tabled. - **The blitter at bus-cycle level** with the CPU halted through the measured handshake, not MAME's "compute at once, charge cycles". ## Package and classes (proposed) ``` williams_python/ machine.py # rows: map (later/Defender), blitter (none/SC1/SC2), CMOS width, speech, # sound boards (1 or 2), sound CPU part and crystal, visible window romset.py # load a MAME zip by member SHA-1 into regions (program, sound, speech, PROMs) maps.py # WilliamsMap (C900 bank, C000-CFFF I/O) and DefenderMap (D000 page latch) board.py # MainBoard: MC6809E (m6809-python), DRAM, timeline, HALT, IRQ wiring video.py # VideoCounter (16,640 counts, 0x3F00 reload), vertical count, COUNT240, VA11, # blanking, pixel output, colour RAM with its write glitch, flip blitter.py # SpecialChips(sc1: bool): registers, control bits, per-cycle blit, clipper pia.py # Pia6821: pin-shaped (port and control-line callbacks, irq_a/irq_b outputs) cmos.py # CmosRam(width 4 or 8, size, protect range, coin-door switch) watchdog.py # Watchdog(8 vertical scans, data pattern, reset output) sound.py # SoundBoard: MC6808/6802 (m6800-python), RAM, ROM, Pia6821, Mc1408 DAC speech.py # SpeechModule: ROM extender + Hc55516 (behavioural, per bit clock) inputs.py # per-game widget multiplexers and coin door savestate.py # whole-machine states naming romsets by hash ``` ## What the board needs from its cores (the embedding contracts) From **m6809-python** (not yet built; requests in [cpu-cores.md](cpu-cores.md)): `step()` returning E cycles; host `read_byte`/`write_byte` called for every bus cycle in order, dummy (VMA-low) cycles marked; level IRQ/FIRQ resampled per boundary, edge NMI; **a HALT input and the dead cycles of entering and leaving the halt**; Python 3.11. From **m6800-python** (built, pin 96302c2): `M6808`/`M6802` with host bus callbacks, `step()` cycles, level IRQ, edge NMI (the diagnostic switch), reset; `undocumented="measured"`. ## The gate (defined at milestone 1) Unit tests of every documented fact, the board-event comparison with MAME's run log (`scripts/mame_trace.py`, every difference named), and from milestone 3 Riddle's 256 blits byte-exact. Adding a row (Defender, Sinistar's speech, Blaster) must not move the gate's results for the rows already passing. ## Milestones | # | Milestone | Judge (tier) | Exit | | --- | --- | --- | --- | | M0 | **Prerequisites**: m6809-python core with rungs 1-2 passing and the HALT request in; m6800-python pinned | the cores' own ladders | the core's README says rungs 1-2 pass; HALT has a unit test | | M1 | **Main board without pictures**: WilliamsMap, romset loader, video counter and vertical count, COUNT240/VA11 into the ROM-board PIA, both PIAs, CMOS, watchdog, reset, bank latch, timeline | DEF-T, SR-HW (2-3); SR-WETS vertical count (1); MAME run log (5) | Robotron from a blank CMOS runs its ROM tests into the Advance wait, and after Advance its first 20 s of IRQ entries, watchdog writes and PIA writes match MAME's log line for line, or each difference is named; unit tests for 16,640, 0x3F00, 0xFC on 256-259, the four VA11 edges, COUNT240, CMOS protect, watchdog timeout | | M2 | **Pictures**: per-microsecond fetch, six pixels per µs, colour RAM with its write glitch, flip; decoder PROMs as data; Stargate (no blitter) as the first row | DEF-T (2); MAME snapshots (5) | Stargate's and Robotron's attract frames triaged against MAME pixel by pixel; PyPy speed measured and recorded | | M3 | **Blitter**: SC1 and SC2, all control bits, slow mode, clipper (Sinistar), the HALT handshake | SR-BLIT dumps and times (1) | all 256 of Riddle's blits byte-exact on SC1 (and with the XOR undone on SC2); times within the fitted model (fast 5.0 + 1.001 µs/byte, slow 6.2 + 2.001) or the residual explained; Robotron, Joust, Bubbles, Splat attract | | M4 | **Sound board**: m6800-python, PIA, DAC, the command channel; two boards for the cockpit and Blaster rows | SIN-DS p. 17 (2); m6800-python's rung-4 capture and MAME's DAC stream (5) | Robotron's sound board reproduces the 199,418 DAC bytes of m6800-python's capture within its cycle tolerance, now driven by the board's own command writes | | M5 | **Speech**: SpeechModule, HC-55516 behavioural model, constants tagged | HC55516 (2); MAME (5) | Sinistar's speech intelligible; waveform compared with MAME's and differences recorded (good-enough rule) | | M6 | **Defender map and remaining rows**: DefenderMap and its page latch; Mayday, Colony 7, Jin; Bubbles' 8-bit CMOS; Blaster's extras | DEF-T, DEF-TE (2); MAME (5) | each row's attract mode triaged; Defender's watchdog decode (C3FC) explained | | M7 | **WETS and states**: Riddle's interrupt, vertical-count, RAM and blitter-timing programs run on the board (assembled with a tool per decision 9); save states; the smoke list | SR-WETS published results (1) | his published real-board results reproduced or each difference explained; a save state loads into a fresh board and continues identically | ## The chip rule | Chip | Users in or near the family | Proposal | | --- | --- | --- | | MC6809E | Williams, Vectrex, Namco System 1/86, Konami, CoCo | `m6809-python` (to build) | | MC6808/6802 | Williams sound, many arcade sound boards, pinball | `m6800-python` (built) | | MC6821 PIA | Williams (x3-4), Atari 400/800 (as the 6520) | in the board behind a pin-shaped class; extraction open decision 3 | | Special Chips, video generator, MC1408, HC-55516 | Williams only | stay in the board | ## Unknowns (U) and conflicts (C) | # | Unknown | Best source now | Status | | --- | --- | --- | --- | | U1 | the HALT handshake in cycles: when /HALT is sampled, how many dead cycles before and after a blit | SR-BLIT pictures ("nearly one", "nearly 2"), 6809PM | read Riddle's `2blits` pictures and Saleae captures | | U2 | open-bus value of unmapped reads | none | follow the schematic's bus pull-ups; HYPOTHESIS | | U3 | the blitter's fixed cost (~5 µs) split, and the read/write order inside a blit | SR-BLIT Saleae captures (not fetched) | FITTED until read | | U4 | power-on contents of DRAM, colour RAM, blitter registers (they survive a reset) | none | random-or-zero option, logged | | U5 | the vertical count's D0-D1; whether MAME 0.285 still returns 0x00 on lines 256-259 | DEF-T (VA8-13 on D2-D7); SR-WETS | follow Riddle (0xFC); probe MAME | | U6 | address mirrors and partial decoding on the later boards | ROB-DS, JST-DS decoders | read the schematics at M1 | | U7 | which nibble of a byte is the left pixel | DEF-T shift-register text | read the schematic; check against MAME's picture | | U8 | the colour output levels (resistor ladder) | the CPU board schematic | tag DOC once read | | U9 | reads of write-only addresses (CA01, colour RAM) | OBSERVED: CLR's read, PSHU's stack read in MAME | settled as CPU bus behaviour; the core decides PSHU's read | | U10 | PIA corner behaviour: read-back of output bits, flag timing against E | PIA data sheet | detectors | | U11 | CMOS power-on values, the undriven upper nibble on reads | none | logged option | | U12 | early versus later Defender boards | DEF-TE vs DEF-T | read at M6 | | U13 | the watchdog's accepted data pattern; what its reset clears (video counter?) | DEF-T fig. 3-2 | read the gate; C3 | | U14 | which sound-PIA lines are the CVSD's clock and data; the speech ROMs' addresses | SIN-DS sound board and speech module sheets | read at M5 | | U15 | the HC-55516's digital filter arithmetic | data sheet constants only; no die analysis | behavioural, FITTED by ear and against MAME | | U16 | each game's widget multiplexer and inputs (Robotron's two sticks, Sinistar's 49-way stick, Splat, Bubbles) | the drawing sets' interface sheets | per row | | U17 | average 6809 cycles per instruction on a Williams workload | none (estimate 4) | measure at M2 | | U18 | RAM-to-RAM blits without the slow bit | MEASURED as non-deterministic | log and treat as fast; HYPOTHESIS | | # | Conflict | Sides | Proposal | | --- | --- | --- | --- | | C1 | which PIA input carries which interrupt | DEF-T's MPU section: "IRQA and IRQB ... (4 mSec and Count 240 respectively)"; DEF-T's ROM-board PIA section: CA1 = Count 240, CA2 = slam, CB1 = VA11 | the detailed section (it names pins; MAME's IRQ timing and m6809-python's trace agree with it); confirm on DEF-DS | | C2 | pixel clock | DEF-T: 6 MHz shift clock, six pixels per µs; MAME: 8 MHz pixel clock, 512 per line | DEF-T; MAME's geometry is presentation | | C3 | Defender's watchdog | DEF-T: C3FF with 38h or 39h; the program writes 38h to C3FC (OBSERVED) | partial decode; read the gate (U13) | | C4 | vertical count on lines 256-259 | Riddle's board: 0xFC; MAME of 2012: 0x00 | Riddle (tier 1) | | C5 | blitter timing | MAME's estimate (slow blits once at half the real time); Riddle's measured times | Riddle (tier 1) | | C6 | resolution | DEF-T section 2: "360 x 240 pixels"; SR-MAP: 304 x 256 in memory; MAME: 292 x 240 visible | memory 304 x 256 (SR-MAP); visible window per row from the blanking decode (DEF-T), not MAME's | | C7 | m6809-python's Python floor | its README and brief: 3.12+; the family: 3.11 (PyPy) | 3.11 (request 4) | ## Domains and speed - **Domains**: main (MC6809E, video, DRAM, colour RAM, blitter, PIAs, CMOS, watchdog; all on the 12 MHz crystal, E = 1 MHz) and sound (MC6808 on its own 3.58 MHz crystal, E = 894,886 Hz; its PIA, DAC and on Sinistar the speech module stepped inside it). Sinistar cockpit and Blaster: two sound domains. - **Channels**: the sound command (main's ROM-board PIA port B write → sound PIA port B and CB1 → 6808 IRQ), one way only; audio out as a producer; inputs from the host. No channel returns from sound to main, so the sound domain may run any distance behind and stay deterministic. - **Instructions per second**: main 1,000,000 cycles/s at roughly 4 cycles an instruction ≈ 250,000 instructions/s (bus events never above 1,000,000/s because the CPU is halted during blits); video 16,640 x 60.096 ≈ 1,000,000 fetches/s; sound 894,886 cycles/s ≈ 200,000 instructions/s per board. Whole machine ≈ 450,000 instructions/s. - **No-JIT path**: Rust `-fast` reaches real time with a large margin on desktop, phone and browser (a few percent of a core); no cached interpreter or threads are needed (the sound thread is available). PyPy likely reaches real time for the reference board (m6800-python's Williams sound board alone ran 15x real time on PyPy). Capability: `recompile: none`. Details: [domains-and-speed.md](domains-and-speed.md). ## Open decisions for Aubrey (each with a recommendation) 1. **Scope and first machine.** Recommend the first generation (Defender through Blaster, 59 sets minus the six second-generation ones) in this repository, Robotron first. 2. **Defender: row or sibling.** Recommend a machine row with its own map module: it shares the CPU, clocks, video, PIAs, CMOS, watchdog and the whole sound board; only the address decoding and the absent blitter differ ([defender.md](defender.md)). 3. **The 6821 PIA as a shared core.** This board is its second family user (Atari 400/800's 6520 is pin- and software-compatible). Recommend building it in this board behind a pin-shaped class through milestone 4, then extracting it with history as `m6821-python` (package `m6821_python`, matching m6800/m6809; name provisional) before atari8bit-python writes its own. 4. **Requests to m6809-python** (fixes start upstream): HALT with its dead cycles, every bus cycle with dummy cycles marked, the 3.11 floor, and handing its rung-4 Williams host to this board. Recommend raising them in its brief now, before its build session. 5. **MAME's BSD-3 Williams files.** Their `license:` lines say BSD-3-Clause; tonight's brief keeps them closed. Recommend they stay closed for this board: Williams's own theory and schematics plus Riddle's measurements cover what MAME's source would add, and keep the board's provenance simple. 6. **The second generation** (Mystic Marathon, Turkey Shoot, Inferno, Joust 2). Recommend later rows in this repository after M7 (they share the CPU, SC2, PIAs and sound board; their tile background and palette are a second video module); Joust 2's background board would pin ym2151-python. 7. **Contacting Sean Riddle.** His site is CC BY 3.0 and his 222-blit second set, SC2 data and Saleae captures would strengthen the judges; he invites email. Recommend Aubrey decide whether to write (outside contact is his call); credit him in the README either way (CC BY requires it). 8. **KLOV set aside.** Its robots.txt bars AI-training crawlers (it allows Claude-User). Recommend it stays set aside; nothing here needs it. 9. **A 6809 assembler for Riddle's WETS programs** (M7). The common ones (lwtools, asm6809) are GPL; recommend building one in emu-tools-gpl as a tool and assembling his public-domain programs there, reading only the binaries here. 10. **sources.md rows** (emulator-lineage): the seven rows proposed at the end of [sources.md](sources.md) (Riddle CC BY; Williams documents facts only; KLOV set aside; robotron-2084.co.uk downloads not fetched; original Williams source not kept; MAME's Williams files BSD-3 but closed here; the Harris data book). 11. **atari8bit-python's note** "no other family board uses one" (its PIA page) is now out of date; recommend its owner update it when decision 3 is taken.