diff options
author | Háčky <hatschky@gmail.com> | 2014-11-27 07:15:45 +0000 |
---|---|---|
committer | Háčky <hatschky@gmail.com> | 2014-11-27 07:15:45 +0000 |
commit | 319ed6d0e0266f5f6174a5acd929914db8cfae1d (patch) | |
tree | 76408d9cadcbed1e702efa8c44f4cf5e364b0a4d /scripts/regionalize.py | |
parent | 17853b802692237d98f96d1a80caf2019f71753e (diff) |
Diffstat (limited to 'scripts/regionalize.py')
-rw-r--r-- | scripts/regionalize.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/scripts/regionalize.py b/scripts/regionalize.py new file mode 100644 index 0000000..c178d06 --- /dev/null +++ b/scripts/regionalize.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +import sys +from gen3text import utf8ToRSText +from asmquote import asmQuote + +data_region = sys.argv[3] # determines region code +text_region = sys.argv[4] # determines string translation + +out = open(sys.argv[2], 'w') + +with open(sys.argv[1], 'rb') as f: + for asm in f: + asms = asm.split('"') + command = asms[0].strip() + if (command == "Text_" + text_region) or (command == "Text"): + asms[1] = utf8ToRSText(asms[1], text_region) + try: + length = asms[2].split(';')[0] # strip trailing comment + padding = int(length) - len(asms[1]) + if padding > 0: + asms[1] += '\xFF' + for i in range(padding - 1): + asms[1] += "\x00" + except ValueError: + pass + out.write("db " + asmQuote(asms[1]) + "\n") + elif len(command) < 5 or command[0:5] != "Text_": + out.write(asm) + if "macros.asm" in asm: + # can’t do this until after REGION_EN, etc. are loaded + out.write("REGION EQU REGION_" + data_region + "\n") + # else this is foreign text, delete it +f.closed
\ No newline at end of file |