mirror of
https://github.com/pret/pokegold-spaceworld.git
synced 2026-10-02 13:26:45 -05:00
Parse charmap.asm for dump_text.py and dump_names.py
This commit is contained in:
69
charmap.asm
69
charmap.asm
@@ -2,8 +2,10 @@
|
||||
|
||||
; Control characters (see home/text.asm)
|
||||
|
||||
charmap "<NULL>", $00
|
||||
|
||||
charmap "<PLAY_G>", $14 ; "<PLAYER>くん" or "<PLAYER>ちゃん"; same as "<PLAYER>" in English
|
||||
charmap "<JP_18>", $18 ; "ノ゛"? (ungrammatical)
|
||||
|
||||
charmap "<NI>", $1d ; "に "
|
||||
charmap "<TTE>", $1e ; "って"
|
||||
charmap "<WO>", $1f ; "を "
|
||||
@@ -44,15 +46,47 @@
|
||||
charmap "<ROCKET>", $5e ; "ROCKET"
|
||||
charmap "<DEXEND>", $5f
|
||||
|
||||
; Actual characters (from other graphics files)
|
||||
; Other characters
|
||||
|
||||
; needed for _LoadFontsExtra1 (see engine/load_font.asm)
|
||||
charmap "■", $60 ; gfx/font/black.2bpp
|
||||
charmap "▲", $61 ; gfx/font/up_arrow.png
|
||||
charmap "☎", $62 ; gfx/font/phone_icon.2bpp
|
||||
charmap "■", $60
|
||||
charmap "▲", $61
|
||||
charmap "☎", $62
|
||||
|
||||
charmap "D", $63
|
||||
charmap "E", $64
|
||||
charmap "F", $65
|
||||
charmap "G", $66
|
||||
charmap "H", $67
|
||||
charmap "I", $68
|
||||
charmap "V", $69
|
||||
charmap "S", $6a
|
||||
charmap "L", $6b
|
||||
charmap "M", $6c
|
||||
|
||||
charmap ":", $6d
|
||||
|
||||
charmap "「", $70
|
||||
charmap "」", $71
|
||||
charmap "『", $72
|
||||
charmap "』", $73
|
||||
charmap "・", $74
|
||||
charmap "…", $75
|
||||
|
||||
charmap "┌", $79
|
||||
charmap "─", $7a
|
||||
charmap "┐", $7b
|
||||
charmap "│", $7c
|
||||
charmap "└", $7d
|
||||
charmap "┘", $7e
|
||||
charmap " ", $7f
|
||||
|
||||
; Japanese kana
|
||||
|
||||
charmap "イ゛", $01
|
||||
charmap "ヴ", $02
|
||||
charmap "エ゛", $03
|
||||
charmap "オ゛", $04
|
||||
|
||||
charmap "ガ", $05
|
||||
charmap "ギ", $06
|
||||
charmap "グ", $07
|
||||
@@ -69,11 +103,17 @@
|
||||
charmap "デ", $12
|
||||
charmap "ド", $13
|
||||
|
||||
charmap "ネ゛", $17
|
||||
charmap "ノ゛", $18
|
||||
|
||||
charmap "バ", $19
|
||||
charmap "ビ", $1a
|
||||
charmap "ブ", $1b
|
||||
charmap "ボ", $1c
|
||||
|
||||
charmap "ィ゛", $20
|
||||
charmap "あ゛", $21
|
||||
|
||||
charmap "が", $26
|
||||
charmap "ぎ", $27
|
||||
charmap "ぐ", $28
|
||||
@@ -106,25 +146,14 @@
|
||||
charmap "ぺ", $47
|
||||
charmap "ぽ", $48
|
||||
|
||||
charmap "「", $70
|
||||
charmap "」", $71
|
||||
charmap "『", $72
|
||||
charmap "』", $73
|
||||
charmap "·", $74
|
||||
charmap "⋯", $75
|
||||
charmap "も゜", $4d
|
||||
|
||||
charmap "ぃ", $6e
|
||||
charmap "ぅ", $6f
|
||||
charmap "ぁ", $76
|
||||
charmap "ぇ", $77
|
||||
charmap "ぉ", $78
|
||||
|
||||
charmap "┌", $79
|
||||
charmap "─", $7a
|
||||
charmap "┐", $7b
|
||||
charmap "│", $7c
|
||||
charmap "└", $7d
|
||||
charmap "┘", $7e
|
||||
charmap " ", $7f
|
||||
|
||||
charmap "ア", $80
|
||||
charmap "イ", $81
|
||||
charmap "ウ", $82
|
||||
|
||||
@@ -1,18 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys, os, io
|
||||
|
||||
def parse_int(s):
|
||||
s = s.strip()
|
||||
if s.startswith('$'):
|
||||
return int(s[1:], 16)
|
||||
if s.startswith('%'):
|
||||
return int(s[1:], 2)
|
||||
return int(s)
|
||||
|
||||
def parse_string(s):
|
||||
# assumes strings are literal, no STRCAT() etc
|
||||
return s.strip('" ')
|
||||
from read_charmap import get_project_dir, read_charmap
|
||||
|
||||
def calc_bank(p):
|
||||
return p // 0x4000
|
||||
@@ -26,39 +15,10 @@ def get_sym_loc(p):
|
||||
b, a = calc_bank(p), calc_address(p)
|
||||
return '%02x:%04x' % (b, a)
|
||||
|
||||
def strip_comment(s):
|
||||
# assumes ";" is not in the charmap
|
||||
return s.split(';')[0].rstrip()
|
||||
|
||||
def get_project_dir():
|
||||
script_path = os.path.realpath(__file__)
|
||||
script_dir = os.path.dirname(script_path)
|
||||
project_dir = os.path.join(script_dir, '..')
|
||||
return os.path.normpath(project_dir)
|
||||
|
||||
def get_charmap_path():
|
||||
project_dir = get_project_dir()
|
||||
return os.path.join(project_dir, 'charmap.asm')
|
||||
|
||||
def get_baserom_path():
|
||||
project_dir = get_project_dir()
|
||||
return os.path.join(project_dir, 'baserom.gb')
|
||||
|
||||
def read_charmap():
|
||||
charmap_path = get_charmap_path()
|
||||
charmap = {}
|
||||
with io.open(charmap_path, 'r', encoding='utf-8') as f:
|
||||
lines = f.readlines()
|
||||
for line in lines:
|
||||
line = strip_comment(line).lstrip()
|
||||
if not line.startswith('charmap '):
|
||||
continue
|
||||
char, value = line[len('charmap '):].rsplit(',', 1)
|
||||
char = parse_string(char)
|
||||
value = parse_int(value)
|
||||
charmap[value] = char
|
||||
return charmap
|
||||
|
||||
def dump_strings(data):
|
||||
charmap = read_charmap()
|
||||
ss = []
|
||||
|
||||
@@ -1,26 +1,12 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
from sys import argv, stdout
|
||||
from read_charmap import read_charmap
|
||||
|
||||
|
||||
char_table = [
|
||||
"?", "イ゛", "ヴ", "エ゛", "オ゛", "ガ", "ギ", "グ", "ゲ", "ゴ", "ザ", "ジ", "ズ", "ゼ", "ゾ", "ダ",
|
||||
"ヂ", "ヅ", "デ", "ド", "<PLAY_G>", "<0x15>", "<0x16>", "ネ゛", "<JP_18>", "バ", "ビ", "ブ", "ボ", "<NI>", "<TTE>", "<WO>",
|
||||
"ィ゛", "あ゛", "<TA!>", "<KOUGEKI>", "<WA>", "<NO>", "が", "ぎ", "ぐ", "げ", "ご", "ざ", "じ", "ず", "ぜ", "ぞ",
|
||||
"だ", "ぢ", "づ", "で", "ど", "<ROUTE>", "<WATASHI>", "<KOKO_WA>", "<RED>", "<GREEN>", "ば", "び", "ぶ", "べ", "ぼ", "<ENEMY>",
|
||||
"パ", "ピ", "プ", "ポ", "ぱ", "ぴ", "ぷ", "ぺ", "ぽ", "<MOM>", "<GA>", "<_CONT>", "<SCROLL>", "も゜", "<NEXT>", "<LINE>",
|
||||
"@", "<PARA>", "<PLAYER>", "<RIVAL>", "#", "<CONT>", "<……>", "<DONE>", "<PROMPT>", "<TARGET>", "<USER>", "<PC>", "<TM>", "<TRAINER>", "<ROCKET>", "<DEXEND>",
|
||||
"■", "▲", "☎", "D", "E", "F", "G", "H", "I", "V", "S", "L", "M", ":", "ぃ", "ぅ",
|
||||
"「", "」", "『", "』", "・", "<・・・>", "ぁ", "ぇ", "ぉ", "┌", "─", "┐", "│", "└", "┘", " ",
|
||||
"ア", "イ", "ウ", "エ", "オ", "カ", "キ", "ク", "ケ", "コ", "サ", "シ", "ス", "セ", "ソ", "タ",
|
||||
"チ", "ツ", "テ", "ト", "ナ", "ニ", "ヌ", "ネ", "ノ", "ハ", "ヒ", "フ", "ホ", "マ", "ミ", "ム",
|
||||
"メ", "モ", "ヤ", "ユ", "ヨ", "ラ", "ル", "レ", "ロ", "ワ", "ヲ", "ン", "ッ", "ャ", "ュ", "ョ",
|
||||
"ィ", "あ", "い", "う", "え", "お", "か", "き", "く", "け", "こ", "さ", "し", "す", "せ", "そ",
|
||||
"た", "ち", "つ", "て", "と", "な", "に", "ぬ", "ね", "の", "は", "ひ", "ふ", "へ", "ほ", "ま",
|
||||
"み", "む", "め", "も", "や", "ゆ", "よ", "ら", "り", "る", "れ", "ろ", "わ", "を", "ん", "っ",
|
||||
"ゃ", "ゅ", "ょ", "ー", "゜", "゛", "?", "!", "。", "ァ", "ゥ", "ェ", "▷", "▶", "▼", "♂",
|
||||
"円", "×", ".", "/", "ォ", "♀", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
|
||||
]
|
||||
bank_size = 0x4000
|
||||
|
||||
charmap = read_charmap()
|
||||
|
||||
if len(argv) != 4:
|
||||
print(f"Usage: {argv[0]} path/to/ROM.gb start_offset end_offset\noffsets are in the form bank:address (both hex), and end_offset is *not* included.")
|
||||
@@ -31,9 +17,9 @@ try:
|
||||
start_bank,start_addr = [ int(s, 16) for s in argv[2].split(':') ]
|
||||
end_bank, end_addr = [ int(s, 16) for s in argv[3].split(':') ]
|
||||
if start_bank != 0:
|
||||
start_addr += (start_bank - 1) * 0x4000
|
||||
start_addr += (start_bank - 1) * bank_size
|
||||
if end_bank != 0:
|
||||
end_addr += (end_bank - 1) * 0x4000
|
||||
end_addr += (end_bank - 1) * bank_size
|
||||
except Error:
|
||||
print("Please specify valid offsets (bank:address, both hex)")
|
||||
exit(1)
|
||||
@@ -41,10 +27,12 @@ except Error:
|
||||
|
||||
with open(argv[1], "rb") as f:
|
||||
f.seek(start_addr)
|
||||
|
||||
|
||||
string = ""
|
||||
while start_addr < end_addr:
|
||||
string += char_table[ int.from_bytes(f.read(1), "little") ]
|
||||
b = f.read(1)
|
||||
v = int.from_bytes(b, "little")
|
||||
string += char_table[ v ]
|
||||
start_addr += 1
|
||||
|
||||
|
||||
stdout.buffer.write( f"db \"{string}\"\n".encode('utf-8') )
|
||||
|
||||
43
tools/read_charmap.py
Normal file
43
tools/read_charmap.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import os, io
|
||||
|
||||
def parse_int(s):
|
||||
# assumes integers are literal; no +-*/, etc
|
||||
s = s.strip()
|
||||
if s.startswith('$'):
|
||||
return int(s[1:], 16)
|
||||
if s.startswith('%'):
|
||||
return int(s[1:], 2)
|
||||
return int(s)
|
||||
|
||||
def parse_string(s):
|
||||
# assumes strings are literal; no STRCAT() etc
|
||||
return s.strip('" ')
|
||||
|
||||
def strip_comment(s):
|
||||
# assumes ";" is not in the charmap
|
||||
return s.split(';')[0].rstrip()
|
||||
|
||||
def get_project_dir():
|
||||
script_path = os.path.realpath(__file__)
|
||||
script_dir = os.path.dirname(script_path)
|
||||
project_dir = os.path.join(script_dir, '..')
|
||||
return os.path.normpath(project_dir)
|
||||
|
||||
def get_charmap_path():
|
||||
project_dir = get_project_dir()
|
||||
return os.path.join(project_dir, 'charmap.asm')
|
||||
|
||||
def read_charmap():
|
||||
charmap_path = get_charmap_path()
|
||||
charmap = {}
|
||||
with io.open(charmap_path, 'r', encoding='utf-8') as f:
|
||||
lines = f.readlines()
|
||||
for line in lines:
|
||||
line = strip_comment(line).lstrip()
|
||||
if not line.startswith('charmap '):
|
||||
continue
|
||||
char, value = line[len('charmap '):].rsplit(',', 1)
|
||||
char = parse_string(char)
|
||||
value = parse_int(value)
|
||||
charmap[value] = char
|
||||
return charmap
|
||||
Reference in New Issue
Block a user