diff --git a/tests/insn/test_bit.py b/tests/insn/test_bit.py new file mode 100644 index 0000000..2c2613a --- /dev/null +++ b/tests/insn/test_bit.py @@ -0,0 +1,47 @@ +import pytest + +from tests.insn.helpers import * + + +@pytest.mark.parametrize("n,r", [(n, r) for n in range(8) for r in R8]) +def test_set_n_r(n, r): + cpu = CPU() + + SET_N_R(n, r).exec(cpu) + + assert cpu.get_reg8(r) == 1 << n + assert cpu.cycles == 8 + + +@pytest.mark.parametrize("n", range(8)) +def test_set_n_hl(n): + cpu = CPU() + cpu.set_reg16(R16.HL, 0x1234) + + SET_N_HL(n).exec(cpu) + + assert cpu.get_mem8(0x1234) == 1 << n + assert cpu.cycles == 16 + + +@pytest.mark.parametrize("n,r", [(n, r) for n in range(8) for r in R8]) +def test_res_n_r(n, r): + cpu = CPU() + cpu.set_reg8(r, 0xFF) + + RES_N_R(n, r).exec(cpu) + + assert cpu.get_reg8(r) == 0xFF - (1 << n) + assert cpu.cycles == 8 + + +@pytest.mark.parametrize("n", range(8)) +def test_res_n_hl(n): + cpu = CPU() + cpu.set_reg16(R16.HL, 0x1234) + cpu.set_mem8(0x1234, 0xFF) + + RES_N_HL(n).exec(cpu) + + assert cpu.get_mem8(0x1234) == 0xFF - (1 << n) + assert cpu.cycles == 16 diff --git a/tests/insn/test_cpu.py b/tests/insn/test_cpu.py new file mode 100644 index 0000000..3c5dec1 --- /dev/null +++ b/tests/insn/test_cpu.py @@ -0,0 +1,24 @@ +from tests.insn.helpers import * + + +def test_ccf(): + cpu = CPU() + + CCF().exec(cpu) + + assert cpu.carry == 1 + assert cpu.cycles == 4 + + CCF().exec(cpu) + + assert cpu.carry == 0 + assert cpu.cycles == 8 + + +def test_scf(): + cpu = CPU() + + SCF().exec(cpu) + + assert cpu.carry == 1 + assert cpu.cycles == 4