# Domains and speed Read with the charter's "Domains and channels" and "Capabilities" (`recompile: native | wasm | none`) and the accepted JIT proposal (no-JIT path first: Rust `-fast`, then a cached interpreter, then threads at domain channels). Everything here is a proposal for the specification to confirm. ## Domains: one Every clock on the board divides from one 16 MHz crystal ([start-here.md](start-here.md)): the CPU's 2 MHz (stretched to the 1 MHz phase for slow devices), the 6845's 1 or 2 MHz, the Video ULA's pixel clocks, the SAA5050's 1 and 6 MHz, the VIAs' 1MHzE, the SN76489's 4 MHz, the serial ULA's 16/13 MHz. The CPU and the video share RAM on alternate phases of every 2 MHz cycle. **The whole machine is one domain** (C), in the charter's sense, run in one order of record: - **Order of record**: one timeline in 16 MHz ticks. Each CPU bus cycle advances 8 ticks (16 or 24 when stretched); inside it, the video advances by its character clock and pixels, the VIAs by their 1 MHz edges, the PSG by its 4 MHz clocks, in a fixed order (devices up to the cycle's start, then the CPU's access, then devices to its end). The exact interleave (which device acts first at a shared edge) is a specification choice, marked PROVISIONAL until the tier-1 VIA outputs fix the visible part of it. Candidates for separate scheduling from `-fast` on (each meets C only at the channel named): | Part | Channel to C | Why it can run apart | | --- | --- | --- | | SN76489 synthesis | the register writes (time-stamped) | a pure producer: sound from register state over time | | picture output (palette, serialiser, SAA5050 rendering) | the 6845's fetch addresses and the bytes read, the Video ULA register writes, time-stamped | a pure producer **only if** the fetched bytes are logged as C reads them (the CPU can write the screen mid-frame); the fetch itself stays in C | | the disc drive (rotation, index, head) | the FDC's register file and its NMI line | the Sega CD precedent: a drive stepped inside the controller's domain, on the same crystal | | a Tube second processor (later) | the Tube ULA's FIFOs and IRQ/NMI | its own clock (3 MHz 6502, 4 MHz Z80 ...): a real second domain, the first one this board would have | ## Channels and sync points (the JIT proposal's four declarations) - **Sync points**: every access to FRED, JIM or SHEILA (&FC00-&FEFF); every IRQ and NMI edge (the VIAs' timers, vsync on CA1, the ACIA, the ADC's EOC, the FDC's data requests); the end of each stretched cycle. A block may run freely between them only if it touches RAM and ROM alone. - **Memory kinds and writers** (what invalidates cached decode): | Memory | Kind | Written by | Invalidated also by | | --- | --- | --- | --- | | &0000-&7FFF main RAM | RAM, code runs here | the CPU only (the video reads it) | B+/Master shadow switching (&FE34) remaps &3000-&7FFF by **opcode address** | | &8000-&BFFF paged slot | ROM or sideways RAM | the CPU, when a RAM slot is selected | **every write to &FE30** (the whole window changes) | | &C000-&FFFF MOS | ROM (Master: HAZEL RAM over &C000-&DFFF when ACCCON Y) | nobody (Master: the CPU into HAZEL) | ACCCON writes on the Master | - **Timing as data**: the 6502's per-opcode cycle tables live in 6502-python (and the 65SC12's in w65c02-python); the board adds one rule, the stretch, which depends on the address and the 1 MHz phase, so **summed cycle counts are never valid across a slow access**: a cached block must end at, or charge per access around, every slow access. - **Semantics in a restricted form**: the cores' business. ## Instructions per second needed (arithmetic) - CPU: 2,000,000 cycles a second. Measured on MAME 0.285 booting a Model B to BASIC: **570,564 instructions in 50 frames** (1.00 s at 50 Hz), 2,003,212 cycles: 3.5 cycles an instruction (OBSERVED: [mame-oracle.md](mame-oracle.md); MAME does not stretch, so on the real machine slightly fewer instructions fit a second). Need: about **0.6 M 6502 instructions a second**, plus the stretch bookkeeping. - Video: the 6845 at 2 M character clocks a second in modes 0-3 (1 M in 4-7), each character one RAM fetch and 8 pixels out of the Video ULA in mode 0 (16 M pixel-clock periods a second while displaying, 640 x 256 visible): about **2 M chip steps and up to 10 M pixel writes a second**. - VIAs: 2 x 1 M ticks a second (each tick is a few counter decrements: cheap, but 2 M calls in a naive model). - SN76489: 4 MHz / 16 = 250,000 steps a second. - Total fine-grained work: roughly **6-7 M device steps a second plus 0.6 M instructions**. For scale: the Atari 2600 board does 1.19 M CPU cycles and 3.58 M TIA colour clocks a second, and `a2600-rust-fast` runs at about 4x real time natively and 5.0-5.4x as WebAssembly in a browser (a2600-rust-fast README, measured there). The BBC's per-second work is about twice the 2600's in step count, with simpler per-step work for the VIAs and the 6845 and a heavier pixel stage. ## Does the no-JIT path reach real time? | Target | Tier | Estimate | Basis | | --- | --- | --- | --- | | desktop, PyPy | `bbcmicro-python` (reference) | below real time to about real time | w65c02-python's bare core on PyPy: 8.9 M instructions a second (its build-progress.md, loaded machine); the board's device stepping dominates. "Reference boards: correct, not fast" (Aubrey): not a target | | desktop, native | `bbcmicro-rust` | several times real time | the transcription of a one-domain 8-bit board; a2600-rust ran 3.4-3.7x | | phone, native (iOS: no JIT) | `bbcmicro-rust-fast` | real time with margin: **yes** (HYPOTHESIS by analogy with a2600-rust-fast) | per-pixel batching of the serialiser and per-character stepping of the 6845, the 2600 fork's techniques | | browser, wasm | `bbcmicro-rust-fast` | real time: **yes** (HYPOTHESIS, same analogy: play-2600 is live at 5x) | | | any, with run-ahead of 1-2 frames | `-fast` | likely yes on desktop and browser; phone to measure | Aubrey uses 1 frame, sometimes 2 | So: **`recompile: none`** is the expected capability line for every target. A cached interpreter is not expected to be needed; threads are not needed (one domain), though the sound producer can take a thread cheaply. A `-turbo` tier is not planned unless run-ahead on a phone measures short. The figures above are estimates from the arithmetic and from sibling boards' measured numbers, not measurements of this board: the first real number comes from milestone 1.