blob: f31ed0440add8697a7dac57086e05af36cb74262 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
import sys
if len(sys.argv) < 2:
raise ValueError("Must have gbtxt file in first argument")
gbtxt_filename = sys.argv[1]
gbtxt_file = open(gbtxt_filename, 'r')
def ascii_to_gbtext_format(c):
c = c.upper()
match c:
case c if c <= '9' and c >= '0':
return ord(c) - ord('0') + 0x80
case c if c <= 'Z' and c >= 'A':
return ord(c) - ord('A') + 0x80 + 10
case ':':
return 0xaa
case '"':
return 0xa9
case "'":
return 0xa8
case ',':
return 0xa7
case '?':
return 0xa6
case '!':
return 0xa5
case '.':
return 0xa4
case ' ':
return 0x00
case _:
raise ValueError("Char \"" + c + "\" is not in the allowed charset")
for line in gbtxt_file:
line = line.strip()
if len(line) == 0:
continue
if line[0] == '#':
continue
if not ':' in line:
raise ValueError("Text without label is not allowed")
label = line[:line.index(':') + 1]
text = line[line.index(':') + 1:].strip()
print(label)
print(".DB", ", ".join([hex(ascii_to_gbtext_format(c)) for c in text]) + ", 0xff")
|