broken-neees
Version:
A really broken NEEES emulator that introduces glitches and random bugs on purpose!
36 lines (35 loc) • 905 B
JavaScript
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 STACK_ADDRESS = 0x0100;
class Stack {
constructor(memory, sp) {
this._memory = memory;
this._sp = sp;
}
push(value) {
this._memory.write(this._currentAddress(), value);
this._sp.decrement();
}
pop() {
this._sp.increment();
return this._memory.read(this._currentAddress());
}
push16(value) {
this.push(_byte.default.highByteOf(value));
this.push(_byte.default.lowByteOf(value));
}
pop16() {
const low = this.pop();
const high = this.pop();
return _byte.default.buildU16(high, low);
}
_currentAddress() {
return STACK_ADDRESS + this._sp.getValue();
}
}
exports.default = Stack;
;