Ejemplo n.º 1
0
def clear(close_files=False, preserve_common=False, preserve_all=False, preserve_deftype=False):
    """ Execute a CLEAR command. """
    #   Resets the stack and string space
    #   Clears all COMMON and user variables
    var.clear_variables(preserve_common, preserve_all, preserve_deftype)
    # reset random number generator
    rnd.clear()
    if close_files:
        # close all files
        devices.close_files()
    # release all disk buffers (FIELD)?
    disk.reset_fields()
    # clear last error number (ERR) and line number (ERL)
    state.basic_state.errn, state.basic_state.errp = 0, 0
    # disable error trapping
    state.basic_state.on_error = None
    state.basic_state.error_resume = None
    state.basic_state.error_handle_mode = False
    # stop all sound
    state.console_state.sound.stop_all_sound()
    # Resets STRIG to off
    state.console_state.stick.switch(False)
    # disable all event trapping (resets PEN to OFF too)
    state.basic_state.events.reset()
    # CLEAR also dumps for_next and while_wend stacks
    state.basic_state.for_next_stack = []
    state.basic_state.while_wend_stack = []
    # reset sound and PLAY state
    state.console_state.sound.reset()
    # reset DRAW state (angle, scale) and current graphics position
    state.console_state.screen.drawing.reset()
    # reset the DATA pointer
    flow.restore()
Ejemplo n.º 2
0
def clear(close_files=False,
          preserve_common=False,
          preserve_all=False,
          preserve_deftype=False):
    """ Execute a CLEAR command. """
    #   Resets the stack and string space
    #   Clears all COMMON and user variables
    var.clear_variables(preserve_common, preserve_all, preserve_deftype)
    # reset random number generator
    rnd.clear()
    if close_files:
        # close all files
        devices.close_files()
    # release all disk buffers (FIELD)?
    disk.reset_fields()
    # clear ERR and ERL
    state.basic_state.errn, state.basic_state.errp = 0, 0
    # disable error trapping
    state.basic_state.on_error = None
    state.basic_state.error_resume = None
    # stop all sound
    state.console_state.sound.stop_all_sound()
    # Resets STRIG to off
    state.console_state.stick.switch(False)
    # disable all event trapping (resets PEN to OFF too)
    state.basic_state.events.reset()
    # CLEAR also dumps for_next and while_wend stacks
    state.basic_state.for_next_stack = []
    state.basic_state.while_wend_stack = []
    # reset sound and PLAY state
    state.console_state.sound.reset()
    # reset DRAW state (angle, scale) and current graphics position
    state.console_state.screen.drawing.reset()
Ejemplo n.º 3
0
 def run(self, command, run, quit, wait):
     """ Interactive interpreter session. """
     if command:
         self.store_line(command)
         self.loop()
     if run:
         # position the pointer at start of program and enter execute mode
         flow.jump(None)
         state.basic_state.parse_mode = True
         state.console_state.screen.cursor.reset_visibility()
     try:
         try:
             while True:
                 self.loop()
                 if quit and state.console_state.keyb.buf.is_empty():
                     break
         except error.Exit:
             # pause before exit if requested
             if wait:
                 signals.video_queue.put(signals.Event(signals.VIDEO_SET_CAPTION, 'Press a key to close window'))
                 signals.video_queue.put(signals.Event(signals.VIDEO_SHOW_CURSOR, False))
                 state.console_state.keyb.pause = True
                 # this performs a blocking keystroke read if in pause state
                 events.check_events()
         finally:
             # close interfaces
             signals.video_queue.put(signals.Event(signals.VIDEO_QUIT))
             signals.message_queue.put(signals.Event(signals.AUDIO_QUIT))
             # persist unplayed tones in sound queue
             state.console_state.tone_queue_store = [
                     signals.save_queue(q) for q in signals.tone_queue]
             state.save()
             # close files if we opened any
             devices.close_files()
             devices.close_devices()
     except error.Reset:
         # delete state if resetting
         state.delete()
Ejemplo n.º 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)
Ejemplo n.º 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(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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
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)