pokecrystal/textpre.py

342 lines
7.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
chars = {}
chars[""] = "$05"
chars[""] = "$06"
chars[""] = "$07"
chars[""] = "$08"
chars[""] = "$09"
chars[""] = "$0A"
chars[""] = "$0B"
chars[""] = "$0C"
chars[""] = "$0D"
chars[""] = "$0E"
chars[""] = "$0F"
chars[""] = "$10"
chars[""] = "$11"
chars[""] = "$12"
chars[""] = "$13"
chars[""] = "$19"
chars[""] = "$1A"
chars[""] = "$1B"
chars[""] = "$1C"
chars[""] = "$26"
chars[""] = "$27"
chars[""] = "$28"
chars[""] = "$29"
chars[""] = "$2A"
chars[""] = "$2B"
chars[""] = "$2C"
chars[""] = "$2D"
chars[""] = "$2E"
chars[""] = "$2F"
chars[""] = "$30"
chars[""] = "$31"
chars[""] = "$32"
chars[""] = "$33"
chars[""] = "$34"
chars[""] = "$3A"
chars[""] = "$3B"
chars[""] = "$3C"
chars[""] = "$3D"
chars[""] = "$3E"
chars[""] = "$40"
chars[""] = "$41"
chars[""] = "$42"
chars[""] = "$43"
chars[""] = "$44"
chars[""] = "$45"
chars[""] = "$46"
chars[""] = "$47"
chars[""] = "$48"
chars[""] = "$80"
chars[""] = "$81"
chars[""] = "$82"
chars[""] = "$83"
chars[""] = "$84"
chars[""] = "$85"
chars[""] = "$86"
chars[""] = "$87"
chars[""] = "$88"
chars[""] = "$89"
chars[""] = "$8A"
chars[""] = "$8B"
chars[""] = "$8C"
chars[""] = "$8D"
chars[""] = "$8E"
chars[""] = "$8F"
chars[""] = "$90"
chars[""] = "$91"
chars[""] = "$92"
chars[""] = "$93"
chars[""] = "$94"
chars[""] = "$95"
chars[""] = "$96"
chars[""] = "$97"
chars[""] = "$98"
chars[""] = "$99"
chars[""] = "$9A"
chars[""] = "$9B"
chars[""] = "$9C"
chars[""] = "$9D"
chars[""] = "$9E"
chars[""] = "$9F"
chars[""] = "$A0"
chars[""] = "$A1"
chars[""] = "$A2"
chars[""] = "$A3"
chars[""] = "$A4"
chars[""] = "$A5"
chars[""] = "$A6"
chars[""] = "$A7"
chars[""] = "$A8"
chars[""] = "$A9"
chars[""] = "$AA"
chars[""] = "$AB"
chars[""] = "$AC"
chars[""] = "$AD"
chars[""] = "$AE"
chars[""] = "$AF"
chars[""] = "$B0"
chars[""] = "$B1"
chars[""] = "$B2"
chars[""] = "$B3"
chars[""] = "$B4"
chars[""] = "$B5"
chars[""] = "$B6"
chars[""] = "$B7"
chars[""] = "$B8"
chars[""] = "$B9"
chars[""] = "$BA"
chars[""] = "$BB"
chars[""] = "$BC"
chars[""] = "$BD"
chars[""] = "$BE"
chars[""] = "$BF"
chars[""] = "$C0"
chars[""] = "$C1"
chars[""] = "$C2"
chars[""] = "$C3"
chars[""] = "$C4"
chars[""] = "$C5"
chars[""] = "$C6"
chars[""] = "$C7"
chars[""] = "$C8"
chars[""] = "$C9"
chars[""] = "$CA"
chars[""] = "$CB"
chars[""] = "$CC"
chars[""] = "$CD"
chars[""] = "$CE"
chars[""] = "$CF"
chars[""] = "$D0"
chars[""] = "$D1"
chars[""] = "$D2"
chars[""] = "$D3"
chars[""] = "$D4"
chars[""] = "$D5"
chars[""] = "$D6"
chars[""] = "$D7"
chars[""] = "$D8"
chars[""] = "$D9"
chars[""] = "$DA"
chars[""] = "$DB"
chars[""] = "$DC"
chars[""] = "$DD"
chars[""] = "$DE"
chars[""] = "$DF"
chars[""] = "$E0"
chars[""] = "$E1"
chars[""] = "$E2"
chars[""] = "$E3"
chars["@"] = "$50"
chars["#"] = "$54"
chars[""] = "$75"
# textbox borders
chars[""] = "$79"
chars[""] = "$7A"
chars[""] = "$7B"
chars[""] = "$7C"
chars[""] = "$7D"
chars[""] = "$7E"
chars[""] = "$74"
chars[" "] = "$7F"
chars["A"] = "$80"
chars["B"] = "$81"
chars["C"] = "$82"
chars["D"] = "$83"
chars["E"] = "$84"
chars["F"] = "$85"
chars["G"] = "$86"
chars["H"] = "$87"
chars["I"] = "$88"
chars["J"] = "$89"
chars["K"] = "$8A"
chars["L"] = "$8B"
chars["M"] = "$8C"
chars["N"] = "$8D"
chars["O"] = "$8E"
chars["P"] = "$8F"
chars["Q"] = "$90"
chars["R"] = "$91"
chars["S"] = "$92"
chars["T"] = "$93"
chars["U"] = "$94"
chars["V"] = "$95"
chars["W"] = "$96"
chars["X"] = "$97"
chars["Y"] = "$98"
chars["Z"] = "$99"
chars["("] = "$9A"
chars[")"] = "$9B"
chars[":"] = "$9C"
chars[";"] = "$9D"
chars["["] = "$9E"
chars["]"] = "$9F"
chars["a"] = "$A0"
chars["b"] = "$A1"
chars["c"] = "$A2"
chars["d"] = "$A3"
chars["e"] = "$A4"
chars["f"] = "$A5"
chars["g"] = "$A6"
chars["h"] = "$A7"
chars["i"] = "$A8"
chars["j"] = "$A9"
chars["k"] = "$AA"
chars["l"] = "$AB"
chars["m"] = "$AC"
chars["n"] = "$AD"
chars["o"] = "$AE"
chars["p"] = "$AF"
chars["q"] = "$B0"
chars["r"] = "$B1"
chars["s"] = "$B2"
chars["t"] = "$B3"
chars["u"] = "$B4"
chars["v"] = "$B5"
chars["w"] = "$B6"
chars["x"] = "$B7"
chars["y"] = "$B8"
chars["z"] = "$B9"
chars["Ä"] = "$C0"
chars["Ö"] = "$C1"
chars["Ü"] = "$C2"
chars["ä"] = "$C3"
chars["ö"] = "$C4"
chars["ü"] = "$C5"
chars["'d"] = "$D0"
chars["'l"] = "$D1"
chars["'m"] = "$D2"
chars["'r"] = "$D3"
chars["'s"] = "$D4"
chars["'t"] = "$D5"
chars["'v"] = "$D6"
chars["'"] = "$E0"
chars["-"] = "$E3"
chars["?"] = "$E6"
chars["!"] = "$E7"
chars["."] = "$E8"
chars["&"] = "$E9"
chars["é"] = "$EA"
chars[""] = "$EB"
chars[""] = "$EF"
chars["¥"] = "$F0"
chars["×"] = "$F1"
chars["/"] = "$F3"
chars[","] = "$F4"
chars[""] = "$F5"
chars["0"] = "$F6"
chars["1"] = "$F7"
chars["2"] = "$F8"
chars["3"] = "$F9"
chars["4"] = "$FA"
chars["5"] = "$FB"
chars["6"] = "$FC"
chars["7"] = "$FD"
chars["8"] = "$FE"
chars["9"] = "$FF"
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(chars[char])
if len(token):
sys.stdout.write(", ")
else:
sys.stdout.write(token)
even = not even