def run(infile, options, outfile): header, snapshot = _read_z80(infile) for spec in options.moves: move(snapshot, spec) for spec in options.pokes: poke(snapshot, spec) set_z80_registers(header, *options.reg) set_z80_state(header, *options.state) _write_z80(header, snapshot, outfile)
def run(infile, options, outfile): header, snapshot = _read_z80(infile) for spec in options.moves: move(snapshot, spec) for spec in options.pokes: poke(snapshot, spec) set_z80_registers(header, *options.reg) set_z80_state(header, *options.state) _write_z80(header, snapshot, outfile)
def run(infile, outfile, options): if options.binary or options.org is not None: snapshot = read_bin_file(infile, 49152) if options.org is None: org = 65536 - len(snapshot) else: org = options.org snapshot = [0] * org + list(snapshot) + [0] * (65536 - org - len(snapshot)) elif infile[-4:].lower() == '.scr': scr = read_bin_file(infile, 6912) snapshot = [0] * 65536 snapshot[16384:16384 + len(scr)] = scr elif infile[-4:].lower() in ('.sna', '.szx', '.z80'): snapshot = get_snapshot(infile) else: try: snapshot = BinWriter(infile, fix_mode=options.fix_mode).snapshot except SkoolKitError: raise except: raise SkoolKitError( 'Unable to parse {} as a skool file'.format(infile)) for spec in options.moves: move(snapshot, spec) for spec in options.pokes: poke(snapshot, spec) if options.macro is not None: match = re.match('(#?)(FONT|SCR|UDG|UDGARRAY)([^A-Z]|$)', options.macro) if match: macro = match.group(2) try: frame = MACROS[macro](snapshot, options.macro[match.end(2):]) except skoolmacro.MacroParsingError as e: raise SkoolKitError('Invalid #{} macro: {}'.format( macro, e.args[0])) else: raise SkoolKitError('Macro must be #FONT, #SCR, #UDG or #UDGARRAY') else: (x, y), (w, h) = options.origin, options.size frame = Frame(scr_udgs(snapshot, x, y, w, h), options.scale) if options.invert: for row in frame.udgs: for udg in row: if udg.attr & 128: udg.data = [b ^ 255 for b in udg.data] udg.attr &= 127 flip_udgs(frame.udgs, options.flip) rotate_udgs(frame.udgs, options.rotate) _write_image(frame, outfile, options.animated)
def _get_ram(blocks, options): snapshot = [0] * 65536 operations = [] standard_load = True for spec in options.ram_ops: op_type, sep, param_str = spec.partition('=') if op_type in ('load', 'move', 'poke', 'sysvars'): operations.append((op_type, param_str)) if op_type == 'load': standard_load = False else: raise SkoolKitError("Invalid operation: {}".format(spec)) if standard_load: start = None for block_num, block in enumerate(blocks, 1): if block: if block[0] == 0 and len(block) >= 19: # Header block_type = block[1] if block_type == 3: # Bytes start = block[14] + 256 * block[15] elif block_type == 0: # Program start = 23755 else: raise TapeError( 'Unknown block type ({}) in header block {}'. format(block_type, block_num)) elif block[0] == 255 and start is not None: # Data _load_block(snapshot, block, start) start = None counters = {} for op_type, param_str in operations: if op_type == 'load': _load(snapshot, counters, blocks, param_str) elif op_type == 'move': move(snapshot, param_str) elif op_type == 'poke': poke(snapshot, param_str) elif op_type == 'sysvars': snapshot[23552:23755] = SYSVARS return snapshot[16384:]
def _get_ram(blocks, options): snapshot = [0] * 65536 operations = [] standard_load = True for spec in options.ram_ops: op_type, param_str = spec.split('=', 1) if op_type in ('load', 'move', 'poke'): operations.append((op_type, param_str)) if op_type == 'load': standard_load = False else: raise SkoolKitError("Invalid operation: {}".format(spec)) if standard_load: start = None for block_num, block in enumerate(blocks, 1): if block: if block[0] == 0 and len(block) >= 19: # Header block_type = block[1] if block_type == 3: # Bytes start = block[14] + 256 * block[15] elif block_type == 0: # Program start = 23755 else: raise TapeError('Unknown block type ({}) in header block {}'.format(block_type, block_num)) elif block[0] == 255 and start is not None: # Data _load_block(snapshot, block, start) start = None counters = {} for op_type, param_str in operations: if op_type == 'load': _load(snapshot, counters, blocks, param_str) elif op_type == 'move': move(snapshot, param_str) elif op_type == 'poke': poke(snapshot, param_str) return snapshot[16384:]
def run(infile, outfile, options): if options.binary or options.org is not None or infile[-4:].lower() in ('.sna', '.szx', '.z80'): snapshot = make_snapshot(infile, options.org)[0] elif infile[-4:].lower() == '.scr': snapshot = make_snapshot(infile, 16384)[0] else: try: snapshot = BinWriter(infile, fix_mode=options.fix_mode).snapshot except SkoolKitError: raise except: raise SkoolKitError('Unable to parse {} as a skool file'.format(infile)) for spec in options.moves: move(snapshot, spec) for spec in options.pokes: poke(snapshot, spec) if options.macro is not None: match = re.match('(#?)(FONT|SCR|UDG|UDGARRAY)([^A-Z]|$)', options.macro) if match: macro = match.group(2) try: frame = MACROS[macro](snapshot, options.macro[match.end(2):]) except skoolmacro.MacroParsingError as e: raise SkoolKitError('Invalid #{} macro: {}'.format(macro, e.args[0])) else: raise SkoolKitError('Macro must be #FONT, #SCR, #UDG or #UDGARRAY') else: (x, y), (w, h) = options.origin, options.size frame = Frame(scr_udgs(snapshot, x, y, w, h), options.scale) if options.invert: for row in frame.udgs: for udg in row: if udg.attr & 128: udg.data = [b^255 for b in udg.data] udg.attr &= 127 flip_udgs(frame.udgs, options.flip) rotate_udgs(frame.udgs, options.rotate) _write_image(frame, outfile, options.animated)
def run(infile, outfile, options): ram = list(read_bin_file(infile, 49152)) org = options.org or 65536 - len(ram) snapshot = [0] * org + ram + [0] * (65536 - org - len(ram)) if options.start is None: start = org else: start = options.start if options.stack is None: stack = org else: stack = options.stack for spec in options.pokes: poke(snapshot, spec) parent_dir = os.path.dirname(outfile) if parent_dir and not os.path.isdir(parent_dir): os.makedirs(parent_dir) registers = ['sp={}'.format(stack), 'pc={}'.format(start)] + options.reg state = ['border={}'.format(options.border)] + options.state write_z80v3(outfile, snapshot[16384:], registers, state)