Skip to content

mikeyhogarth/chip8-typescript

Repository files navigation

CHIP8 Typescript

An implementation of a CHIP8 interpreter, written entirely in TypeScript.

If you want to see a demo of this in action, check out my Svelte Chip8 frontend which uses this module to display the screen output and take user input directly within a browser.

npm NPM Build Status Codacy Badge Coverage Status

Installation

Install using NPM;

npm i typescript-chip8

Usage

  import { createCpu } from "typescript-chip8";
  let cpu = createCpu();

  // Roms are buffers of big-endian 2-byte instructions. You can hard code these...
  const rom = Buffer.from([0x60, 0xaa, 0x61, 0xbb, 0x62, 0xcc]);
  /*
  // Or fetch from a remote source somewhere...
  const rom = await fetch(`http://example.com/roms/HelloWorld.ch8`)
    .then((r) => r.arrayBuffer())
    .then((data) => new Uint8Array(data));
  */
  cpu.load(rom);

  // perform 1 CPU cycle (you could put this in a loop/interval to "run" the cpu forever) 
  cpu.cycle();

Tests

This emulator is 100% unit tested and covered. Run tests with either of the following;

npm run test
npm run test -- --watch

Thank you

This would not have been possible if not for these excellent guides;