# Domains, channels and speed ## Domains (proposed for the specification) | Domain | Parts | Clock | | --- | --- | --- | | **main** | MC68EC020, work RAM, ROMs, K056832, K055673/K053246, K053936 (types 1/3/4), K055555, K054338 + colour RAM, K053252, the ESC (a bus master on this bus), 93C46, inputs, ADC0834, watchdog | 24 MHz CPU; dot clock 6-32 MHz by `DOTSEL` | | **sound** | MC68000, its ROM and RAM, two K054539s, the K056800's sound side | 8 MHz CPU; 18.4 MHz PCM | | **dasp** | TMS57002, its 256 KB delay DRAM, the 056602 DAC | 24 MHz in, 46,875 Hz frames | The ESC stays inside **main**: it takes the 68EC020's bus with `BR`/`BG` and shares its memory cycle by cycle (the charter's "tightly coupled processors usually stay one domain"). ## Channels | Channel | Between | What crosses | Evidence | | --- | --- | --- | --- | | K056800 registers (16 each side) | main <-> sound | bytes; `SNDINT` to the 68000 | DOC (pins), OBSERVED (maps) | | `SOUNDRESET`, `TOP1RES`, `TOP2RES` | main -> sound | reset lines | DOC | | DASP host port (`300001`) and latch (`500000`) | sound <-> dasp | program and coefficient bytes; `PLOAD`, `CLOAD`, `BIO`, `MUTE`, `DSPRESET` out; `DREADY`, `EMPTY`, `PC0` back | DOC (pins), OBSERVED (handler names) | | serial audio `SINPUT0/1`, `AXLRO`, `TOP2DTCK` | sound -> dasp | two stereo sample streams a frame (the K054539s' mix as routed by the K056800) | DOC | | `SOUT0/1` | dasp -> DAC | the output samples | DOC | | `CCUINT1/2`, vertical blank | main (CRTC -> CPU) | interrupts (internal to main) | DOC | | picture producer | main -> host | a log of video RAM and register writes per line | design | Sync points for threads: the sound domain may run ahead of main until main next touches the K056800 or a reset line; the dasp domain may run behind sound by a sample buffer until the 68000 reads the DASP's status or port (during program load it polls; in play the reads are rare: to measure, U21). ## The need, with its arithmetic Measured with MAME 0.285 as a closed box (windowed traces at 25 s, attract mode, one emulated second each; [mame-oracle.md](mame-oracle.md)): | CPU | Game | Instructions / s | MAME cycles / instruction | Note | | --- | --- | --- | --- | --- | | 68EC020 | Salamander 2 | 3,883,784 | 6.18 | 93% in a four-instruction wait loop | | 68EC020 | Sexy Parodius | 3,892,901 | 6.17 | 89% in a wait loop | | 68EC020 | Run and Gun 2 | 3,931,472 (counted from MAME's trace file) | - | 92% in a two-instruction wait loop | | 68EC020 | Racin' Force | 3,352,337 | 7.16 | **51% of instructions run from work RAM**; 54 frames a second | | 68EC020 | Salamander 2, boot | 5,155,669 | 4.66 | ROM/RAM test | | 68000 | Salamander 2 | 508,410 | 15.7 | | | TMS57002 | Salamander 2 | 12,000,020 | 1.00 | 256 per sample x 46,875 samples | The 68EC020 figures depend on MAME's cycle tables (Musashi-derived: fixed counts per instruction). A real 68020 running a tight loop from its cache is faster per instruction (the manual's best case), so **the exact figure for an interpreter that runs the wait loops could be up to about twice MAME's** (HYPOTHESIS; U1). Planning numbers: - 68EC020: **5 M** instructions a second typical, **10 M** worst case. - 68000: 0.5 M. TMS57002: 12 M (fixed by the program length and the sample rate). - **Total: about 18 M a second typical, 23 M worst**, against the Mega Drive's ~2.5 M (68000 ~1.6 M + Z80 ~0.9 M): **7-9x the Mega Drive's instruction load**. - Clock ticks to interleave (rational time): 24 M (68EC020) + 8 M (68000) + 12 M (DASP instruction slots) + 2 x 46,875 x 8 channel steps (K054539: ~0.75 M) ≈ **45 M a second**, 4x the Mega Drive's 11.25 M and 1.9x the TMNT-era Konami boards' 24 M. - Pixels: 384 x 264 x 59.19 = **6.0 M dots a second** at 6 MHz (most games); 8 M at 8 MHz (Racin' Force, Open Golf, Run and Gun 2); the dual-screen type 3/4 games draw two screens, 576 or 384 wide (OBSERVED `-listxml`), so up to roughly 2-3x that (U22 for their dot clocks). ## Can the no-JIT path reach real time? Family figures: m68000-rust 101-157 M instructions a second; megadrive-rust 4-6x real time with sound; megadrive-rust-fast x1.56 on top (konami68k-python's domains-and-speed.md). Reference: **MAME 0.285 runs these games at 340-406% of real time on this desktop**, one thread, with its own C++ interpreters and a high-level ESC (OBSERVED: "Average speed" of the snapshot runs: salmndr2 342%, racinfrc 340%, rungun2 406%, sexyparo 347%). - **CPU instructions alone**: 18-23 M a second is 12-23% of m68000-rust's rate. Not the wall, but no longer negligible; the DASP's 12 M simple multiply-accumulate steps are half of it. - **Plain Rust, desktop**: scaled from megadrive-rust by the instruction and tick loads above (4-9x the Mega Drive's), **~0.7-1.5x real time** (HYPOTHESIS). Not enough with margin. - **`-fast`, desktop**: x1.4-1.9 on that: **~1-2.5x** (HYPOTHESIS), roughly MAME's class. - **Threads at the channels** (`-fast`): the dasp domain is a pure-looking producer of samples from its inputs and its program; on its own thread it removes about half the instruction load from the main thread. The picture producer removes the pixel work. With both: **~2-4x desktop** (HYPOTHESIS), enough for desktop native and run-ahead 1. - **Cached interpreter** (turbo): the 68EC020's code is in ROM for three games but **half in work RAM for Racin' Force**, so the decode cache must invalidate on writes to RAM it has decoded (the JIT proposal's invalidation tests; the 68020's own cache and CACR clear give a natural hook). The TMS57002's program is a fixed 256-word loop between loads: pre-decoding it once per program load into a straight-line list of operations is the board's single biggest no-JIT win (HYPOTHESIS), and invalidates only on `PLOAD`. - **Desktop browser** (WebAssembly ~1.5-2x slower, threads only with cross-origin isolation): ~1-2x with threads, below real time without (HYPOTHESIS). - **Phones** (a third to a half of this desktop): native with `-fast`, threads and the cached interpreter ~1-2x; **phone browsers likely below real time**. - **`recompile: none`** is expected to meet **desktop native and desktop browser with threads**; **phones are marginal and phone browsers are not expected to reach real time** without a concession (HYPOTHESIS until a Rust board measures it). Candidate concessions, each a named switch, off by default: **DASP bypass** (the K054539 mix straight to the DAC: loses the effects, saves half the instructions) and **idle-loop skipping** on the 68EC020's vertical-blank wait (only if proven not to change any read the CPU makes; otherwise it is a turbo fast path, not a concession). - **Python**: 18-23 M instructions a second is out of reach for Python (PyPy manages a few million simple emulated instructions a second at best): ~0.05-0.2x real time with PyPy (HYPOTHESIS). The reference is correct, not fast; its tests are short and targeted (the charter's era-3 note fits this era-2/3 board).