From a9b0b37a2ee4423fe821010fd2a00be1c2b11a9b Mon Sep 17 00:00:00 2001
From: MadMaurice <madmaurice@zom.bi>
Date: Tue, 29 Aug 2023 21:01:23 +0200
Subject: [PATCH] tests - Add test_cpu_prefix

---
 tests/test_cpu_prefix.cpp | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 tests/test_cpu_prefix.cpp

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);
+}