import pytest from tests.insn.helpers import * @pytest.mark.parametrize("rr", set(R16) - {R16.AF, 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.carry == 0 assert cpu.cycles == 8 cpu.set_reg16(rr, 0xFFFF - 0xBE01 + 1) ADD_HL_RR(rr).exec(cpu) assert cpu.get_reg16(R16.HL) == 0 assert cpu.carry == 1 assert cpu.cycles == 16 @pytest.mark.parametrize("rr", set(R16) - {R16.AF}) def test_inc_rr(rr): cpu = CPU() cpu.set_reg16(rr, 0xABCD) INC_RR(rr).exec(cpu) assert cpu.get_reg16(rr) == 0xABCE assert cpu.cycles == 8 @pytest.mark.parametrize("rr", set(R16) - {R16.AF}) def test_dec_rr(rr): cpu = CPU() cpu.set_reg16(rr, 0xABCD) DEC_RR(rr).exec(cpu) assert cpu.get_reg16(rr) == 0xABCC assert cpu.cycles == 8 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.carry == 0 assert cpu.cycles == 16 ADD_SP_DD(2).exec(cpu) assert cpu.get_reg16(R16.SP) == 0 assert cpu.carry == 1 assert cpu.cycles == 32 ADD_SP_DD(-1).exec(cpu) assert cpu.get_reg16(R16.SP) == 0xFFFF assert cpu.carry == 1 assert cpu.cycles == 48 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.carry == 1 assert cpu.cycles == 12 cpu.set_reg16(R16.SP, 0) LD_HL_SP_DD(-1).exec(cpu) assert cpu.get_reg16(R16.HL) == 0xFFFF assert cpu.carry == 1 assert cpu.cycles == 24 cpu.set_reg16(R16.SP, 0xFFFF) LD_HL_SP_DD(-2).exec(cpu) assert cpu.get_reg16(R16.HL) == 0xFFFD assert cpu.carry == 0 assert cpu.cycles == 36