UNPKG

nes-emu

Version:

A NES emulator

44 lines (39 loc) 1.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _ControllerPort = _interopRequireDefault(require("./ControllerPort")); var _helpers = require("../helpers"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } const STROBE_BIT = 0; /** * Primary Controller Port Register (<> read/write) * * Writing a value here affects the "strobe" flag (bit 0). * Games usually write 1, then 0, and then perform 8 consecutive reads to get the state of all buttons. */ class PrimaryControllerPort extends _ControllerPort.default { constructor() { super(); this._strobe = false; this._secondary = null; } /** Returns the strobe flag. */ get strobe() { return this._strobe; } /** Sets a `secondary` controller port, that will be affected by the strobe flag. */ setSecondary(secondary) { this._secondary = secondary; } /** Writes the strobe flag, potentially resetting the cursor. */ writeAt(__, byte) { this._strobe = !!_helpers.Byte.getBit(byte, STROBE_BIT); if (this._strobe) { this.cursor = 0; if (this._secondary) this._secondary.cursor = 0; } } } exports.default = PrimaryControllerPort;