def test_write_from_memory(self): self.memory[0x1000] = 0x3e self.memory[0x1001] = 0x05 self.memory[0x1002] = 0x3c with NamedTemporaryFile() as outfile: save_memory(self.memory, outfile.name, 0x1000, 3) load_memory(self.memory, outfile.name, 0x2000) assert_equals(self.memory[0x1000], 0x3e) assert_equals(self.memory[0x1001], 0x05) assert_equals(self.memory[0x1002], 0x3c)
def start(rom_file, snapshot_file): memory = [0x00] * 0x10000 processor = Processor(memory, DummyIO()) display_adapter = DisplayAdapter(memory) load_memory(memory, rom_file, 0x0000) load_z80_v1_snapshot(snapshot_file, processor, memory) pygame.init() size = 256, 192 screen = pygame.display.set_mode(size) run_loop(processor, PixelArray(screen), display_adapter)
def run(): parser = argparse.ArgumentParser(description='Run a Z80 assembly program') parser.add_argument('sourcefile', metavar='sourcefile', type=str, help='Z80 binary file') parser.add_argument('--dumprange', type=str, help='Range of memory to dump', required=False) parser.add_argument('--verbose', '-v', help='Enable verbose output', required=False, action='store_true') args = parser.parse_args() memory = Memory() io = IO() processor = Processor(memory, io) load_memory(memory, args.sourcefile, 0x0000) t_states = 0 while True: executed = processor.execute() if args.verbose: print(executed) else: print('.'), t_states += executed.t_states() if str(executed) == 'nop': break print('\n') print('Completed program execution in {} t-states'.format(t_states)) print('Main register states:') for reg, value in processor.main_registers.items(): print('{0:}: {1:#04x}\t\t').format(reg, value), print('\n') print('Alternate register states:') for reg, value in processor.alternate_registers.items(): print('{0:}: {1:#04x}\t\t'.format(reg, value)), print('\n') print('Special register states:') for reg, value in processor.special_registers.items(): print('{0:}: {1:#06x}\t\t'.format(reg, value)), if args.dumprange is not None: start = int(args.dumprange.split(':')[0], 16) & 0xffff end = int(args.dumprange.split(':')[1], 16) & 0xffff print('\n') print('Listing of memory values from {0:#06x} to {1:#06x}'.format(start, end)) addr = start while True: if addr > end: break values = [0x00] * 8 for i in range(0, 8): values[i] = memory[0xffff & (addr + i)] hex_values = ['{:#04x}'.format(val) for val in values] chr_values = ['{}'.format(chr(val)) for val in values] print '{0:#06x}: {1:}\t\t{2:}'.format(addr, ' '.join(hex_values), ' '.join(chr_values)) addr += 8
def test_read_into_memory(self): load_memory(self.memory, _this_directory() + '/test.rom', 0x1000) assert_equals(self.memory[0x1000], 0x3e) assert_equals(self.memory[0x1001], 0x05) assert_equals(self.memory[0x1002], 0x3c)
def run(): parser = argparse.ArgumentParser(description='Run a Z80 assembly program') parser.add_argument('sourcefile', metavar='sourcefile', type=str, help='Z80 binary file') parser.add_argument('--dumprange', type=str, help='Range of memory to dump', required=False) parser.add_argument('--verbose', '-v', help='Enable verbose output', required=False, action='store_true') args = parser.parse_args() memory = Memory() io = IO() processor = Processor(memory, io) load_memory(memory, args.sourcefile, 0x0000) t_states = 0 while True: executed = processor.execute() if args.verbose: print(executed) else: print('.'), t_states += executed.t_states() if str(executed) == 'nop': break print('\n') print('Completed program execution in {} t-states'.format(t_states)) print('Main register states:') for reg, value in processor.main_registers.items(): print('{0:}: {1:#04x}\t\t').format(reg, value), print('\n') print('Alternate register states:') for reg, value in processor.alternate_registers.items(): print('{0:}: {1:#04x}\t\t'.format(reg, value)), print('\n') print('Special register states:') for reg, value in processor.special_registers.items(): print('{0:}: {1:#06x}\t\t'.format(reg, value)), if args.dumprange is not None: start = int(args.dumprange.split(':')[0], 16) & 0xffff end = int(args.dumprange.split(':')[1], 16) & 0xffff print('\n') print('Listing of memory values from {0:#06x} to {1:#06x}'.format( start, end)) addr = start while True: if addr > end: break values = [0x00] * 8 for i in range(0, 8): values[i] = memory[0xffff & (addr + i)] hex_values = ['{:#04x}'.format(val) for val in values] chr_values = ['{}'.format(chr(val)) for val in values] print '{0:#06x}: {1:}\t\t{2:}'.format(addr, ' '.join(hex_values), ' '.join(chr_values)) addr += 8