# Start here: the machine, the clock, the module shape Read [README.md](../README.md) first, then this, then [memory-map.md](memory-map.md), [vdp.md](vdp.md), [psg.md](psg.md), [controllers.md](controllers.md), [cartridge.md](cartridge.md), [expansion.md](expansion.md), [validation.md](validation.md), [mame-oracle.md](mame-oracle.md), and last [handoff-brief.md](handoff-brief.md). Nothing here is code: this is Phase 0. ## The machine as data | | ColecoVision NTSC (1982) | ColecoVision PAL (1983) | | --- | --- | --- | | CPU | Z80A, 3.579545 MHz, one wait clock on every M1 cycle | same (crystal unverified: U7) | | Video | TMS9928A, 16K VRAM, 262 lines, 59.92 Hz | TMS9929A, 313 lines, 50.16 Hz | | Sound | SN76489A at the CPU clock, READY on `/WAIT` | same | | BIOS | OS-7, 8K, SHA-1 `45bedc4c...`; `$0069` = 60; logo delay count `$17` | SHA-1 `160077af...`; `$0069` = 50; logo delay count `$06` | | RAM | 1K, mirrored through `$6000-$7FFF` | same | | Frame interrupt | VDP `/INT` to Z80 `/NMI` | same | | Maskable interrupt | spinner pulses, IM 1 | same | One board, a machine table with two rows. The chip's variant and the BIOS hash are the row. ## Time One timeline in **VDP clocks** (10.738635 MHz, exactly three per CPU clock): a pixel is 2, a VDP memory cycle 4, a line 684, an NTSC frame 179,208. The board asks z80-python for one instruction, gets its T-states, adds the M1 waits and any READY wait, and runs the video and sound chips to each port access before serving it. z80-python steps by instruction and does not say where inside the instruction a port access falls; the board places it from the instruction's shape (`OUT (n),A`: the access is in the last machine cycle), as sms-python does, and that placement is part of what MAME lockstep checks. ## Module shape (proposed) ``` colecovision/ machine.py the two machine rows board.py decode, mirrors, BIOS, RAM, the timeline, M1 and READY waits, NMI edge, INT pulse controllers.py ControllerPort protocol; hand controller, Super Action, roller, driving module cartridge.py plain, MegaCart, Activision (+ 24Cxx EEPROM); chosen by argument or layout sockets.py the Protocols of expansion.md and their test-only fakes system.py run_frame, frames as colour indices, audio samples mame_log.py reader for the trace of mame-oracle.md (lockstep) ``` with `z80-python` and `sn76489-python` pinned by revision, the video chip from `tms9918-python` (or `colecovision/tms9918/` behind an import boundary: open decision 1), and nothing copied from a sibling. No module-level state. Package name **`colecovision`**, proposed by the task; the family's other boards are `sms_python`, `pcengine_python` (open decision 11). ## Performance Reference boards are correct, not fast. For scale only (nothing measured here): sms-python runs the same CPU core at the same clock with a line-based VDP; a VDP stepped by memory cycle (171 a line, 44,802 a frame) will cost more than that. Measure at M3 and keep `len(vars(obj)) < 80` on hot objects (the PyPy attribute limit). ## Rules that bind the build Python 3.11 floor, PyPy must work, modern forms over shims; never copy code between repositories; cartridges and BIOS are bring-your-own and never committed; smoke lists while iterating, full library sweeps only at commit points; commit locally at good points, never push without asking.