Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
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;
}