Browse Source

Add some tests for 16-bit ALU instructions

master
Forest Belton 2 years ago
parent
commit
d069e44609
2 changed files with 48 additions and 0 deletions
  1. +3
    -0
      gbso/insn.py
  2. +45
    -0
      tests/insn/test_alu16.py

+ 3
- 0
gbso/insn.py View File

@ -680,6 +680,7 @@ class ADD_HL_RR(Insn):
hl = cpu.get_reg16(R16.HL) + cpu.get_reg16(self.rr)
cpu.carry = 1 if hl > 0xFFFF else 0
cpu.set_reg16(R16.HL, hl)
cpu.cycles += 8
def pretty(self) -> str:
return f"ADD HL, {self.rr.value}"
@ -691,6 +692,7 @@ class INC_RR(Insn):
def exec(self, cpu: CPU) -> None:
cpu.set_reg16(self.rr, cpu.get_reg16(self.rr) + 1)
cpu.cycles += 8
def pretty(self) -> str:
return f"INC {self.rr.value}"
@ -702,6 +704,7 @@ class DEC_RR(Insn):
def exec(self, cpu: CPU) -> None:
cpu.set_reg16(self.rr, cpu.get_reg16(self.rr) - 1)
cpu.cycles += 8
def pretty(self) -> str:
return f"DEC {self.rr.value}"

+ 45
- 0
tests/insn/test_alu16.py View File

@ -0,0 +1,45 @@
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.carry == 0
assert cpu.cycles == 8
cpu.set_reg16(rr, 0xFFFF - 0xBE01 + 1)
ADD_HL_RR(rr).exec(cpu)
assert cpu.get_reg16(R16.HL) == 0
assert cpu.carry == 1
assert cpu.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.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.cycles == 8

Loading…
Cancel
Save