# 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). A proposal for the specification to confirm. ## Domains | Domain | Holds | Clock (MAME) | Why one domain | | --- | --- | --- | --- | | **M: main** | the main Z80 (or its encrypted variant, or the MC-8123), program ROM and bank, work RAM, the PIO or 8255, inputs and DIPs, the video RAMs as the CPU sees them, the 8751 on three System 2 sets | 4 MHz (20 MHz / 5, HYPOTHESIS) | the 8751 holds the Z80 at power-on and reads its ROM over its bus (OBSERVED in MAME, [protection.md](protection.md)): a second bus master, tightly coupled | | **V: video** | the tile and sprite hardware, the line buffers, palette RAM or PROMs, the lookup PROM, collision detection | 10 MHz pixel clock | shares the RAMs with M; whether the CPU's accesses wait on the video (contention) is U12 | | **S: sound** | the sound Z80, its RAM and ROM, the two SN76489A, the timer interrupt | 4 MHz (2.5 on three sets) | the PSGs' READY stalls the Z80 (MAME's `sn_ready`): one domain, stepped together | V may be folded into M in the specification's order of record (both are derived from one crystal, HYPOTHESIS) as long as the channels stay the only meeting points; the charter allows a domain stepped inside another when the specification says so. ## Channels | Channel | From -> to | Mechanism (MAME, OBSERVED or HYPOTHESIS) | Sync point | | --- | --- | --- | --- | | sound command | M -> S | an 8-bit latch written through the PIO's port A (0x18 on `wboyu`) or the 8255; the sound Z80 takes an NMI | the write's time | | video RAMs | M <-> V | tile, sprite and palette RAM writes; collision reads | every access (and every collision read) | | video control | M -> V | the byte written to port 0x19 each frame on `wboyu` (HYPOTHESIS: display enable, flip, banks) | the write's time | | vblank interrupt | V -> M | one IM 1 interrupt a frame (59 in 60 frames) | the edge | | timer interrupt | (S's own) | four a frame, 16,384 cycles apart (MAME's `soundirq`; U8) | inside S | | audio out | S -> host | samples | none (a pure producer) | ## Sync points and code invalidation (the JIT proposal's declarations) - **Sync points**: every channel above, plus interrupt sampling on both Z80s and the 8751. - **Memory kinds and writers**: | Memory | Kind | Written by | | --- | --- | --- | | main program ROM | ROM; on protected sets the bytes executed depend on whether the read is an M1 fetch (two views): a decode cache keys on the fetch path's output, not the ROM byte | nobody (the bank latch selects on System 2) | | main work RAM | RAM; code possible (not seen) | the main Z80 (and the 8751 through its window: U7) | | sound ROM, RAM | ROM, RAM | the sound Z80 (RAM) | | 8751 internal EPROM (4 KB) | ROM | nobody | - **Timing as data**: z80-python's per-instruction T-states; the sound Z80's READY waits as a board rule; MCS51's 12 clocks a machine cycle. ## The arithmetic: instructions per second | Processor | Clock | Rate per instruction (OBSERVED in MAME) | Instructions a second | | --- | --- | --- | --- | | main Z80 | 4 MHz | 10.2 cycles (`wboyu`, 60 frames); 12.0 in the first 3 | 4 M / 10.2 = **0.39 M** | | sound Z80 | 4 MHz | 10.6 cycles (`wboyu`, 60 frames) | **0.38 M** | | 8751 (3 sets) | 8 MHz / 12 = 0.667 M machine cycles | 1.71 machine cycles (`choplift`: 19,503 in 33,278) | **0.39 M** | | two PSGs | 2 + 4 MHz, divided by 16 | | 0.125 M + 0.25 M = **0.375 M** ticks | | video | 10 MHz dots | 640 x 260 x 60.096 | **10.0 M** dots, 6.9 M visible at MAME's 512 width (3.4 M if the hardware is 256 wide, U10) | **A board is 0.77 M CPU instructions a second** (1.16 M with the 8751), plus 0.375 M PSG ticks and 10 M dots. The CPUs are tiny; the per-dot video is the cost, as on every era-1 board. ## What that means per tier - **segasys1-python** (PyPy): the nearest precedent is sms-python (one 3.58 MHz Z80, one PSG, a VDP at 342 x 262 dots a frame, about 5.4 M dots a second by that arithmetic). This board has two Z80s at 4 MHz (about twice the CPU work) and about twice the dots if MAME's 512-wide raster is the hardware's (U10). sn76489-python runs a board's PSG load at about 22 times real time on PyPy (sn76489-rust README); two PSGs at 2 and 4 MHz are 1.7 times one SMS PSG's 3.58 MHz load, so about 13 times real time. Expect near real time or below on PyPy with per-dot video (HYPOTHESIS until the board runs); reference boards are correct, not fast. - **segasys1-rust**: z80-rust runs about 50 M instructions a second (its README, i9-13900K), over 60 times this board's 0.77 M; sn76489-rust runs 1,400-1,650 times real time. **The plain Rust transcription reaches real time on desktop, phone and browser**: a phone at a tenth of the desktop's single-core speed still has six times the CPU need, and the family already runs a Z80 arcade board (Galaxian, z80-wasm) in browsers. - **segasys1-rust-fast**: for run-ahead headroom only (1-2 frames double or triple the work); z80-rust-fast reaches 344-397 M instructions a second. - **Threads**: not needed. The sound domain is a natural thread at the latch channel, but the gain is small. - **Turbo / JIT**: not needed. `recompile: none` on every target, the iPhone included.