diff --git a/cpu.js b/cpu.js index 8974daa..7c0da07 100644 --- a/cpu.js +++ b/cpu.js @@ -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; }