diff options
| author | James Barnett <noreply@jamesbarnett.xyz> | 2018-06-27 21:56:05 +0100 |
|---|---|---|
| committer | James Barnett <noreply@jamesbarnett.xyz> | 2018-06-27 21:56:05 +0100 |
| commit | 6f87feb0c835589adcd566323e058a9158860071 (patch) | |
| tree | 2ccfd21db561892d6b1ec1d3209f0dc72a00151b /src/main/kotlin/cpu/opcodes/Loads16Bit.kt | |
| parent | 155c200400ac80be1113e35df6637e2f77296d1a (diff) | |
| download | KGB-6f87feb0c835589adcd566323e058a9158860071.tar.xz KGB-6f87feb0c835589adcd566323e058a9158860071.zip | |
Add 16-Bit pop commands
Diffstat (limited to 'src/main/kotlin/cpu/opcodes/Loads16Bit.kt')
| -rw-r--r-- | src/main/kotlin/cpu/opcodes/Loads16Bit.kt | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/main/kotlin/cpu/opcodes/Loads16Bit.kt b/src/main/kotlin/cpu/opcodes/Loads16Bit.kt index 6c915cf..671a02d 100644 --- a/src/main/kotlin/cpu/opcodes/Loads16Bit.kt +++ b/src/main/kotlin/cpu/opcodes/Loads16Bit.kt @@ -1,6 +1,8 @@ package cpu.opcodes import cpu.Operation +import cpu.Registers +import ram.Ram import BitManipulation as bm // 8-Bit Loads @@ -35,6 +37,17 @@ var loads16Bit = mapOf( 0xE5 to Operation("PUSH HL", 0, 16, {r, m, _ -> m.writeByte(r.decrementAndGetSP(), bm.getMsb(r.HL)) m.writeByte(r.decrementAndGetSP(), bm.getLsb(r.HL)) - }) + }), + + 0xF1 to Operation("POP AF", 0, 12, {r, m, _ -> r.AF = pop(r, m)}), + 0xC1 to Operation("POP BC", 0, 12, {r, m, _ -> r.BC = pop(r, m)}), + 0xD1 to Operation("POP DE", 0, 12, {r, m, _ -> r.DE = pop(r, m)}), + 0xE1 to Operation("POP HL", 0, 12, {r, m, _ -> r.HL = pop(r, m)}) ) + +fun pop(r: Registers, m: Ram): Int { + val lsb = m.readByte(r.getAndIncrementSP()) + val msb = m.readByte(r.getAndIncrementSP()) + return bm.bytesToWord(msb, lsb) +} |