[−][src]Struct nes_rust::Nes
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]
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
input
For pad inputdisplay
For screen outputaudio
For audio output
pub fn set_rom(&mut self, rom: Rom)
[src]
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]
pub fn release_button(&mut self, button: Button)
[src]
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,