1.0.20 • Published 8 months ago

nes-emu v1.0.20

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

NesCore

A NES Emulator made in JavaScript for educational purposes. Try it!

It's main objective is to reflect the NES internals as simply as possible by using clean, object-oriented code. It doesn't have any complex bitwise operations, huge switch-case statements or files with lots of magic numbers.

⚠️ This is not a cycle-accurate emulator and performance is not the main concern ⚠️

Features

  • 👾 It emulates the NES
  • 👨‍🔧 It plays Super Mario Bros. 3!
  • 💻 CPU
    • All official instructions are implemented
    • nestest passes ✔️
  • Fully functional 🖥️ PPU and 🔊 APU
  • 🔌 Supported mappers
  • 🐏 SRAM support
  • 💾 Save states support
  • 🌎 Web frontend using Web Workers and Gamepad API

Usage

npm install --save nes-emu

// configure video and audio:
const onFrame = (frameBuffer) => {
  // write `frameBuffer` (an Uint32Array) to screen...
};
const onSample = (sample) => {
  // write `sample` (a number) to audio buffer...
};

// create an instance:
const nes = new NES(onFrame, onSample);

// load a game:
nes.load(rom); // rom = Uint8Array

// run at 60 fps, or as fast as you can:
{
  nes.setButton(1, "BUTTON_A", true); // player = 1, button = A, pressed = true
  nes.setButton(2, "BUTTON_DOWN", false); // player = 2, button = DOWN, pressed = false
  // ...set the rest of the buttons
  nes.frame();
}

// save / restore states:
const saveState = nes.getSaveState();
nes.setSaveState(saveState);

👀 Have a look at the demo implementation for more details. When running the demo (npm start) you can add ?debug to the URL to enable a global window.debug object.

Full API

MethodParametersDescription
constructoronFrame, onSample, loggerCreates an emulator's instance. All properties can be set at any time.
loadrom, saveFileBytesLoads a ROM. If a saveFileBytes array is provided, it sets the SRAM content.
frameRuns the emulation for a whole video frame.
samplesrequestedSamplesRuns the emulation until the audio system generates requestedSamples.
scanlineRuns the emulation until the next scanline.
setButtonplayer, button, isPressedSets the button state of player to isPressed. The button can be one of: ["BUTTON_A", "BUTTON_B", "BUTTON_SELECT", "BUTTON_START", "BUTTON_UP", "BUTTON_DOWN", "BUTTON_LEFT", "BUTTON_RIGHT"]
clearButtonsplayerSets all buttons of player to a non-pressed state.
getSaveFileReturns an array with the SRAM bytes, or null.
getSaveStateReturns an object with a snapshot of the current state.
setSaveStatesaveStateRestores a saveState.

Screenshots

nestest screenshot

Useful links

1.0.20

8 months ago

1.0.19

9 months ago

1.0.18

10 months ago

1.0.17

11 months ago

1.0.16

11 months ago

1.0.15

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

1.0.0

2 years ago

0.0.0

2 years ago