[][src]Struct nes_rust::Nes

pub struct Nes { /* fields omitted */ }

NES emulator.

This example is not tested
use std::fs::File;
use std::io::Read;
use std::time::Duration;
use nes_rust::Nes;
use nes_rust::rom::Rom;
use nes_rust::default_input::DefaultInput;
use nes_rust::default_audio::DefaultAudio;
use nes_rust::default_display::DefaultDisplay;

let input = Box::new(DefaultInput::new());
let display = Box::new(DefaultDisplay::new());
let audio = Box::new(DefaultAudio::new());
let mut nes = Nes::new(input, display, audio);

// Load and set Rom from rom image binary
let filename = &args[1];
let mut file = File::open(filename)?;
let mut contents = vec![];
file.read_to_end(&mut contents)?;
let rom = Rom::new(contents);
nes.set_rom(rom);

// Go!
nes.bootup();
let mut rgba_pixels = [256 * 240 * 4];
loop {
  nes.step_frame();
  nes.copy_pixels(rgba_pixels);
  // Render rgba_pixels
  // @TODO: Audio buffer sample code is T.B.D.
  // Adjust sleep time for your platform
  std::thread::sleep(Duration::from_millis(1));
}

Implementations

impl Nes[src]

pub fn new(
    input: Box<dyn Input>,
    display: Box<dyn Display>,
    audio: Box<dyn Audio>
) -> Self
[src]

Creates a new Nes. You need to pass input::Input, display::Display, and audio::Audio traits for your platform specific Input/Output.

Arguments

  • input For pad input
  • display For screen output
  • audio For audio output

pub fn set_rom(&mut self, rom: Rom)[src]

Sets up NES rom

Arguments

  • rom

pub fn bootup(&mut self)[src]

Boots up

pub fn reset(&mut self)[src]

Resets

pub fn step(&mut self)[src]

Executes a CPU cycle

pub fn step_frame(&mut self)[src]

Executes a PPU (screen refresh) frame

pub fn copy_pixels(&self, pixels: &mut [u8])[src]

Copies RGB pixels of screen to passed pixels. The length and result should be specific to display passed via the constructor.

Arguments

  • pixels

pub fn copy_sample_buffer(&mut self, buffer: &mut [f32])[src]

Copies audio buffer to passed buffer. The length and result should be specific to audio passed via the constructor.

Arguments

  • buffer

pub fn press_button(&mut self, button: Button)[src]

Presses a pad button

Arguments

  • button

pub fn release_button(&mut self, button: Button)[src]

Releases a pad button

Arguments

  • buffer

Auto Trait Implementations

impl !RefUnwindSafe for Nes

impl !Send for Nes

impl !Sync for Nes

impl Unpin for Nes

impl !UnwindSafe for Nes

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.