fn add_word_and_set_flags(cpu: &mut Cpu, x: u16, y: u16) -> u16 {
    // Check for carry using 32bit arithmetics
    let x = x as u32;
    let y = y as u32;
    let r = x.wrapping_add(y);

    cpu.set_substract(false);
    cpu.set_carry(r & 0x10000 != 0);
    cpu.set_halfcarry((x ^ y ^ r) & 0x1000 != 0);
    // zero flag is untouched.

    cpu.delay(1);

    r as u16
}
/// Helper function to add two `u16` and update the CPU flags
Helper function to add two `u16` and update the CPU flags
Helper function to add two ` u16 ` and update the CPU flags
fn add_word_and_set_flags(cpu: &mut Cpu, x: u16, y: u16) -> u16 {
    // Check for carry using 32bit arithmetics
    let x = x as u32;
    let y = y as u32;
    let r = x.wrapping_add(y);
    cpu.set_substract(false);
    cpu.set_carry(r & 0x10000 != 0);
    cpu.set_halfcarry((x ^ y ^ r) & 0x1000 != 0);
    // zero flag is untouched.
    cpu.delay(1);
    r as u16
}
fn add_word_and_set_flags ( cpu : & mut Cpu , x : u16 , y : u16 ) -> u16 { // Check for carry using 32bit arithmetics let x = x as u32 ; let y = y as u32 ; let r = x . wrapping_add ( y ) ; cpu . set_substract ( false ) ; cpu . set_carry ( r & 0x10000 != 0 ) ; cpu . set_halfcarry ( ( x ^ y ^ r ) & 0x1000 != 0 ) ; // zero flag is untouched. cpu . delay ( 1 ) ; r as u16 }
Helper function to add two `u16` and update the CPU flags
Helper function to add two ` u16 ` and update the CPU flags
cpu
&mut Cpu
x
u16
y
u16
cpu
&mut Cpu
x
u16
y
u16