• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python util.range_check函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中util.range_check函数的典型用法代码示例。如果您正苦于以下问题:Python range_check函数的具体用法?Python range_check怎么用?Python range_check使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了range_check函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: value_lof

def value_lof(ins):
    """ LOF: get length of file. """
    util.skip_white(ins)
    num = vartypes.pass_int_unpack(parse_bracket(ins), maxint=0xffff)
    util.range_check(0, 255, num)
    the_file = devices.get_file(num)
    return fp.pack(fp.Single.from_int(the_file.lof()))
开发者ID:gilsim12,项目名称:pcbasic,代码行数:7,代码来源:expressions.py


示例2: value_loc

def value_loc(ins):
    """ LOC: get file pointer. """
    util.skip_white(ins)
    num = vartypes.pass_int_unpack(parse_bracket(ins), maxint=0xffff)
    util.range_check(0, 255, num)
    the_file = devices.get_file(num)
    return vartypes.pack_int(the_file.loc())
开发者ID:nony05,项目名称:pcbasic,代码行数:7,代码来源:expressions.py


示例3: value_play

def value_play(ins):
    """ PLAY: get length of music queue. """
    voice = vartypes.pass_int_unpack(parse_bracket(ins))
    util.range_check(0, 255, voice)
    if not(is_pcjr_syntax and voice in (1, 2)):
        voice = 0
    return vartypes.int_to_integer_signed(state.console_state.sound.queue_length(voice))
开发者ID:gilsim12,项目名称:pcbasic,代码行数:7,代码来源:expressions.py


示例4: put

 def put(self, lcoord, array_name, operation_token):
     """ Put a sprite on the screen (PUT). """
     x0, y0 = self.view_coords(*self.get_window_physical(*lcoord))
     self.last_point = x0, y0
     try:
         _, byte_array, a_version = state.basic_state.arrays[array_name]
     except KeyError:
         byte_array = bytearray()
     try:
         spriterec = self.sprites[array_name]
         dx, dy, sprite, s_version = spriterec
     except KeyError:
         spriterec = None
     if (not spriterec) or (s_version != a_version):
         # we don't have it stored or it has been modified
         dx, dy = self.screen.mode.record_to_sprite_size(byte_array)
         sprite = self.screen.mode.array_to_sprite(byte_array, 4, dx, dy)
         # store it now that we have it!
         self.sprites[array_name] = (dx, dy, sprite, a_version)
     # sprite must be fully inside *viewport* boundary
     x1, y1 = x0+dx-1, y0+dy-1
     # Tandy screen 6 sprites are twice as wide as claimed
     if self.screen.mode.name == '640x200x4':
         x1 = x0 + 2*dx - 1
     # illegal fn call if outside viewport boundary
     vx0, vy0, vx1, vy1 = self.get_view()
     util.range_check(vx0, vx1, x0, x1)
     util.range_check(vy0, vy1, y0, y1)
     # apply the sprite to the screen
     self.screen.put_rect(x0, y0, x1, y1, sprite, operation_token)
开发者ID:Yungzuck,项目名称:pcbasic,代码行数:30,代码来源:graphics.py


示例5: get

 def get(self, lcoord0, lcoord1, array_name):
     """ Read a sprite from the screen (GET). """
     x0, y0 = self.view_coords(*self.get_window_physical(*lcoord0))
     x1, y1 = self.view_coords(*self.get_window_physical(*lcoord1))
     self.last_point = x1, y1
     try:
         _, byte_array, version = state.basic_state.arrays[array_name]
     except KeyError:
         raise error.RunError(error.IFC)
     dx, dy = x1-x0+1, y1-y0+1
     # Tandy screen 6 simply GETs twice the width, it seems
     if self.screen.mode.name == '640x200x4':
         x1 = x0 + 2*dx - 1
     # illegal fn call if outside viewport boundary
     vx0, vy0, vx1, vy1 = self.get_view()
     util.range_check(vx0, vx1, x0, x1)
     util.range_check(vy0, vy1, y0, y1)
     # set size record
     byte_array[0:4] = self.screen.mode.sprite_size_to_record(dx, dy)
     # read from screen and convert to byte array
     sprite = self.screen.get_rect(x0, y0, x1, y1)
     try:
         self.screen.mode.sprite_to_array(sprite, dx, dy, byte_array, 4)
     except ValueError:
         raise error.RunError(error.IFC)
     # store a copy in the sprite store
     self.sprites[array_name] = (dx, dy, sprite, version)
开发者ID:Yungzuck,项目名称:pcbasic,代码行数:27,代码来源:graphics.py


示例6: value_lpos

def value_lpos(ins):
    """ LPOS: get the current printer column. """
    num = vartypes.pass_int_unpack(parse_bracket(ins))
    util.range_check(0, 3, num)
    printer = state.io_state.devices['LPT' + max(1, num) + ':']
    if printer.device_file:
        return vartypes.int_to_integer_signed(printer.device_file.col)
    else:
        return vartypes.int_to_integer_signed(1)
开发者ID:gilsim12,项目名称:pcbasic,代码行数:9,代码来源:expressions.py


示例7: value_eof

def value_eof(ins):
    """ EOF: get end-of-file. """
    util.skip_white(ins)
    num = vartypes.pass_int_unpack(parse_bracket(ins), maxint=0xffff)
    if num == 0:
        return vartypes.null('%')
    util.range_check(0, 255, num)
    the_file = devices.get_file(num, 'IR')
    return vartypes.bool_to_integer(the_file.eof())
开发者ID:gilsim12,项目名称:pcbasic,代码行数:9,代码来源:expressions.py


示例8: parse_file_number

def parse_file_number(ins, file_mode='IOAR'):
    """ Helper function: parse a file number and retrieve the file object. """
    screen = None
    if util.skip_white_read_if(ins, ('#',)):
        number = vartypes.pass_int_unpack(parse_expression(ins))
        util.range_check(0, 255, number)
        screen = devices.get_file(number, file_mode)
        util.require_read(ins, (',',))
    return screen
开发者ID:gilsim12,项目名称:pcbasic,代码行数:9,代码来源:expressions.py


示例9: value_pen

def value_pen(ins):
    """ PEN: poll the light pen. """
    fn = vartypes.pass_int_unpack(parse_bracket(ins))
    util.range_check(0, 9, fn)
    pen = state.console_state.pen.poll(fn)
    if pen is None or not state.basic_state.events.pen.enabled:
        # should return 0 or char pos 1 if PEN not ON
        pen = 1 if fn >= 6 else 0
    return vartypes.int_to_integer_signed(pen)
开发者ID:gilsim12,项目名称:pcbasic,代码行数:9,代码来源:expressions.py


示例10: value_environ

def value_environ(ins):
    """ ENVIRON$: get environment string. """
    util.require_read(ins, ('$',))
    expr = parse_bracket(ins)
    if expr[0] == '$':
        return state.basic_state.strings.store(shell.get_env(var.copy_str(expr)))
    else:
        expr = vartypes.pass_int_unpack(expr)
        util.range_check(1, 255, expr)
        return state.basic_state.strings.store(shell.get_env_entry(expr))
开发者ID:gilsim12,项目名称:pcbasic,代码行数:10,代码来源:expressions.py


示例11: value_left

def value_left(ins):
    """ LEFT$: get substring at the start of string. """
    util.require_read(ins, ('(',))
    s = vartypes.pass_string_unpack(parse_expression(ins))
    util.require_read(ins, (',',))
    stop = vartypes.pass_int_unpack(parse_expression(ins))
    util.require_read(ins, (')',))
    util.range_check(0, 255, stop)
    if stop == 0:
        return vartypes.null['$']
    stop = min(stop, len(s))
    return vartypes.pack_string(s[:stop])
开发者ID:nony05,项目名称:pcbasic,代码行数:12,代码来源:expressions.py


示例12: value_right

def value_right(ins):
    """ RIGHT$: get substring at the end of string. """
    util.require_read(ins, ('(',))
    s = var.copy_str(vartypes.pass_string(parse_expression(ins)))
    util.require_read(ins, (',',))
    stop = vartypes.pass_int_unpack(parse_expression(ins))
    util.require_read(ins, (')',))
    util.range_check(0, 255, stop)
    if stop == 0:
        return vartypes.null('$')
    stop = min(stop, len(s))
    return state.basic_state.strings.store(s[-stop:])
开发者ID:gilsim12,项目名称:pcbasic,代码行数:12,代码来源:expressions.py


示例13: value_input

def value_input(ins):
    """ INPUT$: get characters from the keyboard or a file. """
    util.require_read(ins, ('$',))
    util.require_read(ins, ('(',))
    num = vartypes.pass_int_unpack(parse_expression(ins))
    util.range_check(1, 255, num)
    infile = backend.kybd_file
    if util.skip_white_read_if(ins, (',',)):
        infile = iolayer.get_file(parse_file_number_opthash(ins))
    util.require_read(ins, (')',))
    word = vartypes.pack_string(bytearray(infile.read_raw(num)))
    if len(word) < num:
        # input past end
        raise error.RunError(62)
    return word
开发者ID:boriel,项目名称:pcbasic,代码行数:15,代码来源:expressions.py


示例14: value_input

def value_input(ins):
    """ INPUT$: get characters from the keyboard or a file. """
    util.require_read(ins, ('$',))
    util.require_read(ins, ('(',))
    num = vartypes.pass_int_unpack(parse_expression(ins))
    util.range_check(1, 255, num)
    infile = state.io_state.kybd_file
    if util.skip_white_read_if(ins, (',',)):
        infile = devices.get_file(parse_file_number_opthash(ins))
    util.require_read(ins, (')',))
    word = bytearray(infile.read_raw(num))
    if len(word) < num:
        # input past end
        raise error.RunError(error.INPUT_PAST_END)
    return state.basic_state.strings.store(word)
开发者ID:gilsim12,项目名称:pcbasic,代码行数:15,代码来源:expressions.py


示例15: value_instr

def value_instr(ins):
    """ INSTR: find substring in string. """
    util.require_read(ins, ('(',))
    big, small, n = '', '', 1
    s = parse_expression(ins, empty_err=error.STX)
    if s[0] != '$':
        n = vartypes.pass_int_unpack(s)
        util.range_check(1, 255, n)
        util.require_read(ins, (',',))
        big = vartypes.pass_string_unpack(parse_expression(ins, allow_empty=True))
    else:
        big = vartypes.pass_string_unpack(s)
    util.require_read(ins, (',',))
    small = vartypes.pass_string_unpack(parse_expression(ins, allow_empty=True))
    util.require_read(ins, (')',))
    return vartypes.str_instr(big, small, n)
开发者ID:nony05,项目名称:pcbasic,代码行数:16,代码来源:expressions.py


示例16: value_mid

def value_mid(ins):
    """ MID$: get substring. """
    util.require_read(ins, ('(',))
    s = var.copy_str(vartypes.pass_string(parse_expression(ins)))
    util.require_read(ins, (',',))
    start = vartypes.pass_int_unpack(parse_expression(ins))
    if util.skip_white_read_if(ins, (',',)):
        num = vartypes.pass_int_unpack(parse_expression(ins))
    else:
        num = len(s)
    util.require_read(ins, (')',))
    util.range_check(1, 255, start)
    util.range_check(0, 255, num)
    if num == 0 or start > len(s):
        return vartypes.null('$')
    start -= 1
    stop = start + num
    stop = min(stop, len(s))
    return state.basic_state.strings.store(s[start:stop])
开发者ID:gilsim12,项目名称:pcbasic,代码行数:19,代码来源:expressions.py


示例17: value_pmap

def value_pmap(ins):
    """ PMAP: convert between logical and physical coordinates. """
    util.require_read(ins, ('(',))
    coord = parse_expression(ins)
    util.require_read(ins, (',',))
    mode = vartypes.pass_int_unpack(parse_expression(ins))
    util.require_read(ins, (')',))
    util.range_check(0, 3, mode)
    screen = state.console_state.screen
    if screen.mode.is_text_mode:
        return vartypes.null('%')
    if mode == 0:
        value, _ = screen.drawing.get_window_physical(fp.unpack(vartypes.pass_single(coord)), fp.Single.zero)
        return vartypes.int_to_integer_signed(value)
    elif mode == 1:
        _, value = screen.drawing.get_window_physical(fp.Single.zero, fp.unpack(vartypes.pass_single(coord)))
        return vartypes.int_to_integer_signed(value)
    elif mode == 2:
        value, _ = screen.drawing.get_window_logical(vartypes.pass_int_unpack(coord), 0)
        return fp.pack(value)
    elif mode == 3:
        _, value = screen.drawing.get_window_logical(0, vartypes.pass_int_unpack(coord))
        return fp.pack(value)
开发者ID:gilsim12,项目名称:pcbasic,代码行数:23,代码来源:expressions.py


示例18: value_instr

def value_instr(ins):
    """ INSTR: find substring in string. """
    util.require_read(ins, ('(',))
    big, small, n = '', '', 1
    # followed by coma so empty will raise STX
    s = parse_expression(ins)
    if s[0] != '$':
        n = vartypes.pass_int_unpack(s)
        util.range_check(1, 255, n)
        util.require_read(ins, (',',))
        big = vartypes.pass_string(parse_expression(ins, allow_empty=True))
    else:
        big = vartypes.pass_string(s)
    util.require_read(ins, (',',))
    small = vartypes.pass_string(parse_expression(ins, allow_empty=True))
    util.require_read(ins, (')',))
    big, small = var.copy_str(big), var.copy_str(small)
    if big == '' or n > len(big):
        return vartypes.null('%')
    # BASIC counts string positions from 1
    find = big[n-1:].find(small)
    if find == -1:
        return vartypes.null('%')
    return vartypes.int_to_integer_signed(n + find)
开发者ID:gilsim12,项目名称:pcbasic,代码行数:24,代码来源:expressions.py


示例19: value_screen

def value_screen(ins):
    """ SCREEN: get char or attribute at a location. """
    util.require_read(ins, ('(',))
    row, col, z = parse_int_list(ins, 3, 5)
    if row is None or col is None:
        raise error.RunError(error.IFC)
    if z is None:
        z = 0
    cmode = state.console_state.screen.mode
    util.range_check(1, cmode.height, row)
    if state.console_state.view_set:
        util.range_check(state.console_state.view_start, state.console_state.scroll_height, row)
    util.range_check(1, cmode.width, col)
    util.range_check(0, 255, z)
    util.require_read(ins, (')',))
    if z and not cmode.is_text_mode:
        return vartypes.null['%']
    else:
        return vartypes.pack_int(state.console_state.screen.apage.get_char_attr(row, col, z!=0))
开发者ID:nony05,项目名称:pcbasic,代码行数:19,代码来源:expressions.py


示例20: value_screen

def value_screen(ins):
    """ SCREEN: get char or attribute at a location. """
    util.require_read(ins, ('(',))
    row = vartypes.pass_int_unpack(parse_expression(ins))
    util.require_read(ins, (',',), err=error.IFC)
    col = vartypes.pass_int_unpack(parse_expression(ins))
    z = 0
    if util.skip_white_read_if(ins, (',',)):
        z = vartypes.pass_int_unpack(parse_expression(ins))
    cmode = state.console_state.screen.mode
    util.range_check(1, cmode.height, row)
    if state.console_state.view_set:
        util.range_check(state.console_state.view_start, state.console_state.scroll_height, row)
    util.range_check(1, cmode.width, col)
    util.range_check(0, 255, z)
    util.require_read(ins, (')',))
    if z and not cmode.is_text_mode:
        return vartypes.null('%')
    else:
        return vartypes.int_to_integer_signed(state.console_state.screen.apage.get_char_attr(row, col, z!=0))
开发者ID:gilsim12,项目名称:pcbasic,代码行数:20,代码来源:expressions.py



注:本文中的util.range_check函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.read_dfile函数代码示例发布时间:2022-05-26
下一篇:
Python util.raises函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap