From e6f0c80ca0a5cdac7d9a2b0dadde1d200712c66d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com> Date: Wed, 29 Jun 2022 10:46:13 +0100 Subject: [PATCH] feat: new jump opcode --- src/cpu.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/cpu.rs b/src/cpu.rs index 02f7d692..6ea093ba 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -46,7 +46,7 @@ pub const INSTRUCTIONS: [(fn(&mut Cpu), u8, &'static str); 256] = [ (nop, 4, "! UNIMP !"), (nop, 4, "! UNIMP !"), (nop, 4, "! UNIMP !"), - (nop, 4, "! UNIMP !"), + (jr_z_i8, 8, "JR Z, i8"), (nop, 4, "! UNIMP !"), (nop, 4, "! UNIMP !"), (nop, 4, "! UNIMP !"), @@ -816,6 +816,17 @@ fn inc_hl(cpu: &mut Cpu) { cpu.set_hl(cpu.hl().wrapping_add(1)); } +fn jr_z_i8(cpu: &mut Cpu) { + let byte = cpu.read_u8() as i8; + + if !cpu.get_zero() { + return; + } + + cpu.pc = (cpu.pc as i16).wrapping_add(byte as i16) as u16; + cpu.ticks = cpu.ticks.wrapping_add(4); +} + fn ld_sp_u16(cpu: &mut Cpu) { cpu.sp = cpu.read_u16(); } -- GitLab