pub struct Chip8 {
pub keypad: [u8; 16],
pub video: [u32; 2048],
/* private fields */
}Expand description
General chip 8 struct
Fields§
§keypad: [u8; 16]§video: [u32; 2048]Implementations§
Source§impl Chip8
impl Chip8
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new chip8 instance with an empty rom, ready for use
§Example:
let mut chip8: Chip8 = Chip8::new();
chip.load_rom(path);
let rom: PathBuf = '...';
let speed: u64 = 30;
loop {
chip8.Cycle();
chip8.pretty_print_video(rom);
thread::sleep(time::Duration::from_millis(speed);
}§Values
registers: all zeroesmemory/rom: all zeroesindex_register: 0program_counter: 0x200stack: all zeroesstack_poionter: 0delay_timer: 0sound_timer: 0keypad: all zeroesvideo: all zeroesop_code: 0fontset_size: 80
pub fn last_opcode(&self) -> u16
Sourcepub fn play(&mut self, speed: u64)
pub fn play(&mut self, speed: u64)
Runs the CHIP8 Machine forever with the currently loaded ROM.
The clock speed is determined by the passed in speed parameter.
loop {
self.Cycle();
self.pretty_print_video();
thread::sleep(cycle_wait_time);
}Sourcepub fn add_table(&mut self)
pub fn add_table(&mut self)
Adds the correct function pointer tables to the newly created Chip8 object
pub fn reset_hard(&mut self)
pub fn reset_and_load_bytes(&mut self, rom: &[u8]) -> Result<(), Chip8Error>
Sourcepub fn load_rom(&mut self, path: PathBuf) -> Result<(), Error>
pub fn load_rom(&mut self, path: PathBuf) -> Result<(), Error>
Loads a given rom into memory, starting from memory address 0x200
pub fn load_rom_bytes(&mut self, rom: &[u8])
Sourcepub fn dump_rom(&self, start_address: usize, byte_number: usize) -> Vec<u8> ⓘ
pub fn dump_rom(&self, start_address: usize, byte_number: usize) -> Vec<u8> ⓘ
Returns byte_number amount of bytes after the pointer in rom
pub fn export_video(&mut self) -> &[u32; 2048]
pub fn pretty_print_video(&mut self)
pub fn key_down(&mut self, k: u8)
pub fn key_up(&mut self, k: u8)
pub fn is_key_down(&self, k: u8) -> bool
Sourcepub fn take_recent_press(&mut self) -> Option<u8>
pub fn take_recent_press(&mut self) -> Option<u8>
Use this in FX0A (wait for key): returns one press if available.
pub fn Cycle(&mut self)
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more