|
|
- import pytest
-
- from tests.insn.helpers import *
-
-
- @pytest.mark.parametrize("rr", set(R16) - {R16.AF})
- def test_ld_rr_nn(rr):
- cpu = CPU()
-
- LD_RR_NN(rr, 0x1234).exec(cpu)
-
- assert cpu.get_reg16(rr) == 0x1234
- assert cpu.state.cycles == 12
-
-
- def test_ld_nn_sp():
- cpu = CPU()
- cpu.set_reg16(R16.SP, 0xABCD)
-
- LD_NN_SP(0x1234).exec(cpu)
-
- assert cpu.get_mem16(0x1234) == 0xABCD
- assert cpu.state.cycles == 20
-
-
- def test_ld_sp_hl():
- cpu = CPU()
- cpu.set_reg16(R16.HL, 0x1234)
-
- LD_SP_HL().exec(cpu)
-
- assert cpu.get_reg16(R16.SP) == 0x1234
- assert cpu.state.cycles == 8
-
-
- @pytest.mark.parametrize("rr", set(R16) - {R16.AF, R16.SP})
- def test_push_rr(rr):
- cpu = CPU()
- cpu.set_reg16(R16.SP, 0xFFFF)
- cpu.set_reg16(rr, 0x1234)
-
- PUSH_RR(rr).exec(cpu)
-
- assert cpu.get_reg16(R16.SP) == 0xFFFD
- assert cpu.get_mem16(0xFFFD) == 0x1234
- assert cpu.state.cycles == 16
-
-
- @pytest.mark.parametrize("rr", set(R16) - {R16.AF, R16.SP})
- def test_pop_rr(rr):
- cpu = CPU()
- cpu.set_reg16(R16.SP, 0xFFFD)
- cpu.set_mem16(0xFFFD, 0x1234)
-
- POP_RR(rr).exec(cpu)
-
- assert cpu.get_reg16(R16.SP) == 0xFFFF
- assert cpu.get_reg16(rr) == 0x1234
- assert cpu.state.cycles == 12
|