# Steps 2-3: the fix, and the proof Branch `savestate-pointers`, commit ca869b9 on upstream 594ca2a (local only, not pushed). ## The fix (8 lines added, 1 removed, 3 files) - `fc1004.c`: the six pointer assignments move out of `FC1004_Init` into `FC1004_InitPointers`; `FC1004_Init` calls it, then `ARB_Init` as before. Start-up behaviour is unchanged. - `fc1004.h`: declares `FC1004_InitPointers`. - `savestate.c`: `load_state` calls `FC1004_InitPointers(&ym)` straight after `load_blob(&ym, ...)`. - Calling `FC1004_Init` again instead would also run `ARB_Init`, which re-initialises the arbiter's delay chains that were just loaded. - Line endings kept: `fc1004.c`/`fc1004.h` are CRLF, `savestate.c` LF (checked with `file`). - Audit: those six are the only pointer members anywhere in the restored state (`md`, `mcycles`, `ram`, `zram`, VRAM banks and `vram_flat`, `m68k`, `z80`, `ym`, `tmss_rom`, cartridge arrays). ## The proof Harness in `study/harness/` (ours; upstream files untouched): Nuked-MD's sources built as a shared library, `md.c` compiled with `-Dmain=nuked_main -DAudio_Update=probe_audio_update`. `probe_audio_update` runs once per main-loop pass before the real `Audio_Update`; at `mcycles == STOP` it zeroes the six pointers (they differ between processes by design), writes the whole state with Nuked-MD's own `save_state`, and exits. - Process A: fresh launch, Nuked-MD's `pending_save_state` set after ~10 s (what F5 does; saved at 1.58M-1.97M half-MCLK), keeps running, dumps at STOP. - Process B: fresh launch, `pending_load_state` set before the first pass (what F7 does), runs, dumps at STOP. - Pass = B's dump byte-identical to A's (9,566,180 bytes). ROM: Sonic The Hedgehog (USA, Europe). STOP = 20,000,000 half-MCLK (about 11 NTSC frames), `long-20M.log`: | build | ASLR | pointers off target after load | B | | --- | --- | --- | --- | | upstream 594ca2a | on, try 1 | 6/6 | segmentation fault | | upstream 594ca2a | on, try 2 | 6/6 | segmentation fault | | upstream 594ca2a | off (`setarch -R`) | 0/6 | identical | | fix ca869b9 | on, try 1 | 0/6 | identical | | fix ca869b9 | on, try 2 | 0/6 | identical | | fix ca869b9 | off | 0/6 | identical | ## A window that was too short (kept on record) At STOP = 4,000,000 (about 2 frames of early boot) upstream with ASLR on gave IDENTICAL dumps 3 times out of 3 with 6/6 pointers off target: in that window the chip never wrote through them. So a short window cannot tell the fix from upstream; only the 20M runs above count. Upstream's failure is undefined behaviour: whether it crashes depends on what the stale address holds, and in step 1 one fresh-launch run took ~3.8M half-MCLK after loading to crash. ## Not tested Windows; a real key press in the SDL window (the same `work_thread` / `save_state` / `load_state` code runs, driven through the flags F5/F7 set); ROMs other than Sonic; saves taken late in a game.