Browse Source

Test ADC instructions

master
Forest Belton 2 years ago
parent
commit
ff8c1c65dd
1 changed files with 65 additions and 2 deletions
  1. +65
    -2
      tests/insn/test_alu8.py

+ 65
- 2
tests/insn/test_alu8.py View File

@ -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})

Loading…
Cancel
Save