From 501d93c37b3aa76da40418df006b880a3b4454fe Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Tue, 23 Mar 2021 18:21:59 -0500 Subject: [PATCH] chore: clean up code in one instruction --- src/instruction.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/instruction.rs b/src/instruction.rs index d2c42bf..fa8bad3 100644 --- a/src/instruction.rs +++ b/src/instruction.rs @@ -198,22 +198,18 @@ impl Instruction { } (LDTarget::Register(reg), LDTarget::ImmediateByte(n)) => { // LD r[y], n | Store n in Register + use InstrRegister::*; + match reg { - InstrRegister::IndirectHL => { + A | B | C | D | E | H | L => { + cpu.set_register(reg.to_register(), n); + Cycles::new(8) + } + IndirectHL => { let addr = cpu.register_pair(RegisterPair::HL); cpu.write_byte(addr, n); Cycles::new(12) } - InstrRegister::A - | InstrRegister::B - | InstrRegister::C - | InstrRegister::D - | InstrRegister::E - | InstrRegister::H - | InstrRegister::L => { - cpu.set_register(reg.to_register(), n); - Cycles::new(8) - } } } (LDTarget::IndirectC, LDTarget::Register(InstrRegister::A)) => { @@ -376,11 +372,14 @@ impl Instruction { let (cycles, sum) = match reg { B | C | D | E | H | L | A => { let value = cpu.register(reg.to_register()); + let sum = Self::add_u8s(a_value, value, &mut flags); (Cycles::new(4), sum) } IndirectHL => { - let value = cpu.read_byte(cpu.register_pair(RegisterPair::HL)); + let addr = cpu.register_pair(RegisterPair::HL); + let value = cpu.read_byte(addr); + let sum = Self::add_u8s(a_value, value, &mut flags); (Cycles::new(8), sum) }