# Results: each milestone's exit test, as measured Every number here was produced by a command in this file on the date given, on the shared machine (load average 40+, so times move between runs). CPython is 3.14.4; PyPy is 3.11 / 7.3.20 with `PYPY_GC_NURSERY=1M`. Pins: z80-python `f97c0f5` (branch `m1-fetch-hook-rebased`), tms9918-python `df9d8ae`. ## M1: CPU, bus, BIOS (2026-11-12) — verified **Exit test**: the 2-second no-cartridge MAME 0.285 trace (`tests/mame_traces/coleco-nocart/error.log`, docs/mame-oracle.md) replayed in lockstep, with MAME's choice on every switch (`mame_options()`: C11 off, U3 off, VDP accesses served at once, F at line 193, R1 bit 7 inert, MAME's power-on registers AF = $0040, IX = IY = $FFFF). ```sh python scripts/lockstep_mame.py tests/mame_traces/coleco-nocart/error.log pytest tests/test_lockstep.py ``` | Compared | Count | Differences | | --- | ---: | ---: | | instructions: PC, AF, BC, DE, HL, IX, IY, SP, AF', I, R and `totalcycles` before each | 945,993 | 0 | | port writes (port, data, instruction-start clock), in order | 17,821 | 0 | | port reads (the one status read, `$80` at clock 771,902) | 1 | 0 | Board clock at the end: 7,168,327 (MAME's last instruction starts at 7,168,314 and takes 13). Wall time: CPython 7.3 s, PyPy 1.8 s. **Seeded faults** (`tests/test_lockstep.py::test_seeded_fault_is_caught`), each caught by the replay (1 difference): | Fault | Caught at | | --- | --- | | READY wait 27 instead of 28 | instruction 10 (`OUT ($FF),A` one clock short) | | READY wait 29 | instruction 10 | | prefix bytes without the M1 wait | first prefixed instruction | | RAM only at `$6000-$63FF` (no mirror) | first stack use at `$73xx` | | power-on registers the core's zeros instead of MAME's | instruction 0 (AF, IX, IY) | | VDP never run (F never set before the status read) | the status read (`$00` against `$80`) | What this replay does **not** exercise: no interrupt is taken in these 2 s (the BIOS leaves the NMI off on this screen), so C11 and U3 are untested here (unit tests in `tests/test_board.py` cover both settings); the status read happens long after F sets, so the frame-flag dot and the VDP phase are not checked by it (shifting the phase by half a frame or moving F to TI's dot leaves the replay at 0 differences). **Unit tests M1** (`tests/test_board.py`): instruction clocks with the M1 wait for 12 instruction shapes (prefixes, `DD CB`, stray `DD`, `OUT`/`IN`, the READY wait), HALT cycles (5 each), `OTIR` to `$FF` (51 and 46 clocks), C11 on and off for NMI (11/12) and IM 1 (13/14), the RAM mirror, open bus (U4, U5), the VDP's `$A0-$BF` decode with A0, controller segments and the keypad AND, the NMI edge (including setting IE while F is up), U3 on and off, each socket with its fake, the VDP's power-on phase (line 203, dot 315) and clear status. ## M2: VDP background (2026-11-12) — verified The modes themselves are tms9918-python's (its rungs 0-3); the board's part is the decode, the timeline and the BIOS reaching its screens. **Exit test**: pictures compared by colour index (`colecovision_python.pictures`: the detectors' RGB read back through their shared 16-colour table; 0 and 1 one class), with the board's defaults and with `mame_options()`: ```sh pytest -m slow tests/test_pictures.py python scripts/compare_pictures.py CART DETECTOR.png... --frames N [--mame] ``` | Screen | Board frame | MAME 0.285 snapshot (280 x 216, border cropped) | Gearcoleco frame 300 | | --- | --- | ---: | ---: | | no cartridge (BIOS logo, "TURN GAME OFF...") | 119 | 0 pixels differ (default), 0 (MAME options) | not run: Gearcoleco refuses a headerless image | | Zaxxon title | 299 | 0, 0 | 0, 0 | | Final Test Cartridge | 299 | 0, 0 | 0, 0 | Each comparison is 49,152 pixels. **The Final Test Cartridge's verdict**, read from its name table (`test_final_test_cartridge_verdict`): rows 5, 6, 8 = "ROM CHECKSUM D483", "ROM GOOD", "RAM TEST RAM GOOD" (D483 is the NTSC dump's 16-bit byte sum). Seeded fault: the no-cartridge frame against Zaxxon's picture differs in more than 1,000 pixels (`test_comparison_can_fail`). **Mode tests** (`tests/test_video_modes.py`, 13): Graphics I, Graphics II with full masks and with R4 = 0 (all thirds use third 0's patterns), the R3 mask on the colour table, Multicolor, Text, Text + thirds, Multicolor + thirds, the two table-less combinations, blanking, transparent colour over the backdrop, and 4K mode moving the DRAM cell with the core's C11 default but not with MAME's settings. Each expected pixel is computed from TI's address rules (data manual 2.4-2.7), Young 3.3-3.7 for the undocumented combinations, and TI table 3-3 for the text mode's 6-pixel offset (left border 19 against 13). **The 4K watch-point** measured: the BIOS makes 16,384 data writes before it first sets R1 bit 7 (clock 772,205). With power-on VRAM zeros the four combinations of the core's `roll_over_4k`/`mux_4k` give identical VRAM (806 non-zero cells after 2 s) and identical pictures. With seeded power-on VRAM the roll-over leaves 11,732 seeded cells and 11,253 differing pixels on the title screen ([core issue 0002](core-issues/0002-4k-rollover-leaves-bios-clear-incomplete.md)). Wall time for the six picture comparisons and the verdict: CPython 59.9 s, PyPy 10.7 s. ## M3: sprites and status (2026-11-12) — verified with named differences The sprite engine and status bits are tms9918-python's; the board's part is the NMI edge, the timeline and the clocks of the status reads. C1 and C2 are decided in the core (its C1: a status read clears F, 5S and C, following TI; its C7: off-screen pixels collide, dropped fifth-sprite lines do not) and recorded in [claims.md](claims.md). **Smoke list** (`tests/smoke/m3.tsv`, chosen by a board survey of 24 titles over 1,500 frames): 4 sprite-heavy (Donkey Kong, Frogger, Venture, Pitfall!: 5S set in 256 to 1,481 status reads), 4 that mask the NMI through R1 (Mr. Do! 657 times, Defender 1,112, Popeye 668, BurgerTime 2), 4 that poll status instead of taking the NMI (Smurf 345,512 reads, Carnival, Q-bert 648,505, Root Beer Tapper) — the last four also where MAME and Gearcoleco disagree most (Smurf 2,469-2,669 pixels between the two detectors, BurgerTime 5,099, Q-bert 624, Carnival 480). Inputs scripted per title (keypad 1 at frame 800, a direction, fire); all 12 reach gameplay by frame 1,700 (contact sheet checked by eye). **Method**: `scripts/smoke_pictures.py` runs MAME 0.285 (`scripts/mame_frames.py`, inputs through its frame notifier), Gearcoleco (`scripts/libretro_run.py --input --snap`) and the board with the same inputs, and compares 4 pictures per title by colour index (49,152 pixels each). Frame and input timing were measured, not assumed: MAME's frame notifier k fires at CPU clock 59,736.0056 (k + 1) (a 5,369,317 Hz pixel clock), its frame k is the board's frame k + 1, and a field set in notifier k - 1 reaches the game at notifier k. `--io` also replays MAME's full port-access log (`scripts/mame_io.py`, `scripts/replay_io.py`). | Board options | Pictures equal to MAME | Pictures equal to Gearcoleco | MAME and Gearcoleco disagree | of those, board = MAME | | --- | ---: | ---: | ---: | ---: | | `mame_options()`, PyPy | 44 of 48 | 31 of 48 | 16 | 13 | | defaults (tracings, TI flag dot, windows on), PyPy | 39 of 48 | 31 of 48 | 16 | 9 | The four `mame_options()` pictures that differ from MAME: Defender frames 1300 and 1700 (4 and 3 pixels) and Carnival 1300 and 1700 (91 and 520): in both the port-access replay had already diverged at a status read (below), so the games ran on from different status values. With the defaults, 9 pictures differ (103 to 3,100 pixels), all in frames after the first NMI, where the switches move the timeline: C11 adds one clock per NMI, F sets at TI's line 191 instead of MAME's 193, and VRAM writes wait for access windows. Every Gearcoleco difference with `mame_options()` equals the MAME-vs-Gearcoleco difference at the same frame (e.g. Donkey Kong 900: 651 and 651) except where the board also differs from MAME: Gearcoleco runs one frame apart on inputs (Donkey Kong at 900 equals the board's frame 900 before input timing was corrected). Gearcoleco's frame and input timing were not measured; it is the weaker detector here. **Port-access replay against MAME** (`mame_options()`; every access: kind, port, value, instruction-start clock): | Title | Accesses identical | First difference | | --- | ---: | --- | | Mr. Do! | 149,725 (all, 1,701 frames) | none | | Defender | 600,135 | status `$22` against `$02` at 49,433,580 (C) | | Q-bert | 517,062 | status `$45` against `$1F` (5S timing) | | Pitfall! | 106,318 | status `$F1` against `$E7` (number) | | Donkey Kong | 66,954 | status `$BF` against `$E8` (5S timing) | | Carnival | 56,952 | status `$44` against `$1F` (5S timing) | | Smurf | 56,652 | status `$47` against `$1F` | | Root Beer Tapper | 52,025 | status `$04` against `$1F` (number) | | BurgerTime | 44,248 | status `$44` against `$1F` | | Venture | 39,378 | status `$8D` against `$9F` (number) | | Popeye | 32,801 | status `$80` against `$9F` (number) | | Frogger | 156 | first status read, frame 0: `$80` against `$9F` (number) | All 11 first differences are status-register reads whose 5S, C or number bits differ: the core's sprite-status timing and bookkeeping (its provisional C5, C6, U4, U10) against MAME's line-start evaluation. Named and raised as [core issue 0003](core-issues/0003-sprite-status-timing-vs-mame.md). No CPU, wait-state, decode or NMI-timing difference remains in these 1.7 M accesses after two fixes found by this replay: MAME's 5,369,317 Hz video rounding and its interrupt arriving about one CPU clock early (both reproduced only under `mame_options()`, [claims.md](claims.md)), and the input-timing rules of the harness. **CPython**: the same smoke list with `mame_options()` gives the same 48 rows, digit for digit (`diff` of the two outputs: identical). Speed in these runs (1,701 frames each, `mame_options()`): PyPy 9.7 to 47.7 s per title (35.7 to 175 frames/s, 0.60 to 2.9 x real time); CPython 60.5 to 94.5 s (18.0 to 28.1 frames/s, 0.30 to 0.47 x real time). With the defaults (windows on), PyPy 10.4 to 30.0 s. ## M4: sound (2026-11-12) — verified, both interpreters The chip is sn76489-python `c0d88a6` (`main`, the restart written from documents; the first pin given for this milestone was withdrawn with the earlier core), its `SN76489AN` row, wired at `$E0-$FF`: the board runs it to each write's clock (`Board.run_psg`) and keeps its own 28-clock READY wait (C9). `audio.Mixer` takes its levels to 44,100 Hz mono and sums the expansion `AudioSource`; `--wav` writes the run's sound. No GPL or LGPL sound-chip source was opened for any of this (the core's restart rule); sound was compared only as outputs. **Rendered sound** (`tests/test_audio.py`, both interpreters): a program writing channel 0 period 169 plays at 661.9 Hz within 5 Hz (zero crossings per emulated second); seeded fault (chip run at half the CPU clock) caught; `OUT ($FF),A` still 40 clocks with the chip attached; the mixer gives 44,100 samples per emulated second; the WAV header and samples round-trip. **Against MAME's recording, as a detector** (`scripts/compare_audio.py`): the Final Test Cartridge for 2,400 frames, the board's `--wav` against MAME 0.285's `-wavwrite` at 44,100 Hz, in 2,402 windows of 1/60 s: sounding/silent agree in 2,392 windows (board 183 sounding, MAME 175); RMS envelope correlation 0.9970; spectral shape (48 log-spaced frequencies, 100-8,000 Hz) in the 174 windows where both sound: cosine similarity median 0.867, 10th percentile 0.747, minimum 0.584. Seeded fault (every tone period doubled): median 0.572, 10th percentile 0.479. The CPython and PyPy WAV files are byte-identical (CPython 92.7 s, 0.43 x real time; PyPy 19.1 s, 2.1 x). MAME's output filtering and levels are its own; the remaining spectral difference is not attributed (U12). **Earlier results with the chip attached** (smoke list rerun on PyPy with MAME's and the default switches and on CPython with MAME's; the M7 failure list; the PAL list; the whole test suite with `-m "slow or not slow"`, 99 tests, on both interpreters): every picture count and every port-replay first difference is the same as before, digit for digit. The only change in the outputs is the title column, no longer cut at 40 characters. Gearcoleco's pictures of Artillery Duel came out different on its rerun (a detector's own variation; the board's and MAME's counts are unchanged). **Measured without the chip, still standing:** 1. **Register streams against MAME** (`scripts/sound_streams.py --frames 1800`: every port access in order with its instruction-start clock, READY as the only stall, MAME's switches; 30 emulated seconds; "game" writes are those after the BIOS's four silencing writes, i.e. after the 12.9-17.2 s title screen of these `AA 55` titles): | Title | Accesses identical (all) | Game sound writes identical | Span of game sound | | --- | ---: | ---: | ---: | | Mr. Do! | 160,916 | 6,332 | 17.1 s | | Cosmic Avenger | 149,825 | 6,521 | 16.5 s | | Zaxxon | 236,629 | 6,149 | 12.8 s | | Gorf | 104,860 | 5,032 | 17.1 s | | Pepper II | 119,339 | 7,809 | 16.7 s | | Mouse Trap | 162,995 | 5,528 | 16.6 s | 0 differences in all six, on PyPy and on CPython (outputs identical). Eight other titles tried stop earlier at a status read (core issue 0003), before 10 s of sound. 2. **The Final Test Cartridge's sound step** (`scripts/final_test.py`, board defaults): "SOUND TEST" on screen from frame ~1,050; it writes 236 sound bytes in 2,400 frames: three tones together on channels 0, 1, 2 (periods 169, 213, 286, then 213, 286, 339, ...) at attenuations 6, 7, 9 and others, each chord followed by all four channels off, then the noise generator: noise control 7 (white noise clocked by channel 2's period) with attenuations 0, 2, 4, ... while channel 2's period is stepped, including periods 0 and 1 for one frame each (59,720 and 59,755 clocks heard). 3. **Periods 0 and 1 in the library (C8)**: `scripts/psg_sweep.py` ran MAME on all 200 cartridges for 1,800 frames each (generic inputs; 207 s), logging every write to `$E0-$FF`: 1,018,254 sound writes. `scripts/psg_streams.py` replays the register file and measures the time each channel spends at period 0 or 1 **while its attenuation is not 15** (when the two readings, "held high" and MAME's "0 plays as 1,024, 1 toggles", sound different). 78 titles write period 0 at some point, 23 period 1. Audible time at period 0: never in 73 titles, at most 1,000 clocks in 108 (start-up transients: a channel switched on before its period is written, about 103 clocks), up to one frame in 13, more than a frame in 6. At period 1: never in 182, more than a frame in 7. The titles where it is long enough to hear: | Title | Period 0 heard | Period 1 heard | How | | --- | ---: | ---: | --- | | Dragon's Lair (Proto) | 78,466,376 clocks (21.9 s of 30) | 2,428,260 | tone channels 0 and 2, 2,563 writes of period 0 | | Memory Manor | 0 | 4,179,986 (1.17 s) | channel 1 | | Strike It! | 2,923,599 (0.82 s) | 0 | channel 0 | | Oil's Well | 895,411 (0.25 s) | 0 | channel 0 | | BC's Quest for Tires (USA and Canada) | 299,326 | 298,642 | channel 2 and noise clocked by it | | Space Panic | 309 | 359,406 | noise clocked by channel 2 at period 1 | | Masters of the Universe (Proto) | 129,830 | 132,747 | noise clocked by channel 2 | | Final Test Cartridge | 59,720 | 59,755 | noise clocked by channel 2 (the factory test) | So the question is audible in the library: under "held high" Dragon's Lair's two channels would be silent for most of the run and Coleco's own test would play no noise for two frames; under MAME's reading they play a 109 Hz tone (period 0) or the highest tone (period 1). **The streams cannot say which the chip does**; a recording of Dragon's Lair (or Memory Manor, or the Final Test Cartridge's noise step) on a console would. MAME is the source of these streams, but what a game writes does not depend on the PSG model, and the board's streams equal MAME's where compared (item 1). ## M5: controllers (2026-11-12) — verified, except the Super Controller Tester `tests/test_controllers.py` (20 tests, both interpreters) and two scripts: - **The BIOS's own decode**: DECODER (`$1F79`) returns 0-9, `$A`, `$B` for the twelve keys and `$F` for none, with the "arm" (right) button in H, for port 1 and port 2; the joystick segment returns the complemented direction bits and fire. The Super Action Controller's purple and blue read as codes 8 and 4. - **The spinner through OS-7**: an IM 1 handler calling UPDATE_SPINNER (`$1F88`): 200 cycles/s for a quarter second counts SPIN_SW0_CT (`$73EB`) to at least +45 or -45 by direction, port 2's counter unmoved; the Roller Controller at x = +100, y = -100 counts both ports (20-30 and 226-236); the pulse sets /INT for 39 clocks, bit 4 low and bit 7 high for 1,790 clocks (U15, C12), bit 5 = pin 7. - **Final Test Cartridge controller screen** (`scripts/final_test.py --press-from 1400`): pressing, on each controller in turn, the four directions, the four diagonals, both fire buttons and the twelve keys, 10 frames each: by frame 2,400 every function marker of CONTROL 1 and CONTROL 2 has blanked (only the two titles remain on screen). - **Turbo and Slither** (`scripts/spinner_games.py`, 1,500 frames, spinner from frame 1,100 at -60, 0, +60 cycles/s): Turbo takes 192 interrupt responses turning either way and 0 still, and its last frames differ by 308 (left/still), 26,786 (right/still) and 26,690 (left/right) pixels (the car on opposite sides of the road); Slither takes 369 and 372 responses and differs by 1,055, 974 and 655 pixels. - **Not met: the Super Controller Tester.** Its screen at frame 900 equals MAME's (0 pixels differ) and looks like garbage text in both; without a description of its procedure no input script was written. Needs: its expected screens (Coleco's manual does not cover it) or a run on a console. ## M6: cartridge boards (2026-11-12) — verified on synthetic images only `tests/test_cartridges.py` (13 tests, both interpreters), from MAME's, openMSX's and ColecoDS's rules (tier 5; no image in the library uses these boards, open decision 9): MegaCart at 64K, 128K, 256K, 512K and 1M (last bank fixed at `$8000`, bank 0 at reset, `$FFC0-$FFFF` selecting address AND (banks - 1), strobes repeating, the write switch on and off), a 128K MegaCart booting through the BIOS from its last bank's header and switching bank 2 in; X-in-1 (last slice at reset, switch after the byte); Activision (fixed bank 0, banks 1-3 at `$FF90/$FFA0/$FFB0`, open area above `$FF80`) with a 24C02 and a 24C256 written and read back over the two-wire bus by accesses (page write, random read, sequential read, no acknowledge for another device code, page wrap); board choice by size and header position. **Superseded 2026-11-26** by the clean-room rewrite (docs/provenance.md, "Mapper rewrite"): the boards above are rewritten from documents only, X-in-1 is removed, and `tests/test_cartridges.py` is new (23 tests). The 13 tests above, run as a black box on the new code: 8 pass, 5 fail, each failure a documented difference (docs/provenance.md). ## M7: library sweep, PAL, long replays (2026-11-12) — met with named causes, PyPy **Sweep** (`scripts/make_sweep_list.py`, `scripts/smoke_pictures.py tests/smoke/sweep.tsv --mame`, `scripts/sweep_summary.py`): all 200 No-Intro cartridges, no inputs, pictures at MAME frames 300, 900 and 1,500 against MAME 0.285 and Gearcoleco; 1,330 s of board time on PyPy. | | Count | | --- | ---: | | pictures compared | 600 | | equal to MAME by colour index | 584 | | equal to Gearcoleco | 533 | | titles with all three equal to MAME | 192 of 200 | | titles where MAME and Gearcoleco disagree somewhere | 30 (by the 40-character title key: 195 keys) | | Gearcoleco refuses the image (Monitor Test, no header) | 1 | The 16 pictures (8 titles) that differ from MAME, each triaged with a 1,501-frame port-access replay (`scripts/mame_io.py` + `scripts/replay_io.py`): | Title | Pixels differing from MAME at 300 / 900 / 1500 | Cause | | --- | --- | --- | | Aquattack | 0 / 0 / 72 | status read `$80` against `$9F` at access 17,164 (core issue 0003) | | Artillery Duel | 11 / 19,515 / 19,765 | status `$00` against `$1F`, access 16,426 (0003) | | Beamrider | 4,856 / 5,818 / 5,824 | status `$1F` against `$54` (5S), access 26,981 (0003) | | Power Lords (Proto 2) | 15 / 0 / 0 | status `$00` against `$1F`, access 4 (0003) | | Slurpy | 0 / 772 / 933 | status `$80` against `$9F`, access 17,950 (0003) | | Squish'em Featuring Sam | 16 / 0 / 0 | **port accesses identical for all 1,501 frames (342,797)**: a rendering difference with the same VRAM writes: the core draws from bytes fetched at their slots, MAME draws each line at its start (tms9918-python's claims list this; its DokiDoki case) | | Video Hustler (Proto 1) | 0 / 42 / 344 | status `$44` against `$1F`, access 17,172 (0003) | | Zenji | 339 / 254 / 430 | status `$00` against `$1F`, access 16,410 (0003) | Every other difference is with Gearcoleco only, where MAME and Gearcoleco also disagree. The 8 failing titles are kept as the next smoke list: `tests/smoke/m7-failures.tsv`. **PAL row** (`tests/smoke/pal.tsv --pal --mame`, against MAME's `colecop`; Gearcoleco not set up for PAL): MAME's 2 s PAL BIOS trace (`scripts/mame_trace.py colecop`, MAME resets at raster 268, the PAL vertical-blank start, which is the same active-relative phase as NTSC) replays in lockstep: **951,253 instructions, 17,821 port writes, 1 read, 0 differences, on PyPy and CPython**. The 8 Europe-only images: 23 of 24 pictures equal to MAME; Meteoric Shower at frame 900 differs by 3 pixels: status `$44` against `$1F` at access 21,828 (0003). **Long replays** (`scripts/sound_streams.py --frames 3700`: MAME port-access logs of 62 emulated seconds with inputs, replayed with MAME's switches). This is a port-level lockstep (every access's kind, port, value and instruction-start clock), not the instruction-level trace of M1, which at 27 MB of log per emulated second was not run for this length: | Title | CPU steps | Port accesses identical | Differences | | --- | ---: | ---: | ---: | | Mr. Do! | 22,682,445 | 361,677 | 0 | | Cosmic Avenger | 20,131,870 | 441,896 | 0 | | Zaxxon | 23,261,219 | 641,351 | 0 | | Gorf | 22,319,362 | 235,382 | 0 | | Pepper II | 26,165,711 | 301,874 | 0 | | Mouse Trap | 21,526,271 | 356,353 | 0 | **CPython**: the full sweep was not repeated on CPython (about 4 hours at 0.3-0.5 x real time on the shared machine). That the interpreters agree is shown on the M3 smoke list (48 picture rows identical) and the M4 streams (identical); for M7 it is inferred.