aboutsummaryrefslogtreecommitdiffstats
path: root/atk16_emu/cli.py
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2024-02-24 20:30:17 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2024-02-24 20:30:17 +0200
commit6dd1e346d330e662e42dd8bc75d17317223908fd (patch)
treec081b1de90cfc5ca7007a8935e6892aaee03aa56 /atk16_emu/cli.py
parent0a2cf66672364ed555c85682e948cff0b54c8f35 (diff)
Add setup.py, fix bugs
Diffstat (limited to 'atk16_emu/cli.py')
-rw-r--r--atk16_emu/cli.py62
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()