summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--65c02.ts15
-rw-r--r--instructions/TAX.ts6
-rw-r--r--instructions/TAY.ts6
-rw-r--r--instructions/TSX.ts6
-rw-r--r--instructions/TXA.ts6
-rw-r--r--instructions/TXS.ts6
-rw-r--r--instructions/TYA.ts6
-rw-r--r--runtime.ts14
8 files changed, 53 insertions, 12 deletions
diff --git a/65c02.ts b/65c02.ts
index 4329664..fe17cb5 100644
--- a/65c02.ts
+++ b/65c02.ts
@@ -12,8 +12,6 @@ export class BitField {
         this.bits[bit] = value;
     }
     set(value: number) {
-        // if (this.num() == 259 && value == 0)
-        //     throw new Error('debug')
         for (let bit = 0; bit < this.bits.length; bit++) {
             const mask: number = 1 << bit;
             this.setBit(bit, (value & mask) != 0)
@@ -41,7 +39,6 @@ export class Register<T=number> extends BitField {
         this.set(value)
     }
     increment(): number {
-        console.log('inc', this.num(), '->', this.num() + 1)
         this.set(this.num() + 1);
         return this.num()
     }
@@ -94,10 +91,14 @@ export class IO {
 export default class The65c02 {
     io:                    IO = new IO();
     //SECTION - register
-    programCounter:  Register<16> = new Register(16);
-    regA:            Register<8>  = new Register(8);
-    regX:            Register<8>  = new Register(8);
-    regY:            Register<8>  = new Register(8);
+    programCounter:      Register<16> = new Register(16);
+    private registerA:    Register<8> = new Register(8);
+    private registerX:    Register<8> = new Register(8);
+    private registerY:    Register<8> = new Register(8);
+
+    get regA () { return this.registerA }
+    get regX () { return this.registerX }
+    get regY () { return this.registerY }
 
     stackPointer:    Register<8>  = new Register(8);
     status:          Register<8>  = new Register(8);
diff --git a/instructions/TAX.ts b/instructions/TAX.ts
new file mode 100644
index 0000000..7fcc14f
--- /dev/null
+++ b/instructions/TAX.ts
@@ -0,0 +1,6 @@
+import type The65c02 from "../65c02.ts";
+
+export default function (this: The65c02) {
+    this.programCounter.increment()
+    this.regX.set(this.regA.num())
+}
\ No newline at end of file
diff --git a/instructions/TAY.ts b/instructions/TAY.ts
new file mode 100644
index 0000000..e9cec13
--- /dev/null
+++ b/instructions/TAY.ts
@@ -0,0 +1,6 @@
+import type The65c02 from "../65c02.ts";
+
+export default function (this: The65c02) {
+    this.programCounter.increment()
+    this.regY.set(this.regA.num())
+}
\ No newline at end of file
diff --git a/instructions/TSX.ts b/instructions/TSX.ts
new file mode 100644
index 0000000..d2fc4d3
--- /dev/null
+++ b/instructions/TSX.ts
@@ -0,0 +1,6 @@
+import type The65c02 from "../65c02.ts";
+
+export default function (this: The65c02) {
+    this.programCounter.increment()
+    this.regX.set(this.stackPointer.num())
+}
\ No newline at end of file
diff --git a/instructions/TXA.ts b/instructions/TXA.ts
new file mode 100644
index 0000000..abbdaaa
--- /dev/null
+++ b/instructions/TXA.ts
@@ -0,0 +1,6 @@
+import type The65c02 from "../65c02.ts";
+
+export default function (this: The65c02) {
+    this.programCounter.increment()
+    this.regA.set(this.regX.num())
+}
\ No newline at end of file
diff --git a/instructions/TXS.ts b/instructions/TXS.ts
new file mode 100644
index 0000000..ce83b13
--- /dev/null
+++ b/instructions/TXS.ts
@@ -0,0 +1,6 @@
+import type The65c02 from "../65c02.ts";
+
+export default function (this: The65c02) {
+    this.programCounter.increment()
+    this.stackPointer.set(this.regX.num())
+}
\ No newline at end of file
diff --git a/instructions/TYA.ts b/instructions/TYA.ts
new file mode 100644
index 0000000..df6f8ca
--- /dev/null
+++ b/instructions/TYA.ts
@@ -0,0 +1,6 @@
+import type The65c02 from "../65c02.ts";
+
+export default function (this: The65c02) {
+    this.programCounter.increment()
+    this.regA.set(this.regY.num())
+}
\ No newline at end of file
diff --git a/runtime.ts b/runtime.ts
index d74e230..2759b6e 100644
--- a/runtime.ts
+++ b/runtime.ts
@@ -53,13 +53,17 @@ cpu.cycle()
 //the cpu reset, pull RESB high and start execution!
 cpu.io.reset.HI()
 
+const debug = Deno.args.includes('-d')
+
 while (!cpu.io.interruptRequest.high) {
     cpu.cycle();
-    const i = new Uint8Array(8);
-    await Deno.stdin.read(i);
-    if (i[0] == 'b'.charCodeAt(0)) {
-        console.log('BREAK!!')
-        break;
+    if (debug) {
+        const i = new Uint8Array(8);
+        await Deno.stdin.read(i);
+        if (i[0] == 'b'.charCodeAt(0)) {
+            console.log('BREAK!!')
+            break;
+        }
     }
 }