From e2568226af4af2d3b27e9e1a775e7244c5ef7191 Mon Sep 17 00:00:00 2001 From: WlodekM Date: Thu, 3 Apr 2025 21:51:53 +0300 Subject: more progress on trying to get wozmon running --- runtime.ts | 130 +++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 87 insertions(+), 43 deletions(-) (limited to 'runtime.ts') 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(); -- cgit 1.4.1-2-gfad0