Exemplo n.º 1
0
def test_LDY_DP2():
    mem = MemoryMock([0xA4, 0xFF])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000  # 16 Bit mode
    cpu.e = 0
    mem.write(0x000000, 0xCD)
    mem.write(0x00FFFF, 0xAB) # zero bank wrapping!
    mem.write(0x010000, 0xEF) # Bug if this is read
    cpu.DP = 0xFF00
    assert cpu.Y == 0

    cpu.fetch_decode_execute()

    assert cpu.cycles in (3, 4, 5)
    assert cpu.Y == 0xCDAB
    assert cpu.P == 0b10000000
    assert cpu.PC == 2 + mem.header.reset_int_addr
Exemplo n.º 2
0
def test_TSB_absolute_8bit():
    mem = MemoryMock([0x0C, 0xCD, 0xAB])
    cpu = CPU65816(mem)
    cpu.P = 0b00100000  # 8 Bit mode
    cpu.e = 0
    cpu.DBR = 0x12
    cpu.A = 0x43

    mem.write(0x12ABCD, 0x9C)

    cpu.fetch_decode_execute()

    assert mem.read(0x12ABCD) == 0xDF
    assert cpu.cycles == 6
    assert cpu.A == 0x43
    assert cpu.P == 0b00100010
    assert cpu.PC == 3 + mem.header.reset_int_addr
Exemplo n.º 3
0
def test_ORA_long_indexed_X2():
    mem = MemoryMock([0x1F, 0xFE, 0xFF, 0x12])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000  # 16 Bit mode
    cpu.e = 0
    cpu.X = 0x000A
    cpu.A = 0xCDAB

    mem.write(0x130008, 0xFF)
    mem.write(0x130009, 0xFF)

    cpu.fetch_decode_execute()

    assert cpu.cycles == 6
    assert cpu.A == 0xFFFF
    assert cpu.P == 0b10000000
    assert cpu.PC == 4 + mem.header.reset_int_addr
Exemplo n.º 4
0
def test_LDA_stack_relative2():
    mem = MemoryMock([0xA3, 0xFA])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000 # 16 Bit mode
    cpu.e = 0
    cpu.SP = 0xFF10

    mem.write(0x00000A, 0xAB)
    mem.write(0x00000B, 0xCD)
    assert cpu.A == 0

    cpu.fetch_decode_execute()

    assert cpu.cycles == 5
    assert cpu.A == 0xCDAB
    assert cpu.P == 0b10000000
    assert cpu.PC == 2 + mem.header.reset_int_addr
Exemplo n.º 5
0
def test_ORA_absolute():
    mem = MemoryMock([0x0D, 0x56, 0x34])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000  # 16 Bit mode
    cpu.e = 0
    cpu.DBR = 0x12
    cpu.A = 0xFFFF

    mem.write(0x123456, 0xFF)
    mem.write(0x123457, 0x0F)

    cpu.fetch_decode_execute()

    assert cpu.cycles == 5
    assert cpu.A == 0xFFFF
    assert cpu.P == 0b10000000
    assert cpu.PC == 3 + mem.header.reset_int_addr
Exemplo n.º 6
0
def test_ORA_long2():
    mem = MemoryMock([0x0F, 0xFF, 0xFF, 0x12])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000  # 16 Bit mode
    cpu.e = 0
    cpu.A = 0xFABC

    mem.write(0x12FFFF, 0x23)
    mem.write(0x130000, 0xF1)  # no wrapping

    cpu.fetch_decode_execute()

    assert cpu.cycles == 6
    # 1111 1010 1011 1100 | 1111 0001 0010 0011 = 1111 1011 1011 1111
    assert cpu.A == 0xFBBF
    assert cpu.P == 0b10000000
    assert cpu.PC == 4 + mem.header.reset_int_addr
Exemplo n.º 7
0
def test_TAY_NX():
    mem = MemoryMock([0xA8])
    cpu = CPU65816(mem)
    cpu.P = 0b00010000 # x
    cpu.e = 0
    cpu.A = 0x6789
    cpu.X = 0xABCD
    cpu.Y = 0x1234

    cpu.fetch_decode_execute() # TAY

    assert cpu.cycles == 2
    assert cpu.A == 0x6789
    assert cpu.X == 0xABCD
    assert cpu.Y == 0x1289
    assert cpu.P == 0b10010000 # nx
    assert cpu.PC == 1 + mem.header.reset_int_addr
Exemplo n.º 8
0
def test_ORA_stack_relative():
    mem = MemoryMock([0x03, 0x01])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000  # 16 Bit mode
    cpu.e = 0
    cpu.SP = 0x1FF0
    cpu.A = 0xCDAB

    mem.write(0x001FF1, 0x00)
    mem.write(0x001FF2, 0x00)

    cpu.fetch_decode_execute()

    assert cpu.cycles == 5
    assert cpu.A == 0xCDAB
    assert cpu.P == 0b10000000
    assert cpu.PC == 2 + mem.header.reset_int_addr
Exemplo n.º 9
0
def test_INC_abs_indexed_X_Zero():
    mem = MemoryMock([0xFE, 0x00, 0x80])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000  # 16 Bit mode
    cpu.e = 0
    cpu.DBR = 0x80
    cpu.X = 0x0001
    mem.write(0x808001, 0xFF)  # no wrapping
    mem.write(0x808002, 0xFF)

    cpu.fetch_decode_execute()

    assert cpu.cycles == 9
    assert mem.read(0x808001) == 0x00
    assert mem.read(0x808002) == 0x00
    assert cpu.P == 0b00000010  # zero flag
    assert cpu.PC == 3 + mem.header.reset_int_addr
Exemplo n.º 10
0
def test_INC_abs_indexed_X_no_overflow_8BIT():
    mem = MemoryMock([0xFE, 0x00, 0x80])
    cpu = CPU65816(mem)
    cpu.P = 0b00100000  # 8 Bit mode
    cpu.e = 0
    cpu.DBR = 0x80
    cpu.X = 0x0001
    mem.write(0x808001, 0x7F)  # no wrapping
    mem.write(0x808002, 0x00)  # 128(MAX INT)

    cpu.fetch_decode_execute()

    assert cpu.cycles == 7
    assert mem.read(0x808001) == 0x80  # -127(MIN INT)
    assert mem.read(0x808002) == 0x00
    assert cpu.P == 0b10100000  # negative flag, no overflow flag
    assert cpu.PC == 3 + mem.header.reset_int_addr
Exemplo n.º 11
0
def test_BIT_abs_indexed_X_8bit():
    mem = MemoryMock([0x3C, 0x00, 0x80])
    cpu = CPU65816(mem)
    cpu.P = 0b11100010  # 8 Bit mode
    cpu.e = 0
    cpu.DBR = 0x80
    cpu.X = 0x0001
    cpu.A = 0x0F

    mem.write(0x808001, 0xFF)  # no wrapping

    cpu.fetch_decode_execute()

    assert cpu.cycles >= 5
    assert cpu.A == 0x0F
    assert cpu.P == 0b11100000
    assert cpu.PC == 3 + mem.header.reset_int_addr
Exemplo n.º 12
0
def test_BIT_DP_indexed_X_8bit():
    mem = MemoryMock([0x34, 0x30])
    cpu = CPU65816(mem)
    cpu.P = 0b11100010  # 8 Bit mode
    cpu.e = 0
    cpu.DP = 0x0020
    cpu.X = 0x0004
    cpu.A = 0x0F

    mem.write(0x000054, 0x0F)

    cpu.fetch_decode_execute()

    assert cpu.cycles == 5
    assert cpu.A == 0x0F
    assert cpu.P == 0b00100000
    assert cpu.PC == 2 + mem.header.reset_int_addr
Exemplo n.º 13
0
def test_CPY_absolute():
    mem = MemoryMock([0xCC, 0x56, 0x34])
    cpu = CPU65816(mem)
    cpu.P = 0b10000001  # 16 Bit mode, n should be cleared
    cpu.e = 0
    cpu.DBR = 0x12
    cpu.Y = 0x0FFF

    mem.write(0x123456, 0xFF)
    mem.write(0x123457, 0x00)

    cpu.fetch_decode_execute()

    assert cpu.cycles == 5
    assert cpu.Y == 0x0FFF
    assert cpu.P == 0b00000001
    assert cpu.PC == 3 + mem.header.reset_int_addr
Exemplo n.º 14
0
def test_CPY_DP():
    mem = MemoryMock([0xC4, 0x34])
    cpu = CPU65816(mem)
    cpu.P = 0b10000011  # 16 Bit mode, n should be cleared
    cpu.e = 0
    cpu.DP = 0x1200
    cpu.Y = 0x0FAB

    mem.write(0x001234, 0xAB)
    mem.write(0x001235, 0x0F)

    cpu.fetch_decode_execute()

    assert cpu.cycles == 4
    assert cpu.Y == 0x0FAB
    assert cpu.P == 0b00000011
    assert cpu.PC == 2 + mem.header.reset_int_addr
Exemplo n.º 15
0
def test_TXA_N():
    mem = MemoryMock([0x8A])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000
    cpu.e = 0
    cpu.A = 0xABCD
    cpu.X = 0x8234
    cpu.Y = 0x6789

    cpu.fetch_decode_execute() # TXA

    assert cpu.cycles == 2
    assert cpu.A == 0x8234
    assert cpu.X == 0x8234
    assert cpu.Y == 0x6789
    assert cpu.P == 0b10000000 # n
    assert cpu.PC == 1 + mem.header.reset_int_addr
Exemplo n.º 16
0
def test_TRB_absolute_8bit():
    mem = MemoryMock([0x1C, 0x56, 0x34])
    cpu = CPU65816(mem)
    cpu.P = 0b00100000  # 8 Bit mode
    cpu.e = 0
    cpu.DBR = 0x12
    cpu.A = 0x66

    mem.write(0x123456, 0x77)

    cpu.fetch_decode_execute()

    assert mem.read(0x123456) == 0x11
    assert cpu.cycles == 6
    assert cpu.A == 0x66
    assert cpu.P == 0b00100000
    assert cpu.PC == 3 + mem.header.reset_int_addr
Exemplo n.º 17
0
def test_TYA_Z():
    mem = MemoryMock([0x98])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000
    cpu.e = 0
    cpu.X = 0xABCD
    cpu.Y = 0x0000
    cpu.A = 0xABCD

    cpu.fetch_decode_execute() # TXA

    assert cpu.cycles == 2
    assert cpu.X == 0xABCD
    assert cpu.Y == 0x0000
    assert cpu.A == 0x0000
    assert cpu.P == 0b00000010 # z
    assert cpu.PC == 1 + mem.header.reset_int_addr
Exemplo n.º 18
0
def test_ORA_DP():
    mem = MemoryMock([0x05, 0x34])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000  # 16 Bit mode
    cpu.e = 0
    cpu.DP = 0x1200
    cpu.A = 0x0000

    mem.write(0x001234, 0xAB)
    mem.write(0x001235, 0x0F)

    cpu.fetch_decode_execute()

    assert cpu.cycles == 4
    assert cpu.A == 0x0FAB
    assert cpu.P == 0b00000000
    assert cpu.PC == 2 + mem.header.reset_int_addr
Exemplo n.º 19
0
def test_TYX_X():
    mem = MemoryMock([0xBB])
    cpu = CPU65816(mem)
    cpu.P = 0b00010000 # x
    cpu.e = 0
    cpu.A = 0x8765
    cpu.Y = 0x1234
    cpu.X = 0xABCD

    cpu.fetch_decode_execute() # TYX

    assert cpu.cycles == 2
    assert cpu.A == 0x8765
    assert cpu.Y == 0x1234
    assert cpu.X == 0xAB34
    assert cpu.P == 0b00010000 # x
    assert cpu.PC == 1 + mem.header.reset_int_addr
Exemplo n.º 20
0
def test_ORA_absolute2():
    mem = MemoryMock([0x0D, 0xFF, 0xFF])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000  # 16 Bit mode
    cpu.e = 0
    cpu.DBR = 0x12
    cpu.A = 0x1234

    mem.write(0x12FFFF, 0x34)  # no wrapping
    mem.write(0x130000, 0x12)

    cpu.fetch_decode_execute()

    assert cpu.cycles == 5
    assert cpu.A == 0x1234
    assert cpu.P == 0b00000000
    assert cpu.PC == 3 + mem.header.reset_int_addr
Exemplo n.º 21
0
def test_LDA_long_indexed_X():
    mem = MemoryMock([0xBF, 0x00, 0x80, 0x80])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000 # 16 Bit mode
    cpu.e = 0
    cpu.X = 0x0001

    mem.write(0x808001, 0xAB)
    mem.write(0x808002, 0xCD)
    assert cpu.A == 0

    cpu.fetch_decode_execute()

    assert cpu.cycles == 6
    assert cpu.A == 0xCDAB
    assert cpu.P == 0b10000000
    assert cpu.PC == 4 + mem.header.reset_int_addr
Exemplo n.º 22
0
def test_ORA_abs_indexed_X2():
    mem = MemoryMock([0x1D, 0xFE, 0xFF])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000  # 16 Bit mode
    cpu.e = 0
    cpu.DBR = 0x12
    cpu.X = 0x000A
    cpu.A = 0x0F0F

    mem.write(0x130008, 0xFF)  # no wrapping
    mem.write(0x130009, 0xFF)

    cpu.fetch_decode_execute()
    assert cpu.cycles >= 6
    assert cpu.A == 0xFFFF
    assert cpu.P == 0b10000000
    assert cpu.PC == 3 + mem.header.reset_int_addr
Exemplo n.º 23
0
def test_TRB_DP_8bit():
    mem = MemoryMock([0x14, 0x34])
    cpu = CPU65816(mem)
    cpu.P = 0b00100000  # 8 Bit mode
    cpu.e = 0
    cpu.DP = 0x1200
    cpu.A = 0x9A

    mem.write(0x001234, 0x65)

    cpu.fetch_decode_execute()

    assert mem.read(0x001234) == 0x65
    assert cpu.cycles == 5
    assert cpu.A == 0x9A
    assert cpu.P == 0b00100010
    assert cpu.PC == 2 + mem.header.reset_int_addr
Exemplo n.º 24
0
def test_CMP_stack_relative():
    mem = MemoryMock([0xC3, 0x01])
    cpu = CPU65816(mem)
    cpu.P = 0b10000010  # 16 Bit mode, n and z flag should be cleared
    cpu.e = 0
    cpu.SP = 0x1FF0
    cpu.A = 0x0DAB

    mem.write(0x001FF1, 0x00)
    mem.write(0x001FF2, 0x00)

    cpu.fetch_decode_execute()

    assert cpu.cycles == 5
    assert cpu.A == 0x0DAB
    assert cpu.P == 0b00000001
    assert cpu.PC == 2 + mem.header.reset_int_addr
Exemplo n.º 25
0
def test_RTL():
    mem = MemoryMock([0x6B])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000
    cpu.PBR = 0x00
    cpu.SP = 0x01FC
    mem.write(0x0001FF, 0x12)
    mem.write(0x0001FE, 0x34)
    mem.write(0x0001FD, 0x56)
    cpu.stack = [0x12, 0x34, 0x56]

    cpu.fetch_decode_execute()

    assert cpu.P == 0b00000000  # no effect
    assert cpu.cycles == 6
    assert cpu.PBR == 0x12
    assert cpu.PC == 0x3456 + 1  # the inc to 3456 will be done by the loop
    assert cpu.SP == 0x01FF
Exemplo n.º 26
0
def test_ADC_absolute():
    ROM = [0x6D, 0x56, 0x34]
    mem = MemoryMock(ROM)
    cpu = CPU65816(mem)
    cpu.P = 0b11000011  # 16 Bit mode
    cpu.e = 0
    cpu.DBR = 0x12
    cpu.A = 0x7000

    mem.write(0x123456, 0x00)
    mem.write(0x123457, 0x10)

    cpu.fetch_decode_execute()

    assert cpu.cycles == 5
    assert cpu.A == 0x8001
    assert cpu.P == 0b11000000  # negative and overflow flag
    assert cpu.PC == 3 + mem.header.reset_int_addr
Exemplo n.º 27
0
def test_ADC_DP():
    ROM = [0x65, 0x34]
    mem = MemoryMock(ROM)
    cpu = CPU65816(mem)
    cpu.P = 0b00000000  # 16 Bit mode
    cpu.e = 0
    cpu.DP = 0x1200
    cpu.A = 0xAAAA

    mem.write(0x001234, 0xAA)
    mem.write(0x001235, 0xAA)

    cpu.fetch_decode_execute()

    assert cpu.cycles == 4
    assert cpu.A == 0x5554
    assert cpu.P == 0b00000001  # carry flag
    assert cpu.PC == 2 + mem.header.reset_int_addr
Exemplo n.º 28
0
def test_ADC_stack_relative():
    ROM = [0x63, 0x01]
    mem = MemoryMock(ROM)
    cpu = CPU65816(mem)
    cpu.P = 0b11000010  # 16 Bit mode
    cpu.e = 0
    cpu.SP = 0x1FF0
    cpu.A = 0x7777

    mem.write(0x001FF1, 0x11)
    mem.write(0x001FF2, 0x11)

    cpu.fetch_decode_execute()

    assert cpu.cycles == 5
    assert cpu.A == 0x8888
    assert cpu.P == 0b11000000  # negative and overflow flag
    assert cpu.PC == 2 + mem.header.reset_int_addr
Exemplo n.º 29
0
def test_XCE2():
    mem = MemoryMock([0xFB])
    cpu = CPU65816(mem)
    cpu.P = 0b00000001
    cpu.e = 0
    cpu.X = 0x1234
    cpu.Y = 0x5678
    cpu.SP = 0x0201

    cpu.fetch_decode_execute()

    assert cpu.e == 1
    assert cpu.P == 0b00110000
    assert cpu.X == 0x0034
    assert cpu.Y == 0x0078
    assert cpu.SP == 0x0101
    assert cpu.cycles == 2
    assert cpu.PC == 1 + mem.header.reset_int_addr
Exemplo n.º 30
0
def test_EOR_abs_indexed_X():
    mem = MemoryMock([0x5D, 0x00, 0x80])
    cpu = CPU65816(mem)
    cpu.P = 0b00000000  # 16 Bit mode
    cpu.e = 0
    cpu.DBR = 0x80
    cpu.X = 0x0001
    cpu.A = 0x0F0F

    mem.write(0x808001, 0xFF)  # no wrapping
    mem.write(0x808002, 0x00)

    cpu.fetch_decode_execute()

    assert cpu.cycles >= 6
    assert cpu.A == 0x0FF0
    assert cpu.P == 0b00000000
    assert cpu.PC == 3 + mem.header.reset_int_addr