diff --git a/tests/test_cpu_prefix.cpp b/tests/test_cpu_prefix.cpp new file mode 100644 index 0000000..890e03c --- /dev/null +++ b/tests/test_cpu_prefix.cpp @@ -0,0 +1,39 @@ +#include "doctest.h" + +#include "cpu/cpu.h" +#include "memory/ram.h" + +TEST_CASE("Bit set, clear and test") +{ + u8 test_ram[] = { + 0xCB, 0xD7, // SET 2, A + 0xCB, 0x57, // BIT 2, A + 0xCB, 0x97, // RES 2, A + 0xCB, 0x57, // BIT 2, A + }; + RAM r(test_ram, 0x8, true); + Cpu cpu(&r); + + CHECK(cpu.state.PC == 0x00); + CHECK(cpu.state.A == 0b00000000); + + cpu.step(); + + CHECK(cpu.state.PC == 0x02); + CHECK(cpu.state.A == 0b00000100); + + cpu.step(); + + CHECK(cpu.state.PC == 0x04); + CHECK(!cpu.state.zero); + + cpu.step(); + + CHECK(cpu.state.PC == 0x06); + CHECK(cpu.state.A == 0b00000000); + + cpu.step(); + + CHECK(cpu.state.PC == 0x08); + CHECK(cpu.state.zero); +}