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’sresume) 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-sidergb_table. - Old states are refused, not converted. The reference’s JSON names each field, so it
loads a state of 0.1.0 with the CPU’s new
polled_irq_linesasNone(pcengine-python 0.2.0). bincode names nothing: a body of version 1 does not decode as version 2, and the version check refuses it first, with the system untouched (tests/state.rs). A converter would carry the old layouts of the CPU and the PSG for states nobody keeps (the crate has no users who save yet); a state is for the build that made it. - 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
- 2 since 0.2.0: the CPU’s state gained
polled_irq_lines(huc6280-rust 0.2.0), the PSG lostacc_stepsand gainedlevels_units. A state of version 1 is refused, not converted (see the module’s notes).
Functions§
- load_
snapshot - Put
systemback wheresave_snapshotfound it (the system the snapshot was taken from, or one built the same way: nothing is checked). - load_
state - Put
systemin the statedatawas saved from (the same machine, card and add-on). - save_
snapshot - The state of
systemforload_snapshoton the same system later: no header, no compression, nothing hashed. - save_
state - The state of
systemas bytes (between two of its steps).