Exemple #1
0
    def _run(self, stopcodes):
        stopcodes = set(stopcodes)
        breakpoints = set(self._breakpoints)
        mpu = self._mpu
        mem = self._mpu.memory

        # Switch to immediate (noncanonical) no-echo input mode on POSIX
        # operating systems.  This has no effect on Windows.
        console.noncanonical_mode(self.stdin)

        if not breakpoints:
            while True:
                mpu.step()
                if mem[mpu.pc] in stopcodes:
                    break
        else:
            while True:
                mpu.step()
                pc = mpu.pc
                if mem[pc] in stopcodes:
                    break
                if pc in breakpoints:
                    msg = "Breakpoint %d reached."
                    self._output(msg % self._breakpoints.index(pc))
                    break

        # Switch back to the previous input mode.
        console.restore_mode()
Exemple #2
0
    def __init__(self,
                 argv=None,
                 stdin=None,
                 stdout=None,
                 mpu_type=NMOS6502,
                 memory=None,
                 putc_addr=0xF001,
                 getc_addr=0xF004):
        self.mpu_type = mpu_type
        self.memory = memory
        self.putc_addr = putc_addr
        self.getc_addr = getc_addr
        self._breakpoints = []
        self._width = 78
        self.prompt = "."
        self._add_shortcuts()

        # Save the current system input mode so it can be restored after
        # after processing commands and before exiting.
        console.save_mode(sys.stdin)

        # Attempt to get a copy of stdin that is unbuffered on systems
        # that support it.  This allows for immediate response to
        # typed input as well as pasted input.  If unable to get an
        # unbuffered version of stdin, the original version is returned.
        self.unbuffered_stdin = console.get_unbuffered_stdin(stdin)

        cmd.Cmd.__init__(self, stdin=self.unbuffered_stdin, stdout=stdout)

        # Check for any exceptions thrown during __init__ while
        # processing the arguments.
        try:

            if argv is None:
                argv = sys.argv
            load, rom, goto = self._parse_args(argv)

            self._reset(self.mpu_type, self.getc_addr, self.putc_addr)

            if load is not None:
                self.do_load("%r" % load)

            if goto is not None:
                self.do_goto(goto)

            if rom is not None:
                # load a ROM and run from the reset vector
                self.do_load("%r top" % rom)
                physMask = self._mpu.memory.physMask
                reset = self._mpu.RESET & physMask
                dest = self._mpu.memory[reset] + \
                    (self._mpu.memory[reset + 1] << self.byteWidth)
                self.do_goto("$%x" % dest)
        except:
            # Restore input mode on any exception and then rethrow the
            # exception.
            console.restore_mode()
            raise
Exemple #3
0
 def __del__(self):
     try:
         # Restore the input mode.
         console.restore_mode()
         # Close the unbuffered input file handle, if it exists.
         if self.unbuffered_stdin != None:
             if self.unbuffered_stdin != sys.stdin:
                 self.unbuffered_stdin.close()
     except:
         pass
Exemple #4
0
def main(args=None):
    c = Monitor()

    try:
        import readline
        readline = readline  # pyflakes
    except ImportError:
        pass

    try:
        c.onecmd('version')
        c.cmdloop()
    except KeyboardInterrupt:
        c._output('')
        console.restore_mode()
Exemple #5
0
    def onecmd(self, line):
        line = self._preprocess_line(line)

        result = None
        try:
            result = cmd.Cmd.onecmd(self, line)
        except KeyboardInterrupt:
            self._output("Interrupt")
        except Exception:
            (file, fun, line), t, v, tbinfo = compact_traceback()
            error = 'Error: %s, %s: file: %s line: %s' % (t, v, file, line)
            self._output(error)

        if not line.startswith("quit"):
            self._output_mpu_status()

        # Switch back to the previous input mode.
        console.restore_mode()

        return result