# Handoff: build `midwayyunit-python`, Midway's TMS34010 boards ## Context you are inheriting Chips are cores, boards compose cores; the board pins its cores by commit. This board's cores are **all Phase 0 tonight**: `../tms34010-python` (CPU; documents only), `../m6809-python`, `../ym2151-python`, `../msm6295-python` (documents only), and two that do not exist yet: `adsp2100-python` (DCS) and `pic16c5x-python` (Wolf security). The board cannot run a game until tms34010-python reaches its rung 4; it can be written against the core's agreed host contract in parallel. Era 2 (charter): several CPUs, cycle-lockstep, `-fast` needed, threads optional (sound). Rules: Python >= 3.11, CPython and PyPy; MIT; MAME is a closed box (decision 7); no game ROM, PIC dump, sound ROM or Midway artwork in the repository (`$MAME_ROMPATH`, SHA-1s in census.md); MAME output stays in git-ignored `tests/mame_traces/`; local git only; no sweeps. ### Read in this order README.md; docs/start-here.md; docs/cpu-needs.md; docs/domains.md; docs/dma-blitter.md; docs/video-and-palette.md; docs/protection.md; docs/sound-williams.md; docs/sound-dcs.md; docs/census.md; docs/validation.md; docs/mame-oracle.md; docs/provenance.md; then tms34010-python's handoff-brief.md (the host contract) and the TI User's Guide sections for the milestone at hand. ## Scope In: the Y-unit board (memory map, CMOS, inputs, watchdog, control register, protection port), the DMA blitter, VRAM with its serial side and autoerase, the palette, the video timing that the TMS34010's registers drive, the picture; the sound-board socket with the Williams CVSD and ADPCM boards; then the T-unit row (DMA2's 16 registers, its map, NBA Jam's protection device) and the DCS board; later the Wolf row (PIC16C57, DCS 8K) and the Z-unit row (Narc). Out: the CPU and sound chip cores (their own repositories); the X-unit (a TMS34020); hosts, windows, sites. ## Rows or siblings: rows (decision 1) Y, T and Wolf share the CPU, the clocking, the video timing (8 MHz, 506 x 289), the palette scheme and the DMA's way of working (a register block written last-register-starts, a busy bit, the CPU held off the bus); they differ in sizes (VRAM 256 KB / 512 KB, palette 8K / 32K entries), the DMA's register count (10 / 16, scaling and clipping on 16), the address map, and the sound board fitted. That is a machine-row difference, as `sms-python`'s 16 machines are. One repository with rows `Z`, `Y`, `T`, `W` keeps one DMA model with a row switch, one video model, one map builder; separate repositories would copy all three. ## Proposed names - Package **`midwayyunit_python`**; `midwayyunit_python.MidwayBoard(row, game)` with `row` in `"Y"`, `"T"` (later `"W"`, `"Z"`), and a per-game table (`games.py`: set name, CPU clock 40/48/50 MHz, ROM layout, sound board, protection responses) keyed by MAME set name and identified by the ROMs' SHA-1s. - Modules: `board.py` (the map per row, CMOS, inputs, watchdog, control), `dma.py` (one class, row-parameterised), `video.py` (the TMS34010 video registers, counters, display interrupt, serial transfers, autoerase), `vram.py`, `palette.py`, `picture.py` (the producer), `protection.py`, `sound/` (`socket.py` the protocol; `cvsd.py`, `adpcm.py`, `narc.py`, `dcs.py`; `hc55516.py`, `pia6821.py`, `dacs.py`), `domains.py` (the channels as code), `machine.py`. - Sockets (pin-shaped, so extraction is a move): the CPU (tms34010-python's host contract plus the two additions in decision 3), the sound board (`write_command`, `read_status`, `reset`, `run_until(time)`, `audio()`), the protection device (`read(bit_address)`, `write(bit_address, value)`). ## Import boundary The board imports `tms34010_python`, `m6809_python`, `ym2151_python`, `msm6295_python`, later `adsp2100_python` and `pic16c5x_python`, and nothing else of the family's. Cores never import the board. ## Unknowns (U) - U1 The DMA's control bits (transparency, flip, pixel depth, the constant-colour and skip modes) and registers 0/1 beyond start/busy - dma-blitter.md. - U2 The DMA's timing per pixel, per row, per transfer, with scaling - dma-blitter.md. - U3 How the DMA shares the bus: held for the whole transfer or per row; where the CPU stalls - dma-blitter.md, cpu-needs.md. - U4 The Y-unit's "Custom ASIC": no schematic sheet read tonight; its pins and identity. - U5 VRAM parts (the "48121") and the pixel format; the palette index width per row - video-and-palette.md. - U6 Autoerase mechanics; mid-line palette and VRAM effects - video-and-palette.md. - U7 Protection: which Y-unit games read `01C00060` and when; whether `mk` (T) checks anything; the parts that answer - protection.md. - U8 Sound-board clocks (8 MHz / 4 for the 6809E assumed); MSM6295 pin 7 as wired; the command latch's interrupt line (IRQ or FIRQ) per board - sound-williams.md. - U9 The 9 bytes past 4,096 in the Wolf PIC dumps - census.md. - U10 No HC-55516 data sheet; its slope and filter constants - sound-williams.md. - U11 DCS: the DAC's sample rate and the autobuffer setup; the boot-load sequence's timing - sound-dcs.md. - U12 No FPGA or HDL implementation of these boards was searched for in depth. - U13 The Wolf DMA's differences from DMA2 (no Wolf manual pinned). - U14 The TMS34010's per-instruction machine states for the polling loops (core rung 7) decide the per-frame instruction counts. - U15 The Y-unit's VCLK source (24 MHz / 3 assumed). ## Contradictions (C) - C1 The commission placed a PIC16C57 on the Y-unit; MAME 0.285 and the Y and T manuals' parts lists have none; it is on the Wolf and X units (protection.md). - C2 Smash T.V.'s parts list names a "TMS34010-50 GSP" but a 40 MHz crystal, and MAME clocks the game at 40 MHz: the part is rated 50, the board runs it at 40 (resolved: the crystal decides). - C3 MAME files the Y-unit Mortal Kombat sets as clones of the T-unit `mk`, and the Z-unit Narc in the Y-unit driver: names are not evidence of the board (census.md). - C4 tms34010-python calls FBNeo's TMS34010 core BSD-3; emulator-lineage sources.md lists FinalBurn Neo as non-commercial (cpu-needs.md). - C5 tms34010-python and m6809-python state Python 3.12+; the family floor is 3.11. - C6 The commission lists "Mortal Kombat 1/2 (Y/T)": MK1 exists on both Y and T; MK II only on T (with DCS). ## Milestones M1 Y-unit skeleton on `yunittst`; M2 video timing and picture; M3 DMA; M4 CVSD and ADPCM sound boards; M5 the T-unit row; M6 DCS; M7 seeded faults; M8 the Wolf row; M9 the Z-unit row. Exit tests in validation.md. First game targets: `yunittst`, then `smashtv` (CVSD) and `term2` (ADPCM), then `mk` and `nbajam` (T, ADPCM); `mk2` waits for DCS. ## Domains and speed Full arithmetic in [domains.md](domains.md). - **Domains:** Main (TMS34010 + DMA + VRAM + palette + video timing + I/O + protection; the DMA holds the CPU off the bus, so they cannot be split); Sound (a Williams 6809 board, or DCS); the Wolf's security PIC; the picture as a pure producer. - **Channels:** the sound command latch and its interrupt, the status/talkback port, sound reset, the DCS latches, the PIC's serial port: each a sync point on access. - **Need:** main CPU 6.25 M instructions/s ceiling (50 MHz / 8), 1.8-2.8 M as MAME runs the games; DMA 11-12 M pixels/s in a fight scene; ADSP-2105 10 M instructions/s (98.7 % a wait loop); 6809 0.4-1 M; YM2151 1.79 M operator slots; MSM6295 30 k voice-samples. - **No JIT anywhere:** estimates put the whole board at 2.5-4x real time on one desktop core from the plain transcription (x-rust), real time on an iPhone app and in a desktop browser at x-rust, and on a phone browser or an A55-class handheld with -fast, an exact DCS wait-loop skip and a sound thread. All main-CPU code is ROM, so a cached interpreter would be exact by construction, but it is not needed. `recompile: none`. - **Python** runs the main CPU at about 1/3 to 1/60 of real time and DCS at 1/10 to 1/100: targeted windows only. ## Open decisions for Aubrey 1. **The T-unit (and later Wolf and Z) as machine rows of this repository, not siblings; the X-unit out.** Recommended: they share the CPU, the clocks, the video and the DMA's design; the differences are sizes, register counts and the sound board. Keep the name `midwayyunit-python` (the commission's) although it will hold T and W rows; a rename to `midway34010-python` before the first public push is the alternative. 2. **The DMA at transaction level** (each transfer's pixels in the hardware's order, a duration from FITTED per-pixel and per-row costs, the CPU held off the bus for it), judged by `yunittst`'s DMA tests. Recommended (provisional, chip-level). 3. **tms34010-python goes first, with three changes to its brief:** Python 3.11 floor; two new host-contract items this board needs (HOLD/HLDA: "bus held until time T"; an SRT callback for shift-register transfers); and a provenance pass (its documents cite MAME's BSD-3 TMS34010 source by line, and it names FBNeo's TMS34010 core BSD-3 against sources.md's non-commercial row). Recommended: the board is blocked on it. 4. **`pic16c5x-python`: a new CPU core extracted with history from famicom-python's `pic16c54.py`**, grown to the PIC16C57, pinned by famicom-python and this board. Recommended, but only when the Wolf row starts; Y and T need no PIC. 5. **`adsp2100-python`: a new CPU core (ADSP-2105 first) with its own Phase 0.** Recommended; MK II and every Wolf game need it. DCS itself stays a sound board inside this repository until a second family board needs it. 6. **HC-55516, the 6821 PIA and the DACs stay inside the board** (chip rule: one family user), as do the Williams sound boards and DCS behind the sound socket. Recommended. 7. **MAME's Midway files are BSD-3-Clause** (`midyunit*.cpp`, `midtunit*.cpp`, `midwunit.cpp`, `williamssound.cpp`, `dcs.cpp`, `midwayic.cpp`; licence lines read tonight). The DMA's mode bits (U1) have no other written source. Recommended: allow facts-only reading of those named files, with the notice in NOTICE.md and every fact tagged OBSERVED (MAME), because the alternative, inferring the same MAME behaviour from bus taps, yields the same tier-5 facts more slowly. Keeping them closed (as psx-python chose for its BSD files) is the alternative. 8. **Sites set aside by the robots.txt rule:** arcade-museum.com (blocks ClaudeBot) and ww1.microchip.com (blocks all but search engines). famicom-python already pins Microchip's DS30453E from ww1.microchip.com, fetched before the rule: recommended, re-pin it there to bitsavers' 1992 scan (the same chip family's data sheet) and record the host as set aside. 9. **First-light order: `yunittst` -> `smashtv` -> `term2` -> `mk` (T) -> `nbajam` -> `mk2` (DCS)**, with the ADPCM games before any DCS game because they need no new CPU core. Recommended.