From c415056194d6965d65c0fa18a38cdbc24660bb2c Mon Sep 17 00:00:00 2001 From: n loewen Date: Tue, 15 Aug 2023 16:59:12 +0100 Subject: [PATCH 1/4] ! Feature: Change to a 5x5 display [breaking change] --- display.js | 8 ++++---- machine.config.js | 6 +++--- readme.md | 10 +++++----- test-programs/fill-display.asm | 22 +++++++++++++--------- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/display.js b/display.js index 9fe6303..6a2c1b8 100644 --- a/display.js +++ b/display.js @@ -7,8 +7,8 @@ const { num2hex } = require('./logging.js'); **/ const printDisplay = (mem) => { const disp = mem[POINTER_TO_START_OF_DISPLAY_MEM]; - for (let i = disp; i < disp + 16; i += 4) { - console.log(`${num2hex(mem[i])} ${num2hex(mem[i+1])} ${num2hex(mem[i+2])} ${num2hex(mem[i+3])}`); + for (let i = disp; i < disp + 25; i += 5) { + console.log(`${num2hex(mem[i])} ${num2hex(mem[i+1])} ${num2hex(mem[i+2])} ${num2hex(mem[i+3])} ${num2hex(mem[i+4])}`); } } @@ -19,8 +19,8 @@ const printDisplay = (mem) => { const prettyPrintDisplay = (mem) => { const disp = mem[POINTER_TO_START_OF_DISPLAY_MEM]; const num2pic = (n) => n > 0 ? '⚫' : '⚪'; - for (let i = disp; i < disp + 16; i += 4) { - console.log(`${num2pic(mem[i])}${num2pic(mem[i+1])}${num2pic(mem[i+2])}${num2pic(mem[i+3])}`); + for (let i = disp; i < disp + 25; i += 5) { + console.log(`${num2pic(mem[i])}${num2pic(mem[i])}${num2pic(mem[i+1])}${num2pic(mem[i+2])}${num2pic(mem[i+4])}`); } } diff --git a/machine.config.js b/machine.config.js index b526793..63b8bc8 100644 --- a/machine.config.js +++ b/machine.config.js @@ -1,11 +1,11 @@ module.exports = { "START_OF_DISPLAY_MEM": 0, - "POINTER_TO_START_OF_DISPLAY_MEM": 32, - "POINTER_TO_START_OF_KEYPAD_MEM": 33, + "POINTER_TO_START_OF_DISPLAY_MEM": 33, + "POINTER_TO_START_OF_KEYPAD_MEM": 34, "INITIAL_IP_ADDRESS": 48, // max number of times to step the CPU, // to stop endless loops // 0 = infinite - "CYCLE_LIMIT": 128, + "CYCLE_LIMIT": 256, } \ No newline at end of file diff --git a/readme.md b/readme.md index 20c9b12..6bb9b1d 100644 --- a/readme.md +++ b/readme.md @@ -62,11 +62,11 @@ With verbose debugging output: ## Memory map / Peripherals -- `00-0F` - display (4x4) -- `10-1F` - keypad? (details TBD) -- `20 ` - pointer to display memory -- `21 ` - pointer to keypad memory -- `22-2F` - reserved for future use / variable storage +- `00-19` - display (5x5) +- `20 ` - keypad (details TBD) +- `21 ` - pointer to display memory +- `22 ` - pointer to keypad memory +- `23-2F` - reserved for future use / variable storage - `30 ` - initial value for IP - `30-FF` - free diff --git a/test-programs/fill-display.asm b/test-programs/fill-display.asm index aa09e53..1d7f36a 100644 --- a/test-programs/fill-display.asm +++ b/test-programs/fill-display.asm @@ -1,23 +1,27 @@ ;; Fill display with $FF +; updated for 5x5 display + +=pixelIndex $24 +=pixelFill $25 LDA $00 ; Start of display -STO $21 ; Pixel index +STO =pixelIndex -; store the $FF that we'll use to fill the screen LDA $FF -STO $22 +STO =pixelFill @copy-to-display - LDA ($22) ; A = mem[$22] = $FF - STO ($21) ; mem[mem[$21]] = A = $FF + LDA ($25) ; A = mem[$25] = $FF + STO ($24) ; update pixel ... mem[mem[$24]] = A = $FF ; increment pixel index -LDA ($21) +LDA ($24) ADD $01 -STO $21 +STO =pixelIndex -; if CF is set, then the display is full and we're done -FHP 0 +LDA ($24) ; pixelIndex +SUB $19 ; if pixelIndex - $19 == 0, we've reached the end +FHP 2 ; Zero flag is #2 JMP @copy-to-display END \ No newline at end of file From 1baa0ded328ce3027bfee815451372ef77bd515b Mon Sep 17 00:00:00 2001 From: n loewen Date: Tue, 15 Aug 2023 17:01:51 +0100 Subject: [PATCH 2/4] 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 934f4c0f3f7a9d9b05b7fdfc6e60bd906517d18b Mon Sep 17 00:00:00 2001 From: n loewen Date: Tue, 15 Aug 2023 17:02:02 +0100 Subject: [PATCH 3/4] 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 2cceaa71f2e006c4a47b7d5fce603c9d1a029b74 Mon Sep 17 00:00:00 2001 From: n loewen Date: Tue, 15 Aug 2023 20:53:51 +0100 Subject: [PATCH 4/4] Refactor: Rewrite fill-display: - make more use of constants - improve comments --- test-programs/fill-display.asm | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/test-programs/fill-display.asm b/test-programs/fill-display.asm index 1d7f36a..a9b92a7 100644 --- a/test-programs/fill-display.asm +++ b/test-programs/fill-display.asm @@ -1,27 +1,25 @@ ;; Fill display with $FF ; updated for 5x5 display -=pixelIndex $24 -=pixelFill $25 +=*px $24 +=fill $25 -LDA $00 ; Start of display -STO =pixelIndex + ; Initialize variables... +LDA $00 ; (Address for the first px on the display) +STO =*px ; Pointer to current px +LDA $FF ; ($FF is 'on', $00 is 'off') +STO =fill ; Stash value to fill with -LDA $FF -STO =pixelFill +@paint + LDA (=fill) ; (A = mem[fill] = $FF) + STO (=*px) ; Paint pixel (mem[mem[*px]] = A = $FF) -@copy-to-display - LDA ($25) ; A = mem[$25] = $FF - STO ($24) ; update pixel ... mem[mem[$24]] = A = $FF - -; increment pixel index -LDA ($24) +LDA (=*px) ; Increment pixel pointer... ADD $01 -STO =pixelIndex - -LDA ($24) ; pixelIndex -SUB $19 ; if pixelIndex - $19 == 0, we've reached the end -FHP 2 ; Zero flag is #2 - JMP @copy-to-display +STO =*px +LDA (=*px) ; Test whether to loop or not... +SUB $19 ; if *px - $19 == 0, we've reached the end +FHP 2 ; (Zero flag is #2) + JMP @paint END \ No newline at end of file