diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2024-02-24 20:30:17 +0200 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2024-02-24 20:30:17 +0200 |
| commit | 6dd1e346d330e662e42dd8bc75d17317223908fd (patch) | |
| tree | c081b1de90cfc5ca7007a8935e6892aaee03aa56 /atk16_emu | |
| parent | 0a2cf66672364ed555c85682e948cff0b54c8f35 (diff) | |
Add setup.py, fix bugs
Diffstat (limited to 'atk16_emu')
| -rw-r--r-- | atk16_emu/cli.py | 62 | ||||
| -rw-r--r-- | atk16_emu/debugger.py | 8 |
2 files changed, 41 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() diff --git a/atk16_emu/debugger.py b/atk16_emu/debugger.py index f887ed0..3d8f131 100644 --- a/atk16_emu/debugger.py +++ b/atk16_emu/debugger.py @@ -76,11 +76,19 @@ class Debugger: else: self.breakpoints.add(addr) elif cmd == "n": + if not self.machine.running: + print("Machine halted.") + continue + self.machine.step() + + if not self.machine.running: + print("Machine halted.") elif cmd == "s": self.machine.print_state_summary() elif cmd == "0": self.machine.reset() + self.machine.run() print("Machine reset.") else: print(f"Unknown command: {cmd}") |
