fn daa(cpu: &mut Cpu) {
    let a          = cpu.a();
    let mut adjust = 0;

    // See if we had a carry/borrow for the low nibble in the last
    // operation
    if cpu.halfcarry() {
        // Yes, we have to adjust it.
        adjust |= 0x06;
    }

    // See if we had a carry/borrow for the high nibble in the last
    // operation
    if cpu.carry() {
        // Yes, we have to adjust it.
        adjust |= 0x60;
    }

    let res =
        if cpu.substract() {
            // If the operation was a substraction we're done since we
            // can never end up in the A-F range by substracting
            // without generating a (half)carry.
            a.wrapping_sub(adjust)
        } else {
            // Additions are a bit more tricky because we might have
            // to adjust even if we haven't overflowed (and no carry
            // is present). For instance: 0x8 + 0x4 -> 0xc.
	    if a & 0x0F > 0x09 {
                adjust |= 0x06;
            }

	    if a > 0x99 {
                adjust |= 0x60;
            }

	    a.wrapping_add(adjust)
        };

    cpu.set_a(res);

    cpu.set_zero(res == 0);
    cpu.set_carry(adjust & 0x60 != 0);
    cpu.set_halfcarry(false);
}
/// Decimal adjust `A` for BCD operations.
Decimal adjust `A` for BCD operations.
Decimal adjust ` A ` for BCD operations .
fn daa(cpu: &mut Cpu) {
    let a          = cpu.a();
    let mut adjust = 0;
    // See if we had a carry/borrow for the low nibble in the last
    // operation
    if cpu.halfcarry() {
        // Yes, we have to adjust it.
        adjust |= 0x06;
    }
    // See if we had a carry/borrow for the high nibble in the last
    // operation
    if cpu.carry() {
        // Yes, we have to adjust it.
        adjust |= 0x60;
    }
    let res =
        if cpu.substract() {
            // If the operation was a substraction we're done since we
            // can never end up in the A-F range by substracting
            // without generating a (half)carry.
            a.wrapping_sub(adjust)
        } else {
            // Additions are a bit more tricky because we might have
            // to adjust even if we haven't overflowed (and no carry
            // is present). For instance: 0x8 + 0x4 -> 0xc.
	    if a & 0x0F > 0x09 {
                adjust |= 0x06;
            }
	    if a > 0x99 {
                adjust |= 0x60;
            }
	    a.wrapping_add(adjust)
        };
    cpu.set_a(res);
    cpu.set_zero(res == 0);
    cpu.set_carry(adjust & 0x60 != 0);
    cpu.set_halfcarry(false);
}
fn daa ( cpu : & mut Cpu ) { let a = cpu . a ( ) ; let mut adjust = 0 ; // See if we had a carry/borrow for the low nibble in the last // operation if cpu . halfcarry ( ) { // Yes, we have to adjust it. adjust |= 0x06 ; } // See if we had a carry/borrow for the high nibble in the last // operation if cpu . carry ( ) { // Yes, we have to adjust it. adjust |= 0x60 ; } let res = if cpu . substract ( ) { // If the operation was a substraction we're done since we // can never end up in the A-F range by substracting // without generating a (half)carry. a . wrapping_sub ( adjust ) } else { // Additions are a bit more tricky because we might have // to adjust even if we haven't overflowed (and no carry // is present). For instance: 0x8 + 0x4 -> 0xc. if a & 0x0F > 0x09 { adjust |= 0x06 ; } if a > 0x99 { adjust |= 0x60 ; } a . wrapping_add ( adjust ) } ; cpu . set_a ( res ) ; cpu . set_zero ( res == 0 ) ; cpu . set_carry ( adjust & 0x60 != 0 ) ; cpu . set_halfcarry ( false ) ; }
Decimal adjust `A` for BCD operations.
Decimal adjust ` A ` for BCD operations .
cpu
&mut Cpu
cpu
&mut Cpu