nes-emu
Version:
A NES emulator
36 lines (33 loc) • 1.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _registers = require("../registers");
var _constants = _interopRequireDefault(require("../constants"));
var _helpers = require("../helpers");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
* Controller Port Register
*
* If the "strobe" flag is active, reads return the current state of the A button.
* If not, reads return the current state of [A, B, Select, Start, Up, Down, Left, Right] in a loop.
*/
class ControllerPort extends _registers.InMemoryRegister {
constructor() {
super();
this.cursor = 0;
}
/** Returns the strobe flag. */
get strobe() {
throw new Error("not_implemented");
}
/** Reads the current buton state, and updates the cursor if the strobe flag is on. */
readAt() {
if (this.cursor >= _constants.default.BUTTONS) return 1;
const isPressed = _helpers.Byte.getBit(this.value, this.cursor);
if (!this.strobe) this.cursor++;
return isPressed;
}
}
exports.default = ControllerPort;