# Domains, channels and speed ## Domains and channels (proposed) | Domain | Parts | Clocks | | --- | --- | --- | | **Main** | the 68000 (or KONAMI CPU), work RAM, K052109/K051962, the sprite pair, K053251 or PROM, palette and colour output, inputs, output latches, ER5911, 051550 watchdog, K054000 | 68000 8/12/16 MHz; video 6 MHz dot clock. GX063/064: 32 MHz crystal / 2 for the 68000 and a separate 24 MHz clock (DOC, sheet 5); 6 MHz = 24 / 4 (HYPOTHESIS) | | **Sound** | Z80, its RAM and banked ROM, YM2151, K007232 / K053260 / K054539, uPD7759, the title-tune DAC (tmnt) | Z80 3.58 or 8 MHz; YM2151 3.579545 (4 MHz on xmen); K054539 18.432 MHz; uPD7759 640 kHz | **Channels** (the only places the two meet): - the sound command path: tmnt/aliens latch + IRQ line; the K053260's four ports (two each way) and the IRQ write; the K054321 on xmen and prmrsocr; - the sound CPU's reset line, where a main-CPU latch drives it (xmen, HYPOTHESIS: U23); - the picture and audio producers: drawing from a register-and-RAM write log of the main domain's video chips; PCM and FM synthesis from the sound domain's register writes. The K053260 sits in **both** domains (its ports face the main CPU, its voices face the Z80). The specification models it as two halves joined by its port registers: the ports are the channel; nothing else crosses. The same holds for the K054321. **Order of record**: by bus time, earlier first, main before sound on a tie. The clocks do not share an obvious master (16 MHz from 32 MHz, 6 MHz from 24 MHz, YM2151 from a 3.579545 MHz crystal, the K054539 from 18.432 MHz), so the timeline should be rational time (a count of a common fine unit per row, as megadrive-python does for its two crystals), chosen per row in M0 (U24). ## How much work (arithmetic shown) Measured on MAME 0.285 over emulated frames 60-118 of a 2-second boot trace ([mame-oracle.md](mame-oracle.md)): instructions per second = instructions in those frames / (58 frames / 59.1856 Hz). | Set | Main CPU instr/s | Main cycles/s | Sound Z80 instr/s | Z80 cycles/s | | --- | --- | --- | --- | --- | | tmnt | 1.05 M (68000) | 8.0 M | 0.35 M | 3.58 M | | punkshot | 1.26 M (68000) | 12.0 M | - (not traced) | 3.58 M | | ssriders | 2.15 M (68000) | 16.0 M | 0.74 M | 8.0 M | | xmen | 1.95 M (68000) | 16.0 M | 1.04 M | 8.0 M | | simpsons | 0.82 M (KONAMI) | 3.0 M | 0.52 M | 3.58 M | | aliens | 0.66 M (KONAMI) | 3.0 M | - (not traced) | 3.58 M | Heaviest row: **Sunset Riders / X-Men, ~3.0 M instructions a second** (2.15 + 0.74; 1.95 + 1.04), **24 M CPU clock ticks a second to interleave** (16 + 8), 6.0 M dots a second (384 x 264 x 59.1856), YM2151 at 55,930 samples a second (3,579,545 / 64), and on X-Men eight K054539 channels (at 48 kHz if its rate is 18.432 MHz / 384: HYPOTHESIS). For comparison, the Mega Drive interleaves 11.25 M ticks (7.67 + 3.58): Sunset Riders is about **2.1x the Mega Drive's bus work** with a simpler picture (no VDP DMA, no line-interrupt raster tricks seen yet). The 8-bit rows (simpsons, aliens) are about a third of that. ## Can the no-JIT path reach real time? Family measurements: m68000-rust 101-157 M instructions a second; megadrive-rust 4-6x real time with sound; megadrive-rust-fast x1.56 on top. - **Instructions**: 3 M a second is 2-3% of m68000-rust's rate; the CPUs are not the cost. - **Plain Rust, desktop**: scaled from megadrive-rust by bus work, **~2-3x real time** (HYPOTHESIS). Enough, with room for one run-ahead frame. - **`-fast`, desktop and desktop browser**: ~3-4.5x native; WebAssembly at 1.5-2x slower gives ~1.5-3x in a browser: real time with run-ahead 1 (HYPOTHESIS). - **Cached interpreter**: all code runs from ROM (OBSERVED in every trace: no PC outside ROM), so a decode cache never invalidates in practice; the board must still detect code in RAM and fall back. It helps phones most. - **Threads at the channels**: the sound domain meets the main domain only at the ports and lines above, so it can run ahead to the next port access; the picture producer runs beside the main domain from its write log. Whether running ahead pays depends on how often the 68000 polls the ports (to measure in M5). - **Phones (native and browser)**: at a third to a half of this desktop, plain Rust is around real time; `-fast` plus the cached interpreter should reach it, threads give margin. **`recompile: none` is expected to meet every target** (HYPOTHESIS until the Rust board measures it); no JIT is needed for this board. - **Python**: a 16 MHz 68000 plus an 8 MHz Z80 is far from real time in Python. The reference is correct, not fast.