diff options
Diffstat (limited to 'instructions')
-rw-r--r-- | instructions/ADC.ts | 10 | ||||
-rw-r--r-- | instructions/AND.ts | 11 | ||||
-rw-r--r-- | instructions/ASL.ts | 21 | ||||
-rw-r--r-- | instructions/BCC.ts | 7 | ||||
-rw-r--r-- | instructions/BCS.ts | 7 | ||||
-rw-r--r-- | instructions/BEQ.ts | 7 |
6 files changed, 59 insertions, 4 deletions
diff --git a/instructions/ADC.ts b/instructions/ADC.ts index c8163d0..5e00f15 100644 --- a/instructions/ADC.ts +++ b/instructions/ADC.ts @@ -1,9 +1,11 @@ import type The65c02 from "../65c02.ts"; export default function (this: The65c02, mode: string) { - const addr = this.getAddr(mode); + const addr = this.getAddr(mode) this.io.address.set(addr); - this.read(); - this.flagZN(this.io.data.num()) - this.regA.set(this.io.data.num()) + this.read() + const mem = this.io.data.num(); + const result = this.regA.num() + mem + this.flagZCN(result); + this.regA.set(result & 0xFF); } \ No newline at end of file diff --git a/instructions/AND.ts b/instructions/AND.ts new file mode 100644 index 0000000..bf44a66 --- /dev/null +++ b/instructions/AND.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 + this.flagZCN(result); + this.regA.set(result & 0xFF); +} \ No newline at end of file diff --git a/instructions/ASL.ts b/instructions/ASL.ts new file mode 100644 index 0000000..1f3fcbb --- /dev/null +++ b/instructions/ASL.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.negative = (mem & 128) != 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.negative = (mem & 128) != 0 + this.carry = (mem & 256) != 0 + this.io.data.set(result & 0xFF); + this.write() + } +} \ No newline at end of file diff --git a/instructions/BCC.ts b/instructions/BCC.ts new file mode 100644 index 0000000..f2d8cc3 --- /dev/null +++ b/instructions/BCC.ts @@ -0,0 +1,7 @@ +import type The65c02 from "../65c02.ts"; + +export default function (this: The65c02, mode: string) { + const location = this.getAddr(mode, ['relative', 'absolute']); + if (!this.carry) + this.programCounter.set(location) +} \ No newline at end of file diff --git a/instructions/BCS.ts b/instructions/BCS.ts new file mode 100644 index 0000000..6d7d984 --- /dev/null +++ b/instructions/BCS.ts @@ -0,0 +1,7 @@ +import type The65c02 from "../65c02.ts"; + +export default function (this: The65c02, mode: string) { + const location = this.getAddr(mode, ['relative', 'absolute']); + if (this.carry) + this.programCounter.set(location) +} \ No newline at end of file diff --git a/instructions/BEQ.ts b/instructions/BEQ.ts new file mode 100644 index 0000000..d91aa63 --- /dev/null +++ b/instructions/BEQ.ts @@ -0,0 +1,7 @@ +import type The65c02 from "../65c02.ts"; + +export default function (this: The65c02, mode: string) { + const location = this.getAddr(mode, ['relative', 'absolute']); + if (this.zero) + this.programCounter.set(location) +} \ No newline at end of file |