diff options
Diffstat (limited to 'atk16_emu/cli.py')
| -rw-r--r-- | atk16_emu/cli.py | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/atk16_emu/cli.py b/atk16_emu/cli.py index d6bd46b..824fbbf 100644 --- a/atk16_emu/cli.py +++ b/atk16_emu/cli.py @@ -21,41 +21,45 @@ def print_help(): print(" -h: print help") print(" -d: enable debugger") -for arg in sys.argv[1:]: - if arg == "-d": - options.debugger_enabled = True - elif arg == "-h" or arg == "--help" or arg == "-?": - print_help() - sys.exit(0) - elif arg[0] == "-": - print(f"Unknown option: {arg}") +def main(): + for arg in sys.argv[1:]: + if arg == "-d": + options.debugger_enabled = True + elif arg == "-h" or arg == "--help" or arg == "-?": + print_help() + sys.exit(0) + elif arg[0] == "-": + print(f"Unknown option: {arg}") + print_help() + sys.exit(1) + else: + options.rom_image_path = arg + + if options.rom_image_path is None: print_help() sys.exit(1) - else: - options.rom_image_path = arg -if options.rom_image_path is None: - print_help() - sys.exit(1) + def load_rom_image_from_path(path: str) -> bytearray: + with open(path, "rb") as f: + return bytearray(f.read()) -def load_rom_image_from_path(path: str) -> bytearray: - with open(path, "rb") as f: - return bytearray(f.read()) + rom_image = load_rom_image_from_path(options.rom_image_path) -rom_image = load_rom_image_from_path(options.rom_image_path) + if not options.debugger_enabled: + machine = Machine() + machine.load_rom_image(rom_image) + machine.reset() + machine.run_until_halted() -if not options.debugger_enabled: - machine = Machine() - machine.load_rom_image(rom_image) - machine.reset() - machine.run_until_halted() + print("Machine halted.") + print("===============") - print("Machine halted.") - print("===============") + machine.print_state_summary() - machine.print_state_summary() + else: + debugger = Debugger() + debugger.load_rom_image(rom_image) + debugger.activate() -else: - debugger = Debugger() - debugger.load_rom_image(rom_image) - debugger.activate() +if __name__ == "__main__": + main() |
