# Handoff: build `invaders-python`, the Taito / Midway 8080 bitmap board ## Context you are inheriting The family's shape (emulator-lineage `docs/charter.md`): chips are cores, boards compose cores, CPUs always get their own core, a non-CPU chip used by one board stays in it; pin siblings by commit, never copy files between repositories. This board is era 1 in the charter's table: one clock domain, cycle level everywhere, Python runs the tests, Rust plays. Read [start-here.md](start-here.md) first. Reading order: [start-here.md](start-here.md), [video.md](video.md), [shifter.md](shifter.md), [sound.md](sound.md), [siblings.md](siblings.md), [cpu-cores.md](cpu-cores.md), [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` (6 files, about 50 MB; `--verify` to check). The schematics have no usable text layer: read sheets with `pdftoppm -r 150` and crop. The model board to copy in shape: **galemu** (Galaxian on z80-python: a small arcade board around a family CPU core, ROMs by CRC and SHA-1, vblank interrupt scheduling) and i8080-python's own `validation/mame_lockstep.py` (it already hosts this program for its rung 5; read it, do not copy it). ## Decided by Aubrey (standing rules that apply) - Name `invaders-python`, package `invaders_python`. Local, no remote until he says. - Romsets through `MAME_ROMPATH`, identified by SHA-1; nothing of Taito's or Midway's (ROMs, samples, artwork) 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. - Technical choices are made, marked provisional and reported; policy waits for him. ## Scope The Space Invaders board (`invaders`, `sitv`, `sisv`) at cycle level for the CPU's memory and I/O accesses and the beam, the shift register, the two interrupts, the watchdog, the inputs and DIP switches, the one-bit picture, and the sound circuit as a model of Taito's schematic. Siblings ([siblings.md](siblings.md)) as machine rows after. ## Package and classes (proposed) ``` invaders_python/ machine.py # machine rows: ROM layout and SHA-1s, shifter present, ports, colour hardware, sound board board.py # Board: owns I8080CPU, RAM, the beam counter, interrupts, watchdog; step()/run_frame() bus.py # memory map with the RAM mirror; I/O decode for ports 0-7 shifter.py # Shifter: the 16-bit register (shifter.md) video.py # Video: draws each line from video RAM as the beam passes; screen flip inputs.py # ports 0-2 from a controls object; DIP switches per machine row sound.py # SoundBoard: reads the port-3/5 bit log; circuit model (milestone 4) romset.py # loads a MAME zip by CRC/SHA-1 from MAME_ROMPATH savestate.py # whole-board states naming the romset by hash ``` Import boundary: the CPU core owns registers, flags, instruction semantics and state counts; the board owns everything else, including when INT is asserted and which `RST` is on the bus. ## What the board needs from its core i8080-python already provides all of it ([cpu-cores.md](cpu-cores.md)): two memory and two port callables, `step()` returning states, INT with a one-byte instruction at acknowledge. Possible later request: per-machine-cycle bus callbacks, only if a picture difference is traced to access timing (open decision 5). ## Milestones | # | Milestone | Judge (tier) | Exit | | --- | --- | --- | --- | | M1 | **Board skeleton**: romset loader, memory map and mirror, ports, shifter, watchdog, beam counter, the two interrupts, inputs; no picture | TSCH/MSI (2), CA (3) cross-check; MAME trace (5) detector | lockstep with MAME's `invaders` trace for 60 frames from reset (instruction stream, port writes, interrupt lines): `0 unexplained`; unit tests of shifter.md, the map and the port bits; seeded faults caught | | M2 | **Picture**: bitmap drawn per line, flip, frame timing; shifter corners settled from TSCH (C1) | TSCH (2); MAME snapshots (5) | attract-mode frames at fixed frame numbers pixel-identical to MAME's snapshots, or each difference explained from the schematic | | M3 | **Rows and smoke**: `sitv`, `sisv`, `tst_invd`; a smoke list of these plus two siblings; save states | the maker's self-test (3) | each row boots to attract; `tst_invd` passes its own tests; a state saved mid-game loads into a fresh board and continues identically | | M4 | **Sound**: the circuit model of each sound from TSCH (sound.md option 2), the SN76477 block once its datasheet is in hand (U9) | TSCH values (2); MAME's discrete output (5) | each port bit produces its sound; spectra and envelopes compared with MAME's, differences named; FITTED constants in one table | | M5 | **Colour siblings**: `invadpt2`, then `lrescue`, `schaser`, `polaris`, `ballbomb`, `indianbt` | their schematics (to fetch then) | each boots and draws in colour; sample-only sounds silent and listed | | M6 | **Midway DNA siblings**: `gunfight`, `seawolf`, `boothill`, `280zzzap`, ... each with its own inputs and sound | their schematics; CC0 netlists for two | rows boot; sound per their circuits | ## The chip rule | Chip | Other users in the family | Proposal | | --- | --- | --- | | 8080A (TMS8080A) | i8080-python's own boards | the existing core | | shift register (MB14241 in MAME; TTL on Taito's lists) | none | stays in the board | | SN76477 | none (MAME uses it in 111 of these machines and in some other arcade boards) | stays in the board behind a pin-shaped class; extract if a second family board needs it | | discrete sound circuits | per game | in the board, one module per sound board | ## Domains and speed **Domains:** one. The CPU, the beam (video), the interrupt flip-flop and the shifter all run from the 19.968 MHz crystal and meet on the CPU's bus. The sound board is a natural second domain for `-fast` threads: its only channel is the port-3/5 bit log with cycle stamps (plus the amplifier enable), and it is a pure producer (nothing it does is visible to the CPU). In the order of record (x-python) the board steps the CPU an instruction at a time, advances the beam by the states taken, raises INT at lines 96 and 224, and appends sound-bit changes to the log the sound model reads at the end of each frame. **Instructions per second:** 1,996,800 states a second divided by about 8.7 states an instruction gives about 230,000 instructions a second (MAME's 1 s run: 230,313 instructions, 2,012,152 states; i8080-python rung 5). Plus 320 x 262 x 59.54 = 4.99 M pixel clocks a second, handled as 262 x 59.54 = 15,600 line events a second (a line of 256 pixels drawn from 32 bytes). **No-JIT path:** i8080-python under PyPy ran 30 emulated seconds of this program in lockstep with a 328 MB trace in 26.5 s (its validation.md), so the Python reference already runs near real time on desktop PyPy. A Rust transcription needs about 0.25 M 8080 instructions a second, two to three orders of magnitude below what z80-rust-fast reaches for a comparable core (about 350 M Z80 instructions a second on this machine): **real time on desktop, phone and browser without JIT, threads or turbo**. The one cost to watch is the sound circuit model: a nodal solver at, say, 48 kHz with a few dozen nodes per active sound is the largest per-second cost in the board and the only place a `-fast` tier might be wanted (on a phone in a browser). recompile: none. ## Unknowns (U) and conflicts (C) | # | Unknown | Best source now | Status | | --- | --- | --- | --- | | U1 | the CPU clock divider (crystal / 10) and the 8224/clock circuit | TSCH logic sheets (to read) | MAME's 1.9968 MHz agrees with /10 | | U2 | whether the TMS8080A differs from Intel's 8080A anywhere | none found | follow Intel (i8080-python) | | U3 | MAME's 260-pixel width against the 256-pixel bitmap | TSCH video sheets | draw 256; check blanking | | U4 | whether the CPU waits for video or DRAM refresh | TSCH (8080 READY wiring) | none modelled (MAME none) | | U5 | the overlay band positions and colours | photographs or a measured cabinet | host option, our own table | | U6 | the noise source's taps (CD4006A + CD4030) | TSCH sound sheets | to trace at M4 | | U7 | which circuit makes which sound, and all component values in use | TSCH sheets and parts lists | to trace at M4 | | U8 | what `tst_invd` is and who wrote it | its ROM, MAME's description only | read before using as a smoke row | | U9 | an SN76477 datasheet from a host we may use | not found (bitsavers refuses this machine; not on archive.org) | find a mirror (open decision 3) | | U10 | power-on contents of RAM and the shifter | none | option; zero by default | | # | Conflict | Sides | Proposal | | --- | --- | --- | --- | | C1 | which part implements the shift register | MAME: an MB14241 device in 40 of 51 parent machines; Taito's SVN00002A and SVN00003 parts lists: no Fujitsu part, TTL only | behaviour is agreed; read the TTL off TSCH before M2 and record what Taito built; the MB14241 may be Midway's or a later board's part | | C2 | Space Invaders sound in MAME vs "MAME has netlist models" (the brief) | MAME 0.285 models `invaders` with discrete + SN76477; its only 8080 netlists are Gun Fight and 280-ZZZAP (CC0) | record; our own circuit model either way | | C3 | DIP SW6 bonus value | MSI's Table 2 scan reads 1500 / 1?00 (the second digit unclear); CA: 1500 / 1000 | follow CA until the scan is read at higher resolution | ## Open decisions for Aubrey (each with a recommendation) 1. **First machine.** Recommend `invaders` (MAME's parent, Midway's set) with Taito's `sitv` and `sisv` as rows from M3; colour siblings at M5, Midway DNA games at M6. 2. **Sound strategy.** Recommend our own circuit model from Taito's schematic (sound.md option 2) at M4, under "sound good enough"; no samples in the board; a host may offer player-supplied samples for sample-only siblings; an event-synthesis shortcut only as a named concession in a turbo tier if a target ever needs it. 3. **The SN76477 datasheet.** Recommend permission to fetch it from a mirror that serves automated clients (the brief names the UK Mirror Service for bitsavers), pinned by SHA-256, before M4. 4. **Colour overlay.** Recommend a host-side option with our own band table, labelled as an approximation of the cabinet; the board stays one-bit. Never ship artwork scans. 5. **Bus-cycle placement.** Recommend placing each memory and port access at its instruction's end in M1 (FITTED, recorded), and asking i8080-python for per-machine- cycle callbacks only if a picture difference is traced to it; a fix would start in i8080-python. 6. **The siblings' extra cores** (MC6802 + AY-3-8910 in `invrvnge`): recommend leaving such rows to the end; m6800-python and ay8910-python already cover them. 7. **sources.md rows** (emulator-lineage): recommend adding the rows proposed in [sources.md](sources.md) (the Taito/Midway scans, Computer Archeology with its "(AI)" pages, MAME's CC0 netlists, bitsavers' refusal, KLOV set aside).