Example #1
0
def main(args):
    parser = argparse.ArgumentParser(
        usage='skool2asm.py [options] FILE',
        description="Convert a skool file into an ASM file and write it to standard output. "
                    "FILE may\nbe a regular file, or '-' for standard input.",
        formatter_class=argparse.RawTextHelpFormatter,
        add_help=False
    )
    parser.add_argument('skoolfile', help=argparse.SUPPRESS, nargs='?')
    group = parser.add_argument_group('Options')
    group.add_argument('-c', '--create-labels', dest='create_labels', action='store_true',
                       help="Create default labels for unlabelled instructions")
    group.add_argument('-D', '--decimal', dest='base', action='store_const', const=BASE_10,
                       help="Write the disassembly in decimal")
    group.add_argument('-E', '--end', dest='end', metavar='ADDR', type=int, default=65536,
                       help="Stop converting at this address")
    group.add_argument('-f', '--fixes', dest='fix_mode', metavar='N', type=int, choices=range(4), default=0,
                       help="Apply fixes:\n"
                            "  N=0: None (default)\n"
                            "  N=1: @ofix only\n"
                            "  N=2: @ofix and @bfix\n"
                            "  N=3: @ofix, @bfix and @rfix (implies -r)")
    group.add_argument('-H', '--hex', dest='base', action='store_const', const=BASE_16,
                       help="Write the disassembly in hexadecimal")
    group.add_argument('-l', '--lower', dest='case', action='store_const', const=CASE_LOWER,
                       help="Write the disassembly in lower case")
    group.add_argument('-p', '--package-dir', dest='package_dir', action='store_true',
                       help="Show path to skoolkit package directory and exit")
    group.add_argument('-P', '--set', dest='properties', metavar='p=v', action='append', default=[],
                       help="Set the value of ASM writer property 'p' to 'v'; this\noption may be used multiple times")
    group.add_argument('-q', '--quiet', dest='quiet', action='store_true',
                       help="Be quiet")
    group.add_argument('-r', '--rsub', dest='asm_mode', action='store_const', const=3, default=1,
                       help="Apply safe substitutions (@ssub) and relocatability\nsubstitutions (@rsub) (implies '-f 1')")
    group.add_argument('-s', '--ssub', dest='asm_mode', action='store_const', const=2, default=1,
                       help="Apply safe substitutions (@ssub)")
    group.add_argument('-S', '--start', dest='start', metavar='ADDR', type=int, default=0,
                       help="Start converting at this address")
    group.add_argument('-u', '--upper', dest='case', action='store_const', const=CASE_UPPER,
                       help="Write the disassembly in upper case")
    group.add_argument('-V', '--version', action='version', version='SkoolKit {}'.format(VERSION),
                       help='Show SkoolKit version number and exit')
    group.add_argument('-w', '--no-warnings', dest='warn', action='store_false',
                       help="Suppress warnings")
    group.add_argument('-W', '--writer', dest='writer', metavar='CLASS',
                       help="Specify the ASM writer class to use")

    namespace, unknown_args = parser.parse_known_args(args)
    if namespace.package_dir:
        show_package_dir()
    if unknown_args or namespace.skoolfile is None:
        parser.exit(2, parser.format_help())
    run(namespace.skoolfile, namespace)
Example #2
0
def main(args):
    global verbose, show_timings

    config = get_config('skool2html')

    parser = argparse.ArgumentParser(
        usage='skool2html.py [options] FILE [FILE...]',
        description=
        "Convert skool files and ref files to HTML. FILE may be a regular file, or '-'\n"
        "for standard input.",
        formatter_class=argparse.RawTextHelpFormatter,
        add_help=False)
    parser.add_argument('infiles', help=argparse.SUPPRESS, nargs='*')
    group = parser.add_argument_group('Options')
    group.add_argument(
        '-1',
        '--asm-one-page',
        dest='asm_one_page',
        action='store_const',
        const=1,
        default=config['AsmOnePage'],
        help="Write all routines and data blocks to a single page")
    group.add_argument('-a',
                       '--asm-labels',
                       dest='asm_labels',
                       action='store_const',
                       const=1,
                       default=config['AsmLabels'],
                       help="Use ASM labels")
    group.add_argument(
        '-c',
        '--config',
        dest='config_specs',
        metavar='S/L',
        action='append',
        default=[],
        help="Add the line 'L' to the ref file section 'S'; this\n"
        "option may be used multiple times")
    group.add_argument(
        '-C',
        '--create-labels',
        dest='create_labels',
        action='store_const',
        const=1,
        default=config['CreateLabels'],
        help="Create default labels for unlabelled instructions")
    group.add_argument('-d',
                       '--output-dir',
                       dest='output_dir',
                       metavar='DIR',
                       default=config['OutputDir'],
                       help="Write files in this directory (default is '.')")
    group.add_argument('-D',
                       '--decimal',
                       dest='base',
                       action='store_const',
                       const=BASE_10,
                       default=config['Base'],
                       help="Write the disassembly in decimal")
    group.add_argument('-H',
                       '--hex',
                       dest='base',
                       action='store_const',
                       const=BASE_16,
                       default=config['Base'],
                       help="Write the disassembly in hexadecimal")
    group.add_argument(
        '-I',
        '--ini',
        dest='params',
        metavar='p=v',
        action='append',
        default=[],
        help=
        "Set the value of the configuration parameter 'p' to\n'v'; this option may be used multiple times"
    )
    group.add_argument(
        '-j',
        '--join-css',
        dest='single_css',
        metavar='NAME',
        default=config['JoinCss'],
        help="Concatenate CSS files into a single file with this name")
    group.add_argument('-l',
                       '--lower',
                       dest='case',
                       action='store_const',
                       const=CASE_LOWER,
                       default=config['Case'],
                       help="Write the disassembly in lower case")
    group.add_argument('-o',
                       '--rebuild-images',
                       dest='new_images',
                       action='store_const',
                       const=1,
                       default=config['RebuildImages'],
                       help="Overwrite existing image files")
    group.add_argument('-p',
                       '--package-dir',
                       dest='package_dir',
                       action='store_true',
                       help="Show path to skoolkit package directory and exit")
    group.add_argument(
        '-P',
        '--pages',
        dest='pages',
        metavar='PAGES',
        help="Write only these pages (when using '--write P');\n"
        "PAGES is a comma-separated list of page IDs")
    group.add_argument('-q',
                       '--quiet',
                       dest='quiet',
                       action='store_const',
                       const=1,
                       default=config['Quiet'],
                       help="Be quiet")
    group.add_argument(
        '-r',
        '--ref-sections',
        dest='ref_sections',
        metavar='PREFIX',
        help="Show default ref file sections whose names start with\n"
        "PREFIX and exit")
    group.add_argument('-R',
                       '--ref-file',
                       dest='ref_file',
                       action='store_true',
                       help="Show the entire default ref file and exit")
    group.add_argument(
        '-s',
        '--search-dirs',
        dest='search_dirs',
        action='store_true',
        help="Show the locations skool2html.py searches for resources")
    group.add_argument(
        '-S',
        '--search',
        dest='search',
        metavar='DIR',
        action='append',
        default=config['Search'],
        help="Add this directory to the resource search path; this\n"
        "option may be used multiple times")
    group.add_argument('-t',
                       '--time',
                       dest='show_timings',
                       action='store_const',
                       const=1,
                       default=config['Time'],
                       help="Show timings")
    group.add_argument(
        '-T',
        '--theme',
        dest='themes',
        metavar='THEME',
        action='append',
        default=config['Theme'],
        help="Use this CSS theme; this option may be used multiple\ntimes")
    group.add_argument('-u',
                       '--upper',
                       dest='case',
                       action='store_const',
                       const=CASE_UPPER,
                       default=config['Case'],
                       help="Write the disassembly in upper case")
    group.add_argument('-V',
                       '--version',
                       action='version',
                       version='SkoolKit {}'.format(VERSION),
                       help='Show SkoolKit version number and exit')
    group.add_argument(
        '-w',
        '--write',
        dest='files',
        metavar='X',
        default='dimoP',
        help="Write only these files, where X is one or more of:\n"
        "  d = Disassembly files   o = Other code\n"
        "  i = Disassembly index   P = Other pages\n"
        "  m = Memory maps\n")
    group.add_argument(
        '-W',
        '--writer',
        dest='writer',
        metavar='CLASS',
        help="Specify the HTML writer class to use; shorthand for\n"
        "'--config Config/HtmlWriterClass=CLASS'")

    start = time.time()
    namespace, unknown_args = parser.parse_known_args(args)
    if namespace.package_dir:
        show_package_dir()
    if namespace.search_dirs:
        show_search_dirs()
    if namespace.ref_file:
        show_ref_file()
    if namespace.ref_sections is not None:
        show_ref_sections(namespace.ref_sections)
    if unknown_args or not namespace.infiles:
        parser.exit(2, parser.format_help())
    update_options('skool2html', namespace, namespace.params)
    verbose, show_timings = not namespace.quiet, namespace.show_timings
    if namespace.asm_one_page:
        namespace.config_specs.append('Game/AsmSinglePageTemplate=AsmAllInOne')
    if namespace.writer:
        namespace.config_specs.append('Config/HtmlWriterClass={}'.format(
            namespace.writer))
    if namespace.pages:
        namespace.pages = namespace.pages.split(',')
    else:
        namespace.pages = []
    run(namespace.infiles, namespace)
    if show_timings:
        notify('Done ({0:0.2f}s)'.format(time.time() - start))
Example #3
0
def main(args):
    config = get_config('skool2asm')
    def_properties = ['{}={}'.format(k[4:], v) for k, v in config.items() if k.startswith('Set-')]

    parser = argparse.ArgumentParser(
        usage='skool2asm.py [options] FILE',
        description="Convert a skool file into an ASM file and write it to standard output. "
                    "FILE may\nbe a regular file, or '-' for standard input.",
        formatter_class=argparse.RawTextHelpFormatter,
        add_help=False
    )
    parser.add_argument('skoolfile', help=argparse.SUPPRESS, nargs='?')
    group = parser.add_argument_group('Options')
    group.add_argument('-c', '--create-labels', dest='create_labels', action='store_const', const=1, default=config['CreateLabels'],
                       help="Create default labels for unlabelled instructions.")
    group.add_argument('-D', '--decimal', dest='base', action='store_const', const=BASE_10, default=config['Base'],
                       help="Write the disassembly in decimal.")
    group.add_argument('-E', '--end', dest='end', metavar='ADDR', type=integer, default=65536,
                       help="Stop converting at this address.")
    group.add_argument('-f', '--fixes', dest='fix_mode', metavar='N', type=int, choices=range(4), default=0,
                       help="Apply fixes:\n"
                            "  N=0: None (default)\n"
                            "  N=1: @ofix only\n"
                            "  N=2: @ofix and @bfix\n"
                            "  N=3: @ofix, @bfix and @rfix (implies -r)")
    group.add_argument('-F', '--force', dest='force', action='store_true',
                       help="Force conversion, ignoring @start and @end directives.")
    group.add_argument('-H', '--hex', dest='base', action='store_const', const=BASE_16, default=config['Base'],
                       help="Write the disassembly in hexadecimal.")
    group.add_argument('-I', '--ini', dest='params', metavar='p=v', action='append', default=[],
                       help="Set the value of the configuration parameter 'p' to\n'v'. This option may be used multiple times.")
    group.add_argument('-l', '--lower', dest='case', action='store_const', const=CASE_LOWER, default=config['Case'],
                       help="Write the disassembly in lower case.")
    group.add_argument('-p', '--package-dir', dest='package_dir', action='store_true',
                       help="Show path to skoolkit package directory and exit.")
    group.add_argument('-P', '--set', dest='properties', metavar='p=v', action='append', default=def_properties,
                       help="Set the value of ASM writer property 'p' to 'v'. This\noption may be used multiple times.")
    group.add_argument('-q', '--quiet', dest='quiet', action='store_const', const=1, default=config['Quiet'],
                       help="Be quiet.")
    group.add_argument('-r', '--rsub', dest='asm_mode', action='store_const', const=3, default=1,
                       help="Apply safe substitutions (@ssub) and relocatability\nsubstitutions (@rsub) (implies '-f 1').")
    group.add_argument('--show-config', dest='show_config', action='store_true',
                       help="Show configuration parameter values.")
    group.add_argument('-s', '--ssub', dest='asm_mode', action='store_const', const=2, default=1,
                       help="Apply safe substitutions (@ssub).")
    group.add_argument('-S', '--start', dest='start', metavar='ADDR', type=integer, default=0,
                       help="Start converting at this address.")
    group.add_argument('-u', '--upper', dest='case', action='store_const', const=CASE_UPPER, default=config['Case'],
                       help="Write the disassembly in upper case.")
    group.add_argument('--var', dest='variables', metavar='name=value', action='append', default=[],
                       help="Define a variable that can be used by @if, #IF and #MAP.\nThis option may be used multiple times.")
    group.add_argument('-V', '--version', action='version', version='SkoolKit {}'.format(VERSION),
                       help='Show SkoolKit version number and exit.')
    group.add_argument('-w', '--no-warnings', dest='warn', action='store_const', const=0, default=config['Warnings'],
                       help="Suppress warnings.")
    group.add_argument('-W', '--writer', dest='writer', metavar='CLASS',
                       help="Specify the ASM writer class to use.")

    namespace, unknown_args = parser.parse_known_args(args)
    if namespace.show_config:
        show_config('skool2asm', config)
    if namespace.package_dir:
        show_package_dir()
    if unknown_args or namespace.skoolfile is None:
        parser.exit(2, parser.format_help())
    update_options('skool2asm', namespace, namespace.params, config)
    namespace.properties += [p[4:] for p in namespace.params if p.startswith('Set-')]
    if namespace.fix_mode == 3:
        namespace.asm_mode = 3
    elif namespace.asm_mode == 3:
        namespace.fix_mode = max(namespace.fix_mode, 1)
    run(namespace.skoolfile, namespace)
Example #4
0
def main(args):
    config = get_config('skool2asm')
    def_properties = [
        '{}={}'.format(k[4:], v) for k, v in config.items()
        if k.startswith('Set-')
    ]

    parser = argparse.ArgumentParser(
        usage='skool2asm.py [options] FILE',
        description=
        "Convert a skool file into an ASM file and write it to standard output. "
        "FILE may\nbe a regular file, or '-' for standard input.",
        formatter_class=argparse.RawTextHelpFormatter,
        add_help=False)
    parser.add_argument('skoolfile', help=argparse.SUPPRESS, nargs='?')
    group = parser.add_argument_group('Options')
    group.add_argument(
        '-c',
        '--create-labels',
        dest='create_labels',
        action='store_const',
        const=1,
        default=config['CreateLabels'],
        help="Create default labels for unlabelled instructions")
    group.add_argument('-D',
                       '--decimal',
                       dest='base',
                       action='store_const',
                       const=BASE_10,
                       default=config['Base'],
                       help="Write the disassembly in decimal")
    group.add_argument('-E',
                       '--end',
                       dest='end',
                       metavar='ADDR',
                       type=int,
                       default=65536,
                       help="Stop converting at this address")
    group.add_argument('-f',
                       '--fixes',
                       dest='fix_mode',
                       metavar='N',
                       type=int,
                       choices=range(4),
                       default=0,
                       help="Apply fixes:\n"
                       "  N=0: None (default)\n"
                       "  N=1: @ofix only\n"
                       "  N=2: @ofix and @bfix\n"
                       "  N=3: @ofix, @bfix and @rfix (implies -r)")
    group.add_argument('-H',
                       '--hex',
                       dest='base',
                       action='store_const',
                       const=BASE_16,
                       default=config['Base'],
                       help="Write the disassembly in hexadecimal")
    group.add_argument(
        '-I',
        '--ini',
        dest='params',
        metavar='p=v',
        action='append',
        default=[],
        help=
        "Set the value of the configuration parameter 'p' to\n'v'; this option may be used multiple times"
    )
    group.add_argument('-l',
                       '--lower',
                       dest='case',
                       action='store_const',
                       const=CASE_LOWER,
                       default=config['Case'],
                       help="Write the disassembly in lower case")
    group.add_argument('-p',
                       '--package-dir',
                       dest='package_dir',
                       action='store_true',
                       help="Show path to skoolkit package directory and exit")
    group.add_argument(
        '-P',
        '--set',
        dest='properties',
        metavar='p=v',
        action='append',
        default=def_properties,
        help=
        "Set the value of ASM writer property 'p' to 'v'; this\noption may be used multiple times"
    )
    group.add_argument('-q',
                       '--quiet',
                       dest='quiet',
                       action='store_const',
                       const=1,
                       default=config['Quiet'],
                       help="Be quiet")
    group.add_argument(
        '-r',
        '--rsub',
        dest='asm_mode',
        action='store_const',
        const=3,
        default=1,
        help=
        "Apply safe substitutions (@ssub) and relocatability\nsubstitutions (@rsub) (implies '-f 1')"
    )
    group.add_argument('-s',
                       '--ssub',
                       dest='asm_mode',
                       action='store_const',
                       const=2,
                       default=1,
                       help="Apply safe substitutions (@ssub)")
    group.add_argument('-S',
                       '--start',
                       dest='start',
                       metavar='ADDR',
                       type=int,
                       default=0,
                       help="Start converting at this address")
    group.add_argument('-u',
                       '--upper',
                       dest='case',
                       action='store_const',
                       const=CASE_UPPER,
                       default=config['Case'],
                       help="Write the disassembly in upper case")
    group.add_argument('-V',
                       '--version',
                       action='version',
                       version='SkoolKit {}'.format(VERSION),
                       help='Show SkoolKit version number and exit')
    group.add_argument('-w',
                       '--no-warnings',
                       dest='warn',
                       action='store_const',
                       const=0,
                       default=config['Warnings'],
                       help="Suppress warnings")
    group.add_argument('-W',
                       '--writer',
                       dest='writer',
                       metavar='CLASS',
                       help="Specify the ASM writer class to use")

    namespace, unknown_args = parser.parse_known_args(args)
    if namespace.package_dir:
        show_package_dir()
    if unknown_args or namespace.skoolfile is None:
        parser.exit(2, parser.format_help())
    update_options('skool2asm', namespace, namespace.params)
    if namespace.fix_mode == 3:
        namespace.asm_mode = 3
    elif namespace.asm_mode == 3:
        namespace.fix_mode = max(namespace.fix_mode, 1)
    run(namespace.skoolfile, namespace)
Example #5
0
def main(args):
    global verbose, show_timings

    parser = argparse.ArgumentParser(
        usage='skool2html.py [options] FILE [FILE...]',
        description="Convert skool files and ref files to HTML. FILE may be a regular file, or '-'\n"
                    "for standard input.",
        formatter_class=argparse.RawTextHelpFormatter,
        add_help=False
    )
    parser.add_argument('infiles', help=argparse.SUPPRESS, nargs='*')
    group = parser.add_argument_group('Options')
    group.add_argument('-a', '--asm-labels', dest='asm_labels', action='store_true',
                       help="Use ASM labels")
    group.add_argument('-c', '--config', dest='config_specs', metavar='S/L', action='append',
                       help="Add the line 'L' to the ref file section 'S'; this\n"
                            "option may be used multiple times")
    group.add_argument('-C', '--create-labels', dest='create_labels', action='store_true',
                       help="Create default labels for unlabelled instructions")
    group.add_argument('-d', '--output-dir', dest='output_dir', metavar='DIR',
                       help="Write files in this directory (default is '.')")
    group.add_argument('-D', '--decimal', dest='base', action='store_const', const=BASE_10,
                       help="Write the disassembly in decimal")
    group.add_argument('-H', '--hex', dest='base', action='store_const', const=BASE_16,
                       help="Write the disassembly in hexadecimal")
    group.add_argument('-j', '--join-css', dest='single_css', metavar='NAME',
                       help="Concatenate CSS files into a single file with this name")
    group.add_argument('-l', '--lower', dest='case', action='store_const', const=CASE_LOWER,
                       help="Write the disassembly in lower case")
    group.add_argument('-o', '--rebuild-images', dest='new_images', action='store_true',
                       help="Overwrite existing image files")
    group.add_argument('-p', '--package-dir', dest='package_dir', action='store_true',
                       help="Show path to skoolkit package directory and exit")
    group.add_argument('-P', '--pages', dest='pages', metavar='PAGES',
                       help="Write only these custom pages (when using '--write P');\n"
                            "PAGES is a comma-separated list of page IDs")
    group.add_argument('-q', '--quiet', dest='verbose', action='store_false',
                       help="Be quiet")
    group.add_argument('-r', '--ref-sections', dest='ref_sections', metavar='PREFIX',
                       help="Show default ref file sections whose names start with\n"
                            "PREFIX and exit")
    group.add_argument('-R', '--ref-file', dest='ref_file', action='store_true',
                       help="Show the entire default ref file and exit")
    group.add_argument('-s', '--search-dirs', dest='search_dirs', action='store_true',
                       help="Show the locations skool2html.py searches for resources")
    group.add_argument('-S', '--search', dest='search', metavar='DIR', action='append',
                       help="Add this directory to the resource search path; this\n"
                            "option may be used multiple times")
    group.add_argument('-t', '--time', dest='show_timings', action='store_true',
                       help="Show timings")
    group.add_argument('-T', '--theme', dest='themes', metavar='THEME', action='append', default=[],
                       help="Use this CSS theme; this option may be used multiple\ntimes")
    group.add_argument('-u', '--upper', dest='case', action='store_const', const=CASE_UPPER,
                       help="Write the disassembly in upper case")
    group.add_argument('-V', '--version', action='version',
                       version='SkoolKit {}'.format(VERSION),
                       help='Show SkoolKit version number and exit')
    group.add_argument('-w', '--write', dest='files', metavar='X', default='BbcdGgimoPpty',
                       help="Write only these files, where X is one or more of:\n"
                            "  B = Graphic glitches    o = Other code\n"
                            "  b = Bugs                P = Custom pages\n"
                            "  c = Changelog           p = Pokes\n"
                            "  d = Disassembly files   t = Trivia\n"
                            "  i = Disassembly index   y = Glossary\n"
                            "  m = Memory maps\n")
    group.add_argument('-W', '--writer', dest='writer', metavar='CLASS',
                       help="Specify the HTML writer class to use; shorthand for\n"
                            "'--config Config/HtmlWriterClass=CLASS'")

    start = time.time()
    namespace, unknown_args = parser.parse_known_args(args)
    if namespace.package_dir:
        show_package_dir()
    if namespace.search_dirs:
        show_search_dirs()
    if namespace.ref_file:
        show_ref_file()
    if namespace.ref_sections is not None:
        show_ref_sections(namespace.ref_sections)
    if unknown_args or not namespace.infiles:
        parser.exit(2, parser.format_help())
    verbose, show_timings = namespace.verbose, namespace.show_timings
    namespace.config_specs = namespace.config_specs or []
    if namespace.writer:
        namespace.config_specs.append('Config/HtmlWriterClass={}'.format(namespace.writer))
    if namespace.pages:
        namespace.pages = namespace.pages.split(',')
    else:
        namespace.pages = []
    run(namespace.infiles, namespace)
    if show_timings:
        notify('Done ({0:0.2f}s)'.format(time.time() - start))
Example #6
0
def main(args):
    global verbose, show_timings

    config = get_config('skool2html')

    parser = argparse.ArgumentParser(
        usage='skool2html.py [options] SKOOLFILE [REFFILE...]',
        description="Convert a skool file and ref files to HTML. SKOOLFILE may be a regular file, or\n"
                    "'-' for standard input.",
        formatter_class=argparse.RawTextHelpFormatter,
        add_help=False
    )
    parser.add_argument('infiles', help=argparse.SUPPRESS, nargs='*')
    group = parser.add_argument_group('Options')
    group.add_argument('-1', '--asm-one-page', dest='asm_one_page', action='store_const', const=1, default=config['AsmOnePage'],
                       help="Write all routines and data blocks to a single page.")
    group.add_argument('-a', '--asm-labels', dest='asm_labels', action='store_const', const=1, default=config['AsmLabels'],
                       help="Use ASM labels.")
    group.add_argument('-c', '--config', dest='config_specs', metavar='S/L', action='append', default=[],
                       help="Add the line 'L' to the ref file section 'S'. This\n"
                            "option may be used multiple times.")
    group.add_argument('-C', '--create-labels', dest='create_labels', action='store_const', const=1, default=config['CreateLabels'],
                       help="Create default labels for unlabelled instructions.")
    group.add_argument('-d', '--output-dir', dest='output_dir', metavar='DIR', default=config['OutputDir'],
                       help="Write files in this directory (default is '.').")
    group.add_argument('-D', '--decimal', dest='base', action='store_const', const=BASE_10, default=config['Base'],
                       help="Write the disassembly in decimal.")
    group.add_argument('-H', '--hex', dest='base', action='store_const', const=BASE_16, default=config['Base'],
                       help="Write the disassembly in hexadecimal.")
    group.add_argument('-I', '--ini', dest='params', metavar='p=v', action='append', default=[],
                       help="Set the value of the configuration parameter 'p' to\n'v'. This option may be used multiple times.")
    group.add_argument('-j', '--join-css', dest='single_css', metavar='NAME', default=config['JoinCss'],
                       help="Concatenate CSS files into a single file with this name.")
    group.add_argument('-l', '--lower', dest='case', action='store_const', const=CASE_LOWER, default=config['Case'],
                       help="Write the disassembly in lower case.")
    group.add_argument('-o', '--rebuild-images', dest='new_images', action='store_const', const=1, default=config['RebuildImages'],
                       help="Overwrite existing image files.")
    group.add_argument('-p', '--package-dir', dest='package_dir', action='store_true',
                       help="Show path to skoolkit package directory and exit.")
    group.add_argument('-P', '--pages', dest='pages', metavar='PAGES',
                       help="Write only these pages (when using '--write P').\n"
                            "PAGES is a comma-separated list of page IDs.")
    group.add_argument('-q', '--quiet', dest='quiet', action='store_const', const=1, default=config['Quiet'],
                       help="Be quiet.")
    group.add_argument('-r', '--ref-sections', dest='ref_sections', metavar='PREFIX',
                       help="Show default ref file sections whose names start with\n"
                            "PREFIX and exit.")
    group.add_argument('-R', '--ref-file', dest='ref_file', action='store_true',
                       help="Show the entire default ref file and exit.")
    group.add_argument('-s', '--search-dirs', dest='search_dirs', action='store_true',
                       help="Show the locations skool2html.py searches for resources.")
    group.add_argument('-S', '--search', dest='search', metavar='DIR', action='append', default=config['Search'],
                       help="Add this directory to the resource search path. This\n"
                            "option may be used multiple times.")
    group.add_argument('--show-config', dest='show_config', action='store_true',
                       help="Show configuration parameter values.")
    group.add_argument('-t', '--time', dest='show_timings', action='store_const', const=1, default=config['Time'],
                       help="Show timings.")
    group.add_argument('-T', '--theme', dest='themes', metavar='THEME', action='append', default=config['Theme'],
                       help="Use this CSS theme. This option may be used multiple\ntimes.")
    group.add_argument('-u', '--upper', dest='case', action='store_const', const=CASE_UPPER, default=config['Case'],
                       help="Write the disassembly in upper case.")
    group.add_argument('--var', dest='variables', metavar='name=value', action='append', default=[],
                       help="Define a variable that can be used by @if, #IF and #MAP.\nThis option may be used multiple times.")
    group.add_argument('-V', '--version', action='version',
                       version='SkoolKit {}'.format(VERSION),
                       help='Show SkoolKit version number and exit.')
    group.add_argument('-w', '--write', dest='files', metavar='X', default='dimoP',
                       help="Write only these files, where X is one or more of:\n"
                            "  d = Disassembly files   o = Other code\n"
                            "  i = Disassembly index   P = Other pages\n"
                            "  m = Memory maps\n")
    group.add_argument('-W', '--writer', dest='writer', metavar='CLASS',
                       help="Specify the HTML writer class to use; shorthand for\n"
                            "'--config Config/HtmlWriterClass=CLASS'.")

    start = time.time()
    namespace, unknown_args = parser.parse_known_args(args)
    if namespace.show_config:
        show_config('skool2html', config)
    if namespace.package_dir:
        show_package_dir()
    if namespace.search_dirs:
        show_search_dirs()
    if namespace.ref_file:
        show_ref_file()
    if namespace.ref_sections is not None:
        show_ref_sections(namespace.ref_sections)
    if unknown_args or not namespace.infiles:
        parser.exit(2, parser.format_help())
    update_options('skool2html', namespace, namespace.params)
    verbose, show_timings = not namespace.quiet, namespace.show_timings
    if namespace.asm_one_page:
        namespace.config_specs.append('Game/AsmSinglePageTemplate=AsmAllInOne')
    if namespace.writer:
        namespace.config_specs.append('Config/HtmlWriterClass={}'.format(namespace.writer))
    if namespace.pages:
        namespace.pages = namespace.pages.split(',')
    else:
        namespace.pages = []
    run(namespace.infiles, namespace)
    if show_timings:
        notify('Done ({0:0.2f}s)'.format(time.time() - start))
Example #7
0
def main(args):
    parser = argparse.ArgumentParser(
        usage="skool2asm.py [options] FILE",
        description="Convert a skool file into an ASM file and write it to standard output. "
        "FILE may\nbe a regular file, or '-' for standard input.",
        formatter_class=argparse.RawTextHelpFormatter,
        add_help=False,
    )
    parser.add_argument("skoolfile", help=argparse.SUPPRESS, nargs="?")
    group = parser.add_argument_group("Options")
    group.add_argument(
        "-c",
        "--create-labels",
        dest="create_labels",
        action="store_true",
        help="Create default labels for unlabelled instructions",
    )
    group.add_argument(
        "-D", "--decimal", dest="base", action="store_const", const=BASE_10, help="Write the disassembly in decimal"
    )
    group.add_argument(
        "-E", "--end", dest="end", metavar="ADDR", type=int, default=65536, help="Stop converting at this address"
    )
    group.add_argument(
        "-f",
        "--fixes",
        dest="fix_mode",
        metavar="N",
        type=int,
        choices=range(4),
        default=0,
        help="Apply fixes:\n"
        "  N=0: None (default)\n"
        "  N=1: @ofix only\n"
        "  N=2: @ofix and @bfix\n"
        "  N=3: @ofix, @bfix and @rfix (implies -r)",
    )
    group.add_argument(
        "-H", "--hex", dest="base", action="store_const", const=BASE_16, help="Write the disassembly in hexadecimal"
    )
    group.add_argument(
        "-l", "--lower", dest="case", action="store_const", const=CASE_LOWER, help="Write the disassembly in lower case"
    )
    group.add_argument(
        "-p",
        "--package-dir",
        dest="package_dir",
        action="store_true",
        help="Show path to skoolkit package directory and exit",
    )
    group.add_argument(
        "-P",
        "--set",
        dest="properties",
        metavar="p=v",
        action="append",
        default=[],
        help="Set the value of ASM writer property 'p' to 'v'; this\noption may be used multiple times",
    )
    group.add_argument("-q", "--quiet", dest="quiet", action="store_true", help="Be quiet")
    group.add_argument(
        "-r",
        "--rsub",
        dest="asm_mode",
        action="store_const",
        const=3,
        default=1,
        help="Apply safe substitutions (@ssub) and relocatability\nsubstitutions (@rsub) (implies '-f 1')",
    )
    group.add_argument(
        "-s",
        "--ssub",
        dest="asm_mode",
        action="store_const",
        const=2,
        default=1,
        help="Apply safe substitutions (@ssub)",
    )
    group.add_argument(
        "-S", "--start", dest="start", metavar="ADDR", type=int, default=0, help="Start converting at this address"
    )
    group.add_argument(
        "-u", "--upper", dest="case", action="store_const", const=CASE_UPPER, help="Write the disassembly in upper case"
    )
    group.add_argument(
        "-V",
        "--version",
        action="version",
        version="SkoolKit {}".format(VERSION),
        help="Show SkoolKit version number and exit",
    )
    group.add_argument("-w", "--no-warnings", dest="warn", action="store_false", help="Suppress warnings")
    group.add_argument("-W", "--writer", dest="writer", metavar="CLASS", help="Specify the ASM writer class to use")

    namespace, unknown_args = parser.parse_known_args(args)
    if namespace.package_dir:
        show_package_dir()
    if unknown_args or namespace.skoolfile is None:
        parser.exit(2, parser.format_help())
    run(namespace.skoolfile, namespace)