diff options
Diffstat (limited to 'src/main/kotlin/cpu')
| -rw-r--r-- | src/main/kotlin/cpu/Cpu.kt | 1 | ||||
| -rw-r--r-- | src/main/kotlin/cpu/opcodes/Restarts.kt | 27 |
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 |