Exemplo n.º 1
0
def test_write_AbsoluteX():
    address_mode = AbsoluteX
    cpu = CPU()
    memory = Memory(rom=[0x30, 0x01, 0xFF, 0x02, 0x0A, 0x05], ram=list(map(lambda x: x % 256, range(Memory.ram_size()))))

    cpu.inc_cycle_by(-cpu.cycle)
    cpu.inc_pc_by(-cpu.pc + MemoryPositions.PRG_ROM_START.start)
    cpu.x = 0x25
    address = address_mode.fetch_address(cpu, memory)
    address_mode.write_to(cpu, memory, address, 20)
    assert address == 0x0155
    assert memory.ram[address] == 20

    cpu.inc_cycle_by(-cpu.cycle)
    cpu.x = 0x30
    address = address_mode.fetch_address(cpu, memory)
    address_mode.write_to(cpu, memory, address, 100)
    assert address == 0x032F
    assert memory.ram[address] == 100

    cpu.inc_cycle_by(-cpu.cycle)
    cpu.x = 0x20
    address = address_mode.fetch_address(cpu, memory)
    address_mode.write_to(cpu, memory, address, 67)
    assert address == 0x052A
    assert memory.ram[address] == 67
Exemplo n.º 2
0
def test_read_AbsoluteX():
    address_mode = AbsoluteX
    cpu = CPU()
    memory = Memory(rom=[0x32, 0x02, 0x7F, 0x01, 0x00, 0x20], ram=list(map(lambda x: x % 256, range(Memory.ram_size()))))

    cpu.inc_cycle_by(-cpu.cycle)
    cpu.inc_pc_by(-cpu.pc + MemoryPositions.PRG_ROM_START.start)
    cpu.x = 0x0A
    address = address_mode.fetch_address(cpu, memory)
    value = address_mode.read_from(cpu, memory, address)
    assert address == 0x023C
    assert value == (0x023C % 256)

    cpu.inc_cycle_by(-cpu.cycle)
    cpu.x = 0xA1
    address = address_mode.fetch_address(cpu, memory)
    value = address_mode.read_from(cpu, memory, address)

    assert address == 0x0220
    assert value == (0x0220 % 256)

    cpu.inc_cycle_by(-cpu.cycle)
    cpu.x = 0x07
    address = address_mode.fetch_address(cpu, memory)
    value = address_mode.read_from(cpu, memory, address)

    assert address == 0x2007
Exemplo n.º 3
0
def test_TAX():
     cpu = CPU()
     memory = Memory()
     cpu.x = 1
     cpu.a = 2
     TAX = OpCodes.all[170]
     TAX.exec(cpu, memory)

     assert cpu.x == 2
     assert cpu.zero == False
     assert cpu.negative == False

     cpu.a = 0
     cpu.x = 1
     cpu.inc_cycle_by(-cpu.cycle)
     TAX.exec(cpu, memory)

     assert cpu.cycle == (TAX.cycles - 1)
     assert cpu.x == 0
     assert cpu.zero == True
     assert cpu.negative == False

     cpu.a = 0b10000001
     cpu.x = 1
     TAX.exec(cpu, memory)

     assert cpu.x == 0b10000001
     assert cpu.zero == False
     print(cpu.negative)
     assert cpu.negative == True
Exemplo n.º 4
0
def test_TXA():
     cpu = CPU()
     memory = Memory()
     cpu.a = 1
     cpu.x = 2
     TXA = OpCodes.all[138]
     TXA.exec(cpu, memory)

     assert cpu.a == 2
     assert cpu.zero == False
     assert cpu.negative == False

     cpu.x = 0
     cpu.a = 1
     TXA.exec(cpu, memory)

     assert cpu.a == 0
     assert cpu.zero == True
     assert cpu.negative == False

     cpu.x = 0b10000001
     cpu.a = 1
     cpu.inc_cycle_by(-cpu.cycle)
     TXA.exec(cpu, memory)

     assert cpu.cycle == (TXA.cycles - 1)
     assert cpu.a == 0b10000001
     assert cpu.zero == False
     print(cpu.negative)
     assert cpu.negative == True
def test_write_ZeroPageX():
    address_mode = ZeroPageX
    cpu = CPU()
    memory = Memory(rom=list(range(256)))

    cpu.inc_cycle_by(-cpu.cycle)
    cpu.inc_pc_by(-cpu.pc + MemoryPositions.PRG_ROM_START.start)
    cpu.x = 5
    address = address_mode.fetch_address(cpu, memory)
    address_mode.write_to(cpu, memory, address, 6)
    assert address == 5
    assert memory.ram[address] == 6
    assert cpu.cycle == 3

    cpu.inc_cycle_by(-cpu.cycle)
    cpu.inc_pc_by(-cpu.pc + MemoryPositions.PRG_ROM_START.start + 20)
    cpu.x = 15
    address = address_mode.fetch_address(cpu, memory)
    address_mode.write_to(cpu, memory, address, 105)

    assert address == 35
    assert memory.ram[address] == 105
    assert cpu.cycle == 3

    cpu.inc_cycle_by(-cpu.cycle)
    cpu.inc_pc_by(-cpu.pc + MemoryPositions.PRG_ROM_START.start + 100)
    cpu.x = 155
    address = address_mode.fetch_address(cpu, memory)
    address_mode.write_to(cpu, memory, address, 143)

    assert address == 255
    assert memory.ram[address] == 143
    assert cpu.cycle == 3

    cpu.inc_cycle_by(-cpu.cycle)
    cpu.inc_pc_by(-cpu.pc + MemoryPositions.PRG_ROM_START.start + 255)
    cpu.x = 0
    address = address_mode.fetch_address(cpu, memory)
    address_mode.write_to(cpu, memory, address, 255)

    assert address == 255
    assert memory.ram[address] == 255
    assert cpu.cycle == 3

    cpu.inc_cycle_by(-cpu.cycle)
    cpu.inc_pc_by(-cpu.pc + MemoryPositions.PRG_ROM_START.start + 255)
    cpu.x = 75
    address = address_mode.fetch_address(cpu, memory)
    address_mode.write_to(cpu, memory, address, 255)

    assert address == 74
    assert memory.ram[address] == 255
    assert cpu.cycle == 3
def test_read_ZeroPageX():
    address_mode = ZeroPageX
    cpu = CPU()
    memory = Memory(rom=list(range(256)), ram=list(reversed(range(256))))

    cpu.inc_cycle_by(-cpu.cycle)
    cpu.inc_pc_by(-cpu.pc + MemoryPositions.PRG_ROM_START.start)
    cpu.x = 1
    address = address_mode.fetch_address(cpu, memory)
    value = address_mode.read_from(cpu, memory, address)
    assert address == 1
    assert value == 254
    assert cpu.cycle == 3

    cpu.inc_cycle_by(-cpu.cycle)
    cpu.inc_pc_by(-cpu.pc + MemoryPositions.PRG_ROM_START.start + 20)
    cpu.x = 10
    address = address_mode.fetch_address(cpu, memory)
    value = address_mode.read_from(cpu, memory, address)

    assert address == 30
    assert value == 225
    assert cpu.cycle == 3

    cpu.inc_cycle_by(-cpu.cycle)
    cpu.inc_pc_by(-cpu.pc + MemoryPositions.PRG_ROM_START.start + 100)
    cpu.x = 5
    address = address_mode.fetch_address(cpu, memory)
    value = address_mode.read_from(cpu, memory, address)

    assert address == 105
    assert value == 150
    assert cpu.cycle == 3

    cpu.inc_cycle_by(-cpu.cycle)
    cpu.inc_pc_by(-cpu.pc + MemoryPositions.PRG_ROM_START.start + 255)
    cpu.x = 0
    address = address_mode.fetch_address(cpu, memory)
    value = address_mode.read_from(cpu, memory, address)

    assert address == 255
    assert value == 0
    assert cpu.cycle == 3

    cpu.inc_cycle_by(-cpu.cycle)
    cpu.inc_pc_by(-cpu.pc + MemoryPositions.PRG_ROM_START.start + 255)
    cpu.x = 5
    address = address_mode.fetch_address(cpu, memory)
    value = address_mode.read_from(cpu, memory, address)

    assert address == 4
    assert value == 251
    assert cpu.cycle == 3
Exemplo n.º 7
0
def test_DEX_within_bounds():
    instruction = OpCodes.all[0xCA]
    cpu = CPU()
    memory = Memory()
    cpu.inc_cycle_by(-cpu.cycle)
    cpu.x = 7
    instruction.exec(cpu, memory)

    assert cpu.cycle == (instruction.cycles - 1)
    assert cpu.x == 6
    assert cpu.zero == False
    assert cpu.negative == False
Exemplo n.º 8
0
def test_DEX_zero():
    instruction = OpCodes.all[0xCA]
    cpu = CPU()
    memory = Memory()
    cpu.inc_cycle_by(-cpu.cycle)
    cpu.x = 1
    instruction.exec(cpu, memory)

    assert cpu.cycle == (instruction.cycles - 1)
    assert cpu.x == 0
    assert cpu.zero == True
    assert cpu.negative == False

    cpu.inc_cycle_by(-cpu.cycle)
    cpu.x = 257
    instruction.exec(cpu, memory)

    assert cpu.cycle == (instruction.cycles - 1)
    assert cpu.x == 0
    assert cpu.zero == True
    assert cpu.negative == False
def test_read_IndirectX():
    address_mode = IndirectX
    cpu = CPU()
    memory = Memory(rom=[0x00, 0x02, 0x7F, 0x01, 0xFF, 0x07],
                    ram=list(map(lambda x: x % 256, range(Memory.ram_size()))))

    cpu.inc_cycle_by(-cpu.cycle)
    cpu.inc_pc_by(-cpu.pc + MemoryPositions.PRG_ROM_START.start)
    cpu.x = 4
    address = address_mode.fetch_address(cpu, memory)
    value = address_mode.read_from(cpu, memory, address)
    assert address == (((0x0504 + 1) % 256) << 8 | (0x0504 % 256))
    assert value == address % 256
    assert cpu.cycle == 5

    cpu.inc_cycle_by(-cpu.cycle)
    cpu.x = 0xFF
    address = address_mode.fetch_address(cpu, memory)
    value = address_mode.read_from(cpu, memory, address)
    assert address == (((0x0201 + 1) % 256) << 8 | (0x0201 % 256))
    assert value == address % 256
    assert cpu.cycle == 5