pub fn decimal_adjust(cpu: &mut CPU) -> u8 {
    let mut carry = false;

    if !cpu.registers.f.contains(Flags::SUBTRACT) {
        if cpu.registers.f.contains(Flags::CARRY) || cpu.registers.a > 0x99 {
            cpu.registers.a = cpu.registers.a.wrapping_add(0x60);
            carry = true;
        }
        if cpu.registers.f.contains(Flags::HALF_CARRY) || cpu.registers.a & 0x0F > 0x09 {
            cpu.registers.a = cpu.registers.a.wrapping_add(0x06);
        }
    } else if cpu.registers.f.contains(Flags::CARRY) {
        carry = true;
        cpu.registers.a =
            cpu.registers
                .a
                .wrapping_add(if cpu.registers.f.contains(Flags::HALF_CARRY) {
                    0x9A
                } else {
                    0xA0
                });
    } else if cpu.registers.f.contains(Flags::HALF_CARRY) {
        cpu.registers.a = cpu.registers.a.wrapping_add(0xFA);
    }

    cpu.registers.f.set(Flags::ZERO, cpu.registers.a == 0);
    cpu.registers.f.set(Flags::HALF_CARRY, false);
    cpu.registers.f.set(Flags::CARRY, carry);

    4
}
/// This instruction conditionally adjusts the accumulator for BCD addition and subtraction
/// operations.
///
/// Takes 4 cycles.
///
/// # Examples
///
/// ```asm
/// DAA
/// ```
This instruction conditionally adjusts the accumulator for BCD addition and subtraction
operations.

Takes 4 cycles.
This instruction conditionally adjusts the accumulator for BCD addition and subtraction operations . Takes 4 cycles .
pub fn decimal_adjust(cpu: &mut CPU) -> u8 {
    let mut carry = false;
    if !cpu.registers.f.contains(Flags::SUBTRACT) {
        if cpu.registers.f.contains(Flags::CARRY) || cpu.registers.a > 0x99 {
            cpu.registers.a = cpu.registers.a.wrapping_add(0x60);
            carry = true;
        }
        if cpu.registers.f.contains(Flags::HALF_CARRY) || cpu.registers.a & 0x0F > 0x09 {
            cpu.registers.a = cpu.registers.a.wrapping_add(0x06);
        }
    } else if cpu.registers.f.contains(Flags::CARRY) {
        carry = true;
        cpu.registers.a =
            cpu.registers
                .a
                .wrapping_add(if cpu.registers.f.contains(Flags::HALF_CARRY) {
                    0x9A
                } else {
                    0xA0
                });
    } else if cpu.registers.f.contains(Flags::HALF_CARRY) {
        cpu.registers.a = cpu.registers.a.wrapping_add(0xFA);
    }
    cpu.registers.f.set(Flags::ZERO, cpu.registers.a == 0);
    cpu.registers.f.set(Flags::HALF_CARRY, false);
    cpu.registers.f.set(Flags::CARRY, carry);
    4
}
pub fn decimal_adjust ( cpu : & mut CPU ) -> u8 { let mut carry = false ; if ! cpu . registers . f . contains ( Flags :: SUBTRACT ) { if cpu . registers . f . contains ( Flags :: CARRY ) || cpu . registers . a > 0x99 { cpu . registers . a = cpu . registers . a . wrapping_add ( 0x60 ) ; carry = true ; } if cpu . registers . f . contains ( Flags :: HALF_CARRY ) || cpu . registers . a & 0x0F > 0x09 { cpu . registers . a = cpu . registers . a . wrapping_add ( 0x06 ) ; } } else if cpu . registers . f . contains ( Flags :: CARRY ) { carry = true ; cpu . registers . a = cpu . registers . a . wrapping_add ( if cpu . registers . f . contains ( Flags :: HALF_CARRY ) { 0x9A } else { 0xA0 } ) ; } else if cpu . registers . f . contains ( Flags :: HALF_CARRY ) { cpu . registers . a = cpu . registers . a . wrapping_add ( 0xFA ) ; } cpu . registers . f . set ( Flags :: ZERO , cpu . registers . a == 0 ) ; cpu . registers . f . set ( Flags :: HALF_CARRY , false ) ; cpu . registers . f . set ( Flags :: CARRY , carry ) ; 4 }
This instruction conditionally adjusts the accumulator for BCD addition and subtraction
operations.
This instruction conditionally adjusts the accumulator for BCD addition and subtraction operations .
cpu
&mut CPU
cpu
&mut CPU
examples
None