Ejemplo n.º 1
0
def main(args):
    config = get_config('sna2skool')
    parser = argparse.ArgumentParser(
        usage='sna2skool.py [options] FILE',
        description="Convert a binary (raw memory) file or a SNA, SZX or Z80 snapshot into a skool file. "
                    "FILE may be a regular file, or '-' for standard input.",
        add_help=False
    )
    parser.add_argument('snafile', help=argparse.SUPPRESS, nargs='?')
    group = parser.add_argument_group('Options')
    group.add_argument('-c', '--ctl', dest='ctlfile', metavar='FILE',
                       help="Use FILE as the control file (may be '-' for standard input).")
    group.add_argument('-e', '--end', dest='end', metavar='ADDR', type=integer, default=END,
                       help='Stop disassembling at this address (default={}).'.format(END))
    group.add_argument('-g', '--generate-ctl', dest='genctlfile', metavar='FILE',
                       help='Generate a control file in FILE.')
    group.add_argument('-h', '--ctl-hex', dest='ctl_hex', action='store_const', const=2, default=config['CtlHex'],
                       help='Write upper case hexadecimal addresses in the generated control file.')
    group.add_argument('-H', '--skool-hex', dest='base', action='store_const', const=16, default=config['Base'],
                       help='Write hexadecimal addresses and operands in the disassembly.')
    group.add_argument('-I', '--ini', dest='params', metavar='p=v', action='append', default=[],
                       help="Set the value of the configuration parameter 'p' to 'v'. This option may be used multiple times.")
    group.add_argument('-L', '--lower', dest='case', action='store_const', const=1, default=config['Case'],
                       help='Write the disassembly in lower case.')
    group.add_argument('-M', '--map', dest='code_map', metavar='FILE',
                       help='Use FILE as a code execution map when generating a control file.')
    group.add_argument('-o', '--org', dest='org', metavar='ADDR', type=integer,
                       help='Specify the origin address of a binary (.bin) file (default: 65536 - length).')
    group.add_argument('-p', '--page', dest='page', metavar='PAGE', type=int, choices=list(range(8)),
                       help='Specify the page (0-7) of a 128K snapshot to map to 49152-65535.')
    group.add_argument('--show-config', dest='show_config', action='store_true',
                       help="Show configuration parameter values.")
    group.add_argument('-s', '--start', dest='start', metavar='ADDR', type=integer, default=0,
                       help='Start disassembling at this address (default={}).'.format(START))
    group.add_argument('-T', '--sft', dest='sftfile', metavar='FILE',
                       help="Use FILE as the skool file template (may be '-' for standard input).")
    group.add_argument('-V', '--version', action='version', version='SkoolKit {}'.format(VERSION),
                       help='Show SkoolKit version number and exit.')
    group.add_argument('-w', '--line-width', dest='line_width', metavar='W', type=int, default=config['LineWidth'],
                       help='Set the maximum line width of the skool file (default: {}).'.format(config['LineWidth']))

    namespace, unknown_args = parser.parse_known_args(args)
    if namespace.show_config:
        show_config(config)
    snafile = namespace.snafile
    if unknown_args or snafile is None:
        parser.exit(2, parser.format_help())
    if snafile[-4:].lower() in ('.bin', '.sna', '.szx', '.z80'):
        prefix = snafile[:-4]
    else:
        prefix = snafile
    if not (namespace.ctlfile or namespace.sftfile):
        namespace.sftfile = find_file(prefix + '.sft')
    if not (namespace.ctlfile or namespace.sftfile):
        namespace.ctlfile = find_file(prefix + '.ctl')
    update_options('sna2skool', namespace, namespace.params, config)
    run(snafile, namespace, config)
Ejemplo n.º 2
0
def get_config(name):
    config = {}
    for k, v in COMMANDS.get(name, {}).items():
        if isinstance(v, tuple):
            if isinstance(v[0], tuple):
                config[k] = []
            else:
                config[k] = v[0]
        else:
            config[k] = v
    skoolkit_ini = find_file('skoolkit.ini', ('', expanduser('~/.skoolkit')))
    if skoolkit_ini:
        ref_parser = RefParser()
        ref_parser.parse(skoolkit_ini)
        for k, v in ref_parser.get_dictionary(name).items():
            if isinstance(config.get(k), int):
                try:
                    config[k] = int(v)
                except ValueError:
                    pass
            elif isinstance(config.get(k), list):
                config[k] = [s for s in v.split(',') if s]
            else:
                config[k] = v
    return config
Ejemplo n.º 3
0
def find(fname, extra_search_dirs, first_search_dir=None):
    if first_search_dir:
        search_dirs = [first_search_dir]
    else:
        search_dirs = []
    search_dirs.extend(SEARCH_DIRS)
    search_dirs.extend(extra_search_dirs)
    return find_file(fname, search_dirs)
Ejemplo n.º 4
0
def main(args):
    config = get_config('sna2skool')
    parser = argparse.ArgumentParser(
        usage='sna2skool.py [options] FILE',
        description="Convert a binary (raw memory) file or a SNA, SZX or Z80 snapshot into a skool file. "
                    "FILE may be a regular file, or '-' for standard input.",
        add_help=False
    )
    parser.add_argument('snafile', help=argparse.SUPPRESS, nargs='?')
    group = parser.add_argument_group('Options')
    group.add_argument('-c', '--ctl', dest='ctlfiles', metavar='FILE', action='append', default=[],
                       help="Use FILE as a control file (may be '-' for standard input). This option may be used multiple times.")
    group.add_argument('-e', '--end', dest='end', metavar='ADDR', type=integer, default=END,
                       help='Stop disassembling at this address (default={}).'.format(END))
    group.add_argument('-H', '--hex', dest='base', action='store_const', const=16, default=config['Base'],
                       help='Write hexadecimal addresses and operands in the disassembly.')
    group.add_argument('-I', '--ini', dest='params', metavar='p=v', action='append', default=[],
                       help="Set the value of the configuration parameter 'p' to 'v'. This option may be used multiple times.")
    group.add_argument('-l', '--lower', dest='case', action='store_const', const=1, default=config['Case'],
                       help='Write the disassembly in lower case.')
    group.add_argument('-o', '--org', dest='org', metavar='ADDR', type=integer,
                       help='Specify the origin address of a binary (.bin) file (default: 65536 - length).')
    group.add_argument('-p', '--page', dest='page', metavar='PAGE', type=int, choices=list(range(8)),
                       help='Specify the page (0-7) of a 128K snapshot to map to 49152-65535.')
    group.add_argument('--show-config', dest='show_config', action='store_true',
                       help="Show configuration parameter values.")
    group.add_argument('-s', '--start', dest='start', metavar='ADDR', type=integer, default=0,
                       help='Start disassembling at this address (default=16384).')
    group.add_argument('-T', '--sft', dest='sftfile', metavar='FILE',
                       help="Use FILE as the skool file template (may be '-' for standard input).")
    group.add_argument('-V', '--version', action='version', version='SkoolKit {}'.format(VERSION),
                       help='Show SkoolKit version number and exit.')
    group.add_argument('-w', '--line-width', dest='line_width', metavar='W', type=int, default=config['LineWidth'],
                       help='Set the maximum line width of the skool file (default: {}).'.format(config['LineWidth']))

    namespace, unknown_args = parser.parse_known_args(args)
    if namespace.show_config:
        show_config('sna2skool', config)
    snafile = namespace.snafile
    if unknown_args or snafile is None:
        parser.exit(2, parser.format_help())
    if snafile[-4:].lower() in ('.bin', '.sna', '.szx', '.z80'):
        prefix = snafile[:-4]
    else:
        prefix = snafile
    if not (namespace.ctlfiles or namespace.sftfile):
        namespace.sftfile = find_file(prefix + '.sft')
    if not (namespace.ctlfiles or namespace.sftfile):
        namespace.ctlfiles.extend(sorted(glob.glob(prefix + '*.ctl')))
    update_options('sna2skool', namespace, namespace.params, config)
    run(snafile, namespace, config)
Ejemplo n.º 5
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.º 6
0
def get_config(name):
    config = {}
    for k, v in COMMANDS.get(name, {}).items():
        if isinstance(v[0], tuple):
            config[k] = []
        else:
            config[k] = v[0]
    skoolkit_ini = find_file('skoolkit.ini', ('', expanduser('~/.skoolkit')))
    if skoolkit_ini:
        ref_parser = RefParser()
        ref_parser.parse(skoolkit_ini)
        for k, v in ref_parser.get_dictionary(name).items():
            if isinstance(config.get(k), int):
                try:
                    config[k] = int(v)
                except ValueError:
                    pass
            elif isinstance(config.get(k), list):
                config[k] = [s for s in v.split(',') if s]
            else:
                config[k] = v
    return config
Ejemplo n.º 7
0
def find(fname, extra_search_dirs, first_search_dir=None):
    return find_file(fname, _get_search_dirs(extra_search_dirs, first_search_dir))
Ejemplo n.º 8
0
def find(fname, extra_search_dirs, first_search_dir=None):
    return find_file(fname, _get_search_dirs(extra_search_dirs, first_search_dir))