Chip8

Struct Chip8 

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

Struct representing the Chip-8 virtual machine.

Implementations§

Source§

impl Chip8

Source

pub fn new(seed: u32) -> Self

Creates a new Chip-8 virtual machine. We use a seed to initialize the random number generator for portability across environments.

Source

pub fn frame_width(&self) -> u32

Returns the width of the frame in pixels.

Source

pub fn frame_height(&self) -> u32

Returns the height of the frame in pixels.

Source

pub fn speed(&self) -> u32

Returns the speed of the virtual machine in instructions per second.

Source

pub fn set_speed(&mut self, instructions_per_second: u32)

Sets the speed of the virtual machine in instructions per second.

Source

pub fn load(&mut self, bytes: &[u8])

Loads a program into the virtual machine.

Source

pub fn update(&mut self, time_delta: u32)

This will progress the virtual machine by the given time delta. It takes into account any accumulated time from previous calls that were less than a full cycle. The time delta given is in microseconds.

Source

pub fn step(&mut self)

Executes a single cycle of the virtual machine.

Source

pub fn frame(&self) -> FrameBuffer

Returns a copy of the frame buffer.

Source

pub fn registers(&self) -> Registers

Returns a copy of the registers.

Source

pub fn set_registers(&mut self, registers: Registers)

Sets the registers.

Source

pub fn handle_key_event(&mut self, key: Key, state: KeyState)

Passes a key event to the virtual machine.

Source

pub fn reset(&mut self)

Resets the virtual machine. The seed for the random number generator is not reset. All registers, the stack, timers, ram and the frame buffer are reset. The font is reloaded… However any program that was in memory is cleared, and will need to be loaded again.

Auto Trait Implementations§

§

impl Freeze for Chip8

§

impl RefUnwindSafe for Chip8

§

impl Send for Chip8

§

impl Sync for Chip8

§

impl Unpin for Chip8

§

impl UnwindSafe for Chip8

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.