Struct ControlDeck

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

Represents an NES Control Deck. Encapsulates the entire emulation state.

Implementations§

Source§

impl ControlDeck

Source

pub fn new() -> Self

Create a NES ControlDeck with the default configuration.

Source

pub fn with_config(cfg: Config) -> Self

Create a NES ControlDeck with a configuration.

Source

pub fn sram_dir(&self, name: &str) -> PathBuf

Returns the path to the SRAM save file for a given ROM name which is used to store battery-backed Cart RAM. Returns None when the current platform doesn’t have a data directory and no custom data_dir was configured.

Source

pub fn load_rom<S: ToString, F: Read>( &mut self, name: S, rom: &mut F, ) -> Result<LoadedRom>

Loads a ROM cartridge into memory

§Errors

If there is any issue loading the ROM, then an error is returned.

Source

pub fn load_rom_path(&mut self, path: impl AsRef<Path>) -> Result<LoadedRom>

Loads a ROM cartridge into memory from a path.

§Errors

If there is any issue loading the ROM, then an error is returned.

Source

pub fn unload_rom(&mut self) -> Result<()>

Unloads the currently loaded ROM and saves SRAM to disk if the Cart is battery-backed.

§Errors

If the loaded Cart is battery-backed and saving fails, then an error is returned.

Source

pub fn load_cpu(&mut self, cpu: Cpu)

Load a previously saved CPU state.

Source

pub const fn set_mapper_revision(&mut self, rev: MapperRevision)

Set the MapperRevision to emulate for the any ROM loaded that uses this mapper.

Source

pub const fn set_mapper_revisions(&mut self, revs: MapperRevisionsConfig)

Set the set of MapperRevisionsConfig to emulate for the any ROM loaded that uses this mapper.

Source

pub fn set_concurrent_dpad(&mut self, enabled: bool)

Set whether concurrent D-Pad input is enabled which wasn’t possible on the original NES.

Source

pub const fn set_cycle_accurate(&mut self, enabled: bool)

Set whether emulation should be cycle accurate or not. Disabling this can increase performance.

Source

pub const fn set_ram_state(&mut self, ram_state: RamState)

Set emulation RAM initialization state.

Source

pub const fn set_headless_mode(&mut self, mode: HeadlessMode)

Set the headless mode which can increase performance when the frame and audio outputs are not needed.

Source

pub const fn set_emulate_ppu_warmup(&mut self, enabled: bool)

Set whether to emulate PPU warmup where writes to certain registers are ignored. Can result in some games not working correctly.

See: https://www.nesdev.org/wiki/PPU_power_up_state

Source

pub fn add_debugger(&mut self, debugger: Debugger)

Adds a debugger callback to be executed any time the debugger conditions match.

Source

pub fn remove_debugger(&mut self, debugger: Debugger)

Removes a debugger callback.

Source

pub const fn loaded_rom(&self) -> Option<&LoadedRom>

Returns the name of the currently loaded ROM Cart. Returns None if no ROM is loaded.

Source

pub fn cart_region(&self) -> Option<NesRegion>

Returns the auto-detected NesRegion for the loaded ROM. Returns None if no ROM is loaded.

Source

pub fn cart_battery_backed(&self) -> Option<bool>

Returns whether the loaded ROM is battery-backed. Returns None if no ROM is loaded.

Source

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

Returns the NES Work RAM.

Source

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

Returns the battery-backed Save RAM.

Source

pub fn save_sram(&self, path: impl AsRef<Path>) -> Result<()>

Save battery-backed Save RAM to a file (if cartridge supports it)

§Errors

If the file path is invalid or fails to save, then an error is returned.

Source

pub fn load_sram(&mut self, path: impl AsRef<Path>) -> Result<()>

Load battery-backed Save RAM from a file (if cartridge supports it)

§Errors

If the file path is invalid or fails to load, then an error is returned.

Source

pub fn save_state(&mut self, path: impl AsRef<Path>) -> Result<()>

Save the current state of the console into a save file.

§Errors

If there is an issue saving the state, then an error is returned.

Source

pub fn load_state(&mut self, path: impl AsRef<Path>) -> Result<()>

Load the console with data saved from a save state, if it exists.

§Errors

If there is an issue loading the save state, then an error is returned.

Source

pub fn frame_buffer_raw(&mut self) -> &[u16]

Load the raw underlying frame buffer from the PPU for further processing.

Source

pub fn frame_buffer(&mut self) -> &[u8]

Load a frame worth of pixels.

Source

pub fn frame_buffer_into(&self, buffer: &mut [u8])

Load a frame worth of pixels into the given buffer.

Source

pub const fn frame_number(&self) -> u32

Get the current frame number.

Source

pub fn audio_samples(&self) -> &[f32]

Get audio samples.

Source

pub fn clear_audio_samples(&mut self)

Clear audio samples.

Source

pub const fn clock_rate(&self) -> f32

CPU clock rate based on currently configured NES region.

Source

pub fn clock_instr(&mut self) -> Result<u64>

Steps the control deck one CPU clock.

§Errors

If CPU encounters an invalid opcode, then an error is returned.

Source

pub fn clock_seconds(&mut self, seconds: f32) -> Result<u64>

Steps the control deck the number of seconds.

§Errors

If CPU encounters an invalid opcode, then an error is returned.

Source

pub fn clock_frame(&mut self) -> Result<u64>

Steps the control deck an entire frame.

§Errors

If CPU encounters an invalid opcode, then an error is returned.

Source

pub fn clock_frame_output<T>( &mut self, handle_output: impl FnOnce(u64, &[u8], &[f32]) -> T, ) -> Result<T>

Steps the control deck an entire frame, calling handle_output with the cycles, frame_buffer and audio_samples for that frame.

§Errors

If CPU encounters an invalid opcode, then an error is returned.

Source

pub fn clock_frame_into( &mut self, frame_buffer: &mut [u8], audio_samples: &mut [f32], ) -> Result<u64>

Steps the control deck an entire frame, copying the frame_buffer and audio_samples for that frame into the provided buffers.

§Errors

If CPU encounteres an invalid opcode, an error is returned.

Source

pub fn clock_frame_ahead<T>( &mut self, run_ahead: usize, handle_output: impl FnOnce(u64, &[u8], &[f32]) -> T, ) -> Result<T>

Steps the control deck an entire frame with run-ahead frames to reduce input lag.

§Errors

If CPU encounters an invalid opcode, then an error is returned.

Source

pub fn clock_frame_ahead_into( &mut self, run_ahead: usize, frame_buffer: &mut [u8], audio_samples: &mut [f32], ) -> Result<u64>

Steps the control deck an entire frame with run-ahead frames to reduce input lag.

§Errors

If CPU encounters an invalid opcode, then an error is returned.

Source

pub fn clock_scanline(&mut self) -> Result<u64>

Steps the control deck a single scanline.

§Errors

If CPU encounters an invalid opcode, then an error is returned.

Source

pub const fn cpu_corrupted(&self) -> bool

Returns whether the CPU is corrupted or not which means it encounted an invalid/unhandled opcode and can’t proceed executing the current ROM.

Source

pub const fn cpu(&self) -> &Cpu

Returns the current Cpu state.

Source

pub const fn cpu_mut(&mut self) -> &mut Cpu

Returns a mutable reference to the current Cpu state.

Source

pub const fn ppu(&self) -> &Ppu

Returns the current Ppu state.

Source

pub const fn ppu_mut(&mut self) -> &mut Ppu

Returns a mutable reference to the current Ppu state.

Source

pub const fn bus(&self) -> &Bus

Retu[ns the current Bus state.

Source

pub const fn bus_mut(&mut self) -> &mut Bus

Returns a mutable reference to the current Bus state.

Source

pub const fn apu(&self) -> &Apu

Returns the current Apu state.

Source

pub const fn apu_mut(&mut self) -> &Apu

Returns a mutable reference to the current Apu state.

Source

pub const fn mapper(&self) -> &Mapper

Returns the current Mapper state.

Source

pub const fn mapper_mut(&mut self) -> &mut Mapper

Returns a mutable reference to the current Mapper state.

Source

pub const fn four_player(&self) -> FourPlayer

Returns the current four player mode.

Source

pub fn set_four_player(&mut self, four_player: FourPlayer)

Enable/Disable Four Score for 4-player controllers.

Source

pub const fn joypad(&mut self, slot: Player) -> &Joypad

Returns the current Joypad state for a given controller slot.

Source

pub const fn joypad_mut(&mut self, slot: Player) -> &mut Joypad

Returns a mutable reference to the current Joypad state for a given controller slot.

Source

pub const fn zapper_connected(&self) -> bool

Returns whether the Zapper gun is connected.

Source

pub const fn connect_zapper(&mut self, enabled: bool)

Enable Zapper gun.

Source

pub const fn zapper_pos(&self) -> (u32, u32)

Returns the current Zapper aim position.

Source

pub fn trigger_zapper(&mut self)

Trigger Zapper gun.

Source

pub fn aim_zapper(&mut self, x: u32, y: u32)

Aim Zapper gun.

Source

pub const fn set_filter(&mut self, filter: VideoFilter)

Set the video filter for frame buffer output when calling ControlDeck::frame_buffer.

Source

pub fn set_sample_rate(&mut self, sample_rate: f32)

Set the Apu sample rate.

Source

pub fn set_frame_speed(&mut self, speed: f32)

Set the emulation speed.

Source

pub fn add_genie_code(&mut self, genie_code: String) -> Result<()>

Add a NES Game Genie code.

§Errors

If the genie code is invalid, an error is returned.

Source

pub fn remove_genie_code(&mut self, genie_code: &str)

Remove a NES Game Genie code.

Source

pub fn clear_genie_codes(&mut self)

Remove all NES Game Genie codes.

Source

pub const fn channel_enabled(&self, channel: Channel) -> bool

Returns whether a given Apu Channel is enabled.

Source

pub const fn set_apu_channel_enabled(&mut self, channel: Channel, enabled: bool)

Enable or disable a given Apu Channel.

Source

pub const fn toggle_apu_channel(&mut self, channel: Channel)

Toggle a given Apu Channel.

Source

pub const fn is_running(&self) -> bool

Returns whether the control deck is currently running.

Trait Implementations§

Source§

impl Clock for ControlDeck

Source§

fn clock(&mut self) -> u64

Steps the control deck a single clock cycle.

Source§

impl Clone for ControlDeck

Source§

fn clone(&self) -> ControlDeck

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ControlDeck

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for ControlDeck

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Regional for ControlDeck

Source§

fn region(&self) -> NesRegion

Get the NES format for the emulation.

Source§

fn set_region(&mut self, region: NesRegion)

Set the NES format for the emulation.

Source§

impl Reset for ControlDeck

Source§

fn reset(&mut self, kind: ResetKind)

Resets the console.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more