instruction changes & fixes

This commit is contained in:
Alex Janka 2023-02-01 22:46:41 +11:00
parent 7460d31913
commit 3da02edc34
2 changed files with 29 additions and 17 deletions

View file

@ -20,25 +20,15 @@ impl CPU {
}
pub(crate) fn inc(&mut self, reg: Reg8) {
let result = self.reg.get_8(reg).wrapping_add(0x1);
self.clear_flag(Flags::NSubtract);
self.set_or_clear_flag(Flags::Zero, result == 0x0);
self.set_or_clear_flag(
Flags::HalfCarry,
(((self.reg.get_8(reg) & 0xF).wrapping_add(0x1 & 0xF)) & 0x10) == 0x10,
);
self.reg.set_8(reg, result);
let result = self.reg.get_8(reg);
let val = self.inc_raw(result);
self.reg.set_8(reg, val);
}
pub(crate) fn dec(&mut self, reg: Reg8) {
let result = self.reg.get_8(reg).wrapping_sub(0x1);
self.set_flag(Flags::NSubtract);
self.set_or_clear_flag(Flags::Zero, result == 0x0);
self.set_or_clear_flag(
Flags::HalfCarry,
(((self.reg.get_8(reg) & 0xF).wrapping_sub(0x1 & 0xF)) & 0x10) == 0x10,
);
self.reg.set_8(reg, result);
let result = self.reg.get_8(reg);
let val = self.dec_raw(result);
self.reg.set_8(reg, val);
}
pub(crate) fn inc_pair(&mut self, val: u16) -> u16 {

View file

@ -79,7 +79,7 @@ impl CPU {
}
}
pub(crate) fn is_flag(&mut self, flag: Flags) -> bool {
pub(crate) fn is_flag(&self, flag: Flags) -> bool {
get_bit(self.reg.af.get_low(), flag as u8)
}
@ -167,4 +167,26 @@ impl CPU {
);
return result;
}
pub(crate) fn dec_raw(&mut self, val: u8) -> u8 {
let result = val.wrapping_sub(0x1);
self.set_flag(Flags::NSubtract);
self.set_or_clear_flag(Flags::Zero, result == 0x0);
self.set_or_clear_flag(
Flags::HalfCarry,
(((val & 0xF).wrapping_sub(0x1 & 0xF)) & 0x10) == 0x10,
);
result
}
pub(crate) fn inc_raw(&mut self, val: u8) -> u8 {
let result = val.wrapping_add(0x1);
self.clear_flag(Flags::NSubtract);
self.set_or_clear_flag(Flags::Zero, result == 0x0);
self.set_or_clear_flag(
Flags::HalfCarry,
(((val & 0xF).wrapping_add(0x1 & 0xF)) & 0x10) == 0x10,
);
result
}
}