From ae3bb9819aad653d6a2ed972000e3c3696e39bf1 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Mon, 16 Jul 2018 21:27:33 +0100 Subject: Implement JUMP ops --- src/main/kotlin/cpu/opcodes/Arithmetic16Bit.kt | 2 +- src/main/kotlin/cpu/opcodes/Jumps.kt | 22 ++++++++++++++++++++++ src/main/kotlin/cpu/opcodes/Loads16Bit.kt | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/cpu/opcodes/Jumps.kt (limited to 'src/main/kotlin/cpu/opcodes') diff --git a/src/main/kotlin/cpu/opcodes/Arithmetic16Bit.kt b/src/main/kotlin/cpu/opcodes/Arithmetic16Bit.kt index 0c2c9cb..0eff88a 100644 --- a/src/main/kotlin/cpu/opcodes/Arithmetic16Bit.kt +++ b/src/main/kotlin/cpu/opcodes/Arithmetic16Bit.kt @@ -17,7 +17,7 @@ var arithmetic16Bit = mapOf( val absoluteValue = bm.getAbsoluteValue(a[0]) - if (bm.isSignedBitNegative(a[0])) { + if (bm.isSignedByteNegative(a[0])) { r.setFlagFromBool(Flag.HALF_CARRY, r.SP and 0x0F < absoluteValue and 0x0F) r.setFlagFromBool(Flag.CARRY,r.SP and 0xFF < absoluteValue) r.SP = r.SP - absoluteValue diff --git a/src/main/kotlin/cpu/opcodes/Jumps.kt b/src/main/kotlin/cpu/opcodes/Jumps.kt new file mode 100644 index 0000000..6e0ea3e --- /dev/null +++ b/src/main/kotlin/cpu/opcodes/Jumps.kt @@ -0,0 +1,22 @@ +package cpu.opcodes + +import cpu.Operation +import cpu.Registers.Flag +import BitManipulation as bm + +val jumps = mapOf( + + 0xC3 to Operation("JP nn", 2, 12, {r, _, a -> r.PC = bm.argsToWord(a)}), + 0xC2 to Operation("JP NZ,nn", 2, 12, {r, _, a -> if(r.getFlag(Flag.ZERO) == 0) r.PC = bm.argsToWord(a)}), + 0xCA to Operation("JP Z,nn", 2, 12, {r, _, a -> if(r.getFlag(Flag.ZERO) == 1) r.PC = bm.argsToWord(a)}), + 0xD2 to Operation("JP NC,nn", 2, 12, {r, _, a -> if(r.getFlag(Flag.CARRY) == 0) r.PC = bm.argsToWord(a)}), + 0xDA to Operation("JP C,nn", 2, 12, {r, _, a -> if(r.getFlag(Flag.CARRY) == 1) r.PC = bm.argsToWord(a)}), + 0xE9 to Operation("JP (HL)", 0, 4, {r, m, _ -> r.PC = m.readByte(r.HL)}), + + 0x18 to Operation("JR n", 1, 8, {r, _, a -> r.addSignedByteToPC(a[0])}), + 0x20 to Operation("JR NZ,n", 1, 8, {r, _, a -> if(r.getFlag(Flag.ZERO) == 0) r.addSignedByteToPC(a[0])}), + 0x28 to Operation("JR Z,n", 1, 8, {r, _, a -> if(r.getFlag(Flag.ZERO) == 1) r.addSignedByteToPC(a[0])}), + 0x30 to Operation("JR NC,n", 1, 8, {r, _, a -> if(r.getFlag(Flag.CARRY) == 0) r.addSignedByteToPC(a[0])}), + 0x38 to Operation("JR C,n", 1, 8, {r, _, a -> if(r.getFlag(Flag.CARRY) == 1) r.addSignedByteToPC(a[0])}) + +) \ No newline at end of file diff --git a/src/main/kotlin/cpu/opcodes/Loads16Bit.kt b/src/main/kotlin/cpu/opcodes/Loads16Bit.kt index 134b3a9..2f679c3 100644 --- a/src/main/kotlin/cpu/opcodes/Loads16Bit.kt +++ b/src/main/kotlin/cpu/opcodes/Loads16Bit.kt @@ -24,7 +24,7 @@ var loads16Bit = mapOf( val absoluteValue = bm.getAbsoluteValue(a[0]) - if (bm.isSignedBitNegative(a[0])) { + if (bm.isSignedByteNegative(a[0])) { r.setFlagFromBool(Flag.HALF_CARRY, r.SP and 0x0F < absoluteValue and 0x0F) r.setFlagFromBool(Flag.CARRY,r.SP and 0xFF < absoluteValue) r.HL = r.SP - absoluteValue -- cgit v1.2.3