Move cycle limit to a constant

This commit is contained in:
n loewen 2023-08-01 12:01:50 +01:00
parent d0a6ca886b
commit 34e86cd4f8
1 changed files with 3 additions and 2 deletions

View File

@ -3,6 +3,8 @@
// - instructions are two bytes long:
// one byte for the opcode, one for the argument
const CYCLE_LIMIT = 64; // max number of times to step the CPU, to stop endless loops
// STATE
const CPU = {
@ -174,7 +176,6 @@ exports.runProgram = (code) => {
CPU.loadMemory(code);
const initialMemory = JSON.parse(JSON.stringify(CPU.memory)); // Hack to make a copy-by-value -- https://stackoverflow.com/questions/18829099/copy-a-variables-value-into-another
console.log();
console.log("————————————————————————————————————————");
let time = new Date();
console.log( `┌─────────────────────┐`);
// Running at 11:48:15 AM
@ -183,7 +184,7 @@ exports.runProgram = (code) => {
logCPUState();
CPU.running = true;
for (let i = 0; i < 255; i++) { // FIXME: temporary limit as a lazy way to halt infinite loops
for (let i = 0; i < CYCLE_LIMIT; i++) { // FIXME: temporary limit as a lazy way to halt infinite loops
if (!CPU.running) break;
if (CPU.IP >= CPU.memory.length) break;
stepCPU();