예제 #1
0
파일: program.py 프로젝트: Yungzuck/pcbasic
def store_line(linebuf):
    """ Store the given line buffer. """
    if state.basic_state.protected:
        raise error.RunError(error.IFC)
    # get the new line number
    linebuf.seek(1)
    scanline = util.parse_line_number(linebuf)
    # check if linebuf is an empty line after the line number
    empty = (util.skip_white_read(linebuf) in tk.end_line)
    pos, afterpos, deleteable, beyond = find_pos_line_dict(scanline, scanline)
    if empty and not deleteable:
        raise error.RunError(error.UNDEFINED_LINE_NUMBER)
    # read the remainder of the program into a buffer to be pasted back after the write
    state.basic_state.bytecode.seek(afterpos)
    rest = state.basic_state.bytecode.read()
    # insert
    state.basic_state.bytecode.seek(pos)
    # write the line buffer to the program buffer
    length = 0
    if not empty:
        # set offsets
        linebuf.seek(3) # pass \x00\xC0\xDE
        length = len(linebuf.getvalue())
        state.basic_state.bytecode.write( '\0' + str(vartypes.integer_to_bytes(vartypes.int_to_integer_unsigned(program_memory_start + pos + length))) + linebuf.read())
    # write back the remainder of the program
    truncate_program(rest)
    # update all next offsets by shifting them by the length of the added line
    update_line_dict(pos, afterpos, length, deleteable, beyond)
    if not empty:
        state.basic_state.line_numbers[scanline] = pos
    # clear all program stacks
    flow.init_program()
    state.basic_state.last_stored = scanline
예제 #2
0
def erase_program():
    """ Erase the program from memory. """
    state.basic_state.bytecode.truncate(0)
    state.basic_state.bytecode.write('\0\0\0')
    state.basic_state.protected = False
    state.basic_state.line_numbers = {65536: 0}
    state.basic_state.current_statement = 0
    state.basic_state.last_stored = None
    # reset stacks
    flow.init_program()
예제 #3
0
파일: program.py 프로젝트: Yungzuck/pcbasic
def erase_program():
    """ Erase the program from memory. """
    state.basic_state.bytecode.truncate(0)
    state.basic_state.bytecode.write('\0\0\0')
    state.basic_state.protected = False
    state.basic_state.line_numbers = { 65536: 0 }
    state.basic_state.current_statement = 0
    state.basic_state.last_stored = None
    # reset stacks
    flow.init_program()
예제 #4
0
파일: program.py 프로젝트: Yungzuck/pcbasic
def delete(fromline, toline):
    """ Delete range of lines from stored program. """
    fromline = fromline if fromline is not None else min(state.basic_state.line_numbers)
    toline = toline if toline is not None else 65535
    startpos, afterpos, deleteable, beyond = find_pos_line_dict(fromline, toline)
    if not deleteable:
        # no lines selected
        raise error.RunError(error.IFC)
    # do the delete
    state.basic_state.bytecode.seek(afterpos)
    rest = state.basic_state.bytecode.read()
    state.basic_state.bytecode.seek(startpos)
    truncate_program(rest)
    # update line number dict
    update_line_dict(startpos, afterpos, 0, deleteable, beyond)
    # clear all program stacks
    flow.init_program()
예제 #5
0
def delete(fromline, toline):
    """ Delete range of lines from stored program. """
    fromline = fromline if fromline is not None else min(
        state.basic_state.line_numbers)
    toline = toline if toline is not None else 65535
    startpos, afterpos, deleteable, beyond = find_pos_line_dict(
        fromline, toline)
    if not deleteable:
        # no lines selected
        raise error.RunError(error.IFC)
    # do the delete
    state.basic_state.bytecode.seek(afterpos)
    rest = state.basic_state.bytecode.read()
    state.basic_state.bytecode.seek(startpos)
    truncate_program(rest)
    # update line number dict
    update_line_dict(startpos, afterpos, 0, deleteable, beyond)
    # clear all program stacks
    flow.init_program()
예제 #6
0
def store_line(linebuf):
    """ Store the given line buffer. """
    if state.basic_state.protected:
        raise error.RunError(error.IFC)
    # get the new line number
    linebuf.seek(1)
    scanline = util.parse_line_number(linebuf)
    # check if linebuf is an empty line after the line number
    empty = (util.skip_white_read(linebuf) in tk.end_line)
    pos, afterpos, deleteable, beyond = find_pos_line_dict(scanline, scanline)
    if empty and not deleteable:
        raise error.RunError(error.UNDEFINED_LINE_NUMBER)
    # read the remainder of the program into a buffer to be pasted back after the write
    state.basic_state.bytecode.seek(afterpos)
    rest = state.basic_state.bytecode.read()
    # insert
    state.basic_state.bytecode.seek(pos)
    # write the line buffer to the program buffer
    length = 0
    if not empty:
        # set offsets
        linebuf.seek(3)  # pass \x00\xC0\xDE
        length = len(linebuf.getvalue())
        state.basic_state.bytecode.write(
            '\0' +
            str(vartypes.value_to_uint(program_memory_start + pos + length)) +
            linebuf.read())
    # write back the remainder of the program
    truncate_program(rest)
    # update all next offsets by shifting them by the length of the added line
    update_line_dict(pos, afterpos, length, deleteable, beyond)
    if not empty:
        state.basic_state.line_numbers[scanline] = pos
    # clear all program stacks
    flow.init_program()
    state.basic_state.last_stored = scanline