Ejemplo n.º 1
0
def run(infile, outfile, options):
    snapshot_reader = get_snapshot_reader()
    if options.binary or options.org is not None or snapshot_reader.can_read(
            infile):
        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)
Ejemplo n.º 2
0
def run(infile, options, config):
    if any((options.find, options.tile, options.text, options.call_graph,
            options.peek, options.word, options.basic, options.variables)):
        snapshot, start, end = make_snapshot(infile,
                                             options.org,
                                             page=options.page)
        if options.find:
            _find(snapshot, options.find)
        elif options.tile:
            _find_tile(snapshot, options.tile)
        elif options.text:
            _find_text(snapshot, options.text)
        elif options.call_graph:
            _call_graph(snapshot, options.ctlfiles, infile, start, end, config)
        elif options.peek:
            _peek(snapshot, options.peek, config['Peek'])
        elif options.word:
            _word(snapshot, options.word, config['Word'])
        else:
            if options.basic:
                print(BasicLister().list_basic(snapshot))
            if options.variables:
                print(VariableLister().list_variables(snapshot))
    else:
        snapshot_type = infile[-4:].lower()
        if snapshot_type == '.sna':
            _analyse_sna(infile)
        elif snapshot_type == '.z80':
            _analyse_z80(infile)
        elif snapshot_type == '.szx':
            _analyse_szx(infile)
Ejemplo n.º 3
0
def run(infile, options, config):
    snapshot, start, end = make_snapshot(infile, options.org, options.start,
                                         options.end, options.page)
    ctl_parser = get_ctl_parser(options.ctlfiles, infile, options.start,
                                options.end, start, end)
    writer = SkoolWriter(snapshot, ctl_parser, options, config)
    writer.write_skool(config['ListRefs'], config['Text'])
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
def run(snafile, options, config):
    snapshot, start, end = make_snapshot(snafile, options.org, options.start, options.end, options.page)

    if options.ctlfiles:
        # Use control file(s)
        if len(options.ctlfiles) > 1:
            suffix = 's'
        else:
            suffix = ''
        info('Using control file{}: {}'.format(suffix, ', '.join(options.ctlfiles)))
        ctl_parser = CtlParser()
        ctl_parser.parse_ctls(options.ctlfiles, options.start, options.end)
    else:
        ctl_parser = CtlParser({start: 'c', end: 'i'})
    writer = SkoolWriter(snapshot, ctl_parser, options, config)
    writer.write_skool(config['ListRefs'], config['Text'])
Ejemplo n.º 6
0
def run(snafile, options, config):
    words = set()
    dict_fname = config['Dictionary']
    if dict_fname:
        if find_file(dict_fname):
            info("Using dictionary file: {}".format(dict_fname))
            with open_file(config['Dictionary']) as f:
                for line in f:
                    word = line.strip().lower()
                    if word:
                        words.add(word)
        else:
            info("Dictionary file '{}' not found".format(dict_fname))
    ctl_config = Config(config['TextChars'], config['TextMinLengthCode'], config['TextMinLengthData'], words)
    snapshot, start, end = make_snapshot(snafile, options.org, options.start, options.end, options.page)
    ctls = get_component('ControlFileGenerator').generate_ctls(snapshot, start, end, options.code_map, ctl_config)
    write_ctl(ctls, options.ctl_hex)
Ejemplo n.º 7
0
def run(snafile, options, config):
    snapshot, start, end = make_snapshot(snafile, options.org, options.start, options.end, options.page)

    if options.sftfile:
        # Use a skool file template
        info('Using skool file template: {}'.format(options.sftfile))
        writer = SftParser(snapshot, options.sftfile, config['DefbZfill'], options.base == 16, options.case == 1)
        writer.write_skool(options.start, options.end)
        return

    if options.ctlfiles:
        # Use control file(s)
        if len(options.ctlfiles) > 1:
            suffix = 's'
        else:
            suffix = ''
        info('Using control file{}: {}'.format(suffix, ', '.join(options.ctlfiles)))
        ctl_parser = CtlParser()
        ctl_parser.parse_ctls(options.ctlfiles, options.start, options.end)
    else:
        ctl_parser = CtlParser({start: 'c', end: 'i'})
    writer = SkoolWriter(snapshot, ctl_parser, options, config)
    writer.write_skool(config['ListRefs'], config['Text'])