summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--65c02.ts10
-rw-r--r--instructions/ADC.ts10
-rw-r--r--instructions/AND.ts11
-rw-r--r--instructions/ASL.ts21
-rw-r--r--instructions/BCC.ts7
-rw-r--r--instructions/BCS.ts7
-rw-r--r--instructions/BEQ.ts7
7 files changed, 68 insertions, 5 deletions
diff --git a/65c02.ts b/65c02.ts
index 96207a3..f3b0bd1 100644
--- a/65c02.ts
+++ b/65c02.ts
@@ -207,12 +207,20 @@ export default class The65c02 {
         const hi_abit = this.readPC().num()
         return ((hi_abit << 8) | lo_abit) + this.regY.num();
     }
-    getAddr(mode: string): number {
+    getAddr(mode: string, allow?: string[]): number {
+        if (allow && !allow.includes(mode))
+            throw 'disallowed mode'
         switch (mode) {
             case 'immediate':
                 this.programCounter.increment()
                 this.programCounter.increment()
                 return this.programCounter.num() - 1
+            // deno-lint-ignore no-case-declarations
+            case 'relative':
+                this.programCounter.increment()
+                const offset = this.readPC()
+                this.programCounter.increment()
+                return this.programCounter.num() + offset.num()
             case 'zero-page':
                 return this.getZPAddr()
             case 'zero-page, X-indexed':
diff --git a/instructions/ADC.ts b/instructions/ADC.ts
index c8163d0..5e00f15 100644
--- a/instructions/ADC.ts
+++ b/instructions/ADC.ts
@@ -1,9 +1,11 @@
 import type The65c02 from "../65c02.ts";
 
 export default function (this: The65c02, mode: string) {
-    const addr = this.getAddr(mode);
+    const addr = this.getAddr(mode)
     this.io.address.set(addr);
-    this.read();
-    this.flagZN(this.io.data.num())
-    this.regA.set(this.io.data.num())
+    this.read()
+    const mem = this.io.data.num();
+    const result = this.regA.num() + mem
+    this.flagZCN(result);
+    this.regA.set(result & 0xFF);
 }
\ No newline at end of file
diff --git a/instructions/AND.ts b/instructions/AND.ts
new file mode 100644
index 0000000..bf44a66
--- /dev/null
+++ b/instructions/AND.ts
@@ -0,0 +1,11 @@
+import type The65c02 from "../65c02.ts";
+
+export default function (this: The65c02, mode: string) {
+    const addr = this.getAddr(mode)
+    this.io.address.set(addr);
+    this.read()
+    const mem = this.io.data.num();
+    const result = this.regA.num() & mem
+    this.flagZCN(result);
+    this.regA.set(result & 0xFF);
+}
\ No newline at end of file
diff --git a/instructions/ASL.ts b/instructions/ASL.ts
new file mode 100644
index 0000000..1f3fcbb
--- /dev/null
+++ b/instructions/ASL.ts
@@ -0,0 +1,21 @@
+import type The65c02 from "../65c02.ts";
+
+export default function (this: The65c02, mode: string) {
+    if (mode == 'implicit') {
+        const mem = this.regA.num();
+        const result = mem << 1;
+        this.negative = (mem & 128) != 0
+        this.carry = (mem & 256) != 0
+        this.regA.set(result & 0xFF);
+    } else {
+        const addr = this.getAddr(mode)
+        this.io.address.set(addr);
+        this.read()
+        const mem = this.io.data.num();
+        const result = mem << 1;
+        this.negative = (mem & 128) != 0
+        this.carry = (mem & 256) != 0
+        this.io.data.set(result & 0xFF);
+        this.write()
+    }
+}
\ No newline at end of file
diff --git a/instructions/BCC.ts b/instructions/BCC.ts
new file mode 100644
index 0000000..f2d8cc3
--- /dev/null
+++ b/instructions/BCC.ts
@@ -0,0 +1,7 @@
+import type The65c02 from "../65c02.ts";
+
+export default function (this: The65c02, mode: string) {
+    const location = this.getAddr(mode, ['relative', 'absolute']);
+    if (!this.carry)
+        this.programCounter.set(location)
+}
\ No newline at end of file
diff --git a/instructions/BCS.ts b/instructions/BCS.ts
new file mode 100644
index 0000000..6d7d984
--- /dev/null
+++ b/instructions/BCS.ts
@@ -0,0 +1,7 @@
+import type The65c02 from "../65c02.ts";
+
+export default function (this: The65c02, mode: string) {
+    const location = this.getAddr(mode, ['relative', 'absolute']);
+    if (this.carry)
+        this.programCounter.set(location)
+}
\ No newline at end of file
diff --git a/instructions/BEQ.ts b/instructions/BEQ.ts
new file mode 100644
index 0000000..d91aa63
--- /dev/null
+++ b/instructions/BEQ.ts
@@ -0,0 +1,7 @@
+import type The65c02 from "../65c02.ts";
+
+export default function (this: The65c02, mode: string) {
+    const location = this.getAddr(mode, ['relative', 'absolute']);
+    if (this.zero)
+        this.programCounter.set(location)
+}
\ No newline at end of file