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
2.0 KiB

import pytest
from tests.insn.helpers import *
@pytest.mark.parametrize("rr", set(R16) - {R16.AF, R16.HL})
def test_add_hl_rr(rr):
cpu = CPU()
cpu.set_reg16(R16.HL, 0xABCD)
cpu.set_reg16(rr, 0x1234)
ADD_HL_RR(rr).exec(cpu)
assert cpu.get_reg16(R16.HL) == 0xBE01
assert cpu.state.carry == 0
assert cpu.state.cycles == 8
cpu.set_reg16(rr, 0xFFFF - 0xBE01 + 1)
ADD_HL_RR(rr).exec(cpu)
assert cpu.get_reg16(R16.HL) == 0
assert cpu.state.carry == 1
assert cpu.state.cycles == 16
@pytest.mark.parametrize("rr", set(R16) - {R16.AF})
def test_inc_rr(rr):
cpu = CPU()
cpu.set_reg16(rr, 0xABCD)
INC_RR(rr).exec(cpu)
assert cpu.get_reg16(rr) == 0xABCE
assert cpu.state.cycles == 8
@pytest.mark.parametrize("rr", set(R16) - {R16.AF})
def test_dec_rr(rr):
cpu = CPU()
cpu.set_reg16(rr, 0xABCD)
DEC_RR(rr).exec(cpu)
assert cpu.get_reg16(rr) == 0xABCC
assert cpu.state.cycles == 8
def test_add_sp_dd():
cpu = CPU()
cpu.set_reg16(R16.SP, 0xFFFF)
ADD_SP_DD(-1).exec(cpu)
assert cpu.get_reg16(R16.SP) == 0xFFFE
assert cpu.state.carry == 0
assert cpu.state.cycles == 16
ADD_SP_DD(2).exec(cpu)
assert cpu.get_reg16(R16.SP) == 0
assert cpu.state.carry == 1
assert cpu.state.cycles == 32
ADD_SP_DD(-1).exec(cpu)
assert cpu.get_reg16(R16.SP) == 0xFFFF
assert cpu.state.carry == 1
assert cpu.state.cycles == 48
def test_ld_hl_sp_dd():
cpu = CPU()
cpu.set_reg16(R16.SP, 0xFFFF)
LD_HL_SP_DD(1).exec(cpu)
assert cpu.get_reg16(R16.HL) == 0
assert cpu.state.carry == 1
assert cpu.state.cycles == 12
cpu.set_reg16(R16.SP, 0)
LD_HL_SP_DD(-1).exec(cpu)
assert cpu.get_reg16(R16.HL) == 0xFFFF
assert cpu.state.carry == 1
assert cpu.state.cycles == 24
cpu.set_reg16(R16.SP, 0xFFFF)
LD_HL_SP_DD(-2).exec(cpu)
assert cpu.get_reg16(R16.HL) == 0xFFFD
assert cpu.state.carry == 0
assert cpu.state.cycles == 36