# Handoff: build `x1-python`, the Sharp X1 board ## Context you are inheriting Chips are cores, boards compose cores; the board pins its cores by commit and raises their corners there; CPUs always get their own core; a non-CPU chip stays in its board until a second family board needs it. The X1 is era 1 (charter): one main domain at cycle level, Python runs the tests and Rust plays. Its peculiarities: **every I/O port is 16-bit** and the video memories live in I/O space; a **sub-CPU with no dumped firmware** owns the keyboard, clock and cassette; the plain X1's **PCG** depends on the CRTC's raster position. Nearest family models: `cpc-python` (Z80 + 6845 + 8255 + AY, Phase 0 2026-11-26), `msx-python` (Z80 + 8255 + AY + WD-family FDC), `colecovision-python` and `sms-python` (built Z80 boards), `x68000-python` (the YM2151 beside a CRTC, Phase 0 2026-11-26). Rules: Python >= 3.11, CPython and PyPy; MIT; nothing read from GPL, LGPL, unlicensed or non-commercial emulators (MAME's X1 driver is LGPL-2.1+: run as a binary only); no firmware, disk or tape in the repository; `MAME_ROMPATH`, `MAME_HASHPATH`, `X1_MIRROR_DIRS` (proposed); local git only; no sweeps. ### Read in this order README.md; docs/start-here.md; io-map-and-memory.md; cpu-and-z80-peripherals.md; video.md; subcpu.md; sound.md; fdc.md; reuse.md; domains-and-speed.md; validation.md; mame-oracle.md; census.md; sources.md; provenance.md. Then SX1 (`python -I scripts/fetch_references.py`, then the scan from archive.org for any page whose OCR is doubtful) chapters 0, 1, 2 and 4 in full before M1. ## Scope In (row `x1`): Z80A, 64 KB RAM, IPL ROM switch, 8255②, HD46505, text/attribute/PCG/CG, graphics planes, palette and priority, the CTC at 1FA0h, the high-level sub-CPU (keyboard, clock/calendar, timers, cassette deck control), the AY with joysticks, the MB8877A with four drives and D88/2D images, the FM board socket (CZ-8BS1: YM2151 + its CTC). Later rows: `x1turbo` (400 lines, kanji ROM, 1FD0h, SIO, DMA, 32 KB IPL), `x1turboz` (palette modes, built-in OPM). Out: the X1twin's PC Engine half; tape audio as waveforms (the sub-CPU and a TAP player first); the 8-inch drives; printers. ## Proposed names - Package **`x1_python`**; `x1_python.X1(model="x1", ipl=..., cg=..., fm_board=False, drives=...)`, ROMs checked against census.md's SHA-1s. - Modules: `bus.py` (memory, IPL switch, the 16-bit I/O decode table of io-map-and-memory.md), `crtc.py` (HD46505, pin-shaped until `crtc6845-python`), `video.py` (text, attributes, CG, PCG, graphics, palette, priority; a producer from a per-line log), `ppi.py` (until `i8255-python`), `ctc.py` (until a `z80-peripherals-python` core; daisy chain module), `subcpu.py` (`SubCpu`: table 4-1, keyboard matrix, RTC, timers, deck; FITTED delays in one table), `fdc.py` (until `wd179x-python`), `disk.py` (D88, 2D), `tape.py` (TAP), `fm_board.py` (socket: `ym2151_python` + its CTC), `machine.py`. - Sockets: the FM board slot, the cassette deck, four drives, two joysticks, the printer. ## Import boundary The board imports `z80_python`, `ay8910_python`, `ym2151_python` (FM board), later `crtc6845_python`, `i8255_python`, `wd179x_python`, `z80_peripherals_python` as decisions land. The cores never import the board. ## Unknowns (U) and contradictions (C) - U1 Whether every CZ-800C has the 1FA0h CTC on the main board. - U2 The 4 KB IPL's image across the 32 KB ROM window. - U3 The HD46505's character clock per mode (MAME: 894.88 kHz on `x1`). - U4 The RED and GREEN plane bases; the simultaneous-write rule (1A02h). - U5 Undecoded I/O reads; MAME's 255 reads of 4000h before the first OUT. - U6 Memory and I/O wait states (none documented; MAME shows none). - U7 The plain X1's PCG raster-timed access rule. - U8 HD46505S against the CPC's measured type-0 rules. - U9 The sub-CPU part: 80C49 (SX1) or an 8050-class part (MAME's 4 KB `80c48`). - U10 The sub-CPU's position in the interrupt daisy chain relative to the CTC. - U11 The sub-CPU's response delays per command (FITTED from MAME's model, a detector). - U12 The AY's and OPM's mixing levels and stereo wiring. - U13 The other CTC-carrying boards ("立体ボード"). - U14 MB8877A differences from the FD1793 that FUJ87 states. - U15 The FDC's INTRQ wiring (interrupt or polled). - U16 A permissively described D88 format. - U17 Why MAME's IPL loops on E4h/00h for 2 s (MAME's model or the IPL's design). - U18 A Sharp service manual or schematic for the CZ-800C on a host we may fetch from. - C1 The CZ-8BS1's OPM clock: 4 MHz (SX1 ch. 11) vs 2.00 MHz (MAME 0.285 `x1turbo`). Follow SX1. - C2 The FM board's CTC ports: 1FA8h-1FABh (SX1 p. 21's CTC entry) vs 0704h-0707h (SX1 p. 13's FM board entry). Read both pages in the scan; the board may decode both. - C3 The X1 CRTC part: HD46505-SP (SX1) vs "HD6845S" (MAME's device name). HIT87 lists both names as one family; follow SX1 and check HIT87 for differences. - C4 The sub-CPU's name: 80C49 (SX1) vs `80c48` (MAME's ROM region); see U9. ## Milestones Exit tests are validation.md's rungs. - **M1** Bus, IPL switch, 8255②, CRTC registers, text and attributes: the IPL reaches "IPL is under preparing" with MAME's first 3 ms of I/O (R0). - **M2** The high-level sub-CPU: the IPL's handshake completes; table 4-1 as unit tests (R1). - **M3** Video: text and CG pictures, 40/80 columns (R2); graphics, palette, priority (R3). - **M4** CTC and the interrupt daisy chain, after z80-python's Z2 (R4). - **M5** FDC and D88/2D: a disk boots (R5), after decision 6. - **M6** PSG, joysticks; the FM board when ym2151-python is built (R6). - **M7** PCG timing on the plain X1 (R7). - **M8** The turbo row (R8); **M9** seeded faults (R9); the turbo Z row after. ## Domains and speed (docs/domains-and-speed.md in full.) - **Domains:** main (Z80, memory, CRTC and video memories, 8255, CTC, FDC, turbo DMA/SIO; the PCG's raster dependence binds CPU and CRTC per character clock); the high-level sub-CPU (channel: the 1900h byte with 1A01h's busy bit and /INT with its vector); sound (AY, OPM; channels: their port writes); a picture producer. - **Need, with arithmetic:** 4 M T-states/s at 6.0-8 T-states per instruction = **500,000-670,000 instructions/s**; CRTC 56 x 258 = 14,448 character clocks a frame, 0.9 M/s; AY 2 MHz / 8 = 250,000 steps/s; OPM 4 MHz / 64 = 62,500 samples/s. - **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.2-0.4 x CPython, 0.5-2 x PyPy (estimate); x-rust above real time on desktop, phone and browser; x-rust-fast with run-ahead 1-2 and rewind. `recompile: none`. No threads needed; the sound and picture producers are available if a weak target asks. ## Open decisions for Aubrey 1. **Scope and order: X1 (CZ-800C) first, the turbo as a row, the turbo Z after.** Recommended: the brief's order; the turbo adds SIO, DMA and kanji on the same board shape. 2. **The sub-CPU is high-level** (no MCS-48 core in the board). Recommended: its ROM has never been dumped (MAME: "NO GOOD DUMP KNOWN"), so a core would have nothing to run; the command table (SX1 p. 79) is the specification and its delays are FITTED and tagged. Revisit if a dump appears. 3. **A `z80-peripherals-python` set core (CTC, SIO, PIO, DMA behind one daisy-chain module)**, created when a second family board builds a Z80 peripheral (segasys1-python's PIO or model2-python's DSB); until then the X1 keeps its CTC (and the turbo's SIO, DMA) in the board. Recommended: one core rather than four, because the daisy chain and the RETI watch are shared. 4. **Support extracting `crtc6845-python`** (the X1 is the fourth family user after the CPC, BBC Micro and IBM PC). Recommended: an HD46505S row equal to type 0 unless HIT87 shows a difference. 5. **Support extracting `i8255-python` from sms-python with history** (msx decision 6, cpc decision 5, ibmpc). Recommended: the X1 needs mode 0 and bit set/reset only. 6. **Support creating `wd179x-python` now** (coco decision 5, oric decision 6, and six more boards keep one in board). Recommended: variant rows by part, the X1 using the MB8877A (FD1793-compatible, positive bus). 7. **Ask z80-python (public: your call) for Z2**: an acknowledge-time vector callback and the M1 hook on main (to see RETI). Recommended: the X1, the X1turbo and any Z80-peripheral board need it; until then the board fakes RETI through the `m1-fetch-hook` branch's hook. 8. **MAME's BSD-3 device files and xmil-libretro (BSD-3 by its LICENSE): stay closed boxes, or may a later session read them with notice?** Recommended: keep them closed for this board (the documents suffice for M1-M6), and if a corner needs them, read only after a per-file licence check, with the notice in NOTICE.md. MAME's X1 driver itself is LGPL: closed box regardless. 9. **No X1 library on hand.** Recommended: add `X1_MIRROR_DIRS` to the family's environment file now (one translation on hand); decide on a TOSEC X1 set (not on the mirror) when the board reaches M5. MAME's `x1_flop` list names 372 titles for a smoke list's choice. 10. **The OPM clock (C1): follow SX1's 4 MHz.** Recommended: SX1 explains the key-code shift it causes, which is a strong, checkable statement; MAME's 2 MHz is a detector's choice. 11. **Proposed sources.md rows**: the eight rows at the end of docs/sources.md, for the register's owner to add.