aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/cpu
diff options
context:
space:
mode:
authorJames Barnett <noreply@jamesbarnett.xyz>2018-07-16 22:18:02 +0100
committerJames Barnett <noreply@jamesbarnett.xyz>2018-07-16 22:18:02 +0100
commit377d5637f618a11b0fca2d37063caa4c2284f85e (patch)
tree93d035b7f97995a2c657de576f99f32b604a7e98 /src/main/kotlin/cpu
parenta6e35c04ce8a37e78702997977c95e1d1bafb932 (diff)
downloadKGB-377d5637f618a11b0fca2d37063caa4c2284f85e.tar.xz
KGB-377d5637f618a11b0fca2d37063caa4c2284f85e.zip
Add RST ops
Diffstat (limited to 'src/main/kotlin/cpu')
-rw-r--r--src/main/kotlin/cpu/Cpu.kt1
-rw-r--r--src/main/kotlin/cpu/opcodes/Restarts.kt27
2 files changed, 28 insertions, 0 deletions
diff --git a/src/main/kotlin/cpu/Cpu.kt b/src/main/kotlin/cpu/Cpu.kt
index 3336900..32fd39a 100644
--- a/src/main/kotlin/cpu/Cpu.kt
+++ b/src/main/kotlin/cpu/Cpu.kt
@@ -20,6 +20,7 @@ class Cpu {
stdCommandGroup.putAll(rotates)
stdCommandGroup.putAll(jumps)
stdCommandGroup.putAll(calls)
+ stdCommandGroup.putAll(restarts)
standardOpcodes = stdCommandGroup.toMap()
val extCommandGroup: MutableMap<Int, Operation> = mutableMapOf()
diff --git a/src/main/kotlin/cpu/opcodes/Restarts.kt b/src/main/kotlin/cpu/opcodes/Restarts.kt
new file mode 100644
index 0000000..606fb21
--- /dev/null
+++ b/src/main/kotlin/cpu/opcodes/Restarts.kt
@@ -0,0 +1,27 @@
+package cpu.opcodes
+
+import cpu.Operation
+import cpu.Registers
+import ram.Ram
+import BitManipulation as bm
+
+val restarts = mapOf(
+
+ 0xC7 to Operation("RST 00H", 0, 32, {r, m, _ -> restart(0x00, r, m)}),
+ 0xCF to Operation("RST 08H", 0, 32, {r, m, _ -> restart(0x08, r, m)}),
+ 0xD7 to Operation("RST 10H", 0, 32, {r, m, _ -> restart(0x10, r, m)}),
+ 0xDF to Operation("RST 18H", 0, 32, {r, m, _ -> restart(0x18, r, m)}),
+ 0xE7 to Operation("RST 20H", 0, 32, {r, m, _ -> restart(0x20, r, m)}),
+ 0xEF to Operation("RST 28H", 0, 32, {r, m, _ -> restart(0x28, r, m)}),
+ 0xF7 to Operation("RST 30H", 0, 32, {r, m, _ -> restart(0x30, r, m)}),
+ 0xFF to Operation("RST 38H", 0, 32, {r, m, _ -> restart(0x38, r, m)})
+
+)
+
+private fun restart(word: Int, r: Registers, m: Ram) {
+
+ m.writeByte(r.decrementAndGetSP(), bm.getMsb(r.PC))
+ m.writeByte(r.decrementAndGetSP(), bm.getLsb(r.PC))
+
+ r.PC = word
+} \ No newline at end of file