当前位置: 首页>>代码示例>>Python>>正文


Python snapshot.get_snapshot函数代码示例

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


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

示例1: main

def main(args):
    parser = argparse.ArgumentParser(
        usage='bin2tap.py [options] FILE [file.tap]',
        description="Convert a binary (raw memory) file or a SNA, SZX or Z80 snapshot into a TAP file. "
                    "FILE may be a regular file, or '-' to read a binary file from standard input.",
        add_help=False
    )
    parser.add_argument('infile', help=argparse.SUPPRESS, nargs='?')
    parser.add_argument('outfile', help=argparse.SUPPRESS, nargs='?')
    group = parser.add_argument_group('Options')
    group.add_argument('-c', '--clear', dest='clear', metavar='N', type=int,
                       help="Use a 'CLEAR N' command in the BASIC loader and leave the stack pointer alone")
    group.add_argument('-e', '--end', dest='end', metavar='ADDR', type=int, default=65536,
                       help="Set the end address when reading a snapshot")
    group.add_argument('-o', '--org', dest='org', metavar='ORG', type=int,
                       help="Set the origin address (default: 16384 for a snapshot, otherwise 65536 minus the length of FILE)")
    group.add_argument('-p', '--stack', dest='stack', metavar='STACK', type=int,
                       help="Set the stack pointer (default: ORG)")
    group.add_argument('-s', '--start', dest='start', metavar='START', type=int,
                       help="Set the start address to JP to (default: ORG)")
    group.add_argument('-S', '--screen', dest='screen', metavar='FILE',
                       help="Add a loading screen to the TAP file; FILE may be a snapshot or a 6912-byte SCR file")
    group.add_argument('-t', '--tapfile', dest='tapfile', metavar='TAPFILE',
                       help="Set the TAP filename")
    group.add_argument('-V', '--version', action='version', version='SkoolKit {}'.format(VERSION),
                       help='Show SkoolKit version number and exit')

    namespace, unknown_args = parser.parse_known_args(args)
    infile = namespace.infile
    if unknown_args or infile is None:
        parser.exit(2, parser.format_help())
    if infile.lower().endswith(('.sna', '.szx', '.z80')):
        org = namespace.org or 16384
        if org >= namespace.end:
            raise SkoolKitError('End address must be greater than {}'.format(org))
        ram = get_snapshot(infile)[org:namespace.end]
    else:
        ram = read_bin_file(infile, 49152)
        if len(ram) == 0:
            raise SkoolKitError('{} is empty'.format(infile))
        org = namespace.org or 65536 - len(ram)
    clear = namespace.clear
    start = namespace.start or org
    stack = namespace.stack or org
    tapfile = namespace.outfile or namespace.tapfile
    if tapfile is None:
        if infile.lower().endswith(('.bin', '.sna', '.szx', '.z80')):
            prefix = infile[:-4]
        elif infile == '-':
            prefix = 'program'
        else:
            prefix = infile
        tapfile = prefix + ".tap"
    scr = namespace.screen
    if scr is not None:
        if scr.lower().endswith(('.sna', '.szx', '.z80')):
            scr = get_snapshot(scr)[16384:23296]
        else:
            scr = read_bin_file(scr, 6912)
    run(ram, clear, org, start, stack, tapfile, scr)
开发者ID:Wolfe-Lyon,项目名称:skoolkit,代码行数:60,代码来源:bin2tap.py

示例2: test_szx_128k_no_specregs

 def test_szx_128k_no_specregs(self):
     szx = self._get_szx_header(2, specregs=False)
     tmp_szx = self.write_bin_file(szx, suffix='.szx')
     try:
         get_snapshot(tmp_szx)
     except SnapshotError as e:
         self.assertEqual(e.args[0], "SPECREGS (SPCR) block not found")
开发者ID:TitsMagee,项目名称:skoolkit,代码行数:7,代码来源:test_snapshot.py

示例3: test_szx_48k_missing_page

 def test_szx_48k_missing_page(self):
     szx = self._get_szx_header()
     szx.extend(self._get_zxstrampage(5, True, [0] * 16384))
     tmp_szx = self.write_bin_file(szx, suffix='.szx')
     try:
         get_snapshot(tmp_szx)
     except SnapshotError as e:
         self.assertEqual(e.args[0], "Page 2 not found")
开发者ID:TitsMagee,项目名称:skoolkit,代码行数:8,代码来源:test_snapshot.py

示例4: test_bad_z80

 def test_bad_z80(self):
     header = [0] * 30
     header[6] = 255 # Set PC > 0 to indicate a v1 Z80 snapshot
     header[12] |= 32 # Signal that the RAM data block is compressed
     z80 = header + [255] # Good byte to start with
     z80 += [237, 237, 0, 11] # Bad block of length 0
     z80 += [0, 237, 237, 0] # Terminator
     z80_file = self.write_bin_file(z80, suffix='.z80')
     with self.assertRaisesRegexp(SnapshotError, 'Found ED ED 00 0B'):
         get_snapshot(z80_file)
开发者ID:TitsMagee,项目名称:skoolkit,代码行数:10,代码来源:test_snapshot.py

示例5: test_szx_48k_bad_page_size

 def test_szx_48k_bad_page_size(self):
     szx = self._get_szx_header()
     ram = [0, 0, 0] # Bad page size (3 != 16384)
     page = 5
     szx.extend(self._get_zxstrampage(page, False, ram))
     tmp_szx = self.write_bin_file(szx, suffix='.szx')
     try:
         get_snapshot(tmp_szx)
     except SnapshotError as e:
         self.assertEqual(e.args[0], "Page {0} is {1} bytes (should be 16384)".format(5, len(ram)))
开发者ID:TitsMagee,项目名称:skoolkit,代码行数:10,代码来源:test_snapshot.py

示例6: test_szx_48k_bad_zlib_block

 def test_szx_48k_bad_zlib_block(self):
     szx = self._get_szx_header()
     szx.extend((82, 65, 77, 80)) # RAMP
     ram = (1, 2, 3, 4, 5, 6, 7, 8) # Invalid zlib block
     size = len(ram) + 3
     szx.extend((size % 256, size // 256, 0, 0))
     szx.extend((1, 0)) # Compressed
     page = 5
     szx.append(page)
     tmp_szx = self.write_bin_file(szx, suffix='.szx')
     try:
         get_snapshot(tmp_szx)
     except SnapshotError as e:
         self.assertTrue(e.args[0].startswith("Error while decompressing page {0}:".format(page)))
开发者ID:TitsMagee,项目名称:skoolkit,代码行数:14,代码来源:test_snapshot.py

示例7: _find_text

def _find_text(infile, text):
    size = len(text)
    byte_values = [ord(c) for c in text]
    snapshot = get_snapshot(infile)
    for a in range(16384, 65536 - size + 1):
        if snapshot[a:a + size] == byte_values:
            print("{0}-{1} {0:04X}-{1:04X}: {2}".format(a, a + size - 1, text))
开发者ID:Wolfe-Lyon,项目名称:skoolkit,代码行数:7,代码来源:snapinfo.py

示例8: run

def run(infile, outfile, options):
    x, y = [int(c) for c in options.xy.split(',', 1)]
    w, h = [int(c) for c in options.wh.split(',', 1)]
    w = min(32 - x, w)
    h = min(24 - y, h)

    if infile[-4:].lower() == '.scr':
        with open(infile, 'rb') as f:
            scr = bytearray(f.read(6912))
        snapshot = [0] * 65536
        snapshot[16384:16384 + len(scr)] = scr
    else:
        snapshot = get_snapshot(infile)

    for spec in options.pokes:
        poke(snapshot, spec)

    scr = snapshot[16384:23296]

    if options.invert:
        for i in range(6144, 6912):
            if scr[i] & 128:
                df = 2048 * (i // 256 - 24) + i % 256
                for j in range(df, df + 2048, 256):
                    scr[j] ^= 255
                scr[i] -= 128

    scrshot = _get_screenshot(scr, x, y, w, h, options.flip)
    _write_image(scrshot, outfile, options.scale, options.animated)
开发者ID:Wolfe-Lyon,项目名称:skoolkit,代码行数:29,代码来源:scr2img.py

示例9: _read_z80

def _read_z80(z80file):
    data = read_bin_file(z80file)
    if get_word(data, 6) > 0:
        header = data[:30]
    else:
        header_len = 32 + get_word(data, 30)
        header = data[:header_len]
    return list(header), get_snapshot(z80file)
开发者ID:skoolkid,项目名称:skoolkit,代码行数:8,代码来源:snapmod.py

示例10: test_sna_48k

 def test_sna_48k(self):
     header = [0] * 27
     exp_ram = [(n + 23) & 255 for n in range(49152)]
     sna = header + exp_ram
     tmp_sna = self.write_bin_file(sna, suffix='.sna')
     snapshot = get_snapshot(tmp_sna)
     ram = snapshot[16384:]
     self.assertEqual(len(ram), 49152)
     self.assertEqual(ram, exp_ram)
开发者ID:TitsMagee,项目名称:skoolkit,代码行数:9,代码来源:test_snapshot.py

示例11: run

def run(subcommand):
    func = functions[subcommand][0]
    if not os.path.isdir(BUILD_DIR):
        os.mkdir(BUILD_DIR)
    if not os.path.isfile(MM_Z80):
        tap2sna.main(('-d', BUILD_DIR, '@{}/manic_miner.t2s'.format(MANICMINER_HOME)))
    ctlfile = '{}/{}.ctl'.format(BUILD_DIR, subcommand)
    with open(ctlfile, 'wt') as f:
        f.write(func(get_snapshot(MM_Z80)))
    sna2skool.main(('-c', ctlfile, MM_Z80))
开发者ID:skoolkid,项目名称:manicminer,代码行数:10,代码来源:mm2skool.py

示例12: main

def main(args):
    parser = argparse.ArgumentParser(
        usage='snapinfo.py [options] file',
        description="Analyse an SNA, SZX or Z80 snapshot.",
        add_help=False
    )
    parser.add_argument('infile', help=argparse.SUPPRESS, nargs='?')
    group = parser.add_argument_group('Options')
    group.add_argument('-b', '--basic', action='store_true',
                       help='List the BASIC program.')
    group.add_argument('-f', '--find', metavar='A[,B...[-M[-N]]]',
                       help='Search for the byte sequence A,B... with distance ranging from M to N (default=1) between bytes.')
    group.add_argument('-p', '--peek', metavar='A[-B[-C]]', action='append',
                       help='Show the contents of addresses A TO B STEP C. This option may be used multiple times.')
    group.add_argument('-t', '--find-text', dest='text', metavar='TEXT',
                       help='Search for a text string.')
    group.add_argument('-T', '--find-tile', dest='tile', metavar='X,Y[-M[-N]]',
                       help='Search for the graphic data of the tile at (X,Y) with distance ranging from M to N (default=1) between bytes.')
    group.add_argument('-v', '--variables', action='store_true',
                       help='List variables.')
    group.add_argument('-V', '--version', action='version', version='SkoolKit {}'.format(VERSION),
                       help='Show SkoolKit version number and exit.')
    group.add_argument('-w', '--word', metavar='A[-B[-C]]', action='append',
                       help='Show the words at addresses A TO B STEP C. This option may be used multiple times.')
    namespace, unknown_args = parser.parse_known_args(args)
    if unknown_args or namespace.infile is None:
        parser.exit(2, parser.format_help())
    infile = namespace.infile
    snapshot_type = infile[-4:].lower()
    if snapshot_type not in ('.sna', '.szx', '.z80'):
        raise SkoolKitError('Unrecognised snapshot type')

    if any((namespace.find, namespace.tile, namespace.text, namespace.peek, namespace.word, namespace.basic, namespace.variables)):
        snapshot = get_snapshot(infile)
        if namespace.find:
            _find(snapshot, namespace.find)
        elif namespace.tile:
            _find_tile(snapshot, namespace.tile)
        elif namespace.text:
            _find_text(snapshot, namespace.text)
        elif namespace.peek:
            _peek(snapshot, namespace.peek)
        elif namespace.word:
            _word(snapshot, namespace.word)
        else:
            if namespace.basic:
                print(BasicLister().list_basic(snapshot))
            if namespace.variables:
                print(VariableLister().list_variables(snapshot))
    elif snapshot_type == '.sna':
        _analyse_sna(infile)
    elif snapshot_type == '.z80':
        _analyse_z80(infile)
    else:
        _analyse_szx(infile)
开发者ID:skoolkid,项目名称:skoolkit,代码行数:55,代码来源:snapinfo.py

示例13: find

def find(infile, byte_seq):
    step = 1
    if '-' in byte_seq:
        byte_seq, step = byte_seq.split('-', 1)
        step = get_int_param(step)
    byte_values = [get_int_param(i) for i in byte_seq.split(',')]
    offset = step * len(byte_values)
    snapshot = get_snapshot(infile)
    for a in range(16384, 65537 - offset):
        if snapshot[a:a + offset:step] == byte_values:
            print("{}-{}-{}: {}".format(a, a + offset - step, step, byte_seq))
开发者ID:TitsMagee,项目名称:skoolkit,代码行数:11,代码来源:analyse-sna.py

示例14: test_tap_file_in_zip_archive

 def test_tap_file_in_zip_archive(self):
     data = [1]
     block = create_tap_data_block(data)
     tap_name = 'game.tap'
     zip_fname = self._write_tap([block], zip_archive=True, tap_name=tap_name)
     z80file = self.write_bin_file(suffix='.z80')
     start = 16385
     output, error = self.run_tap2sna('--force --ram load=1,{} {} {}'.format(start, zip_fname, z80file))
     self.assertEqual(output, 'Extracting {}\nWriting {}\n'.format(tap_name, z80file))
     self.assertEqual(error, '')
     snapshot = get_snapshot(z80file)
     self.assertEqual(data, snapshot[start:start + len(data)])
开发者ID:skoolkid,项目名称:skoolkit,代码行数:12,代码来源:test_tap2sna.py

示例15: test_standard_load_ignores_headerless_block

    def test_standard_load_ignores_headerless_block(self):
        code_start = 16384
        code_header = self._create_tap_bytes_header_block(code_start)
        code = [2]
        blocks = [code_header, self._create_tap_data_block(code)]
        blocks.append(self._create_tap_data_block([23]))

        tapfile = self._write_tap(blocks)
        z80file = self.write_bin_file(suffix='.z80')
        output, error = self.run_tap2sna('--force {} {}'.format(tapfile, z80file))
        self.assertEqual(error, '')
        snapshot = get_snapshot(z80file)
        self.assertEqual(snapshot[code_start:code_start + len(code)], code)
开发者ID:TitsMagee,项目名称:skoolkit,代码行数:13,代码来源:test_tap2sna.py


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