From 567cbf026407392a1b70ebf989fb205918fbebb1 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Fri, 24 Feb 2023 19:28:18 +1100 Subject: [PATCH] fix opcodes e8 & f8... WE PASS CPU_INSTRS!!!!! --- src/processor/instructions/primitives.rs | 17 ++++++----------- src/processor/opcodes.rs | 4 ++-- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/processor/instructions/primitives.rs b/src/processor/instructions/primitives.rs index e50cfac..70925d4 100644 --- a/src/processor/instructions/primitives.rs +++ b/src/processor/instructions/primitives.rs @@ -1,6 +1,6 @@ use crate::{ processor::{Cpu, Direction, Flags, SplitRegister}, - util::{get_bit, get_rotation_carry, rotate, Nibbles}, + util::{as_signed, get_bit, get_rotation_carry, rotate, Nibbles}, }; use std::ops::{BitAnd, BitOr}; @@ -106,18 +106,13 @@ impl Cpu { } } - pub(crate) fn sp_add(&mut self, first: u16, second: i8) -> u16 { - let (result, carry) = first.overflowing_add_signed(second.into()); + pub(crate) fn sp_add(&mut self, first: u16, second: u8) -> u16 { + self.add_u8s(first.get_low(), second, false); + self.clear_flag(Flags::NSubtract); self.clear_flag(Flags::Zero); - self.set_or_clear_flag(Flags::Carry, carry); - self.set_or_clear_flag( - Flags::HalfCarry, - (((first & 0xFFF).wrapping_add_signed(>::into(second) & 0xFFF)) - & 0x1000) - == 0x1000, - ); - result + + first.wrapping_add_signed(as_signed(second).into()) } pub(crate) fn add_u8s(&mut self, first: u8, second: u8, with_carry: bool) -> u8 { diff --git a/src/processor/opcodes.rs b/src/processor/opcodes.rs index 2bc00fc..92bf565 100644 --- a/src/processor/opcodes.rs +++ b/src/processor/opcodes.rs @@ -1130,7 +1130,7 @@ impl Cpu { 4 } 0xE8 => { - let v = as_signed(self.ld_immediate_byte()); + let v = self.ld_immediate_byte(); self.reg.sp = self.sp_add(self.reg.sp, v); 4 } @@ -1191,7 +1191,7 @@ impl Cpu { 4 } 0xF8 => { - let v = as_signed(self.ld_immediate_byte()); + let v = self.ld_immediate_byte(); self.reg.hl = self.sp_add(self.reg.sp, v); 3 }