From 2a7d855b3582c95d84953b82effe366afbb450a7 Mon Sep 17 00:00:00 2001 From: n loewen Date: Tue, 15 Aug 2023 17:01:51 +0100 Subject: [PATCH 1/5] 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 From 59861ecdebd2afc40d89316fad5e34af800dd931 Mon Sep 17 00:00:00 2001 From: n loewen Date: Tue, 15 Aug 2023 17:02:02 +0100 Subject: [PATCH 2/5] Docs: Update to-do list --- notes/todo.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/notes/todo.md b/notes/todo.md index 4d2a0e1..92fec6e 100644 --- a/notes/todo.md +++ b/notes/todo.md @@ -1,9 +1,5 @@ # To do -## Issues to fix - -- [ ] Allow tabs in assembler - ## Research - [ ] Learn how the C64's PC gets initialized (what is the initial value? how is it set?) From 88e36eccceca7af174ac99ac1c5ed197676ff81e Mon Sep 17 00:00:00 2001 From: n loewen Date: Tue, 15 Aug 2023 20:17:02 +0100 Subject: [PATCH 3/5] Docs: Update to-dos in dev note 2023-08-15 --- notes/2023-08-15--dev-notes.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notes/2023-08-15--dev-notes.md b/notes/2023-08-15--dev-notes.md index c74537a..8466918 100644 --- a/notes/2023-08-15--dev-notes.md +++ b/notes/2023-08-15--dev-notes.md @@ -6,11 +6,11 @@ - [x] 'opcodes' and 'operands' - [x] fix $00 contains $20 bug -- [ ] Review planned changes to the system +- [x] Review planned changes to the system - [x] CHP, CFC -> FHP, FTG -- dev note 2023-08-07 - [/] bank-switching flag in 0 page - added notes below, but decided to leave implementation for another day - - [ ] ? 5x5 display + - [x] ? 5x5 display - [ ] Implement any changes necessary for writing a program? - [ ] Write a program From 899c24be7f91bc816d23c863c81068a75c67d631 Mon Sep 17 00:00:00 2001 From: n loewen Date: Tue, 15 Aug 2023 20:51:15 +0100 Subject: [PATCH 4/5] Bugfix (assembler): Make camelCase =constant names work in indirect expressions --- assembler.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/assembler.js b/assembler.js index be49a6c..96a3893 100644 --- a/assembler.js +++ b/assembler.js @@ -137,6 +137,8 @@ function decodeInstructions(line) { addressingMode = "indirect"; arg_str = arg_str.replace("(=", ""); arg_str = arg_str.replace(")", ""); + // FIXME - a quick hack to get around problems caused by another use of lower-casing to sanitize input: + arg_str = arg_str.toLowerCase(); dbg(2, `INDY - operand references '${arg_str}'`); arg_str = constants[arg_str]; From 5c41369ecd51c4d1e837345be4d8b186230037e8 Mon Sep 17 00:00:00 2001 From: n loewen Date: Tue, 15 Aug 2023 20:58:05 +0100 Subject: [PATCH 5/5] Add sketches/notes re: subroutines and a call stack --- notes/2023-08-12--dev-notes.md | 60 ++++++++++++++++++++++++++++++++ test-programs/subroutines.asm | 62 ++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 notes/2023-08-12--dev-notes.md create mode 100644 test-programs/subroutines.asm diff --git a/notes/2023-08-12--dev-notes.md b/notes/2023-08-12--dev-notes.md new file mode 100644 index 0000000..b7b29af --- /dev/null +++ b/notes/2023-08-12--dev-notes.md @@ -0,0 +1,60 @@ +# Dev notes — 2023-08-12 + +Brainstorming/sketching around subroutines with a return stack... + + ; need an instruction for IP → A i guess? + ; ideally… + ; but a jump table would work + ; put that at beginning of the code + ; then store numbers for subroutine labels in a designated memory slot + + lda $1 + sto $19 ; contains ID # for the next fn to jump to + + @jump_table + hop $1 + jmp @jt2 + jmp @example_computation + @jt2 + hop $2 + ; jmp @jt3 + nop + ; etc … + jmp @end + + @example_computation + lda 5 + sto $20 + lda 3 + sto $21 + ; $19 still has the # for this routine + ; but let’s pretend it doesn’t and demonstrate updating it + lda $1 + sto $19 + jmp @greater? + + ; call with numbers to test in $20 and $21 + ; result is stored in acc + @greater? + ; lda ($20) + ; sub ($21) + ; todo… + ; wouldn’t it be great to have a “hop if neg” op… + ; do we have to just subtract numbers until we get 0? + + ; no! + ; here’s an approach that’s at least better than that + lda ($21) + sto $22 ; stash + @loop + lda ($21) + sub $1 + sto $22 ; stash + sub ($20) + hop $0 + jmp @loop + sto $1 + jmp $jmp_table + ; ok this isn’t quite it… we also need to chexk if we hit 0 by just deceementinf and if so retuen 0 + + jmp @jump_table \ No newline at end of file diff --git a/test-programs/subroutines.asm b/test-programs/subroutines.asm new file mode 100644 index 0000000..2264517 --- /dev/null +++ b/test-programs/subroutines.asm @@ -0,0 +1,62 @@ +;; sketching around subroutines with return stack + +; jump table +; ---------- +; each function has a label +; and you can get to it with `JMP @label` +; ...but you can't push a label onto a stack +; so instead we give each function a number +; and stash that number in $24 when jumping to a subroutine +; then when the subroutine ends, it jumps here +; where that number gets mapped back onto the function's label + +lda $1 +sto $19 ; contains ID # for the next fn to jump to + +@jump_table +hop $1 + jmp @jt2 +jmp @example_computation +@jt2 +hop $2 + ; jmp @jt3 + nop +; etc … +jmp @end + +@example_computation +lda 5 +sto $20 +lda 3 +sto $21 +; $19 still has the # for this routine +; but let’s pretend it doesn’t and demonstrate updating it +lda $1 +sto $19 +jmp @greater? + +; call with numbers to test in $20 and $21 +; result is stored in acc +@greater? +; lda ($20) +; sub ($21) +; todo… +; wouldn’t it be great to have a “hop if neg” op… +; do we have to just subtract numbers until we get 0? + +; no! +; here’s an approach that’s at least better than that +lda ($21) +sto $22 ; stash +@loop +lda ($21) +sub $1 +sto $22 ; stash +sub ($20) +hop $0 + jmp @loop +sto $1 +jmp $jmp_table +; ok this isn’t quite it… we also need to chexk if we hit 0 by just deceementinf and if so retuen 0 + +jmp @jump_table