From c43686a5328d03534866409dd35142b6bd519755 Mon Sep 17 00:00:00 2001 From: Mario Keller Date: Thu, 6 Oct 2016 23:12:50 +0200 Subject: [PATCH 1/4] reordered cmd parsing --- py65/monitor.py | 66 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/py65/monitor.py b/py65/monitor.py index 354c80c..85b1364 100644 --- a/py65/monitor.py +++ b/py65/monitor.py @@ -62,6 +62,14 @@ class Monitor(cmd.Cmd): shortopts = 'hi:o:m:l:r:g:' longopts = ['help', 'mpu=', 'input=', 'output=', 'load=', 'rom=', 'goto='] options, args = getopt.getopt(argv[1:], shortopts, longopts) + flag_load = False + load_value = "" + flag_rom = False + rom_value = "" + flag_goto = False + goto_value = "" + flag_mpu = False + mpu_value = "6502" except getopt.GetoptError as exc: self._output(exc.args[0]) self._usage() @@ -76,38 +84,54 @@ class Monitor(cmd.Cmd): self.putc_addr = int(value.upper(), 16) if opt in ('-l', '--load'): - cmd = "load %s" % value - self.onecmd(cmd) + flag_load = True + load_value = value if opt in ('-r', '--rom'): - # load a ROM and run from the reset vector - cmd = "load '%s' top" % value - self.onecmd(cmd) - physMask = self._mpu.memory.physMask - reset = self._mpu.RESET & physMask - dest = self._mpu.memory[reset] + \ - (self._mpu.memory[reset + 1] << self.byteWidth) - cmd = "goto %08x" % dest - self.onecmd(cmd) + flag_rom = True + rom_value = value if opt in ('-g', '--goto'): - cmd = "goto %s" % value - self.onecmd(cmd) + flag_goto = True + goto_value = value if opt in ('-m', '--mpu'): - if self._get_mpu(value) is None: - mpus = list(self.Microprocessors.keys()) - mpus.sort() - msg = "Fatal: no such MPU. Available MPUs: %s" - self._output(msg % ', '.join(mpus)) - sys.exit(1) - cmd = "mpu %s" % value - self.onecmd(cmd) + flag_mpu = True + mpu_value = value elif opt in ("-h", "--help"): self._usage() self._exit(1) + if flag_load == True: + cmd = "load %s" % load_value + self.onecmd(cmd) + + # mpu should set everytime (default ist 6502) + if self._get_mpu(mpu_value) is None: + mpus = list(self.Microprocessors.keys()) + mpus.sort() + msg = "Fatal: no such MPU. Available MPUs: %s" + self._output(msg % ', '.join(mpus)) + sys.exit(1) + cmd = "mpu %s" % mpu_value + self.onecmd(cmd) + + if flag_goto == True: + cmd = "goto %s" % goto_value + self.onecmd(cmd) + + if flag_rom == True: + # load a ROM and run from the reset vector + cmd = "load '%s' top" % rom_value + self.onecmd(cmd) + physMask = self._mpu.memory.physMask + reset = self._mpu.RESET & physMask + dest = self._mpu.memory[reset] + \ + (self._mpu.memory[reset + 1] << self.byteWidth) + cmd = "goto %08x" % dest + self.onecmd(cmd) + def _usage(self): usage = __doc__ % sys.argv[0] self._output(usage) From 7832a71e7279308179d961aa0f5d0eb2bb54bda7 Mon Sep 17 00:00:00 2001 From: Mario Keller Date: Thu, 6 Oct 2016 23:17:28 +0200 Subject: [PATCH 2/4] fixed failing tests --- py65/monitor.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/py65/monitor.py b/py65/monitor.py index 85b1364..d1c7b5d 100644 --- a/py65/monitor.py +++ b/py65/monitor.py @@ -107,15 +107,15 @@ class Monitor(cmd.Cmd): cmd = "load %s" % load_value self.onecmd(cmd) - # mpu should set everytime (default ist 6502) - if self._get_mpu(mpu_value) is None: - mpus = list(self.Microprocessors.keys()) - mpus.sort() - msg = "Fatal: no such MPU. Available MPUs: %s" - self._output(msg % ', '.join(mpus)) - sys.exit(1) - cmd = "mpu %s" % mpu_value - self.onecmd(cmd) + if flag_mpu == True: + if self._get_mpu(mpu_value) is None: + mpus = list(self.Microprocessors.keys()) + mpus.sort() + msg = "Fatal: no such MPU. Available MPUs: %s" + self._output(msg % ', '.join(mpus)) + sys.exit(1) + cmd = "mpu %s" % mpu_value + self.onecmd(cmd) if flag_goto == True: cmd = "goto %s" % goto_value From cfcc892a647c749a5fbdde531bbbef6cc5ebf688 Mon Sep 17 00:00:00 2001 From: Mario Keller Date: Thu, 6 Oct 2016 23:32:09 +0200 Subject: [PATCH 3/4] fixed no mpu set if rom is loaded --- py65/monitor.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/py65/monitor.py b/py65/monitor.py index d1c7b5d..ff94663 100644 --- a/py65/monitor.py +++ b/py65/monitor.py @@ -107,7 +107,9 @@ class Monitor(cmd.Cmd): cmd = "load %s" % load_value self.onecmd(cmd) - if flag_mpu == True: + if (flag_mpu == True) or (flag_rom == True): + if mpu_value == "": + mpu_value = "6502" if self._get_mpu(mpu_value) is None: mpus = list(self.Microprocessors.keys()) mpus.sort() From ec2f1031884fbec71b428d1d313022c6f6e816ea Mon Sep 17 00:00:00 2001 From: Mario Keller Date: Thu, 6 Oct 2016 23:42:11 +0200 Subject: [PATCH 4/4] fixed bug in load and mpu argument order --- py65/monitor.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/py65/monitor.py b/py65/monitor.py index ff94663..754d91d 100644 --- a/py65/monitor.py +++ b/py65/monitor.py @@ -103,10 +103,6 @@ class Monitor(cmd.Cmd): self._usage() self._exit(1) - if flag_load == True: - cmd = "load %s" % load_value - self.onecmd(cmd) - if (flag_mpu == True) or (flag_rom == True): if mpu_value == "": mpu_value = "6502" @@ -119,6 +115,10 @@ class Monitor(cmd.Cmd): cmd = "mpu %s" % mpu_value self.onecmd(cmd) + if flag_load == True: + cmd = "load %s" % load_value + self.onecmd(cmd) + if flag_goto == True: cmd = "goto %s" % goto_value self.onecmd(cmd)