summary refs log tree commit diff
path: root/instructions
diff options
context:
space:
mode:
authorWlodekM <[email protected]>2025-04-02 21:12:13 +0300
committerWlodekM <[email protected]>2025-04-02 21:12:13 +0300
commitcec2dc2b9f2598cdf341627fe2ab91c37d637eac (patch)
tree4050ddb4a1413ac19cd352c752fd3ca43bd53a96 /instructions
parent2f63e169edb3ba1e95a33719c021e1bab9d9ac8c (diff)
yea
Diffstat (limited to 'instructions')
-rw-r--r--instructions/BRK.ts3
-rw-r--r--instructions/JSR.ts3
-rw-r--r--instructions/ROL.ts21
-rw-r--r--instructions/ROR.ts21
-rw-r--r--instructions/RTI.ts6
-rw-r--r--instructions/RTS.ts5
-rw-r--r--instructions/SBC.ts11
-rw-r--r--instructions/SEC.ts6
8 files changed, 75 insertions, 1 deletions
diff --git a/instructions/BRK.ts b/instructions/BRK.ts
index 99e4072..419eeef 100644
--- a/instructions/BRK.ts
+++ b/instructions/BRK.ts
@@ -5,6 +5,9 @@ export default function (this: The65c02, mode: string) {
         case 'implied':
             this.io.interruptRequest.HI()
             //TODO: push shit onto stack
+            this.push(this.programCounter.num() & 0x00FF)
+            this.push(this.programCounter.num() & 0xFF00)
+            this.push(this.status.num())
             this.io.data.set(this.programCounter.num() & 0x00FF)
             this.io.address.set(0xFFFF)
             this.write()
diff --git a/instructions/JSR.ts b/instructions/JSR.ts
index 59d95d8..5614d9b 100644
--- a/instructions/JSR.ts
+++ b/instructions/JSR.ts
@@ -2,6 +2,7 @@ import type The65c02 from "../65c02.ts";
 
 export default function (this: The65c02, mode: string) {
     const location = this.getAddr(mode, ['absolute']);
-    this.push(this.programCounter.num())
+    this.push(this.programCounter.num() & 0x00FF)
+    this.push(this.programCounter.num() & 0xFF00)
     this.programCounter.set(location)
 }
\ No newline at end of file
diff --git a/instructions/ROL.ts b/instructions/ROL.ts
new file mode 100644
index 0000000..c76ef8b
--- /dev/null
+++ b/instructions/ROL.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.carry;
+        this.negative = (result & 256) != 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.carry;
+        this.negative = (result & 256) != 0
+        this.carry = (mem & 256) != 0
+        this.io.data.set(result & 0xFF);
+        this.write()
+    }
+}
\ No newline at end of file
diff --git a/instructions/ROR.ts b/instructions/ROR.ts
new file mode 100644
index 0000000..7226604
--- /dev/null
+++ b/instructions/ROR.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.carry ? 128 : 0);
+        this.negative = (result & 256) != 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.carry ? 128 : 0);
+        this.negative = (result & 256) != 0
+        this.carry = (mem & 256) != 0
+        this.io.data.set(result & 0xFF);
+        this.write()
+    }
+}
\ No newline at end of file
diff --git a/instructions/RTI.ts b/instructions/RTI.ts
new file mode 100644
index 0000000..ab000b7
--- /dev/null
+++ b/instructions/RTI.ts
@@ -0,0 +1,6 @@
+import type The65c02 from "../65c02.ts";
+
+export default function (this: The65c02) {
+    this.status.set(this.pop())
+    this.programCounter.set(this.pop() | (this.pop() << 8))
+}
\ No newline at end of file
diff --git a/instructions/RTS.ts b/instructions/RTS.ts
new file mode 100644
index 0000000..483a441
--- /dev/null
+++ b/instructions/RTS.ts
@@ -0,0 +1,5 @@
+import type The65c02 from "../65c02.ts";
+
+export default function (this: The65c02) {
+    this.programCounter.set(this.pop() | (this.pop() << 8))
+}
\ No newline at end of file
diff --git a/instructions/SBC.ts b/instructions/SBC.ts
new file mode 100644
index 0000000..b6840fb
--- /dev/null
+++ b/instructions/SBC.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 - (1-+this.carry)
+    this.flagZCN(result);
+    this.regA.set(result & 0xFF);
+}
\ No newline at end of file
diff --git a/instructions/SEC.ts b/instructions/SEC.ts
new file mode 100644
index 0000000..7572500
--- /dev/null
+++ b/instructions/SEC.ts
@@ -0,0 +1,6 @@
+import type The65c02 from "../65c02.ts";
+
+export default function (this: The65c02) {
+    this.carry = true;
+    this.programCounter.increment();
+}
\ No newline at end of file