summary refs log tree commit diff
path: root/instructions
diff options
context:
space:
mode:
Diffstat (limited to 'instructions')
-rw-r--r--instructions/ADC.ts9
-rw-r--r--instructions/BRK.ts22
-rw-r--r--instructions/CLC.ts13
-rw-r--r--instructions/INC.ts71
-rw-r--r--instructions/INX.ts15
-rw-r--r--instructions/INY.ts15
-rw-r--r--instructions/LDA.ts9
7 files changed, 154 insertions, 0 deletions
diff --git a/instructions/ADC.ts b/instructions/ADC.ts
new file mode 100644
index 0000000..c8163d0
--- /dev/null
+++ b/instructions/ADC.ts
@@ -0,0 +1,9 @@
+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();
+    this.flagZN(this.io.data.num())
+    this.regA.set(this.io.data.num())
+}
\ No newline at end of file
diff --git a/instructions/BRK.ts b/instructions/BRK.ts
new file mode 100644
index 0000000..99e4072
--- /dev/null
+++ b/instructions/BRK.ts
@@ -0,0 +1,22 @@
+import type The65c02 from "../65c02.ts";
+
+export default function (this: The65c02, mode: string) {
+    switch (mode) {
+        case 'implied':
+            this.io.interruptRequest.HI()
+            //TODO: push shit onto stack
+            this.io.data.set(this.programCounter.num() & 0x00FF)
+            this.io.address.set(0xFFFF)
+            this.write()
+            this.io.data.set(this.programCounter.num() & 0xFF00)
+            this.io.address.set(0xFFFE)
+            this.write()
+            this.BRK = true
+            this.programCounter.increment();
+            this.programCounter.increment();
+            break;
+    
+        default:
+            throw 'wha';
+    }
+}
\ No newline at end of file
diff --git a/instructions/CLC.ts b/instructions/CLC.ts
new file mode 100644
index 0000000..d14b2f4
--- /dev/null
+++ b/instructions/CLC.ts
@@ -0,0 +1,13 @@
+import type The65c02 from "../65c02.ts";
+
+export default function (this: The65c02, mode: string) {
+    switch (mode) {
+        case 'implied':
+            this.carry = false;
+            this.programCounter.increment();
+            break;
+    
+        default:
+            throw 'wha';
+    }
+}
\ No newline at end of file
diff --git a/instructions/INC.ts b/instructions/INC.ts
new file mode 100644
index 0000000..971abd3
--- /dev/null
+++ b/instructions/INC.ts
@@ -0,0 +1,71 @@
+// deno-lint-ignore-file no-case-declarations
+import type The65c02 from "../65c02.ts";
+
+export default function (this: The65c02, mode: string) {
+    switch (mode) {
+        case 'zero-page':
+            // set PC to where the ZP address is
+            this.programCounter.increment()
+            const zpa = this.readPC()
+            this.io.address.set(zpa.num());
+            this.read();
+            let v = this.io.data.num();
+            v++
+            v &= 0xFF
+            this.io.data.set(v)
+            this.write()
+            this.flagZN(v)
+            this.programCounter.increment()
+            break;
+        
+        case 'zero-page, X-indexed':
+            // set PC to where the ZP address is
+            this.programCounter.increment()
+            const zpax = this.readPC()
+            this.io.address.set(zpax.num() + this.regX.num());
+            this.read();
+            let vzx = this.io.data.num();
+            vzx++
+            vzx &= 0xFF
+            this.io.data.set(vzx)
+            this.write()
+            this.flagZN(vzx)
+            this.programCounter.increment()
+            break;
+        
+        case 'absolute':
+            // skip over the opcode
+            this.programCounter.increment()
+            const lo_abit = this.readPC().num()
+            this.programCounter.increment()
+            const hi_abit = this.readPC().num()
+            this.io.address.set((hi_abit << 8) | lo_abit)
+            this.read()
+            let va = this.io.data.num();
+            va++
+            va &= 0xFF
+            this.io.data.set(va)
+            this.write()
+            this.programCounter.increment()
+            break;
+        
+        case 'absolute, X-indexed':
+            // skip over the opcode
+            this.programCounter.increment()
+            const lo_axbit = this.readPC().num()
+            this.programCounter.increment()
+            const hi_axbit = this.readPC().num()
+            this.io.address.set(((hi_axbit << 8) | lo_axbit) + this.regX.num())
+            this.read()
+            let vax = this.io.data.num();
+            vax++
+            vax &= 0xFF
+            this.io.data.set(vax)
+            this.write()
+            this.programCounter.increment()
+            break;
+    
+        default:
+            throw 'wha';
+    }
+}
\ No newline at end of file
diff --git a/instructions/INX.ts b/instructions/INX.ts
new file mode 100644
index 0000000..9c1cc1b
--- /dev/null
+++ b/instructions/INX.ts
@@ -0,0 +1,15 @@
+import type The65c02 from "../65c02.ts";
+
+export default function (this: The65c02, mode: string) {
+    switch (mode) {
+        case 'implied':
+            this.regX.increment()
+            this.negative = this.regX.bit(7);
+            this.zero = this.regX.num() == 0;
+            this.programCounter.increment();
+            break;
+    
+        default:
+            throw 'wha';
+    }
+}
\ No newline at end of file
diff --git a/instructions/INY.ts b/instructions/INY.ts
new file mode 100644
index 0000000..566c6d4
--- /dev/null
+++ b/instructions/INY.ts
@@ -0,0 +1,15 @@
+import type The65c02 from "../65c02.ts";
+
+export default function (this: The65c02, mode: string) {
+    switch (mode) {
+        case 'implied':
+            this.regY.increment()
+            this.negative = this.regY.bit(7);
+            this.zero = this.regY.num() == 0;
+            this.programCounter.increment();
+            break;
+    
+        default:
+            throw 'wha';
+    }
+}
\ No newline at end of file
diff --git a/instructions/LDA.ts b/instructions/LDA.ts
new file mode 100644
index 0000000..c8163d0
--- /dev/null
+++ b/instructions/LDA.ts
@@ -0,0 +1,9 @@
+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();
+    this.flagZN(this.io.data.num())
+    this.regA.set(this.io.data.num())
+}
\ No newline at end of file