Skip to content

ZHKO1/JS_Chip8

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JS-CHIP8

A Chip-8 emulator written in JavaScript.
Try it here: https://js-chip8.netlify.app

Usage

The simplest way to set up the emulator is the following code:

let chip8 = Object.create(Chip8);
chip8.init({
  container: "#chip8_container",
});

// Load ROM file asynchronously...
fetch(`roms/${rom}`)
  .then(i => i.arrayBuffer())
  .then(async (buffer) => {
    const uint8View = new Uint8Array(buffer)
    chip8.read(uint8View);
    chip8.run();
  })

// Reset, Stop or Step
chip8.reset();
chip8.stop();
chip8.step();

// Catch keyboard events
let KeyboardMap = {
  "4": "ArrowLeft",
  "6": "ArrowRight",
};
document.onkeydown = (e) => {
  let key = e.key;
  for (let _0xKey in KeyboardMap) {
    if (KeyboardMap[_0xKey] == key) {
      chip8.keyDown(parseInt(_0xKey, 16));
    }
  }
}
document.onkeyup = (e) => {
  let key = e.key;
  for (let _0xKey in KeyboardMap) {
    if (KeyboardMap[_0xKey] == key) {
      chip8.keyUp(parseInt(_0xKey, 16));
    }
  }
}

Browser Support

This emulator should work in any decent web browser supporting typed arrays and canvas element.

Reference

License

This project is open source and available under the MIT License.

Releases

No releases published

Packages

No packages published