Expand description
This crate provides the internal implementations for a chip 8 interpreter/emulator.
It currently provides two external traits that need to be implemented by the user of the crate (a third trait might be added if sound is ever supported), the Draw and ReadInputState traits.
The main idea that I was hoping to achieve here was to not have any external dependencies so I can load the interpreter on to almost any device I want in future without needing to rewrite the entire application.
Once the abovementioned traits are implemented, the interpreter will call these functions when appropriate.
For example implementations see the examples directory.
§Usage:
// These would be your own implementation
struct Drawer;
struct InputReader;
impl chip_eight::Draw for Drawer {
fn draw_buffer(&mut self, screen_buf: &[u8], screen_width: usize, screen_height: usize) { todo!() }
fn clear_screen(&mut self) { todo!() }
}
impl chip_eight::ReadInputState for InputReader {
fn read_keys_state(&self) -> Result<[u8; 16], String> { todo!() }
fn reset_keys_state(&mut self) { todo!() }
}
let (drawer, input_reader) = (Drawer, InputReader);
let program = vec![]; // Read it from somewhere
let mut emulator = chip_eight::Emulator::init(program, drawer, input_reader)
.expect("The chip 8 program is probably too large");
emulator
.set_max_draw_delay(std::time::Duration::from_millis(6))
.set_quirks_mode(chip_eight::QuirksMode::Chip8);
// Most simply you can then run the emulator as follows:
// EITHER: emulator.run_blocking();
// OR:
for emulator_state in emulator {
// Here emulator_state gives you access to the previous instruction as well as
// This is the expensive way of using the emulator, but is nice for debuggers
//(Just breaking here for the doctest)
break;
}Structs§
- Emulator
- This is the main emulator interface, used to configure and run the interpreter.
- Emulator
State - Data that is returned after each iteration of the interpreter as long as it is running as an iterator.
- Quirks
Fields - A customisable set of behaviours.
Enums§
- Application
Error - Currently the only ApplicationError variant is the program being too large to fit in the interpreter’s memory.
- Quirks
Mode - The preferred predefined set of behaviours.
- Super
Chip Behaviour - Modern or Legacy SuperChip behaviour, I can’t get it to work entirely correctly.
Traits§
- Draw
- Implement this trait on a type and use it to draw to or clear the screen.
- Read
Input State - Implement this trait on a type and use it to read input state.