|
@ -12,14 +12,12 @@ def test_add_a_r(r): |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == 0x7F |
|
|
assert cpu.get_reg8(R8.A) == 0x7F |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.cycles == 4 |
|
|
|
|
|
|
|
|
|
|
|
cpu.set_reg8(r, 0x81) |
|
|
cpu.set_reg8(r, 0x81) |
|
|
ADD_A_R(r).exec(cpu) |
|
|
ADD_A_R(r).exec(cpu) |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == 0x00 |
|
|
assert cpu.get_reg8(R8.A) == 0x00 |
|
|
assert cpu.state.carry == 1 |
|
|
assert cpu.state.carry == 1 |
|
|
assert cpu.state.cycles == 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("n", n8()) |
|
|
@pytest.mark.parametrize("n", n8()) |
|
@ -31,7 +29,6 @@ def test_add_a_n(n): |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == (0x7F + n) & 0xFF |
|
|
assert cpu.get_reg8(R8.A) == (0x7F + n) & 0xFF |
|
|
assert cpu.state.carry == (1 if n >= 0x81 else 0) |
|
|
assert cpu.state.carry == (1 if n >= 0x81 else 0) |
|
|
assert cpu.state.cycles == 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_add_a_hl(): |
|
|
def test_add_a_hl(): |
|
@ -43,14 +40,12 @@ def test_add_a_hl(): |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == 0x7F |
|
|
assert cpu.get_reg8(R8.A) == 0x7F |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.cycles == 8 |
|
|
|
|
|
|
|
|
|
|
|
cpu.set_mem8(0x1234, 0x81) |
|
|
cpu.set_mem8(0x1234, 0x81) |
|
|
ADD_A_HL().exec(cpu) |
|
|
ADD_A_HL().exec(cpu) |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == 0 |
|
|
assert cpu.get_reg8(R8.A) == 0 |
|
|
assert cpu.state.carry == 1 |
|
|
assert cpu.state.carry == 1 |
|
|
assert cpu.state.cycles == 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("r", set(R8) - {R8.A}) |
|
|
@pytest.mark.parametrize("r", set(R8) - {R8.A}) |
|
@ -62,21 +57,18 @@ def test_adc_a_r(r): |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == 0x7F |
|
|
assert cpu.get_reg8(R8.A) == 0x7F |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.cycles == 4 |
|
|
|
|
|
|
|
|
|
|
|
cpu.set_reg8(r, 0x81) |
|
|
cpu.set_reg8(r, 0x81) |
|
|
ADC_A_R(r).exec(cpu) |
|
|
ADC_A_R(r).exec(cpu) |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == 0x00 |
|
|
assert cpu.get_reg8(R8.A) == 0x00 |
|
|
assert cpu.state.carry == 1 |
|
|
assert cpu.state.carry == 1 |
|
|
assert cpu.state.cycles == 8 |
|
|
|
|
|
|
|
|
|
|
|
cpu.set_reg8(r, 0x00) |
|
|
cpu.set_reg8(r, 0x00) |
|
|
ADC_A_R(r).exec(cpu) |
|
|
ADC_A_R(r).exec(cpu) |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == 0x01 |
|
|
assert cpu.get_reg8(R8.A) == 0x01 |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.cycles == 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("n", n8()) |
|
|
@pytest.mark.parametrize("n", n8()) |
|
@ -88,7 +80,6 @@ def test_adc_a_n(n): |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == (0x7F + n) & 0xFF |
|
|
assert cpu.get_reg8(R8.A) == (0x7F + n) & 0xFF |
|
|
assert cpu.state.carry == (1 if n >= 0x81 else 0) |
|
|
assert cpu.state.carry == (1 if n >= 0x81 else 0) |
|
|
assert cpu.state.cycles == 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_adc_a_hl(): |
|
|
def test_adc_a_hl(): |
|
@ -100,21 +91,18 @@ def test_adc_a_hl(): |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == 0x7F |
|
|
assert cpu.get_reg8(R8.A) == 0x7F |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.cycles == 8 |
|
|
|
|
|
|
|
|
|
|
|
cpu.hl = 0x81 |
|
|
cpu.hl = 0x81 |
|
|
ADC_A_HL().exec(cpu) |
|
|
ADC_A_HL().exec(cpu) |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == 0 |
|
|
assert cpu.get_reg8(R8.A) == 0 |
|
|
assert cpu.state.carry == 1 |
|
|
assert cpu.state.carry == 1 |
|
|
assert cpu.state.cycles == 16 |
|
|
|
|
|
|
|
|
|
|
|
cpu.hl = 0x00 |
|
|
cpu.hl = 0x00 |
|
|
ADC_A_HL().exec(cpu) |
|
|
ADC_A_HL().exec(cpu) |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == 1 |
|
|
assert cpu.get_reg8(R8.A) == 1 |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.cycles == 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: SUB_A_R, SUB_A_N, SUB_A_HL, SBC_A_R, SBC_A_N, SBC_A_HL |
|
|
# TODO: SUB_A_R, SUB_A_N, SUB_A_HL, SBC_A_R, SBC_A_N, SBC_A_HL |
|
@ -130,7 +118,6 @@ def test_and_a_r(r): |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == 0x12 |
|
|
assert cpu.get_reg8(R8.A) == 0x12 |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.cycles == 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("n", n8()) |
|
|
@pytest.mark.parametrize("n", n8()) |
|
@ -142,7 +129,6 @@ def test_and_a_n(n): |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == 0x12 & n |
|
|
assert cpu.get_reg8(R8.A) == 0x12 & n |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.cycles == 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_and_a_hl(): |
|
|
def test_and_a_hl(): |
|
@ -156,7 +142,6 @@ def test_and_a_hl(): |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == 0x12 |
|
|
assert cpu.get_reg8(R8.A) == 0x12 |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.cycles == 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("r", set(R8) - {R8.A}) |
|
|
@pytest.mark.parametrize("r", set(R8) - {R8.A}) |
|
@ -169,7 +154,6 @@ def test_xor_a_r(r): |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == 0x6D |
|
|
assert cpu.get_reg8(R8.A) == 0x6D |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.cycles == 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("n", n8()) |
|
|
@pytest.mark.parametrize("n", n8()) |
|
@ -181,7 +165,6 @@ def test_xor_a_n(n): |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == 0x12 ^ n |
|
|
assert cpu.get_reg8(R8.A) == 0x12 ^ n |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.cycles == 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_xor_a_hl(): |
|
|
def test_xor_a_hl(): |
|
@ -195,7 +178,6 @@ def test_xor_a_hl(): |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == 0x6D |
|
|
assert cpu.get_reg8(R8.A) == 0x6D |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.cycles == 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("r", set(R8) - {R8.A}) |
|
|
@pytest.mark.parametrize("r", set(R8) - {R8.A}) |
|
@ -208,7 +190,6 @@ def test_or_a_r(r): |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == 0x7F |
|
|
assert cpu.get_reg8(R8.A) == 0x7F |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.cycles == 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("n", n8()) |
|
|
@pytest.mark.parametrize("n", n8()) |
|
@ -220,7 +201,6 @@ def test_or_a_n(n): |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == 0x12 | n |
|
|
assert cpu.get_reg8(R8.A) == 0x12 | n |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.cycles == 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_or_a_hl(): |
|
|
def test_or_a_hl(): |
|
@ -234,7 +214,6 @@ def test_or_a_hl(): |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == 0x7F |
|
|
assert cpu.get_reg8(R8.A) == 0x7F |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.cycles == 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("r", set(R8) - {R8.A}) |
|
|
@pytest.mark.parametrize("r", set(R8) - {R8.A}) |
|
@ -247,14 +226,12 @@ def test_cp_a_r(r): |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == 0x7F |
|
|
assert cpu.get_reg8(R8.A) == 0x7F |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.cycles == 4 |
|
|
|
|
|
|
|
|
|
|
|
cpu.set_reg8(r, 0x80) |
|
|
cpu.set_reg8(r, 0x80) |
|
|
CP_A_R(r).exec(cpu) |
|
|
CP_A_R(r).exec(cpu) |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == 0x7F |
|
|
assert cpu.get_reg8(R8.A) == 0x7F |
|
|
assert cpu.state.carry == 1 |
|
|
assert cpu.state.carry == 1 |
|
|
assert cpu.state.cycles == 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("n", n8()) |
|
|
@pytest.mark.parametrize("n", n8()) |
|
@ -266,7 +243,6 @@ def test_cp_a_n(n): |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == 0x12 |
|
|
assert cpu.get_reg8(R8.A) == 0x12 |
|
|
assert cpu.state.carry == (1 if 0x12 < n else 0) |
|
|
assert cpu.state.carry == (1 if 0x12 < n else 0) |
|
|
assert cpu.state.cycles == 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_cp_a_hl(): |
|
|
def test_cp_a_hl(): |
|
@ -280,7 +256,6 @@ def test_cp_a_hl(): |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == 0x7F |
|
|
assert cpu.get_reg8(R8.A) == 0x7F |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.carry == 0 |
|
|
assert cpu.state.cycles == 8 |
|
|
|
|
|
|
|
|
|
|
|
cpu.set_mem8(0x1234, 0x80) |
|
|
cpu.set_mem8(0x1234, 0x80) |
|
|
|
|
|
|
|
@ -288,7 +263,6 @@ def test_cp_a_hl(): |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == 0x7F |
|
|
assert cpu.get_reg8(R8.A) == 0x7F |
|
|
assert cpu.state.carry == 1 |
|
|
assert cpu.state.carry == 1 |
|
|
assert cpu.state.cycles == 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("r,n", [(r, n) for r in R8 for n in n8()]) |
|
|
@pytest.mark.parametrize("r,n", [(r, n) for r in R8 for n in n8()]) |
|
@ -299,7 +273,6 @@ def test_inc_r(r, n): |
|
|
INC_R(r).exec(cpu) |
|
|
INC_R(r).exec(cpu) |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(r) == (n + 1) & 0xFF |
|
|
assert cpu.get_reg8(r) == (n + 1) & 0xFF |
|
|
assert cpu.state.cycles == 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("n", n8()) |
|
|
@pytest.mark.parametrize("n", n8()) |
|
@ -311,7 +284,6 @@ def test_inc_hl(n): |
|
|
INC_HL(n).exec(cpu) |
|
|
INC_HL(n).exec(cpu) |
|
|
|
|
|
|
|
|
assert cpu.hl == (n + 1) & 0xFF |
|
|
assert cpu.hl == (n + 1) & 0xFF |
|
|
assert cpu.state.cycles == 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("r,n", [(r, n) for r in R8 for n in n8()]) |
|
|
@pytest.mark.parametrize("r,n", [(r, n) for r in R8 for n in n8()]) |
|
@ -322,7 +294,6 @@ def test_dec_r(r, n): |
|
|
DEC_R(r).exec(cpu) |
|
|
DEC_R(r).exec(cpu) |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(r) == (n - 1) & 0xFF |
|
|
assert cpu.get_reg8(r) == (n - 1) & 0xFF |
|
|
assert cpu.state.cycles == 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("n", n8()) |
|
|
@pytest.mark.parametrize("n", n8()) |
|
@ -334,7 +305,6 @@ def test_dec_hl(n): |
|
|
DEC_HL(n).exec(cpu) |
|
|
DEC_HL(n).exec(cpu) |
|
|
|
|
|
|
|
|
assert cpu.hl == (n - 1) & 0xFF |
|
|
assert cpu.hl == (n - 1) & 0xFF |
|
|
assert cpu.state.cycles == 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# TODO: Test DAA after implementing it |
|
|
# TODO: Test DAA after implementing it |
|
@ -348,4 +318,3 @@ def test_cpl(n): |
|
|
CPL().exec(cpu) |
|
|
CPL().exec(cpu) |
|
|
|
|
|
|
|
|
assert cpu.get_reg8(R8.A) == n ^ 0xFF |
|
|
assert cpu.get_reg8(R8.A) == n ^ 0xFF |
|
|
assert cpu.state.cycles == 4 |
|
|
|