summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan Bishop <kanzure@gmail.com>2012-05-04 17:25:48 -0500
committerBryan Bishop <kanzure@gmail.com>2012-05-04 17:25:48 -0500
commit0d4b34cb32e02dbb126e5098ff879ca52ea8639b (patch)
treef4b22009986e1091dc19954f2ff2ad76d822739e
parent42a0e91d154f8fefacedf3706e918553ef3a5677 (diff)
to_asm output for $50 and unknown bytes in texts
original-commit-id: 55e40b520ec498630398ad302085868df870cf49
-rw-r--r--crystal.py57
1 files changed, 52 insertions, 5 deletions
diff --git a/crystal.py b/crystal.py
index 3765c4c..3e1d18e 100644
--- a/crystal.py
+++ b/crystal.py
@@ -1838,28 +1838,75 @@ class MainText(TextCommand):
# whether or not there was a ", " last..
# this is useful outside of quotes
was_comma = False
+
+ # has a $50 or $57 been passed yet?
+ end = False
for byte in self.bytes:
+ if end:
+ raise Exception, "the text ended due to a $50 or $57 but there are more bytes?"
+
# $4f, $51 and $55 can end a line
if byte in [0x4f, 0x51, 0x55]:
assert not new_line, "can't have $4f, $51, $55 as the first character on a newline"
if in_quotes:
output += "\", $%.2x\n" % (byte)
- in_quotes = False
- new_line = True
elif not in_quotes:
if not was_comma:
output += ", "
output += "$%.2x\n" % (byte)
- was_comma = False
- new_line = True
+
+ # reset everything
+ in_quotes = False
+ new_line = True
+ was_comma = False
elif byte == 0x50:
+ # technically you could have this i guess... db "@"
+ # but in most situations it will be added to the end of the previous line
assert not new_line, "can't have $50 or '@' as the first character on a newline"
if in_quotes:
- output += "@\""
+ output += "@\"\n"
+ new_line = True
+ elif not in_quotes:
+ if not was_comma:
+ output += ", "
+ output += "\"@\"\n"
+
+ # reset everything
+ in_quotes = False
+ new_line = True
+ was_comma = False
+ end = True
+ elif byte in chars.keys():
+ char = chars[byte]
+
+ if char == "\"":
+ pass
pass
+ else:
+ # raise Exception, "unknown byte in text script ($%.2x)" % (byte)
+ # just add an unknown byte directly to the text.. what's the worse that can happen?
+
+ if new_line:
+ output += "db "
+
+ if in_quotes:
+ output += "\", $%.2x" % (byte)
+
+ in_quotes = False
+ was_comma = False
+ new_line = False
+ elif not in_quotes:
+ if not was_comma and not new_line:
+ output += ", "
+ output += "$%.2x" % (byte)
+
+ # reset things
+ in_quotes = False
+ new_line = False
+ was_comma = False
# TODO