# The cores this board reuses, and what each needs Reuse first: the CPC needs one CPU (Z80A) and one sound chip (AY-3-8912) the family already has; two peripheral chips the family has inside `sms-python` (8255, uPD765A); and two video chips it does not have (Gate Array, 6845). Source names as in start-here.md. | Chip | Family core | State (2026-11-26) | What the CPC needs from it | | --- | --- | --- | --- | | Z80A (NMOS) | `../z80-python` (PUBLIC; local `main` `1302260`, origin/main `b59c80b` adds `timing.instruction_timing`) | instruction core; access-timing table on origin/main | W1-W5 below | | AY-3-8912 | `../ay8910-python` (PUBLIC, `76cace3`) | built, die-judged, `AY8912` variant | nothing new: see ppi-psg-keyboard-tape.md | | 8255 PPI | inside `../sms-python` (`io.py`, `PPI8255`, mode 0) | mode 0, latches and directions | extraction (open decision 5) plus the Plus ASIC's imperfect copy as a variant | | uPD765A | inside `../sms-python` (`sf7000.py`, `UPD765`, `7066415`) | one drive, polled, no DMA | extraction (decision 6), two units, double-sided, the CPC's unconnected INT/TC | | 6845 CRTC | none | - | in this board (decision 2) | | Gate Array 40007/40010, ASICs 40226/40489 | none | - | in this board (no other machine uses them) | ## z80-python and the Gate Array's /WAIT z80-python is an instruction-level core: `step()` runs one instruction through the host's `read_byte`, `write_byte`, `read_port`, `write_port` and returns its T-states. On the CPC, every memory and I/O cycle is stretched to the Gate Array's 1-µs grid: /WAIT is low for three of every four T-states, and the Z80 samples it once per memory or I/O M-cycle (ap12 A; ACCC 4.4.4). Internal T-states (no MREQ/IORQ) are not stretched. So the length of an instruction depends on where in the microsecond it starts, and an unaligned instruction lengthens the next one (ACCC 4.4.4, diagram A: `OUT (n),A` twice, then two NOPs: 11, 12, 5, 4 T-states). The board can compute this from outside the core, the way zxspectrum-python plans to apply ULA contention: the k-th bus callback is the k-th access of `instruction_timing(bytes).accesses`, at offset `t` plus the waits already inserted; at that access's /WAIT sample point the board adds waits until the Gate Array's free phase. Waits only delay, never reorder, so this gives every access's T-state exactly, provided the core's table is right and the board knows where each kind of cycle samples /WAIT. What the board needs from z80-python, in order: **W1. The /WAIT sample point of each access, by cycle kind.** The table's `kind` is `read`, `write`, `in` or `out`; an opcode fetch (M1, /WAIT sampled in T2) and a memory read (sampled in T2 of a 3-T cycle) are both `read`; I/O samples after its automatic wait state (T3; ACCC 4.4.4 lists "OPCODE FETCH, during the 2nd cycle T of the first M Cycle ... IO REQ, during the 3rd cycle T"). Because the offsets are absolute and M1 fetches sit at known places (`t == 1`, and after each prefix), the board can tell fetch from read itself; a `fetch` kind in the table would make it explicit. **Request (optional):** mark M1 fetches as `fetch` in `AccessTiming.kind`. **W2. Interrupt acknowledge and HALT timing.** The table excludes the acknowledge cycles and the HALT idle cycle. The CPC needs the IM 1 acknowledge (ACCC 27.4: 5 µs, against 4 µs for an executed RST 38) and IM 2 (ACCC 27.5: 7 µs), so the M1+IORQ cycle's sample point and the two stack writes' offsets; HALT's idle M1 is 1 µs (ACCC 27.3.3). **Request:** publish the acknowledge's access timing like the instruction table (the same request zxspectrum-python made as its N3). Until then the board keeps a small table derived from the Z80 manual's acknowledge cycle and checks it against ACCC 27.4/27.5. **W3. An acknowledge event at its T-state.** The Gate Array clears its counter's bit 5 and the pending request when it sees M1 with IORQ (KT `ints`; ACCC 27.3), and ACCC 27.7.1 shows an observable race between that clear and an HSYNC end. z80-python clears its pending request on acceptance (`_accept_maskable_interrupt`), so the board can see that an acknowledge happened in a `step()`; with W2's offsets it knows when. Nothing new is needed beyond W2. (The `read_m1` hook on `m1-fetch-hook-rebased` would make it direct; not needed.) **W4. IM 0 and IM 2 with a floating bus.** On the old CPCs nothing drives the data bus during the acknowledge (ACCC 27.5; KT `im2`): IM 0 reads FF (RST 38), which z80-python supports; IM 2 reads an undefined byte that the board supplies through `request_maskable_interrupt(vector_byte)`. The Plus's ASIC supplies real IM 2 vectors (plus-asic.md). Nothing new needed. (z80-python's IM 0 refuses non-RST bytes; the CPC never needs them.) **W5. NMOS `OUT (C),0`.** Demos use `OUT (C),0` on the CRTC and Gate Array (ACCC 4.4.2). The CPC's Z80A is NMOS (SOFT 968 ap12 A says "Z80A"; no CPC with a CMOS Z80 is reported in the pinned sources), so the default (`cmos_out_c_zero = False`, writes 0) is right. Nothing new. **The exit test this gives (rung R2 in validation.md):** start every instruction of the table on an aligned T-state, apply W1's rule, and the rounded length in microseconds must equal ACCC chapter 26's for every instruction and both shapes of conditional ones; then ACCC 4.4.3's I/O timing (OUT (C),r reaching the CRTC in its 3rd µs, OUTI in its 5th, IN in its 4th) must fall out of the same rule. A disagreement is either the table (emulator-derived from SingleStepTests, tier 5) or the rule; ACCC (tier 3, measured on real CPCs) is the judge, and the case is raised on z80-python with a repro. **What is not needed:** a cycle-stepped Z80. If W1-W2 cannot express some case (none known), the fallback is a z80-python "bus-cycle" mode, raised there with a repro. ## MAME's timing is not a judge here MAME 0.285's `cpc464` trace (mame-oracle.md, OBSERVED): of 14,579 instructions, 69.9 % have lengths that are multiples of 4 T-states; the rest take 5, 7, 9, 11, 13 ... T-states. The firmware's first instructions (`LD BC,&7F89`, `OUT (C),C`, `JP &0580`) take 11, 14 and 14 T-states in MAME's count, where the per-access rule and ACCC chapter 26 give 3, 4 and 3 µs (12, 16, 12 T-states). MAME's driver (GPL-2.0+, not read) evidently approximates the stretching differently from the per-access rule above. MAME is used for the order and values of I/O, not for timing.