From 18530b62ad1ff648471b802ffc4ca1762ae824a9 Mon Sep 17 00:00:00 2001 From: Jayesh Puri Date: Thu, 21 May 2026 22:35:13 +0530 Subject: [PATCH 1/4] opccc lol --- src/core/cpu/instructions/opcodes/op_0C.cpp | 22 ++++++++- tests/op_tests/op_0C_tests.cpp | 51 +++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/src/core/cpu/instructions/opcodes/op_0C.cpp b/src/core/cpu/instructions/opcodes/op_0C.cpp index 402819e..040d460 100644 --- a/src/core/cpu/instructions/opcodes/op_0C.cpp +++ b/src/core/cpu/instructions/opcodes/op_0C.cpp @@ -176,7 +176,27 @@ int op_cb_prefix(ProcessingUnit& cpu , MMU& mmu) // 0xCB return cbInstructionTable[cb_opcode](cpu, mmu); } -DUMMY(op_call_z) // 0xCC +int op_call_z(ProcessingUnit& cpu, MMU& mmu) // 0xCC +{ + const u8 lo = mmu.read(cpu.inc_pc()); + const u8 hi = mmu.read(cpu.inc_pc()); + const u16 addr = static_cast((hi << 8) | lo); + + if (cpu.get_flag_z()) + { + const u16 pc = cpu.get_pc(); + const u16 sp = cpu.get_sp(); + + mmu.write(sp - 1, static_cast(pc >> 8)); + mmu.write(sp - 2, static_cast(pc & 0xFF)); + cpu.set_sp(sp - 2); + cpu.set_pc(addr); + + return totalMachineCycles(6); + } + return totalMachineCycles(3); +} + DUMMY(op_call) // 0xCD DUMMY(op_adc_a_d8) // 0xCE DUMMY(op_rst_08) // 0xCF diff --git a/tests/op_tests/op_0C_tests.cpp b/tests/op_tests/op_0C_tests.cpp index a1060d9..062f920 100644 --- a/tests/op_tests/op_0C_tests.cpp +++ b/tests/op_tests/op_0C_tests.cpp @@ -415,4 +415,55 @@ TEST_F(OpcodesCPUTest, RET_PopsReturnAddressAndRestoresSP) EXPECT_EQ(cycles, 16); EXPECT_EQ(cpu.get_pc(), 0x1234); EXPECT_EQ(cpu.get_sp(), 0xFFFE); +} + +TEST_F(OpcodesCPUTest, CALL_Z_CallsWhenZeroFlagSet) +{ + std::vector rom(0x8000, 0x00); + // addr = 0x2000 + rom[0x100] = 0x00; + rom[0x101] = 0x20; + ASSERT_TRUE(mmu.map_rom(rom)); + cpu.set_sp(0xFFFE); + cpu.reg(ProcessingUnit::Register::F) = 0x80; // Z set + const int cycles = op_call_z(cpu, mmu); + EXPECT_EQ(cycles, 24); + EXPECT_EQ(cpu.get_pc(), 0x2000); + EXPECT_EQ(cpu.get_sp(), 0xFFFC); + // return addr 0x102 pushed hi 1st + EXPECT_EQ(mmu.read(0xFFFD), 0x01); + EXPECT_EQ(mmu.read(0xFFFC), 0x02); +} + +TEST_F(OpcodesCPUTest, CALL_Z_SkipsWhenZeroFlagClear) +{ + std::vector rom(0x8000, 0x00); + rom[0x100] = 0x00; + rom[0x101] = 0x20; + ASSERT_TRUE(mmu.map_rom(rom)); + cpu.set_sp(0xFFFE); + cpu.reg(ProcessingUnit::Register::F) = 0x00; // Z clear + const int cycles = op_call_z(cpu, mmu); + EXPECT_EQ(cycles, 12); + EXPECT_EQ(cpu.get_pc(), 0x102); + EXPECT_EQ(cpu.get_sp(), 0xFFFE); +} + +TEST_F(OpcodesCPUTest, CALL_Z_ThroughStep_UsesOpcodeTableAndCalls) +{ + std::vector rom(0x8000, 0x00); + // addr = 0x5678 + rom[0x100] = 0xCC; + rom[0x101] = 0x78; + rom[0x102] = 0x56; + ASSERT_TRUE(mmu.map_rom(rom)); + cpu.set_pc(0x100); + cpu.set_sp(0xFFFE); + cpu.reg(ProcessingUnit::Register::F) = 0x80; // Z set + const int cycles = cpu.step(mmu); + EXPECT_EQ(cycles, 24); + EXPECT_EQ(cpu.get_pc(), 0x5678); + EXPECT_EQ(cpu.get_sp(), 0xFFFC); + EXPECT_EQ(mmu.read(0xFFFD), 0x01); + EXPECT_EQ(mmu.read(0xFFFC), 0x03); } \ No newline at end of file From ae279a5d4eeb5579c6d751bb08c2336610657909 Mon Sep 17 00:00:00 2001 From: Jayesh Puri Date: Thu, 21 May 2026 22:55:41 +0530 Subject: [PATCH 2/4] opcd and opce lol --- src/core/cpu/instructions/opcodes/op_0C.cpp | 36 +++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/core/cpu/instructions/opcodes/op_0C.cpp b/src/core/cpu/instructions/opcodes/op_0C.cpp index 040d460..0cb10bc 100644 --- a/src/core/cpu/instructions/opcodes/op_0C.cpp +++ b/src/core/cpu/instructions/opcodes/op_0C.cpp @@ -197,6 +197,38 @@ int op_call_z(ProcessingUnit& cpu, MMU& mmu) // 0xCC return totalMachineCycles(3); } -DUMMY(op_call) // 0xCD -DUMMY(op_adc_a_d8) // 0xCE +int op_call(ProcessingUnit& cpu, MMU& mmu) // 0xCD +{ + const u8 lo = mmu.read(cpu.inc_pc()); + const u8 hi = mmu.read(cpu.inc_pc()); + const u16 addr = static_cast((hi << 8) | lo); + + const u16 pc = cpu.get_pc(); + const u16 sp = cpu.get_sp(); + + mmu.write(sp - 1, static_cast(pc >> 8)); + mmu.write(sp - 2, static_cast(pc & 0xFF)); + + cpu.set_sp(sp - 2); + cpu.set_pc(addr); + + return totalMachineCycles(6); +} + +int op_adc_a_d8(ProcessingUnit& cpu, MMU& mmu) // 0xCE +{ + const u8 d8 = mmu.read(cpu.inc_pc()); + const u8 a = cpu.reg(ProcessingUnit::Register::A); + const u8 c = cpu.get_flag_c() ? 1 : 0; + const u16 result = a + d8 + c; + + cpu.setFlag(ProcessingUnit::Flag::Z, (result & 0xFF) == 0); + cpu.setFlag(ProcessingUnit::Flag::N, false); + cpu.setFlag(ProcessingUnit::Flag::H, ((a & 0xF) + (d8 & 0xF) + c) > 0xF); + cpu.setFlag(ProcessingUnit::Flag::C, result > 0xFF); + + cpu.reg(ProcessingUnit::Register::A) = static_cast(result); + return totalMachineCycles(2); +} + DUMMY(op_rst_08) // 0xCF From 7088c405c0c9d575d26254d99a38276966ae2d20 Mon Sep 17 00:00:00 2001 From: Jayesh Puri Date: Thu, 21 May 2026 23:05:12 +0530 Subject: [PATCH 3/4] conflits:fixed poor code practice using already impl method --- include/ProcessingUnit.hpp | 2 +- src/core/cpu/instructions/opcodes/op_0C.cpp | 16 +++- tests/op_tests/cb_op_08_tests.cpp | 32 +++---- tests/op_tests/cb_op_09_tests.cpp | 32 +++---- tests/op_tests/cb_op_0A_tests.cpp | 32 +++---- tests/op_tests/cb_op_0B_tests.cpp | 32 +++---- tests/op_tests/cb_op_0C_tests.cpp | 32 +++---- tests/op_tests/cb_op_0D_tests.cpp | 32 +++---- tests/op_tests/cb_op_0E_tests.cpp | 32 +++---- tests/op_tests/cb_op_0F_tests.cpp | 32 +++---- tests/op_tests/op_01_tests.cpp | 8 +- tests/op_tests/op_02_tests.cpp | 6 +- tests/op_tests/op_03_tests.cpp | 6 +- tests/op_tests/op_04_tests.cpp | 6 +- tests/op_tests/op_05_tests.cpp | 6 +- tests/op_tests/op_06_tests.cpp | 6 +- tests/op_tests/op_07_tests.cpp | 4 +- tests/op_tests/op_09_tests.cpp | 4 +- tests/op_tests/op_0A_tests.cpp | 32 +++---- tests/op_tests/op_0B_tests.cpp | 32 +++---- tests/op_tests/op_0C_tests.cpp | 101 ++++++++++++++++++-- tests/op_tests/op_0E_tests.cpp | 2 +- tests/op_tests/op_0F_tests.cpp | 2 +- 23 files changed, 291 insertions(+), 198 deletions(-) diff --git a/include/ProcessingUnit.hpp b/include/ProcessingUnit.hpp index 08237f1..dbbaaa8 100644 --- a/include/ProcessingUnit.hpp +++ b/include/ProcessingUnit.hpp @@ -79,7 +79,7 @@ class ProcessingUnit{ } void normalizeFlags() { - F &= 0xF0; + F = 0xF0; } void setFlag(Flag flag, bool value) { diff --git a/src/core/cpu/instructions/opcodes/op_0C.cpp b/src/core/cpu/instructions/opcodes/op_0C.cpp index 0cb10bc..57886cb 100644 --- a/src/core/cpu/instructions/opcodes/op_0C.cpp +++ b/src/core/cpu/instructions/opcodes/op_0C.cpp @@ -226,9 +226,21 @@ int op_adc_a_d8(ProcessingUnit& cpu, MMU& mmu) // 0xCE cpu.setFlag(ProcessingUnit::Flag::N, false); cpu.setFlag(ProcessingUnit::Flag::H, ((a & 0xF) + (d8 & 0xF) + c) > 0xF); cpu.setFlag(ProcessingUnit::Flag::C, result > 0xFF); - + cpu.reg(ProcessingUnit::Register::A) = static_cast(result); return totalMachineCycles(2); } -DUMMY(op_rst_08) // 0xCF +int op_rst_08(ProcessingUnit& cpu, MMU& mmu) // 0xCF +{ + const u16 pc = cpu.get_pc(); + const u16 sp = cpu.get_sp(); + + mmu.write(sp - 1, static_cast(pc >> 8)); + mmu.write(sp - 2, static_cast(pc & 0xFF)); + cpu.set_sp(sp - 2); + + cpu.set_pc(0x0008); + + return totalMachineCycles(4); +} diff --git a/tests/op_tests/cb_op_08_tests.cpp b/tests/op_tests/cb_op_08_tests.cpp index 6c7f146..070443c 100644 --- a/tests/op_tests/cb_op_08_tests.cpp +++ b/tests/op_tests/cb_op_08_tests.cpp @@ -13,7 +13,7 @@ class CB_OpcodesCPUTest : public testing::Test { // --- RES 0 --- TEST_F(CB_OpcodesCPUTest, RES_0_B) { cpu.reg(ProcessingUnit::Register::B) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; // Set flags to ensure they aren't cleared + cpu.normalizeFlags(); // Set flags to ensure they aren't cleared int cycles = op_res_0_b(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::B), 0xFE); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); // Flags unchanged @@ -26,7 +26,7 @@ TEST_F(CB_OpcodesCPUTest, RES_0_B) { TEST_F(CB_OpcodesCPUTest, RES_0_C) { cpu.reg(ProcessingUnit::Register::C) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_0_c(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::C), 0xFE); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -35,7 +35,7 @@ TEST_F(CB_OpcodesCPUTest, RES_0_C) { TEST_F(CB_OpcodesCPUTest, RES_0_D) { cpu.reg(ProcessingUnit::Register::D) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_0_d(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::D), 0xFE); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -44,7 +44,7 @@ TEST_F(CB_OpcodesCPUTest, RES_0_D) { TEST_F(CB_OpcodesCPUTest, RES_0_E) { cpu.reg(ProcessingUnit::Register::E) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_0_e(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::E), 0xFE); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -53,7 +53,7 @@ TEST_F(CB_OpcodesCPUTest, RES_0_E) { TEST_F(CB_OpcodesCPUTest, RES_0_H) { cpu.reg(ProcessingUnit::Register::H) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_0_h(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::H), 0xFE); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -62,7 +62,7 @@ TEST_F(CB_OpcodesCPUTest, RES_0_H) { TEST_F(CB_OpcodesCPUTest, RES_0_L) { cpu.reg(ProcessingUnit::Register::L) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_0_l(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::L), 0xFE); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -74,7 +74,7 @@ TEST_F(CB_OpcodesCPUTest, RES_0_HL) { cpu.reg(ProcessingUnit::Register::H) = 0xC0; cpu.reg(ProcessingUnit::Register::L) = 0x00; mmu.write(addr, 0xFF); - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_0_hl(cpu, mmu); EXPECT_EQ(mmu.read(addr), 0xFE); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -83,7 +83,7 @@ TEST_F(CB_OpcodesCPUTest, RES_0_HL) { TEST_F(CB_OpcodesCPUTest, RES_0_A) { cpu.reg(ProcessingUnit::Register::A) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_0_a(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::A), 0xFE); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -93,7 +93,7 @@ TEST_F(CB_OpcodesCPUTest, RES_0_A) { // --- RES 1 --- TEST_F(CB_OpcodesCPUTest, RES_1_B) { cpu.reg(ProcessingUnit::Register::B) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_1_b(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::B), 0xFD); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -102,7 +102,7 @@ TEST_F(CB_OpcodesCPUTest, RES_1_B) { TEST_F(CB_OpcodesCPUTest, RES_1_C) { cpu.reg(ProcessingUnit::Register::C) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_1_c(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::C), 0xFD); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -111,7 +111,7 @@ TEST_F(CB_OpcodesCPUTest, RES_1_C) { TEST_F(CB_OpcodesCPUTest, RES_1_D) { cpu.reg(ProcessingUnit::Register::D) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_1_d(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::D), 0xFD); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -120,7 +120,7 @@ TEST_F(CB_OpcodesCPUTest, RES_1_D) { TEST_F(CB_OpcodesCPUTest, RES_1_E) { cpu.reg(ProcessingUnit::Register::E) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_1_e(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::E), 0xFD); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -129,7 +129,7 @@ TEST_F(CB_OpcodesCPUTest, RES_1_E) { TEST_F(CB_OpcodesCPUTest, RES_1_H) { cpu.reg(ProcessingUnit::Register::H) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_1_h(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::H), 0xFD); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -138,7 +138,7 @@ TEST_F(CB_OpcodesCPUTest, RES_1_H) { TEST_F(CB_OpcodesCPUTest, RES_1_L) { cpu.reg(ProcessingUnit::Register::L) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_1_l(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::L), 0xFD); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -150,7 +150,7 @@ TEST_F(CB_OpcodesCPUTest, RES_1_HL) { cpu.reg(ProcessingUnit::Register::H) = 0xC0; cpu.reg(ProcessingUnit::Register::L) = 0x00; mmu.write(addr, 0xFF); - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_1_hl(cpu, mmu); EXPECT_EQ(mmu.read(addr), 0xFD); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -159,7 +159,7 @@ TEST_F(CB_OpcodesCPUTest, RES_1_HL) { TEST_F(CB_OpcodesCPUTest, RES_1_A) { cpu.reg(ProcessingUnit::Register::A) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_1_a(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::A), 0xFD); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); diff --git a/tests/op_tests/cb_op_09_tests.cpp b/tests/op_tests/cb_op_09_tests.cpp index 2374593..8a01b74 100644 --- a/tests/op_tests/cb_op_09_tests.cpp +++ b/tests/op_tests/cb_op_09_tests.cpp @@ -13,7 +13,7 @@ class CB_OpcodesCPUTest : public testing::Test { // --- RES 2 --- TEST_F(CB_OpcodesCPUTest, RES_2_B) { cpu.reg(ProcessingUnit::Register::B) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_2_b(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::B), 0xFB); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -22,7 +22,7 @@ TEST_F(CB_OpcodesCPUTest, RES_2_B) { TEST_F(CB_OpcodesCPUTest, RES_2_C) { cpu.reg(ProcessingUnit::Register::C) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_2_c(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::C), 0xFB); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -31,7 +31,7 @@ TEST_F(CB_OpcodesCPUTest, RES_2_C) { TEST_F(CB_OpcodesCPUTest, RES_2_D) { cpu.reg(ProcessingUnit::Register::D) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_2_d(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::D), 0xFB); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -40,7 +40,7 @@ TEST_F(CB_OpcodesCPUTest, RES_2_D) { TEST_F(CB_OpcodesCPUTest, RES_2_E) { cpu.reg(ProcessingUnit::Register::E) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_2_e(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::E), 0xFB); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -49,7 +49,7 @@ TEST_F(CB_OpcodesCPUTest, RES_2_E) { TEST_F(CB_OpcodesCPUTest, RES_2_H) { cpu.reg(ProcessingUnit::Register::H) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_2_h(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::H), 0xFB); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -58,7 +58,7 @@ TEST_F(CB_OpcodesCPUTest, RES_2_H) { TEST_F(CB_OpcodesCPUTest, RES_2_L) { cpu.reg(ProcessingUnit::Register::L) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_2_l(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::L), 0xFB); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -70,7 +70,7 @@ TEST_F(CB_OpcodesCPUTest, RES_2_HL) { cpu.reg(ProcessingUnit::Register::H) = 0xC0; cpu.reg(ProcessingUnit::Register::L) = 0x00; mmu.write(addr, 0xFF); - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_2_hl(cpu, mmu); EXPECT_EQ(mmu.read(addr), 0xFB); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -79,7 +79,7 @@ TEST_F(CB_OpcodesCPUTest, RES_2_HL) { TEST_F(CB_OpcodesCPUTest, RES_2_A) { cpu.reg(ProcessingUnit::Register::A) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_2_a(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::A), 0xFB); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -89,7 +89,7 @@ TEST_F(CB_OpcodesCPUTest, RES_2_A) { // --- RES 3 --- TEST_F(CB_OpcodesCPUTest, RES_3_B) { cpu.reg(ProcessingUnit::Register::B) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_3_b(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::B), 0xF7); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -98,7 +98,7 @@ TEST_F(CB_OpcodesCPUTest, RES_3_B) { TEST_F(CB_OpcodesCPUTest, RES_3_C) { cpu.reg(ProcessingUnit::Register::C) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_3_c(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::C), 0xF7); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -107,7 +107,7 @@ TEST_F(CB_OpcodesCPUTest, RES_3_C) { TEST_F(CB_OpcodesCPUTest, RES_3_D) { cpu.reg(ProcessingUnit::Register::D) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_3_d(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::D), 0xF7); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -116,7 +116,7 @@ TEST_F(CB_OpcodesCPUTest, RES_3_D) { TEST_F(CB_OpcodesCPUTest, RES_3_E) { cpu.reg(ProcessingUnit::Register::E) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_3_e(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::E), 0xF7); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -125,7 +125,7 @@ TEST_F(CB_OpcodesCPUTest, RES_3_E) { TEST_F(CB_OpcodesCPUTest, RES_3_H) { cpu.reg(ProcessingUnit::Register::H) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_3_h(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::H), 0xF7); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -134,7 +134,7 @@ TEST_F(CB_OpcodesCPUTest, RES_3_H) { TEST_F(CB_OpcodesCPUTest, RES_3_L) { cpu.reg(ProcessingUnit::Register::L) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_3_l(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::L), 0xF7); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -146,7 +146,7 @@ TEST_F(CB_OpcodesCPUTest, RES_3_HL) { cpu.reg(ProcessingUnit::Register::H) = 0xC0; cpu.reg(ProcessingUnit::Register::L) = 0x00; mmu.write(addr, 0xFF); - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_3_hl(cpu, mmu); EXPECT_EQ(mmu.read(addr), 0xF7); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -155,7 +155,7 @@ TEST_F(CB_OpcodesCPUTest, RES_3_HL) { TEST_F(CB_OpcodesCPUTest, RES_3_A) { cpu.reg(ProcessingUnit::Register::A) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_3_a(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::A), 0xF7); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); diff --git a/tests/op_tests/cb_op_0A_tests.cpp b/tests/op_tests/cb_op_0A_tests.cpp index 10ffba5..6945c4f 100644 --- a/tests/op_tests/cb_op_0A_tests.cpp +++ b/tests/op_tests/cb_op_0A_tests.cpp @@ -13,7 +13,7 @@ class CB_OpcodesCPUTest : public testing::Test { // --- RES 4 --- TEST_F(CB_OpcodesCPUTest, RES_4_B) { cpu.reg(ProcessingUnit::Register::B) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_4_b(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::B), 0xEF); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -22,7 +22,7 @@ TEST_F(CB_OpcodesCPUTest, RES_4_B) { TEST_F(CB_OpcodesCPUTest, RES_4_C) { cpu.reg(ProcessingUnit::Register::C) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_4_c(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::C), 0xEF); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -31,7 +31,7 @@ TEST_F(CB_OpcodesCPUTest, RES_4_C) { TEST_F(CB_OpcodesCPUTest, RES_4_D) { cpu.reg(ProcessingUnit::Register::D) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_4_d(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::D), 0xEF); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -40,7 +40,7 @@ TEST_F(CB_OpcodesCPUTest, RES_4_D) { TEST_F(CB_OpcodesCPUTest, RES_4_E) { cpu.reg(ProcessingUnit::Register::E) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_4_e(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::E), 0xEF); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -49,7 +49,7 @@ TEST_F(CB_OpcodesCPUTest, RES_4_E) { TEST_F(CB_OpcodesCPUTest, RES_4_H) { cpu.reg(ProcessingUnit::Register::H) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_4_h(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::H), 0xEF); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -58,7 +58,7 @@ TEST_F(CB_OpcodesCPUTest, RES_4_H) { TEST_F(CB_OpcodesCPUTest, RES_4_L) { cpu.reg(ProcessingUnit::Register::L) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_4_l(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::L), 0xEF); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -70,7 +70,7 @@ TEST_F(CB_OpcodesCPUTest, RES_4_HL) { cpu.reg(ProcessingUnit::Register::H) = 0xC0; cpu.reg(ProcessingUnit::Register::L) = 0x00; mmu.write(addr, 0xFF); - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_4_hl(cpu, mmu); EXPECT_EQ(mmu.read(addr), 0xEF); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -79,7 +79,7 @@ TEST_F(CB_OpcodesCPUTest, RES_4_HL) { TEST_F(CB_OpcodesCPUTest, RES_4_A) { cpu.reg(ProcessingUnit::Register::A) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_4_a(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::A), 0xEF); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -89,7 +89,7 @@ TEST_F(CB_OpcodesCPUTest, RES_4_A) { // --- RES 5 --- TEST_F(CB_OpcodesCPUTest, RES_5_B) { cpu.reg(ProcessingUnit::Register::B) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_5_b(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::B), 0xDF); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -98,7 +98,7 @@ TEST_F(CB_OpcodesCPUTest, RES_5_B) { TEST_F(CB_OpcodesCPUTest, RES_5_C) { cpu.reg(ProcessingUnit::Register::C) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_5_c(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::C), 0xDF); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -107,7 +107,7 @@ TEST_F(CB_OpcodesCPUTest, RES_5_C) { TEST_F(CB_OpcodesCPUTest, RES_5_D) { cpu.reg(ProcessingUnit::Register::D) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_5_d(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::D), 0xDF); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -116,7 +116,7 @@ TEST_F(CB_OpcodesCPUTest, RES_5_D) { TEST_F(CB_OpcodesCPUTest, RES_5_E) { cpu.reg(ProcessingUnit::Register::E) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_5_e(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::E), 0xDF); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -125,7 +125,7 @@ TEST_F(CB_OpcodesCPUTest, RES_5_E) { TEST_F(CB_OpcodesCPUTest, RES_5_H) { cpu.reg(ProcessingUnit::Register::H) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_5_h(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::H), 0xDF); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -134,7 +134,7 @@ TEST_F(CB_OpcodesCPUTest, RES_5_H) { TEST_F(CB_OpcodesCPUTest, RES_5_L) { cpu.reg(ProcessingUnit::Register::L) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_5_l(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::L), 0xDF); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -146,7 +146,7 @@ TEST_F(CB_OpcodesCPUTest, RES_5_HL) { cpu.reg(ProcessingUnit::Register::H) = 0xC0; cpu.reg(ProcessingUnit::Register::L) = 0x00; mmu.write(addr, 0xFF); - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_5_hl(cpu, mmu); EXPECT_EQ(mmu.read(addr), 0xDF); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -155,7 +155,7 @@ TEST_F(CB_OpcodesCPUTest, RES_5_HL) { TEST_F(CB_OpcodesCPUTest, RES_5_A) { cpu.reg(ProcessingUnit::Register::A) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_5_a(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::A), 0xDF); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); diff --git a/tests/op_tests/cb_op_0B_tests.cpp b/tests/op_tests/cb_op_0B_tests.cpp index bbbe822..b13abf0 100644 --- a/tests/op_tests/cb_op_0B_tests.cpp +++ b/tests/op_tests/cb_op_0B_tests.cpp @@ -13,7 +13,7 @@ class CB_OpcodesCPUTest : public testing::Test { // --- RES 6 --- TEST_F(CB_OpcodesCPUTest, RES_6_B) { cpu.reg(ProcessingUnit::Register::B) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_6_b(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::B), 0xBF); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -22,7 +22,7 @@ TEST_F(CB_OpcodesCPUTest, RES_6_B) { TEST_F(CB_OpcodesCPUTest, RES_6_C) { cpu.reg(ProcessingUnit::Register::C) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_6_c(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::C), 0xBF); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -31,7 +31,7 @@ TEST_F(CB_OpcodesCPUTest, RES_6_C) { TEST_F(CB_OpcodesCPUTest, RES_6_D) { cpu.reg(ProcessingUnit::Register::D) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_6_d(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::D), 0xBF); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -40,7 +40,7 @@ TEST_F(CB_OpcodesCPUTest, RES_6_D) { TEST_F(CB_OpcodesCPUTest, RES_6_E) { cpu.reg(ProcessingUnit::Register::E) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_6_e(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::E), 0xBF); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -49,7 +49,7 @@ TEST_F(CB_OpcodesCPUTest, RES_6_E) { TEST_F(CB_OpcodesCPUTest, RES_6_H) { cpu.reg(ProcessingUnit::Register::H) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_6_h(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::H), 0xBF); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -58,7 +58,7 @@ TEST_F(CB_OpcodesCPUTest, RES_6_H) { TEST_F(CB_OpcodesCPUTest, RES_6_L) { cpu.reg(ProcessingUnit::Register::L) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_6_l(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::L), 0xBF); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -70,7 +70,7 @@ TEST_F(CB_OpcodesCPUTest, RES_6_HL) { cpu.reg(ProcessingUnit::Register::H) = 0xC0; cpu.reg(ProcessingUnit::Register::L) = 0x00; mmu.write(addr, 0xFF); - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_6_hl(cpu, mmu); EXPECT_EQ(mmu.read(addr), 0xBF); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -79,7 +79,7 @@ TEST_F(CB_OpcodesCPUTest, RES_6_HL) { TEST_F(CB_OpcodesCPUTest, RES_6_A) { cpu.reg(ProcessingUnit::Register::A) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_6_a(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::A), 0xBF); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -89,7 +89,7 @@ TEST_F(CB_OpcodesCPUTest, RES_6_A) { // --- RES 7 --- TEST_F(CB_OpcodesCPUTest, RES_7_B) { cpu.reg(ProcessingUnit::Register::B) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_7_b(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::B), 0x7F); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -98,7 +98,7 @@ TEST_F(CB_OpcodesCPUTest, RES_7_B) { TEST_F(CB_OpcodesCPUTest, RES_7_C) { cpu.reg(ProcessingUnit::Register::C) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_7_c(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::C), 0x7F); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -107,7 +107,7 @@ TEST_F(CB_OpcodesCPUTest, RES_7_C) { TEST_F(CB_OpcodesCPUTest, RES_7_D) { cpu.reg(ProcessingUnit::Register::D) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_7_d(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::D), 0x7F); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -116,7 +116,7 @@ TEST_F(CB_OpcodesCPUTest, RES_7_D) { TEST_F(CB_OpcodesCPUTest, RES_7_E) { cpu.reg(ProcessingUnit::Register::E) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_7_e(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::E), 0x7F); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -125,7 +125,7 @@ TEST_F(CB_OpcodesCPUTest, RES_7_E) { TEST_F(CB_OpcodesCPUTest, RES_7_H) { cpu.reg(ProcessingUnit::Register::H) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_7_h(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::H), 0x7F); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -134,7 +134,7 @@ TEST_F(CB_OpcodesCPUTest, RES_7_H) { TEST_F(CB_OpcodesCPUTest, RES_7_L) { cpu.reg(ProcessingUnit::Register::L) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_7_l(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::L), 0x7F); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -146,7 +146,7 @@ TEST_F(CB_OpcodesCPUTest, RES_7_HL) { cpu.reg(ProcessingUnit::Register::H) = 0xC0; cpu.reg(ProcessingUnit::Register::L) = 0x00; mmu.write(addr, 0xFF); - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_7_hl(cpu, mmu); EXPECT_EQ(mmu.read(addr), 0x7F); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); @@ -155,7 +155,7 @@ TEST_F(CB_OpcodesCPUTest, RES_7_HL) { TEST_F(CB_OpcodesCPUTest, RES_7_A) { cpu.reg(ProcessingUnit::Register::A) = 0xFF; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_res_7_a(cpu, mmu); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::A), 0x7F); EXPECT_EQ(cpu.reg(ProcessingUnit::Register::F), 0xF0); diff --git a/tests/op_tests/cb_op_0C_tests.cpp b/tests/op_tests/cb_op_0C_tests.cpp index ad32eb6..585ae68 100644 --- a/tests/op_tests/cb_op_0C_tests.cpp +++ b/tests/op_tests/cb_op_0C_tests.cpp @@ -13,7 +13,7 @@ class CB_OpcodesCPUTest : public testing::Test { // --- SET 0 --- TEST_F(CB_OpcodesCPUTest, SET_0_B) { cpu.reg(ProcessingUnit::Register::B) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_0_b(cpu, mmu); @@ -24,7 +24,7 @@ TEST_F(CB_OpcodesCPUTest, SET_0_B) { TEST_F(CB_OpcodesCPUTest, SET_0_C) { cpu.reg(ProcessingUnit::Register::C) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_0_c(cpu, mmu); @@ -35,7 +35,7 @@ TEST_F(CB_OpcodesCPUTest, SET_0_C) { TEST_F(CB_OpcodesCPUTest, SET_0_D) { cpu.reg(ProcessingUnit::Register::D) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_0_d(cpu, mmu); @@ -46,7 +46,7 @@ TEST_F(CB_OpcodesCPUTest, SET_0_D) { TEST_F(CB_OpcodesCPUTest, SET_0_E) { cpu.reg(ProcessingUnit::Register::E) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_0_e(cpu, mmu); @@ -57,7 +57,7 @@ TEST_F(CB_OpcodesCPUTest, SET_0_E) { TEST_F(CB_OpcodesCPUTest, SET_0_H) { cpu.reg(ProcessingUnit::Register::H) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_0_h(cpu, mmu); @@ -68,7 +68,7 @@ TEST_F(CB_OpcodesCPUTest, SET_0_H) { TEST_F(CB_OpcodesCPUTest, SET_0_L) { cpu.reg(ProcessingUnit::Register::L) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_0_l(cpu, mmu); @@ -82,7 +82,7 @@ TEST_F(CB_OpcodesCPUTest, SET_0_HL) { cpu.reg(ProcessingUnit::Register::H) = 0xC0; cpu.reg(ProcessingUnit::Register::L) = 0x00; mmu.write(addr, 0x00); - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_0_hl(cpu, mmu); @@ -93,7 +93,7 @@ TEST_F(CB_OpcodesCPUTest, SET_0_HL) { TEST_F(CB_OpcodesCPUTest, SET_0_A) { cpu.reg(ProcessingUnit::Register::A) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_0_a(cpu, mmu); @@ -105,7 +105,7 @@ TEST_F(CB_OpcodesCPUTest, SET_0_A) { // --- SET 1 --- TEST_F(CB_OpcodesCPUTest, SET_1_B) { cpu.reg(ProcessingUnit::Register::B) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_1_b(cpu, mmu); @@ -116,7 +116,7 @@ TEST_F(CB_OpcodesCPUTest, SET_1_B) { TEST_F(CB_OpcodesCPUTest, SET_1_C) { cpu.reg(ProcessingUnit::Register::C) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_1_c(cpu, mmu); @@ -127,7 +127,7 @@ TEST_F(CB_OpcodesCPUTest, SET_1_C) { TEST_F(CB_OpcodesCPUTest, SET_1_D) { cpu.reg(ProcessingUnit::Register::D) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_1_d(cpu, mmu); @@ -138,7 +138,7 @@ TEST_F(CB_OpcodesCPUTest, SET_1_D) { TEST_F(CB_OpcodesCPUTest, SET_1_E) { cpu.reg(ProcessingUnit::Register::E) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_1_e(cpu, mmu); @@ -149,7 +149,7 @@ TEST_F(CB_OpcodesCPUTest, SET_1_E) { TEST_F(CB_OpcodesCPUTest, SET_1_H) { cpu.reg(ProcessingUnit::Register::H) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_1_h(cpu, mmu); @@ -160,7 +160,7 @@ TEST_F(CB_OpcodesCPUTest, SET_1_H) { TEST_F(CB_OpcodesCPUTest, SET_1_L) { cpu.reg(ProcessingUnit::Register::L) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_1_l(cpu, mmu); @@ -174,7 +174,7 @@ TEST_F(CB_OpcodesCPUTest, SET_1_HL) { cpu.reg(ProcessingUnit::Register::H) = 0xC0; cpu.reg(ProcessingUnit::Register::L) = 0x00; mmu.write(addr, 0x00); - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_1_hl(cpu, mmu); @@ -185,7 +185,7 @@ TEST_F(CB_OpcodesCPUTest, SET_1_HL) { TEST_F(CB_OpcodesCPUTest, SET_1_A) { cpu.reg(ProcessingUnit::Register::A) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_1_a(cpu, mmu); diff --git a/tests/op_tests/cb_op_0D_tests.cpp b/tests/op_tests/cb_op_0D_tests.cpp index 9e80480..34546de 100644 --- a/tests/op_tests/cb_op_0D_tests.cpp +++ b/tests/op_tests/cb_op_0D_tests.cpp @@ -13,7 +13,7 @@ class CB_OpcodesCPUTest : public testing::Test { // --- SET 2 --- TEST_F(CB_OpcodesCPUTest, SET_2_B) { cpu.reg(ProcessingUnit::Register::B) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_2_b(cpu, mmu); @@ -24,7 +24,7 @@ TEST_F(CB_OpcodesCPUTest, SET_2_B) { TEST_F(CB_OpcodesCPUTest, SET_2_C) { cpu.reg(ProcessingUnit::Register::C) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_2_c(cpu, mmu); @@ -35,7 +35,7 @@ TEST_F(CB_OpcodesCPUTest, SET_2_C) { TEST_F(CB_OpcodesCPUTest, SET_2_D) { cpu.reg(ProcessingUnit::Register::D) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_2_d(cpu, mmu); @@ -46,7 +46,7 @@ TEST_F(CB_OpcodesCPUTest, SET_2_D) { TEST_F(CB_OpcodesCPUTest, SET_2_E) { cpu.reg(ProcessingUnit::Register::E) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_2_e(cpu, mmu); @@ -57,7 +57,7 @@ TEST_F(CB_OpcodesCPUTest, SET_2_E) { TEST_F(CB_OpcodesCPUTest, SET_2_H) { cpu.reg(ProcessingUnit::Register::H) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_2_h(cpu, mmu); @@ -68,7 +68,7 @@ TEST_F(CB_OpcodesCPUTest, SET_2_H) { TEST_F(CB_OpcodesCPUTest, SET_2_L) { cpu.reg(ProcessingUnit::Register::L) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_2_l(cpu, mmu); @@ -82,7 +82,7 @@ TEST_F(CB_OpcodesCPUTest, SET_2_HL) { cpu.reg(ProcessingUnit::Register::H) = 0xC0; cpu.reg(ProcessingUnit::Register::L) = 0x00; mmu.write(addr, 0x00); - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_2_hl(cpu, mmu); @@ -93,7 +93,7 @@ TEST_F(CB_OpcodesCPUTest, SET_2_HL) { TEST_F(CB_OpcodesCPUTest, SET_2_A) { cpu.reg(ProcessingUnit::Register::A) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_2_a(cpu, mmu); @@ -105,7 +105,7 @@ TEST_F(CB_OpcodesCPUTest, SET_2_A) { // --- SET 3 --- TEST_F(CB_OpcodesCPUTest, SET_3_B) { cpu.reg(ProcessingUnit::Register::B) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_3_b(cpu, mmu); @@ -116,7 +116,7 @@ TEST_F(CB_OpcodesCPUTest, SET_3_B) { TEST_F(CB_OpcodesCPUTest, SET_3_C) { cpu.reg(ProcessingUnit::Register::C) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_3_c(cpu, mmu); @@ -127,7 +127,7 @@ TEST_F(CB_OpcodesCPUTest, SET_3_C) { TEST_F(CB_OpcodesCPUTest, SET_3_D) { cpu.reg(ProcessingUnit::Register::D) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_3_d(cpu, mmu); @@ -138,7 +138,7 @@ TEST_F(CB_OpcodesCPUTest, SET_3_D) { TEST_F(CB_OpcodesCPUTest, SET_3_E) { cpu.reg(ProcessingUnit::Register::E) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_3_e(cpu, mmu); @@ -149,7 +149,7 @@ TEST_F(CB_OpcodesCPUTest, SET_3_E) { TEST_F(CB_OpcodesCPUTest, SET_3_H) { cpu.reg(ProcessingUnit::Register::H) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_3_h(cpu, mmu); @@ -160,7 +160,7 @@ TEST_F(CB_OpcodesCPUTest, SET_3_H) { TEST_F(CB_OpcodesCPUTest, SET_3_L) { cpu.reg(ProcessingUnit::Register::L) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_3_l(cpu, mmu); @@ -174,7 +174,7 @@ TEST_F(CB_OpcodesCPUTest, SET_3_HL) { cpu.reg(ProcessingUnit::Register::H) = 0xC0; cpu.reg(ProcessingUnit::Register::L) = 0x00; mmu.write(addr, 0x00); - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_3_hl(cpu, mmu); @@ -185,7 +185,7 @@ TEST_F(CB_OpcodesCPUTest, SET_3_HL) { TEST_F(CB_OpcodesCPUTest, SET_3_A) { cpu.reg(ProcessingUnit::Register::A) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_3_a(cpu, mmu); diff --git a/tests/op_tests/cb_op_0E_tests.cpp b/tests/op_tests/cb_op_0E_tests.cpp index 52df48f..453b401 100644 --- a/tests/op_tests/cb_op_0E_tests.cpp +++ b/tests/op_tests/cb_op_0E_tests.cpp @@ -13,7 +13,7 @@ class CB_OpcodesCPUTest : public testing::Test { // --- SET 4 --- TEST_F(CB_OpcodesCPUTest, SET_4_B) { cpu.reg(ProcessingUnit::Register::B) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_4_b(cpu, mmu); @@ -24,7 +24,7 @@ TEST_F(CB_OpcodesCPUTest, SET_4_B) { TEST_F(CB_OpcodesCPUTest, SET_4_C) { cpu.reg(ProcessingUnit::Register::C) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_4_c(cpu, mmu); @@ -35,7 +35,7 @@ TEST_F(CB_OpcodesCPUTest, SET_4_C) { TEST_F(CB_OpcodesCPUTest, SET_4_D) { cpu.reg(ProcessingUnit::Register::D) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_4_d(cpu, mmu); @@ -46,7 +46,7 @@ TEST_F(CB_OpcodesCPUTest, SET_4_D) { TEST_F(CB_OpcodesCPUTest, SET_4_E) { cpu.reg(ProcessingUnit::Register::E) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_4_e(cpu, mmu); @@ -57,7 +57,7 @@ TEST_F(CB_OpcodesCPUTest, SET_4_E) { TEST_F(CB_OpcodesCPUTest, SET_4_H) { cpu.reg(ProcessingUnit::Register::H) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_4_h(cpu, mmu); @@ -68,7 +68,7 @@ TEST_F(CB_OpcodesCPUTest, SET_4_H) { TEST_F(CB_OpcodesCPUTest, SET_4_L) { cpu.reg(ProcessingUnit::Register::L) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_4_l(cpu, mmu); @@ -82,7 +82,7 @@ TEST_F(CB_OpcodesCPUTest, SET_4_HL) { cpu.reg(ProcessingUnit::Register::H) = 0xC0; cpu.reg(ProcessingUnit::Register::L) = 0x00; mmu.write(addr, 0x00); - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_4_hl(cpu, mmu); @@ -93,7 +93,7 @@ TEST_F(CB_OpcodesCPUTest, SET_4_HL) { TEST_F(CB_OpcodesCPUTest, SET_4_A) { cpu.reg(ProcessingUnit::Register::A) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_4_a(cpu, mmu); @@ -105,7 +105,7 @@ TEST_F(CB_OpcodesCPUTest, SET_4_A) { // --- SET 5 --- TEST_F(CB_OpcodesCPUTest, SET_5_B) { cpu.reg(ProcessingUnit::Register::B) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_5_b(cpu, mmu); @@ -116,7 +116,7 @@ TEST_F(CB_OpcodesCPUTest, SET_5_B) { TEST_F(CB_OpcodesCPUTest, SET_5_C) { cpu.reg(ProcessingUnit::Register::C) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_5_c(cpu, mmu); @@ -127,7 +127,7 @@ TEST_F(CB_OpcodesCPUTest, SET_5_C) { TEST_F(CB_OpcodesCPUTest, SET_5_D) { cpu.reg(ProcessingUnit::Register::D) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_5_d(cpu, mmu); @@ -138,7 +138,7 @@ TEST_F(CB_OpcodesCPUTest, SET_5_D) { TEST_F(CB_OpcodesCPUTest, SET_5_E) { cpu.reg(ProcessingUnit::Register::E) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_5_e(cpu, mmu); @@ -149,7 +149,7 @@ TEST_F(CB_OpcodesCPUTest, SET_5_E) { TEST_F(CB_OpcodesCPUTest, SET_5_H) { cpu.reg(ProcessingUnit::Register::H) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_5_h(cpu, mmu); @@ -160,7 +160,7 @@ TEST_F(CB_OpcodesCPUTest, SET_5_H) { TEST_F(CB_OpcodesCPUTest, SET_5_L) { cpu.reg(ProcessingUnit::Register::L) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_5_l(cpu, mmu); @@ -174,7 +174,7 @@ TEST_F(CB_OpcodesCPUTest, SET_5_HL) { cpu.reg(ProcessingUnit::Register::H) = 0xC0; cpu.reg(ProcessingUnit::Register::L) = 0x00; mmu.write(addr, 0x00); - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_5_hl(cpu, mmu); @@ -185,7 +185,7 @@ TEST_F(CB_OpcodesCPUTest, SET_5_HL) { TEST_F(CB_OpcodesCPUTest, SET_5_A) { cpu.reg(ProcessingUnit::Register::A) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_5_a(cpu, mmu); diff --git a/tests/op_tests/cb_op_0F_tests.cpp b/tests/op_tests/cb_op_0F_tests.cpp index 6430829..21fac38 100644 --- a/tests/op_tests/cb_op_0F_tests.cpp +++ b/tests/op_tests/cb_op_0F_tests.cpp @@ -13,7 +13,7 @@ class CB_OpcodesCPUTest : public testing::Test { // --- SET 6 --- TEST_F(CB_OpcodesCPUTest, SET_6_B) { cpu.reg(ProcessingUnit::Register::B) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_6_b(cpu, mmu); @@ -24,7 +24,7 @@ TEST_F(CB_OpcodesCPUTest, SET_6_B) { TEST_F(CB_OpcodesCPUTest, SET_6_C) { cpu.reg(ProcessingUnit::Register::C) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_6_c(cpu, mmu); @@ -35,7 +35,7 @@ TEST_F(CB_OpcodesCPUTest, SET_6_C) { TEST_F(CB_OpcodesCPUTest, SET_6_D) { cpu.reg(ProcessingUnit::Register::D) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_6_d(cpu, mmu); @@ -46,7 +46,7 @@ TEST_F(CB_OpcodesCPUTest, SET_6_D) { TEST_F(CB_OpcodesCPUTest, SET_6_E) { cpu.reg(ProcessingUnit::Register::E) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_6_e(cpu, mmu); @@ -57,7 +57,7 @@ TEST_F(CB_OpcodesCPUTest, SET_6_E) { TEST_F(CB_OpcodesCPUTest, SET_6_H) { cpu.reg(ProcessingUnit::Register::H) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_6_h(cpu, mmu); @@ -68,7 +68,7 @@ TEST_F(CB_OpcodesCPUTest, SET_6_H) { TEST_F(CB_OpcodesCPUTest, SET_6_L) { cpu.reg(ProcessingUnit::Register::L) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_6_l(cpu, mmu); @@ -82,7 +82,7 @@ TEST_F(CB_OpcodesCPUTest, SET_6_HL) { cpu.reg(ProcessingUnit::Register::H) = 0xC0; cpu.reg(ProcessingUnit::Register::L) = 0x00; mmu.write(addr, 0x00); - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_6_hl(cpu, mmu); @@ -93,7 +93,7 @@ TEST_F(CB_OpcodesCPUTest, SET_6_HL) { TEST_F(CB_OpcodesCPUTest, SET_6_A) { cpu.reg(ProcessingUnit::Register::A) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_6_a(cpu, mmu); @@ -105,7 +105,7 @@ TEST_F(CB_OpcodesCPUTest, SET_6_A) { // --- SET 7 --- TEST_F(CB_OpcodesCPUTest, SET_7_B) { cpu.reg(ProcessingUnit::Register::B) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_7_b(cpu, mmu); @@ -116,7 +116,7 @@ TEST_F(CB_OpcodesCPUTest, SET_7_B) { TEST_F(CB_OpcodesCPUTest, SET_7_C) { cpu.reg(ProcessingUnit::Register::C) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_7_c(cpu, mmu); @@ -127,7 +127,7 @@ TEST_F(CB_OpcodesCPUTest, SET_7_C) { TEST_F(CB_OpcodesCPUTest, SET_7_D) { cpu.reg(ProcessingUnit::Register::D) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_7_d(cpu, mmu); @@ -138,7 +138,7 @@ TEST_F(CB_OpcodesCPUTest, SET_7_D) { TEST_F(CB_OpcodesCPUTest, SET_7_E) { cpu.reg(ProcessingUnit::Register::E) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_7_e(cpu, mmu); @@ -149,7 +149,7 @@ TEST_F(CB_OpcodesCPUTest, SET_7_E) { TEST_F(CB_OpcodesCPUTest, SET_7_H) { cpu.reg(ProcessingUnit::Register::H) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_7_h(cpu, mmu); @@ -160,7 +160,7 @@ TEST_F(CB_OpcodesCPUTest, SET_7_H) { TEST_F(CB_OpcodesCPUTest, SET_7_L) { cpu.reg(ProcessingUnit::Register::L) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_7_l(cpu, mmu); @@ -174,7 +174,7 @@ TEST_F(CB_OpcodesCPUTest, SET_7_HL) { cpu.reg(ProcessingUnit::Register::H) = 0xC0; cpu.reg(ProcessingUnit::Register::L) = 0x00; mmu.write(addr, 0x00); - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_7_hl(cpu, mmu); @@ -185,7 +185,7 @@ TEST_F(CB_OpcodesCPUTest, SET_7_HL) { TEST_F(CB_OpcodesCPUTest, SET_7_A) { cpu.reg(ProcessingUnit::Register::A) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); int cycles = op_set_7_a(cpu, mmu); diff --git a/tests/op_tests/op_01_tests.cpp b/tests/op_tests/op_01_tests.cpp index ba3a997..2ab6f12 100644 --- a/tests/op_tests/op_01_tests.cpp +++ b/tests/op_tests/op_01_tests.cpp @@ -196,7 +196,7 @@ TEST_F(OpcodesCPUTest, RLA_RotatesAThroughCarry) TEST_F(OpcodesCPUTest, RLA_UsesCarryIn) { cpu.reg(ProcessingUnit::Register::A) = 0x42; - cpu.reg(ProcessingUnit::Register::F) = 0x00; + cpu.clearFlags(); const int cycles = op_rla(cpu, mmu); @@ -214,7 +214,7 @@ TEST_F(OpcodesCPUTest, JR_R8_JumpsForwardFromNextInstruction) rom[0x101] = 0x05; mmu.map_rom(rom); - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_jr_r8(cpu, mmu); @@ -241,7 +241,7 @@ TEST_F(OpcodesCPUTest, ADD_HL_DE_AddsRegisterPairAndUpdatesFlags) cpu.reg(ProcessingUnit::Register::L) = 0x34; cpu.reg(ProcessingUnit::Register::D) = 0x11; cpu.reg(ProcessingUnit::Register::E) = 0x11; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_add_hl_de(cpu, mmu); @@ -259,7 +259,7 @@ TEST_F(OpcodesCPUTest, ADD_HL_DE_SetsHalfCarryAndCarry) cpu.reg(ProcessingUnit::Register::L) = 0xFF; cpu.reg(ProcessingUnit::Register::D) = 0x00; cpu.reg(ProcessingUnit::Register::E) = 0x01; - cpu.reg(ProcessingUnit::Register::F) = 0x00; + cpu.clearFlags(); const int cycles = op_add_hl_de(cpu, mmu); diff --git a/tests/op_tests/op_02_tests.cpp b/tests/op_tests/op_02_tests.cpp index ed54e10..0e7a47b 100644 --- a/tests/op_tests/op_02_tests.cpp +++ b/tests/op_tests/op_02_tests.cpp @@ -14,7 +14,7 @@ TEST_F(OpcodesCPUTest, JR_NZ_JumpsWhenZeroFlagIsClear) std::vector rom(0x200); rom[0x101] = 0x05; mmu.map_rom(rom); - cpu.reg(ProcessingUnit::Register::F) = 0x00; + cpu.clearFlags(); const int cycles = op_jr_nz(cpu, mmu); @@ -120,7 +120,7 @@ TEST_F(OpcodesCPUTest, LD_H_D8_LoadsImmediateIntoH) TEST_F(OpcodesCPUTest, DAA_AdjustsAfterAddition) { cpu.reg(ProcessingUnit::Register::A) = 0x3C; - cpu.reg(ProcessingUnit::Register::F) = 0x00; + cpu.clearFlags(); const int cycles = op_daa(cpu, mmu); @@ -165,7 +165,7 @@ TEST_F(OpcodesCPUTest, JR_Z_DoesNotJumpWhenZeroFlagIsClear) std::vector rom(0x200); rom[0x101] = 0xFB; mmu.map_rom(rom); - cpu.reg(ProcessingUnit::Register::F) = 0x00; + cpu.clearFlags(); const int cycles = op_jr_z(cpu, mmu); diff --git a/tests/op_tests/op_03_tests.cpp b/tests/op_tests/op_03_tests.cpp index 5163443..b994161 100644 --- a/tests/op_tests/op_03_tests.cpp +++ b/tests/op_tests/op_03_tests.cpp @@ -14,7 +14,7 @@ TEST_F(OpcodesCPUTest, JR_NC_JumpsWhenCarryFlagIsClear) std::vector rom(0x200); rom[0x101] = 0x05; mmu.map_rom(rom); - cpu.reg(ProcessingUnit::Register::F) = 0x00; + cpu.clearFlags(); const int cycles = op_jr_nc(cpu, mmu); @@ -153,7 +153,7 @@ TEST_F(OpcodesCPUTest, JR_C_DoesNotJumpWhenCarryFlagIsClear) std::vector rom(0x200); rom[0x101] = 0x05; mmu.map_rom(rom); - cpu.reg(ProcessingUnit::Register::F) = 0x00; + cpu.clearFlags(); const int cycles = op_jr_c(cpu, mmu); @@ -247,7 +247,7 @@ TEST_F(OpcodesCPUTest, LD_A_D8_LoadsImmediateIntoA) TEST_F(OpcodesCPUTest, CCF_ComplementsCarryAndClearsNH) { - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_ccf(cpu, mmu); diff --git a/tests/op_tests/op_04_tests.cpp b/tests/op_tests/op_04_tests.cpp index 4493e1b..8f8e5ee 100644 --- a/tests/op_tests/op_04_tests.cpp +++ b/tests/op_tests/op_04_tests.cpp @@ -12,7 +12,7 @@ class OpcodesCPUTest : public testing::Test { TEST_F(OpcodesCPUTest, LD_B_B_KeepsBUnchanged) { cpu.reg(ProcessingUnit::Register::B) = 0x7A; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_ld_b_b(cpu, mmu); @@ -96,7 +96,7 @@ TEST_F(OpcodesCPUTest, LD_B_HL_LoadsMemoryIntoB) cpu.reg(ProcessingUnit::Register::H) = 0xC0; cpu.reg(ProcessingUnit::Register::L) = 0x88; cpu.reg(ProcessingUnit::Register::B) = 0x11; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); mmu.write(0xC088, 0x9B); const int cycles = op_ld_b_hl(cpu, mmu); @@ -223,7 +223,7 @@ TEST_F(OpcodesCPUTest, LD_C_A_LoadsAIntoC) { cpu.reg(ProcessingUnit::Register::A) = 0x77; cpu.reg(ProcessingUnit::Register::C) = 0x11; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_ld_c_a_4f(cpu, mmu); diff --git a/tests/op_tests/op_05_tests.cpp b/tests/op_tests/op_05_tests.cpp index bf5c954..4b1fa2d 100644 --- a/tests/op_tests/op_05_tests.cpp +++ b/tests/op_tests/op_05_tests.cpp @@ -13,7 +13,7 @@ TEST_F(OpcodesCPUTest, LD_D_B_LoadsBIntoD) { cpu.reg(ProcessingUnit::Register::B) = 0x7A; cpu.reg(ProcessingUnit::Register::D) = 0x11; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_ld_d_b(cpu, mmu); @@ -96,7 +96,7 @@ TEST_F(OpcodesCPUTest, LD_D_HL_LoadsMemoryIntoD) cpu.reg(ProcessingUnit::Register::H) = 0xC0; cpu.reg(ProcessingUnit::Register::L) = 0x88; cpu.reg(ProcessingUnit::Register::D) = 0x11; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); mmu.write(0xC088, 0x9B); const int cycles = op_ld_d_hl(cpu, mmu); @@ -223,7 +223,7 @@ TEST_F(OpcodesCPUTest, LD_E_A_LoadsAIntoE) { cpu.reg(ProcessingUnit::Register::A) = 0x77; cpu.reg(ProcessingUnit::Register::E) = 0x11; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_ld_e_a(cpu, mmu); diff --git a/tests/op_tests/op_06_tests.cpp b/tests/op_tests/op_06_tests.cpp index 38c705b..d505364 100644 --- a/tests/op_tests/op_06_tests.cpp +++ b/tests/op_tests/op_06_tests.cpp @@ -13,7 +13,7 @@ TEST_F(OpcodesCPUTest, LD_H_B_LoadsBIntoH) { cpu.reg(ProcessingUnit::Register::B) = 0x7A; cpu.reg(ProcessingUnit::Register::H) = 0x11; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_ld_h_b(cpu, mmu); @@ -95,7 +95,7 @@ TEST_F(OpcodesCPUTest, LD_H_HL_LoadsMemoryIntoH) { cpu.reg(ProcessingUnit::Register::H) = 0xC0; cpu.reg(ProcessingUnit::Register::L) = 0x88; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); mmu.write(0xC088, 0x9B); const int cycles = op_ld_h_hl(cpu, mmu); @@ -223,7 +223,7 @@ TEST_F(OpcodesCPUTest, LD_L_A_LoadsAIntoL) { cpu.reg(ProcessingUnit::Register::A) = 0x77; cpu.reg(ProcessingUnit::Register::L) = 0x11; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_ld_l_a(cpu, mmu); diff --git a/tests/op_tests/op_07_tests.cpp b/tests/op_tests/op_07_tests.cpp index 3394b26..8a25899 100644 --- a/tests/op_tests/op_07_tests.cpp +++ b/tests/op_tests/op_07_tests.cpp @@ -13,7 +13,7 @@ TEST_F(OpcodesCPUTest, LD_HL_B_WritesBToMemoryAtHL) cpu.reg(ProcessingUnit::Register::H) = 0xC1; cpu.reg(ProcessingUnit::Register::L) = 0x23; cpu.reg(ProcessingUnit::Register::B) = 0xA7; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); mmu.write(0xC123, 0x00); const int cycles = op_ld_hl_b(cpu, mmu); @@ -139,7 +139,7 @@ TEST_F(OpcodesCPUTest, LD_A_B_LoadsBIntoA) { cpu.reg(ProcessingUnit::Register::A) = 0x11; cpu.reg(ProcessingUnit::Register::B) = 0x4A; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_ld_a_b(cpu, mmu); diff --git a/tests/op_tests/op_09_tests.cpp b/tests/op_tests/op_09_tests.cpp index 46262d7..202b045 100644 --- a/tests/op_tests/op_09_tests.cpp +++ b/tests/op_tests/op_09_tests.cpp @@ -182,7 +182,7 @@ TEST_F(OpcodesCPUTest, SBC_A_E_NoCarryInBehavesLikeSUB) { cpu.reg(ProcessingUnit::Register::A) = 0x22; cpu.reg(ProcessingUnit::Register::E) = 0x11; - cpu.reg(ProcessingUnit::Register::F) = 0x00; + cpu.clearFlags(); const int cycles = op_sbc_a_e(cpu, mmu); @@ -214,7 +214,7 @@ TEST_F(OpcodesCPUTest, SBC_A_L_BorrowWithoutHalfBorrow) { cpu.reg(ProcessingUnit::Register::A) = 0x30; cpu.reg(ProcessingUnit::Register::L) = 0x40; - cpu.reg(ProcessingUnit::Register::F) = 0x00; + cpu.clearFlags(); const int cycles = op_sbc_a_l(cpu, mmu); diff --git a/tests/op_tests/op_0A_tests.cpp b/tests/op_tests/op_0A_tests.cpp index af5ecae..3546cca 100644 --- a/tests/op_tests/op_0A_tests.cpp +++ b/tests/op_tests/op_0A_tests.cpp @@ -13,7 +13,7 @@ TEST_F(OpcodesCPUTest, AND_B_BitwiseAndAndFlags) { cpu.reg(ProcessingUnit::Register::A) = 0xF0; cpu.reg(ProcessingUnit::Register::B) = 0x3C; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_and_b(cpu, mmu); @@ -29,7 +29,7 @@ TEST_F(OpcodesCPUTest, AND_C_SetsZeroWhenResultZero) { cpu.reg(ProcessingUnit::Register::A) = 0x0F; cpu.reg(ProcessingUnit::Register::C) = 0xF0; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_and_c(cpu, mmu); @@ -45,7 +45,7 @@ TEST_F(OpcodesCPUTest, AND_D_BitwiseAndAndFlags) { cpu.reg(ProcessingUnit::Register::A) = 0xAA; cpu.reg(ProcessingUnit::Register::D) = 0xCC; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_and_d(cpu, mmu); @@ -61,7 +61,7 @@ TEST_F(OpcodesCPUTest, AND_E_BitwiseAndAndFlags) { cpu.reg(ProcessingUnit::Register::A) = 0x5A; cpu.reg(ProcessingUnit::Register::E) = 0x0F; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_and_e(cpu, mmu); @@ -77,7 +77,7 @@ TEST_F(OpcodesCPUTest, AND_H_BitwiseAndAndFlags) { cpu.reg(ProcessingUnit::Register::A) = 0x3F; cpu.reg(ProcessingUnit::Register::H) = 0x33; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_and_h(cpu, mmu); @@ -93,7 +93,7 @@ TEST_F(OpcodesCPUTest, AND_L_BitwiseAndAndFlags) { cpu.reg(ProcessingUnit::Register::A) = 0xF5; cpu.reg(ProcessingUnit::Register::L) = 0x5F; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_and_l(cpu, mmu); @@ -110,7 +110,7 @@ TEST_F(OpcodesCPUTest, AND_HL_ReadsMemoryAndUpdatesFlags) cpu.reg(ProcessingUnit::Register::A) = 0xF0; cpu.reg(ProcessingUnit::Register::H) = 0xC1; cpu.reg(ProcessingUnit::Register::L) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); mmu.write(0xC100, 0x0F); const int cycles = op_and_hl(cpu, mmu); @@ -126,7 +126,7 @@ TEST_F(OpcodesCPUTest, AND_HL_ReadsMemoryAndUpdatesFlags) TEST_F(OpcodesCPUTest, AND_A_KeepsAAndSetsH) { cpu.reg(ProcessingUnit::Register::A) = 0x9C; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_and_a(cpu, mmu); @@ -142,7 +142,7 @@ TEST_F(OpcodesCPUTest, XOR_B_BitwiseXorAndFlags) { cpu.reg(ProcessingUnit::Register::A) = 0xF0; cpu.reg(ProcessingUnit::Register::B) = 0x0F; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_xor_b(cpu, mmu); @@ -158,7 +158,7 @@ TEST_F(OpcodesCPUTest, XOR_C_SetsZeroWhenSame) { cpu.reg(ProcessingUnit::Register::A) = 0x5A; cpu.reg(ProcessingUnit::Register::C) = 0x5A; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_xor_c(cpu, mmu); @@ -174,7 +174,7 @@ TEST_F(OpcodesCPUTest, XOR_D_BitwiseXorAndFlags) { cpu.reg(ProcessingUnit::Register::A) = 0xAA; cpu.reg(ProcessingUnit::Register::D) = 0xCC; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_xor_d(cpu, mmu); @@ -190,7 +190,7 @@ TEST_F(OpcodesCPUTest, XOR_E_BitwiseXorAndFlags) { cpu.reg(ProcessingUnit::Register::A) = 0x3C; cpu.reg(ProcessingUnit::Register::E) = 0x0F; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_xor_e(cpu, mmu); @@ -206,7 +206,7 @@ TEST_F(OpcodesCPUTest, XOR_H_BitwiseXorAndFlags) { cpu.reg(ProcessingUnit::Register::A) = 0x81; cpu.reg(ProcessingUnit::Register::H) = 0x01; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_xor_h(cpu, mmu); @@ -222,7 +222,7 @@ TEST_F(OpcodesCPUTest, XOR_L_BitwiseXorAndFlags) { cpu.reg(ProcessingUnit::Register::A) = 0x55; cpu.reg(ProcessingUnit::Register::L) = 0xAA; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_xor_l(cpu, mmu); @@ -239,7 +239,7 @@ TEST_F(OpcodesCPUTest, XOR_HL_ReadsMemoryAndUpdatesFlags) cpu.reg(ProcessingUnit::Register::A) = 0xF0; cpu.reg(ProcessingUnit::Register::H) = 0xC2; cpu.reg(ProcessingUnit::Register::L) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); mmu.write(0xC200, 0xF0); const int cycles = op_xor_hl(cpu, mmu); @@ -255,7 +255,7 @@ TEST_F(OpcodesCPUTest, XOR_HL_ReadsMemoryAndUpdatesFlags) TEST_F(OpcodesCPUTest, XOR_A_AlwaysClearsA) { cpu.reg(ProcessingUnit::Register::A) = 0x9C; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_xor_a(cpu, mmu); diff --git a/tests/op_tests/op_0B_tests.cpp b/tests/op_tests/op_0B_tests.cpp index f75ba32..c40f385 100644 --- a/tests/op_tests/op_0B_tests.cpp +++ b/tests/op_tests/op_0B_tests.cpp @@ -13,7 +13,7 @@ TEST_F(OpcodesCPUTest, OR_B_BitwiseOrAndFlags) { cpu.reg(ProcessingUnit::Register::A) = 0xF0; cpu.reg(ProcessingUnit::Register::B) = 0x0F; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_or_b(cpu, mmu); @@ -29,7 +29,7 @@ TEST_F(OpcodesCPUTest, OR_C_SetsZeroWhenBothZero) { cpu.reg(ProcessingUnit::Register::A) = 0x00; cpu.reg(ProcessingUnit::Register::C) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_or_c(cpu, mmu); @@ -45,7 +45,7 @@ TEST_F(OpcodesCPUTest, OR_D_BitwiseOrAndFlags) { cpu.reg(ProcessingUnit::Register::A) = 0xAA; cpu.reg(ProcessingUnit::Register::D) = 0x55; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_or_d(cpu, mmu); @@ -61,7 +61,7 @@ TEST_F(OpcodesCPUTest, OR_E_BitwiseOrAndFlags) { cpu.reg(ProcessingUnit::Register::A) = 0x10; cpu.reg(ProcessingUnit::Register::E) = 0x01; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_or_e(cpu, mmu); @@ -77,7 +77,7 @@ TEST_F(OpcodesCPUTest, OR_H_BitwiseOrAndFlags) { cpu.reg(ProcessingUnit::Register::A) = 0x03; cpu.reg(ProcessingUnit::Register::H) = 0x30; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_or_h(cpu, mmu); @@ -93,7 +93,7 @@ TEST_F(OpcodesCPUTest, OR_L_BitwiseOrAndFlags) { cpu.reg(ProcessingUnit::Register::A) = 0x44; cpu.reg(ProcessingUnit::Register::L) = 0x22; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_or_l(cpu, mmu); @@ -110,7 +110,7 @@ TEST_F(OpcodesCPUTest, OR_HL_ReadsMemoryAndUpdatesFlags) cpu.reg(ProcessingUnit::Register::A) = 0x0F; cpu.reg(ProcessingUnit::Register::H) = 0xC3; cpu.reg(ProcessingUnit::Register::L) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); mmu.write(0xC300, 0xF0); const int cycles = op_or_hl(cpu, mmu); @@ -126,7 +126,7 @@ TEST_F(OpcodesCPUTest, OR_HL_ReadsMemoryAndUpdatesFlags) TEST_F(OpcodesCPUTest, OR_A_KeepsAAndClearsNHC) { cpu.reg(ProcessingUnit::Register::A) = 0x9C; - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); const int cycles = op_or_a(cpu, mmu); @@ -142,7 +142,7 @@ TEST_F(OpcodesCPUTest, CP_B_CompareSetsFlagsWithoutChangingA) { cpu.reg(ProcessingUnit::Register::A) = 0x3C; cpu.reg(ProcessingUnit::Register::B) = 0x3C; - cpu.reg(ProcessingUnit::Register::F) = 0x00; + cpu.clearFlags(); const int cycles = op_cp_b(cpu, mmu); @@ -158,7 +158,7 @@ TEST_F(OpcodesCPUTest, CP_C_HalfBorrowNoCarry) { cpu.reg(ProcessingUnit::Register::A) = 0x10; cpu.reg(ProcessingUnit::Register::C) = 0x01; - cpu.reg(ProcessingUnit::Register::F) = 0x00; + cpu.clearFlags(); const int cycles = op_cp_c(cpu, mmu); @@ -174,7 +174,7 @@ TEST_F(OpcodesCPUTest, CP_D_CarryWithoutHalfBorrow) { cpu.reg(ProcessingUnit::Register::A) = 0x20; cpu.reg(ProcessingUnit::Register::D) = 0x30; - cpu.reg(ProcessingUnit::Register::F) = 0x00; + cpu.clearFlags(); const int cycles = op_cp_d(cpu, mmu); @@ -190,7 +190,7 @@ TEST_F(OpcodesCPUTest, CP_E_HalfBorrowAndCarry) { cpu.reg(ProcessingUnit::Register::A) = 0x00; cpu.reg(ProcessingUnit::Register::E) = 0x01; - cpu.reg(ProcessingUnit::Register::F) = 0x00; + cpu.clearFlags(); const int cycles = op_cp_e(cpu, mmu); @@ -206,7 +206,7 @@ TEST_F(OpcodesCPUTest, CP_H_StandardCompare) { cpu.reg(ProcessingUnit::Register::A) = 0x9A; cpu.reg(ProcessingUnit::Register::H) = 0x20; - cpu.reg(ProcessingUnit::Register::F) = 0x00; + cpu.clearFlags(); const int cycles = op_cp_h(cpu, mmu); @@ -222,7 +222,7 @@ TEST_F(OpcodesCPUTest, CP_L_StandardCompare) { cpu.reg(ProcessingUnit::Register::A) = 0x3A; cpu.reg(ProcessingUnit::Register::L) = 0x10; - cpu.reg(ProcessingUnit::Register::F) = 0x00; + cpu.clearFlags(); const int cycles = op_cp_l(cpu, mmu); @@ -239,7 +239,7 @@ TEST_F(OpcodesCPUTest, CP_HL_ReadsMemoryAndSetsFlags) cpu.reg(ProcessingUnit::Register::A) = 0x40; cpu.reg(ProcessingUnit::Register::H) = 0xC4; cpu.reg(ProcessingUnit::Register::L) = 0x00; - cpu.reg(ProcessingUnit::Register::F) = 0x00; + cpu.clearFlags(); mmu.write(0xC400, 0x41); const int cycles = op_cp_hl(cpu, mmu); @@ -255,7 +255,7 @@ TEST_F(OpcodesCPUTest, CP_HL_ReadsMemoryAndSetsFlags) TEST_F(OpcodesCPUTest, CP_A_AlwaysZeroSet) { cpu.reg(ProcessingUnit::Register::A) = 0x77; - cpu.reg(ProcessingUnit::Register::F) = 0x00; + cpu.clearFlags(); const int cycles = op_cp_a(cpu, mmu); diff --git a/tests/op_tests/op_0C_tests.cpp b/tests/op_tests/op_0C_tests.cpp index 062f920..fd2b748 100644 --- a/tests/op_tests/op_0C_tests.cpp +++ b/tests/op_tests/op_0C_tests.cpp @@ -52,7 +52,7 @@ TEST_F(OpcodesCPUTest, RET_NZ_ReturnsWhenZeroFlagClear) { cpu.set_pc(0x1234); cpu.set_sp(0xC100); - cpu.reg(ProcessingUnit::Register::F) = 0x00; + cpu.clearFlags(); mmu.write(0xC100, 0x78); mmu.write(0xC101, 0x56); @@ -71,7 +71,7 @@ TEST_F(OpcodesCPUTest, JP_NZ_JumpsWhenZeroFlagClear) rom[0x101] = 0x12; ASSERT_TRUE(mmu.map_rom(rom)); - cpu.reg(ProcessingUnit::Register::F) = 0x00; + cpu.clearFlags(); const int cycles = op_jp_nz(cpu, mmu); @@ -103,7 +103,7 @@ TEST_F(OpcodesCPUTest, JP_NZ_ThroughStep_UsesOpcodeTableAndJumps) ASSERT_TRUE(mmu.map_rom(rom)); cpu.set_pc(0x100); - cpu.reg(ProcessingUnit::Register::F) = 0x00; + cpu.clearFlags(); const int cycles = cpu.step(mmu); @@ -133,7 +133,7 @@ TEST_F(OpcodesCPUTest, JP_Z_DoesNotJumpWhenZeroFlagClear) rom[0x101] = 0x12; ASSERT_TRUE(mmu.map_rom(rom)); - cpu.reg(ProcessingUnit::Register::F) = 0x00; + cpu.clearFlags(); const int cycles = op_jp_z(cpu, mmu); @@ -161,7 +161,7 @@ TEST_F(OpcodesCPUTest, POP_BC_LoadsLowByteIntoCAndHighByteIntoB) TEST_F(OpcodesCPUTest, POP_BC_DoesNotModifyFlags) { - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); cpu.set_sp(0xC120); mmu.write(0xC120, 0x00); @@ -235,7 +235,7 @@ TEST_F(OpcodesCPUTest, JP_JumpsUnconditionally) rom[0x101] = 0x12; ASSERT_TRUE(mmu.map_rom(rom)); - cpu.reg(ProcessingUnit::Register::F) = 0x00; // the flags are irrelevant, + cpu.clearFlags(); // the flags are irrelevant, //use a non-zero value to confirm no flag check const int cycles = op_jp(cpu, mmu); @@ -268,7 +268,7 @@ TEST_F(OpcodesCPUTest, CALL_NZ_CallsWhenZeroFlagClear) ASSERT_TRUE(mmu.map_rom(rom)); cpu.set_sp(0xFFFE); - cpu.reg(ProcessingUnit::Register::F) = 0x00; // Z clear + cpu.clearFlags(); // Z clear const int cycles = op_call_nz(cpu, mmu); @@ -307,7 +307,7 @@ TEST_F(OpcodesCPUTest, CALL_NZ_ThroughStep_UsesOpcodeTableAndCalls) cpu.set_pc(0x100); cpu.set_sp(0xFFFE); - cpu.reg(ProcessingUnit::Register::F) = 0x00; + cpu.clearFlags(); const int cycles = cpu.step(mmu); @@ -393,7 +393,7 @@ TEST_F(OpcodesCPUTest, RET_Z_SkipsWhenZeroFlagClear) ASSERT_TRUE(mmu.map_rom(rom)); cpu.set_sp(0xFFFC); - cpu.reg(ProcessingUnit::Register::F) = 0x00; + cpu.clearFlags(); const int cycles = op_ret_z(cpu, mmu); @@ -442,7 +442,7 @@ TEST_F(OpcodesCPUTest, CALL_Z_SkipsWhenZeroFlagClear) rom[0x101] = 0x20; ASSERT_TRUE(mmu.map_rom(rom)); cpu.set_sp(0xFFFE); - cpu.reg(ProcessingUnit::Register::F) = 0x00; // Z clear + cpu.clearFlags(); // Z clear const int cycles = op_call_z(cpu, mmu); EXPECT_EQ(cycles, 12); EXPECT_EQ(cpu.get_pc(), 0x102); @@ -466,4 +466,85 @@ TEST_F(OpcodesCPUTest, CALL_Z_ThroughStep_UsesOpcodeTableAndCalls) EXPECT_EQ(cpu.get_sp(), 0xFFFC); EXPECT_EQ(mmu.read(0xFFFD), 0x01); EXPECT_EQ(mmu.read(0xFFFC), 0x03); +} + +TEST_F(OpcodesCPUTest, CALL_AlwaysCallsRegardlessOfFlags) +{ + std::vector rom(0x8000, 0x00); + // addr = 0x2000 + rom[0x100] = 0x00; // low + rom[0x101] = 0x20; // hi + ASSERT_TRUE(mmu.map_rom(rom)); + + cpu.set_sp(0xFFFE); + cpu.reg(ProcessingUnit::Register::F) = 0xFF; // all flags set (not relevant) + + const int cycles = op_call(cpu, mmu); + EXPECT_EQ(cycles, 24); + EXPECT_EQ(cpu.get_pc(), 0x2000); + EXPECT_EQ(cpu.get_sp(), 0xFFFC); + // return addr 0x102 pushed hi first + EXPECT_EQ(mmu.read(0xFFFD), 0x01); + EXPECT_EQ(mmu.read(0xFFFC), 0x02); +} + +TEST_F(OpcodesCPUTest, CALL_ThroughStep_UsesOpcodeTableAndCalls) +{ + std::vector rom(0x8000, 0x00); + // addr = 0x5678 + rom[0x100] = 0xCD; + rom[0x101] = 0x78; + rom[0x102] = 0x56; + ASSERT_TRUE(mmu.map_rom(rom)); + + cpu.set_pc(0x100); + cpu.set_sp(0xFFFE); + cpu.clearFlags(); + + const int cycles = cpu.step(mmu); + EXPECT_EQ(cycles, 24); + + EXPECT_EQ(cpu.get_pc(), 0x5678); + EXPECT_EQ(cpu.get_sp(), 0xFFFC); + EXPECT_EQ(mmu.read(0xFFFD), 0x01); + EXPECT_EQ(mmu.read(0xFFFC), 0x03); +} + +TEST_F(OpcodesCPUTest, ADC_A_D8_AddsImmediateAndCarryToA) +{ + std::vector rom(0x8000, 0x00); + rom[0x100] = 0x05; // d8 + ASSERT_TRUE(mmu.map_rom(rom)); + + cpu.reg(ProcessingUnit::Register::A) = 0x10; + cpu.reg(ProcessingUnit::Register::F) = 0x10; + + const int cycles = op_adc_a_d8(cpu, mmu); + EXPECT_EQ(cycles, 8); + + EXPECT_EQ(cpu.reg(ProcessingUnit::Register::A), 0x16); // 0x10 + 0x05 + 1 + + EXPECT_EQ(cpu.get_flag_z(), false); + EXPECT_EQ(cpu.get_flag_n(), false); + EXPECT_EQ(cpu.get_flag_h(), false); + EXPECT_EQ(cpu.get_flag_c(), false); +} + +TEST_F(OpcodesCPUTest, RST_08_PushesReturnAddrAndJumpsTo0x0008) +{ + std::vector rom(0x8000, 0x00); + rom[0x100] = 0xCF; + ASSERT_TRUE(mmu.map_rom(rom)); + + cpu.set_pc(0x101); + cpu.set_sp(0xFFFE); + + const int cycles = op_rst_08(cpu, mmu); + EXPECT_EQ(cycles, 16); + EXPECT_EQ(cpu.get_pc(), 0x0008); + EXPECT_EQ(cpu.get_sp(), 0xFFFC); + + // return addr 0x101 pushed hi first + EXPECT_EQ(mmu.read(0xFFFD), 0x01); // hi + EXPECT_EQ(mmu.read(0xFFFC), 0x01); // lo } \ No newline at end of file diff --git a/tests/op_tests/op_0E_tests.cpp b/tests/op_tests/op_0E_tests.cpp index 7eb1f82..0af9684 100644 --- a/tests/op_tests/op_0E_tests.cpp +++ b/tests/op_tests/op_0E_tests.cpp @@ -115,7 +115,7 @@ TEST_F(OpcodesCPUTest, ADD_SP_E8_AddsSignedOffsetAndUpdatesFlags) cpu.set_sp(initial_sp); cpu.set_pc(initial_pc); - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); mmu.write(initial_pc, offset); int cycles = op_add_sp_e8(cpu, mmu); diff --git a/tests/op_tests/op_0F_tests.cpp b/tests/op_tests/op_0F_tests.cpp index 9c112ac..f4d7d75 100644 --- a/tests/op_tests/op_0F_tests.cpp +++ b/tests/op_tests/op_0F_tests.cpp @@ -147,7 +147,7 @@ TEST_F(OpcodesCPUTest, LD_HL_SP_E8_AddsSignedOffsetAndUpdatesFlags) cpu.set_sp(initial_sp); cpu.set_pc(initial_pc); - cpu.reg(ProcessingUnit::Register::F) = 0xF0; + cpu.normalizeFlags(); mmu.write(initial_pc, offset); int cycles = op_ld_hl_sp_e8(cpu, mmu); From 34d3636f7a68d5c74f8e832a2b0a45d557d8434b Mon Sep 17 00:00:00 2001 From: Jayesh Puri Date: Thu, 21 May 2026 23:06:18 +0530 Subject: [PATCH 4/4] op0xc complete boii, readme update prog --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3828787..5af37bf 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ Game Boy (DMG-01) emulator project focused on building an accurate LR35902 CPU c ```bash ❯ ./utility_scripts/opcode_progress.py -- Base Opcodes: [██████████████████░░] 92.2% (236/256) +- Base Opcodes: [██████████████████░░] 93.8% (240/256) - CB Opcodes: [████████████████████] 100.0% (256/256) -- Combined: [███████████████████░] 96.1% (492/512) +- Combined: [███████████████████░] 96.9% (496/512) ``` ## Current Focus