cpu - Change to throw errors, instead of logging with console.error()
This commit is contained in:
parent
b08d9854c4
commit
37bb92f296
|
|
@ -54,8 +54,8 @@ module.exports = class CPU {
|
||||||
this._cycleStartCallbacks.forEach((fn) => fn());
|
this._cycleStartCallbacks.forEach((fn) => fn());
|
||||||
|
|
||||||
if (this.IP >= this.memory.length) {
|
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;
|
this.running = false;
|
||||||
|
throw new Error('HALTING - IP greater than memory size');
|
||||||
} else {
|
} else {
|
||||||
this.instruction.opcode = this.memory[this.IP];
|
this.instruction.opcode = this.memory[this.IP];
|
||||||
this.instruction.operand = this.memory[this.IP+1];
|
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
|
// Temporary limit as a lazy way to halt infinite loops
|
||||||
if ((this._cycleLimit > 0) && this.dbg.cycleCounter >= this._cycleLimit) {
|
if ((this._cycleLimit > 0) && this.dbg.cycleCounter >= this._cycleLimit) {
|
||||||
console.warn(' HALTING - reached cycle limit'); // FIXME - throw error instead
|
|
||||||
this.running = false;
|
this.running = false;
|
||||||
|
throw new Error(' HALTING - reached cycle limit');
|
||||||
}
|
}
|
||||||
|
|
||||||
this._cycleEndCallbacks.forEach((fn) => fn());
|
this._cycleEndCallbacks.forEach((fn) => fn());
|
||||||
|
|
@ -292,8 +292,8 @@ module.exports = class CPU {
|
||||||
|
|
||||||
flag_toggle: (flagNum) => {
|
flag_toggle: (flagNum) => {
|
||||||
if (flagNum === null) {
|
if (flagNum === null) {
|
||||||
console.error('Invalid flag number');
|
let info = this.dbg.sourceInfo[this.IP];
|
||||||
process.exit(); // FIXME -- throw error instead
|
throw new Error(`Invalid flag number: '${flagNum}' on line ${info.lineNumber}: ${info.source}`);
|
||||||
}
|
}
|
||||||
const flagName = this.flagNums[flagNum];
|
const flagName = this.flagNums[flagNum];
|
||||||
this.dbg.currentMnemonic = `FTG ${flagName}`;
|
this.dbg.currentMnemonic = `FTG ${flagName}`;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue