# Status Every rung passes. The ladder was rerun on 2026-11-12 against the new reference pin, at `e31d681`; rung 4 on 2026-11-13; the Super Game Boy row (below) and every gate table again on 2026-11-13 at `518eeb0`, and again with the SGB border fade at `f7a9b78`. Reference: gameboy-python at tag `gameboy-rust-pin-2` (`47a97e6`) for the board; the clone is now checked out at master `ac01aff`, which is `gameboy-rust-pin-3` (`c5e9568`: pin-2 plus `sgb.py`, comments (`2b0b40f`) and a new PNG helper (`image.rgb24_png_bytes`)) plus the border fade, whose `src` change is `sgb.py` alone (`git diff c5e9568 ac01aff -- src`), so the board's reference traces cached at the pin stay valid (checked: every table identical again); the 17 SGB traces of pin-3 were set aside in `external/old/refcache-sgb-pin3` and regenerated. **Since the history reset of 2026-11-19** (see the README) the reference is gameboy-python tag `gameboy-rust-pin-4`, commit `030d3a7`, a single commit whose tree is exactly `ac01aff`'s; the hashes in this file are from before the reset and name the same trees. **Since 2026-11-26** the clone is at gameboy-python `3d1d93e` (pin-4 plus the author-respect change: dmg-sim's quickboot removed, comments re-cited; `git diff 030d3a7 3d1d93e -- src` touches no hardware behaviour), and every rung was rerun against it (below, "Carry-down rerun"). Cloned to `external/gameboy-python` (not committed); its interpreter is `external/venv` (PyPy 3.11 with sm83-python `1f312fa` and gb-apu-python `d4393c6`, gameboy-python editable from the clone; until 2026-11-22 `95f2b8b` and `f0a7f48`, the same trees before those repositories' history rewrites of 2026-11-21, which took them off every branch). The crate was built from [handoff-brief.md](handoff-brief.md) (historical). At `f7a9b78`: `cargo test --release` 25 pass (3 board, 22 SGB), `cargo fmt --check` and `cargo clippy --release --all-targets -- -D warnings -W clippy::needless_range_loop` (stable toolchain clippy) clean. ## Copyleft clean-up (2026-11-12) gameboy-python's licence audit found two pieces that had come from Gambatte's GPL-2 source and replaced them (its docs/validation.md "Copyleft clean-up (2026-11-12)", commit `47a97e6`). This board carried the same code and now transcribes the replacements: the CGB OAM-DMA conflict rules (`board.rs`: SameBoy's bus model plus the `oamdma_src*_busypush*/busypop*` verdict fits; the Gambatte-derived `DmaKind` table is gone) and `gameboy-suite`'s Gambatte reader (digit glyphs and CGB colours read from `tests/data/`, copies of the tables gameboy-python learned from the tests themselves; an RGB555 word not in the table matches no colour). The window-undo comment in `ppu.rs` now says the idea was first read in Gambatte's source and the dots are fitted. Gambatte's test ROMs and their hardware verdicts remain the judge; nothing under its `libgambatte/` or `testrunner.cpp` was read for this. Pin-2 also brought the CPU CGB C row (`cgb-c`), the CGB D/E line-153 shift, and the SCY/palette revision fields, transcribed from `git diff gameboy-rust-pin-1 gameboy-rust-pin-2 -- src`. ## Rungs | Rung | Result | Command | | --- | --- | --- | | 1 | blargg `cpu_instrs` 01-11 pass natively (and the combined ROM, 3,191 frames) | see below | | 2 | Lockstep gate built: 36 of 36 cases identical (23 test-ROM cases incl. real DMG and CGB boot, 13 commercial dumps on DMG and CGB, 1,200-1,800 slices each, with `scripts/inputs/poke.txt`), APU register values included | `python3 scripts/lockstep.py --reference-cache external/refcache` | | 3 | Mealybug DMG 24 of 24 pixel-exact; CGB-D 20 of 21 exact, the 21st (`m3_lcdc_obj_size_change_scx`, 15 pixels: the reference's documented photo match) differing by the same 15 pixels on the reference; CPU CGB C (`--revision cgb_c`, `cgb-c` row) 24 of 27 exact, the three the reference leaves open differing by its pixel counts (`m3_lcdc_obj_size_change_scx` 15, `m3_lcdc_tile_sel_change2` and `m3_lcdc_tile_sel_win_change2` 166 each); cgb-acid-hell, cgb-acid2, dmg-acid2, halt_bug, strikethrough exact. Gambatte from skip-boot: DMG-08 1,695 of 1,784 and CGB-04c on `cgb-c` (`--cgb --machine cgb-c`) 2,892 of 3,221, both the reference's `tests/gambatte_*_pass.txt` exactly. Lockstep: `cases-rung3.tsv` 229 of 229 identical (all Mealybug DMG and CGB-D from the real boot ROMs, acid pictures, every 20th/30th Gambatte listed ROM); `cases-oamdma-cgb.tsv` 418 of 418 (every Gambatte oamdma ROM with a CGB-04c verdict, on `cgb-c`: the rewritten DMA conflict rules) | `gameboy-suite pictures`, `gameboy-suite mealybug-dmg`, `gameboy-suite cgb-pictures`, `gameboy-suite cgb-pictures --revision cgb_c`, `gameboy-suite gambatte [--cgb --machine cgb-c] --skip-boot --write F` and diff with `external/gameboy-python/tests/gambatte_*_pass.txt`; `lockstep.py --cases scripts/cases-rung3.tsv`, `--cases scripts/cases-oamdma-cgb.tsv` | | 4 | 1,360 suite jobs (2026-11-26 at gameboy-python `3d1d93e`, 0 differ; until then 1,379, with the 19 `mooneye-dmg-quick/*` jobs, which went with dmg-sim; rerun at pin-2 on 2026-11-13: the same jobs, 0 differ), every result field identical on both boards (verdict, text, B-L registers, T-cycles, frames; shootout verdict and measured startup time): Mooneye acceptance/emulator-only/misc on DMG-B and CGB E (111 each: 94 and 87 pass), misc from the real CGB boot ROM, the boot_* ROMs from the real DMG/MGB/DMG-0 boot ROMs (and dmg-sim's quickboot until 2026-11-26); blargg 47 of 49 (cpu_instrs, instr_timing, mem_timing, mem_timing-2, oam_bug, interrupt_time, dmg_sound, cgb_sound); SameSuite + AGE on CGB 78 of 125 and DMG 11 of 125; GBMicrotest 481 of 513 (= the reference's list); GB Emulator Shootout 257 PASS (pin-1: 256; daid `ppu_scanline_bgp` on GBC now passes, as the reference's CGB line-153 change says it should) | `external/venv/bin/python scripts/suite_jobs.py --out external/rung4-pin2/suite-jobs.jsonl`; `target/release/gameboy-jobs external/rung4-pin2/suite-jobs.jsonl --out external/rung4-pin2/suite-rust.jsonl`; `external/venv/bin/python scripts/suite_ref.py external/rung4-pin2/suite-jobs.jsonl --out external/rung4-pin2/suite-ref.jsonl --jobs 9` (about 90 min); `python3 scripts/suite_compare.py external/rung4-pin2/suite-ref.jsonl external/rung4-pin2/suite-rust.jsonl` | | 5 | Every board class under the gate on a dump that uses it: `cases-rung5.tsv` 21 of 21 identical (ROM-only, MBC1, MBC1+RAM+battery, MBC1M multicart x2, MBC2, MBC3+RAM+battery, MBC3+timer x3 incl. CGB, MBC30, MBC5, MBC5+rumble, MMM01 x2; rtc3test basic/range/sub-second and mbc3-tester on DMG and CGB). The MBC3 clock runs on board time on both sides. (No No-Intro dump uses ROM+RAM, $08/$09.) Dumps found by `scripts/mapper_dumps.py` | `lockstep.py --cases scripts/cases-rung5.tsv` | | 6 | Every row of `machines.py` under the gate: `cases-rung6.tsv` 48 of 48 identical (DMG-0/A/B/C and MGB from their real boot ROMs, SGB/SGB2 from skip-boot, CGB; dmg-acid2, boot_regs, boot_hwio, stat_irq_blocking, oam_bug 5, Tetris; CPU CGB C: Tetris and stat_irq_blocking from the real boot ROM, Mealybug m3_scy/bgp/obp0_change, Gambatte ly0 lycint152 x3). Save states (`src/state.rs`, the reference has none): the round trip (save half way, load into a new console, go on) identical to the reference's uninterrupted trace on every case of `cases.tsv`, `cases-rung5.tsv` and `cases-rung6.tsv` (105 of 105; with the APU in the state since 2026-11-13, every table: 871 of 871, see "Save states"); `tests/board.rs` checks it without ROMs | `lockstep.py --cases scripts/cases-rung6.tsv`; add `--save-at-half` for the round trip | | 7 | gb-apu-rust adopted (by path, 0c2c240). APU register reads and writes are in every gate comparison (all case tables above, identical). `cases-rung7.tsv` with `--extra=--audio` (a CRC of each slice's 44.1 kHz samples, `apu.capture`): 119 of 119 identical (blargg dmg_sound and cgb_sound singles, SameSuite apu, every 12th Gambatte outaudio ROM from the real boot ROM, the 13 game cases). Gambatte audio (`gameboy-suite gambatte-audio`, real DMG boot ROM, `APU.audible()` in the last of 15 frames): 82 of 87 agree with the DMG-08, the same 82 as the reference at the pin (its committed `tests/gambatte_audio_pass.txt` has 76: stale by 6). blargg dmg_sound/cgb_sound verdicts are in rung 4's jobs, identical | `lockstep.py --cases scripts/cases-rung7.tsv --extra=--audio`; `gameboy-suite gambatte-audio --write F` and diff with the reference's `scripts/gambatte_audio.py --write` | | SGB | `src/sgb.rs`, the transcription of the reference's HLE Super Game Boy (`sgb.py` at `ac01aff`: pin-3 `c5e9568` plus the BIOS's border fade, which fits the real BIOS's measured palette writes, 0 exceptions in five games: gameboy-python docs/validation.md "Super Game Boy, the border fade"), under the gate: with `--sgb` both trace tools attach it, send the inputs to its pad and add `sgb=PIC/STATE` to each slice (CRC-32 of `render()`'s 256 x 224 words and of `save_state()`'s blob). `cases-sgb.tsv` 18 of 18 identical (22,800 slices): the eight games the reference validated against the real BIOS (Donkey Kong, Kirby's Dream Land 2, Pokemon Red, Pokemon Yellow, Link's Awakening DX, Wario Land II, Mario's Picross, Tetris DX), 1,500 slices each from the SGB boot ROM (every border is sent by about frame 780: Tetris DX's is the last), Donkey Kong on SGB2 from its boot ROM, and all eight from skip-boot (Pokemon Red 900 slices, Donkey Kong and Mario's Picross 1,200, the rest 1,500: every one loads its border), and Donkey Kong skip-boot for 300 slices, whose `--save-at-half` save (slice 150) falls at fade tick 25 of its first border, the new border still pending. Save/load round trip on the table 18 of 18; three of the saves fall inside a fade (that one, and Mario's Picross's second border: tick 65, fading in, from the boot ROM; tick 22, fading out, from skip-boot). The fades run about 150 slices from the PCT_TRN (e.g. Donkey Kong skip-boot slices 89-258). PNGs from `gameboy-sgb` and the reference's `scripts/sgb_picture.py`: pixel-identical on all five compared at pin-3 (Donkey Kong skip-boot 600 = the reference test's SHA-1 `0cf50643...`, rechecked with the fade; Pokemon Red 900, Kirby 2 1200, Tetris DX 1000, Link's Awakening DX 800 from the boot ROM). Seeded one-line faults in `sgb.rs`, over `cases-sgb.tsv`: 6 of 7 caught (first screen line 18 cases, VRAM transfer delay 18, border palette bits 18, PAL_SET shared colour 0 8, fade delay 4 -> 3 frames 18, fade-in `min(c, tick - 37)` -> `tick - 38` 18); MISSED: ATTR_BLK's inside-only edge palette (`inside_pal -> outside_pal`): none of the cases sends an inside-only block whose outside palette differs; `tests/sgb.rs` `attr_blk_inside_edge_outside_and_the_exception` fails on it | `lockstep.py --cases scripts/cases-sgb.tsv [--save-at-half]`; `gameboy-sgb ROM --boot mame --frames N --png F`; `seeded_faults.py --cases scripts/cases-sgb.tsv --only sgb:` | | faults | 17 of 18 seeded one-line faults caught over `cases.tsv`, `cases-rung3/5/6.tsv` and `cases-targeted.tsv` (168 cases: Mooneye mbc/timer/oam_dma/ppu, GBMicrotest vblank/lyc/win/dma, all identical on the true board): PPU (OAM scan height, first-object discount, mode-0 read lag, VBlank IF lateness, HBlank IRQ lead), pixels (DMG BGP glitch, CGB register delay, window row counter), DMA (start delay, length, bus conflict), timer (TAC=01 bit, reload-cycle write, DIV-write edge), cartridge (MBC1 bank 0, MBC3 RTC carry), serial clock bit. MISSED: MBC5 ROM bank bit 8 (no case reads banks 256+ differently: Mooneye `mbc5/rom_64Mb` passes with the bit stuck at 0, on both boards; a >4 MB MBC5 dump case would close it). Two first-draft mutants were equivalent and were replaced (LY=LYC compare at line 153 `dot < 8 -> 12`, masked by `lyc_match`; the timing PPU's `window_line`, written but never read here or in the reference) | `python3 scripts/seeded_faults.py --cases scripts/cases.tsv --cases scripts/cases-rung3.tsv --cases scripts/cases-rung5.tsv --cases scripts/cases-rung6.tsv --cases scripts/cases-targeted.tsv` (worktree at external/faults-tree) | Setup, once (the reference repositories beside this one). The test ROMs are the ones the reference's `scripts/fetch_references.py` puts in its `tests/test_roms/`; the case tables and `gameboy-suite` read them in place, by default from `external/gameboy-python/tests/test_roms` and No-Intro dumps from `$NO_INTRO_DIR`: set `GBTR`, `MTS` and `NOINTRO` to move them. ```sh git clone ../gameboy-python external/gameboy-python && git -C external/gameboy-python checkout 3d1d93e # pin-4 (030d3a7: the tree of ac01aff, pin-3 + the SGB border fade) + author respect (quickboot removed) pypy3 -m venv external/venv external/venv/bin/pip install \ "git+https://github.com/alewman/sm83-python@1f312fa3c9e60c2fc43d7044ddf2a95219d0d36b" \ "git+https://github.com/alewman/gb-apu-python@d4393c6af0d634e637ff63a421278fd0c6b6700f" external/venv/bin/pip install --no-deps -e external/gameboy-python # rung 1 B=${GBTR:-external/gameboy-python/tests/test_roms/gbtr}/blargg for f in $B/cpu_instrs/individual/*.gb; do target/release/gameboy $f --protocol blargg-serial --max-frames 2000; done ``` ## Carry-down rerun (2026-11-26) These are the rungs at `cd31eff` (the quick boot removed) against gameboy-python `3d1d93e`. The reference traces were regenerated into an empty `external/refcache`, and the old ones were set aside in `external/old/refcache-pin4-030d3a7`. The runs used CPUs 16-23 (`taskset -c 16-23`) with 4 jobs, at load averages of 12-25 on 32 cores. sm83-rust was at `70f7ed5` and gb-apu-rust at main `f662a29` (clones beside a worktree), because the gb-apu-rust checkout was on another session's branch. - Rung 1: `cpu_instrs` 11 of 11, and the combined ROM passes. - Lockstep, plain and `--save-at-half`, every table identical: cases 36, rung 3 229, rung 5 21, rung 6 48, oamdma 418, SGB 18, and rung 7 with `--audio` 119. - All 889 regenerated reference traces are byte-identical to the pin-4 cache. - Gambatte: DMG-08 1,695 of 1,784 and CGB-04c 2,892 of 3,221, both exactly the reference's pass lists. Gambatte audio: 82, identical to the reference's `gambatte_audio.py`. - Mealybug DMG 24 of 24. CGB-D 20 of 21. CGB C 25 of 28 (with cgb-acid-hell). The pictures are exact. - Rung 4: 1,360 jobs, 0 differ (outputs in `external/carry-2026-11-26/`). The reference's 1,360 results equal pin-2's on every job that remains. The seeded faults were not rerun: the change touches no line that a fault mutates. (`cf927a5`, a comment, came after the runs.) `cargo test --release` gives 25 pass. `cargo fmt --check` is clean, and so is stable clippy (1.99) with `-D warnings`. ## Super Game Boy `src/sgb.rs` transcribes `sgb.py` line by line (docs/sgb.md in the reference is the guide). The board owns the unit: `Hw::sgb: Option>`, `None` unless `GameBoy::attach_sgb` is called on an `sgb`/`sgb2` row; it is serde, so it is part of the board's save state (header `GBRUST04` since the border fade grew the unit; `GBRUST03` states are refused). The fade runs on the board's clock `t`, which reaches the unit as `Icd::t` (commands) and as an argument (`lcd_frame`, `run_fade`, `render`, `save_state`); `render` and `save_state` take the fade's due steps first, as the reference's do, so they take `&mut self`, and `GameBoy::sgb_render` / `sgb_save_state` pass the board's `t`. The reference's three callbacks are board calls: a P1 write is `Hw::joypad_write` (`Joypad::write_select`, then `SuperGameBoy::p1_write`, then `Joypad::fell`: the order of the reference's `Joypad.write` with `on_write`), and the PPU, with `taps` set, queues `Tap::Line(ly, shades)` / `Tap::Frame` where the reference calls `line_out` / `frame_start`; `Hw::sgb_taps` hands them over right after each PPU tick. With no SGB attached the PPU queues nothing and the P1 write is the old one: every DMG/CGB table is unchanged (cases 36, rung 3 229, rung 5 21, rung 6 48, oamdma 418, rung 7 `--audio` 119, each also with `--save-at-half`: 871 + 871 identical). The reference traces of `cases.tsv` were also regenerated from the `a8bdf5e` clone (`external/refcache-sgbhle`): byte-identical to the pin-2 cache. With the fade (`f7a9b78`), every table plain once more: cases 36, rung 3 229, rung 5 21, rung 6 48, oamdma 418, rung 7 `--audio` 119, all identical; the regenerated SGB reference traces differ from pin-3's only in their `sgb=` fields. The SGB boot ROM is bring-your-own: the case table uses `$SGBBOOT` / `$SGB2BOOT`, which `lockstep.py` finds as MAME's `sns_rom_sgb.zip` / `sns_rom_sgb2.zip` in `$MAME_ROMPATH`; the games come from `$NOINTRO` (`NO_INTRO_DIR`). ## Findings about the reference **`sgb.py` from skip-boot lost the game's first packet (fixed in the reference, c5e9568, and here).** The ICD2 starts with `p1 = gb.joypad.select`, which is $00 in the skip-boot state (the board's P1 power-on value); after the real SGB boot ROM it is $30 (its header packets end with both lines high). A game's first packet starts with a write of $00, which `p1_write` then ignores as "no change", so the start pulse is missed and the packet is lost. Pokemon Red's first packet is its SGB check (`MLT_REQ` two players, `89 01 ...`): from skip-boot the game decides it is not on an SGB and never sends a border. Repro on the reference: `scripts/sgb_picture.py "Pokemon - Red Version (USA, Europe) (SGB Enhanced).zip" --frames 900 --packets` prints one packet (`frame 43: 8900...`); with `--boot mame` it prints the header packets, `89 01` at frame 25 and the border transfers. From skip-boot Pokemon Yellow, Kirby's Dream Land 2, Wario Land II, Link's Awakening DX and Tetris DX show no border by frame 1,500 either (likely the same cause, not traced one by one); Donkey Kong and Mario's Picross are not affected. The reference's validation ran from the boot ROM, where this does not arise. A possible fix there: start the ICD2 at $30 when no boot ROM is mapped. Done that way in gameboy-python c5e9568 and transcribed here (`SuperGameBoy::new` takes `boot_mapped`); with it all eight games load their borders from skip-boot, and the five that did not before are now cases. No divergence where gameboy-python looks wrong; nothing for sm83-rust either. At pin-1 two of its committed pass lists were stale; at pin-2 `tests/gambatte_cgb04c_pass.txt` is current (2,892 on `cgb-c`), and `tests/gambatte_audio_pass.txt` (76) still trails what the board agrees on (82 of 87). The PPU's `window_line` is dead state (written, never read). Three comments that named Gambatte's source functions were reworded in gameboy-python `2b0b40f` (comments only, after pin-2) and here to match. ## Open - An MBC5 case with more than 4 MB of ROM, for the one missed fault. - An SGB case whose game sends an inside-only ATTR_BLK with a different outside palette, for the one missed SGB fault. - The SGB is not yet in a player: the speed fork and the browser player can take `sgb.rs` as is (with the fade, its picture calls are `&mut`: `GameBoy::sgb_render`). - Later, in other repositories: a speed fork (gameboy-rust-fast) with an SDL2 window. ## APU gb-apu-rust (4032227, its ladder passed; the `serde` feature on) is used by path: `src/apu.rs` re-exports `gb_apu::APU`, and APU register values are compared in every gate case (`--mask-apu` on both trace tools zeroes them, to compare against traces recorded before the APU was in the gate). Rung 7 above covers the audio itself. `gb_apu::APU` is not `Clone`, so `Hw` and `GameBoy` are not `Clone`. ## Save states `GameBoy::save_state()` / `load_state()` carry the CPU (`CpuState`) and all of `Hw`, the APU included (gb-apu-rust's `serde` feature, 2026-11-13), except the cartridge ROM/header, the boot ROM and the machine row, which come from the console the state is loaded into. The header is `GBRUST02` (`GBRUST01` states had no APU and are refused). The gate's round trip (`--save-at-half`: save before the middle slice, load into a new console, go on there) is identical to the reference's uninterrupted trace on every table: cases 36, rung 3 229, rung 5 21, rung 6 48, oamdma 418, rung 7 with `--audio` 119 (871 of 871, sample CRCs included). ## The gate `scripts/lockstep.py` runs `target/release/gameboy-trace` and `scripts/gameboy_trace.py` (on `external/venv`) per case of `scripts/cases.tsv`, one line per 70,224 T slice: CPU state, board time, timer, PPU/DMA position, serial length, CRC-32 of every bus M-cycle (`t<<26|kind<<24| address<<8|value`) and CRC-32 of the finished picture. On a difference rerun both tools with `--detail SLICE` and diff. `--reference-cache DIR` keeps the reference's traces (empty it when the pin moves; pin-1's are in `external/refcache-pin1`). MBC3 clocks run on board time on both sides.