cpu - Fix: Quit the process when the CPU halts
This commit is contained in:
parent
41632b0a0f
commit
edad9ecbb8
7
cpu.js
7
cpu.js
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue