aboutsummaryrefslogtreecommitdiff
path: root/tools/raw.py
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-07-02 21:31:19 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-07-02 21:31:19 +0100
commita88810c8a70c8e3a7533a266774ab61a84a9adf4 (patch)
tree9ec78cd5e20f06a6cbcbd0251e215f2ecaae71c4 /tools/raw.py
parent6e03fe85b19bc533888a4689572aab0ccf68edc4 (diff)
downloadgold-mine-run-a88810c8a70c8e3a7533a266774ab61a84a9adf4.tar.gz
gold-mine-run-a88810c8a70c8e3a7533a266774ab61a84a9adf4.zip
Add sound support
Diffstat (limited to 'tools/raw.py')
-rwxr-xr-xtools/raw.py58
1 files changed, 58 insertions, 0 deletions
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 <jjm@usebox.net>",
+ )
+
+ 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()