diff options
Diffstat (limited to 'instructions/INC.ts')
-rw-r--r-- | instructions/INC.ts | 71 |
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 |