summaryrefslogtreecommitdiff
path: root/extras/add_map_labels_to_map_headers.py
blob: 89e6f361bb13cad49ff23c8d697c96625a357024 (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
#author: Bryan Bishop <kanzure@gmail.com>
#date: 2011-01-04
#purpose: insert labels into map headers
import sys

asm = None
asm_lines = []
def load_asm():
    global asm, asm_lines
    asm = open("../pokered.asm", "r").read()
    asm_lines = asm.split("\n")

def find_with_start_of_line(name):
    global asm_lines
    for line in asm_lines:
        if len(line) > len(name) and ": " in line:
            if line[:len(name)] == name: return True
    return False

def process_lines():
    global asm, asm_lines
    for line in asm_lines:
        if not "_h:" in line: continue #skip
        index = asm_lines.index(line)
        name = line.split("_h:")[0]

        if "Blocks" in asm_lines[index+3]: continue #skip, already done
        #if not (str(name + "Blocks:") in asm): continue #skip, no block label found
        if not find_with_start_of_line(name + "Blocks:"): continue #skip

        orig_line = asm_lines[index+3]
        fixed_line = orig_line.split(",")
        fixed_line[0] = "    dw " + name + "Blocks"
        fixed_line = ",".join(fixed_line)

        asm_lines[index+3] = fixed_line

if __name__ == "__main__":
    load_asm()
    process_lines()
    sys.stdout.write("\n".join(asm_lines))