More example lines

This commit is contained in:
Remy Oukaour 2018-01-03 15:41:15 -05:00
parent 78c818e4c9
commit 83f7400671
1 changed files with 18 additions and 17 deletions

View File

@ -43,8 +43,8 @@ def map_to_sym(input):
bank_type = None bank_type = None
bank_number = None bank_number = None
bank_size = 0 bank_size = 0
bank_queue = [] bank_lines = []
section_queue = [] section_lines = []
for line in input: for line in input:
@ -58,8 +58,8 @@ def map_to_sym(input):
bank_type = x.group(1) bank_type = x.group(1)
bank_number = '00' bank_number = '00'
bank_size = 0 bank_size = 0
del bank_queue[:] del bank_lines[:]
del section_queue[:] del section_lines[:]
continue continue
x = re.match(bank_rx, line) x = re.match(bank_rx, line)
@ -72,22 +72,23 @@ def map_to_sym(input):
if bank_type == 'WRAM': if bank_type == 'WRAM':
bank_type = 'WRAM0' if bank_number == '00' else 'WRAMX' bank_type = 'WRAM0' if bank_number == '00' else 'WRAMX'
bank_size = 0 bank_size = 0
del bank_queue[:] del bank_lines[:]
del section_queue[:] del section_lines[:]
continue continue
x = re.match(section_rx, line) x = re.match(section_rx, line)
if x: if x:
# finish current section # finish current section
bank_queue.extend(sorted(section_queue)) bank_lines.extend(sorted(section_lines))
# start a new section # start a new section
start = x.group(1) start = x.group(1)
end = x.group(2) or start end = x.group(2) or start
size = x.group(3).zfill(4) size = x.group(3).zfill(4)
name = x.group(4) name = x.group(4)
bank_size += int(size, 16) bank_size += int(size, 16)
bank_queue.append('; %s:%s-%s ($%s) %s\n' % (bank_number, start, end, size, name)) # ex: ; ROMX $01 ($347B) ($0B85 free)
del section_queue[:] bank_lines.append('; %s:%s-%s ($%s) %s\n' % (bank_number, start, end, size, name))
del section_lines[:]
continue continue
x = re.match(label_rx, line) x = re.match(label_rx, line)
@ -95,17 +96,19 @@ def map_to_sym(input):
# add label to section # add label to section
address = x.group(1) address = x.group(1)
label = x.group(2) label = x.group(2)
section_queue.append('%s:%s %s\n' % (bank_number, address, label)) # ex: 01:4025 PlaceWaitingText.Waiting
section_lines.append('%s:%s %s\n' % (bank_number, address, label))
continue continue
x = re.match(slack_rx, line) x = re.match(slack_rx, line)
if x: if x:
# finish current section # finish current section
bank_queue.extend(sorted(section_queue)) bank_lines.extend(sorted(section_lines))
# finish current bank # finish current bank
slack = int(x.group(1), 16) slack = int(x.group(1), 16)
# ex: ; 01:4000-747A ($347B) bank1
yield '; %s $%s ($%04X) ($%04X free)\n' % (bank_type, bank_number, bank_size, slack) yield '; %s $%s ($%04X) ($%04X free)\n' % (bank_type, bank_number, bank_size, slack)
for line in bank_queue: for line in bank_lines:
yield line yield line
continue continue
@ -113,12 +116,10 @@ def main():
if len(sys.argv) < 3: if len(sys.argv) < 3:
sys.stderr.write('Usage: %s pokecrystal.map sorted.sym\n' % sys.argv[0]) sys.stderr.write('Usage: %s pokecrystal.map sorted.sym\n' % sys.argv[0])
sys.exit(1) sys.exit(1)
input_filename = sys.argv[1] with open(sys.argv[1], 'r') as infile:
output_filename = sys.argv[2]
with open(input_filename, 'r') as infile:
input = infile.readlines() input = infile.readlines()
output = map_to_sym(input) output = map_to_sym(input)
with open(output_filename, 'w') as outfile: with open(sys.argv[2], 'w') as outfile:
outfile.writelines(output) outfile.writelines(output)
if __name__ == '__main__': if __name__ == '__main__':