cpu - Fix: Quit the process when the CPU halts

This commit is contained in:
n loewen 2023-08-26 13:26:26 +01:00
parent 41632b0a0f
commit edad9ecbb8
1 changed files with 19 additions and 20 deletions

7
cpu.js
View File

@ -84,7 +84,7 @@ const Instructions = {
},
store_addr: (addr) => {
CPU.currentInstruction.mnemonic = 'STO addr';
CPU.currentInstruction.mnemonic = `STO addr; @addr: ${num2hex(CPU.memory[addr])}`;
CPU.memory[CPU.memory[addr]] = CPU.Acc;
CPU.incrementIP(2);
},
@ -333,7 +333,6 @@ async function stepCPU(debugInfo, debug = false, prettyPrintDisplay = false) {
CPU.running = false;
}
}
if (CPU.running) {
if (CPU.IP >= CPU.memory.length) {
console.error('HALTING - IP greater than memory size');
CPU.running = false;
@ -353,8 +352,8 @@ async function stepCPU(debugInfo, debug = false, prettyPrintDisplay = false) {
executeInstruction(CPU.currentInstruction.operand);
CPU.cycleCounter += 1;
}
}
logCPUState(debugInfo, debug, prettyPrintDisplay);
if (!CPU.running) process.exit();
}
/**
@ -374,7 +373,7 @@ exports.runProgram =
// Animate the output by pausing between steps
const loop = setInterval(async () => {
stepCPU(debugInfo, debug, prettyPrint);
if (!CPU.running) clearInterval(loop);
if (!CPU.running) process.exit();
}, clockSpeed);
}
};