Module state

Module state 

Source
Expand description

Save states (state.py): the whole console between two instructions, as bytes, and back.

As in the reference, a state is everything that changes as the console runs: the CPU (huc6280-rust’s CpuState), the board’s clock and lines, the VDCs, the VCE, the PSG, the timer and the interrupt registers, work RAM, the card’s mapper and its RAM, the capture and the mixer, and whatever an add-on has plugged in. It is not the wiring: a state is loaded into a System built the same way (the same machine row, the same card, the same add-on), which keeps its configuration, its page table and its devices.

Equivalence is the test (tests/state.rs, pce-state-roundtrip): a run saved at some instruction boundary and loaded into another system continues exactly as the run that was never interrupted, bus cycle for bus cycle; and the loaded system, saved at once, gives the same bytes back.

Refused, with an error and the system untouched: bytes that are not a state of this format and version, another machine row, another card (its identity is the SHA-1 and length of the image: no ROM byte is in a state), a system built another way (a device in a socket the state has empty, or another device there, or other media in it). A state refused further in (a device that cannot read its part) may have written part of itself, and the system should be rebuilt.

Differences forced by Rust:

  • The format is this crate’s own: a magic and a version, then zlib of the bincode of a header and the body. The reference’s is tagged JSON of a walk of the object graph, which Rust cannot make; a state is not portable to the reference or back. What holds is the reference’s property.
  • Devices behind a socket trait save themselves (sockets::DeviceState): bytes out, bytes in, and an identity. The reference reaches them by the same walk.
  • The named switches: the reference saves instance attributes (the VDC’s vblank_dots, vertical_at_line_start, the DMA’s resume) and so does this; its class attributes (the PSG’s switches, the timer’s window) are not in a state there, and a loaded state keeps the system’s own here too, with the VCE’s host-side rgb_table.
  • A snapshot pair the reference does not have: save_snapshot / load_snapshot, the body alone with no header, no check and no compression, for run-ahead (a state taken and put back within one run of one system). Loading a snapshot into a system built another way is not detected.

Constants§

MAGIC
VERSION

Functions§

load_snapshot
Put system back where save_snapshot found it (the system the snapshot was taken from, or one built the same way: nothing is checked).
load_state
Put system in the state data was saved from (the same machine, card and add-on).
save_snapshot
The state of system for load_snapshot on the same system later: no header, no compression, nothing hashed.
save_state
The state of system as bytes (between two of its steps).