aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin')
-rw-r--r--src/main/kotlin/cpu/Registers.kt7
-rw-r--r--src/main/kotlin/cpu/opcodes/Loads16Bit.kt40
2 files changed, 47 insertions, 0 deletions
diff --git a/src/main/kotlin/cpu/Registers.kt b/src/main/kotlin/cpu/Registers.kt
index 6d1e626..5f45e87 100644
--- a/src/main/kotlin/cpu/Registers.kt
+++ b/src/main/kotlin/cpu/Registers.kt
@@ -115,5 +115,12 @@ class Registers {
return currentHL
}
+ fun decrementAndGetSP(): Int {
+ return if(SP > 0x0000) {
+ --SP
+ } else {
+ SP
+ }
+ }
} \ No newline at end of file
diff --git a/src/main/kotlin/cpu/opcodes/Loads16Bit.kt b/src/main/kotlin/cpu/opcodes/Loads16Bit.kt
new file mode 100644
index 0000000..6c915cf
--- /dev/null
+++ b/src/main/kotlin/cpu/opcodes/Loads16Bit.kt
@@ -0,0 +1,40 @@
+package cpu.opcodes
+
+import cpu.Operation
+import BitManipulation as bm
+
+// 8-Bit Loads
+var loads16Bit = mapOf(
+
+ 0x01 to Operation("LD BC,nn", 2, 12, {r, _, a -> r.BC = bm.argsToWord(a)}),
+ 0x11 to Operation("LD DE,nn", 2, 12, {r, _, a -> r.DE = bm.argsToWord(a)}),
+ 0x21 to Operation("LD HL,nn", 2, 12, {r, _, a -> r.HL = bm.argsToWord(a)}),
+ 0x31 to Operation("LD SP,nn", 2, 12, {r, _, a -> r.SP = bm.argsToWord(a)}),
+
+ 0xF9 to Operation("LD SP,HL", 0, 8, {r, _, _ -> r.SP = r.HL}),
+
+ 0xF8 to Operation("LDHL SP,n", 1, 12, {r, _, a -> r.HL = (r.SP + a[0])}), // TODO - not sure what the flags should be here
+ 0x08 to Operation("LD (nn),SP", 2, 20, {r, m, a ->
+ m.writeByte(bm.argsToWord(a), bm.getLsb(r.SP))
+ m.writeByte(bm.argsToWord(a) + 1, bm.getMsb(r.SP))
+ // TODO - not sure if the lsb/msb order is right here
+ }),
+
+ 0xF5 to Operation("PUSH AF", 0, 16, {r, m, _ ->
+ m.writeByte(r.decrementAndGetSP(), bm.getMsb(r.AF))
+ m.writeByte(r.decrementAndGetSP(), bm.getLsb(r.AF))
+ }),
+ 0xC5 to Operation("PUSH BC", 0, 16, {r, m, _ ->
+ m.writeByte(r.decrementAndGetSP(), bm.getMsb(r.BC))
+ m.writeByte(r.decrementAndGetSP(), bm.getLsb(r.BC))
+ }),
+ 0xD5 to Operation("PUSH DE", 0, 16, {r, m, _ ->
+ m.writeByte(r.decrementAndGetSP(), bm.getMsb(r.DE))
+ m.writeByte(r.decrementAndGetSP(), bm.getLsb(r.DE))
+ }),
+ 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))
+ })
+
+)