From d30050a292f74874234d8afcc2392c1ad537d16d Mon Sep 17 00:00:00 2001 From: n loewen Date: Thu, 24 Aug 2023 16:31:11 +0100 Subject: [PATCH] cpu - Add feature: 'Invalid opcode' error message --- cpu.js | 9 +++++++++ 1 file changed, 9 insertions(+) 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; }