Expand description
Implements the VM that runs the CHIP-8 interpreter leaving you free to focus on the frontend with the graphics library and renderer of your choice.
§Example
This is a basic skeleton of how to start implementing a frontend. It’s recommended to use the anyhow crate as well.
ⓘ
use schip8::Chip8;
use anyhow::{Context, Result};
fn main() -> Result<()> {
let mut chip = Chip8::default();
// The load_file function needs to be implemented
let file = load_file("roms/TETRIS")?;
chip.load_rom(&file).context("Loading ROM file")?;
// Use the frontend to make this loop run at 60 Hz
loop {
// Process input
// ...
chip.tick().context("Interpreter tick")?;
// Render screen - check the examples for scaling demo
for y in 0..chip.screen.height {
for x in 0..chip.screen.width {
if chip.screen.get_pixel(x, y) {
// Draw
}
}
}
// Reset with chip.reset() if reset key is pressed
if chip.should_play_sound() {
// Play a tone
}
}
}
An example frontend using Macroquad has been provided here.
Structs§
- Chip8
- Represents the CHIP-8 VM that acts as the interpreter.
- Config
- Settings to modify the behaviour of the interpreter.
- Cpu
- The CPU of the machine. In charge of interpreting all the commands from the loaded ROM.
- Screen
- Represents the pixels of the 64x32 CHIP-8 display.
Enums§
- Chip
Error - The error types used by the interpreter