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.

93 lines
1.9 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.carry == 0
  11. assert cpu.cycles == 8
  12. cpu.set_reg16(rr, 0xFFFF - 0xBE01 + 1)
  13. ADD_HL_RR(rr).exec(cpu)
  14. assert cpu.get_reg16(R16.HL) == 0
  15. assert cpu.carry == 1
  16. assert cpu.cycles == 16
  17. @pytest.mark.parametrize("rr", set(R16) - {R16.AF})
  18. def test_inc_rr(rr):
  19. cpu = CPU()
  20. cpu.set_reg16(rr, 0xABCD)
  21. INC_RR(rr).exec(cpu)
  22. assert cpu.get_reg16(rr) == 0xABCE
  23. assert cpu.cycles == 8
  24. @pytest.mark.parametrize("rr", set(R16) - {R16.AF})
  25. def test_dec_rr(rr):
  26. cpu = CPU()
  27. cpu.set_reg16(rr, 0xABCD)
  28. DEC_RR(rr).exec(cpu)
  29. assert cpu.get_reg16(rr) == 0xABCC
  30. assert cpu.cycles == 8
  31. def test_add_sp_dd():
  32. cpu = CPU()
  33. cpu.set_reg16(R16.SP, 0xFFFF)
  34. ADD_SP_DD(-1).exec(cpu)
  35. assert cpu.get_reg16(R16.SP) == 0xFFFE
  36. assert cpu.carry == 0
  37. assert cpu.cycles == 16
  38. ADD_SP_DD(2).exec(cpu)
  39. assert cpu.get_reg16(R16.SP) == 0
  40. assert cpu.carry == 1
  41. assert cpu.cycles == 32
  42. ADD_SP_DD(-1).exec(cpu)
  43. assert cpu.get_reg16(R16.SP) == 0xFFFF
  44. assert cpu.carry == 1
  45. assert cpu.cycles == 48
  46. def test_ld_hl_sp_dd():
  47. cpu = CPU()
  48. cpu.set_reg16(R16.SP, 0xFFFF)
  49. LD_HL_SP_DD(1).exec(cpu)
  50. assert cpu.get_reg16(R16.HL) == 0
  51. assert cpu.carry == 1
  52. assert cpu.cycles == 12
  53. cpu.set_reg16(R16.SP, 0)
  54. LD_HL_SP_DD(-1).exec(cpu)
  55. assert cpu.get_reg16(R16.HL) == 0xFFFF
  56. assert cpu.carry == 1
  57. assert cpu.cycles == 24
  58. cpu.set_reg16(R16.SP, 0xFFFF)
  59. LD_HL_SP_DD(-2).exec(cpu)
  60. assert cpu.get_reg16(R16.HL) == 0xFFFD
  61. assert cpu.carry == 0
  62. assert cpu.cycles == 36