Skip to content
Snippets Groups Projects
cpu.rs 23 KiB
Newer Older
  • Learn to ignore specific revisions
  •     let value = x.wrapping_sub(y);
    
        let value_b = value as u8;
    
        cpu.set_sub(true);
        cpu.set_carry(value & 0x100 == 0x100);
        cpu.set_zero(value_b == 0);
        cpu.set_half_carry((x ^ y ^ value) & 0x10 == 0x10);
    
    fn add_u16_u16(cpu: &mut Cpu, first: u16, second: u16) -> u16 {
        let first = first as u32;
        let second = second as u32;
        let value = first.wrapping_add(second);
    
        cpu.set_sub(false);
    
        cpu.set_carry(value & 0x10000 == 0x10000);
    
        cpu.set_half_carry((first ^ second ^ value) & 0x1000 == 0x1000);
    
        value as u16
    }