pub struct System {
pub bus: Bus,
pub cpu: Cpu,
/* private fields */
}Expand description
Owns the run loop. Determinism contract: same seed + ROM + input => bit-identical AV.
Fields§
§bus: BusThe Bus — owns everything mutable (PPU/APU/cart/WRAM/controllers/DMA + the master clock).
cpu: CpuThe 65C816 main CPU. It borrows &mut bus for each Cpu::step.
Implementations§
Source§impl System
impl System
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset the CPU from the cart’s emulation reset vector ($00FFFC). Safe to call with no
cart (the CPU reads open bus and parks); the boot flag tracks readiness. Auto-detects
NTSC vs PAL from the installed cart’s header (Bus::sync_region_from_cart) before
resetting the CPU, so a PAL cart boots at the PAL line count/timing without the caller
(frontend or test) having to know or guess the region up front.
Sourcepub fn run_frame(&mut self)
pub fn run_frame(&mut self)
Run one full video frame: step the CPU until the PPU’s frame-count advances, firing the per-frame HDMA setup at the top of the frame and the per-line HDMA at each visible-line boundary.
Sourcepub fn sa1_cycles(&self) -> Option<u64>
pub fn sa1_cycles(&self) -> Option<u64>
Cumulative cycles the SA-1’s second CPU has executed since power-on, or None when no SA-1
cart is installed. A non-zero value is the SA-1 liveness signal: the second 65C816 actually
fetched + executed out of the cart ROM (many SA-1 titles run their main logic on the SA-1).
Sourcepub fn sa1_regs(&self) -> Option<Regs>
pub fn sa1_regs(&self) -> Option<Regs>
The SA-1 second CPU’s architectural register file, or None when no SA-1 cart is
installed. For the debugger overlay’s Cart panel (docs/frontend.md §Debugger overlay).
Sourcepub const fn seed(&self) -> u64
pub const fn seed(&self) -> u64
The determinism seed this System was constructed with (Self::new). A TAS movie’s
power-on start point records this so a replay can verify the caller reconstructed the
System with the exact same seed before calling crate::movie::Movie::seek_to_start —
a different seed gives different power-on phase alignment, breaking bit-identical replay
even against the same ROM and input log (docs/adr/0004).
Sourcepub fn step_instruction(&mut self)
pub fn step_instruction(&mut self)
Step a single CPU instruction (drives the whole machine in lockstep via the Bus).
Sourcepub fn tick_one_master(&mut self)
pub fn tick_one_master(&mut self)
Advance by one CPU instruction (kept for API compatibility with the old skeleton). The real timebase advances through the CPU’s bus accesses, not a bare master tick.
Sourcepub fn save_state(&self) -> Vec<u8> ⓘ
pub fn save_state(&self) -> Vec<u8> ⓘ
Serialize the entire emulated machine — the main CPU, the whole Bus (PPU, APU, DMA,
WRAM, plus the cart’s coprocessor state and battery SRAM if a cart is loaded), the
determinism seed, the boot/HDMA-line bookkeeping, and (if present) the SA-1 second CPU
plus its master-clock catch-up accounting — into a versioned binary blob
(docs/adr/0006-save-state-format.md). The blob leads with a 4-byte magic and a u16
format-version header that Self::load_state checks before trusting anything else. The
cart’s ROM is never embedded (docs/adr/0003’s “never embed a ROM/firmware byte” posture,
already applied to every coprocessor’s firmware) — restoring a cart-carrying save-state
requires the caller to have already loaded the SAME ROM onto the target System first.
Sourcepub fn load_state(&mut self, bytes: &[u8]) -> Result<(), SaveStateError>
pub fn load_state(&mut self, bytes: &[u8]) -> Result<(), SaveStateError>
The inverse of Self::save_state.
§Errors
SaveStateError::BadMagic if bytes doesn’t lead with the expected magic (not a
RustySNES save-state at all); SaveStateError::UnsupportedVersion if the format version
is newer than this build understands; SaveStateError on truncated/corrupt input or a
section with unconsumed trailing bytes; or SaveStateError::Invalid if the save-state’s
SA-1-second-CPU presence, or (via Bus::load_state) cart presence/SRAM size, doesn’t
match this System’s own installed state — restoring onto the wrong ROM/board
configuration is rejected rather than silently corrupting it.