add RCF generator for ROM fix
authorDan White <dan@whiteaudio.com>
Mon, 29 Apr 2013 18:41:26 +0000 (13:41 -0500)
committerDan White <dan@whiteaudio.com>
Mon, 29 Apr 2013 18:41:26 +0000 (13:41 -0500)
make-romfix.sh [new file with mode: 0755]
romasm2rcf.py [new file with mode: 0755]

diff --git a/make-romfix.sh b/make-romfix.sh
new file mode 100755 (executable)
index 0000000..c23c445
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+./romasm2rcf.py rom-bugfix.asm > rom-bugfix.rcf
+./rcf2ihex.py rom-bugfix.rcf > rom-bugfix.hex
+
+
+echo "********* RCF differences *********"
+diff -u rom.rcf rom-bugfix.rcf
+echo "***********************************"
+echo
+
diff --git a/romasm2rcf.py b/romasm2rcf.py
new file mode 100755 (executable)
index 0000000..37b939b
--- /dev/null
@@ -0,0 +1,59 @@
+#! /usr/bin/env python
+
+
+import sys
+from collections import defaultdict
+
+
+
+infile = 'rom-bugfix.asm'
+
+# unused ROM words default to this value
+addresses = defaultdict(lambda: 0)
+
+# trailing bytes (typ. after a string) should be this value
+empty_byte = 0
+
+
+def binword(w, width=16):
+    """Return a width-length, left-zero-padded bit string binary representation
+    of the integer w."""
+    b = bin(w)
+    b = b.lstrip('0b')
+    return ('0' * (width - len(b))) + b
+
+
+#for line in open(sys.argv[1]):
+for line in open(infile):
+    line.strip()
+
+    if line.startswith(';'):
+        continue
+
+    sp = line.split()
+
+    if (len(sp) > 0) and sp[0].endswith(':'):
+        #is this a label?
+        try:
+            addr = int(sp[0][0:4], 16)
+        except ValueError:
+            continue
+
+
+        addresses[addr] = int(sp[1], 16)
+
+        # collect the next bytes, if present
+        for i in (1, 2, 3):
+            try:
+                data = int(sp[i+1], 16)
+            except (IndexError, ValueError):
+                continue
+
+            addresses[addr + i] = data
+
+
+# dump all the ROM addresses
+for addr in range(0x3000, 0x4000, 2):
+    word = (addresses[addr+1] << 8) + addresses[addr]
+    print binword(word)
+