Implement DAA
This commit is contained in:
parent
1a29412c85
commit
a6066d1fdf
21
src/cpu.rs
21
src/cpu.rs
@ -414,7 +414,26 @@ mod instructions {
|
||||
/// Funky instructions
|
||||
impl CPU {
|
||||
pub fn daa(&mut self) -> IResult {
|
||||
Err(UnimplementedInsn(self.ir))?
|
||||
let mut carry = false;
|
||||
let mut adjusted = self[R8::A];
|
||||
let previous = adjusted.0;
|
||||
let flags = self.flags();
|
||||
// ones digit: if there was a carry out, or the value *grew* too large
|
||||
if flags.h() || (!flags.n() && previous & 0xf > 9) {
|
||||
adjusted += 0x06;
|
||||
}
|
||||
// tens digit: if there was a carry out, or the value *grew* too large
|
||||
if flags.c() || (!flags.n() && previous >> 4 > 9) {
|
||||
adjusted += 0x60;
|
||||
carry = true;
|
||||
}
|
||||
adjusted += previous;
|
||||
self[R8::A] = adjusted;
|
||||
|
||||
let flags = self.flags_mut();
|
||||
*flags = flags.with_z(adjusted.0 == 0).with_h(false).with_c(carry);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
pub fn cpl(&mut self) -> IResult {
|
||||
self[R8::A] ^= 0xff;
|
||||
|
Loading…
Reference in New Issue
Block a user