Skip to main content

VsDualSystem

Struct VsDualSystem 

Source
pub struct VsDualSystem { /* private fields */ }
Expand description

Two complete NES systems + the cabinet’s cross-wiring. See the module docs for the architecture and protocol.

Implementations§

Source§

impl VsDualSystem

Source

pub fn from_rom(bytes: &[u8]) -> Result<Self, RomError>

Construct the dual system from one ROM image. A proper DualSystem dump carries BOTH CPUs’ programs (64 KiB PRG: main half then sub half — MAME’s prg + sub regions; Mesen2’s prgOuter split); the sub console’s mapper banks the second half. A 32 KiB (main-half-only) dump constructs and runs, but its boot handshake cannot complete — the sub-CPU program is simply absent.

The caller has already determined the cart is a DualSystem board (the SHA-keyed vs_db dual_system flag — see crate::Emu).

§Errors

Returns the underlying [RomError] if the bytes don’t parse.

Source

pub fn from_rom_with_sample_rate( bytes: &[u8], sample_rate: u32, ) -> Result<Self, RomError>

Construct the dual system with an explicit audio sample rate (the frontend’s output-device rate), applied to BOTH consoles.

The sample rate is baked into each Nes at construction (there is no runtime setter), so the desktop present path — which knows the cpal device rate — must build the pair through this constructor for the main console’s audio to resample correctly. Otherwise identical to Self::from_rom.

§Errors

Returns the underlying [RomError] if the bytes don’t parse.

Source

pub fn run_frame(&mut self)

Run one MAIN-console frame with the sub console soft-locksteped to within a 5-CPU-cycle gap (Mesen2 RunFrame + RunVsSubConsole).

Returns when the main console’s PPU completes a frame (or its CPU jams / the frame budget trips — mirroring Nes::run_frame’s guards).

Source

pub fn main_framebuffer(&self) -> &[u8]

The main console’s 256x240 RGBA8 framebuffer (the left screen).

Source

pub fn sub_framebuffer(&self) -> &[u8]

The sub console’s 256x240 RGBA8 framebuffer (the right screen).

Source

pub const fn set_buttons(&mut self, port: usize, buttons: Buttons)

Route controller input: ports 0/1 (P1/P2) → the main console’s ports 0/1; ports 2/3 (P3/P4) → the sub console’s ports 0/1.

Source

pub const fn insert_coin(&mut self, acceptor: u8)

Coin routing (Mesen2 VsControlManager): acceptors 0/1 latch on the MAIN console, 2/3 on the SUB console.

Source

pub const fn clear_coin(&mut self)

Clear both consoles’ latched coin signals.

Source

pub const fn set_vs_service(&mut self, panel: u8, pressed: bool)

The service button (main panel) / service-2 (sub panel).

Source

pub const fn main(&self) -> &Nes

Borrow the main console (read-only diagnostics).

Source

pub const fn sub(&self) -> &Nes

Borrow the sub console (read-only diagnostics).

Source

pub const fn main_mut(&mut self) -> &mut Nes

Mutably borrow the main console (debugger / diagnostics — e.g. the side-effect-free debug_peek_cpu, which needs &mut for the mapper’s banked lookups). Cross-wiring stays wrapper-owned; don’t drive $4016 writes through this handle.

Source

pub const fn sub_mut(&mut self) -> &mut Nes

Mutably borrow the sub console (debugger / diagnostics; see Self::main_mut).

Source

pub const fn split_mut(&mut self) -> (&mut Nes, &mut Nes)

Simultaneously borrow both consoles (diagnostics — e.g. a tracing harness replicating the lockstep loop with instrumented pumping).

Source

pub fn snapshot(&self) -> Vec<u8>

Serialize the dual system: a versioned container nesting the two standard Nes snapshots plus the wrapper’s latch state.

Layout: RVSD magic, u16 version, latch byte (bit0 = main_bit1, bit1 = sub_bit1; bit 2 reserved — it carried a WRAM-ownership flag in a pre-release layout and is ignored on load), then two u32-length-prefixed Nes snapshots (main, sub).

Source

pub fn restore(&mut self, data: &[u8]) -> Result<(), SnapshotError>

Restore a dual-system snapshot produced by Self::snapshot.

§Errors

Returns SnapshotError on a bad container or when either nested console snapshot fails to restore.

Auto Trait Implementations§

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.