# Handoff: build `pc88-python`, the NEC PC-8801 board ## Context you are inheriting Chips are cores, boards compose cores; the board pins its cores by commit; CPUs always get their own core; a non-CPU chip stays in its board until a second family board needs it. The PC-8801 is era 1: Python runs the tests and Rust plays. Its peculiarities: **two Z80 computers** (the main machine and the disk unit, which runs its own ROM and whatever code games upload to it) joined only by a cross-wired 8255 pair; a **text screen fed from main RAM by DMA**, which costs the CPU time; a sound chip that changes by model (none, OPN, OPNA). Nearest family models: `cpc-python`, `msx-python` (Z80 + 8255 + uPD765-family, Phase 0 2026-11-26), `sms-python` (built; holds the family's 8255 and uPD765), `dkong-python` (an 8257 in board), `segacd-python` and `sega32x-python` (boards with a second CPU domain). Rules: Python >= 3.11, CPython and PyPy; MIT; nothing read from GPL, LGPL, unlicensed or non-commercial emulators (QUASI88 and M88 are closed boxes); no firmware, disk, tape or CD in the repository; `MAME_ROMPATH`, `MAME_HASHPATH`, `REDUMP_DIR`, `PC88_MIRROR_DIRS` (proposed); local git only; no sweeps. ### Read in this order README.md; docs/start-here.md; io-map-and-memory.md; cpus-and-disk-subsystem.md; video.md; sound.md; interrupts-and-peripherals.md; reuse.md; domains-and-speed.md; validation.md; mame-oracle.md; census.md; sources.md; provenance.md. Then the YK pages in full (`reference/docs/youkan/`) and KAISEKI's chapter 5 before M1. ## Scope In (row `mk2sr`): main Z80, memory and banking (ROM modes, text window, GVRAM independent and extended access, high-speed text RAM), uPD3301 + uPD8257 text, graphics and palette, the 8214, the 600 Hz timer, VRTC, keyboard, DIP switches, beeper, uPD1990A, the 8251 (cassette later), the OPN, the disk unit as a second Z80 with the uPD765A and two 2D drives, D88 images. Later rows: `mk2fr`/`mk2mr` (2HD with the 8 KB disk ROM), `fh` (8 MHz, OPN, 6Eh, 6Fh), `mh`, `ma` (OPNA, expansion RAM, dictionary ROM), `ma2`, `fa`, `mc` (CD-ROM). V1-mode rows for the PC-8801 and mkII. Out: the PC-88VA; the 8-inch DMA disk interface; the expansion boards other than the Sound Board II (later, as sockets). ## Proposed names - Package **`pc88_python`**; `pc88_python.PC88(model="mk2sr", dip=..., roms=..., drives=...)`, ROMs checked against census.md's SHA-1s. - Modules: `bus.py` (memory map, banking ports 31h/32h/5Ch-5Fh/70h/71h/E2h/E3h, I/O decode), `crtc.py` (uPD3301), `dma.py` (uPD8257, pin-shaped), `video.py` (text from the row buffers, attributes, GVRAM, ALU, palette; producer), `pic.py` (8214 and the masks), `ppi.py` (until `i8255-python`), `rtc.py` (uPD1990A), `usart.py` (8251), `keyboard.py`, `diskunit.py` (the second Z80, its ROM and RAM, its 8255, the FDC, drives: a domain), `fdc.py` (until `upd765-python`), `disk.py` (D88), `sound.py` (the OPN/OPNA socket), `machine.py`. - Sockets: the disk unit (so an external PC-80S31 and the internal unit are one thing), the expansion slot (INT2, INT4, the Sound Board II), the cassette, the joystick (SSG ports), the printer. ## Import boundary The board imports `z80_python` (twice), the OPN/OPNA core of decision 2, later `i8255_python`, `upd765_python`. The disk unit's Z80 sees only its own bus. ## Unknowns (U) and contradictions (C) - U1 Open-bus values of undecoded ports. - U2 GVRAM access waits per mode. - U3 Any difference between the uPD70008C-8 and a Z80. - U4 The disk unit's port F8h (written 05h, FFh) and F7h (08h) meanings. - U5 The uPD765A's interrupt to the unit's Z80 (wired or polled). - U6 The uPD3301's parameter and command bits (no data sheet found). - U7 The text DMA's cost to the main CPU per row and frame. - U8 The V1S "high-speed" graphics mode's exact effect on waits. - U9 The IM 2 vector formula for the 8214's levels. - U10 The 600 Hz timer's source. - U11 The 8214's behaviour when E4h is written with a request pending. - U12 Which command the first disk-unit byte (0Fh at 2.017 s) answers. - U13 Main-CPU writes to C1h, C3h, C8h, CAh at boot (not in YK-IO). - U14 A uPD1990A data sheet. - C1 **FH/MH's sound chip**: OPN by NEC's FH Programmer's Guide (tier 2) vs OPNA by youkan's I/O map and MAME's `pc8801mh`. Follow NEC: FH and MH carry the OPN. - C2 The main CPU clock: 4 MHz by NEC's documents vs 3.9936 MHz in MAME (a 31.9488 MHz / 8 derivation, HYPOTHESIS). Use the precise figure once a crystal is documented. - C3 The uPD3301 "is an 8275 with extensions" (common description) vs no NEC document in hand: every 8275 fact is HYPOTHESIS for the uPD3301 until decision 7 resolves it. ## Milestones Exit tests are validation.md's rungs. - **M1** Main machine to the BASIC prompt with the disk unit absent (DIP: no disk), the uPD3301/8257 set-up and text (R0 without the disk part, R2). - **M2** The disk unit as a second Z80 domain; the 8255 link; the disk start-up prompt "How many files(0-15)?" (R0, R1). - **M3** Graphics and palette (R3); interrupts (R4). - **M4** Disk: D88 2D boots through the real disk ROM (R5), after decision 6. - **M5** OPN through the new core (R6), after decision 2. - **M6** The text DMA's CPU cost (R7), FITTED and tagged. - **M7** FH row (R8); **M8** MA row with OPNA (R9); **M9** seeded faults (R10). ## Domains and speed (docs/domains-and-speed.md in full.) - **Domains:** main (Z80, memory, uPD3301 and uPD8257 which hold its bus, GVRAM, 8214, 8251, uPD1990A, keyboard, the main 8255); the **disk unit** (Z80, ROM, RAM, uPD765A, its 8255), whose only channel is the cross-wired 8255 pair; sound (OPN/OPNA: register port channel and the level-4 IRQ); a picture producer. - **Need, with arithmetic:** main 3,993,600 T-states/s, 511,000 instructions/s at MAME's 7.8 T-states average (8 MHz rows about 1 M/s); disk unit 4,000,000 T-states/s, 559,000 instructions/s at 7.2; text DMA 3,000 bytes a frame, about 180,000 bytes/s; OPN 55.5 kHz. - **No-JIT path:** reaches real time everywhere. Anchors: colecovision-python 0.30-0.47 x real time CPython, 0.60-2.9 x PyPy (MEASURED); z80-rust-fast 344-397 M instructions/s (MEASURED). x-python 0.15-0.3 x CPython, 0.4-1.5 x PyPy (estimate); x-rust above real time on desktop, phone and browser; x-rust-fast with run-ahead and rewind. `recompile: none`. Threads at the disk link are possible (the cleanest channel in the family's Z80 boards) but not needed. ## Open decisions for Aubrey 1. **Scope and order: mkII SR first, then FH and MA rows; the original and mkII as V1 rows.** Recommended: the SR is the machine most software targets (V2 mode, OPN), and the FH/MA add an 8 MHz clock and the OPNA on the same board. 2. **A new `ym2608-python` (OPNA) core with a YM2203 (OPN) row**, its SSG delegated to `ay8910-python`'s YM2149 row, YM2608-LLE and YM2203-LLE as closed-box judges, ymfm as comparator; ym2610-python later pins its FM block. Recommended (ym2610-python's own decisions said to extract a shared OPN core "when a YM2203 or YM2608 is wanted"; the PC-88 and the PC-98 Phase 0 both want them). Not an extension of ym2612-python (OPN2 lacks the SSG, rhythm and ADPCM and has its own output stage). 3. **MAME's PC-8801 files are BSD-3 (driver, disk unit, uPD3301 device): may a later session read them, with notice, for the uPD3301 (U6) and the disk unit's ports (U4)?** Recommended: yes for `video/upd3301.cpp` only, and only if no NEC uPD3301 document turns up first (decision 7), after a per-file licence check and with NOTICE.md; the driver stays a closed box as the brief says. 4. **The uPD8257 stays in the board**; extract `i8257-python` when dkong-python builds its own (two users then). Recommended. 5. **Support extracting `i8255-python` from sms-python with history** (msx decision 6, cpc decision 5, x1-python decision 5). Recommended: the PC-88 needs mode 0 and port C bit set/reset for the handshake. 6. **Support extracting `upd765-python` from sms-python with history** (zxspectrum decision 3, cpc decision 6). Recommended: the PC-88 adds the polled two-drive unit and 2HD on the MR. 7. **The uPD3301 document gap.** Recommended: ask whether you can obtain NEC's uPD3301 data sheet or the mkIISR Technical Map (National Diet Library digital collection, which youkan cites); an agent should not fetch from the NDL without your say. Until then the 8275 sheet is a marked proxy. 8. **Ask z80-python (public: your call) for per-access wait states and DMA stalls (Z1)**, together with segasys1-python's identical request. Recommended: the text DMA cost is the PC-88's chief timing behaviour. 9. **No full PC-88 library.** Recommended: add `PC88_MIRROR_DIRS` to the family's environment file now (about 125 games on hand, enough for a smoke list); decide on a TOSEC PC-88 set when the board reaches M4. 10. **Contradiction C1: FH/MH carry the OPN** (NEC's FH guide). Recommended; MAME's `pc8801mh` stays a detector with a known difference. 11. **Proposed sources.md rows**: the nine rows at the end of docs/sources.md.