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
impl VsDualSystem
Sourcepub fn from_rom(bytes: &[u8]) -> Result<Self, RomError>
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.
Sourcepub fn from_rom_with_sample_rate(
bytes: &[u8],
sample_rate: u32,
) -> Result<Self, RomError>
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.
Sourcepub fn run_frame(&mut self)
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).
Sourcepub fn main_framebuffer(&self) -> &[u8] ⓘ
pub fn main_framebuffer(&self) -> &[u8] ⓘ
The main console’s 256x240 RGBA8 framebuffer (the left screen).
Sourcepub fn sub_framebuffer(&self) -> &[u8] ⓘ
pub fn sub_framebuffer(&self) -> &[u8] ⓘ
The sub console’s 256x240 RGBA8 framebuffer (the right screen).
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.
Sourcepub const fn insert_coin(&mut self, acceptor: u8)
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.
Sourcepub const fn clear_coin(&mut self)
pub const fn clear_coin(&mut self)
Clear both consoles’ latched coin signals.
Sourcepub const fn set_vs_service(&mut self, panel: u8, pressed: bool)
pub const fn set_vs_service(&mut self, panel: u8, pressed: bool)
The service button (main panel) / service-2 (sub panel).
Sourcepub const fn main_mut(&mut self) -> &mut Nes
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.
Sourcepub const fn sub_mut(&mut self) -> &mut Nes
pub const fn sub_mut(&mut self) -> &mut Nes
Mutably borrow the sub console (debugger / diagnostics; see
Self::main_mut).
Sourcepub const fn split_mut(&mut self) -> (&mut Nes, &mut Nes)
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).
Sourcepub fn snapshot(&self) -> Vec<u8> ⓘ
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).
Sourcepub fn restore(&mut self, data: &[u8]) -> Result<(), SnapshotError>
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.