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` bytesDeterminism: 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.
- Section
Iter - Iterate sections starting at
bytes(which should begin immediately after the header).
Enums§
- Snapshot
Error - 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
.rnsfile. - 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
THMsection. - 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) intooutand then append the body bytes.