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)
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)
def main(args): config = get_config('skool2ctl') parser = argparse.ArgumentParser( usage='skool2ctl.py [options] FILE', description="Convert a skool file into a control file and write it to standard output. FILE\n" "may be 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('-b', '--preserve-base', action='store_const', dest='preserve_base', const=1, default=config['PreserveBase'], help="Preserve the base of decimal and hexadecimal values in\n" "instruction operands and DEFB/DEFM/DEFS/DEFW statements.") group.add_argument('-E', '--end', dest='end', metavar='ADDR', type=integer, default=65536, help="Stop converting at this address.") group.add_argument('-h', '--hex', action='store_const', dest='write_hex', const=2, default=config['Hex'], help='Write addresses in upper case hexadecimal format.') 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('-k', '--keep-lines', action='store_const', dest='keep_lines', const=1, default=config['KeepLines'], help="Preserve line breaks in comments.") group.add_argument('-l', '--hex-lower', action='store_const', dest='write_hex', const=1, default=config['Hex'], help='Write addresses in lower case hexadecimal format.') 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 converting at this address.") group.add_argument('-V', '--version', action='version', version='SkoolKit {}'.format(VERSION), help='Show SkoolKit version number and exit.') elements = (ASM_DIRECTIVES, BLOCKS, BLOCK_TITLES, BLOCK_DESC, REGISTERS, BLOCK_COMMENTS, SUBBLOCKS, COMMENTS, NON_ENTRY_BLOCKS) group.add_argument('-w', '--write', dest='elements', metavar='X', default="".join(elements), help="Write only these elements, where X is one or more of:\n" " {} = ASM directives\n" " {} = block types and addresses\n" " {} = block titles\n" " {} = block descriptions\n" " {} = registers\n" " {} = mid-block comments and block start/end comments\n" " {} = sub-block types and addresses\n" " {} = instruction-level comments\n" " {} = non-entry blocks\n".format(*elements)) namespace, unknown_args = parser.parse_known_args(args) if namespace.show_config: show_config('skool2ctl', config) if unknown_args or namespace.skoolfile is None: parser.exit(2, parser.format_help()) update_options('skool2ctl', namespace, namespace.params, config) run(namespace.skoolfile, namespace)
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='ctls', metavar='PATH', action='append', default=[], help="Specify a control file to use, or a directory from which to read control files. " "PATH may be '-' for standard input, or '0' to use no control file. " "This option may be used multiple times.") group.add_argument('-e', '--end', dest='end', metavar='ADDR', type=integer, default=65536, help='Stop disassembling at this address (default=65536).') 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, help='Start disassembling at this address.') 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) if unknown_args or namespace.snafile is None: parser.exit(2, parser.format_help()) update_options('sna2skool', namespace, namespace.params, config) run(namespace.snafile, namespace, config)
def main(args): config = get_config('sna2ctl') parser = argparse.ArgumentParser( usage='sna2ctl.py [options] FILE', description="Generate a control file for a binary (raw memory) file or a SNA, SZX or Z80 snapshot. " "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('-e', '--end', dest='end', metavar='ADDR', type=integer, default=END, help='Stop at this address (default={}).'.format(END)) group.add_argument('-h', '--hex', dest='ctl_hex', action='store_const', const=2, default=config['Hex'], help='Write upper case hexadecimal addresses.') 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', '--hex-lower', dest='ctl_hex', action='store_const', const=1, default=config['Hex'], help='Write lower case hexadecimal addresses.') group.add_argument('-m', '--map', dest='code_map', metavar='FILE', help='Use FILE as a code execution map.') group.add_argument('-o', '--org', dest='org', metavar='ADDR', type=integer, help='Specify the origin address of a binary 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 at this address (default=16384).') 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) if namespace.show_config: show_config('sna2ctl', config) if unknown_args or namespace.snafile is None: parser.exit(2, parser.format_help()) update_options('sna2ctl', namespace, namespace.params, config) run(namespace.snafile, namespace, config)
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))
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)
def main(args): config = get_config('snapinfo') parser = argparse.ArgumentParser( usage='snapinfo.py [options] file', description= "Analyse a binary (raw memory) file or a 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( '-c', '--ctl', dest='ctlfiles', metavar='PATH', action='append', default=[], help= "When generating a call graph, specify a control file to use, or a directory from which to read control files. " "PATH may be '-' for standard input. This option may be used multiple times." ) 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('-g', '--call-graph', action='store_true', help='Generate a call graph in DOT format.') 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( '-o', '--org', dest='org', metavar='ADDR', type=integer, help= 'Specify the origin address of a binary (raw memory) file (default: 65536 - length).' ) 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( '-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('-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 namespace.show_config: show_config('snapinfo', config) if unknown_args or namespace.infile is None: parser.exit(2, parser.format_help()) update_options('snapinfo', namespace, namespace.params, config) run(namespace.infile, namespace, config)
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)
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))
def main(args): config = get_config('skool2ctl') parser = argparse.ArgumentParser( usage='skool2ctl.py [options] FILE', description= "Convert a skool file into a control file and write it to standard output. FILE\n" "may be 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( '-b', '--preserve-base', action='store_const', dest='preserve_base', const=1, default=config['PreserveBase'], help="Preserve the base of decimal and hexadecimal values in\n" "instruction operands and DEFB/DEFM/DEFS/DEFW statements.") group.add_argument('-E', '--end', dest='end', metavar='ADDR', type=integer, default=65536, help="Stop converting at this address.") group.add_argument( '-h', '--hex', action='store_const', dest='write_hex', const=2, default=config['Hex'], help='Write addresses in upper case hexadecimal format.') 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('-k', '--keep-lines', action='store_const', dest='keep_lines', const=1, default=config['KeepLines'], help="Preserve line breaks in comments.") group.add_argument( '-l', '--hex-lower', action='store_const', dest='write_hex', const=1, default=config['Hex'], help='Write addresses in lower case hexadecimal format.') 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 converting at this address.") group.add_argument('-V', '--version', action='version', version='SkoolKit {}'.format(VERSION), help='Show SkoolKit version number and exit.') elements = (ASM_DIRECTIVES, BLOCKS, BLOCK_TITLES, BLOCK_DESC, REGISTERS, BLOCK_COMMENTS, SUBBLOCKS, COMMENTS, NON_ENTRY_BLOCKS) group.add_argument( '-w', '--write', dest='elements', metavar='X', default="".join(elements), help="Write only these elements, where X is one or more of:\n" " {} = ASM directives\n" " {} = block types and addresses\n" " {} = block titles\n" " {} = block descriptions\n" " {} = registers\n" " {} = mid-block comments and block start/end comments\n" " {} = sub-block types and addresses\n" " {} = instruction-level comments\n" " {} = non-entry blocks\n".format(*elements)) namespace, unknown_args = parser.parse_known_args(args) if namespace.show_config: show_config('skool2ctl', config) if unknown_args or namespace.skoolfile is None: parser.exit(2, parser.format_help()) update_options('skool2ctl', namespace, namespace.params, config) run(namespace.skoolfile, namespace)