import pytest from tests.insn.helpers import * @pytest.mark.parametrize("dst,src", [(x, y) for x in R8 for y in R8]) def test_ld_r_r(dst, src): cpu = CPU() cpu.set_reg8(src, 0x7F) LD_R_R(dst, src).exec(cpu) assert cpu.get_reg8(src) == 0x7F @pytest.mark.parametrize("r,imm", [(r, imm) for r in R8 for imm in n8()]) def test_ld_r_n8(r, imm): cpu = CPU() LD_R_N8(r, 0x7F).exec(cpu) assert cpu.get_reg8(r) == 0x7F @pytest.mark.parametrize("r", R8) def test_ld_r_hl(r): cpu = CPU() cpu.set_reg16(R16.HL, 0x1234) cpu.set_mem8(0x1234, 0x7F) LD_R_HL(r).exec(cpu) assert cpu.get_reg8(r) == 0x7F @pytest.mark.parametrize("r", R8) def test_ld_hl_r(r): cpu = CPU() cpu.set_reg8(r, 0x7F) cpu.set_reg16(R16.HL, 0x1234) LD_HL_R(r).exec(cpu) if r == R8.H: assert cpu.hl == 0x12 elif r == R8.L: assert cpu.hl == 0x34 else: assert cpu.hl == 0x7F @pytest.mark.parametrize("imm", n8()) def test_ld_hl_n8(imm): cpu = CPU() cpu.set_reg16(R16.HL, 0x1234) LD_HL_N(imm).exec(cpu) assert cpu.hl == imm def test_ld_a_bc(): cpu = CPU() cpu.set_reg16(R16.BC, 0x1234) cpu.set_mem8(0x1234, 0x7F) LD_A_BC().exec(cpu) assert cpu.get_reg8(R8.A) == 0x7F def test_ld_a_de(): cpu = CPU() cpu.set_reg16(R16.DE, 0x1234) cpu.set_mem8(0x1234, 0x7F) LD_A_DE().exec(cpu) assert cpu.get_reg8(R8.A) == 0x7F # @pytest.mark.parametrize("nn", n16()) def test_ld_a_nn(nn=0x1234): cpu = CPU() cpu.set_mem8(nn, 0x7F) LD_A_NN(nn).exec(cpu) assert cpu.get_reg8(R8.A) == 0x7F def test_ld_bc_a(): cpu = CPU() cpu.set_reg16(R16.BC, 0x1234) cpu.set_reg8(R8.A, 0x7F) LD_BC_A().exec(cpu) assert cpu.get_mem8(0x1234) == 0x7F def test_ld_de_a(): cpu = CPU() cpu.set_reg16(R16.DE, 0x1234) cpu.set_reg8(R8.A, 0x7F) LD_DE_A().exec(cpu) assert cpu.get_mem8(0x1234) == 0x7F # @pytest.mark.parametrize("nn", n16()) def test_ld_nn_a(nn=0x1234): cpu = CPU() cpu.set_reg8(R8.A, 0x7F) LD_NN_A(nn).exec(cpu) assert cpu.get_mem8(nn) == 0x7F @pytest.mark.parametrize("n", n8()) def test_ld_a_ff_n(n): cpu = CPU() cpu.set_mem8(0xFF00 + n, 0x7F) LD_A_FF_N(n).exec(cpu) assert cpu.get_reg8(R8.A) == 0x7F @pytest.mark.parametrize("n", n8()) def test_ld_ff_n_a(n): cpu = CPU() cpu.set_reg8(R8.A, 0x7F) LD_FF_N_A(n).exec(cpu) assert cpu.get_mem8(0xFF00 + n) == 0x7F def test_ld_a_ff_c(): cpu = CPU() cpu.set_reg8(R8.C, 0x12) cpu.set_mem8(0xFF12, 0x7F) LD_A_FF_C().exec(cpu) assert cpu.get_reg8(R8.A) == 0x7F def test_ld_ff_c_a(): cpu = CPU() cpu.set_reg8(R8.C, 0x12) cpu.set_reg8(R8.A, 0x7F) LD_FF_C_A().exec(cpu) assert cpu.get_mem8(0xFF12) == 0x7F def test_ldi_hl_a(): cpu = CPU() cpu.set_reg8(R8.A, 0x7F) cpu.set_reg16(R16.HL, 0x1234) LDI_HL_A().exec(cpu) assert cpu.get_reg16(R16.HL) == 0x1235 assert cpu.get_mem8(0x1234) == 0x7F def test_ldi_a_hl(): cpu = CPU() cpu.set_mem8(0x1234, 0x7F) cpu.set_reg16(R16.HL, 0x1234) LDI_A_HL().exec(cpu) assert cpu.get_reg16(R16.HL) == 0x1235 assert cpu.get_reg8(R8.A) == 0x7F def test_ldd_hl_a(): cpu = CPU() cpu.set_reg8(R8.A, 0x7F) cpu.set_reg16(R16.HL, 0x1234) LDD_HL_A().exec(cpu) assert cpu.get_reg16(R16.HL) == 0x1233 assert cpu.get_mem8(0x1234) == 0x7F def test_ldd_a_hl(): cpu = CPU() cpu.set_mem8(0x1234, 0x7F) cpu.set_reg16(R16.HL, 0x1234) LDD_A_HL().exec(cpu) assert cpu.get_reg16(R16.HL) == 0x1233 assert cpu.get_reg8(R8.A) == 0x7F