# Start here: the machine, the clocks, the module shape Read [README.md](../README.md) first, then this, then [memory-map.md](memory-map.md), [interrupts.md](interrupts.md), [video.md](video.md), [sound.md](sound.md), [system-rom.md](system-rom.md), [inputs.md](inputs.md), [cartridges.md](cartridges.md), [aes-vs-mvs.md](aes-vs-mvs.md), [sockets.md](sockets.md), [validation.md](validation.md), [mame-oracle.md](mame-oracle.md), and last [handoff-brief.md](handoff-brief.md) (scope, ladder, U and C lists, open decisions). Nothing here is code: this is Phase 0. ## What the machine is | Part | Chip | Owner | | --- | --- | --- | | Main CPU | 68000 at 12 MHz (master / 2) | `m68000-python` (pinned) | | Sound CPU | Z80 at 4 MHz (master / 6), 2 KiB RAM | `z80-python` (pinned) | | Sound | YM2610 at 8 MHz (master / 3) | `ym2610-python` (pinned when it exists) | | DAC | YM3016 floating conversion, the analogue mix | board (for now: `ym2610-python`'s decision 4) | | Video | LSPC2-A2 (or LSPC-A0) + NEO-B1 (or PRO-B0/PRO-C0), 68 KiB VRAM, 2 x 8 KiB palette | board | | Glue | NEO-C1, NEO-D0, NEO-E0, NEO-F0, NEO-G0, NEO-I0, NEO-257, 74HC259 system latch [CM:42-55, 164] (the role of each glue chip was the wiki's: [HYPOTHESIS: was wiki Memory mapped registers]) | board | | Calendar | uPD4990A (MVS) | board (chip rule: no second family user today) | | Cartridge chips | PCM/NEO-PCM2, NEO-ZMC/ZMC2, NEO-273, NEO-CMC, NEO-SMA, NEO-PVC, PRO-CT0, the KOF98 and Metal Slug X CPLDs | board's `cartridges` package | ## The machines as data One board, a machine table ([aes-vs-mvs.md](aes-vs-mvs.md)): crystal, slots, memory card, calendar and backup RAM, edge (JAMMA, MVS, console ports), system ROM list, IRQ map (the CD swaps the vblank and timer vectors: [interrupts.md](interrupts.md)). First row `MV1F`; then `AES_NTSC`; then the multi-slot rows. ## Clocks and time Everything is counted in **master clocks** (24 MHz MVS [CM:66]; AES 24.167829 MHz is [HYPOTHESIS: was wiki Clock], C1 provisional). A line is **1536** master clocks (384 pixels of 4), a frame 264 lines (405,504 master clocks; 59.1856 Hz MVS). The 68000 takes 2 master clocks per clock, the Z80 6, the YM2610 3, a pixel 4. **One timeline, one scheduler, owned by the board**: the 68000 is stepped an instruction at a time (plus wait states), and the Z80, the YM2610 and the LSPC are caught up to the 68000's clock before any access that can see them and at every LSPC event (megadrive-python's pattern: one 68000 instruction, then `catch_up_z80`). The LSPC runs on events within the line: the timer underflow, the vblank point (line `$1F0` + 58), the frame reload (`$1F0` + 1146), the line start (sprite parse for line N + 2, list swap, fix fetch), and the CPU's VRAM and palette slots. A reference board steps the line in 16-mclk slots only where a test needs it (VRAM read latency, palette CPU-access artifact, mid-line raster effects); otherwise it renders a line at its start from the state the pipeline would have latched. ## The module shape (proposed) ``` neogeo/ machine.py the machine table (rows as frozen dataclasses) board.py the 68000 map, open bus, wait states, the system latch, watchdog, resets sound.py the Z80 map and ports, latches, NMI gate, the YM2610 core's wiring lspc.py VRAM and its port, line counter, timer, IRQ lines, auto-animation, sprite parse render.py line rendering: sprites through L0 and the shrink patterns, fix, NEO-B1 buffers palette.py banks, the dark bit, the shadow latch, the DAC model (RGB only at the edge) io.py controller ports and devices, DIPs, coins, LEDs, slot select calendar.py uPD4990A memcard.py the card and its locks cartridges/ cartridge rows, plain ROM, banking, cmc, sma, pcm2, pvc, kof98, kof2002, mslugx, prot_ct0, sbp, vliner sockets.py the Protocols and the test-only fakes system.py run_frame, the scheduler ``` No module state (a second slot is a second cartridge instance). The cartridge package sits behind an import-boundary test so the board never imports a protection module directly. ## Performance: correct, not fast The reference board is **correct, not fast** (Aubrey's rule); speed is a later `neogeo-rust` and `-fast` project's job. Nothing was measured on a Neo Geo board. For scale: - `m68000-python` runs about 1.4 M instructions/s on CPython 3.14 and 33 M on PyPy 7.3.20 (its README, 2026-09-25). A Neo Geo 68000 executes on the order of 1.5 M instructions/s (12 MHz, 8 clocks on average): **about real time on CPython for the CPU alone, plenty on PyPy**. - `megadrive-python` (68000 at 7.67 MHz, Z80, YM2612, VDP) makes 16-21 frames/s on PyPy with FM: about a third of real time (its README). - `ym2612-python` runs at 0.104x real time on CPython and 0.028x on PyPy (its README; the long per-cycle loops defeat PyPy's JIT). A cycle-exact YM2610 built the same way will be the slowest part of this board. - Sprites: up to 96 sprites x 16 pixels per line through the shrink tables, plus 320 fix pixels, 224 lines: about 400,000 pixel decisions a frame, 24 M a second at 60 Hz. **Frank estimate**: on PyPy, 0.1-0.3x real time with sound and 0.3-0.6x with the YM2610 off; on CPython, 0.02-0.05x. That is acceptable for a reference: milestones are judged by traces, picture hashes and stream comparisons, not frames per second. Two things keep it from getting worse: the PyPy 80-attribute limit (keep each hot object under 80 attributes; the YM2612 core's 142 already break it), and rendering by line events, not by dot. ## Floors and rules (from Aubrey) Python floor **3.11** (newest PyPy supports): `requires-python = ">=3.11"`, ruff `target-version = "py311"`; PyPy must work. Modern forms over shims. Reference boards are correct, not fast. Never copy a chip file or code between repositories; depend on the pinned sibling; extract a chip on its second consumer. **System ROMs, cartridge sets and CD images are bring-your-own, read in place, never committed** (the `.gitignore` refuses their extensions). Local git only; no remote until Aubrey says. No dangerous-looking shell one-liners in scripts or docs.