def main(rom_filename): cpu = Cpu6502() with open(rom_filename, 'rb') as rom_file: rom = rom_file.read() system = System( cpu, rom, DisplayDriverPyGame(180,200)) system.run()
def test_execute_mult10_function_10xminus10(): test_memory_controller = MemoryControllerForTesting() for byte in range(len(mult10_instructions)): test_memory_controller.buffer[0x600 + byte] = mult10_instructions[byte] cpu = Cpu6502(test_memory_controller) cpu.registers.pc = 0x0600 cpu.registers.accumulator = 0xf6 start = time.perf_counter() total_clocks = cpu.run_until_signalled(test_memory_controller.is_signalled) print("Clocks:{0}".format(total_clocks)) print("Time:{0}".format(time.perf_counter() - start)) assert cpu.registers.accumulator == 0x9c
def test_execute_16bit_subtract_function(): test_memory_controller = MemoryControllerForTesting() for byte in range(len(subtract_16bit_instructions)): test_memory_controller.buffer[0x600 + byte] = subtract_16bit_instructions[byte] subtractions = [ (5000, 3000, 2000), (15000, 2000, 13000), (35000, 4000, 31000), (25000, 12000, 13000), (2000, 3000, 0xfc18), (20000, 26000, 0xe890), (3000, 32000, 0x8eb8), ] cpu = Cpu6502(test_memory_controller) start = time.perf_counter() total_clocks = 0 for subtraction in subtractions: cpu.registers.pc = 0x0600 test_memory_controller.interrupted = False test_memory_controller.buffer[0x20] = subtraction[0] & 0xff test_memory_controller.buffer[0x21] = (subtraction[0] >> 8) & 0xff test_memory_controller.buffer[0x22] = subtraction[1] & 0xff test_memory_controller.buffer[0x23] = (subtraction[1] >> 8) & 0xff total_clocks += cpu.run_until_signalled( test_memory_controller.is_signalled) result = test_memory_controller.read(0x24) + ( test_memory_controller.read(0x25) * 256) print("{0} - {1} = {2}".format( test_memory_controller.read(0x20) + (test_memory_controller.read(0x21) * 256), test_memory_controller.read(0x22) + (test_memory_controller.read(0x23) * 256), result)) assert result == subtraction[2] print("Clocks:{0}".format(total_clocks)) print("Time:{0}".format(time.perf_counter() - start))
def test_execute_fibonacci_function_1(): test_memory_controller = MemoryControllerForTesting() for byte in range(len(fibonacci_instructions)): test_memory_controller.buffer[0x600 + byte] = fibonacci_instructions[byte] cpu = Cpu6502(test_memory_controller) cpu.registers.pc = 0x0600 start = time.perf_counter() total_clocks = cpu.run_until_signalled(test_memory_controller.is_signalled) print("Clocks:{0}".format(total_clocks)) print("Time:{0}".format(time.perf_counter() - start)) expected_results = [1, 1, 2, 3, 5, 8, 13, 21, 34] for result in range(0, 9): assert test_memory_controller.read(0xf1b + result) == expected_results[result]
def test_execute_sqrt_function_1(): test_memory_controller = MemoryControllerForTesting() for byte in range(len(sqrt_instructions)): test_memory_controller.buffer[0x600 + byte] = sqrt_instructions[byte] test_memory_controller.buffer[0xf0] = 0x11 test_memory_controller.buffer[0xf1] = 2 cpu = Cpu6502(test_memory_controller) cpu.registers.pc = 0x0600 start = time.perf_counter() total_clocks = cpu.run_until_signalled(test_memory_controller.is_signalled) print("Clocks:{0}".format(total_clocks)) print("Time:{0}".format(time.perf_counter() - start)) print("Sqrt(25)={0} remainder {1}".format( test_memory_controller.read(0xf6), (test_memory_controller.read(0xf3) * 256) + test_memory_controller.read(0xf2)))
def test_execute_16bit_divide_function_1(): test_memory_controller = MemoryControllerForTesting() for byte in range(len(divide_instructions)): test_memory_controller.buffer[0x600 + byte] = divide_instructions[byte] divisions = [(32, 8, 4, 0), (100, 5, 20, 0), (5000, 100, 50, 0), (15000, 125, 120, 0), (21000, 126, 166, 84)] cpu = Cpu6502(test_memory_controller) start = time.perf_counter() total_clocks = 0 for division in divisions: cpu.registers.pc = 0x0600 test_memory_controller.interrupted = False dividend = division[0] test_memory_controller.buffer[0x5a] = dividend & 0xff test_memory_controller.buffer[0x5b] = (dividend >> 8) & 0xff divisor = division[1] test_memory_controller.buffer[0x58] = divisor & 0xff test_memory_controller.buffer[0x59] = (divisor >> 8) & 0xff total_clocks += cpu.run_until_signalled( test_memory_controller.is_signalled) result = test_memory_controller.read(0x5a) remainder = test_memory_controller.read(0x5c) + ( test_memory_controller.read(0x5d) * 256) print("{0} / {1} = {2} remainder {3}".format(dividend, divisor, result, remainder)) assert result == division[2] assert remainder == division[3] print("Clocks:{0}".format(total_clocks)) print("Time:{0}".format(time.perf_counter() - start))