summary refs log tree commit diff
path: root/instructions/INC.ts
diff options
context:
space:
mode:
authorWlodekM <[email protected]>2025-04-02 12:24:10 +0300
committerWlodekM <[email protected]>2025-04-02 12:24:10 +0300
commitb9cd32d22d20f3fd5e44dd738d7e1bdbdeabc9e0 (patch)
treeaf89604aa85adbde67ba844686e035416446f7c8 /instructions/INC.ts
parent1027b91f357eaaa4793b9d16673b0ab662b37c7e (diff)
big update
Diffstat (limited to 'instructions/INC.ts')
-rw-r--r--instructions/INC.ts71
1 files changed, 71 insertions, 0 deletions
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