Struct System

Source
pub struct System<T: Deref<Target = [u8]>, S: Screen, SO: SerialOutput, AS: AudioSpeaker> { /* private fields */ }

Implementations§

Source§

impl<T: Deref<Target = [u8]>, S: Screen, SO: SerialOutput, AS: AudioSpeaker> System<T, S, SO, AS>

Source

pub fn new(rom: Rom<T>, screen: S, serial_output: SO, speaker: AS) -> Self

Source

pub fn reset(&mut self)

Source

pub fn load_bin(&mut self, bytes: T) -> Result<(), Error>

Replace cartridge with a new buffer

Source

pub fn load_rom(&mut self, rom: Rom<T>)

Reload a new rom

Source

pub fn step(&mut self) -> u8

Single step to execute cpu, ppu, timer, serial & dma

Source

pub fn rom(&self) -> &Rom<T>

Retrieve the rom in readonly

Source

pub fn screen(&mut self) -> &mut S

Retrieve the screen

Source

pub fn serial(&mut self) -> &mut SO

Retrieve the serial output

Source

pub fn speaker(&mut self) -> &mut AS

Retrieve the speaker

Source

pub fn set_button(&mut self, button: Button, is_pressed: bool)

Forward a button press to the joypad controller

let mut emu = System::new(rom, NoScreen, NoSerial, NoSpeaker);
emu.set_button(Button::A, true);
emu.set_button(Button::Up, true);
Source

pub fn set_frame_rate(&mut self, fps: u32)

Sets the FPS (default = 60)

Source

pub fn update_frame(&mut self) -> u32

Execute enough steps to retrieve 1 frame

let mut emu = System::new(rom, NoScreen, NoSerial, NoSpeaker);
// loop {
    let t0 = Instant::now();
    emu.update_frame();
    let frame_time = t0.elapsed();
    let min_frame_time = emu.min_frame_time();
    if frame_time < min_frame_time {
        sleep(min_frame_time - frame_time);
    }
// }
Source

pub fn min_frame_time(&self) -> Duration

Returns the minimum amount of time to wait between each frame Mostly depend on the FPS

Auto Trait Implementations§

§

impl<T, S, SO, AS> Freeze for System<T, S, SO, AS>
where S: Freeze, SO: Freeze, AS: Freeze, T: Freeze,

§

impl<T, S, SO, AS> RefUnwindSafe for System<T, S, SO, AS>

§

impl<T, S, SO, AS> Send for System<T, S, SO, AS>
where S: Send, SO: Send, AS: Send, T: Send,

§

impl<T, S, SO, AS> Sync for System<T, S, SO, AS>
where S: Sync, SO: Sync, AS: Sync, T: Sync,

§

impl<T, S, SO, AS> Unpin for System<T, S, SO, AS>
where S: Unpin, SO: Unpin, AS: Unpin, T: Unpin,

§

impl<T, S, SO, AS> UnwindSafe for System<T, S, SO, AS>
where S: UnwindSafe, SO: UnwindSafe, AS: UnwindSafe, T: UnwindSafe,

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.