5 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 de65040fec Save states: read the pad, mpeg, sif and 989SND sections written before their newer fields
States saved before these sections grew fail to load ("section pad ends before its fields"; then mpeg, sif) and the
game starts from the boot. JC2's states from before 2026-11-24 hit all four:
- pad: libpad2's sockets (pad2Sockets, pad2Next) came after multitapAttached; an older section ends there, and no
  socket is open.
- mpeg: inputEnded (MpegOptions::sdkNodata) came before the sound; an older section has exactly the sound left, and
  the input goes on.
- sif: the IOP side's software registers came before the heap; the older layout is tried first and kept only when it
  reads the section exactly (Archive::end checks it), with the registers cleared; otherwise the reader rewinds.
- snd: a state from before the 989SND driver was saved has "timers" next; the driver stays as it is.

Archive::sectionLeft(): the bytes the open section has left when reading. What is written does not change.

bozo-state-tests (sectionLeft) passes, with the whole engine suite on jc2/native-irx-host (symbol_maps aside: the
build's temp directory has "game" in its path). JC2: s24300_arena.state, saved on the engine before these fields,
loads again and the run goes on in the scene it was saved in.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-24 12:09:55 +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 e6e0a926e8 Save states: read the mixer and libsd sections written before the SPU2 interrupt
3b79730 added the cores' IRQ address and enable to the "mixer" section and
the SPU2 interrupt handler to "libsd", in the middle of each. Every state
saved before it then failed to load ("a mixer input outside the IOP's
memory"): TTA's test states and players' F5 slots alike.

Archive::mark / rewind: a reader goes back to a place and reads again.
Mixer and Libsd read the current layout, and when the section's size check
fails, the older one from the same place, the new fields at their defaults
(no IRQ, no handler). What is written does not change, so states saved
since 3b79730 load as before. state_tests: an older section read again
after the newer reader fails.

TTA (engine at e15775a): its 33 regression captures from saved states are
identical again; without this every scene but battle1 and the boot ones
started from the boot.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-24 02:03:35 +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