cpu - Add feature: 'Invalid opcode' error message

This commit is contained in:
n loewen 2023-08-24 16:31:11 +01:00
parent dbe630eb5e
commit d30050a292
1 changed files with 9 additions and 0 deletions

9
cpu.js
View File

@ -338,6 +338,15 @@ async function stepCPU(debugInfo, debug = false) {
CPU.currentInstruction.opcode = CPU.memory[CPU.IP];
CPU.currentInstruction.operand = CPU.memory[CPU.IP+1];
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);
CPU.cycleCounter += 1;
}