cpu - Fix: Make sure that the 'reached cycle limit' message displays in all output modes

This commit is contained in:
n loewen 2023-08-26 14:48:37 +01:00
parent 9f68bd3027
commit 86d0b57c7a
1 changed files with 6 additions and 6 deletions

12
cpu.js
View File

@ -321,12 +321,6 @@ function startCPU(code) {
* @param {Boolean} [debug] - Print machine status and the line of code being executed
**/
async function stepCPU(debugInfo, debug = false, prettyPrintDisplay = false) {
if (CYCLE_LIMIT) { // Temporary limit as a lazy way to halt infinite loops
if (CPU.cycleCounter > CYCLE_LIMIT) {
console.warn('HALTING - reached cycle limit');
CPU.running = false;
}
}
if (CPU.IP >= CPU.memory.length) {
console.error('HALTING - IP greater than memory size');
CPU.running = false;
@ -347,6 +341,12 @@ async function stepCPU(debugInfo, debug = false, prettyPrintDisplay = false) {
CPU.cycleCounter += 1;
}
logCPUState(debugInfo, debug, prettyPrintDisplay);
if (CYCLE_LIMIT) { // Temporary limit as a lazy way to halt infinite loops
if (CPU.cycleCounter >= CYCLE_LIMIT) {
console.warn(' HALTING - reached cycle limit');
CPU.running = false;
}
}
if (!CPU.running) process.exit();
}