def test_rom(rom): try: logger.info(rom) window = Window(scale=1) window.enable_title = False pyboy = PyBoy(window, rom) serial_output = "" t = time.time() while not pyboy.tick(): b = pyboy.mb.get_serial() if b != "": serial_output += b # print b, t = time.time() if "Passed" in serial_output: return ("Passed") break elif "Failed" in serial_output: return (serial_output) break if time.time() - t > timeout: return ("Timeout:\n" + serial_output) break print serial_output pyboy.stop(save=False) except Exception as ex: print ex return str(ex)
def create_save_state(): try: # Check if the ROM is given through argv if len(sys.argv) > 1: # First arg is SDL2/PyGame filename = sys.argv[1] else: filename = getROM(rom_dir) # Start PyBoy and run loop pyboy = PyBoy(Window(scale=scale), filename, boot_rom) frame = 0 while not pyboy.tick(): if (frame % 10 == 0): print("frame: {}".format(frame)) if frame == 100: pyboy.sendInput([WindowEvent.PressButtonStart]) elif frame == 102: pyboy.sendInput([WindowEvent.ReleaseButtonStart]) if frame == 110: pyboy.mb.saveState(save_file) if frame == 120: pyboy.stop() frame += 1 pyboy.stop() except KeyboardInterrupt: print("Interrupted by keyboard") except Exception as ex: traceback.print_exc()
def start_pyboy(self): self.pyboy = PyBoy(Window(scale=self.scale), self.rom_file, self.boot_rom) self.frame = 0 self.ctrl_left = False self.ctrl_right = False self._mario_x = 0 self._prev_x_steps = [0] * self.max_x_steps # previous x vals self.action_space = self._get_action_space()
def __init__(self): bootROM = None ROMdir = "ROM/" scale = 2 try: # Check if the ROM is given through argv if len(sys.argv) > 1: filename = sys.argv[1] else: filename = self.getROM(ROMdir) # Start PyBoy and run loop self.pyboy = PyBoy(Window(scale=scale), filename, bootROM) except Exception: traceback.print_exc()
def __init__(self, rom_file, state_file, scale=1): """ Initialise the environment TODO: This should create the pyboy instance :param string rom_file: Cartridge rom file :param string state_file: State file to load :param int scale: Scale size of window """ self.pyboy = PyBoy(Window(scale=scale), rom_file, self.boot_rom) self.state_file = state_file self.frame = 0 self.ctrl_left = False self.ctrl_right = False self._mario_x = 0 self._prev_x_steps = [0] * self.max_x_steps # previous x vals self.action_space = self._get_action_space()
import sys import os from PyBoy import PyBoy from PyBoy.GameWindow import SdlGameWindow as Window import paas if __name__ == "__main__": # Automatically bump to '-OO' optimizations if __debug__: os.execl(sys.executable, sys.executable, '-OO', *sys.argv) bootROM = None ROM_path = "ROMs/Pokemon_Red.gb" scale = 2 if not os.path.exists(ROM_path) and len(sys.argv) < 2: print("ROM not found. Please copy the Game-ROM to '%s'" % ROM_path) exit() try: # Start PyBoy and run loop pyboy = PyBoy(Window(scale=scale), ROM_path, bootROM) server = paas.Server(pyboy) server.run() except KeyboardInterrupt: print("Interrupted by keyboard") traceback.print_exc()
if __name__ == "__main__": ROMdir = "ROMs/" for rom in [ "TestROMs/instr_timing/instr_timing.gb", "TestROMs/mem_timing/mem_timing.gb", "TestROMs/oam_bug/rom_singles/1-lcd_sync.gb", "TestROMs/cpu_instrs/individual/01-special.gb", "TestROMs/cpu_instrs/individual/02-interrupts.gb", "TestROMs/cpu_instrs/individual/03-op sp,hl.gb", "TestROMs/cpu_instrs/individual/04-op r,imm.gb", "TestROMs/cpu_instrs/individual/05-op rp.gb", "TestROMs/cpu_instrs/individual/06-ld r,r.gb", "TestROMs/cpu_instrs/individual/07-jr,jp,call,ret,rst.gb", "TestROMs/cpu_instrs/individual/08-misc instrs.gb", "TestROMs/cpu_instrs/individual/09-op r,r.gb", "TestROMs/cpu_instrs/individual/10-bit ops.gb", "TestROMs/cpu_instrs/individual/11-op a,(hl).gb", ]: try: logger.info(rom) window = Window(scale=1) pyboy = PyBoy(window, rom) while not pyboy.tick(): pass pyboy.stop(save=False) except Exception as ex: print ex time.sleep(1)
os.execl(sys.executable, sys.executable, '-OO', *sys.argv) bootROM = "ROMs/DMG_ROM.bin" scale = 1 debug = "debug" in sys.argv and platform.system() != "Windows" # Verify directories if not bootROM is None and not os.path.exists(bootROM): print ("Boot-ROM not found. Please copy the Boot-ROM to '%s'. Using replacement in the meanwhile..." % bootROM) bootROM = None try: filename = "../ROMs/Pokemon Red.gb" # Start PyBoy and run loop pyboy = PyBoy(Window(scale=scale), filename, bootROM) step = 0 while not pyboy.tick(): try: # ((160,144) * scale)-sized black/white array screen_array = pyboy.getScreenBuffer().getScreenBuffer() # print screen_array.shape observation = dqn.processor.process_observation(screen_array) action = dqn.forward(observation) pyboy.sendInput(actions[action]) except Exception as e: print e pass pyboy.stop() except KeyboardInterrupt:
def find_increasing_mem_locations(): """ Find memory locations that have values that increase over time """ try: filename = getROM(rom_dir) # Start PyBoy and run loop pyboy = PyBoy(Window(scale=scale), filename, boot_rom) frame = 0 candidate_mem_locs = {} while not pyboy.tick(): if (frame % 10 == 0): logger.info("frame: {}".format(frame)) if frame == 10: pyboy.mb.loadState(save_file) pyboy.sendInput([WindowEvent.PressArrowRight]) elif frame == 50: pyboy.sendInput([WindowEvent.PressButtonA]) elif frame == 52: pyboy.sendInput([WindowEvent.ReleaseButtonA]) if frame == 55: candidate_mem_locs = pyboy.mb.get_mem_array() if frame == 100: pyboy.sendInput([WindowEvent.PressButtonB]) if frame > 20: if (frame % 10 == 0): pyboy.sendInput([WindowEvent.PressButtonA]) elif (frame % 10 == 5): pyboy.sendInput([WindowEvent.ReleaseButtonA]) # if (frame % 20 == 0): # pyboy.window.dump(filename='/dev/shm/mario_{}.bmp'.format(frame), dump_all=False) # # for n in range(40): # # sprite = pyboy.getSprite(n) # # if sprite.is_on_screen(): # # print('Sprite: {} {}'.format(n, sprite.get_attributes())) if (frame > 79) and (frame % 10 == 0): mem_list = pyboy.mb.get_mem_array(bits=16) candidate_mem_locs = filter_mem_locs(candidate_mem_locs, mem_list) logger.info('-- Mem Pass {}: {}'.format( frame, len(candidate_mem_locs))) for k in candidate_mem_locs: logger.info('{}: {}'.format(hex(k), hex(candidate_mem_locs[k]))) if frame == 500: pyboy.stop() frame += 1 pyboy.stop() except KeyboardInterrupt: print("Interrupted by keyboard") except Exception as ex: traceback.print_exc()