# Handoff: build `colecovision-python`, the ColecoVision board ## Context you are inheriting The family's shape: **chips are cores, boards compose cores; never copy code between repositories; a non-CPU chip gets its own repository when a second emulator could use it.** Each core is certified on its own; each board is validated against the best oracle its machine has, with MAME and other emulators as detectors only. Model this board on `sms-python` (same CPU core, same sound core, a TMS9918A inside it) and on `pcengine-python` for the sockets. Read, in order: [README.md](../README.md), [start-here.md](start-here.md), [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). Then `python -I scripts/fetch_references.py` (`--verify` to check) and a Gearcoleco libretro core (shipped build) at `reference/build-gearcoleco/` for the second detector; its source is not fetched (Aubrey, 2026-11-24). ## Scope In: the ColecoVision console, NTSC (TMS9928A) and PAL (TMS9929A) as two rows of one machine table; Z80A with the M1 wait; SN76489A with its READY wait; 8K BIOS, 1K RAM mirrored; two controller ports with keypad, the spinner interrupt, the Super Action Controller, Roller Controller and driving module; the cartridge slot with plain, MegaCart, Activision-EEPROM and X-in-1 boards; the expansion port as sockets. Later, as an add-on: the Super Game Module. Out: Expansion Module 1 (the 2600 adapter; `a2600-python` is that machine), the ADAM, the clones (Onyx, CZZ-50/Dina, Bit90), the Flashback. ## Names and the import boundary | Thing | Proposal | | --- | --- | | repository | `colecovision-python` | | package | `colecovision` as the task proposed; the family pattern would be `colecovision_python` (open decision 11) | | classes | `ColecoVision` (the system: `run_frame`, input, audio), `Board` (decode, timeline, waits, interrupts), `Machine` (frozen dataclass; rows `NTSC`, `PAL`), `ControllerPort` (Protocol), `HandController`, `SuperActionController`, `RollerController`, `DrivingModule`, `Cartridge` (Protocol), `PlainCartridge`, `MegaCart`, `ActivisionCartridge`, `XinOneCartridge`, `SerialEEPROM` | | video chip | `tms9918_python.TMS9918` with variants `TMS9918A`, `TMS9928A`, `TMS9929A` (open decision 1) | | Owner | Owns | | --- | --- | | `z80-python` | the instruction set, flags, IFF1/IFF2, IM, HALT, acceptance of NMI and INT, R and MEMPTR. **Pin**: release 0.4.0 (`500608c`, on PyPI; what sms-python requires). The local checkout's branch `retire-polish-brief` (`65e7f08`) is 9 commits ahead with "RESET clears I and R" and an opt-in CMOS `OUT (C),0`; repin when that is released | | `sn76489-python` | the PSG's registers, counters, noise and levels. **Pin**: `b0acbc8` (what both Sega boards pin) until the `SN76489A` row exists (open decision 4) | | `tms9918-python` (proposed) | VRAM, registers, the port latch and read-ahead, modes, sprites, status flags, the `/INT` level, the line and frame counters, access windows. Knows nothing of the Z80 or of NMI | | this board | the timeline in VDP clocks; memory and I/O decode with mirrors; BIOS and RAM; **the M1 wait and the READY wait**; turning the VDP's `/INT` level into an NMI *edge*; the spinner's `/INT` pulse; controllers; cartridge boards; sockets; frames as colour indices; the audio mix | | `ay8910-python` | the Super Game Module's AY, inside the add-on only | **What the board needs that the cores lack** 1. **z80-python: the number of M1 cycles in the step just made** (or a constructor option that adds N clocks per M1 cycle). Every opcode fetch costs 5 clocks on this console. Checked at 0.4.0 (`500608c`) and at the local branch head (`65e7f08`): the constructor takes only the four bus callables, `step()` returns a T-state total, and the opcode fetch goes through the same `read_byte` as a data read, so the board cannot see M1 cycles at all. It could derive the count from the change in R, but `LD R,A` breaks that and it reads a register to infer timing. Small, and other boards with M1 waits would use it (MSX: openMSX's race test says "Cycle counts include the MSX M1 wait state (+1 per M1 cycle)"). The count must include the M1 cycles of HALT, NMI response and interrupt acknowledge, so a board can choose whether those get the wait (C11). Nothing else is missing: `request_non_maskable_interrupt()` is the edge the VDP needs, `request_maskable_interrupt()` / `clear_maskable_interrupt()` are the spinner's pulse, IM 1 is there, and the READY wait is time the board adds after the `OUT`. 2. **sn76489-python: an `SN76489A` variant and a `zero_period` field** ([psg.md](psg.md)). Checked in `chip.py` at `b0acbc8` and `b30935d`: the `SN76489AN` row sets `low_periods_hold_high=True` ("tone periods 0 and 1 hold the channel's output high"); MAME 0.285's `sn76496.cpp` plays a TI chip's period 0 as `0x400` and period 1 as itself. The field has to cover period 1 as well. 3. Nothing from ay8910-python until the add-on. ## Sockets `MemoryOverride`, `IOPorts`, `AudioSource`, `InterruptLines`, `WaitLine`, `VideoSwitch`, `ControllerPort` x2, `CartridgeSlot` ([expansion.md](expansion.md)). Define them with test-only fakes in M1. **The gate**: with every socket empty and a plain cartridge, the lockstep replays and sweep rows are byte for byte what they were when the base was tagged; an add-on's first act is to run that gate. ## Milestones, each with its exit test | # | Milestone | Judge | Exit test | | --- | --- | --- | --- | | **M1** | **CPU, bus, BIOS**: decode and mirrors, the M1 wait, the READY wait, ports, a VDP that only keeps registers, VRAM, the port latch and a frame flag; sockets and fakes; the MAME log reader | the BIOS executing (tier 2); MAME instruction stream (tier 5) | the 2-second no-cartridge run of [mame-oracle.md](mame-oracle.md) replayed in lockstep: 945,993 instructions with identical registers and `totalcycles`, 17,821 I/O writes and the one status read (`$80` at clock 771,902) in the same order, **0 unexplained differences**, with the acknowledge-wait parameter set to MAME's choice (C11) | | **M2** | **VDP background**: Graphics I, II (with the R3/R4 masks), Multicolor, Text, the four undocumented combinations, 4K/16K addressing, blanking, backdrop | TI data manual (tier 2), Young (tier 3); detectors for pictures | the BIOS's no-cartridge screen and Zaxxon's title match MAME and Gearcoleco by colour index (MAME cropped by its 12-pixel border); the **Final Test Cartridge shows "ROM CHECKSUM D483 / ROM GOOD / RAM GOOD"**; one unit test per mode built from the manual's address tables | | **M3** | **Sprites and status**: 32 entries, Y = 208, four per line, 5S and its number, C, early clock, SIZE and MAG, F and the NMI edge (both ways it arises), the status read's side effects on the latch | TI 2.3 and 2.5 (tier 2), Young 4 (tier 3) | a 12-title smoke list (4 sprite-heavy, 4 that mask the NMI through R1, 4 chosen from detector disagreements) reaches gameplay with pictures equal to both detectors by index, or the difference is named; C1 and C2 written into the claims with the side taken | | **M4** | **Sound**: sn76489-python wired at port `$FF`, READY wait, mixer, WAV out | the core's own certification; MAME's `IW FF` log as a register stream | 5 games' register streams (port, data, clock) equal MAME's for 10 s each with the READY wait as the only modelled stall; the Final Test Cartridge's sound step steps through three tones and noise (checked by the register writes it makes); the period-0 question (C8) answered for the library by searching the streams for a period-0 write | | **M5** | **Controllers**: both segments, keypad codes and the two-key AND, fire buttons, the spinner's phases and `/INT` pulse, Super Action Controller, Roller Controller, driving module | Coleco's two test cartridges (tier 2); the BIOS's own decode | with scripted inputs the Final Test Cartridge's controller screen blanks every function and the Super Controller Tester registers every button and both spinner directions; the BIOS `DECODER`/`POLLER` return the expected codes; Turbo steers and Slither moves under scripted spinner input | | **M6** | **Cartridge boards**: MegaCart (64K-1M), Activision with 24C02/24C256, X-in-1 | MAME, openMSX, Gearcoleco, ColecoDS sources (tier 5 only) | unit tests built from the documented rules (synthetic images: bank n holds byte n); **real images only if Aubrey supplies them** (open decision 9); board choice by list CRC, then by size and header position | | **M7** | **Library sweep, PAL, lockstep**: all 200 cartridges, both machine rows | detectors | every cartridge boots to a picture equal to both detectors by index at three checkpoints, or is triaged with a named cause; 6 games lockstep against MAME for at least 20 M instructions with 0 unexplained; the PAL row boots the PAL BIOS and the European images; failures kept as the next smoke list | | **M8** | **Super Game Module** (add-on) | MAME `sgm.cpp`, Gearcoleco; ay8910-python's own judge | the base gate unmoved; RAM tests of the two regions; needs an SGM image to go further (open decision 9) | A milestone closes when its exit holds and its undecidable items are written into the certification record as "provisional, tier N". ## Unknowns (each with the best source available) | # | Unknown | Best source, tier | Status | | --- | --- | --- | --- | | U1 | CPU access windows: the slot schedule per mode, and what happens to an access that arrives before the last was served | TI table 2-2 (tier 2) gives delays only; Clock Signal models slots (tier 5) | provisional; decide the model in M2 (open decision 5) | | U2 | The status-read race on the TMS9928A: window width, what the read returns, and the dot at which F sets | TI says it exists (tier 2); measured only on V9938/V9958 (openMSX) | **undecidable without a console**; borrowed window flagged | | U3 | Does an interrupt acknowledge with PC's low byte in `$A0-$BF` read the VDP (the I/O decoder has no `/M1` and no `/RD` term)? | two independent tracings agree on the decoder (tier 3); Coleco's sheet is missing from the manual scan; MiSTer (tier 4) gates with `/RD`, MAME (tier 5) does nothing | **model it as drawn behind a switch, on by default**; only spinner games can trigger it; a console decides ([memory-map.md](memory-map.md)) | | U4 | What reads of the write-only blocks `$80-$9F`, `$C0-$DF` and of ports `$00-$7F` return | MAME: `$FF` (tier 5) | provisional | | U5 | What unmapped memory (`$2000-$5FFF`, absent cartridge selects) reads | none | provisional `$FF` | | U6 | Power-on state: RAM, VRAM, VDP registers other than 0 and 1, the CPU/VDP clock phase | TI: reset clears R0 and R1 only | zeros by default, seedable | | U7 | PAL consoles' crystal and so their CPU clock | MAME uses the NTSC one (tier 5) | provisional | | U8 | Whether the M1 wait also lengthens interrupt and NMI acknowledge and each HALT cycle | two tracings: the flip-flop is cleared only while `/M1` is high, so every M1 cycle (tier 3); MAME's `z80.lst`: fetches and HALT yes, acknowledges no (tier 5) | HALT settled (both say yes); acknowledges are C11 | | U9 | Fifth-sprite number reliability on real chips | forum reports only | noted, not modelled | | U10 | Sprite cloning/ghosting when Graphics II masks are in use | MAME to-do: "exact behaviour is not known" | not modelled | | U11 | When within a line the chip reads sprite attributes and latches registers | none above tier 5 | provisional | | U12 | The analogue audio path: levels, filtering, the mix with expansion audio | none | ideal mix | | U13 | SN76489A period 0, noise output stage, polarity, and whether its counters step in the YM7101's rotation | MAME's header (tier 5); TI silent | open decision 4 | | U14 | What bit 7 (the shaper's NAND output) and bit 4 (the one-shot) read with nothing on pins 7 and 9 | the circuit says bit 4 idles high; bit 7 depends on the NAND's floating input; MAME (tier 5) gives 0 | provisional | | U15 | Spinner `/INT` pulse width and the one-shot's length | RC products on the tracing (about 15 microseconds; 470 microseconds or 1 ms, the two ports' capacitors differ on Boris's drawing); MAME "TODO: measure" (11 and 500); MiSTer about 425; the manual's picture is too coarse | provisional; make them data per port | | U16 | Atarimax and other flash-cart banking; the Super Game Cartridge beyond one game; the community MegaCart FAQ (unfetchable by script) | none / tier 5 | out of the first build | | U17 | Why the manual's `/NMI` oscilloscope picture does not look like one pulse per frame at its stated sweep | tier 1 picture, not understood | noted | | U18 | The TMS9929A's vertical layout (TI's table gives the NTSC column only) and the provenance of the PAL ROM's short logo delay | MAME: top border 13 + 51 lines; our byte diff | provisional | ## Conflicts between sources | # | Conflict | Sides | Decision | | --- | --- | --- | --- | | C1 | What a status read clears | Young: bits 7 and 5; TI 2.3.3, MAME, sms-python: F, C and 5S | follow TI | | C2 | Do off-screen or dropped sprites collide | TI: sprites "partially or completely off the screen are also considered"; Young: a line dropped as a fifth sprite does not count | both, as stated: off-screen pixels collide, dropped lines do not; provisional | | C3 | The SN76489A's noise | sn76489-python and SMS Power: 15 bits, taps 0 and 1; MAME: the same register with the output one stage later, not inverted | same sequence; the stage and sign are open decision 4 | | C4 | The crystal | Coleco's manual: "7.19 MHz"; the same sentence's 3.58 MHz colour burst, and MAME: 7.15909 | 7.15909 | | C5 | Which chips have 262 lines | TI section 3.6.2: "TMS9918A/9929A operates at 262 lines" and, next sentence, the 9929A at 313 | a misprint for 9928A | | C6 | The PAL BIOS | a forum claim that every PAL dump is the NTSC ROM; MAME's `colecop` dump differs in 49 bytes (measured) | they differ; `$0069` and `$196A` matter | | C7 | How many cartridges skip the BIOS title | the common account: a few third parties; the census: 124 of 200 start `55 AA` | the census | | C8 | Tone periods 0 and 1 on the TI chip | sn76489-python's `SN76489AN`: both hold the output high; MAME: 0 plays as 1024, 1 toggles | open decision 4 | | C9 | Length of the READY wait | TI: "approximately 32 clock cycles"; MAME measured here: 28 added clocks; Clock Signal: "thirty-one" | match MAME for lockstep, as data; provisional | | C10 | When the frame flag sets | TI: "at the end of the raster scan of the last line of the active display"; MAME: as it begins line 192, at the left edge of the active area; Clock Signal: a constant quoted for Sega's chip | TI's wording, placed at the end of line 191's active pixels; provisional, and the lockstep's one status read will show MAME's offset | | C11 | Does the M1 wait lengthen the NMI response and the interrupt acknowledge? | two tracings: yes, every M1 cycle; MAME 0.285: no (fixed `+ 5` and `+ 2 + 5` in `take_nmi`/`take_interrupt`) | a board parameter; **follow the tracings by default**, and run M1's lockstep with MAME's choice so the replay is exact; the difference is one clock per NMI | | C12 | Controller bit 7 and bit 4 | tracings and MiSTer: bit 7 the shaper NAND's output, bit 4 the one-shot node, bit 5 pin 7 directly; MAME: bit 7 a 500-microsecond flag set per pulse, bits 4/5 XORed with `$10`/`$30` | the circuit; OS-7 only reads bits 4 and 5, which both sides agree on, so games that use the BIOS routine cannot tell | ## What was not verified in this phase - Nothing was measured on a console. Tier 1 is a few oscilloscope pictures in Coleco's manual. - **Coleco's own schematic is not in the pinned manual scan** (section V-1 is missing). The circuit claims rest on two community tracings (the 2021 KiCad redraw and Dan Boris's 2002 hand tracing), read by eye from rendered pages; they agree on the I/O decoder, the M1 flip-flop, the READY wire and the controller bits. Agreement of two tracings is not proof. - RC time constants (U15) are products of printed part values, not measurements. - AtariAge threads were seen only as search summaries (the site refuses scripted requests). - The ADAM manual was read only for its port sections; the F18A VHDL and MiSTer's `vdp18` were grepped, not read; Clock Signal, openMSX and ares were not built. - The two detectors were compared by eye on three screens; no library sweep was run (the rules forbid it in this phase); no PAL run. - Controller-to-title assignments in [controllers.md](controllers.md) are from titles, not runs. - MAME's 14-value `logerror` limit and its Lua traps are family knowledge, not re-tested here. - The exit-test sizes (20 M instructions, 12 titles) are targets, not measurements. ## Open decisions for Aubrey **Decided by Aubrey on 2026-11-12** (recorded after a walk through all fourteen Phase 0 briefs): - The Python package is `colecovision_python` (family rule set the same day: a repository `x-python` always imports as `x_python`); read any other package name in these documents as that. - Decision 1: **extract `tms9918-python`**, ColecoVision first (option A). Decision 2: sms-python keeps its own VDP for now and adopts the core later, at its next planned work; no re-sweep today. - Decisions 3 and 4: **approved** as issues on the cores: an opcode-fetch (M1) signal in z80-python, and an `SN76489A` row with a low-period setting in sn76489-python. Each core is recertified after its change. Build order: these two and tms9918-python come first, then this board's M1 (the ColecoVision track was chosen as the first build). - Referees built from die-derived material are built just before the rung that needs them, not up front. - Outside contacts proposed below are **deferred until the core or board exists**; Aubrey sends them himself, from a draft. - Remote: local through Phase 0; after the first passing rung or milestone, a private GitHub remote. Where a recommendation below names a different point, this replaces it. - Every other recommendation below is **accepted as written** unless a line here says otherwise. 1. **The video chip: extract `tms9918-python`, or build a second in-board TMS9918.** By the chip rule a chip gets its own repository when a second emulator could use it. Users of the TI part in the family's reach: this board (TMS9928A/9929A), sms-python's SG-1000 and SC-3000 rows (TMS9918A), and any later MSX1, ADAM, TI-99/4A or Spectravideo board. What exists today, read in `/data/emu/sms-python` (`main`, `3f26bc3`): one `VDP` class in `src/sms_python/vdp.py` (945 lines) serves the TMS9918A and four Sega VDPs, with the differences as `VDPVariant` data. The TI part is the row `TMS9918A = VDPVariant("TMS9918A", mode4=False, tms_status_low_bits=True)`, so it inherits **Sega's timing** (`SMS_TIMING`: FluBBa's SMS measurements in mclocks, flags at line-local `m = 0`), Sega's H/V-counter machinery, per-line rendering at one point in the line, and RGB output from a fixed `TMS9918A_RGB` palette; the TMS modes (`_render_tms`, `_tms_sprites`) share code paths with the Sega chips' legacy modes (`tms_cram`, the Mega Drive's blanking, `sms1_masks`). - *Option A, extract* (recommended): a new core repository `tms9918-python`, package `tms9918_python`, with its own short Phase 0 (most of it is [vdp.md](vdp.md) and [validation.md](validation.md)), built from TI's manual with this board as first consumer, stepping by memory cycle, frames as colour indices, variants `TMS9918A`, `TMS9928A`, `TMS9929A` as data. Nothing is copied from sms-python. For sms-python to adopt it later it would have to: (1) make `Board` pick the VDP class per machine row instead of always `VDP(machine.vdp, machine.region)` (`board.py` l. 170), so the SG-1000 and SC-3000 rows get `tms9918_python.TMS9918A`; (2) adapt the 15 VDP calls the board and I/O make (`run`, `irq`, `read_status`, `read_data`, `write_control`, `write_data`, `frame_ready`, `visible_frame`, `line`, `m`, `lines_per_frame`, `lines_started` and the three counter reads that the TI part answers with open bus), converting the core's colour indices to RGB in the board; (3) remove the `TMS9918A` row from `vdp.py` while the Sega variants keep their own legacy-mode code, since those modes on Sega's chips are a different implementation with different quirks; (4) move the TMS9918A cases in `tests/test_vdp.py` to the core or rewrite them against it; (5) re-run its SG-1000 and SC-3000 replays and sweep and accept moved rows, because the timing changes from Sega's to TI's. (Its `megadrive-pbc` and `fm-unit` branches have no commits beyond `main` as of 2026-11-12, so nothing would need rebasing today.) - *Option B, a second in-board VDP*: a `vdp.py` module in this board, written from TI's manual. Faster to a first picture, no cross-repository work, but the family then holds two independent TI-mode implementations that will disagree, and the next TI-VDP machine faces the same choice again. - Fallback inside A if a picture is wanted sooner: incubate it here as a sub-package behind an import-boundary test and move it out before M4. Never a copy of sms-python's code. 2. **When sms-python adopts that core.** *Recommend*: later and separately, on an sms-python branch, the five steps above, gated by its SG-1000 sweep and the M2 Check Program, expecting rows to move because its TMS9918A timing is Sega's today. Its Sega VDPs keep their own TMS modes. 3. **z80-python and the M1 wait.** *Recommend* raising it on the core (an M1-cycle count for the last step, counting the M1 cycles of HALT, NMI response and interrupt acknowledge separately so the board can apply C11) rather than inferring it from R in the board; pin 0.4.0 (`500608c`) until a release carries it. Until then M1 cannot start without a stopgap: the board's `read_byte` cannot tell fetches from data reads, so the only stopgap is the R-delta inference (R counts every M1 cycle except across `LD R,A`), marked as such and removed on repin. 4. **sn76489-python.** *Recommend* an issue on the core for an `SN76489A` variant row and a low-period field covering periods 0 and 1 (`"high"`, or MAME's 1024 and plain toggling), leaving the SG-1000's `SN76489AN` row as it is; decide the ColecoVision's value from the library's register streams at M4. 5. **How much VDP timing in the first build.** *Recommend* stepping by memory cycle from the start (the structure is cheap to have and expensive to retrofit), access windows from TI's table as data, and **the status-read race off by default** with a switch, because its window is measured only on another chip. 6. **The Super Game Module.** *Recommend* a separate add-on repository (`colecovision-sgm-python`) pinning this board and `ay8910-python`, started only once an image that needs it is in the library. 7. **PAL.** *Recommend* a machine-table row from M1 (the chip variant, 313 lines, the PAL BIOS by hash), swept at M7; 8 of the 200 library images are Europe-only. 8. **BIOS handling and the logo delay.** *Recommend* bring-your-own, read in place by path, checked by SHA-1, never committed; no hacked ROMs fetched; if a short logo is wanted, a documented in-memory patch of `$196A` behind a flag, off by default. 9. **Images for the modern boards.** The library has no MegaCart, Activision-board, multicart or Super Game Module image (No-Intro's Aftermarket folder is empty). *Recommend* building M6 from synthetic images and MAME's rules, and treating those boards as untested against real software until Aubrey adds homebrew images he owns. 10. **ADAM and Expansion Module 1.** *Recommend* out of scope; the ADAM recorded as a possible later board that would pin this board's chips (it needs a 6801 core and ADAMnet). 11. **Package name.** The task proposed `colecovision`; every sibling uses the `_python` suffix (`sms_python`, `pcengine_python`). *Recommend* `colecovision_python` for consistency, unless the short name was deliberate. 12. **Local or remote.** *Recommend* local through M3, then a private GitHub remote with the minimal CI the other boards use (PyPy only, main and pull requests, concurrency cancel); the BIOS stays out of the repository either way. 13. **Where the drawings and MAME disagree, which is the default.** *Recommend* the two tracings (tier 3) over MAME (tier 5), each behind a switch: the acknowledge-time VDP read of U3 on, the M1 wait on acknowledges (C11) on, the spinner bits as wired (C12); the M1 lockstep runs with the switches set to MAME's behaviour, and the certification record names each switch as "provisional, tier 3" until someone with a console measures it.