Struct rust_chip8_opengl::processor::Processor

source ·
pub struct Processor { /* private fields */ }
Expand description

The actual CHIP-8 processor. Decodes and runs any opcodes, stores memory, stores screen. Needs to be paired with an interface to allow the user to actually interact with the program.

Implementations§

source§

impl Processor

source

pub fn new() -> Processor

source

pub fn load_program(&mut self, program: &[u8])

Load a program into memory

source

pub fn load_program_u16(&mut self, program: &[u16])

Load a program as u16s instead of u8s. Mostly just a convenience function.

source

pub fn step(&mut self)

Perform the next step in whatever program has been loaded into memory. Equivalent to just calling execute and incrementing PC by 2

source

pub fn on_tick(&mut self)

Function that decrements both timer registers. Should be called at a rate of 60Hz.

source

pub fn update_inputs(&mut self, inputs: [bool; 16])

Update the current input states to the inputs given.

source

pub fn execute(&mut self, inst: u16)

Executes a single given instruction. Does not increment PC or affect DT or ST.

source

pub fn dump_state(&self)

Print the state of the machine (all registers, stack, PC, etc) in the console.

source

pub fn get_register_value(&self, register: u8) -> u8

Get the value of an R register

source

pub fn get_program_counter(&self) -> usize

Get the value of the program counter

source

pub fn get_i(&self) -> u16

Get the value of the I register

source

pub fn get_mem_at(&self, addr: usize) -> u8

Get a single byte of memory at the address given

source

pub fn get_pixel_at(&self, x: u8, y: u8) -> bool

Get a pixel at the given x, y position on the screen. Accounts for screen wrapping.

source

pub fn get_input_state(&self, i: usize) -> bool

Return whether the processor has the i key currently being pressed. This should be set by calls to update_inputs.

source

pub fn get_dt(&self) -> u8

Get the D timer register.

source

pub fn get_st(&self) -> u8

Get the S (sound) time register.

source

pub fn on_key_release(&mut self, kp: u8)

Method that should be called by an interface whenever a key (0-F) is released.

Auto Trait Implementations§

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<S> FromSample<S> for S

source§

fn from_sample_(s: S) -> S

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<F, T> IntoSample<T> for F
where T: FromSample<F>,

source§

fn into_sample(self) -> T

source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

source§

fn to_sample_(self) -> U

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,