fix opcodes e8 & f8... WE PASS CPU_INSTRS!!!!!

This commit is contained in:
Alex Janka 2023-02-24 19:28:18 +11:00
parent 5fbc661f5c
commit 567cbf0264
2 changed files with 8 additions and 13 deletions

View file

@ -1,6 +1,6 @@
use crate::{ use crate::{
processor::{Cpu, Direction, Flags, SplitRegister}, 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}; use std::ops::{BitAnd, BitOr};
@ -106,18 +106,13 @@ impl Cpu {
} }
} }
pub(crate) fn sp_add(&mut self, first: u16, second: i8) -> u16 { pub(crate) fn sp_add(&mut self, first: u16, second: u8) -> u16 {
let (result, carry) = first.overflowing_add_signed(second.into()); self.add_u8s(first.get_low(), second, false);
self.clear_flag(Flags::NSubtract); self.clear_flag(Flags::NSubtract);
self.clear_flag(Flags::Zero); self.clear_flag(Flags::Zero);
self.set_or_clear_flag(Flags::Carry, carry);
self.set_or_clear_flag( first.wrapping_add_signed(as_signed(second).into())
Flags::HalfCarry,
(((first & 0xFFF).wrapping_add_signed(<i8 as Into<i16>>::into(second) & 0xFFF))
& 0x1000)
== 0x1000,
);
result
} }
pub(crate) fn add_u8s(&mut self, first: u8, second: u8, with_carry: bool) -> u8 { pub(crate) fn add_u8s(&mut self, first: u8, second: u8, with_carry: bool) -> u8 {

View file

@ -1130,7 +1130,7 @@ impl Cpu {
4 4
} }
0xE8 => { 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); self.reg.sp = self.sp_add(self.reg.sp, v);
4 4
} }
@ -1191,7 +1191,7 @@ impl Cpu {
4 4
} }
0xF8 => { 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); self.reg.hl = self.sp_add(self.reg.sp, v);
3 3
} }