summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--opcode_matrix.json246
-rw-r--r--runtime.ts37
3 files changed, 257 insertions, 27 deletions
diff --git a/.gitignore b/.gitignore
index 36c5889..854ae08 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,3 +10,4 @@ thefile
 riscv
 pc-thingg
 a.out
+msbasic
diff --git a/opcode_matrix.json b/opcode_matrix.json
index be27986..5cabf60 100644
--- a/opcode_matrix.json
+++ b/opcode_matrix.json
@@ -7,6 +7,14 @@
         "mnemonic": "ORA",
         "mode": "indirect, Y-indexed"
     },
+    "12": {
+        "mnemonic": "ORA",
+        "mode": "zero-page indirect"
+    },
+    "14": {
+        "mnemonic": "TRB",
+        "mode": "zero-page"
+    },
     "15": {
         "mnemonic": "ORA",
         "mode": "zero-page, X-indexed"
@@ -15,6 +23,10 @@
         "mnemonic": "ASL",
         "mode": "zero-page, X-indexed"
     },
+    "17": {
+        "mnemonic": "RMB1",
+        "mode": "zero-page"
+    },
     "18": {
         "mnemonic": "CLC",
         "mode": "implied"
@@ -43,6 +55,10 @@
         "mnemonic": "ROL",
         "mode": "zero-page"
     },
+    "27": {
+        "mnemonic": "RMB2",
+        "mode": "zero-page"
+    },
     "28": {
         "mnemonic": "PLP",
         "mode": "implied"
@@ -59,6 +75,14 @@
         "mnemonic": "AND",
         "mode": "indirect, Y-indexed"
     },
+    "32": {
+        "mnemonic": "AND",
+        "mode": "zero-page indirect"
+    },
+    "34": {
+        "mnemonic": "BIT",
+        "mode": "zero-page, X-indexed"
+    },
     "35": {
         "mnemonic": "AND",
         "mode": "zero-page, X-indexed"
@@ -67,6 +91,10 @@
         "mnemonic": "ROL",
         "mode": "zero-page, X-indexed"
     },
+    "37": {
+        "mnemonic": "RMB3",
+        "mode": "zero-page"
+    },
     "38": {
         "mnemonic": "SEC",
         "mode": "implied"
@@ -91,6 +119,10 @@
         "mnemonic": "LSR",
         "mode": "zero-page"
     },
+    "47": {
+        "mnemonic": "RMB4",
+        "mode": "zero-page"
+    },
     "48": {
         "mnemonic": "PHA",
         "mode": "implied"
@@ -107,6 +139,10 @@
         "mnemonic": "EOR",
         "mode": "indirect, Y-indexed"
     },
+    "52": {
+        "mnemonic": "EOR",
+        "mode": "zero-page indirect"
+    },
     "55": {
         "mnemonic": "EOR",
         "mode": "zero-page, X-indexed"
@@ -115,6 +151,10 @@
         "mnemonic": "LSR",
         "mode": "zero-page, X-indexed"
     },
+    "57": {
+        "mnemonic": "RMB5",
+        "mode": "zero-page"
+    },
     "58": {
         "mnemonic": "CLI",
         "mode": "implied"
@@ -131,6 +171,10 @@
         "mnemonic": "ADC",
         "mode": "X-indexed, indirect"
     },
+    "64": {
+        "mnemonic": "STZ",
+        "mode": "zero-page"
+    },
     "65": {
         "mnemonic": "ADC",
         "mode": "zero-page"
@@ -139,6 +183,10 @@
         "mnemonic": "ROR",
         "mode": "zero-page"
     },
+    "67": {
+        "mnemonic": "RMB6",
+        "mode": "zero-page"
+    },
     "68": {
         "mnemonic": "PLA",
         "mode": "implied"
@@ -155,6 +203,14 @@
         "mnemonic": "ADC",
         "mode": "indirect, Y-indexed"
     },
+    "72": {
+        "mnemonic": "ADC",
+        "mode": "zero-page indirect"
+    },
+    "74": {
+        "mnemonic": "STZ",
+        "mode": "zero-page, X-indexed"
+    },
     "75": {
         "mnemonic": "ADC",
         "mode": "zero-page, X-indexed"
@@ -163,6 +219,10 @@
         "mnemonic": "ROR",
         "mode": "zero-page, X-indexed"
     },
+    "77": {
+        "mnemonic": "RMB7",
+        "mode": "zero-page"
+    },
     "78": {
         "mnemonic": "SEI",
         "mode": "implied"
@@ -171,6 +231,10 @@
         "mnemonic": "ADC",
         "mode": "absolute, Y-indexed"
     },
+    "80": {
+        "mnemonic": "BRA",
+        "mode": "relative"
+    },
     "81": {
         "mnemonic": "STA",
         "mode": "X-indexed, indirect"
@@ -187,10 +251,18 @@
         "mnemonic": "STX",
         "mode": "zero-page"
     },
+    "87": {
+        "mnemonic": "SMB0",
+        "mode": "zero-page"
+    },
     "88": {
         "mnemonic": "DEY",
         "mode": "implied"
     },
+    "89": {
+        "mnemonic": "BIT",
+        "mode": "immediate"
+    },
     "90": {
         "mnemonic": "BCC",
         "mode": "relative"
@@ -199,18 +271,26 @@
         "mnemonic": "STA",
         "mode": "indirect, Y-indexed"
     },
+    "92": {
+        "mnemonic": "STA",
+        "mode": "zero-page indirect"
+    },
     "94": {
         "mnemonic": "STY",
         "mode": "zero-page, X-indexed"
     },
     "95": {
-        "mnemonic": "STA; InsItr",
+        "mnemonic": "STA",
         "mode": "zero-page, X-indexed"
     },
     "96": {
         "mnemonic": "STX",
         "mode": "zero-page, Y-indexed"
     },
+    "97": {
+        "mnemonic": "SMB1",
+        "mode": "zero-page"
+    },
     "98": {
         "mnemonic": "TYA",
         "mode": "implied"
@@ -602,5 +682,169 @@
     "fe": {
         "mnemonic": "INC",
         "mode": "absolute, X-indexed"
+    },
+    "04": {
+        "mnemonic": "TSB",
+        "mode": "zero-page"
+    },
+    "07": {
+        "mnemonic": "RMB0",
+        "mode": "zero-page"
+    },
+    "0c": {
+        "mnemonic": "TSB",
+        "mode": "absolute"
+    },
+    "0f": {
+        "mnemonic": "BBR0",
+        "mode": "relative"
+    },
+    "1a": {
+        "mnemonic": "INC",
+        "mode": "accumulator (implied)"
+    },
+    "1c": {
+        "mnemonic": "TRB",
+        "mode": "absolute"
+    },
+    "1f": {
+        "mnemonic": "BBR1",
+        "mode": "relative"
+    },
+    "2f": {
+        "mnemonic": "BBR2",
+        "mode": "relative"
+    },
+    "3a": {
+        "mnemonic": "DEC",
+        "mode": "accumulator (implied)"
+    },
+    "3c": {
+        "mnemonic": "BIT",
+        "mode": "absolute, X-indexed"
+    },
+    "3f": {
+        "mnemonic": "BBR3",
+        "mode": "relative"
+    },
+    "4f": {
+        "mnemonic": "BBR4",
+        "mode": "relative"
+    },
+    "5a": {
+        "mnemonic": "PHY",
+        "mode": "implied"
+    },
+    "5f": {
+        "mnemonic": "BBR5",
+        "mode": "relative"
+    },
+    "6f": {
+        "mnemonic": "BBR6",
+        "mode": "relative"
+    },
+    "7a": {
+        "mnemonic": "PLY",
+        "mode": "implied"
+    },
+    "7c": {
+        "mnemonic": "JMP",
+        "mode": "absolute indexed indirect"
+    },
+    "7f": {
+        "mnemonic": "BBR7",
+        "mode": "relative"
+    },
+    "8f": {
+        "mnemonic": "BBS0",
+        "mode": "relative"
+    },
+    "9c": {
+        "mnemonic": "STZ",
+        "mode": "absolute"
+    },
+    "9e": {
+        "mnemonic": "STZ",
+        "mode": "absolute, X-indexed"
+    },
+    "9f": {
+        "mnemonic": "BBS1",
+        "mode": "relative"
+    },
+    "a7": {
+        "mnemonic": "SMB2",
+        "mode": "zero-page"
+    },
+    "af": {
+        "mnemonic": "BBS2",
+        "mode": "relative"
+    },
+    "b2": {
+        "mnemonic": "LDA",
+        "mode": "zero-page indirect"
+    },
+    "b7": {
+        "mnemonic": "SMB3",
+        "mode": "zero-page"
+    },
+    "bf": {
+        "mnemonic": "BBS3",
+        "mode": "relative"
+    },
+    "c7": {
+        "mnemonic": "SMB4",
+        "mode": "zero-page"
+    },
+    "cb": {
+        "mnemonic": "WAI",
+        "mode": "implied"
+    },
+    "cf": {
+        "mnemonic": "BBS4",
+        "mode": "relative"
+    },
+    "d2": {
+        "mnemonic": "CMP",
+        "mode": "zero-page indirect"
+    },
+    "d7": {
+        "mnemonic": "SMB5",
+        "mode": "zero-page"
+    },
+    "da": {
+        "mnemonic": "PHX",
+        "mode": "implied"
+    },
+    "db": {
+        "mnemonic": "STP",
+        "mode": "implied"
+    },
+    "df": {
+        "mnemonic": "BBS5",
+        "mode": "relative"
+    },
+    "e7": {
+        "mnemonic": "SMB6",
+        "mode": "zero-page"
+    },
+    "ef": {
+        "mnemonic": "BBS6",
+        "mode": "relative"
+    },
+    "f2": {
+        "mnemonic": "SBC",
+        "mode": "zero-page indirect"
+    },
+    "f7": {
+        "mnemonic": "SMB7",
+        "mode": "zero-page"
+    },
+    "fa": {
+        "mnemonic": "PLX",
+        "mode": "implied"
+    },
+    "ff": {
+        "mnemonic": "BBS7",
+        "mode": "relative"
     }
 }
\ No newline at end of file
diff --git a/runtime.ts b/runtime.ts
index 2759b6e..eedcd70 100644
--- a/runtime.ts
+++ b/runtime.ts
@@ -1,18 +1,9 @@
 import The65c02, { BitField, Pin } from "./65c02.ts";
-// import { instructionIds } from "./instructions.ts";
-import opcodeMatrix from "./opcode_matrix.json" with { type: "json" };
-
-function instruction(name: string | TemplateStringsArray, mode: string = 'implied'): number {
-    const goog = (Object.entries(opcodeMatrix).find(([_, v]) =>
-        v.mnemonic == name && v.mode == mode) ?? [])[0];
-    if (!goog)
-        throw `unknown instruction (${name}-${mode})`
-    return parseInt(goog, 16)
-}
 
 // the thing used for ram
 const ram = new Uint8Array(2**16);
 
+// initiate the emulator
 const cpu = new The65c02(function (this: The65c02) {
     // since this is controlled by the user it's easy
     // to map things into address space
@@ -26,24 +17,15 @@ await cpu.loadInstructions()
 
 // mem address $0000
 ram[0xFFFC] = 0x00
-ram[0xFFFD] = 0x01
+ram[0xFFFD] = 0x80
 
-//TODO: read code from file
-// const code = [
-//     // nop
-//     instruction`CLC`,
-//     // instruction`CLD`,
-//     instruction('INC', 'zero-page'),
-//     0x21,
-//     instruction`BRK`,
-// ]
-
-const code = Deno.readFileSync('a.out')
+// read code from file
+const code = Deno.readFileSync('msbasic/tmp/eater.bin')
 
 // write code to ram before execution
 for (let offset = 0; offset < code.length; offset++) {
     const byte = code[offset];
-    ram[256 + offset] = byte;
+    ram[0x8000 + offset] = byte;
 }
 
 // pull RESB low to reset the 65c02
@@ -55,8 +37,11 @@ cpu.io.reset.HI()
 
 const debug = Deno.args.includes('-d')
 
+// repeat until the cpu requests an interrupt
 while (!cpu.io.interruptRequest.high) {
     cpu.cycle();
+
+    // debug step-by-step mode
     if (debug) {
         const i = new Uint8Array(8);
         await Deno.stdin.read(i);
@@ -84,6 +69,6 @@ console.log(` Y: ${cpu.regY.bits.map(k=>+k).join('')} (0x${cpu.regY.num().toStri
 
 console.debug('\nRAM:')
 Deno.writeFileSync('ram.bin', ram)
-new Deno.Command('hexdump', {
-    args: ['-C', 'ram.bin']
-}).spawn()
+// new Deno.Command('hexdump', {
+//     args: ['-C', 'ram.bin']
+// }).spawn()