def main(args): parser = SkoolKitArgumentParser( usage='\n tap2sna.py [options] INPUT snapshot.z80\n tap2sna.py @FILE', description="Convert a TAP or TZX file (which may be inside a zip archive) into a Z80 snapshot. " "INPUT may be the full URL to a remote zip archive or TAP/TZX file, or the path to a local file. " "Arguments may be read from FILE instead of (or as well as) being given on the command line.", fromfile_prefix_chars='@', add_help=False ) parser.add_argument('args', help=argparse.SUPPRESS, nargs='*') group = parser.add_argument_group('Options') group.add_argument('-d', '--output-dir', dest='output_dir', metavar='DIR', help="Write the snapshot file in this directory.") group.add_argument('-f', '--force', action='store_true', help="Overwrite an existing snapshot.") group.add_argument('-p', '--stack', dest='stack', metavar='STACK', type=integer, help="Set the stack pointer.") group.add_argument('--ram', dest='ram_ops', metavar='OPERATION', action='append', default=[], help="Perform a load, move or poke operation on the memory snapshot being built. " "Do '--ram help' for more information. This option may be used multiple times.") group.add_argument('--reg', dest='reg', metavar='name=value', action='append', default=[], help="Set the value of a register. Do '--reg help' for more information. " "This option may be used multiple times.") group.add_argument('-s', '--start', dest='start', metavar='START', type=integer, help="Set the start address to JP to.") group.add_argument('--state', dest='state', metavar='name=value', action='append', default=[], help="Set a hardware state attribute. Do '--state help' for more information. " "This option may be used multiple times.") group.add_argument('-u', '--user-agent', dest='user_agent', metavar='AGENT', default='', help="Set the User-Agent header.") 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 'help' in namespace.ram_ops: _print_ram_help() return if 'help' in namespace.reg: print_reg_help() return if 'help' in namespace.state: print_state_help() return if unknown_args or len(namespace.args) != 2: parser.exit(2, parser.format_help()) url, z80 = namespace.args if namespace.output_dir: z80 = os.path.join(namespace.output_dir, z80) if namespace.stack is not None: namespace.reg.append('sp={}'.format(namespace.stack)) if namespace.start is not None: namespace.reg.append('pc={}'.format(namespace.start)) if namespace.force or not os.path.isfile(z80): try: make_z80(url, namespace, z80) except Exception as e: raise SkoolKitError("Error while getting snapshot {}: {}".format(os.path.basename(z80), e.args[0] if e.args else e)) else: write_line('{0}: file already exists; use -f to overwrite'.format(z80))
def main(args): parser = argparse.ArgumentParser( usage='bin2sna.py [options] file.bin [file.z80]', description="Convert a binary (raw memory) file into a Z80 snapshot. " "'file.bin' may be a regular file, or '-' for standard input. " "If 'file.z80' is not given, it defaults to the name of the input file with '.bin' replaced by '.z80', " "or 'program.z80' if reading from standard input.", add_help=False ) parser.add_argument('infile', help=argparse.SUPPRESS, nargs='?') parser.add_argument('outfile', help=argparse.SUPPRESS, nargs='?') group = parser.add_argument_group('Options') group.add_argument('-b', '--border', dest='border', metavar='BORDER', type=int, default=7, help="Set the border colour (default: 7).") group.add_argument('-o', '--org', dest='org', metavar='ORG', type=integer, help="Set the origin address (default: 65536 minus the length of file.bin).") group.add_argument('-p', '--stack', dest='stack', metavar='STACK', type=integer, help="Set the stack pointer (default: ORG).") group.add_argument('-P', '--poke', dest='pokes', metavar='a[-b[-c]],[^+]v', action='append', default=[], help="POKE N,v for N in {a, a+c, a+2c..., b}. " "Prefix 'v' with '^' to perform an XOR operation, or '+' to perform an ADD operation. " "This option may be used multiple times.") group.add_argument('-r', '--reg', dest='reg', metavar='name=value', action='append', default=[], help="Set the value of a register. Do '--reg help' for more information. This option may be used multiple times.") group.add_argument('-s', '--start', dest='start', metavar='START', type=integer, help="Set the address at which to start execution (default: ORG).") group.add_argument('-S', '--state', dest='state', metavar='name=value', action='append', default=[], help="Set a hardware state attribute. Do '--state help' for more information. This option may be used multiple times.") 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 'help' in namespace.reg: print_reg_help('r') return if 'help' in namespace.state: print_state_help('S') return infile = namespace.infile if unknown_args or infile is None: parser.exit(2, parser.format_help()) outfile = namespace.outfile if outfile is None: if infile.lower().endswith('.bin'): outfile = infile[:-3] + 'z80' elif infile == '-': outfile = 'program.z80' else: outfile = infile + '.z80' run(infile, outfile, namespace)
def main(args): parser = argparse.ArgumentParser( usage='snapmod.py [options] in.z80 [out.z80]', description="Modify a 48K Z80 snapshot.", add_help=False ) parser.add_argument('infile', help=argparse.SUPPRESS, nargs='?') parser.add_argument('outfile', help=argparse.SUPPRESS, nargs='?') group = parser.add_argument_group('Options') group.add_argument('-f', '--force', dest='force', action='store_true', help="Overwrite an existing snapshot.") group.add_argument('-m', '--move', dest='moves', metavar='src,size,dest', action='append', default=[], help='Move a block of bytes of the given size from src to dest. This option may be used multiple times.') group.add_argument('-p', '--poke', dest='pokes', metavar='a[-b[-c]],[^+]v', action='append', default=[], help="POKE N,v for N in {a, a+c, a+2c..., b}. " "Prefix 'v' with '^' to perform an XOR operation, or '+' to perform an ADD operation. " "This option may be used multiple times.") group.add_argument('-r', '--reg', dest='reg', metavar='name=value', action='append', default=[], help="Set the value of a register. Do '--reg help' for more information. This option may be used multiple times.") group.add_argument('-s', '--state', dest='state', metavar='name=value', action='append', default=[], help="Set a hardware state attribute. Do '--state help' for more information. This option may be used multiple times.") 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 'help' in namespace.reg: print_reg_help('r') return if 'help' in namespace.state: print_state_help('s') return infile = namespace.infile outfile = namespace.outfile if unknown_args or infile is None: parser.exit(2, parser.format_help()) if not infile.lower().endswith('.z80'): raise SkoolKitError('Unrecognised input snapshot type') if outfile is None: outfile = infile if namespace.force or not os.path.isfile(outfile): run(infile, namespace, outfile) else: write_line('{}: file already exists; use -f to overwrite'.format(outfile))
def main(args): parser = SkoolKitArgumentParser( usage='\n tap2sna.py [options] INPUT snapshot.z80\n tap2sna.py @FILE', description= "Convert a TAP or TZX file (which may be inside a zip archive) into a Z80 snapshot. " "INPUT may be the full URL to a remote zip archive or TAP/TZX file, or the path to a local file. " "Arguments may be read from FILE instead of (or as well as) being given on the command line.", fromfile_prefix_chars='@', add_help=False) parser.add_argument('args', help=argparse.SUPPRESS, nargs='*') group = parser.add_argument_group('Options') group.add_argument('-d', '--output-dir', dest='output_dir', metavar='DIR', help="Write the snapshot file in this directory.") group.add_argument('-f', '--force', action='store_true', help="Overwrite an existing snapshot.") group.add_argument('-p', '--stack', dest='stack', metavar='STACK', type=integer, help="Set the stack pointer.") group.add_argument( '--ram', dest='ram_ops', metavar='OPERATION', action='append', default=[], help= "Perform a load, move or poke operation on the memory snapshot being built. " "Do '--ram help' for more information. This option may be used multiple times." ) group.add_argument( '--reg', dest='reg', metavar='name=value', action='append', default=[], help= "Set the value of a register. Do '--reg help' for more information. " "This option may be used multiple times.") group.add_argument('-s', '--start', dest='start', metavar='START', type=integer, help="Set the start address to JP to.") group.add_argument( '--state', dest='state', metavar='name=value', action='append', default=[], help= "Set a hardware state attribute. Do '--state help' for more information. " "This option may be used multiple times.") 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 'help' in namespace.ram_ops: _print_ram_help() return if 'help' in namespace.reg: print_reg_help() return if 'help' in namespace.state: print_state_help() return if unknown_args or len(namespace.args) != 2: parser.exit(2, parser.format_help()) url, z80 = namespace.args if namespace.output_dir: z80 = os.path.join(namespace.output_dir, z80) if namespace.stack is not None: namespace.reg.append('sp={}'.format(namespace.stack)) if namespace.start is not None: namespace.reg.append('pc={}'.format(namespace.start)) if namespace.force or not os.path.isfile(z80): try: make_z80(url, namespace, z80) except Exception as e: raise SkoolKitError("Error while getting snapshot {0}: {1}".format( os.path.basename(z80), e.args[0])) else: write_line('{0}: file already exists; use -f to overwrite'.format(z80))
def main(args): parser = argparse.ArgumentParser( usage='snapmod.py [options] in.z80 [out.z80]', description="Modify a 48K Z80 snapshot.", add_help=False) parser.add_argument('infile', help=argparse.SUPPRESS, nargs='?') parser.add_argument('outfile', help=argparse.SUPPRESS, nargs='?') group = parser.add_argument_group('Options') group.add_argument('-f', '--force', dest='force', action='store_true', help="Overwrite an existing snapshot.") group.add_argument( '-m', '--move', dest='moves', metavar='src,size,dest', action='append', default=[], help= 'Move a block of bytes of the given size from src to dest. This option may be used multiple times.' ) group.add_argument( '-p', '--poke', dest='pokes', metavar='a[-b[-c]],[^+]v', action='append', default=[], help="POKE N,v for N in {a, a+c, a+2c..., b}. " "Prefix 'v' with '^' to perform an XOR operation, or '+' to perform an ADD operation. " "This option may be used multiple times.") group.add_argument( '-r', '--reg', dest='reg', metavar='name=value', action='append', default=[], help= "Set the value of a register. Do '--reg help' for more information. This option may be used multiple times." ) group.add_argument( '-s', '--state', dest='state', metavar='name=value', action='append', default=[], help= "Set a hardware state attribute. Do '--state help' for more information. This option may be used multiple times." ) 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 'help' in namespace.reg: print_reg_help('r') return if 'help' in namespace.state: print_state_help('s') return infile = namespace.infile outfile = namespace.outfile if unknown_args or infile is None: parser.exit(2, parser.format_help()) if not infile.lower().endswith('.z80'): raise SkoolKitError('Unrecognised input snapshot type') if outfile is None: outfile = infile if namespace.force or not os.path.isfile(outfile): run(infile, namespace, outfile) else: write_line( '{}: file already exists; use -f to overwrite'.format(outfile))