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
impl Processor
pub fn new() -> Processor
sourcepub fn load_program(&mut self, program: &[u8])
pub fn load_program(&mut self, program: &[u8])
Load a program into memory
sourcepub fn load_program_u16(&mut self, program: &[u16])
pub fn load_program_u16(&mut self, program: &[u16])
Load a program as u16s instead of u8s. Mostly just a convenience function.
sourcepub fn step(&mut self)
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
sourcepub fn on_tick(&mut self)
pub fn on_tick(&mut self)
Function that decrements both timer registers. Should be called at a rate of 60Hz.
sourcepub fn update_inputs(&mut self, inputs: [bool; 16])
pub fn update_inputs(&mut self, inputs: [bool; 16])
Update the current input states to the inputs given.
sourcepub fn execute(&mut self, inst: u16)
pub fn execute(&mut self, inst: u16)
Executes a single given instruction. Does not increment PC or affect DT or ST.
sourcepub fn dump_state(&self)
pub fn dump_state(&self)
Print the state of the machine (all registers, stack, PC, etc) in the console.
sourcepub fn get_register_value(&self, register: u8) -> u8
pub fn get_register_value(&self, register: u8) -> u8
Get the value of an R register
sourcepub fn get_program_counter(&self) -> usize
pub fn get_program_counter(&self) -> usize
Get the value of the program counter
sourcepub fn get_mem_at(&self, addr: usize) -> u8
pub fn get_mem_at(&self, addr: usize) -> u8
Get a single byte of memory at the address given
sourcepub fn get_pixel_at(&self, x: u8, y: u8) -> bool
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.
sourcepub fn get_input_state(&self, i: usize) -> bool
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
.
sourcepub fn on_key_release(&mut self, kp: u8)
pub fn on_key_release(&mut self, kp: u8)
Method that should be called by an interface whenever a key (0-F) is released.