aboutsummaryrefslogtreecommitdiffstats
path: root/atk16_emu/cli.py
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2024-02-21 12:02:14 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2024-02-21 12:02:14 +0200
commita0b4a1a6107e4dc905b21858d8ac76c47293cfb4 (patch)
treef7ec4d592a6ee7bf6f1e61ef805643c83fedf740 /atk16_emu/cli.py
parent549901c85044b6ccd912688d6be007c2fdacc6c6 (diff)
Add emu
Diffstat (limited to 'atk16_emu/cli.py')
-rw-r--r--atk16_emu/cli.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/atk16_emu/cli.py b/atk16_emu/cli.py
new file mode 100644
index 0000000..dd06f67
--- /dev/null
+++ b/atk16_emu/cli.py
@@ -0,0 +1,50 @@
+import sys
+from dataclasses import dataclass
+from emu import Machine
+
+@dataclass
+class Options:
+ rom_image_path: str | None
+ debugger_enabled: bool
+
+options = Options(
+ rom_image_path=None,
+ debugger_enabled=False,
+)
+
+def print_help():
+ print("Usage: emu_cli.py [-d] [-h|--help] <rom_path>")
+ print("")
+ print("Options:")
+ print(" <rom_path>: path to the rom image")
+ 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}")
+ 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())
+
+rom_image = load_rom_image_from_path(options.rom_image_path)
+
+machine = Machine()
+machine.load_rom_image(rom_image)
+machine.reset()
+machine.run_until_halted()
+print(machine.get_system_state())