From 1cd7d0c2f24c26c2a76d794ccff2efe79c57121f Mon Sep 17 00:00:00 2001 From: MadMaurice Date: Wed, 30 Aug 2023 22:46:25 +0200 Subject: [PATCH] test_cpu_simple - Add test for HALT with IME=1 --- tests/test_cpu_simple.cpp | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/test_cpu_simple.cpp b/tests/test_cpu_simple.cpp index 9f63dcb..90cb754 100644 --- a/tests/test_cpu_simple.cpp +++ b/tests/test_cpu_simple.cpp @@ -249,3 +249,44 @@ TEST_CASE("DAA") CHECK(cpu.state.A == 0x45); } + +TEST_CASE("HALT exits on interrupt") +{ + u8 test_ram[] = { + 0x76, + 0x00, + 0x00, + }; + + RAM r(test_ram, 0x3, true); + Cpu cpu(&r); + + cpu.state.IE = INT_MASK; + cpu.state.IF = 0; + cpu.state.IME = IME_ON; + + CHECK(cpu.state.halted == false); + + cpu.step(); + CHECK(cpu.state.halted == true); + CHECK(cpu.state.PC == 0x01); + + cpu.step(); + CHECK(cpu.state.halted == true); + CHECK(cpu.state.PC == 0x01); + + cpu.step(); + CHECK(cpu.state.halted == true); + CHECK(cpu.state.PC == 0x01); + + cpu.signalInterrupt(INT_LCDSTAT); + + CHECK(cpu.state.IF == INT_LCDSTAT); + + cpu.step(); + + CHECK(cpu.state.halted == false); + CHECK(cpu.state.IF == 0); + CHECK(cpu.state.IME == IME_OFF); + CHECK(cpu.state.PC == 0x48); +}