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.

83 lines
1.6 KiB

  1. import pytest
  2. from tests.insn.helpers import *
  3. @pytest.mark.parametrize("rr", set(R16) - {R16.AF, R16.HL})
  4. def test_add_hl_rr(rr):
  5. cpu = CPU()
  6. cpu.set_reg16(R16.HL, 0xABCD)
  7. cpu.set_reg16(rr, 0x1234)
  8. ADD_HL_RR(rr).exec(cpu)
  9. assert cpu.get_reg16(R16.HL) == 0xBE01
  10. assert cpu.state.carry == 0
  11. cpu.set_reg16(rr, 0xFFFF - 0xBE01 + 1)
  12. ADD_HL_RR(rr).exec(cpu)
  13. assert cpu.get_reg16(R16.HL) == 0
  14. assert cpu.state.carry == 1
  15. @pytest.mark.parametrize("rr", set(R16) - {R16.AF})
  16. def test_inc_rr(rr):
  17. cpu = CPU()
  18. cpu.set_reg16(rr, 0xABCD)
  19. INC_RR(rr).exec(cpu)
  20. assert cpu.get_reg16(rr) == 0xABCE
  21. @pytest.mark.parametrize("rr", set(R16) - {R16.AF})
  22. def test_dec_rr(rr):
  23. cpu = CPU()
  24. cpu.set_reg16(rr, 0xABCD)
  25. DEC_RR(rr).exec(cpu)
  26. assert cpu.get_reg16(rr) == 0xABCC
  27. def test_add_sp_dd():
  28. cpu = CPU()
  29. cpu.set_reg16(R16.SP, 0xFFFF)
  30. ADD_SP_DD(-1).exec(cpu)
  31. assert cpu.get_reg16(R16.SP) == 0xFFFE
  32. assert cpu.state.carry == 0
  33. ADD_SP_DD(2).exec(cpu)
  34. assert cpu.get_reg16(R16.SP) == 0
  35. assert cpu.state.carry == 1
  36. ADD_SP_DD(-1).exec(cpu)
  37. assert cpu.get_reg16(R16.SP) == 0xFFFF
  38. assert cpu.state.carry == 1
  39. def test_ld_hl_sp_dd():
  40. cpu = CPU()
  41. cpu.set_reg16(R16.SP, 0xFFFF)
  42. LD_HL_SP_DD(1).exec(cpu)
  43. assert cpu.get_reg16(R16.HL) == 0
  44. assert cpu.state.carry == 1
  45. cpu.set_reg16(R16.SP, 0)
  46. LD_HL_SP_DD(-1).exec(cpu)
  47. assert cpu.get_reg16(R16.HL) == 0xFFFF
  48. assert cpu.state.carry == 1
  49. cpu.set_reg16(R16.SP, 0xFFFF)
  50. LD_HL_SP_DD(-2).exec(cpu)
  51. assert cpu.get_reg16(R16.HL) == 0xFFFD
  52. assert cpu.state.carry == 0