Chip8

Struct Chip8 

Source
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

Source

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 zeroes
  • memory/rom: all zeroes
  • index_register: 0
  • program_counter: 0x200
  • stack: all zeroes
  • stack_poionter: 0
  • delay_timer: 0
  • sound_timer: 0
  • keypad: all zeroes
  • video: all zeroes
  • op_code: 0
  • fontset_size: 80
Source

pub fn last_opcode(&self) -> u16

Source

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);
}
Source

pub fn add_table(&mut self)

Adds the correct function pointer tables to the newly created Chip8 object

Source

pub fn debug(&mut self)

Toggle debug mode for current chip8 instance

Source

pub fn reset_hard(&mut self)

Source

pub fn reset_and_load_bytes(&mut self, rom: &[u8]) -> Result<(), Chip8Error>

Source

pub fn load_rom(&mut self, path: PathBuf) -> Result<(), Error>

Loads a given rom into memory, starting from memory address 0x200

Source

pub fn load_rom_bytes(&mut self, rom: &[u8])

Source

pub fn dump_rom(&self, start_address: usize, byte_number: usize) -> Vec<u8>

Returns byte_number amount of bytes after the pointer in rom

Source

pub fn export_video(&mut self) -> &[u32; 2048]

Source

pub fn pretty_print_video(&mut self)

Source

pub fn key_down(&mut self, k: u8)

Source

pub fn key_up(&mut self, k: u8)

Source

pub fn is_key_down(&self, k: u8) -> bool

Source

pub fn take_recent_press(&mut self) -> Option<u8>

Use this in FX0A (wait for key): returns one press if available.

Source

pub fn OP_00E0(&mut self)

OPCODE 00E0 - Clear Screen

Source

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