summary refs log tree commit diff
path: root/runtime.ts
diff options
context:
space:
mode:
authorWlodekM <[email protected]>2025-04-03 21:51:53 +0300
committerWlodekM <[email protected]>2025-04-03 21:51:53 +0300
commite2568226af4af2d3b27e9e1a775e7244c5ef7191 (patch)
treef6bd5d51753c549728a7160743e3b935a3a39602 /runtime.ts
parentc62e133afb34fc38445af7bbe61e88cf45e9a7e3 (diff)
more progress on trying to get wozmon running
Diffstat (limited to 'runtime.ts')
-rw-r--r--runtime.ts130
1 files changed, 87 insertions, 43 deletions
diff --git a/runtime.ts b/runtime.ts
index 8ecfe1b..1527c62 100644
--- a/runtime.ts
+++ b/runtime.ts
@@ -59,11 +59,11 @@ function inspect() {
         }).join('\n'));
     
     console.log('\nregisters:')
-    console.log(` A:      ${cpu.regA.bits.reverse().map(k=>+k).join('')} (0x${cpu.regA.num().toString(16)})`)
-    console.log(` X:      ${cpu.regX.bits.reverse().map(k=>+k).join('')} (0x${cpu.regX.num().toString(16)})`)
-    console.log(` Y:      ${cpu.regY.bits.reverse().map(k=>+k).join('')} (0x${cpu.regY.num().toString(16)})`)
-    console.log(` SP:     ${cpu.stackPointer.bits.reverse().map(k=>+k).join('')} (0x${cpu.stackPointer.num().toString(16)})`)
-    console.log(` PC:     ${cpu.programCounter.bits.reverse().map(k=>+k).join('')} (0x${cpu.programCounter.num().toString(16)})`)
+    console.log(` A:  ${cpu.regA.bits.reverse().map(k=>+k).join('')} (0x${cpu.regA.num().toString(16)})`)
+    console.log(` X:  ${cpu.regX.bits.reverse().map(k=>+k).join('')} (0x${cpu.regX.num().toString(16)})`)
+    console.log(` Y:  ${cpu.regY.bits.reverse().map(k=>+k).join('')} (0x${cpu.regY.num().toString(16)})`)
+    console.log(` SP: ${cpu.stackPointer.bits.reverse().map(k=>+k).join('')} (0x${cpu.stackPointer.num().toString(16)})`)
+    console.log(` PC: ${cpu.programCounter.bits.reverse().map(k=>+k).join('')} (0x${cpu.programCounter.num().toString(16)})`)
 }
 
 const debug = Deno.args.includes('-d')
@@ -77,6 +77,7 @@ if (debug) {
 }
 
 // repeat until the cpu requests an interrupt
+mainloop:
 while (!cpu.io.interruptRequest.high) {
     const instId = ram[cpu.programCounter.num()]
         .toString(16)
@@ -106,33 +107,39 @@ while (!cpu.io.interruptRequest.high) {
             skip--
             break dbg;
         }
-        const i = new Uint8Array(8);
-        Deno.stdout.write(Uint8Array.from(['.'.charCodeAt(0)]))
-        await Deno.stdin.read(i);
-        if (i[0] == 'b'.charCodeAt(0)) {
-            console.log('BREAK!!')
-            break;
-        } else if (i[0] == 'i'.charCodeAt(0)) {
-            inspect()
-        } else if (i[0] == 's'.charCodeAt(0)) {
-            console.log('stack:')
-            for (let i = 0; i < cpu.stackPointer.num(); i++) {
-                console.log(` ${i.toString(16).padStart(2, '0')} ${ram[0x01FF - i].toString(2).padStart(8, '0')} (0x${ram[0x01FF - i].toString(16).padStart(4, '0')} ${ram[0x01FF - i].toString().padStart(3)})`)
-            }
-        } else if (i[0] == 'k'.charCodeAt(0)) {
-            const num = +(new TextDecoder().decode(i.slice(1, 7)).replaceAll('\0', ''));
-            if (Number.isNaN(num)) {
-                console.log('NaN')
-                break dbg;
-            }
-            skip = num;
-            console.log(`skipping ${num} cycles`)
-        } else if (i[0] == 'r'.charCodeAt(0)) {
-            const num = i[2] ? parseInt(new TextDecoder().decode(i.slice(1, 7)).replace('\n', '').replaceAll('\0', ''), 16) : cpu.programCounter.num();
-            console.log(`set breakpoint on`, num.toString(16))
-            breakpoints.push(num)
-        } else if (i[0] == '?'.charCodeAt(0)) {
-            console.log(`b - break, exit
+        dbgl:
+        while (true) {
+            const i = new Uint8Array(16);
+            Deno.stdout.write(Uint8Array.from(['.'.charCodeAt(0)]))
+            await Deno.stdin.read(i);
+            if (i[0] == 'b'.charCodeAt(0)) {
+                console.log('BREAK!!')
+                break mainloop;
+            } else if (i[0] == 'i'.charCodeAt(0)) {
+                inspect()
+                continue;
+            } else if (i[0] == 's'.charCodeAt(0)) {
+                console.log('stack:')
+                for (let i = 0; i < cpu.stackPointer.num(); i++) {
+                    console.log(` ${i.toString(16).padStart(2, '0')} ${ram[0x01FF - i].toString(2).padStart(8, '0')} (0x${ram[0x01FF - i].toString(16).padStart(4, '0')} ${ram[0x01FF - i].toString().padStart(3)})`)
+                }
+                continue;
+            } else if (i[0] == 'k'.charCodeAt(0)) {
+                const num = +(new TextDecoder().decode(i.slice(1, 7)).replaceAll('\0', ''));
+                if (Number.isNaN(num)) {
+                    console.log('NaN')
+                    break dbg;
+                }
+                skip = num;
+                console.log(`skipping ${num} cycles`)
+                break dbgl;
+            } else if (i[0] == 'r'.charCodeAt(0)) {
+                const num = i[2] ? parseInt(new TextDecoder().decode(i.slice(1, 7)).replace('\n', '').replaceAll('\0', ''), 16) : cpu.programCounter.num();
+                console.log(`set breakpoint on`, num.toString(16))
+                breakpoints.push(num)
+                continue;
+            } else if (i[0] == '?'.charCodeAt(0)) {
+                console.log(`b - break, exit
 i - inspect
 s - inspect stack
 c - continue
@@ -140,17 +147,54 @@ k[NUM] - skip
 r[ADR] - breakpoint
 g[ADR] - goto, change PC
 I[INS] - breakpoint instruction`);
-        } else if (i[0] == 'g'.charCodeAt(0)) {
-            const num = i[2] ? parseInt(new TextDecoder().decode(i.slice(1, 7)).replace('\n', '').replaceAll('\0', ''), 16) : cpu.programCounter.num();
-            console.log(`PC set to`, num.toString(16))
-            cpu.programCounter.set(num)
-        } else if (i[0] == 'I'.charCodeAt(0)) {
-            const instr = new TextDecoder().decode(i.slice(1, 7)).replace('\n', '').replaceAll('\0', '')
-            console.log(`instruction breakpoint set on`, instr)
-            instBreakpoints.push(instr)
-        } else if (i[0] == 'c'.charCodeAt(0)) {
-            skip = -1
-            console.log(`continuing execution`)
+                continue;
+            } else if (i[0] == 'g'.charCodeAt(0)) {
+                const num = i[2] ? parseInt(new TextDecoder().decode(i.slice(1, 7)).replace('\n', '').replaceAll('\0', ''), 16) : cpu.programCounter.num();
+                console.log(`PC set to`, num.toString(16))
+                cpu.programCounter.set(num)
+                continue;
+            } else if (i[0] == 'I'.charCodeAt(0)) {
+                const instr = new TextDecoder().decode(i.slice(1, 7)).replace('\n', '').replaceAll('\0', '')
+                console.log(`instruction breakpoint set on`, instr)
+                instBreakpoints.push(instr)
+                continue;
+            } else if (i[0] == 'c'.charCodeAt(0)) {
+                skip = -1
+                console.log(`continuing execution`)
+            } else if (i[0] == ':'.charCodeAt(0)) {
+                const instr = new TextDecoder().decode(i.slice(1, 15)).replace('\n', '').replaceAll('\0', '')
+                const match = [...instr.matchAll(/^([a-fA-F0-9]{1,4})=([a-fA-F0-9]{1,2})$/g)];
+                if (!match || !match[0]) {
+                    console.log('not matched, uhoh')
+                    continue;
+                }
+                const [_, addr, data] = match[0]
+                console.log(`set $${addr} to 0x${data}`)
+                ram[parseInt(addr, 16)] = parseInt(data, 16)
+                continue;
+            } else if (i[0] == '\\'.charCodeAt(0)) {
+                const num = parseInt(new TextDecoder().decode(i.slice(1, 7)).replace('\n', '').replaceAll('\0', ''), 16);
+                if (Number.isNaN(num))
+                    continue;
+                console.log(`${num.toString(16).padStart(4, '0')}: ${ram[num].toString(16).padStart(2, '0')}`)
+                continue;
+            } else if (i[0] == '\''.charCodeAt(0)) {
+                if (i[1] == '\n'.charCodeAt(0)) {
+                    ram[0x5000] = 0;
+                    ram[0x5001] = 0;
+                    console.log('reset')
+                    continue;
+                }
+                const num = parseInt(new TextDecoder().decode(i.slice(1, 3)).replace('\n', '').replaceAll('\0', ''), 16);
+                if (Number.isNaN(num))
+                    continue;
+                ram[0x5000] = num;
+                ram[0x5001] = 0x08;
+                console.log(`set $5000 to 0x${num.toString(16).padStart(2, '0')} and $5001 to 08`)
+                console.log('skipping 8 cycles');
+                skip = 8;
+            }
+            break;
         }
     }
     cpu.cycle();