meowio/jsnes
Jeremy Penner 0f73094113 Tweak note-change detection
Values have been tuned to ensure samples aren't retriggered during
Mario's jump, but are generally retriggered in every other situation
where the frequency is changed. Retriggering more often makes the music
in games like Pictionary and Rad Gravity sound _way_ better, as well as
the sound effects in games with slower music.

* do not repeat samples for sustained notes; this never sounds great.
* reset after _any_ frequency change if we have been sitting on the
  same note for longer than a couple of frames.
* fix the "reset if the note has jumped by ~2 semitones" logic, which
  was *wildly* wrong.
2024-11-30 22:14:20 -05:00
..
.github git subrepo clone https://github.com/bfirsh/jsnes.git 2024-10-29 20:12:13 -04:00
example git subrepo clone https://github.com/bfirsh/jsnes.git 2024-10-29 20:12:13 -04:00
roms git subrepo clone https://github.com/bfirsh/jsnes.git 2024-10-29 20:12:13 -04:00
src Tweak note-change detection 2024-11-30 22:14:20 -05:00
test git subrepo clone https://github.com/bfirsh/jsnes.git 2024-10-29 20:12:13 -04:00
.eslintrc.json git subrepo clone https://github.com/bfirsh/jsnes.git 2024-10-29 20:12:13 -04:00
.gitignore git subrepo clone https://github.com/bfirsh/jsnes.git 2024-10-29 20:12:13 -04:00
.gitrepo git subrepo clone https://github.com/bfirsh/jsnes.git 2024-10-29 20:12:13 -04:00
.npmignore git subrepo clone https://github.com/bfirsh/jsnes.git 2024-10-29 20:12:13 -04:00
AUTHORS.md git subrepo clone https://github.com/bfirsh/jsnes.git 2024-10-29 20:12:13 -04:00
LICENSE git subrepo clone https://github.com/bfirsh/jsnes.git 2024-10-29 20:12:13 -04:00
package.json git subrepo clone https://github.com/bfirsh/jsnes.git 2024-10-29 20:12:13 -04:00
README.md git subrepo clone https://github.com/bfirsh/jsnes.git 2024-10-29 20:12:13 -04:00
webpack.config.js git subrepo clone https://github.com/bfirsh/jsnes.git 2024-10-29 20:12:13 -04:00
yarn.lock git subrepo clone https://github.com/bfirsh/jsnes.git 2024-10-29 20:12:13 -04:00

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

Embedding JSNES in a web page

You can use JSNES to embed a playable version of a ROM in a web page. This is handy if you are a homebrew ROM developer and want to put a playable version of your ROM on its web page.

The best implementation is jsnes-web but unfortunately it is not trivial to reuse the code. You'll have to copy and paste the code from that repository, the use the <Emulator> React component. Here is a usage example..

A project for potential contributors (hello!): jsnes-web should be reusable and on NPM! It just needs compiling and bundling.

A more basic example is in the example/ directory of this repository. Unfortunately this is known to be flawed, and doesn't do timing and sound as well as jsnes-web.

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

JSNES is based on James Sanders' vNES, and owes an awful lot to it. It also wouldn't have happened without Matt Wescott's JSSpeccy, which sparked the original idea. (Ben, circa 2008: "Hmm, I wonder what else could run in a browser?!")