Skip to main content

System

Struct System 

Source
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: Bus

The Bus — owns everything mutable (PPU/APU/cart/WRAM/controllers/DMA + the master clock).

§cpu: Cpu

The 65C816 main CPU. It borrows &mut bus for each Cpu::step.

Implementations§

Source§

impl System

Source

pub fn new(seed: u64) -> Self

Power on with a determinism seed.

Source

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.

Source

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.

Source

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).

Source

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).

Source

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).

Source

pub fn step_instruction(&mut self)

Step a single CPU instruction (drives the whole machine in lockstep via the Bus).

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for System

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for System

§

impl !RefUnwindSafe for System

§

impl Send for System

§

impl !Sync for System

§

impl Unpin for System

§

impl UnsafeUnpin for System

§

impl !UnwindSafe for System

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.