diff options
| author | James Barnett <noreply@jamesbarnett.xyz> | 2018-07-16 22:18:02 +0100 |
|---|---|---|
| committer | James Barnett <noreply@jamesbarnett.xyz> | 2018-07-16 22:18:02 +0100 |
| commit | 377d5637f618a11b0fca2d37063caa4c2284f85e (patch) | |
| tree | 93d035b7f97995a2c657de576f99f32b604a7e98 /src/main/kotlin/cpu/opcodes/Restarts.kt | |
| parent | a6e35c04ce8a37e78702997977c95e1d1bafb932 (diff) | |
| download | KGB-377d5637f618a11b0fca2d37063caa4c2284f85e.tar.xz KGB-377d5637f618a11b0fca2d37063caa4c2284f85e.zip | |
Add RST ops
Diffstat (limited to 'src/main/kotlin/cpu/opcodes/Restarts.kt')
| -rw-r--r-- | src/main/kotlin/cpu/opcodes/Restarts.kt | 27 |
1 files changed, 27 insertions, 0 deletions
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 |