Пример #1
0
def test_BVC_backward():
    mem = MemoryMock([0x50, 0xF9], start=10)
    cpu = CPU65816(mem)
    cpu.P = 0b00000000
    cpu.PC += 10

    cpu.fetch_decode_execute()  # -7

    assert cpu.P == 0b00000000
    assert cpu.cycles == 3
    assert cpu.PC == 5 + mem.header.reset_int_addr  # 10 + 2 - 7
Пример #2
0
def test_BVC_forward():
    mem = MemoryMock([0x50, 0x05])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000
    cpu.PC += 0

    cpu.fetch_decode_execute()

    assert cpu.P == 0b00000000
    assert cpu.cycles == 3
    assert cpu.PC == 7 + mem.header.reset_int_addr  # 0 + 2 + 5
Пример #3
0
def test_BVC_no_branch():
    mem = MemoryMock([0x50, 0x05])
    cpu = CPU65816(mem)
    cpu.P = 0b01000000
    cpu.PC += 0

    cpu.fetch_decode_execute()

    assert cpu.P == 0b01000000
    assert cpu.cycles == 2  # no branch
    assert cpu.PC == 2 + mem.header.reset_int_addr  # 0 + 2
Пример #4
0
def test_BCC_wrapped_execution():
    mem = MemoryMock([0x90, 0x0F], start=0x7FF0)
    cpu = CPU65816(mem)
    cpu.P = 0b00000000
    cpu.PC = 0xFFF0
    cpu.e = 0

    cpu.fetch_decode_execute()  # branches forward

    assert cpu.P == 0b00000000
    assert cpu.cycles == 3
    assert (cpu.PC & 0xFFFF) == 1  # 65520 + 2 + 16
Пример #5
0
def test_XCE():
    mem = MemoryMock([0xFB])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000
    cpu.e = 1

    cpu.fetch_decode_execute()

    assert cpu.e == 0
    assert cpu.P == 0b00000001
    assert cpu.cycles == 2
    assert cpu.PC == 1 + mem.header.reset_int_addr
Пример #6
0
def test_xba3():
    mem = MemoryMock([0xEB])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000  # 16 Bit mode
    cpu.A = 0x0089

    cpu.fetch_decode_execute()

    assert cpu.A == 0x8900
    assert cpu.P == 0b00000010  # result is based on AL
    assert cpu.cycles == 3
    assert cpu.PC == 1 + mem.header.reset_int_addr
Пример #7
0
def test_JMP_abs2():
    mem = MemoryMock([0x4C, 0x34, 0x12], 0x7FF0)
    cpu = CPU65816(mem)
    cpu.P = 0b00000000
    cpu.PC += 0x7FF0

    cpu.fetch_decode_execute()
    print(mem.ram)

    assert cpu.P == 0b00000000
    assert cpu.cycles == 3
    assert cpu.PC == 0x1234
Пример #8
0
def test_BCC_branch_page_boundary():
    mem = MemoryMock([0x90, 0x05], start=253)
    cpu = CPU65816(mem)
    cpu.e = 1
    cpu.P = 0b00110000
    cpu.PC += 253

    cpu.fetch_decode_execute()  # branches forward

    assert cpu.P == 0b00110000
    assert cpu.cycles == 4  # page boundary crossed in emulation mode
    assert cpu.PC == 260 + mem.header.reset_int_addr  # 253 + 2 + 5
Пример #9
0
def test_tcd_negative():
    mem = MemoryMock([0x5B])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000  # 16 Bit mode
    cpu.e = 0
    cpu.A = 0xF234

    cpu.fetch_decode_execute()

    assert cpu.cycles == 2
    assert cpu.DP == 0xF234
    assert cpu.P == 0b10000000  # negative flag
    assert cpu.PC == 1 + mem.header.reset_int_addr
Пример #10
0
def test_tsc():
    mem = MemoryMock([0x3B])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000  # 16 Bit mode
    cpu.e = 0
    cpu.SP = 0x1234

    cpu.fetch_decode_execute()

    assert cpu.cycles == 2
    assert cpu.A == 0x1234
    assert cpu.P == 0b0000000  # no flag
    assert cpu.PC == 1 + mem.header.reset_int_addr
Пример #11
0
def test_DEC_underflow():
    mem = MemoryMock([0x3A])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000  # 16 Bit mode
    cpu.e = 0
    cpu.A = 0x8000  # -32.768 (MIN INT)

    cpu.fetch_decode_execute()

    assert cpu.cycles == 2
    assert cpu.A == 0x7FFF  # 32.767 (Max Int)
    assert cpu.P == 0b00000000  # no negative flag
    assert cpu.PC == 1 + mem.header.reset_int_addr
Пример #12
0
def test_INX_Zero():
    mem = MemoryMock([0xE8])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000  # 16 Bit mode
    cpu.e = 0
    cpu.X = 0xFFFF

    cpu.fetch_decode_execute()

    assert cpu.cycles == 2
    assert cpu.X == 0x0000
    assert cpu.P == 0b00000010  # zero flag
    assert cpu.PC == 1 + mem.header.reset_int_addr
Пример #13
0
def test_LDY_const8Bit():
    mem = MemoryMock([0xA0, 0x34])
    cpu = CPU65816(mem)
    cpu.P = 0b00010000 # 8 Bit mode
    cpu.e = 1
    assert cpu.Y == 0

    cpu.fetch_decode_execute()

    assert cpu.cycles == 2
    assert cpu.Y == 0x34
    assert cpu.P == 0b00010000
    assert cpu.PC == 2 + mem.header.reset_int_addr
Пример #14
0
def test_EOR_8Bit_constant_zero():
    mem = MemoryMock([0x49, 0xFF])
    cpu = CPU65816(mem)
    cpu.P = 0b00100000  # 8 Bit mode
    cpu.e = 0
    cpu.A = 0xFF

    cpu.fetch_decode_execute()

    assert cpu.cycles == 2
    assert cpu.A == 0x00
    assert cpu.P == 0b00100010  # zero flag
    assert cpu.PC == 2 + mem.header.reset_int_addr
Пример #15
0
def test_ORA_16Bit_constant_zero():
    mem = MemoryMock([0x09, 0x00, 0x00])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000  # 16 Bit mode
    cpu.e = 0
    cpu.A = 0x0000

    cpu.fetch_decode_execute()

    assert cpu.cycles == 3
    assert cpu.A == 0x0000
    assert cpu.P == 0b00000010  # zero flag
    assert cpu.PC == 3 + mem.header.reset_int_addr
Пример #16
0
def test_INX_no_overflow_8BIT():
    mem = MemoryMock([0xE8])
    cpu = CPU65816(mem)
    cpu.P = 0b00010000  # 8 Bit mode
    cpu.e = 0
    cpu.X = 0x7F  # 127 (Max Int)

    cpu.fetch_decode_execute()

    assert cpu.cycles == 2
    assert cpu.X == 0x80  # -128 (MIN INT)
    assert cpu.P == 0b10010000  # negative flag, no overflow flag
    assert cpu.PC == 1 + mem.header.reset_int_addr
Пример #17
0
def test_INY():
    mem = MemoryMock([0xC8])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000  # 16 Bit mode
    cpu.e = 0
    cpu.Y = 0x0000

    cpu.fetch_decode_execute()

    assert cpu.cycles == 2
    assert cpu.Y == 0x0001
    assert cpu.P == 0b00000000  # no flag
    assert cpu.PC == 1 + mem.header.reset_int_addr
Пример #18
0
def test_INY_no_overflow():
    mem = MemoryMock([0xC8])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000  # 16 Bit mode
    cpu.e = 0
    cpu.Y = 0x7FFF  # 32.767 (Max Int)

    cpu.fetch_decode_execute()

    assert cpu.cycles == 2
    assert cpu.Y == 0x8000  # -32.768 (MIN INT)
    assert cpu.P == 0b10000000  # negative flag, no overflow flag
    assert cpu.PC == 1 + mem.header.reset_int_addr
Пример #19
0
def test_tcs_16_zero():
    mem = MemoryMock([0x1B])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000  # 16 Bit mode
    cpu.e = 0
    cpu.A = 0x0000

    cpu.fetch_decode_execute()

    assert cpu.cycles == 2
    assert cpu.SP == 0x0000
    assert cpu.P == 0b0000010  # zero flag
    assert cpu.PC == 1 + mem.header.reset_int_addr
Пример #20
0
def test_PHP():
    mem = MemoryMock([0x08])
    cpu = CPU65816(mem)
    cpu.P = 0b10101010  # P
    cpu.SP = 0x01FF

    cpu.fetch_decode_execute()

    assert cpu.P == 0b10101010
    assert mem.read(0x0001FF) == 0b10101010
    assert cpu.SP == 0x01FE
    assert cpu.cycles == 3
    assert cpu.PC == 1 + mem.header.reset_int_addr
Пример #21
0
def test_ORA_8bit_affect_16bit_zero():
    mem = MemoryMock([0x09, 0x00])
    cpu = CPU65816(mem)
    cpu.P = 0b00100000  # 8 Bit mode
    cpu.e = 0
    cpu.A = 0xFF00

    cpu.fetch_decode_execute()

    assert cpu.cycles == 2
    assert cpu.A == 0xFF00
    assert cpu.P == 0b00100010  # zero flag
    assert cpu.PC == 2 + mem.header.reset_int_addr
Пример #22
0
def test_LDY_const16Bit():
    mem = MemoryMock([0xA0, 0x34, 0x12])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000 # 16 Bit mode
    cpu.e = 0
    assert cpu.Y == 0

    cpu.fetch_decode_execute()

    assert cpu.cycles == 3
    assert cpu.Y == 0x1234
    assert cpu.P == 0b00000000
    assert cpu.PC == 3 + mem.header.reset_int_addr
Пример #23
0
def test_EOR_8Bit_affect16bit_negative():
    mem = MemoryMock([0x49, 0x80])
    cpu = CPU65816(mem)
    cpu.P = 0b00100000  # 8 Bit mode
    cpu.e = 0
    cpu.A = 0xFF7F

    cpu.fetch_decode_execute()

    assert cpu.cycles == 2
    assert cpu.A == 0xFFFF
    assert cpu.P == 0b10100000  # negative flag
    assert cpu.PC == 2 + mem.header.reset_int_addr
Пример #24
0
def test_DEY_Zero_8BIT():
    mem = MemoryMock([0x88])
    cpu = CPU65816(mem)
    cpu.P = 0b00010000  # 8 Bit mode
    cpu.e = 0
    cpu.Y = 0x01

    cpu.fetch_decode_execute()

    assert cpu.cycles == 2
    assert cpu.Y == 0x00
    assert cpu.P == 0b00010010  # zero flag
    assert cpu.PC == 1 + mem.header.reset_int_addr
Пример #25
0
def test_DEY_NEG():
    mem = MemoryMock([0x88])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000  # 16 Bit mode
    cpu.e = 0
    cpu.Y = 0x0000

    cpu.fetch_decode_execute()

    assert cpu.cycles == 2
    assert cpu.Y == 0xFFFF
    assert cpu.P == 0b10000000  # negative flag
    assert cpu.PC == 1 + mem.header.reset_int_addr
Пример #26
0
def test_DEC_NEG_8BIT():
    mem = MemoryMock([0x3A])
    cpu = CPU65816(mem)
    cpu.P = 0b00100000  # 8 Bit mode
    cpu.e = 0
    cpu.A = 0x00

    cpu.fetch_decode_execute()

    assert cpu.cycles == 2
    assert cpu.A == 0xFF
    assert cpu.P == 0b10100000  # negative flag
    assert cpu.PC == 1 + mem.header.reset_int_addr
Пример #27
0
def test_PEA():
    mem = MemoryMock([0xF4, 0x34, 0x12])
    cpu = CPU65816(mem)
    cpu.SP = 0x01FF
    cpu.P = 0b00000000  # M and X Flag have no effect on PEA

    cpu.fetch_decode_execute()  # PEA #$1234

    assert mem.read(0x0001FF) == 0x12  # high
    assert mem.read(0x0001FE) == 0x34  # low
    assert cpu.SP == 0x01FD
    assert cpu.cycles == 5
    assert cpu.PC == 3 + mem.header.reset_int_addr
Пример #28
0
def test_DEY_underflow_8BIT():
    mem = MemoryMock([0x88])
    cpu = CPU65816(mem)
    cpu.P = 0b00010000  # 8 Bit mode
    cpu.e = 0
    cpu.Y = 0x80  # -128 (MIN INT)

    cpu.fetch_decode_execute()

    assert cpu.cycles == 2
    assert cpu.Y == 0x7F  # 127 (Max Int)
    assert cpu.P == 0b00010000  # no negative flag
    assert cpu.PC == 1 + mem.header.reset_int_addr
Пример #29
0
def test_JMP_long():
    mem = MemoryMock([0x5C, 0x56, 0x34, 0x12])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000
    cpu.PC += 0
    cpu.PBR = 0

    cpu.fetch_decode_execute()

    assert cpu.P == 0b00000000
    assert cpu.cycles == 4
    assert cpu.PC == 0x3456
    assert cpu.PBR == 0x12
Пример #30
0
def test_BIT_imm_8bit():
    mem = MemoryMock([0x89, 0x00])
    cpu = CPU65816(mem)
    cpu.P = 0b11100000  # 8 Bit mode
    cpu.e = 0
    cpu.A = 0xFF

    cpu.fetch_decode_execute()

    assert cpu.cycles == 2
    assert cpu.A == 0xFF
    assert cpu.P == 0b11100010
    assert cpu.PC == 2 + mem.header.reset_int_addr