# Domains and speed Read with the charter's "Domains and channels" and the accepted JIT proposal (emulator-lineage `docs/proposals/2026-11-jit.md`: the no-JIT path first). The C64 is era 1 in the charter's table: one clock domain on the main board, cycle level everywhere, "Python runs the tests, Rust plays". Everything here is a proposal for the specification to confirm. ## Domains | Domain | Holds | Clock | Why | | --- | --- | --- | --- | | **M: main** | 6510, VIC-II, PLA, RAM, colour RAM, ROMs, CIA 1, CIA 2, cartridge port, user port, datasette port | the VIC's phi0 from one crystal | the VIC and the CPU share the bus every half cycle (phase 1 / phase 2, BA, AEC): the tightest coupling there is | | **S: SID** (optional split) | the SID's digital part and its analogue model | phi2 of M (locked) | the CPU only writes it, except four readable registers (POTX, POTY, OSC3, ENV3) and the floating bus on write-only reads; a "part on one locked clock that can still be scheduled apart" (charter, 2026-11-25 wording) | | **D: drive** | the 1541's 6502, two VIAs, the read/write logic, the mechanism and the disk | its own 16 MHz crystal | own clock and own CPU; meets M only at the IEC lines and RESET | | (T: tape) | the datasette's pulse stream | the tape's speed | a producer of edges into CIA 1 FLAG; a timestamped FIFO, not a domain worth a thread | `c64-python` runs them serially in one order of record: per M cycle, VIC phase 1, then the CPU's phase 2 (or the VIC's if AEC is low), CIAs, SID; the drive advanced to the same moment in real time (the ratio of the two crystals, exact as a fraction) before any IEC line is read or written by either side. ## Channels | Channel | From -> to | Mechanism | Sync point for | | --- | --- | --- | --- | | IEC bus | M <-> D | ATN, CLK, DATA wired-AND; RESET | every change of a line (CIA 2 PA writes on the C64; the serial VIA's port B writes and the ATNA gate in the drive) and every read of them | | SID registers | M -> S | writes to $D400-$D418 | none for writes (a timestamped log); reads of $D419-$D41C and of write-only registers are sync points | | SID audio | S -> host | samples | pure producer | | video | M -> host | 8 colour indices per cycle | pure producer (from the VIC's state) | | datasette | T -> M | edges on CIA 1 FLAG; motor and write from the 6510 port | each edge's time | | cartridge | M <-> cartridge | the full bus | inside M | ## Sync points and code invalidation (the JIT proposal's four declarations) - **Sync points:** the channel rows above; interrupt sampling on both CPUs. - **Memory kinds and writers:** | Memory | Kind | Written by | | --- | --- | --- | | C64 RAM (64K) | RAM; code runs anywhere, self-modifying code is common | the 6510; the VIC never writes; a cartridge's DMA (REU) | | colour RAM | 4-bit RAM; code can run from it via open bus tricks (VIC section 4) | the 6510 | | BASIC, KERNAL, character ROM, cartridge ROM | ROM, banked by the PLA (the same address maps to different memories by the port and EXROM/GAME) | nobody; a flash cartridge (EasyFlash) by its own protocol | | 1541 RAM (2K) | RAM; fast loaders upload drive code here | the drive's 6502 | | 1541 ROM | ROM | nobody | - **Timing as data:** 6502-python's per-opcode cycle table; the VIC's access table per chip type (vic-ii.md). - **Restricted semantics:** applies to the cores (6502-python), not the board. ## Instructions per second (the arithmetic) Per emulated second, NTSC (PAL is 3.7% slower): - **6510:** 1,022,727 cycles. MAME's boot ran 593,433 instructions in 2,128,094 cycles (3.59 cycles an instruction, OBSERVED, mame-oracle.md), so about **285,000 instructions a second**, fewer with the screen on (25 bad lines a frame x 40-43 cycles: about 6% of NTSC's 17,095 cycles a frame, 5% of PAL's 19,656), more lost under FLI (a bad line on every line) and sprites. - **VIC-II:** 1,022,727 cycles, each with up to two memory accesses and **8 pixels**: 8.18 M pixels a second. - **SID:** 1,022,727 ticks of three oscillators, three envelopes, the noise LFSR and the filter. - **CIAs:** 2 x 1,022,727 timer ticks. - **1541:** 1,000,000 cycles; 283,621 instructions in MAME's first second (3.54 cycles an instruction, OBSERVED); two VIAs at 1 MHz; the bit clock from 16 MHz ÷13 to ÷16 (DSM). Total for a C64 with a drive: about **570,000 CPU instructions and 6 M chip-cycles a second**, plus 8.18 M pixels. Compare the NES (famicom-python, validation.md): 1.79 M CPU cycles and 5.37 M PPU dots a second, at 3.0x real time on PyPy with the PPU's idle dots batched and 1.8x dot by dot. The C64 without its drive is a similar load; the drive roughly adds another CPU and two timers. ## What that means per tier (HYPOTHESIS until the board runs) - **c64-python** (PyPy): by the NES comparison, around real time without the drive and below it with the drive; the reference is correct, not fast (Aubrey's rule). Tests are short: a boot (2 s), Lorenz (minutes of emulated time per part), VICE tests (their test-list budgets are 6-50 M cycles). - **c64-rust:** the NES and 2600 transcriptions reach several times real time natively (famicom-rust-fast's baseline about 8x on this loaded machine): ample on desktop. - **c64-rust-fast:** for phones and the browser (wasm), as the NES and 2600 lines were. Threads: the SID's analogue model and the picture as pure producers are the cheap wins; the drive on its own thread at the IEC channel pays only while the bus is quiet (the channel can change on any instruction of either CPU, so conservative sync stalls during transfers): to measure, and prune if it does not pay. - **c64-rust-turbo:** not expected to be needed; candidates if a weak target asks: whole-line VIC fast paths when no register changes in the line, an idle-drive skip that is exact (motor off, waiting for ATN). **No-JIT path:** the board meets real time with `recompile: none` on desktop, phone and browser by every family precedent of its era (NES, 2600, Game Boy). A cached interpreter is not needed for a 1 MHz 6502 pair; self-modifying code and banked ROMs would make one costly to invalidate anyway.