From 66c98f53fb0f2221ff9862eb15f35477b5064da9 Mon Sep 17 00:00:00 2001 From: MadMaurice Date: Wed, 30 Aug 2023 12:56:40 +0200 Subject: [PATCH] test_cpu_simple - Add DAA example as a test --- tests/test_cpu_simple.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/test_cpu_simple.cpp b/tests/test_cpu_simple.cpp index 41ea4ec..9f63dcb 100644 --- a/tests/test_cpu_simple.cpp +++ b/tests/test_cpu_simple.cpp @@ -217,3 +217,35 @@ TEST_CASE("RST op leads to correct call") CHECK(cpu.state.PC == expected_pc); } + +TEST_CASE("DAA") +{ + u8 test_ram[] = { + 0x80, // ADD A,B + 0x27, // DAA + 0x90, // SUB A,B + 0x27, // DAA + }; + + RAM r(test_ram, 0x4, true); + Cpu cpu(&r); + + cpu.state.A = 0x45; + cpu.state.B = 0x38; + + cpu.step(); + + CHECK(cpu.state.A == 0x7D); + + cpu.step(); + + CHECK(cpu.state.A == 0x83); + + cpu.step(); + + CHECK(cpu.state.A == 0x4B); + + cpu.step(); + + CHECK(cpu.state.A == 0x45); +}