Expand description
§Oxid-8 Core
oxid8_core is an interpreter core for the Chip-8 programming language,
developed by Joseph Weisbecker in the mid-1970s for making games on the
COSMAC VIP and Telmac 1800.
This is the core interpreter library for Oxid8. So that developers can
create their own renderers on top of this library crate.
§Getting Started
use oxid8_core::Oxid8;
use std::time::{Duration, Instant};
#[derive(Default)]
struct State {
should_exit: bool,
last_frame: Option<Instant>,
}
#[derive(Default)]
struct Emu {
state: State,
core: Oxid8,
}
fn main() -> std::io::Result<()> {
let mut emu = Emu::default();
emu.core.load_font();
emu.core.load_rom("rom_path")?;
while !emu.state.should_exit {
let time = Instant::now();
// TODO: Poll and Handle Events.
if let Some(last_frame) = emu.state.last_frame {
if time.duration_since(last_frame) >= Duration::from_millis(16) {
if let Err(err) = emu.core.next_frame() {
panic!("{err}");
}
// TODO: Draw current frame.
emu.state.last_frame = Some(time);
}
if emu.core.sound() {
// TODO: Beep!
}
} else {
emu.state.last_frame = Some(Instant::now());
}
}
Ok(())
}§WASM Compatibility
# Cargo.toml
[dependencies]
web-time = "1.1.0"
[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.3", features = ["wasm_js"] }# config.toml
[target.'cfg(target_arch = "wasm32")']
rustflags = ["--cfg", 'getrandom_backend="wasm_js"']§Frame Time
You should generate frames at 60Hz or roughly 16ms if not relying on
vsync. std::time::{Instant, Duration} panic in the web so use the
web-time crate when compiling to
web assembly.
Structs§
- Oxid8
- Oxid8 Core
Constants§
- CPU_
TICK - Standard CPU tick rate set to 700Hz. This value is not used internally. Run a CPU cycle this often.
- SCREEN_
AREA - Virtual screen area (2048 pixels).
- SCREEN_
HEIGHT - Virtual screen height (32 pixels).
- SCREEN_
WIDTH - Virtual screen width (64 pixels).
- TIMER_
TICK - Standard TIMER tick rate set to 60Hz. This value is not used internally. Decrement the timers and refresh the display this often.