test_cpu_simple - Add a few more test cases

This commit is contained in:
madmaurice 2023-08-28 23:08:45 +02:00
parent 763fe13f5a
commit 1194340657

View file

@ -25,3 +25,67 @@ TEST_CASE("simple load and add")
CHECK(cpu.state.PC == 0x3); CHECK(cpu.state.PC == 0x3);
CHECK(cpu.state.A == 0x20); CHECK(cpu.state.A == 0x20);
} }
TEST_CASE("direct jump")
{
u8 test_ram[] = {
0xC3, 0x05, 0x00, // JMP $0x0005
0x00, 0x00, // NOP NOP
0xC3, 0x00, 0x00, // JMP $0x0000
};
RAM r(test_ram, 8, true);
Cpu cpu(&r);
CHECK(cpu.state.PC == 0x0000);
cpu.step();
CHECK(cpu.state.PC == 0x0005);
cpu.step();
CHECK(cpu.state.PC == 0x0000);
}
TEST_CASE("LD HL, nn; LD A, [HL]; LD A, n; LD [HL], A")
{
u8 test_ram[] = {
0x21, 0x20, 0x00, // LD HL, $0x0020
0x7E, // LD A, [HL]
0x3E,0x5A, // LD A, $0x5A
0x77, // LD [HL], A
0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xA5, // . = 0x0020
};
RAM r(test_ram, 0x0021, false);
Cpu cpu(&r);
CHECK(cpu.state.PC == 0x0);
cpu.step();
CHECK(cpu.state.PC == 0x3);
CHECK(cpu.state.HL == 0x0020);
CHECK(cpu.state.A == 0x0);
cpu.step();
CHECK(cpu.state.PC == 0x4);
CHECK(cpu.state.A == 0xA5);
cpu.step();
CHECK(cpu.state.PC == 0x6);
CHECK(cpu.state.A == 0x5A);
cpu.step();
CHECK(cpu.state.PC == 0x7);
CHECK(test_ram[0x20] == 0x5A);
}