From 0424cc4e5b5aeffd56f680f36333a4a27fc43a76 Mon Sep 17 00:00:00 2001 From: WlodekM Date: Thu, 3 Apr 2025 09:56:21 +0300 Subject: start working on some 65c02 stuff --- 65c02.ts | 32 ++++++++++++++++++++++++++++++++ instructions/BRA.ts | 6 ++++++ 2 files changed, 38 insertions(+) create mode 100644 instructions/BRA.ts diff --git a/65c02.ts b/65c02.ts index fe17cb5..157e66c 100644 --- a/65c02.ts +++ b/65c02.ts @@ -190,11 +190,13 @@ export default class The65c02 { getZPAddr(): number { this.programCounter.increment() const zp = this.readPC().num() + this.programCounter.increment() return zp } getZPXAddr(): number { this.programCounter.increment() const zp = this.readPC().num() + this.programCounter.increment() return (this.regX.num() + zp) & 0xFF } getAbsoluteAddr(): number { @@ -225,6 +227,7 @@ export default class The65c02 { const lo_abit = this.readPC().num() this.io.address.set((this.regX.num() + addr + 1) & 0xFF) const hi_abit = this.readPC().num() + this.programCounter.increment() return ((hi_abit << 8) | lo_abit) } getIndirectYAddr(): number { @@ -234,8 +237,33 @@ export default class The65c02 { const lo_abit = this.readPC().num() this.io.address.set((addr + 1) & 0xFF) const hi_abit = this.readPC().num() + this.programCounter.increment() return ((hi_abit << 8) | lo_abit) + this.regY.num(); } + getZPI(): number { + this.programCounter.increment() + const addr = this.readPC().num() + this.io.address.set((addr) & 0xFF) + const lo_abit = this.readPC().num() + this.io.address.set((addr + 1) & 0xFF) + const hi_abit = this.readPC().num() + this.programCounter.increment() + return ((hi_abit << 8) | lo_abit); + } + getAbsIndexedIndirect(): number { + this.programCounter.increment() + let addr = this.readPC().num() + this.programCounter.increment() + addr |= this.readPC().num() << 8; + addr += this.regX.num(); + addr &= 0xFFFF + this.io.address.set((addr) & 0xFF) + const lo_abit = this.readPC().num() + this.io.address.set((addr + 1) & 0xFF) + const hi_abit = this.readPC().num() + this.programCounter.increment() + return ((hi_abit << 8) | lo_abit); + } getAddr(mode: string, allow?: string[]): number { if (allow && !allow.includes(mode)) throw 'disallowed mode' @@ -244,6 +272,10 @@ export default class The65c02 { this.programCounter.increment() this.programCounter.increment() return this.programCounter.num() - 1 + case 'zero-page indirect': + return this.getZPI() + case 'absolute indexed indirect': + return this.getAbsIndexedIndirect(); // deno-lint-ignore no-case-declarations case 'relative': this.programCounter.increment() diff --git a/instructions/BRA.ts b/instructions/BRA.ts new file mode 100644 index 0000000..11d32b8 --- /dev/null +++ b/instructions/BRA.ts @@ -0,0 +1,6 @@ +import type The65c02 from "../65c02.ts"; + +export default function (this: The65c02, mode: string) { + const location = this.getAddr(mode, ['relative', 'absolute']); + this.programCounter.set(location) +} \ No newline at end of file -- cgit 1.4.1-2-gfad0