jevsnes.git / apps / replay-probe / README.md
1# Chapter 14: replay-probe, proving the same thing happens twice
2
3Chapter 6's whole design rests on one claim: replay the recorded pad and
4the bot's recorded RAM writes from the same snapshot, and you get the same
5game, byte for byte, every time. If that is even slightly false (a stray
6timer, an uninitialised byte, a sound chip that drifts) then seeking shows
7the wrong frame, a rebuilt bot thinks it is somewhere it is not, and nothing
8complains. So before any of the seeking, rebuilding or disk-capping code was
9written, this probe had to pass.
10
11It starts the real bot from your `home` state, lets it play a warm-up so the
12recording is real gameplay, then records a window of frames: the pad, the
13bot's RAM writes, and a hash of work RAM plus the picture for every frame.
14Then it replays that log from the starting snapshot **twice**, with no bot,
15and compares every frame's hash against the recording's and against the
16other pass.
17
18> **Aside: it also measured the design into existence.** The keyframe tiers
19> and the 1 GiB cap in chapter 6 are not guesses. This probe reports log
20> bytes per hour, keyframe sizes per tier (as the recorder stores them),
21> headless replay throughput in frames a second, and the worst-case seek
22> time at each tier through the real keyframe load. It is also where the
23> discovery that varint snapshots defeat fixed-offset deltas came from: 83
24> consecutive snapshots in 70 different lengths, which is why
25> `Console::snapshot_fixed` exists.
26
27On 2026-09-22 two independent 10,000-frame replay passes were byte-identical
28to the bot-driven recording and to each other.
29
30> **Try it.** With a `home` state in `roms/<rom>.states/` (chapter 11's
31> `--make-home`, pointed at that directory):
32>
33>     nix develop -c buck2 run //apps/replay-probe:replay-probe -- \
34>       "roms/Legend of Zelda, The - A Link to the Past (USA).sfc"
35>
36> The defaults are a 3,000-frame warm-up and a 10,000-frame window.
37
38## For the people who maintain it
39
40`replay-probe <rom.sfc> [--warmup N] [--frames N]`. `--frames` must be at
41least three times `COARSE_FRAMES`, so every keyframe tier's worst case
42exists. The states directory is always the one beside the ROM; the probe
43writes into `run/replay-probe/`, which it empties first.
44
45### In this folder
46
47| Path | What |
48| --- | --- |
49| [src/main.rs](src/main.rs) | The probe: warm-up with the real bot, the recorded window, the two replay passes, and the measurements. |
50| [BUCK](BUCK) | The `rust_binary`, over `console`, `replay` and `zbanks`. |
51
52← Previous: [Chapter 13, jevprobe/](../jevprobe/) · Up: [apps](../) · Next: [Chapter 15, hotdemo/](../hotdemo/) →