A JavaScript NES emulator.
Clone or download
pubby and bfirsh Add (some) support for unofficial/illegal instructions.
Unofficial instructions are extremely rare in licensed games, but prevalent
enough in homebrew games to be worth including.

This commit adds all of the "useful" unofficial opcodes. It does not add
support for the weird ADC #ii SBC #ii variants, nor any instruction that
is unstable or unreliable. It does not implement IGN correctly w.r.t. reads
and page boundaries, but I doubt that will ever be an issue.

Further reading:
https://wiki.nesdev.com/w/index.php/CPU_unofficial_opcodes
https://wiki.nesdev.com/w/index.php/Programming_with_unofficial_opcodes
Latest commit 94f8744 Oct 17, 2018

README.md

JSNES

A JavaScript NES emulator.

It's a library that works in both the browser and Node.js. The browser UI is available at https://github.com/bfirsh/jsnes-web.

Installation

For Node.js or Webpack:

$ npm install jsnes

(Or yarn add jsnes.)

In the browser, you can use unpkg:

<script type="text/javascript" src="https://unpkg.com/jsnes/dist/jsnes.min.js"></script>

Usage

// Initialize and set up outputs
var nes = new jsnes.NES({
  onFrame: function(frameBuffer) {
    // ... write frameBuffer to screen
  },
  onAudioSample: function(left, right) {
    // ... play audio sample
  }
});

// Read ROM data from disk (using Node.js APIs, for the sake of this example)
const fs = require('fs');
var romData = fs.readFileSync('path/to/rom.nes', {encoding: 'binary'});

// Load ROM data as a string or byte array
nes.loadROM(romData);

// Run frames at 60 fps, or as fast as you can.
// You are responsible for reliable timing as best you can on your platform.
nes.frame();
nes.frame();
// ...

// Hook up whatever input device you have to the controller.
nes.buttonDown(1, jsnes.Controller.BUTTON_A);
nes.frame();
nes.buttonUp(1, jsnes.Controller.BUTTON_A);
nes.frame();
// ...

Build

To build a distribution:

$ yarn run build

This will create dist/jsnes.min.js.

Running tests

$ yarn test

Formatting code

All code must conform to Prettier formatting. The test suite won't pass unless it does.

To automatically format all your code, run:

$ yarn run format

Maintainers