3 Commits
Author SHA1 Message Date
Thomas MartinandClaude Opus 5.5 77096ee2bc Memory cards survive a save state; Archive::end checks before closing
A state restored the cards' contents but not their host folder, so a game's saves after
--load-state stayed in memory and were lost. Cards kept in a folder are now taken back from
the folder when a state loads (a console's memory card is not part of a save state); cards in
memory stay the state's.

Archive::end closed a section before checking its size: a reader trying an older layout (the
libraries' sif section) that failed there rewound into a nameless section and the load failed
further on. The check now comes first. Tests for both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-24 21:17:24 +01:00
Thomas MartinandClaude Opus 5.5 b408e4a80b Save states: read the libraries section written before gsVideo
13cddc4 (#132) added Libraries::gsVideo to the "libraries" section, ahead
of its "waits" sub-section, so every state saved before it failed to load
("a container count is out of range") and the game started from the boot.

Archive::nextIs(name): whether the next thing read is that section. The
libraries reader takes gsVideo only when "waits" is not next; an older
state leaves it unknown (zero: its fourth byte is always 3 once
ResetGraph set it), and the GS library's SetDefDispEnv and Z buffer
address then read ResetGraph's parameters from scratchpad 0x100, as the
library did when that state was written. What is written does not change.

bozo-state-tests (nextIs) and bozo-libs-tests pass. TTA (engine at
b6a1980 plus this): all 33 regression captures from its saved states are
identical to the baselines; without it none of them loaded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-24 03:02:25 +01:00
Thomas MartinandClaude Opus 5.5 b73692ed37 Save states: the whole runtime saved and loaded at the dispatcher's safe point
A state is taken at the top of Dispatcher::run's loop, where no guest code is on
the host stack: memory, the dispatcher, the kernel (threads, frames, queues,
deadlines), every library's state, the native IOP host (memory, tasks, kernel
objects, RPC servers, mixer, libsd) and sections ports add (state::Sections).

Parked library lambdas become data: Resume records and native deadline kinds,
rebuilt from tables on load; ports can add their own kinds. FreeHost serves
requestSave / requestLoad from any thread, rolls back a failed load, and takes
FreeOptions (gameTag, loadState[Frame], saveState[Frame]). Windows get ten slots:
F5 save, F7 load, F6 / Shift+F6 select, and a Save states tab in F2.

989SND's engine and a playing movie are not covered: a save waits, saying why.
docs/save-states.md tells a port how to use and check it; tests/runtime/state_tests.cpp
covers the archive, files and a dispatcher round trip.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-18 18:22:15 +01:00