# The CPU: a Z80 with one wait per M1 cycle ## What the standard says "Z80A compatible, Clock 3.579545 MHz (NTSC Color sub-carrier frequency), 1 WAIT in M1 CYCLE" [TDB p. 10, 1.3.1]. The Yamaha S3527 MSX engine lists "insertion of 1 WAIT during M1 cycle" among its features, has an M1 input and a WAIT output "during M1 cycle (possible to wired-OR with external WAIT signal)", and draws the wait state Tw between T2 and T3 of the M1 cycle [S3527 p. 1, p. 4, M1 cycle timing p. 27]. The cartridge bus carries /WAIT (open collector) and /M1 [TDB p. 32-33], so a cartridge can stretch any cycle. Consequences, as the MSX Assembly Page tabulates them: every instruction gains one clock, those with a CB, DD, ED or FD prefix two (two M1 cycles), so NOP takes 5, LD A,(HL) 8, OUT (n),A 12 [GRAUW-Z80, "Z80+M1" column]. DD CB d op has two M1 cycles (the displacement and the final opcode are memory reads), so +2. **Observed (MAME 0.285, `cf2700`, 3 s from reset, 1,374,251 instructions; mame-oracle.md):** the clock deltas per first opcode byte were LD A,n 8, LD A,(HL) 8, INC HL 7, CB-prefixed 10, JR 13, DJNZ 9/14, JR NZ 13/8, ED-prefixed repeats 23. Each is the Zilog count plus one per M1 cycle. That is MAME's reading (tier 5), consistent with TDB and GRAUW; it decides nothing. ## What the family core already offers [z80-python](../../z80-python) is the specification Z80 (SingleStepTests, ZEXALL, its own ladder). It returns T-state totals and does not model WAIT (its README's "reference-core boundary"). Two additions exist: 1. **`read_m1(address, kind)`** (the M1-cycle hook built for the ColecoVision, z80-python issue 0001): called for every M1 cycle with its kind (FETCH, HALT, NMI, ACKNOWLEDGE). The board counts one wait clock per call. It lives on branch `m1-fetch-hook-rebased` (`5434349`, worktree `../z80-python-m1-hook`), **not on z80-python's `main`** (checked 2026-11-26: `git branch --contains a2a0160` lists only that branch; it is pushed to GitHub, with no pull request). colecovision-python pins that commit. The MSX is the hook's second consumer. 2. **`z80_python.timing.instruction_timing(bytes)`** (on `main`, PR #16): every memory and I/O access an instruction makes, with its T-state offset. The board shifts each offset by the M1 waits that precede it, so a VDP port write lands on the right clock for tms9918-python's access windows. colecovision-python does exactly this (`board.py`), which is the model to follow. No new CPU core is needed for MSX1, MSX2 or MSX2+. The board owns the waits. ## Open questions - **Does the M1 wait also stretch interrupt acknowledge and HALT M1 cycles?** (U1) The S3527 keys its wait on /M1; an acknowledge cycle has /M1 low with /IORQ instead of /MREQ. colecovision-python met the same question (its C11): two board tracings there say every M1 cycle, MAME's ColecoVision driver leaves acknowledges unstretched. Default: every M1 cycle (FETCH, HALT, ACKNOWLEDGE), a machine-row switch, and the MAME lockstep run with MAME's choice, as colecovision-python does. - **Extra waits on VDP I/O** (U7). The S1985 MSX2 engine can insert "single wait requested for VDP read or write", chosen by a keyboard-return pin's level at reset (strap X7) [S1985 p. 9]; VATT's results sheet has an "Add. waits" column (0 for the Sony HB-75P, HB-F1XD, Yamaha CX5MII; 1 for an FS-A1GT; 2 for an FS-A1FX). A machine-row field `vdp_io_waits`, 0 for the first MSX1 row; MSX2 rows take theirs from the engine's strap where a schematic says, VATT otherwise. - **Interrupts.** The VDP's /INT is the Z80's /INT (level), taken in IM 1 by the BIOS; keyboard scanning is "driven by VDP interrupt" [TDB p. 13]. Cartridges may also pull /INT [TDB p. 32]. /NMI is not on the cartridge bus list [TDB p. 32-33]; the board leaves it unconnected on MSX1 rows. ## turbo R (later) The turbo R's R800 runs Z80 code at 7.16 MHz with its own (undocumented, measured by the community) waits: 1 for an opcode fetch crossing a 256-byte page in internal RAM, 2 per RAM read or write, 4-5 for external memory, 6-7 for I/O [GRAUW-Z80]. It adds MULUB and MULUW. It is a new CPU (`r800-python`, decision 7), sharing z80-python's instruction semantics where they are identical; its own Phase 0 when a turbo R row is wanted.