diff options
author | Sanky <gsanky@gmail.com> | 2013-10-21 20:24:46 +0200 |
---|---|---|
committer | Sanky <gsanky@gmail.com> | 2013-10-21 20:24:46 +0200 |
commit | b5268ab9207f02574abe8d6f5407e25f4a86365a (patch) | |
tree | adce2892dd4c07781f2db42854e30fc25dba8b15 /textpre.py | |
parent | da3b8dc19d685eb15c23d345aa51afb25b7dce58 (diff) | |
parent | 3016f72851213659656c6ce2cd2dcee6625b06bb (diff) |
Merge remote-tracking branch 'kanzure/master' into mergetastic
Conflicts:
main.asm
Diffstat (limited to 'textpre.py')
-rw-r--r-- | textpre.py | 83 |
1 files changed, 8 insertions, 75 deletions
@@ -1,5 +1,8 @@ # -*- coding: utf-8 -*- +import extras.pokemontools.preprocessor as preprocessor +import extras.pokemontools.configuration as configuration + import sys chars = { @@ -254,81 +257,11 @@ chars = { "6": 0xFC, "7": 0xFD, "8": 0xFE, -"9": 0xFF - +"9": 0xFF, } -for l in sys.stdin: - - # strip comments - line = l.partition(";") - i = 0 - asm = "" - while i < len(line) and l[0] != ";": - asm = asm + line[i] - i = i + 1 - - # skip asm with no quotes - if "\"" not in asm: - sys.stdout.write(l) - continue - - # split by quotes - asms = asm.split("\"") - - # skip asm that actually does use ASCII in quotes - lowasm = asms[0].lower() - if "section" in lowasm \ - or "include" in lowasm \ - or "incbin" in lowasm: - sys.stdout.write(l) - continue - - even = False - i = 0 - for token in asms: - i = i + 1 - if even: - # token is a string to convert to byte values - - while len(token): - # read a single UTF-8 codepoint - char = token[0] - if ord(char) >= 0xFC: - char = char + token[1:6] - token = token[6:] - elif ord(char) >= 0xF8: - char = char + token[1:5] - token = token[5:] - elif ord(char) >= 0xF0: - char = char + token[1:4] - token = token[4:] - elif ord(char) >= 0xE0: - char = char + token[1:3] - token = token[3:] - elif ord(char) >= 0xC0: - char = char + token[1:2] - token = token[2:] - else: - token = token[1:] - - # certain apostrophe-letter pairs are only a single byte - if char == "'" and \ - (token[0] == "d" or \ - token[0] == "l" or \ - token[0] == "m" or \ - token[0] == "r" or \ - token[0] == "s" or \ - token[0] == "t" or \ - token[0] == "v"): - char = char + token[0] - token = token[1:] - - sys.stdout.write("${0:02X}".format(chars[char])) - - if len(token): - sys.stdout.write(", ") +preprocessor.chars = chars - else: - sys.stdout.write(token) - even = not even +config = configuration.Config() +processor = preprocessor.Preprocessor(config, []) +processor.preprocess() |