Skip to main content

Module save_state

Module save_state 

Source
Expand description

Save-state container format for RustyNES v2.

Per CLAUDE.md “Open questions worth knowing”: tagged-section per chip with version byte; cross-version compatibility is best-effort, not guaranteed.

§On-wire layout

HEADER (16 bytes):
    magic       : "RUSTYNES"  (8 bytes)
    format ver  : u16 little-endian  (currently 2 -- see [`FORMAT_VERSION`])
    rom sha-256 : truncated to 6 bytes (sanity tag, not authoritative)

BODY (sections in any order, each):
    tag         : [u8; 4]  e.g. b"CPU ", b"PPU ", b"APU ", b"MAP "
    version     : u8       per-section schema version
    length      : u32 little-endian (body bytes after this length field)
    body        : `length` bytes

Determinism: every snapshot() for a given (seed, ROM, input sequence) produces bit-identical bytes. Loading is order-independent.

Modules§

tag
Section tags. The fixed-width 4-byte format keeps parsing trivial and avoids string allocation on the hot path.

Structs§

BinReader
Cursor-style binary reader, the inverse of BinWriter.
BinWriter
Cursor-style binary writer used by chip snapshot encoders.
Header
Header decoded from the start of the blob.
Section
Decoded view of one section’s metadata + body slice.
SectionIter
Iterate sections starting at bytes (which should begin immediately after the header).

Enums§

SnapshotError
Errors produced by save-state encode / decode.

Constants§

FORMAT_VERSION
Current container-format version.
HEADER_LEN
Header byte length.
MAGIC
Magic header bytes — first 8 bytes of every .rns file.
ROM_HASH_TAG_LEN
Length of the truncated ROM SHA-256 we embed in the header (sanity tag).
THUMBNAIL_HEIGHT
Thumbnail height in pixels (1/2 native NES height).
THUMBNAIL_LEN
Thumbnail byte length (THUMBNAIL_WIDTH * THUMBNAIL_HEIGHT * 4, RGBA8).
THUMBNAIL_VERSION
Body version byte for the THM section.
THUMBNAIL_WIDTH
Thumbnail width in pixels (1/2 native NES width).

Functions§

parse_header
Parse the 16-byte header.
tag_string
Render a 4-byte tag back into a String (lossy — non-ASCII becomes ?).
write_header
Build the 16-byte header into out.
write_section
Encode a section header (tag + version + length) into out and then append the body bytes.