# Handoff: build `irem-python`, Irem's M72 family and M92 boards ## 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). The M72 and M92 are era 2 in the charter's table: several CPUs, still cycle-lockstep, `-fast` needed, threads optional (sound). Boards to model this one on: **system16-python** (Phase 0: a 1986-88 arcade family with rows, a Z80 sound CPU, a YM2151, an i8751 MCU and a proposed mcs51-python), **pcengine-python** (machine rows, sockets, a CPU with a SoC: huc6280), **sega32x-python** (two CPU cores on one board, ROMs by SHA-1). Cores it embeds or needs, read and not touched here: **i8086-python** (Phase 0 only, `6dd7152`), **z80-python** (`1302260`), **ym2151-python** (Phase 0, `3207328`), **v30mz-python** (Phase 0, the reason the V30MZ stays apart), a future **mcs51-python**. Read in order before writing code: [boards.md](boards.md), [memory-map.md](memory-map.md), [video.md](video.md), [sound.md](sound.md), [protection.md](protection.md), [cpu-cores.md](cpu-cores.md), [domains-and-speed.md](domains-and-speed.md), [sources.md](sources.md), [validation.md](validation.md), [mame-oracle.md](mame-oracle.md), [census.md](census.md). Then `python -I scripts/fetch_references.py`. ## Decided by Aubrey (standing rules that apply here) - Name `irem-python`, package `irem_python`. Local, no remote, until he says otherwise. - Bring your own ROMs: MAME's non-merged sets through `MAME_ROMPATH`, identified by SHA-1; nothing of Irem's or Nanao's in the repository. - Python floor = PyPy's (3.11), PyPy must work, classes under ~80 attributes; modern over compat; reference boards are correct, not fast; sound may be less exact than pictures; smoke lists before sweeps; technical choices made, marked provisional and reported. - MAME and every GPL/LGPL emulator or HDL are closed boxes; author respect (furrtek lineage) and site wishes (robots.txt) as recorded in [sources.md](sources.md). ## Proposed by this Phase 0 - **One repository with machine rows** (`m72`, `m72-dac`, `m72-mcu`, `m84`, `m72-v35`, `m92`, `m107`, `m90`), **R-Type (`m72`) first** (open decision 2). - **One NEC core, i8086-python, with V30, V33 and V35 rows**; the V35 Software Guard's table as a constructor input (open decisions 1 and 5). - **mcs51-python** for the i8751, shared with system16-python (open decision 4). - **The µPD71059 in the board, extracted as i8259-python** at the M72's interrupt milestone, as ibmpc-python proposes. - The GA20, the video chips, the dual-port RAM and the DAC stay in the board. ## Package and classes (proposed) ``` irem_python/ machine.py # rows: board, clocks, maps, video system, sound system, MCU, V35 table id, # set SHA-1s; built from the census, never from file names board.py # build(machine, rompath) -> Board; the order of record across domains bus_m72.py # the M72-family main bus: ROM, RAM, video/palette/sprite RAM, the sound # RAM window, I/O 00h-87h, the MCU's dual-port window bus_m92.py # the M92/M107 main bus, the V33 page registers left to the core pic.py # Upd71059: ICW/OCW, IR0-IR7, INTA vector (extracted later, see above) video_m72.py # M72Video: raster 512x284 @ 8 MHz, two tile layers, sprite DMA + buffer, # palettes, priority PROMs, interrupts video_m92.py # M92Video: raster 424x262 @ 6.67 MHz, GA21/GA22 behaviour, buffer RAM DMA sound_m72.py # M72Sound: z80-python + ym2151-python + RST interrupt buffer + latch + DAC sound_m92.py # M92Sound: the V35 row + ym2151-python + Ga20 + the two latches ga20.py # Ga20: 4 PCM channels from the sample ROM mcu.py # the i8751 socket: mcs51-python + the MB8421 dual-port RAM sockets.py # Protocols (CPU bus, sound port, MCU port, video port) and test fakes savestate.py # whole-machine states naming the set by SHA-1s ``` **Import boundary.** The cores own instruction semantics, registers, clocks per access, the V33's page registers and XAM, the V35's internal RAM, SFRs and peripherals, the Software Guard translation, interrupt acceptance. The board owns every address decode, wait state, the PIC, video, sound chips other than the YM2151, the latches, the dual-port RAM, the inputs, and the per-set translation table data. **Sockets.** `MainCpuSocket` (V30 / V33 / V35 behind one bus interface), `SoundSocket` (Z80 system or V35 system), `McuSocket` (empty on non-MCU rows; a fake that answers the shared RAM for tests), `VideoSocket` (M72 or M92 video). ## What the board needs from its cores (the embedding contracts) From **i8086-python** (all rows): `read8/write8/read16/write16(addr, kind)` and `in8/in16/out8/out16(port)` returning or taking the host's wait clocks, `kind` = fetch, data, stack, interrupt acknowledge; `set_intr(level)` with an acknowledge callback returning the vector byte (the PIC); `set_nmi`, `set_reset`; `step() -> clocks`; a `variant` of `"v30" | "v33" | "v35"`; for the V35, `opcode_table: bytes | None` and the N/S pin level, and its peripherals' pins (INTP, the ports, the serial lines unused here). From **z80-python**: IM 0 with an opcode byte supplied at acknowledge (RST n from the RST buffer), the INT line as a level, NMI (if U13 needs it), I/O callbacks. From **ym2151-python**: register writes with their time, the /IRQ output as a level, the two-channel output at clock / 64. From **mcs51-python** (when it exists): the 8751 row with its 4 KB internal ROM, MOVX callbacks on the external data space, port pins, interrupts. ## The gate (defined at milestone 1) The board's lockstep cases: the main CPU's instruction stream and registers against MAME's trace (`scripts/mame_trace.py --frames N`, `0 unexplained` over a stated number of frames), its unit tests of the documented facts (VDB91, V30UM, MCS51, RTMAN, M84SCH), and later its picture and audio rows against MAME. Every gate case runs on both rows that share code (an M72 change must not move the M92's cases), and seeded faults ([validation.md](validation.md)) each fail it. ## Milestones | # | Milestone | Judge (tier) | Exit | | --- | --- | --- | --- | | M0 | **Core prerequisites (in i8086-python, not here):** its 8086 rungs, then its V30 row | SingleStepTests/8088, 8086, v20 (1) | i8086-python's own exits: v20 360 files, 3,125,000 cases, 0 failed | | M1 | **`m72` skeleton on R-Type:** the main bus and I/O map, the µPD71059, a raster skeleton (512 x 284, VBLANK on IR0, the raster compare on IR2), inputs and DIP switches, the sound socket fake | V30UM, VDB91 ICU (2), RTMAN (2); MAME trace (5) | `rtype` runs from reset with its instruction stream equal to MAME's for 10 frames (about 110,000 instructions: 11,186 per boot frame) or a named reason per difference; the ICW sequence 17h/20h/0Fh seen; seeded faults caught | | M2 | **M72 video:** two tile layers, scroll, sprites with the DMA and buffer, palettes, priority | MAME pictures (5); M84SCH B board wiring (2) | R-Type's title and attract play drawn; every pixel difference against MAME snapshots at fixed frames triaged; U1, U2, U15, U16 answered or marked | | M3 | **M72 sound:** z80-python behind the latch and RST buffer, the sound-RAM window and the Z80's release, ym2151-python (or a register-log stub until it exists), the DAC on `m72-dac` rows | z80-python's ladder (1); MAME's Z80 trace (5) | R-Type's Z80 instruction stream equal to MAME's for 10 frames after release; YM2151 register writes equal to MAME's log; audio compared and differences named | | M4 | **`m84` row** (R-Type II, Hammerin' Harry): the moved maps, the Z80 ROM | M84SCH (2); MAME (5) | both sets lockstep for 10 frames; C1 settled or recorded with both clocks selectable | | M5 | **`m72-mcu` row:** mcs51-python (after its own Phase 0 and rungs) with the MB8421 | MCS51 (2); MAME's MCU trace (5) | `nspirit` and `imgfight` lockstep on both the V30 and the MCU for 10 frames; U6, U7 answered | | M6 | **The V33 and V35 rows (in i8086-python)** | VDB91, VINS, V35INS (2); MAME lockstep (5) | unit tests per documented instruction and clock row; V35 SoC peripherals the M92 sound program touches | | M7 | **`m92` row:** main bus, V33 page registers, M92 video (GA21/GA22 behaviour, buffer DMA), the sound domain with the V35S table per decision 5, the GA20 | M92DOC (3); MAME (5) | `gunforce` main and sound lockstep for 10 frames each; title and attract pictures triaged; GA20 register log equal to MAME's | | M8 | **`m107`, `m72-v35`, `m90` rows** as wanted | MAME (5) | `airass`, `cosmccop`, `dynablst` lockstep for 10 frames | ## Unknowns (U) and contradictions (C) | # | Unknown | Best source now | | --- | --- | --- | | U1 | M72 tile and sprite formats (bit planes, attributes, sizes, flips) | the ROMs and MAME's pictures; no document | | U2 | M72 palette format (512 colours; component width) | MAME; M84SCH B board | | U3 | The M92 V33's clock and crystal (MAME 9 MHz; the board capture's video crystal is 26.6666 MHz) | the M92 main board's other sheets; a board photo | | U4 | M72 decode details: mirrors, open bus, what the PALs `m72_a-3d`, `m72_a-4d` do | MAME's PAL dumps (in the sets) decoded; M84SCH | | U5 | How the V30 releases R-Type's Z80 after loading its RAM | MAME trace of the boot (watch I/O 02h) | | U6 | What the i8751 does on each MCU game (shared-RAM protocol; samples?) | run the dumped programs | | U7 | MB8421 mailbox interrupts at the top of the dual-port RAM | the Fujitsu data sheet (not fetched) | | U8 | Wait states on the M72 and M92 main buses | M84SCH (the 71011's RDY inputs, WAIT- net on sheet 3); M92DOC | | U9 | How many distinct Software Guard tables exist (17 first-byte classes seen) | the tables themselves (decision 5) | | U10 | Whether segment-override and REP prefixes are translated as "first bytes" | VDB91 is silent; the tables applied to real code | | U11 | Whether interrupt vector reads and macro-service transfers bypass translation | VDB91 implies only opcode fetches; confirm in code | | U12 | The M72 Z80's RST buffer wiring (which request makes which RST) | M84SCH sheet 7 gates | | U13 | How M72 samples are stepped (Z80 per sample, NMI, or a board counter) | MAME trace of a DAC set (`xmultipl`) | | U14 | GA20: stereo or mono; register layout; pitch and volume curves | MAME register log and `-wavwrite`; board audio captures (decision 8) | | U15 | When the M72 sprite DMA copies and whether it stalls the V30 | M84SCH; MAME trace around I/O 04h writes | | U16 | What the M72 PROMs `m72_a-8l`, `m72_a-9l` decide | M84SCH; MAME pictures | | U17 | The M84 PIC's INTP1 ("TRBL") | M84SCH net names | | U18 | V33 8080 emulation mode (VDB91's V33 sheet never names BRKEM) | VDB91 V33 instruction table | | U19 | Any hardware-captured V33 or V35 test corpus | none found | | U20 | Whether the M72 MCU has its own crystal | a board photo; the M72 schematic (decision 6) | | U21 | M92 latch interrupts on each side | M92DOC `audio_cpu`, `shared_memory` | | U22 | V33 against V33A differences relevant to VINS's V33A clock rows | VDB91 V33 vs VINS | | U23 | Whether any M92/M107 game uses the V33's expanded addressing | MAME trace: writes to I/O FF00h-FF80h, BRKXA | | # | Contradiction | Sources | Resolution for now | | --- | --- | --- | --- | | C1 | M84 main CPU clock: 10 MHz (20 MHz oscillator into a µPD71011 through jumper J8) or 8 MHz | M84SCH sheet 3 + VDB91 µPD71011 (2) against MAME (5) | the drawing outranks MAME on what the board can do; the jumper's fitted position is unknown: make the clock a machine-row field, default MAME's 8 MHz for lockstep, record both | | C2 | i8086-python's brief: "no bus-cycle timing, no prefetch queue model" | against the charter's cycle level for 16-bit CPUs, ibmpc-python's decision 1, and this board's wait states | decision 1 | | C3 | i8086-python's documents restate MAME `m72.cpp` and cite `nec.cpp` line numbers (BSD-3, read by an earlier agent) | against this batch's closed-box rule | legally clean (BSD-3); cite those facts as MAME (tier 5) via i8086-python; decision 5 | | C4 | i8086-python's brief says Python 3.12+ | the family floor is PyPy's 3.11 (also noted by ibmpc-python) | follow the family floor | ## Domains and speed **Domains** ([domains-and-speed.md](domains-and-speed.md)). M72: **main** (V30, PIC, video on the same 32 MHz master), **sound** (Z80, YM2151, DAC; 3.579545 MHz crystal), **protection** (i8751) on MCU rows. M92/M107: **main CPU** (V33, PIC), **video** (26.6666 MHz crystal, GA21/GA22), **sound** (V35S, YM2151, GA20; 14.31818 MHz). Channels: the sound latches and the sound reset; R-Type's sound-RAM window; the MB8421 dual-port RAM; video RAM, palettes, the DMA triggers and scroll registers; the interrupt lines. **Instructions per second**, measured on MAME with every instruction logged (frames 901-903; all CPUs busy all frame): - M72 (`rtype`): V30 12,492-14,566 instructions per frame x 55.02 Hz = 0.69-0.80 M/s; Z80 8,131 x 55.02 = 0.45 M/s; on MCU rows the i8751 8,065 x 55.02 = 0.44 M/s. Total **≈ 1.7 M instructions/s**, plus 512 x 284 x 55.02 = 8 M dots/s and 3,579,545 / 64 x 32 = 1.79 M FM operator steps/s. - M92 (`gunforce`): V33 28,246 x 60.01 = 1.70 M/s; V35 15,730 x 60.01 = 0.94 M/s. Total **≈ 2.6 M instructions/s**, plus 424 x 262 x 60.01 = 6.67 M dots/s. M107 (V33 at 14 MHz) ≈ 3.6 M/s, estimated. **The no-JIT path.** Python (PyPy) is below real time, as reference boards may be. Rust `-rust`/`-fast` reaches real time on desktop with a large margin; on phone and in the browser (wasm) `-fast` is expected to reach real time with run-ahead of 1-2 frames, since 2-4 M simple instructions/s is light for a compiled interpreter (to be measured). A cached interpreter is not expected to be needed; threads at the sound channel are the first lever if a phone falls short. **`recompile: none`** for every row. ## Open decisions for Aubrey 1. **One NEC core: V30, V33 and V35 as rows of i8086-python** (not a new `nec-v-python`, and not merged with v30mz-python). *Recommend yes*, together with ibmpc-python's request that i8086-python gain a bus-cycle host interface (C2): both boards need per-access wait states. If i8086-python is to stay instruction-level only, then a separate `nec-v-python` with the bus interface is the fallback. 2. **M92 as a row of irem-python, not a sibling repository**, with R-Type (`m72`) first and M84, M72-MCU, M92, M107, M72-V35, M90 as later rows. *Recommend yes* (boards.md: shared CPU family, PIC, latch-and-YM2151 sound, I/O layout). 3. **M62 (Kung-Fu Master, Lode Runner) out of this repository**, as its own `m62-python` if wanted (Z80 + MC6803 + AY-3-8910 + MSM5205: nothing in common with the M72 but the maker). *Recommend out.* 4. **mcs51-python Phase 0 before the `m72-mcu` row**, shared with system16-python (its decision 5). *Recommend yes*; this board adds 13 dumped i8751 sets. 5. **How to obtain the V35 Software Guard tables** (protection.md): (a) read MAME's `irem_cpu.cpp` for the tables only, BSD-3-Clause with its notice; (b) measure them from the MAME binary through the debugger's disassembler, 256 probes per table, no source opened; (c) derive them from the ROMs ourselves. *Recommend (b)* now (a closed-box measurement within this batch's rule, tagged tier 5, cheap), with (a) as a cross-check only if Aubrey opens MAME's BSD files; the same decision answers C3 for i8086-python's MAME-derived facts. 6. **The MiSTer M72 core is set aside (furrtek lineage: its KNA70H015 model credits furrtek's reverse engineering).** Its `docs/` holds scans of Irem's own M72 and M84 schematics, a µPD71059C data sheet and R-Type's manual, none of them furrtek's work. *Recommend:* allow those scans as separate documents (Irem's and NEC's, facts only), fetched by SHA-256 from the repository's raw files, never its HDL or its notes; until Aubrey says so, nothing from it is used, and the M84 drawings from archive.org cover the family. 7. **The M84 clock (C1).** *Recommend:* a machine-row field with MAME's 8 MHz as default and the drawing's 10 MHz selectable, both recorded, until a board photo shows J8. 8. **Outside contact for audio captures** (M92 GA20 output from real boards, MiSTer community). *Recommend:* Aubrey's call; not needed before M7, and sound may be less exact. 9. **Proposed sources.md rows** ([sources.md](sources.md), end): add the NEC V-Series data book and manuals, the M84 schematics, the R-Type manual, the M92 board capture, the MiSTer M72 core as set aside (author's wishes), the M92/M107 cores as closed boxes, the MAME Irem files' BSD-3 headers, PLD Archive / system16.com / arcade-museum.com as set aside (site's wishes), Furnace's AI-contribution policy. *Recommend yes.*