Nes

Struct Nes 

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

Representation of the NES system

Implementations§

Source§

impl Nes

Source

pub fn new() -> Self

Instantiate a NES emulator instance

let nes = Nes::new();
Source

pub fn entry(self, entry_addr: u16) -> Self

Directly set the CPU entry point

let nes = Nes::default().entry(0xC000);
Source

pub fn with_cart(self, cart: Cartridge) -> Self

Builder function to allow inserting the cartridge

Source

pub fn debug_mode(self, debug: bool) -> Self

Builder function to set debug mode

let nes = Nes::default().debug_mode(true);
Source

pub fn emulate_frame(&mut self) -> ([u8; 184320], Vec<Sample>)

Run the emulator for a single frame

let mut nes = Nes::from(cart);
let (videobuffer, audiobuffer) = nes.emulate_frame();
  • videobuffer - A RGB8 frame buffer
  • audiobuffer - Raw APU output (This must be down sampled to host playback rate)
Source

pub fn run_audio(&mut self, buffer_size: usize) -> Vec<f32>

Run the NES emulator until it fills an audio buffer to the specified size

let samplebuffer = nes.run_audio(4096);
Source

pub fn input(&mut self, btn: Button, pressed: bool)

Apply a button input into the emulator

nes.input(Button::A, true);
Source

pub fn controller_input( &mut self, controller: Controller, btn: Button, pressed: bool, )

Apply a button input to the emulator from the specified controller

// Send an `A` button press to input 1
nes.controller_input(Controller::Input1, Button::A, true);
// Send an `A` button press to input 2
nes.controller_input(Controller::Input2, Button::A, true);
Source

pub fn run_until(&mut self, addr: u16)

Run until the CPU’s PC is at address addr

Source

pub fn is_holding(&self) -> bool

Check if the CPU is in an infinite loop state

Source

pub fn insert(&mut self, cart: Cartridge)

Load a cartridge

Source

pub fn eject(self) -> Vec<u8>

Eject the cartridge, returning the save state

let nes = Nes::default();
// This consumes the nes instance
let battery_ram = nes.eject();
Source

pub fn get_program_counter(&self) -> u16

Get the CPU’s program counter

Source

pub fn read_cpu_ram(&self, addr: u16) -> u8

Read the byte, at the specified address, from CPU’s internal RAM

Source

pub fn read_ppu_memory(&self, addr: u16) -> u8

Read directly from VRAM

Source

pub fn read_tile(&self, nametable: u16, x: usize, y: usize) -> u8

Read a tile from the current nametable

Trait Implementations§

Source§

impl Default for Nes

Source§

fn default() -> Nes

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

impl From<Cartridge> for Nes

Source§

fn from(cart: Cartridge) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Nes

§

impl !RefUnwindSafe for Nes

§

impl !Send for Nes

§

impl !Sync for Nes

§

impl Unpin for Nes

§

impl !UnwindSafe for Nes

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