- import pytest
-
- from tests.cpu.insn.helpers import *
-
-
- @pytest.mark.parametrize("rr", set(R16) - {R16.HL})
- def test_add_hl_rr(rr):
- cpu = CPU()
- cpu.set_reg16(R16.HL, 0xABCD)
- cpu.set_reg16(rr, 0x1234)
-
- ADD_HL_RR(rr).exec(cpu)
-
- assert cpu.get_reg16(R16.HL) == 0xBE01
- assert cpu.state.carry == 0
-
- cpu.set_reg16(rr, 0xFFFF - 0xBE01 + 1)
- ADD_HL_RR(rr).exec(cpu)
-
- assert cpu.get_reg16(R16.HL) == 0
- assert cpu.state.carry == 1
-
-
- @pytest.mark.parametrize("rr", set(R16))
- def test_inc_rr(rr):
- cpu = CPU()
- cpu.set_reg16(rr, 0xABCD)
-
- INC_RR(rr).exec(cpu)
-
- assert cpu.get_reg16(rr) == 0xABCE
-
-
- @pytest.mark.parametrize("rr", set(R16))
- def test_dec_rr(rr):
- cpu = CPU()
- cpu.set_reg16(rr, 0xABCD)
-
- DEC_RR(rr).exec(cpu)
-
- assert cpu.get_reg16(rr) == 0xABCC
-
-
- def test_add_sp_dd():
- cpu = CPU()
- cpu.set_reg16(R16.SP, 0xFFFF)
-
- ADD_SP_DD(-1).exec(cpu)
-
- assert cpu.get_reg16(R16.SP) == 0xFFFE
- assert cpu.state.carry == 0
-
- ADD_SP_DD(2).exec(cpu)
-
- assert cpu.get_reg16(R16.SP) == 0
- assert cpu.state.carry == 1
-
- ADD_SP_DD(-1).exec(cpu)
-
- assert cpu.get_reg16(R16.SP) == 0xFFFF
- assert cpu.state.carry == 1
-
-
- def test_ld_hl_sp_dd():
- cpu = CPU()
- cpu.set_reg16(R16.SP, 0xFFFF)
-
- LD_HL_SP_DD(1).exec(cpu)
-
- assert cpu.get_reg16(R16.HL) == 0
- assert cpu.state.carry == 1
-
- cpu.set_reg16(R16.SP, 0)
- LD_HL_SP_DD(-1).exec(cpu)
-
- assert cpu.get_reg16(R16.HL) == 0xFFFF
- assert cpu.state.carry == 1
-
- cpu.set_reg16(R16.SP, 0xFFFF)
- LD_HL_SP_DD(-2).exec(cpu)
-
- assert cpu.get_reg16(R16.HL) == 0xFFFD
- assert cpu.state.carry == 0
|