Creates an emulator loaded with an iNES ROM.
sample_rate is the output audio sample rate in hertz, usually
AudioContext.sampleRate. Throws an Error if rom is invalid or uses
an unsupported mapper.
Returns a copy of the current video frame as row-major RGBA bytes.
The returned array contains frameWidth() * frameHeight() * 4 bytes and
can be copied directly into an ImageData object's data array.
Returns the video frame height in pixels.
Returns the video frame width in pixels.
Restores the current cartridge's battery-backed save RAM.
Throws an Error if the ROM has no battery-backed RAM or if ram has
the wrong length for the cartridge.
Replaces the current game with a new iNES ROM.
This starts the new game from power-on state and discards queued audio.
sample_rate is in hertz. Throws an Error if rom is invalid or uses
an unsupported mapper.
Advances emulation until the next complete video frame.
After calling this method, use frameBuffer() to read the new frame and
takeAudio() to drain the audio samples generated so far.
Returns a copy of the current cartridge's battery-backed save RAM.
Throws an Error when the loaded ROM does not declare battery-backed
RAM. Persist the returned bytes and restore them with loadSaveRam().
Sets the buttons currently held on controller 1.
Combine buttons with bitwise OR:
A = 1 << 0
B = 1 << 1
Select = 1 << 2
Start = 1 << 3
Up = 1 << 4
Down = 1 << 5
Left = 1 << 6
Right = 1 << 7.
Pass 0 to release every button.
Sets the buttons currently held on controller 2.
Uses the same button mask as setController1(). Pass 0 to release
every button.
Returns all queued mono audio samples and clears the audio queue.
Samples are 32-bit floating-point values at the sample rate passed to
the constructor or the most recent call to reset().
A self-contained NES emulator.
Create an emulator from an iNES ROM, call
runFrame()to advance it, then read the video and audio produced by that frame. Callfree()when the instance is no longer needed.