broken-neees
Version:
A really broken NEEES emulator that introduces glitches and random bugs on purpose!
48 lines (45 loc) • 1.41 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _byte = _interopRequireDefault(require("../lib/byte"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const BUTTONS = ["BUTTON_A", "BUTTON_B", "BUTTON_SELECT", "BUTTON_START", "BUTTON_UP", "BUTTON_DOWN", "BUTTON_LEFT", "BUTTON_RIGHT"];
class Controller {
constructor(player) {
this.strobe = false;
this.cursor = 0;
this.other = null;
this._player = player;
this._buttons = [false, false, false, false, false, false, false, false];
}
update(button, isPressed) {
const index = BUTTONS.indexOf(button);
this._buttons[index] = isPressed;
}
onRead() {
const strobe = this._player === 1 ? this.strobe : this.other.strobe;
if (this.cursor >= 8) return 1;
// [!!!]
const cursor = this.cursor;
const isPressed = this._buttons[this.cursor];
if (!strobe) this.cursor++;
// [!!!]
if (!this.cpu.unbroken) {
if (this._buttons[0]) {
if (cursor === 6) return +this._buttons[7];else if (cursor === 7) return +this._buttons[6];
}
}
return +isPressed;
}
onWrite(value) {
if (this._player === 2) return;
this.strobe = _byte.default.getFlag(value, 0);
if (this.strobe) {
this.cursor = 0;
this.other.cursor = 0;
}
}
}
exports.default = Controller;