# The Z80 and its family peripherals (CTC, SIO, DMA, PIO) ## The CPU A Z80A at 4 MHz (SX1; MAME OBSERVED), embedded from `../z80-python` (main at `cc2f794`, 2026-09-21; the board pins whatever main holds when it is built). No wait states are documented for the X1's memory or I/O in the parts of SX1 read so far (U6); MAME's 0.05-second trace of `x1` averages **6.0 T-states per instruction** (33,576 instructions in 200,000 T-states, OBSERVED), which is what a wait-free Z80 running the IPL's polling loops gives. What the board needs from z80-python (requests to raise upstream; fixes start there): - **Z1, 16-bit I/O addresses: already met.** Every X1 port is 16-bit. z80-python's `_io.py` (main) passes `A:n` for `IN A,(n)`/`OUT (n),A` and BC for the `(C)` forms to `read_port`/`write_port`, as UM0080 and Young say. One X1-specific consequence to test at M1: in the block instructions B is both the counter and the port's high byte, so `OTIR` walks down through 256 ports; X1 software uses `OUTI` sequences with that in mind (SX1's listings). The board's tests should pin z80-python's B-decrement order for INI/OUTI. - **Z2, interrupt acknowledge and RETI for the daisy chain.** z80-python's docs/interrupt-lifecycle.md says it "does not model interrupt-acknowledge bus callbacks, daisy-chain priority". The Z80 family peripherals need (a) the vector byte to be supplied at acknowledge time by whichever device wins the chain (today's `request_maskable_interrupt (vector_byte)` fixes it at request time, which is wrong when a higher device asserts between request and acknowledge) and (b) a notification when the CPU fetches `ED 4D` (RETI), because the CTC, SIO and PIO watch the bus for RETI to clear their interrupt-under-service state (ZPER, "Daisy-Chain Interrupt Servicing", printed p. 30; "Daisy Chain Interrupt Nesting", p. 308). The board can fake (b) by watching opcode fetches through the M1 hook (`m1-fetch-hook` branch, not on main), so the request is: a first-class acknowledge callback returning the vector, and the M1 hook merged. - **Z3, IM 2.** The IPL and BASIC use mode 2 with vectors from the CTC and the sub-CPU (SX1 ch. 4: the keyboard interrupt vector is set by sub-CPU command E4h, vector 00h meaning "no interrupt"; ch. 5 for the CTC). z80-python implements IM 2 (19 T-states, interrupt-lifecycle.md); only Z2 is missing. ## Z80 CTC (Z8430) Four channels at 1FA0h-1FA3h (SX1 p. 21; UM880 §3.5.1). Channel 0's clock is the 4 MHz system clock (timer periods 4 µs to 16.384 ms); CLK/TRG1 and CLK/TRG2 get 2 MHz; the turbo uses channels for the SIO's baud clocks and BASIC's `PLAY` timing (UM856 p. ~"MUSIC/PLAY は CTC でコントロール"). A second CTC can sit at 1F98h-1F9Bh, and the FM board carries its own (1FA8h-1FABh in SX1's text, 0704h-0707h on the board's own decode: C2). The CZ-8BS1's YM2151 interrupt line is **not** used, because the OPM cannot answer a mode-2 acknowledge; the board's CTC is the timer (SX1 ch. 11, the register 14h description). Programmer's model: ZPER ch. CTC (control word, time constant, vector, prescaler 16/256, counter and timer modes, ZC/TO outputs, daisy-chain position). ## Z80 SIO and Z80 DMA (turbo rows) - SIO at 1F90h-1F93h: channel A RS-232C, channel B the mouse (UM856 §RS-232C: "SIO のチャン ネル B はマウス用に使用"). ZPER ch. SIO. - DMA at 1F8*h (SX1 ch. 8): memory and I/O to memory and I/O, with search; used for disk transfers on the turbo. ZPER ch. DMA. Bus requests stop the Z80 (BUSREQ/BUSACK): the board owns the arbitration and z80-python needs a **BUSREQ input** (Z4) or the board steps the CPU around DMA bursts in the order of record (the second is enough for the reference board: the DMA's transfer timing is the only observable). ## PIO No Z80 PIO on the X1's main board in the parts read (SX1 mentions one only as a way the FM board could have taken the OPM's interrupt). Model 2's sound board (model2-python's sound.md) and Sega System 1 (segasys1-python) carry one. ## The shared-core question (decision 3) | Peripheral | X1 | Other family boards that carry it (per their Phase 0 docs) | | --- | --- | --- | | Z80 CTC | X1 (one to three) | model2-python (TMPZ84C015's CTC) | | Z80 SIO | X1turbo | model2-python (TMPZ84C015's SIO) | | Z80 PIO | none | segasys1-python (System 1/2), model2-python | | Z80 DMA | X1turbo | dkong-python pinned the Z8410 sheet as a relative of its 8257 (not used by it) | The chip rule says non-CPU chips stay in the board until a second family board needs them. The CTC/SIO/PIO/DMA family is a set: one daisy chain, one RETI watcher, one acknowledge protocol. **Proposal: a single `z80-peripherals-python` core** holding CTC, SIO, PIO and DMA as separate classes behind one daisy-chain module, created when a second board reaches its Z80-peripheral milestone (segasys1-python's PIO or model2-python's DSB are the likely seconds). Until then the X1 keeps a CTC (and, for the turbo row, SIO and DMA) inside the board behind pin-shaped classes. The daisy chain itself is what Z2 asks of z80-python.