# Handoff: build `pacman-python`, the Namco Pac-Man 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, siblings are pinned by commit and never copied from. Era 1: one clock domain, cycle level everywhere. Read [start-here.md](start-here.md) first. Reading order: [start-here.md](start-here.md), [video.md](video.md), [wsg.md](wsg.md), [sync-bus.md](sync-bus.md), [mspacman-aux.md](mspacman-aux.md), [siblings.md](siblings.md), [galaxian-galaga.md](galaxian-galaga.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` (8 files, about 30 MB; `--verify` to check). Schematic OCR is poor: read sheets with `pdftoppm -r 170` (PMM's NVC285 sheet is PDF page 42 of the OCR copy). Model boards in shape: galemu (Galaxian on z80-python: the closest board in the family) and emu-galaga's docs (the WSG and Namco board habits); copy neither. ## Decided by Aubrey (standing rules) Name `pacman-python`, package `pacman_python`; local, no remote; romsets through `MAME_ROMPATH` by SHA-1, nothing of Namco's, Midway's or Sega's in the repository; PyPy floor and support; modern over compat; reference boards correct, not fast; sound may be less exact than pictures; smoke lists before sweeps; technical choices made, marked provisional and reported. ## Scope The Pac-Man board (`pacman`, `puckman`) at cycle level for the Z80's accesses and the beam: the map, the 74LS259 latch, the IM 2 vector latch, the watchdog, inputs and DIPs, tiles and sprites drawn per line, the WSG as its TTL sequence; then Ms. Pac-Man's auxiliary board as a socket device, and the siblings as rows ([siblings.md](siblings.md)). ## Package and classes (proposed) ``` pacman_python/ machine.py # rows: ROM layout and SHA-1s, decode stages, sound chip, CPU variant board.py # Board: Z80 (z80-python), RAM, latch, beam, vblank interrupt; run_frame() bus.py # memory map, mirrors, I/O (the vector latch), the Z80 socket protocol syncbus.py # SyncBus: the NVC285's vector latch and access timing (sync-bus.md) video.py # Video: the NVC284 address order, tiles, sprites, PROM colour; per line wsg.py # Wsg: pin-shaped class: write(offset, nibble), clock(), output() (wsg.md) inputs.py # IN0, IN1, DIPs per row aux/mspacman.py # MsPacmanAux: wraps the Z80's bus (mspacman-aux.md) romset.py # MAME zips by CRC/SHA-1; per-row decode (pacplus, Eyes, Mr. TNT) savestate.py ``` Import boundary: z80-python owns the CPU; the board owns when INT is asserted, the byte on the bus at acknowledge, and every device. ## What the board needs from z80-python Nothing new for milestones 1-5 ([cpu-cores.md](cpu-cores.md)): IM 2 with a board-supplied byte exists; the board keeps the request asserted and refreshed. For the encrypted Pengo sets: an opcode-fetch (M1) hook on z80-python's main (open decision 6). ## Milestones | # | Milestone | Judge (tier) | Exit | | --- | --- | --- | --- | | M1 | **Board skeleton**: romset loader, map, latch, vector latch, watchdog, beam, vblank interrupt, inputs; no picture or sound | PMM (2); LOM (3) cross-check; MAME trace (5) | lockstep with MAME's `pacman` trace from reset (30 frames) and at frame 600 (3 frames): instruction stream, 5000-50FF writes, I/O writes, interrupt lines: `0 unexplained`; unit tests; seeded faults caught | | M2 | **Picture**: the NVC284 address order, tiles, sprites, PROM colours, flip, per-line drawing; sprite limits read from PMM (U4, U5) | PMM (2); MAME snapshots (5) | the power-on test screens, the attract maze and the intermission pixel-identical to MAME at fixed frames, or every difference explained from the schematic | | M3 | **`puckman` row, save states, smoke list** (pacman, puckman, crush, eyes, mrtnt, ponpoko) | PMM; the maker's service test | each boots to attract and passes its own test; a state saved mid-game reloads identically | | M4 | **WSG** traced from PMM's sheets (U7, U8), register file updated as the circuit does, 96 kHz | PMM (2); MAME and emu-galaga audio (5) | start-up jingle and siren match MAME's spectrum and envelope, differences named; voice-2/3 low nibble behaviour tested | | M5 | **Ms. Pac-Man auxiliary board** as a socket device; mapping fitted from MAME as a black box (FITTED) unless a PAL source appears | MSS (2) for parts; MAME (5) | `mspacman` lockstep with MAME for its attract and a scripted game: `0 unexplained` | | M6 | **Pengo** (`pengo`, unencrypted), **Jr. Pac-Man**, the plain rows | PGS (2); MAME | rows boot and lockstep | | M7 | **Decode rows**: `pacplus`, the 315-5010 Pengo sets (needs the M1 hook), other-sound and 2650 rows | MAME (5) | rows boot and lockstep | ## The chip rule | Chip | Other users in the family | Proposal | | --- | --- | --- | | Z80A | many | z80-python | | NVC284, NVC285 (and their TTL equivalents) | this board only (Galaga's board has its own customs) | in the board | | WSG (TTL + PROMs) | emu-galaga (Rust site, outside the shape); namcos1-python has a different chip (CUS30) | stays in the board behind a pin-shaped class; extract `namco-wsg-python` when a second x-python board (Galaga, Dig Dug, Bosconian) needs it (open decision 3) | | Ms. Pac-Man aux board | this board only | a socket device in this repository | | Sega 315-5010 | Pengo here; other Sega boards of its era | a decode table in the board, on z80-python with an M1 hook; not a new core | ## Domains and speed **Domains:** one. The Z80, the beam, the latch and the WSG all run from the 18.432 MHz crystal (CPU /6, pixels /3, WSG /192). The WSG is a pure producer: its only channel is the register file at 5040-505F (written by the CPU, never read back: LOM), so from `-fast` on it can run on its own thread from a write log with cycle stamps. The order of record steps the Z80 an instruction at a time, advances the beam by T-states x 2 pixel clocks, raises INT at line 224 while 5000 bit 0 is set, and logs WSG writes. **Instructions per second:** 3,072,000 T-states a second; at a typical 4-11 T-states an instruction (4 the floor) that is at most 768,000 and more likely about 400,000 Z80 instructions a second. Video: 264 x 60.606 = 16,000 lines a second, each 288 pixels from 36 tile fetches and up to 8 sprites. WSG: 96,000 voice updates a second x 3 voices (288,000 small steps), or the TTL sequence at 3.072 MHz / 32 per voice nibble if modelled at nibble level. **No-JIT path:** z80-python reached its 2.5 M instructions-a-second target on PyPy (its validation.md), several times this board's need, so the Python reference is near real time on desktop PyPy (the per-line video in Python is the larger cost; it is the specification's job to be readable, not fast). A Rust transcription needs about 0.4 M Z80 instructions a second; z80-rust-fast runs about 350 M a second on this machine: **real time on desktop, phone and browser without JIT, threads or turbo.** recompile: none. ## Unknowns (U) and conflicts (C) | # | Unknown | Best source now | Status | | --- | --- | --- | --- | | U1 | the vector latch's strobes: which I/O addresses load it, when it drives the bus | PMM p. 36 (NVC285 TTL equivalent), lower half | trace at M1 | | U2 | whether CPU accesses to video RAM are delayed (no WAIT pin on the NVC285) | PMM pp. 36-37 | none modelled (MAME none) | | U3 | the NVC284's address order in gates | PMM p. 38 | LOM's figures until traced | | U4 | the sprite line buffer's parts and rules | PMM sheets | trace at M2 | | U5 | sprites per line, sprite priority, transparency, edges | PMM; MAME as detector | trace at M2 | | U6 | the RGB resistor weights | PMM | LOM's values until read | | U7 | the role of PROM `3m` (sequencing or second waveform bank) | PMM sound sheets | trace at M4 | | U8 | the WSG's nibble-serial order and when the accumulators are written back | PMM sound sheets | trace at M4 | | U9 | Ms. Pac-Man's PAL equations | none held; MAME (BSD-3, closed tonight); David Widel's research (not fetched) | fit from MAME as a black box | | U10 | Pengo's and Jr. Pac-Man's differences in detail | PGS; MAME | at M6 | | U11 | power-on RAM contents | none | option; zero by default | | # | Conflict | Sides | Proposal | | --- | --- | --- | --- | | C1 | program ROM sizes | LOM's prose: "four 1K chips"; LOM's own table, the census and PMM's glossary (MCM2532, 4K x 8): 4 KB each | 4 KB (2 KB in `puckman`) | | C2 | the sound enable | LOM table: 5001; LOM prose: 50C0 (the watchdog's range) | 5001 until the 74LS259's wiring is read | | C3 | the WSG as "a custom chip" (LOM: "custom-made 3-channel Waveform Sound Generator") | PMM's glossary lists only TTL, RAMs and PROMs for it; the two customs are the V-RAM addresser and the sync bus controller | follow PMM: TTL | ## Open decisions for Aubrey (each with a recommendation) 1. **First machine.** Recommend `pacman` (Midway's set, whose manual we hold) with `puckman` as a row in M3. 2. **Ms. Pac-Man's mapping.** No document gives the PAL logic and MAME is closed tonight. Recommend fitting the mapping from MAME runs as a black box (every fetch address and the byte returned), recorded FITTED, and asking whether reading MAME's BSD-3 `pacman_m.cpp` for facts (with notice) is acceptable later, or whether David Widel's pages may be checked for terms and used. 3. **A shared WSG core.** Recommend **no** shared core with namcos1-python (the CUS30 is a different chip: 8 voices, waves in RAM, stereo, noise; namcos1-python reached the same view). Keep `Wsg` in this board behind a pin-shaped class and extract `namco-wsg-python` (WSG only, maybe the 15XX as a variant) when a Galaga, Dig Dug or Bosconian specification starts. 4. **Rebuild galemu in the x-python shape?** Recommend a later `galaxian-python` that pins the same z80-python as this board, with galemu kept as the player-facing app, so the Namco 8-bit line (Galaxian, Pac-Man, Galaga) shares pins and habits. Not now. 5. **Acknowledge-time vector.** Recommend the board-side refresh rule (cpu-cores.md) for now; raise an interrupt-acknowledge callback on z80-python only if a trace shows the program writing the latch while a request is pending. 6. **The M1 hook for encrypted Z80s.** Recommend landing the `z80-python-m1-hook` work on z80-python's main (upstream first) before the 315-5010 Pengo rows; it also serves other Sega encrypted boards. 7. **sources.md rows** (emulator-lineage): recommend adding the rows proposed in [sources.md](sources.md).