From a88810c8a70c8e3a7533a266774ab61a84a9adf4 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sun, 2 Jul 2023 21:31:19 +0100 Subject: Add sound support --- tools/raw.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 tools/raw.py (limited to 'tools/raw.py') diff --git a/tools/raw.py b/tools/raw.py new file mode 100755 index 0000000..755a64c --- /dev/null +++ b/tools/raw.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 + +from argparse import ArgumentParser +import subprocess +import os + +__version__ = "1.0" + +ld = os.environ.get("LD", "i586-pc-msdosdjgpp-ld") +strip = os.environ.get("STRIP", "i586-pc-msdosdjgpp-strip") + + +def main(): + parser = ArgumentParser( + description="RAW to .o", + epilog="Copyright (C) 2023 Juan J Martinez ", + ) + + parser.add_argument( + "--version", action="version", version="%(prog)s " + __version__ + ) + parser.add_argument("file", help="file to convert") + parser.add_argument("output", help="object name for the map data") + + args = parser.parse_args() + + with open(args.file, "rb") as fd: + data = fd.read() + + tmp = args.output.rstrip(".o") + with open(tmp, "wb") as fd: + fd.write(bytearray(data)) + fd.flush() + + # create an object file from the binary + rc = subprocess.call( + [ + ld, + "-r", + "-b", + "binary", + "-o", + args.output, + tmp, + ] + ) + os.unlink(tmp) + if rc != 0: + parser.error("Failed to run %s" % ld) + + # strip unwanted symbols + rc = subprocess.call([strip, "-w", "-K", "*_%s_*" % tmp, args.output]) + if rc != 0: + parser.error("Failed to run %s" % ld) + + +if __name__ == "__main__": + main() -- cgit v1.2.3