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.

146 lines
2.5 KiB

  1. import pytest
  2. from tests.insn.helpers import *
  3. def test_rlca():
  4. cpu = CPU()
  5. cpu.set_reg8(R8.A, 0x80)
  6. RLCA().exec(cpu)
  7. assert cpu.get_reg8(R8.A) == 0x01
  8. assert cpu.carry == 1
  9. assert cpu.cycles == 4
  10. RLCA().exec(cpu)
  11. assert cpu.get_reg8(R8.A) == 0x02
  12. assert cpu.carry == 0
  13. assert cpu.cycles == 8
  14. def test_rla():
  15. cpu = CPU()
  16. cpu.set_reg8(R8.A, 0x80)
  17. RLA().exec(cpu)
  18. assert cpu.get_reg8(R8.A) == 0x00
  19. assert cpu.carry == 1
  20. assert cpu.cycles == 4
  21. RLA().exec(cpu)
  22. assert cpu.get_reg8(R8.A) == 0x01
  23. assert cpu.carry == 0
  24. assert cpu.cycles == 8
  25. def test_rrca():
  26. cpu = CPU()
  27. cpu.set_reg8(R8.A, 0x01)
  28. RRCA().exec(cpu)
  29. assert cpu.get_reg8(R8.A) == 0x80
  30. assert cpu.carry == 1
  31. assert cpu.cycles == 4
  32. RRCA().exec(cpu)
  33. assert cpu.get_reg8(R8.A) == 0x40
  34. assert cpu.carry == 0
  35. assert cpu.cycles == 8
  36. def test_rra():
  37. cpu = CPU()
  38. cpu.set_reg8(R8.A, 0x01)
  39. RRA().exec(cpu)
  40. assert cpu.get_reg8(R8.A) == 0x00
  41. assert cpu.carry == 1
  42. assert cpu.cycles == 4
  43. RRA().exec(cpu)
  44. assert cpu.get_reg8(R8.A) == 0x80
  45. assert cpu.carry == 0
  46. assert cpu.cycles == 8
  47. @pytest.mark.parametrize("r", R8)
  48. def test_rlc_r(r):
  49. cpu = CPU()
  50. cpu.set_reg8(r, 0x80)
  51. RLC_R(r).exec(cpu)
  52. assert cpu.get_reg8(r) == 0x01
  53. assert cpu.carry == 1
  54. assert cpu.cycles == 8
  55. RLC_R(r).exec(cpu)
  56. assert cpu.get_reg8(r) == 0x02
  57. assert cpu.carry == 0
  58. assert cpu.cycles == 16
  59. @pytest.mark.parametrize("r", R8)
  60. def test_rl_r(r):
  61. cpu = CPU()
  62. cpu.set_reg8(r, 0x80)
  63. RL_R(r).exec(cpu)
  64. assert cpu.get_reg8(r) == 0x00
  65. assert cpu.carry == 1
  66. assert cpu.cycles == 8
  67. RL_R(r).exec(cpu)
  68. assert cpu.get_reg8(r) == 0x01
  69. assert cpu.carry == 0
  70. assert cpu.cycles == 16
  71. @pytest.mark.parametrize("r", R8)
  72. def test_rrc_r(r):
  73. cpu = CPU()
  74. cpu.set_reg8(r, 0x01)
  75. RRC_R(r).exec(cpu)
  76. assert cpu.get_reg8(r) == 0x80
  77. assert cpu.carry == 1
  78. assert cpu.cycles == 8
  79. RRC_R(r).exec(cpu)
  80. assert cpu.get_reg8(r) == 0x40
  81. assert cpu.carry == 0
  82. assert cpu.cycles == 16
  83. @pytest.mark.parametrize("r", R8)
  84. def test_rr_r(r):
  85. cpu = CPU()
  86. cpu.set_reg8(r, 0x01)
  87. RR_R(r).exec(cpu)
  88. assert cpu.get_reg8(r) == 0x00
  89. assert cpu.carry == 1
  90. assert cpu.cycles == 8
  91. RR_R(r).exec(cpu)
  92. assert cpu.get_reg8(r) == 0x80
  93. assert cpu.carry == 0
  94. assert cpu.cycles == 16
  95. # TODO: Test RLC_HL, RL_HL, RRC_HL, RR_HL