aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin')
-rw-r--r--src/main/kotlin/cpu/Cpu.kt23
-rw-r--r--src/main/kotlin/cpu/opcodes/Misc.kt20
2 files changed, 26 insertions, 17 deletions
diff --git a/src/main/kotlin/cpu/Cpu.kt b/src/main/kotlin/cpu/Cpu.kt
index 3180aeb..ad006d9 100644
--- a/src/main/kotlin/cpu/Cpu.kt
+++ b/src/main/kotlin/cpu/Cpu.kt
@@ -8,15 +8,22 @@ class Cpu {
val registers = Registers()
val ram = Ram()
- var opcodes: Map<Int, Operation>
+ var standardOpcodes: Map<Int, Operation>
+ var extendedOpcodes: Map<Int, Operation>
init {
- val commandGroups: MutableMap<Int, Operation> = mutableMapOf()
- commandGroups.putAll(loads8Bit)
- commandGroups.putAll(loads16Bit)
- commandGroups.putAll(arithmetic8Bit)
- commandGroups.putAll(arithmetic16Bit)
- commandGroups.putAll(misc)
- opcodes = commandGroups.toMap()
+ val stdCommandGroup: MutableMap<Int, Operation> = mutableMapOf()
+ stdCommandGroup.putAll(loads8Bit)
+ stdCommandGroup.putAll(loads16Bit)
+ stdCommandGroup.putAll(arithmetic8Bit)
+ stdCommandGroup.putAll(arithmetic16Bit)
+ stdCommandGroup.putAll(misc)
+ standardOpcodes = stdCommandGroup.toMap()
+
+ val extCommandGroup: MutableMap<Int, Operation> = mutableMapOf()
+ extCommandGroup.putAll(miscExtended)
+ extendedOpcodes = extCommandGroup.toMap()
+
+
}
} \ No newline at end of file
diff --git a/src/main/kotlin/cpu/opcodes/Misc.kt b/src/main/kotlin/cpu/opcodes/Misc.kt
index 2b8f673..a72f6dc 100644
--- a/src/main/kotlin/cpu/opcodes/Misc.kt
+++ b/src/main/kotlin/cpu/opcodes/Misc.kt
@@ -7,15 +7,6 @@ import BitManipulation as bm
var misc = mapOf(
- 0x37 to Operation("SWAP A", 0, 8, {r, _, _ -> r.A = swap(r.A, r)}),
- 0x30 to Operation("SWAP B", 0, 8, {r, _, _ -> r.B = swap(r.B, r)}),
- 0x31 to Operation("SWAP C", 0, 8, {r, _, _ -> r.C = swap(r.C, r)}),
- 0x32 to Operation("SWAP D", 0, 8, {r, _, _ -> r.D = swap(r.D, r)}),
- 0x33 to Operation("SWAP E", 0, 8, {r, _, _ -> r.E = swap(r.E, r)}),
- 0x34 to Operation("SWAP H", 0, 8, {r, _, _ -> r.H = swap(r.H, r)}),
- 0x35 to Operation("SWAP L", 0, 8, {r, _, _ -> r.L = swap(r.L, r)}),
- 0x36 to Operation("SWAP (HL)", 0, 16, {r, m, _ -> m.writeByte(r.HL, swap(m.readByte(r.HL), r))}),
-
0x27 to Operation("DAA", 0, 4, {r, _, _ ->
// TODO
}),
@@ -48,6 +39,17 @@ var misc = mapOf(
)
+val miscExtended = mapOf(
+ 0x37 to Operation("SWAP A", 0, 8, {r, _, _ -> r.A = swap(r.A, r)}),
+ 0x30 to Operation("SWAP B", 0, 8, {r, _, _ -> r.B = swap(r.B, r)}),
+ 0x31 to Operation("SWAP C", 0, 8, {r, _, _ -> r.C = swap(r.C, r)}),
+ 0x32 to Operation("SWAP D", 0, 8, {r, _, _ -> r.D = swap(r.D, r)}),
+ 0x33 to Operation("SWAP E", 0, 8, {r, _, _ -> r.E = swap(r.E, r)}),
+ 0x34 to Operation("SWAP H", 0, 8, {r, _, _ -> r.H = swap(r.H, r)}),
+ 0x35 to Operation("SWAP L", 0, 8, {r, _, _ -> r.L = swap(r.L, r)}),
+ 0x36 to Operation("SWAP (HL)", 0, 16, {r, m, _ -> m.writeByte(r.HL, swap(m.readByte(r.HL), r))})
+)
+
private fun swap(n: Int, r: Registers): Int {