gameboy superoptimizer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.2 KiB

  1. import pytest
  2. from tests.insn.helpers import *
  3. @pytest.mark.parametrize("rr", set(R16) - {R16.AF})
  4. def test_ld_rr_nn(rr):
  5. cpu = CPU()
  6. LD_RR_NN(rr, 0x1234).exec(cpu)
  7. assert cpu.get_reg16(rr) == 0x1234
  8. assert cpu.cycles == 12
  9. def test_ld_nn_sp():
  10. cpu = CPU()
  11. cpu.set_reg16(R16.SP, 0xABCD)
  12. LD_NN_SP(0x1234).exec(cpu)
  13. assert cpu.get_mem16(0x1234) == 0xABCD
  14. assert cpu.cycles == 20
  15. def test_ld_sp_hl():
  16. cpu = CPU()
  17. cpu.set_reg16(R16.HL, 0x1234)
  18. LD_SP_HL().exec(cpu)
  19. assert cpu.get_reg16(R16.SP) == 0x1234
  20. assert cpu.cycles == 8
  21. @pytest.mark.parametrize("rr", set(R16) - {R16.AF, R16.SP})
  22. def test_push_rr(rr):
  23. cpu = CPU()
  24. cpu.set_reg16(R16.SP, 0xFFFF)
  25. cpu.set_reg16(rr, 0x1234)
  26. PUSH_RR(rr).exec(cpu)
  27. assert cpu.get_reg16(R16.SP) == 0xFFFD
  28. assert cpu.get_mem16(0xFFFD) == 0x1234
  29. assert cpu.cycles == 16
  30. @pytest.mark.parametrize("rr", set(R16) - {R16.AF, R16.SP})
  31. def test_pop_rr(rr):
  32. cpu = CPU()
  33. cpu.set_reg16(R16.SP, 0xFFFD)
  34. cpu.set_mem16(0xFFFD, 0x1234)
  35. POP_RR(rr).exec(cpu)
  36. assert cpu.get_reg16(R16.SP) == 0xFFFF
  37. assert cpu.get_reg16(rr) == 0x1234
  38. assert cpu.cycles == 12