Skip to content
Snippets Groups Projects
inst.rs 23.7 KiB
Newer Older
  • Learn to ignore specific revisions
  •     cpu.set_sub(true);
        cpu.set_zero(value_b == 0);
        cpu.set_half_carry((first ^ second ^ value) & 0x10 == 0x10);
        cpu.set_carry(value & 0x100 == 0x100);
    
        value_b
    }
    
    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_half_carry((first ^ second ^ value) & 0x1000 == 0x1000);
        cpu.set_carry(value & 0x10000 == 0x10000);
    
        value as u16
    }
    
    fn swap(cpu: &mut Cpu, value: u8) -> u8 {
        cpu.set_sub(false);
        cpu.set_zero(value == 0);
        cpu.set_half_carry(false);
        cpu.set_carry(false);
    
        (value << 4) | (value >> 4)
    }
    
    /// Helper function for RST instructions, pushes the
    /// current PC to the stack and jumps to the provided
    /// address.
    fn rst(cpu: &mut Cpu, addr: u16) {
        cpu.push_word(cpu.pc);
        cpu.pc = addr;
    }