# Worklog Newest first. One entry per working session; the measured result, not the intent. ## 2026-10-14 (colour floor) — Lloyd palette fitter, tolerance re-sweep, verified ROM **Current best ROM: `out/rickroll.bin`** (= `out/rickroll_lloyd.bin`, 16,352,978 bytes). Lloyd fitter + tolerances 100/300/250 + ROI 0.45/0.70/1.12 + saturation 1.3 at 2,340 B/frame. Full song: error **231.3 vs 287.0** for the ROI build (same metric, -19.4 %), base 134.8 vs 178.1, 27 frames retried, controller at 0.61x at the end (byte-bound), video 12,460,952 bytes (page-24 limit 12,582,912). Verified on megadrive-rust-fast `megadrive2`: 5,274/5,274 frames in order, exactly 2 hw frames each, 0 unknown; DAC stream 0 faults in 3,736,060 samples (`tools/ym_log.py` + `tools/oracle_audio.py`); BlastEm libretro core (`tools/blastem_compare.py`): 52/52 sampled frames pixel-identical, BlastEm 2 frames behind throughout. User judged the 300-frame sheets: Lloyd + 300/250 (`out/palette_sheet2.png` column 4) looks best. - `9828b7b` `rrmd/palette.py`: generalised Lloyd on the DAC lattice under the encoder's metric (exact E-step over line/shade/pen, exact per-channel M-step with normal and shadow cells sharing the CRAM entry, unused pens reseeded). `tools/palette_study.py` over the 109 shots: colour floor -24 % song-weighted on held-out frames, every shot improved. 300 frames at 2,340 B/f: 269.8 -> 210.5. - `848aa83` tolerance ratios re-swept under the new colours (`encode-clip --first` for a second window): reuse 2.5-3x / rom 2-3x of keep is a plateau 4-6 % below 160/400; 100/300/250 chosen. Mechanism (the user saw it as face detail): at 160/400 the rate controller runs at 11-12x, keep tolerance ~1,200/px, faces go stale; at 300/250 it runs at ~2.3x, keep ~230/px. - `7283e22` per-band palettes measured with the monotone fitter: 2/4/7 bands = -2.8/-5.1/-6.1 % of the floor, i.e. <= -3.7 % of total. Not built. - `c051d0a` fitted backdrop colour (pen 0 as a 61st shared colour): -0.4 %, half the shots regress. Off. - `0cfcfe3` `tools/blastem_compare.py`. - Face detail vs the old fitter, measured: the Lloyd faces have more distinct colours, equal luma spread, higher local contrast and lower Y/Cb/Cr error; the old fitter's faces carried more chroma spread than the source (error that reads as detail). What was lost was temporal, through the keep tolerance, and the ratios recover it. - ROI face weight 0.3 (vs 0.45) at 300/250: face -4 %, background +4.3 %. User kept 0.45. - md-run's frame-1 PNG is a 65-byte degenerate file (display off); delete it before `verify-clip --recheck`, and pass `--hw-frames 10564` so the last frame is inside the window. **Next levers:** keep tolerance vs bytes is the face-freshness knob (cheap A/B); the S/H per-pixel mask (PLAN 9) is the remaining large one; per-band palettes small. ## 2026-10-14 (later) — ADPCM assessed and parked; retry ceiling; colour floor next **ADPCM payoff, measured.** 300 frames, ROI config, 2,340 vs 2,750 B/frame (what the 1.86 MB freed by 4-bit IMA buys): error 269.8 -> 259.9, **-3.7 %**, with the colour floor (base error 190.7 here, 166 over the song) untouched. The IMA round trip on the soundtrack is 23.8 dB SNR, 1.3 % of samples off by >4 LSB, max 50. Full-song points 2,000/2,330/ 2,340/2,370 B/f -> 269.7/254.7/254.4/253.9 fit E = 164 + 210,600/B: the asymptote is the colour floor. Bytes are no longer the lever. ADPCM stays in `stash@{0}`. **Why the stashed push path fails** (not `v_played`): (1) `adpcm_push` holds BUSREQ with interrupts enabled; VBlank B and the H-int do their own request/release, so a handler mid-hold releases the bus and the rest of the hold's writes to Z80 RAM are dropped (the oracle ignores them, as CMD documents; `z80_serve_page` masks interrupts for this reason). (2) A chunk is 12 back-to-back 16-byte holds, ~1,100 Z80 cycles, against ~120 cycles of slack per 4-sample group in the play-only loop: every chunk loses a timer lap. A workable design pushes 2 bytes per scanline from an every-line H-int with interrupts masked - a redesign, for 3.7 %. **Encoder bug found by the 2,750 run:** `RETRY_CEILING` was 8 and tested before the doubling, so the cut at frame 187 (needs ~10x base, 38.5k of 40k cycles) fit only when the climb started above 5x; from 4.45x the encode raised. Ceiling now 64 (`b45ea08`), tested on the value about to be tried. Existing ROMs are unaffected. ## 2026-10-14 — ROI, saturation, ADPCM attempt, fast full-song verification **Current best ROM: `out/rickroll_roi.bin`** (16,351,562 bytes). Face-region tolerance weighting + saturation 1.3 + 2,340 B/frame, header correct (region E, checksum, extent). Verified on `megadrive2` over the full run via megadrive-rust-fast: 5,274/5,274 video frames, 0 unknown, in order, exactly 2 hardware frames each; audio 0 faults in 3,736,060 DAC samples, byte-exact, all seven page crossings. User watched it: faces better, backgrounds fine, saturation right. Committed (branch `audio-page-crossing`): - `cc89b5f` header: region was JUE (stock BlastEm → NTSC on a PAL-timed ROM), now E; real ROM extent; computed checksum; `finalize_header` guards the 16 MB mapper limit. Fast verification: md-run `--png-dir`/`--ym-log` (Rust changes held uncommitted per the user), `tools/ym_log.py`, `tools/oracle_audio.py`, `tools/wav_audio.py`. Full song byte-exact in ~34 s vs ~70 min on megadrive-python. - `a1c7fc7` `tools/saturation.py`: strips for the dull-source judgement. Sat 1.4 costs 18–25 % error on 4 of 5 frames; 1.3 chosen. - `3c1adb5` ROI weighting (`rrmd/roi.py`, per-cell tolerance 0.45 face / 0.70 edge / 1.12 background from `tools/face_track.py`) + `--saturation`; `tools/roi_score.py`. 300-frame A/B: face −6.4 %, background +3.7 %, whole frame +1.7 %. Encoder lever measured and shipped earlier in the day (other session, `ab7a1d4`): the retry ladder, not the rate floor, capped quality; bisection to the tightest fitting tolerance gives the full song at ~2,340 B/frame, error ~254 vs Phase 5's 269.7, 0 frames over the VBlank budget. `--rate-floor` exposes the floor; memory fix keeps the full-song encode flat at ~0.3 GB. **Measured, not built:** - Per-band palettes (Phase 3): ~5.5 % at 7 bands on a 12-frame sample, but the k-means fit regresses on ~25 % of frames (a band finding a worse local optimum than the whole-frame fit). Needs a *monotone* fitter (keep better of band-local vs global) before the player's H-int CRAM reload is worth building. A deliberate project. - Face detection: `tools/face_track.py` gives 84.5 % coverage, 0.46 % three-cell jumps (was 55.7 % / 5.3 %). 960 frames held/interpolated. User checked sheets: boxes good, misses are people facing away (correct). **ADPCM — attempted, not working, stashed (`git stash@{0}`).** 4-bit IMA frees 1.86 MB (→ ~2,750 B/frame, +18 % video — the user chose to spend it on video). Decode is *proven correct*: the 68000 decoder matches `tools/adpcm.py`'s Python reference byte-for-byte where it runs, verified against the DAC stream. The real-time push integration (68000 decodes into the Z80's 4 KB ring under BUSREQ, since the Z80's bank window cannot reach 68000 work RAM — a read returns $FF) has open interacting bugs: audio races the whole stream while video freezes at frame 6, pointing at `v_played` corruption early that makes the looping `adpcm_fill` decode the whole stream at once. First fix (fill looped to catch up; guard rewritten as a modular available-count) moved the first divergence from 0.3 s to a `v_played`/pacing failure but did not resolve it. Resume by instrumenting `v_played` over time (md-trace, or a 68000 debug counter). `tools/adpcm.py` is committed; the driver/layout changes are in the stash. Decided 2026-10-14 (later session): `rickroll_roi.bin` is the demo ROM, copied to `out/rickroll.bin` and `main` fast-forwarded to it. Rust `md-run` `--png-dir`/`--ym-log`/ `--png-range` + the `board.rs` YM log stay uncommitted in `megadrive-rust-fast` by instruction. The early-Model-1 freeze is NOT open: it was the Z80 driver's Timer A sync race, fixed in `ef702e6` and verified on `megadrive`, `megadrive2` and `megadrive-tmss` (PLAN phase 5). The paragraph that stood here was written in a parallel session before that fix landed.