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

import pytest
from tests.insn.helpers import *
@pytest.mark.parametrize("rr", set(R16) - {R16.AF})
def test_ld_rr_nn(rr):
cpu = CPU()
LD_RR_NN(rr, 0x1234).exec(cpu)
assert cpu.get_reg16(rr) == 0x1234
assert cpu.cycles == 12
def test_ld_nn_sp():
cpu = CPU()
cpu.set_reg16(R16.SP, 0xABCD)
LD_NN_SP(0x1234).exec(cpu)
assert cpu.get_mem16(0x1234) == 0xABCD
assert cpu.cycles == 20
def test_ld_sp_hl():
cpu = CPU()
cpu.set_reg16(R16.HL, 0x1234)
LD_SP_HL().exec(cpu)
assert cpu.get_reg16(R16.SP) == 0x1234
assert cpu.cycles == 8
@pytest.mark.parametrize("rr", set(R16) - {R16.AF, R16.SP})
def test_push_rr(rr):
cpu = CPU()
cpu.set_reg16(R16.SP, 0xFFFF)
cpu.set_reg16(rr, 0x1234)
PUSH_RR(rr).exec(cpu)
assert cpu.get_reg16(R16.SP) == 0xFFFD
assert cpu.get_mem16(0xFFFD) == 0x1234
assert cpu.cycles == 16
@pytest.mark.parametrize("rr", set(R16) - {R16.AF, R16.SP})
def test_pop_rr(rr):
cpu = CPU()
cpu.set_reg16(R16.SP, 0xFFFD)
cpu.set_mem16(0xFFFD, 0x1234)
POP_RR(rr).exec(cpu)
assert cpu.get_reg16(R16.SP) == 0xFFFF
assert cpu.get_reg16(rr) == 0x1234
assert cpu.cycles == 12