# Domains and speed Where the CPC's domains and channels fall (charter, "Domains and channels"), how fast each tier must be, and whether the no-JIT path reaches real time on every target (charter, capabilities, `recompile: native | wasm | none`; emulator-lineage `docs/proposals/2026-11-jit.md`, accepted 2026-11-25). Phase 0: the board does not exist, so every speed figure is an **estimate** with its arithmetic shown, anchored on measured sibling boards. ## Domains and channels The CPC is era 1 (charter): one 16 MHz crystal, one CPU, and a Gate Array that owns the bus every microsecond. Everything a program can observe at a T-state lives in one domain. | Domain | Time base | Parts | Why | | --- | --- | --- | --- | | **Main** | the 1-µs Gate Array cycle, in Z80 T-states (4 per µs) | z80-python; Gate Array (WAIT, video fetch, interrupt counter, RMR, palette); CRTC (counters, VSYNC to the PPI and the Gate Array); memory, ROM select, 6128 PAL; PPI; keyboard; tape level; printer latch; expansion socket | /WAIT stretches every Z80 access to the CRTC's character clock, and the CRTC's VSYNC and HSYNC feed the PPI and the interrupt logic within the microsecond: splitting them makes every access a sync point | | **AY** | AY input clock, 1 MHz | ay8910-python | meets the main domain only when PPI port C's BDIR/BC1 strobe it; its output is a function of the register-write log over time | | **FDC and drives** (664, 6128, DDI-1) | the FDC's 4 MHz clock and disc rotation | uPD765A, drives, images | meets the CPU only at `FB7E`/`FB7F`/`FA7E`; **stepped inside the main domain in the order of record**, because AMSDOS polls the status register for every byte (no INT, no DMA) | | Channel | Between | Sync point for a threaded tier | | --- | --- | --- | | PPI port C bits 7-6 = `10` / `11` (AY write, latch) with port A's latch | main -> AY | none: appended to a log the AY drains | | PPI port C = `01` (AY read) then a port A read | AY -> main | **join**, but only for the register file: the AY's port A input pins are the keyboard (main-domain state), and registers 0-13 read back what was written; no sound state is needed, so the "join" is a register-file lookup in the main domain | | `FB7E`, `FB7F`, `FA7E` | main <-> FDC | every access (same domain in the order of record) | | Gate Array pixel stream | main -> picture | none: a producer. The main domain must run the CRTC counters (VSYNC/HSYNC are read back), but the pixel decode can be a pure function of a per-µs log: (two fetched bytes, mode, palette changes with their pixel position, border/DISPEN) | | AY levels -> audio | AY -> host | none: a producer | Order of record (x-python): the main domain advances one Gate Array microsecond at a time (four T-states: CRTC clock, video fetch, WAIT phase, interrupt counter, then the Z80's accesses that fall in the free phase); the AY is caught up at each strobe and at frame end; the FDC is stepped in the main loop. Catch-up at the channel, as in sega32x-python and segacd-python. Memory kinds (for a cached interpreter's invalidation map, should one ever be wanted): ROM (lower, upper by number: never written; writes go to RAM underneath), RAM banks (written by the CPU only; no DMA on the CPC; the Plus adds DMA that **reads** RAM for the AY), mapping changes on RMR writes (ROM enables), `DFxx` (upper ROM number) and, on the 6128, the bank register. Self-modifying code is common (loaders, demos). ## The need, with arithmetic - **CPU:** 4,000,000 T-states/s, but on the CPC every instruction takes a whole number of microseconds (ACCC ch. 26), 1 to 7 µs. At a typical 2.5-3 µs per instruction (HYPOTHESIS: no CPC instruction-mix measurement here; ACCC's table has most register instructions at 1-2 µs and most memory instructions at 2-5 µs) that is **330,000-400,000 instructions/s**, plus one WAIT-phase computation per access (about 1.5-2 accesses per instruction: 0.5-0.8 M per second). - **CRTC:** 1,000,000 character clocks/s (64 x 312 x 50.08 = 1,000,000 by construction: 19,968 µs per frame), each a handful of counter comparisons. - **Gate Array:** 1,000,000 two-byte fetches/s; pixels at 16 MHz: 16 mode-2 pixels per µs in the visible area (about 50 of 64 µs on about 270 of 312 lines, so ~11 M pixel writes/s if done pixel by pixel, ~0.7 M byte-pair decodes/s if done by lookup table). The decode is the producer above. - **AY:** 1,000,000 input clocks/s; ay8910-python steps every 8: 125,000 steps/s. - **FDC:** 31,250 bytes/s at 250 kbit/s MFM while a disc is read; idle otherwise. ## Tier by tier, target by target (estimates) | Tier | Desktop | Phone (native app) | Browser (desktop / phone) | | --- | --- | --- | --- | | x-python, CPython | ~0.1-0.3 x real time | - | - | | x-python, PyPy | ~0.3-1 x real time | - | - | | x-rust | above real time | above real time | above real time | | x-rust-fast | far above (run-ahead 1-2 and rewind affordable) | above, with run-ahead 1-2 | above | Anchors (MEASURED on siblings, not this board): colecovision-python, a 3.58 MHz Z80 with a TMS9918A and an SN76489, runs at 0.3-0.5 x real time on CPython and 0.6-2.9 x on PyPy (as zxspectrum-python's Phase 0 records). The CPC does more per microsecond than either: a CRTC clock and a two-byte fetch every microsecond, and a WAIT computation per access, so the band is set lower. z80-wasm (z80-rust-fast in WebAssembly) runs Galaxian's 3.072 MHz Z80 at full speed in the browser (live at galaxian.supertux.com); a 4 MHz Z80 whose instruction rate is lower than its clock suggests (whole microseconds) is of the same order. **The no-JIT path reaches real time on every target** (desktop, iPhone app, browser): x-rust already, x-rust-fast with room. `recompile: none`, as the JIT proposal's era-1 row says ("the CPU is a small share of the frame; nothing to gain"). Threads are not needed; the picture producer and the AY are available as producer threads if a weak handheld wants them. A turbo tier (whole-line fast paths for the Gate Array and CRTC when no register changes mid-line) only if a target measures the need, which is likely only for deep run-ahead on weak devices; demos that rewrite CRTC registers mid-line will always take the per-microsecond path. The specification runs its judges directly on PyPy: SHAKER modules and ACCC's cases are a few emulated seconds each.