From ff8c1c65dd23f762d2ea7084179ccb04a357bc67 Mon Sep 17 00:00:00 2001 From: Forest Belton <65484+forestbelton@users.noreply.github.com> Date: Sun, 25 Jul 2021 01:01:58 -0400 Subject: [PATCH] Test ADC instructions --- tests/insn/test_alu8.py | 67 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/tests/insn/test_alu8.py b/tests/insn/test_alu8.py index eadb2d7..9a359b6 100644 --- a/tests/insn/test_alu8.py +++ b/tests/insn/test_alu8.py @@ -53,8 +53,71 @@ def test_add_a_hl(): assert cpu.cycles == 16 -# TODO: ADC_A_R, ADC_A_N, ADC_A_HL, SUB_A_R, SUB_A_N, SUB_A_HL, SBC_A_R, -# SBC_A_N, SBC_A_HL +@pytest.mark.parametrize("r", set(R8) - {R8.A}) +def test_adc_a_r(r): + cpu = CPU() + cpu.set_reg8(r, 0x7F) + + ADC_A_R(r).exec(cpu) + + assert cpu.get_reg8(R8.A) == 0x7F + assert cpu.carry == 0 + assert cpu.cycles == 4 + + cpu.set_reg8(r, 0x81) + ADC_A_R(r).exec(cpu) + + assert cpu.get_reg8(R8.A) == 0x00 + assert cpu.carry == 1 + assert cpu.cycles == 8 + + cpu.set_reg8(r, 0x00) + ADC_A_R(r).exec(cpu) + + assert cpu.get_reg8(R8.A) == 0x01 + assert cpu.carry == 0 + assert cpu.cycles == 12 + + +@pytest.mark.parametrize("n", n8()) +def test_adc_a_n(n): + cpu = CPU() + cpu.set_reg8(R8.A, 0x7F) + + ADC_A_N(n).exec(cpu) + + assert cpu.get_reg8(R8.A) == (0x7F + n) & 0xFF + assert cpu.carry == (1 if n >= 0x81 else 0) + assert cpu.cycles == 8 + + +def test_adc_a_hl(): + cpu = CPU() + cpu.set_reg16(R16.HL, 0x1234) + cpu.deref_hl_set(0x7F) + + ADC_A_HL().exec(cpu) + + assert cpu.get_reg8(R8.A) == 0x7F + assert cpu.carry == 0 + assert cpu.cycles == 8 + + cpu.deref_hl_set(0x81) + ADC_A_HL().exec(cpu) + + assert cpu.get_reg8(R8.A) == 0 + assert cpu.carry == 1 + assert cpu.cycles == 16 + + cpu.deref_hl_set(0x00) + ADC_A_HL().exec(cpu) + + assert cpu.get_reg8(R8.A) == 1 + assert cpu.carry == 0 + assert cpu.cycles == 24 + + +# TODO: SUB_A_R, SUB_A_N, SUB_A_HL, SBC_A_R, SBC_A_N, SBC_A_HL @pytest.mark.parametrize("r", set(R8) - {R8.A})