# Domains and speed Read with the charter's "Domains and channels" and "Capabilities", and the accepted JIT proposal (emulator-lineage `docs/proposals/2026-11-jit.md`: the no-JIT path first). The VIC-20 is era 1: one clock domain on the main board, cycle level everywhere. Everything here is a proposal for the specification to confirm. ## Domains | Domain | Holds | Clock | Why | | --- | --- | --- | --- | | **M: main** | 6502, VIC (picture, sound, paddles, light pen), VIA1, VIA2, RAM, colour RAM, ROMs, expansion port, user port, keyboard and joystick | the VIC's Pφ1/Pφ2 from one crystal | the VIC fetches in phase 1 and the CPU uses phase 2 of the same cycle; the VIAs run on φ2 | | **D: drive** (when attached) | the 1540/1541: 6502, two VIAs, GCR logic, mechanism, disk | its own 16 MHz crystal | own clock, own CPU; meets M only at the IEC lines and RESET (drive-1541.md) | | (T: tape) | the Datasette's pulse stream | the tape's speed | a timestamped producer of edges into VIA2 CA1; not worth a thread | **Order of record** (vic20-python): per CPU cycle, the VIC's phase-1 fetch, then the CPU's phase-2 access, then both VIAs tick, then the sound counters; the drive is advanced to the same moment in real time (the exact ratio of the two crystals as a fraction) before either side reads or writes an IEC line. With 6502-python, which runs whole instructions and calls the bus once per cycle, the board advances M by one cycle inside each bus callback (the shape famicom-python and a2600-python use); interrupt requests raised there reach the core's poll exactly as the chip's (6502-python start-here). ## Channels | Channel | From -> to | Mechanism | Sync point for | | --- | --- | --- | --- | | IEC bus | M <-> D | ATN, CLK, DATA wired-AND, RESET | every change of a line and every read of one, on either side | | sound | M -> host | the VIC's sound registers ($900A-$900E) over time | none: a pure producer from a timestamped write log (the CPU can read these registers back, but they hold what was written) | | video | M -> host | 4 colour indices a cycle | pure producer | | tape | T -> M | edges on VIA2 CA1; motor (VIA1 CA2) and write (VIA2 PB3) back | each edge's time | | cartridge / expansion | inside M | the full bus | | ## The JIT proposal's four declarations - **Sync points:** the IEC rows; interrupt sampling (VIA1 -> NMI edge, VIA2 -> IRQ level, the expansion port's /IRQ and /NMI). - **Memory kinds and writers:** | Memory | Kind | Written by | | --- | --- | --- | | RAM ($0000-$03FF, $1000-$1FFF, expansion RAM) | RAM; code runs anywhere, self-modifying code is common | the CPU only (the VIC never writes: its R/W is held high in phase 1, VDS p. 9) | | colour RAM | 4-bit RAM | the CPU | | BASIC, KERNAL, character ROM, cartridge ROM | ROM, never banked in the base design | nobody | | drive RAM (2K) | RAM; fast loaders upload code | the drive's 6502 | - **Timing as data:** 6502-python's per-opcode table; the VIC's fetch pattern per line. - **Restricted semantics:** applies to 6502-python, not the board. ## Instructions per second (the arithmetic) Per emulated second: - **6502:** NTSC 1,022,727 cycles (14,318,181 / 14), PAL 1,108,405 (4,433,618 / 4). MAME's boot ran 606,646 instructions in 2,045,451 cycles (3.37 cycles an instruction, OBSERVED, mostly the RAM-test loop), so about **300,000 instructions a second NTSC, 330,000 PAL**. No cycles are lost to video (no DMA). - **VIC:** one 12-bit fetch and **4 pixels per cycle**: 1.02 M fetches and **4.09 M pixels** a second NTSC (4.43 M PAL); sound: four dividers stepped from φ2. - **VIAs:** 2 x 1.02 M timer ticks. - **Drive (optional):** 1,000,000 cycles; 283,621 instructions in MAME's first second (c64-python's mame-oracle.md, OBSERVED), two more VIAs, the GCR bit clock. So a bare VIC-20 is **about 1.0 M CPU cycles and 4.1 M pixels a second**: roughly 60 % of the NES's 1.79 M CPU cycles and 5.37 M dots, and less per pixel than the 2600's TIA. ## What that means per tier (HYPOTHESIS until the board runs) Family precedents on PyPy: famicom-python 3.0x real time with idle PPU dots batched, 1.8x dot by dot, 0.89x once the APU ran per cycle (its validation.md); a2600-python about 0.18x (its README). **vic20-python on PyPy is therefore expected somewhere between 0.5x and 2x real time** without the drive, and lower with it. That is fine: reference boards are correct, not fast; tests are short (the KERNAL boot is 2 s; the VICE VIA tests run in seconds; split-tests in frames). - **vic20-rust:** the NES and 2600 transcriptions run several times real time natively; a VIC-20 is lighter. Real time on desktop with margin. - **vic20-rust-fast:** needed only if a phone or the browser (wasm) misses real time with the drive attached and run-ahead on. Candidates: the picture and the sound as pure producers on their own threads; the drive on its own thread at the IEC channel, which pays only while the bus is idle (fast loaders toggle it every few cycles): measure and prune. - **vic20-rust-turbo:** not expected; candidates if ever needed: whole-line VIC fast paths when no register is written in the line; an exact idle-drive skip (motor off, waiting on ATN). **No-JIT path:** `recompile: none` on every target. A 1 MHz 6502 board meets real time interpreted on desktop, phone and browser by every family precedent of its era (NES, 2600, Game Boy in Rust and wasm). A cached interpreter is not needed, and self-modifying code would make one costly to invalidate. Threads at the IEC channel are the only multi-core lever and only with the drive attached.