pub struct Nes { /* private fields */ }Expand description
NES emulator.
ⓘ
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§
Source§impl Nes
impl Nes
Sourcepub fn new(
input: Box<dyn Input>,
display: Box<dyn Display>,
audio: Box<dyn Audio>,
) -> Self
pub fn new( input: Box<dyn Input>, display: Box<dyn Display>, audio: Box<dyn Audio>, ) -> Self
Creates a new Nes.
You need to pass input::Input,
display::Display, and
audio::Audio traits for your platform
specific Input/Output.
§Arguments
inputFor pad inputdisplayFor screen outputaudioFor audio output
Sourcepub fn step_frame(&mut self)
pub fn step_frame(&mut self)
Executes a PPU (screen refresh) frame
Sourcepub fn copy_pixels(&self, pixels: &mut [u8])
pub fn copy_pixels(&self, pixels: &mut [u8])
Copies RGB pixels of screen to passed pixels.
The length and result should be specific to display passed via the constructor.
§Arguments
pixels
Sourcepub fn copy_sample_buffer(&mut self, buffer: &mut [f32])
pub fn copy_sample_buffer(&mut self, buffer: &mut [f32])
Copies audio buffer to passed buffer.
The length and result should be specific to audio passed via the constructor.
§Arguments
buffer
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more