Beispiel #1
0
 def resume(self):
     """ Resume an interpreter session. """
     # resume from saved emulator state (if requested and available)
     # reload the screen in resumed state
     if not state.console_state.screen.resume():
         raise ResumeFailed()
     # rebuild the audio queue
     for q, store in zip(signals.tone_queue, state.console_state.tone_queue_store):
         signals.load_queue(q, store)
     # override selected settings from command line
     cassette.override()
     disk.override()
     # suppress double prompt
     if not state.basic_state.parse_mode:
         self.prompt = False
Beispiel #2
0
def start_basic():
    """ Load & run programs and commands and hand over to interactive mode. """
    import program
    import run
    import error
    import state
    import devices
    import disk
    import cassette
    import reset
    import sound
    do_reset = False
    backend, console = None, None
    try:
        # resume from saved emulator state if requested and available
        resume = config.get('resume') and state.load()
        # choose the video and sound backends
        backend, console = prepare_console()
        # greet, load and run only if not resuming
        if resume:
            # override selected settings from command line
            cassette.override()
            disk.override()
            # suppress double prompt
            if not state.basic_state.execute_mode:
                state.basic_state.prompt = False
            run.start('', False, config.get('quit'))
        else:
            # load/run program
            config.options['run'] = config.get(0) or config.get('run')
            prog = config.get('run') or config.get('load')
            if prog:
                # on load, accept capitalised versions and default extension
                with open_native_or_dos_filename(prog) as progfile:
                    program.load(progfile)
                reset.clear()
            print_greeting(console)
            # start the interpreter (and get out if we ran with -q)
            run.start(config.get('exec'), config.get('run'),
                      config.get('quit'))
    except error.RunError as e:
        msg = error.get_message(e.err)
        if console and config.get('wait'):
            console.write_error_message(msg, None)
        if backend and backend.video:
            # close terminal to avoid garbled error message
            backend.video.close()
            backend.video = None
        logging.error(msg)
    except error.Exit:
        pass
    except error.Reset:
        do_reset = True
    except KeyboardInterrupt:
        if config.get('debug'):
            raise
    except Exception as e:
        logging.error("Unhandled exception\n%s", traceback.format_exc())
    finally:
        try:
            # fix the terminal on exit (important for ANSI terminals)
            # and save display interface state into screen state
            state.console_state.screen.close()
        except (NameError, AttributeError) as e:
            logging.debug('Error on closing screen: %s', e)
        # delete state if resetting
        if do_reset:
            state.delete()
            if plat.system == 'Android':
                shutil.rmtree(plat.temp_dir)
        else:
            state.save()
        try:
            # close files if we opened any
            devices.close_files()
        except (NameError, AttributeError) as e:
            logging.debug('Error on closing files: %s', e)
        try:
            devices.close_devices()
        except (NameError, AttributeError) as e:
            logging.debug('Error on closing devices: %s', e)
        try:
            sound.audio.close()
        except (NameError, AttributeError) as e:
            logging.debug('Error on closing audio: %s', e)
Beispiel #3
0
def start_basic():
    """ Load & run programs and commands and hand over to interactive mode. """
    import program
    import run
    import error
    import state
    import devices
    import disk
    import cassette
    import reset
    import sound
    import audio
    do_reset = False
    backend, console = None, None
    exit_error = ''
    try:
        # resume from saved emulator state if requested and available
        resume = config.get('resume') and state.load()
        # choose the video and sound backends
        backend, console = prepare_console()
        # greet, load and run only if not resuming
        if resume:
            # override selected settings from command line
            cassette.override()
            disk.override()
            # suppress double prompt
            if not state.basic_state.execute_mode:
                state.basic_state.prompt = False
            run.start('', False, config.get('quit'))
        else:
            # load/run program
            config.options['run'] = config.get(1) or config.get('run')
            prog = config.get('run') or config.get('load')
            if prog:
                # on load, accept capitalised versions and default extension
                with open_native_or_dos_filename(prog) as progfile:
                    program.load(progfile)
                reset.clear()
            print_greeting(console)
            # start the interpreter (and get out if we ran with -q)
            run.start(config.get('exec'), config.get('run'), config.get('quit'))
    except error.RunError as e:
        exit_error = error.get_message(e.err)
    except error.Exit:
        # pause before exit if requested
        if config.get('wait'):
            backend.video_queue.put(backend.Event(backend.VIDEO_SET_CAPTION, 'Press a key to close window'))
            backend.video_queue.put(backend.Event(backend.VIDEO_SHOW_CURSOR, False))
            state.console_state.keyb.pause = True
            # this performs a blocking keystroke read if in pause state
            backend.check_events()
    except error.Reset:
        do_reset = True
    except KeyboardInterrupt:
        if config.get('debug'):
            raise
    except Exception as e:
        print traceback.print_exc()
        exit_error = "Unhandled exception\n%s" % traceback.format_exc()
    finally:
        try:
            audio.close()
        except (NameError, AttributeError) as e:
            logging.debug('Error on closing audio: %s', e)
        try:
            # fix the terminal on exit (important for ANSI terminals)
            # and save display interface state into screen state
            state.console_state.screen.close()
        except (NameError, AttributeError) as e:
            logging.debug('Error on closing screen: %s', e)
        # delete state if resetting
        if do_reset:
            state.delete()
            if plat.system == 'Android':
                shutil.rmtree(plat.temp_dir)
        else:
            state.save()
        try:
            # close files if we opened any
            devices.close_files()
        except (NameError, AttributeError) as e:
            logging.debug('Error on closing files: %s', e)
        try:
            devices.close_devices()
        except (NameError, AttributeError) as e:
            logging.debug('Error on closing devices: %s', e)
        if exit_error:
            logging.error(exit_error)
Beispiel #4
0
def start_basic():
    """ Load & run programs and commands and hand over to interactive mode. """
    import program
    import run
    import error
    import state
    import devices
    import disk
    import cassette
    import reset
    import sound
    do_reset = False
    backend, console = None, None
    try:
        # resume from saved emulator state if requested and available
        resume = config.get('resume') and state.load()
        # choose the video and sound backends
        backend, console = prepare_console()
        # greet, load and run only if not resuming
        if resume:
            # override selected settings from command line
            cassette.override()
            disk.override()
            # suppress double prompt
            if not state.basic_state.execute_mode:
                state.basic_state.prompt = False
            run.start('', False, config.get('quit'))
        else:
            # load/run program
            config.options['run'] = config.get(0) or config.get('run')
            prog = config.get('run') or config.get('load')
            if prog:
                # on load, accept capitalised versions and default extension
                with open_native_or_dos_filename(prog) as progfile:
                    program.load(progfile)
                reset.clear()
            print_greeting(console)
            # start the interpreter (and get out if we ran with -q)
            run.start(config.get('exec'), config.get('run'), config.get('quit'))
    except error.RunError as e:
        msg = error.get_message(e.err)
        if console and config.get('wait'):
            console.write_error_message(msg, None)
        if backend and backend.video:
            # close terminal to avoid garbled error message
            backend.video.close()
            backend.video = None
        logging.error(msg)
    except error.Exit:
        pass
    except error.Reset:
        do_reset = True
    except KeyboardInterrupt:
        if config.get('debug'):
            raise
    except Exception as e:
        logging.error("Unhandled exception\n%s", traceback.format_exc())
    finally:
        try:
            # fix the terminal on exit (important for ANSI terminals)
            # and save display interface state into screen state
            state.console_state.screen.close()
        except (NameError, AttributeError) as e:
            logging.debug('Error on closing screen: %s', e)
        # delete state if resetting
        if do_reset:
            state.delete()
            if plat.system == 'Android':
                shutil.rmtree(plat.temp_dir)
        else:
            state.save()
        try:
            # close files if we opened any
            devices.close_files()
        except (NameError, AttributeError) as e:
            logging.debug('Error on closing files: %s', e)
        try:
            devices.close_devices()
        except (NameError, AttributeError) as e:
            logging.debug('Error on closing devices: %s', e)
        try:
            sound.audio.close()
        except (NameError, AttributeError) as e:
            logging.debug('Error on closing audio: %s', e)
Beispiel #5
0
def start_basic():
    """ Load & run programs and commands and hand over to interactive mode. """
    import program
    import run
    import error
    import state
    import devices
    import disk
    import cassette
    import reset
    import sound
    import audio
    do_reset = False
    backend, console = None, None
    exit_error = ''
    try:
        # resume from saved emulator state if requested and available
        resume = config.get('resume') and state.load()
        # choose the video and sound backends
        backend, console = prepare_console()
        # greet, load and run only if not resuming
        if resume:
            # override selected settings from command line
            cassette.override()
            disk.override()
            # suppress double prompt
            if not state.basic_state.execute_mode:
                state.basic_state.prompt = False
            run.start('', False, config.get('quit'))
        else:
            # load/run program
            config.options['run'] = config.get(0) or config.get('run')
            prog = config.get('run') or config.get('load')
            if prog:
                # on load, accept capitalised versions and default extension
                with open_native_or_dos_filename(prog) as progfile:
                    program.load(progfile)
                reset.clear()
            print_greeting(console)
            # start the interpreter (and get out if we ran with -q)
            run.start(config.get('exec'), config.get('run'),
                      config.get('quit'))
    except error.RunError as e:
        exit_error = e.message
    except error.Exit:
        # pause before exit if requested
        if config.get('wait'):
            backend.video_queue.put(
                backend.Event(backend.VIDEO_SET_CAPTION,
                              'Press a key to close window'))
            backend.video_queue.put(
                backend.Event(backend.VIDEO_SHOW_CURSOR, False))
            state.console_state.keyb.pause = True
            # this performs a blocking keystroke read if in pause state
            backend.check_events()
    except error.Reset:
        do_reset = True
    except KeyboardInterrupt:
        if config.get('debug'):
            raise
    except Exception as e:
        exit_error = "Unhandled exception\n%s" % traceback.format_exc()
    finally:
        try:
            audio.close()
        except (NameError, AttributeError) as e:
            logging.debug('Error on closing audio: %s', e)
        try:
            # fix the terminal on exit (important for ANSI terminals)
            # and save display interface state into screen state
            state.console_state.screen.close()
        except (NameError, AttributeError) as e:
            logging.debug('Error on closing screen: %s', e)
        # delete state if resetting
        if do_reset:
            state.delete()
            if plat.system == 'Android':
                shutil.rmtree(plat.temp_dir)
        else:
            state.save()
        try:
            # close files if we opened any
            devices.close_files()
        except (NameError, AttributeError) as e:
            logging.debug('Error on closing files: %s', e)
        try:
            devices.close_devices()
        except (NameError, AttributeError) as e:
            logging.debug('Error on closing devices: %s', e)
        if exit_error:
            logging.error(exit_error)