diff --git a/msx2utf8.py b/msx2utf8.py index 8fee05e..90eeabd 100755 --- a/msx2utf8.py +++ b/msx2utf8.py @@ -27,10 +27,17 @@ def msxchars(): for i in range(65,96): yield (256 + i, chars[160 + i]) -charmap = {} +msx2uni = {} +uni2msx = {} for m,c in msxchars(): - charmap[m] = c + if m in msx2uni: + raise ValueError("MSX code {} is duplicated".format(m)) + msx2uni[m] = c + if c in uni2msx: + raise ValueError("Codepoint {} ({}) is duplicated" + .format(ord(c), c)) + uni2msx[c] = m if len(sys.argv) < 2: while True: @@ -44,7 +51,7 @@ if len(sys.argv) < 2: sys.stdout.write('\x01') break code = 256 + c[0] - char = charmap[code] + char = msx2uni[code] sys.stdout.write(char) if sys.argv[1] == '-l':