ferris-boi/tests/cpu/testutil.rs

48 lines
1.2 KiB
Rust

use ferris_boi::{cpu::Processor, register};
macro_rules! assert_flags_eq {
($processor: expr, $(($flag: path, $value: expr)),+ $(,)?) => {
$(
assert_eq!(
$value,
$processor.registers.get_flag_bit($flag),
"{:?} flag had unexpected value",
$flag
);
)+
};
}
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));
}