shithub: pokecrystal

Download patch

ref: 55e40b520ec498630398ad302085868df870cf49
parent: 2eeae555c5e4f2eed4b1e33d6f980fb5eeb93901
author: Bryan Bishop <[email protected]>
date: Fri May 4 13:25:48 EDT 2012

to_asm output for $50 and unknown bytes in texts

--- a/extras/crystal.py
+++ b/extras/crystal.py
@@ -1838,8 +1838,14 @@
         # 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"
@@ -1846,20 +1852,61 @@
                 
                 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