summary refs log tree commit diff
path: root/runtime.ts
diff options
context:
space:
mode:
authorWlodekM <[email protected]>2025-03-31 19:47:54 +0300
committerWlodekM <[email protected]>2025-03-31 19:47:54 +0300
commitcccb99226d3951fd9dfe1c4cf1c43126a1309d51 (patch)
tree518d3e965558ba313f103cee6161cd2b6aedb3b9 /runtime.ts
parentef4e8c20719822eebd6318a878cc37902c2b85a5 (diff)
move to pc-thing/
Diffstat (limited to 'runtime.ts')
-rw-r--r--runtime.ts55
1 files changed, 0 insertions, 55 deletions
diff --git a/runtime.ts b/runtime.ts
deleted file mode 100644
index cde4b95..0000000
--- a/runtime.ts
+++ /dev/null
@@ -1,55 +0,0 @@
-import { PC } from "./pc.ts";
-
-class Runtime {
-    pc: PC = new PC()
-    instructions: Map<string, (this: PC, argv: string[]) => void> = new Map()
-
-    addInstruction(name: string, instruction: (this: PC, argv: string[]) => void) {
-        this.instructions.set(name, instruction)
-    }
-
-    run(line: string) {
-        line = line.replace(/\s*;.*$/gm, '')
-        if (!line) return;
-        const [instr, ...argv] = line.split(' ')
-        const instructionId = instr.toLowerCase()
-        if (!this.instructions.has(instructionId))
-            throw 'unknown instruction';
-        const instruction = this.instructions.get(instructionId);
-        if (!instruction)
-            throw 'unknown instruction';
-        instruction.call(this.pc, argv)
-    }
-}
-
-const runtime = new Runtime()
-
-const dir = Deno.readDirSync('instructions');
-
-for (const filename of dir) {
-    runtime.addInstruction(filename.name.replace(/\..*?$/g, ''),
-        (await import('./instructions/'+filename.name)).default)
-}
-
-const code = new TextDecoder().decode(Deno.readFileSync('code.p')).split('\n')
-
-runtime.pc.programPointer = 0
-while (runtime.pc.programPointer < code.length) {
-    const line = code[runtime.pc.programPointer]
-    try {
-        runtime.run(line)
-        // console.debug('0'.repeat(4 - String(runtime.pc.programPointer).length) +
-        //     runtime.pc.programPointer,
-        //     runtime.pc.registers, line)
-    } catch (error) {
-        console.error(error, 'at', line);
-        throw 'Unexpected error while running program'
-    }
-    runtime.pc.programPointer++
-}
-
-console.debug('end of execution, dumping ram', runtime.pc.mem)
-Deno.writeFileSync('ram.bin', Uint8Array.from(runtime.pc.mem.map(a => [a & 0x00FF, (a & 0xFF00) >> 8]).flatMap(([a, b]) => [a, b])))
-new Deno.Command('hexdump', {
-    args: ['-C', 'ram.bin']
-}).spawn()
\ No newline at end of file