- import pytest
-
- from tests.insn.helpers import *
-
-
- def test_rlca():
- cpu = CPU()
- cpu.set_reg8(R8.A, 0x80)
-
- RLCA().exec(cpu)
-
- assert cpu.get_reg8(R8.A) == 0x01
- assert cpu.state.carry == 1
-
- RLCA().exec(cpu)
-
- assert cpu.get_reg8(R8.A) == 0x02
- assert cpu.state.carry == 0
-
-
- def test_rla():
- cpu = CPU()
- cpu.set_reg8(R8.A, 0x80)
-
- RLA().exec(cpu)
-
- assert cpu.get_reg8(R8.A) == 0x00
- assert cpu.state.carry == 1
-
- RLA().exec(cpu)
-
- assert cpu.get_reg8(R8.A) == 0x01
- assert cpu.state.carry == 0
-
-
- def test_rrca():
- cpu = CPU()
- cpu.set_reg8(R8.A, 0x01)
-
- RRCA().exec(cpu)
-
- assert cpu.get_reg8(R8.A) == 0x80
- assert cpu.state.carry == 1
-
- RRCA().exec(cpu)
-
- assert cpu.get_reg8(R8.A) == 0x40
- assert cpu.state.carry == 0
-
-
- def test_rra():
- cpu = CPU()
- cpu.set_reg8(R8.A, 0x01)
-
- RRA().exec(cpu)
-
- assert cpu.get_reg8(R8.A) == 0x00
- assert cpu.state.carry == 1
-
- RRA().exec(cpu)
-
- assert cpu.get_reg8(R8.A) == 0x80
- assert cpu.state.carry == 0
-
-
- @pytest.mark.parametrize("r", R8)
- def test_rlc_r(r):
- cpu = CPU()
- cpu.set_reg8(r, 0x80)
-
- RLC_R(r).exec(cpu)
-
- assert cpu.get_reg8(r) == 0x01
- assert cpu.state.carry == 1
-
- RLC_R(r).exec(cpu)
-
- assert cpu.get_reg8(r) == 0x02
- assert cpu.state.carry == 0
-
-
- def test_rlc_hl():
- cpu = CPU()
- cpu.hl = 0x80
-
- RLC_HL().exec(cpu)
-
- assert cpu.hl == 0x01
- assert cpu.state.carry == 1
-
- RLC_HL().exec(cpu)
-
- assert cpu.hl == 0x02
- assert cpu.state.carry == 0
-
-
- @pytest.mark.parametrize("r", R8)
- def test_rl_r(r):
- cpu = CPU()
- cpu.set_reg8(r, 0x80)
-
- RL_R(r).exec(cpu)
-
- assert cpu.get_reg8(r) == 0x00
- assert cpu.state.carry == 1
-
- RL_R(r).exec(cpu)
-
- assert cpu.get_reg8(r) == 0x01
- assert cpu.state.carry == 0
-
-
- def test_rl_hl():
- cpu = CPU()
- cpu.hl = 0x80
-
- RL_HL().exec(cpu)
-
- assert cpu.hl == 0x00
- assert cpu.state.carry == 1
-
- RL_HL().exec(cpu)
-
- assert cpu.hl == 0x01
- assert cpu.state.carry == 0
-
-
- @pytest.mark.parametrize("r", R8)
- def test_rrc_r(r):
- cpu = CPU()
- cpu.set_reg8(r, 0x01)
-
- RRC_R(r).exec(cpu)
-
- assert cpu.get_reg8(r) == 0x80
- assert cpu.state.carry == 1
-
- RRC_R(r).exec(cpu)
-
- assert cpu.get_reg8(r) == 0x40
- assert cpu.state.carry == 0
-
-
- def test_rrc_hl():
- cpu = CPU()
- cpu.set_reg16(R16.HL, 0x1234)
- cpu.hl = 0x01
-
- RRC_HL().exec(cpu)
-
- assert cpu.hl == 0x80
- assert cpu.state.carry == 1
-
- RRC_HL().exec(cpu)
-
- assert cpu.hl == 0x40
- assert cpu.state.carry == 0
-
-
- @pytest.mark.parametrize("r", R8)
- def test_rr_r(r):
- cpu = CPU()
- cpu.set_reg8(r, 0x01)
-
- RR_R(r).exec(cpu)
-
- assert cpu.get_reg8(r) == 0x00
- assert cpu.state.carry == 1
-
- RR_R(r).exec(cpu)
-
- assert cpu.get_reg8(r) == 0x80
- assert cpu.state.carry == 0
-
-
- def test_rr_hl():
- cpu = CPU()
- cpu.set_reg16(R16.HL, 0x1234)
- cpu.hl = 0x01
-
- RR_HL().exec(cpu)
-
- assert cpu.hl == 0x00
- assert cpu.state.carry == 1
-
- RR_HL().exec(cpu)
-
- assert cpu.hl == 0x80
- assert cpu.state.carry == 0
-
-
- @pytest.mark.parametrize("r", R8)
- def test_sla_r(r):
- cpu = CPU()
- cpu.set_reg8(r, 0xFF)
-
- SLA_R(r).exec(cpu)
-
- assert cpu.get_reg8(r) == 0xFE
- assert cpu.state.carry == 1
-
- cpu.set_reg8(r, 0x01)
- SLA_R(r).exec(cpu)
-
- assert cpu.get_reg8(r) == 0x02
- assert cpu.state.carry == 0
-
-
- def test_sla_hl():
- cpu = CPU()
- cpu.set_reg16(R16.HL, 0x1234)
- cpu.hl = 0xFF
-
- SLA_HL().exec(cpu)
-
- assert cpu.hl == 0xFE
- assert cpu.state.carry == 1
-
- cpu.hl = 0x01
- SLA_HL().exec(cpu)
-
- assert cpu.hl == 0x02
- assert cpu.state.carry == 0
-
-
- @pytest.mark.parametrize("r", R8)
- def test_swap_r(r):
- cpu = CPU()
- cpu.set_reg8(r, 0xAB)
-
- SWAP_R(r).exec(cpu)
-
- assert cpu.get_reg8(r) == 0xBA
- assert cpu.state.carry == 0
-
-
- def test_swap_hl():
- cpu = CPU()
- cpu.set_reg16(R16.HL, 0x1234)
- cpu.hl = 0xAB
-
- SWAP_HL().exec(cpu)
-
- assert cpu.hl == 0xBA
- assert cpu.state.carry == 0
-
-
- @pytest.mark.parametrize("r", R8)
- def test_sra_r(r):
- cpu = CPU()
- cpu.set_reg8(r, 0xFF)
-
- SRA_R(r).exec(cpu)
-
- assert cpu.get_reg8(r) == 0xFF
- assert cpu.state.carry == 1
-
- cpu.set_reg8(r, 0x02)
- SRA_R(r).exec(cpu)
-
- assert cpu.get_reg8(r) == 0x01
- assert cpu.state.carry == 0
-
-
- def test_sra_hl():
- cpu = CPU()
- cpu.set_reg16(R16.HL, 0x1234)
- cpu.hl = 0xFF
-
- SRA_HL().exec(cpu)
-
- assert cpu.hl == 0xFF
- assert cpu.state.carry == 1
-
- cpu.hl = 0x02
- SRA_HL().exec(cpu)
-
- assert cpu.hl == 0x01
- assert cpu.state.carry == 0
-
-
- @pytest.mark.parametrize("r", R8)
- def test_srl_r(r):
- cpu = CPU()
- cpu.set_reg8(r, 0xFF)
-
- SRL_R(r).exec(cpu)
-
- assert cpu.get_reg8(r) == 0x7F
- assert cpu.state.carry == 1
-
- cpu.set_reg8(r, 0x02)
- SRL_R(r).exec(cpu)
-
- assert cpu.get_reg8(r) == 0x01
- assert cpu.state.carry == 0
-
-
- def test_srl_hl():
- cpu = CPU()
- cpu.set_reg16(R16.HL, 0x1234)
- cpu.hl = 0xFF
-
- SRL_HL().exec(cpu)
-
- assert cpu.hl == 0x7F
- assert cpu.state.carry == 1
-
- cpu.hl = 0x02
- SRL_HL().exec(cpu)
-
- assert cpu.hl == 0x01
- assert cpu.state.carry == 0
|