Skip to content

CHIP-8 emulator in Rust 🦀 compilable to WASM 🕸

License

Notifications You must be signed in to change notification settings

joao-conde/jc-chip8

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CHIP-8 emulator

CHIP-8 emulator in Rust 🦀 compilable to WASM 🕸.

Below is a web demo using this crate. Play here!

chip8-web

API Reference

Use the Chip8 struct to create an emulator instance and interact with it using the following API:

pub fn new() -> Chip8;
pub fn load_rom(&mut self, rom: &[u8]);
pub fn reset(&mut self);
pub fn clock(&mut self);
pub fn clock_dt(&mut self);
pub fn clock_st(&mut self);
pub fn pixels(&self) -> Vec<u8>;
pub fn beep(&self) -> bool;
pub fn key_press(&mut self, key: u8);
pub fn key_lift(&mut self, key: u8);

Basic usage:

use jc_chip8::chip8::{Chip8, SCREEN_PIXEL_HEIGHT, SCREEN_PIXEL_WIDTH};

let mut chip8 = Chip8::new();
chip8.load_rom(&rom);

loop {
  chip8.clock();
  chip8.clock_dt();
  chip8.clock_st();

  // Your draw code
  let pixels = chip8.pixels();
  ...
  
  // Your event processing
  match event {
    ... => chip8.key_press(0x01)
    ... => chip8.key_press(0x0F)
    ... => chip8.key_lift(0x0A)
    ... => chip8.key_lift(0x0F)
    ...
  }
  
  // Your sound code
  if chip8.beep() {
    ...
  }
}

About

CHIP-8 emulator in Rust 🦀 compilable to WASM 🕸

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Languages