@lukad/sen - v0.4.0
    Preparing search index...

    Class Emulator

    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. Call free() when the instance is no longer needed.

    Index
    • 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.

      Parameters

      • rom: Uint8Array
      • sample_rate: number

      Returns Emulator

    • Returns void

    • 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 Uint8Array

    • Returns the video frame height in pixels.

      Returns number

    • Returns the video frame width in pixels.

      Returns number

    • Returns void

    • 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.

      Parameters

      • ram: Uint8Array

      Returns void

    • 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.

      Parameters

      • rom: Uint8Array
      • sample_rate: number

      Returns void

    • 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 void

    • 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().

      Returns Uint8Array

    • 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.

      Parameters

      • mask: number

      Returns void

    • Sets the buttons currently held on controller 2.

      Uses the same button mask as setController1(). Pass 0 to release every button.

      Parameters

      • mask: number

      Returns void

    • 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().

      Returns Float32Array