summary refs log tree commit diff
path: root/65c02.ts
diff options
context:
space:
mode:
Diffstat (limited to '65c02.ts')
-rw-r--r--65c02.ts17
1 files changed, 17 insertions, 0 deletions
diff --git a/65c02.ts b/65c02.ts
index f3b0bd1..2f9a978 100644
--- a/65c02.ts
+++ b/65c02.ts
@@ -158,6 +158,23 @@ export default class The65c02 {
         this.instructions[opm[instruction].mnemonic].call(this, opm[instruction].mode);
     }
     //SECTION - utils
+    /** push stuff onto stack */
+    push(val: number) {
+        if (this.stackPointer.num() >= 0xFF)
+            throw 'stack overflow (no, not like the website)';
+        this.stackPointer.increment();
+        this.io.address.set(0x01FF - this.stackPointer.num());
+        this.io.data.set(val);
+        this.write();
+    }
+    pop(): number {
+        if (this.stackPointer.num() <= 0)
+            throw 'stack underflow';
+        this.io.address.set(0x01FF - this.stackPointer.num());
+        this.read()
+        this.stackPointer.decrement();
+        return this.io.data.num()
+    }
     getZPAddr(): number {
         this.programCounter.increment()
         const zp = this.readPC().num()