2023-04-15 23:42:37 +00:00
|
|
|
use ferris_boi::{cpu::Processor, register};
|
|
|
|
|
|
|
|
macro_rules! assert_flags_eq {
|
2023-04-30 23:19:02 +00:00
|
|
|
($processor: expr, $(($flag: path, $value: expr)),+ $(,)?) => {
|
|
|
|
$(
|
|
|
|
assert_eq!(
|
|
|
|
$value,
|
|
|
|
$processor.registers.get_flag_bit($flag),
|
|
|
|
"{:?} flag had unexpected value",
|
|
|
|
$flag
|
|
|
|
);
|
|
|
|
)+
|
|
|
|
};
|
|
|
|
}
|
2023-04-15 23:42:37 +00:00
|
|
|
|
|
|
|
pub(crate) use assert_flags_eq;
|
|
|
|
|
|
|
|
pub fn set_opposite_of_expected_flags(
|
|
|
|
processor: &mut Processor,
|
|
|
|
(zero_flag, sub_flag, half_carry_flag, carry_flag): (u8, u8, u8, u8),
|
|
|
|
) {
|
|
|
|
let invert_flag = |value| {
|
|
|
|
if value == 0 {
|
|
|
|
1
|
|
|
|
} else if value == 1 {
|
|
|
|
0
|
|
|
|
} else {
|
|
|
|
panic!("invalid flag value of {value} ")
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
processor
|
|
|
|
.registers
|
|
|
|
.set_flag_bit(register::Flag::Zero, invert_flag(zero_flag));
|
|
|
|
|
|
|
|
processor
|
|
|
|
.registers
|
|
|
|
.set_flag_bit(register::Flag::HalfCarry, invert_flag(half_carry_flag));
|
|
|
|
|
|
|
|
processor
|
|
|
|
.registers
|
|
|
|
.set_flag_bit(register::Flag::Carry, invert_flag(carry_flag));
|
|
|
|
|
|
|
|
processor
|
|
|
|
.registers
|
|
|
|
.set_flag_bit(register::Flag::Subtract, invert_flag(sub_flag));
|
|
|
|
}
|