diff --git a/notes/2023-08-15--dev-notes.md b/notes/2023-08-15--dev-notes.md index ee9e88c..c74537a 100644 --- a/notes/2023-08-15--dev-notes.md +++ b/notes/2023-08-15--dev-notes.md @@ -34,4 +34,19 @@ Ken Shirriff, [The 6502 overflow flag explained mathematically](https://www.righ - `23-2F` - reserved for future use / variable storage - `30 ` - initial value for IP - `30-80` - free -- `80-FF` - free, can be bank-switched \ No newline at end of file +- `80-FF` - free, can be bank-switched + +## Looping using an interval timer + + const loop = setInterval(async () => { + step = step + 1; + // Temporary limit as a lazy way to halt infinite loops: + if (CYCLE_LIMIT && (step > CYCLE_LIMIT)) { + console.log('SIMULATION HALTING - reached cycle limit'); + clearInterval(loop); + } + if (!CPU.running) clearInterval(loop); + if (CPU.IP >= CPU.memory.length) clearInterval(loop); + stepCPU(); + await logCPUState(debug); + }, frameRate); \ No newline at end of file