cpu - Change to throw errors, instead of logging with console.error()

This commit is contained in:
n loewen 2023-08-29 10:42:36 -04:00
parent b08d9854c4
commit 37bb92f296
1 changed files with 4 additions and 4 deletions

View File

@ -54,8 +54,8 @@ module.exports = class CPU {
this._cycleStartCallbacks.forEach((fn) => fn());
if (this.IP >= this.memory.length) {
console.error('HALTING - IP greater than memory size'); // FIXME - halting the CPU should throw an error instead
this.running = false;
throw new Error('HALTING - IP greater than memory size');
} else {
this.instruction.opcode = this.memory[this.IP];
this.instruction.operand = this.memory[this.IP+1];
@ -68,8 +68,8 @@ module.exports = class CPU {
// Temporary limit as a lazy way to halt infinite loops
if ((this._cycleLimit > 0) && this.dbg.cycleCounter >= this._cycleLimit) {
console.warn(' HALTING - reached cycle limit'); // FIXME - throw error instead
this.running = false;
throw new Error(' HALTING - reached cycle limit');
}
this._cycleEndCallbacks.forEach((fn) => fn());
@ -292,8 +292,8 @@ module.exports = class CPU {
flag_toggle: (flagNum) => {
if (flagNum === null) {
console.error('Invalid flag number');
process.exit(); // FIXME -- throw error instead
let info = this.dbg.sourceInfo[this.IP];
throw new Error(`Invalid flag number: '${flagNum}' on line ${info.lineNumber}: ${info.source}`);
}
const flagName = this.flagNums[flagNum];
this.dbg.currentMnemonic = `FTG ${flagName}`;