diff options
author | WlodekM <[email protected]> | 2025-04-02 19:36:18 +0300 |
---|---|---|
committer | WlodekM <[email protected]> | 2025-04-02 19:36:18 +0300 |
commit | bb861f7c074b11c9d379ec28aa91129ffae138bc (patch) | |
tree | 28ef2a410e060089f8d58d2505dfca53d6930f80 /65c02.ts | |
parent | fd0bd2a1901fca162db325829b9398cd7e780c2f (diff) |
stack
Diffstat (limited to '65c02.ts')
-rw-r--r-- | 65c02.ts | 17 |
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() |