From 60732c4d90abe71d990ca00894f41b5078857a60 Mon Sep 17 00:00:00 2001 From: WlodekM Date: Thu, 3 Apr 2025 11:51:48 +0300 Subject: readme --- README.md | 26 +++++++++++++++++++++++++- runtime.ts | 18 +++++++++++++----- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ec5beeb..5a6ff4c 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,28 @@ a 65c02 emulator written in typescript do NOT use this -i am the worst typescript developer ever and it's a miracle that this thing works \ No newline at end of file +i am the worst typescript developer ever and it's a miracle that this thing works + +if you do want to use it, here's how you can use the built-in runtime + +```bash +deno -A runtime.ts +``` + +options: + - `-d` - debug + - `-b`/`--binstart` - start of binary + +debug mode: +in debug mode, on each cycle, the runtime logs every instructions and pauses for input + +the input can either be any of the following commands or anything else, if the input isn't a command the runtime continues execution to the next instruction + +commands: + - `b` - break, exit + - `i` - inspect + - `s` - inspect stack + - `k[NUM]` - skip + - `r[ADR]` - breakpoint + - `g[ADR]` - goto, change PC + - `I[INS]` - breakpoint instruction \ No newline at end of file diff --git a/runtime.ts b/runtime.ts index d400031..2e6723f 100644 --- a/runtime.ts +++ b/runtime.ts @@ -1,5 +1,6 @@ import The65c02, { BitField, Pin } from "./65c02.ts"; import matrix from "./opcode_matrix.json" with { type: "json" }; +import { parseArgs } from "jsr:@std/cli/parse-args"; // the thing used for ram const ram = new Uint8Array(2**16); @@ -16,17 +17,24 @@ const cpu = new The65c02(function (this: The65c02) { await cpu.loadInstructions() +const args = parseArgs(Deno.args) + +const binStart = parseInt(args.b ?? args.binStart ?? '8000', 16) + +if (Number.isNaN(binStart)) + throw 'binStart is NaN!' + // mem address $0000 -ram[0xFFFC] = 0x00 -ram[0xFFFD] = 0x00 +ram[0xFFFC] = binStart & 0x00FF +ram[0xFFFD] = binStart & 0xFF00 // read code from file -const code = Deno.readFileSync('a.out') +const code = Deno.readFileSync(args._.toString() || 'msbasic/tmp/eater.bin') // write code to ram before execution for (let offset = 0; offset < code.length; offset++) { const byte = code[offset]; - ram[0x0000 + offset] = byte; + ram[binStart + offset] = byte; } // pull RESB low to reset the 65c02 @@ -102,7 +110,7 @@ while (!cpu.io.interruptRequest.high) { } 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]})`) + 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', '')); -- cgit 1.4.1-2-gfad0