From 2a7d855b3582c95d84953b82effe366afbb450a7 Mon Sep 17 00:00:00 2001 From: n loewen Date: Tue, 15 Aug 2023 17:01:51 +0100 Subject: [PATCH] Docs: Add an abandoned interval-timer-based refactor of the main CPU loop to dev notes --- notes/2023-08-15--dev-notes.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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