Save states

A state is the whole console at one moment, in the Switch's state file (src/nx/runtime/state_file.h): the header and the 320 by 180 thumbnail the launcher and the game's menu read, then three sections, each with a hash of the names and types of what it holds (src/agb/runtime/state.c):

SectionWhat it holds
BOARDthe AgbBoard: the devices' registers, the display's frame, the timers, DMA, the sound's channels and FIFOs, the cartridge's clock and save chip's protocol
CPUthe AgbCpu: the registers and their banks, the bus and the prefetch unit, the BIOS's time owed
MEMORYEWRAM, IWRAM, the palette, VRAM and OAM

The runner keeps what is its own: the cartridge image (the header names the ROM by its FNV-1a, as the recompiled module's map does), the flat window, the gba_color setting. The cartridge's save memory is the game's save file, <name>.sav, as a Switch game's save files are: a state does not hold it, and a load leaves it as it is. The recompiled blocks are no part of a state: a block built from RAM a load changed is built again at its next dispatch.

snx_agb_state_save and snx_agb_state_load (src/agb/runtime/state.h) take the board and the CPU between two frames. A load reads and checks every section before it changes anything, and refuses another ROM's state (both hashes named), another SNX_AGB_STATE_VERSION (both versions named), a section of another layout (both hashes named), and a file that is damaged or cut short. The test's ROM, which keeps every device busy, makes a state of 306 KiB, 225 KiB of it the thumbnail, saved and loaded in a few milliseconds (agb_state).


Made from docs/platforms/agb/README.md at 69237645142c. GPL-3.0-or-later.