summaryrefslogtreecommitdiff
path: root/preprocessor.py
diff options
context:
space:
mode:
Diffstat (limited to 'preprocessor.py')
-rw-r--r--preprocessor.py49
1 files changed, 42 insertions, 7 deletions
diff --git a/preprocessor.py b/preprocessor.py
index 48906da5e..67e4cdb9f 100644
--- a/preprocessor.py
+++ b/preprocessor.py
@@ -307,7 +307,8 @@ chars = {
}
def separate_comment(l):
- """ Separates asm and comments on a single line.
+ """
+ Separates asm and comments on a single line.
"""
asm = ""
@@ -336,7 +337,8 @@ def separate_comment(l):
return asm, comment
def quote_translator(asm):
- """ Writes asm with quoted text translated into bytes.
+ """
+ Writes asm with quoted text translated into bytes.
"""
# split by quotes
@@ -350,6 +352,11 @@ def quote_translator(asm):
sys.stdout.write(asm)
return
+ print_macro = False
+ if asms[0].strip() == 'print':
+ asms[0] = asms[0].replace('print','db 0,')
+ print_macro = True
+
output = ""
even = False
i = 0
@@ -357,6 +364,7 @@ def quote_translator(asm):
i = i + 1
if even:
+ characters = []
# token is a string to convert to byte values
while len(token):
# read a single UTF-8 codepoint
@@ -391,10 +399,35 @@ def quote_translator(asm):
char = char + token[0]
token = token[1:]
- output += ("${0:02X}".format(chars[char]))
+ characters += [char]
+
+ if print_macro:
+ line = 0
+ while len(characters):
+ last_char = 1
+ if len(characters) > 18 and characters[-1] != '@':
+ for i, char in enumerate(characters):
+ last_char = i + 1
+ if ' ' not in characters[i+1:18]: break
+ output += ", ".join("${0:02X}".format(chars[char]) for char in characters[:last_char-1])
+ if characters[last_char-1] != " ":
+ output += ", ${0:02X}".format(characters[last_char-1])
+ if not line & 1:
+ line_ending = 0x4f
+ else:
+ line_ending = 0x51
+ output += ", ${0:02X}".format(line_ending)
+ line += 1
+ else:
+ output += ", ".join(["${0:02X}".format(chars[char]) for char in characters[:last_char]])
+ characters = characters[last_char:]
+ if len(characters): output += ", "
+ # end text
+ line_ending = 0x57
+ output += ", ${0:02X}".format(line_ending)
+
+ output += ", ".join(["${0:02X}".format(chars[char]) for char in characters])
- if len(token):
- output += (", ")
# if not even
else:
output += (token)
@@ -414,7 +447,8 @@ def make_macro_table():
macro_table = make_macro_table()
def macro_test(asm):
- """ Returns a matching macro, or None/False.
+ """
+ Returns a matching macro, or None/False.
"""
# macros are determined by the first symbol on the line
@@ -427,7 +461,8 @@ def macro_test(asm):
return (None, None)
def macro_translator(macro, token, line):
- """ Converts a line with a macro into a rgbasm-compatible line.
+ """
+ Converts a line with a macro into a rgbasm-compatible line.
"""
assert macro.macro_name == token, "macro/token mismatch"