aboutsummaryrefslogtreecommitdiff
path: root/support
diff options
context:
space:
mode:
Diffstat (limited to 'support')
-rw-r--r--support/in2data.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/support/in2data.py b/support/in2data.py
new file mode 100644
index 0000000..5f497a9
--- /dev/null
+++ b/support/in2data.py
@@ -0,0 +1,52 @@
+import sys
+
+def pascal_to_basic(line):
+ if len(line.strip()) == 0:
+ return "", 0
+
+ ret = ""
+ bytes = 0
+ commands = line.strip().split("/")
+
+ for c in commands:
+ c = c.strip()
+ if c.startswith("$"):
+ if c == commands[0]:
+ ret = "DATA "
+ else:
+ ret = ret + ", "
+
+ cnum = c[1:]
+ ret = ret + "&H" + cnum
+ bytes = bytes + 1
+
+ elif c.startswith("{"):
+ if c != commands[0]:
+ ret = ret + " : "
+ ret = ret + "REM " + c.strip()[1:-1]
+
+ return ret, bytes
+
+
+def inline_to_basic(input_file, output_file, line_start):
+ total_bytes = 0
+ line_number = line_start
+ for line in input_file:
+ line = line.strip()
+
+ basline, line_bytes = pascal_to_basic(line)
+ if basline is not None and len(basline) > 0:
+ output_file.write("{0} {1}\r\n".format(line_number, basline))
+ total_bytes = total_bytes + line_bytes
+ line_number = line_number + 1
+
+ output_file.write("{0} REM Total Bytes in Data: {1}\r\n".format(line_number, total_bytes))
+
+if __name__ == "__main__":
+ fpin = open(sys.argv[1], "r")
+ fpout = open(sys.argv[2], "w")
+
+ inline_to_basic(fpin, fpout, int(sys.argv[3]))
+
+ fpin.close()
+ fpout.close()