def main(): argv = parser.parse_args() log_level(argv.log_level) logger.info( """ The Game Boy controls are as follows: | Keyboard key | GameBoy equivalant | | --- | --- | | Up | Up | | Down | Down | | Left | Left | | Right | Right | | A | A | | S | B | | Return | Start | | Backspace | Select | The other controls for the emulator: | Keyboard key | Emulator function | | --- | --- | | Escape | Quit | | D | Debug | | Space | Unlimited FPS | | Z | Save state | | X | Load state | | I | Toggle screen recording | | O | Save screenshot | | , | Rewind backwards | | . | Rewind forward | See "pyboy --help" for how to enable rewind and other awesome features! """ ) # Start PyBoy and run loop pyboy = PyBoy(argv.ROM, **vars(argv)) if argv.loadstate is not None: if argv.loadstate == INTERNAL_LOADSTATE: # Guess filepath from ROM path state_path = argv.ROM + ".state" else: # Use filepath given state_path = argv.loadstate valid_file_path(state_path) with open(state_path, "rb") as f: pyboy.load_state(f) while not pyboy.tick(): pass pyboy.stop() if argv.profiling: print("\n".join(profiling_printer(pyboy._cpu_hitrate())))
def test_profiling(): pyboy = PyBoy(default_rom, window_type="dummy", bootrom_file=boot_rom, profiling=True) pyboy.set_emulation_speed(0) pyboy.tick() hitrate = pyboy._cpu_hitrate() CHECK_SUM = 7524 assert sum( hitrate ) == CHECK_SUM, "The amount of instructions called in the first frame of the boot-ROM has changed" assert list(main.profiling_printer(hitrate)) == [ "17c BIT 7,H 2507", " 32 LD (HL-),A 2507", " 20 JR NZ,r8 2507", " af XOR A 1", " 31 LD SP,d16 1", " 21 LD HL,d16 1", ], "The output of the profiling formatter has changed. Either the output is wrong, or the formatter has changed." pyboy.stop(save=False)