cpu - Add feature: 'Invalid opcode' error message
This commit is contained in:
parent
dbe630eb5e
commit
d30050a292
9
cpu.js
9
cpu.js
|
|
@ -338,6 +338,15 @@ async function stepCPU(debugInfo, debug = false) {
|
||||||
CPU.currentInstruction.opcode = CPU.memory[CPU.IP];
|
CPU.currentInstruction.opcode = CPU.memory[CPU.IP];
|
||||||
CPU.currentInstruction.operand = CPU.memory[CPU.IP+1];
|
CPU.currentInstruction.operand = CPU.memory[CPU.IP+1];
|
||||||
let executeInstruction = opcodes2mnemonics[CPU.currentInstruction.opcode];
|
let executeInstruction = opcodes2mnemonics[CPU.currentInstruction.opcode];
|
||||||
|
if (typeof executeInstruction === 'undefined') {
|
||||||
|
let info = debugInfo[CPU.previousIP];
|
||||||
|
console.error();
|
||||||
|
console.error(`Error: Invalid opcode`);
|
||||||
|
console.error(` Executing $${num2hex(info.machine[0])} $${num2hex(info.machine[1])}`);
|
||||||
|
console.error(` from line ${info.lineNumber}: ${info.source}`);
|
||||||
|
console.error();
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
executeInstruction(CPU.currentInstruction.operand);
|
executeInstruction(CPU.currentInstruction.operand);
|
||||||
CPU.cycleCounter += 1;
|
CPU.cycleCounter += 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue