From e5f9d4a1444d7a5dcb755ab1304b9be3ee4db6ed Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Tue, 17 Jan 2012 13:34:51 -0600 Subject: text insertion code for unnamed TX_FARs These TX_FARs are found in ASM inside INCBIN intervals, and as a consequence do not have good names. Someone will have to review the naming. Note that these texts may or may not be referenced in scripts that will eventually be imported. Some of these are raw texts that could be completely unreferenced, but so far that doesn't look like the case. hg-commit-id: 47239e73071a --- extras/insert_texts.py | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) (limited to 'extras/insert_texts.py') diff --git a/extras/insert_texts.py b/extras/insert_texts.py index 7a61e854..dc7f872c 100644 --- a/extras/insert_texts.py +++ b/extras/insert_texts.py @@ -1,9 +1,9 @@ #!/usr/bin/python2.7 #author: Bryan Bishop -#date: 2012-01-07 +#date: 2012-01-07, 2012-01-17 #insert TX_FAR targets into pokered.asm import extract_maps -from analyze_texts import analyze_texts, text_pretty_printer_at +from analyze_texts import analyze_texts, text_pretty_printer_at, scan_rom_for_tx_fars from pretty_map_headers import map_name_cleaner, make_text_label, map_constants, find_all_tx_fars, tx_far_pretty_printer, tx_far_label_maker import pretty_map_headers from analyze_incbins import asm, offset_to_pointer, find_incbin_to_replace_for, split_incbin_line_into_three, generate_diff_insert, load_asm, isolate_incbins, process_incbins, reset_incbins, apply_diff @@ -396,7 +396,7 @@ def insert_asm(start_address, label, text_asm=None, end_address=None): result = apply_diff(diff, try_fixing=True) return True -def insert_text(address, label): +def insert_text(address, label, apply=False): "inserts a text script (but not $8s)" start_address = address @@ -427,7 +427,10 @@ def insert_text(address, label): diff = generate_diff_insert(line_number, newlines) print diff - #apply_diff(diff) + if apply: + return apply_diff(diff) + else: #simulate a successful insertion + return True #move this into another file? def scan_for_map_scripts_pointer(): @@ -586,6 +589,23 @@ def scan_for_map_scripts_pointer(): print script_asm sys.exit(0) +def scan_rom_for_tx_fars_and_insert(): + """calls analyze_texts.scan_rom_for_tx_fars() + looks through INCBIN'd addresses from common.asm, + finds TX_FARs that aren't included yet. + """ + address_bundles = scan_rom_for_tx_fars(printer=True) + for address_bundle in address_bundles: + tx_far_address = address_bundle[1] + tx_far_target_address = address_bundle[0] + + tx_far_label = "UnnamedText_%.2x" % (tx_far_address) + tx_far_target_label = "_" + tx_far_label + + result = insert_text(tx_far_target_address, tx_far_target_label, apply=True) + if result: + result2 = insert_text(tx_far_address, tx_far_label, apply=True) + if __name__ == "__main__": #load map headers and object data extract_maps.load_rom() @@ -593,15 +613,16 @@ if __name__ == "__main__": extract_maps.read_all_map_headers() #load texts (these two have different formats) - all_texts = pretty_map_headers.analyze_texts.analyze_texts() - pretty_map_headers.all_texts = all_texts - tx_fars = pretty_map_headers.find_all_tx_fars() + #all_texts = pretty_map_headers.analyze_texts.analyze_texts() + #pretty_map_headers.all_texts = all_texts + #tx_fars = pretty_map_headers.find_all_tx_fars() #load incbins reset_incbins() #scan_for_map_scripts_pointer() - insert_text(0xa586b, "_VermilionCityText14") + scan_rom_for_tx_fars_and_insert() + #insert_text(0xa586b, "_VermilionCityText14") #insert _ViridianCityText10 #insert_tx_far(1, 10) -- cgit v1.2.3 From be34aed58e24303a9d8dee6cf36009cbc2653568 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Tue, 17 Jan 2012 14:54:06 -0600 Subject: fix some offset errors in insert_texts.py hg-commit-id: b131d049ecd3 --- extras/insert_texts.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'extras/insert_texts.py') diff --git a/extras/insert_texts.py b/extras/insert_texts.py index dc7f872c..8438127e 100644 --- a/extras/insert_texts.py +++ b/extras/insert_texts.py @@ -15,6 +15,19 @@ spacing = " " tx_fars = None failed_attempts = {} +def local_reset_incbins(): + asm = None + incbin_lines = [] + processed_incbins = {} + analyze_incbins.asm = None + analyze_incbins.incbin_lines = [] + analyze_incbins.processed_incbins = {} + + #reload + load_asm() + isolate_incbins() + process_incbins() + def find_tx_far_entry(map_id, text_id): for tx_far_line in tx_fars: if tx_far_line[0] == map_id and tx_far_line[1] == text_id: @@ -396,7 +409,7 @@ def insert_asm(start_address, label, text_asm=None, end_address=None): result = apply_diff(diff, try_fixing=True) return True -def insert_text(address, label, apply=False): +def insert_text(address, label, apply=False, try_fixing=True): "inserts a text script (but not $8s)" start_address = address @@ -428,7 +441,7 @@ def insert_text(address, label, apply=False): diff = generate_diff_insert(line_number, newlines) print diff if apply: - return apply_diff(diff) + return apply_diff(diff, try_fixing=try_fixing) else: #simulate a successful insertion return True @@ -594,6 +607,7 @@ def scan_rom_for_tx_fars_and_insert(): looks through INCBIN'd addresses from common.asm, finds TX_FARs that aren't included yet. """ + x = 0 address_bundles = scan_rom_for_tx_fars(printer=True) for address_bundle in address_bundles: tx_far_address = address_bundle[1] @@ -603,8 +617,12 @@ def scan_rom_for_tx_fars_and_insert(): tx_far_target_label = "_" + tx_far_label result = insert_text(tx_far_target_address, tx_far_target_label, apply=True) + local_reset_incbins() if result: result2 = insert_text(tx_far_address, tx_far_label, apply=True) + if not result or not result2: + sys.exit(0) + local_reset_incbins() if __name__ == "__main__": #load map headers and object data -- cgit v1.2.3 From a6f495e25ee25453be690c31f0317e32751ac378 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Tue, 17 Jan 2012 15:31:04 -0600 Subject: fix insert_texts for pre-existing TX_FAR target labels hg-commit-id: b506eecb191a --- extras/insert_texts.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'extras/insert_texts.py') diff --git a/extras/insert_texts.py b/extras/insert_texts.py index 8438127e..53ff4841 100644 --- a/extras/insert_texts.py +++ b/extras/insert_texts.py @@ -416,7 +416,7 @@ def insert_text(address, label, apply=False, try_fixing=True): line_number = find_incbin_to_replace_for(start_address) if line_number == None: print "skipping text at " + hex(start_address) + " with address " + label - return + return "skip" text_asm, byte_count = text_pretty_printer_at(start_address, label) end_address = start_address + byte_count @@ -612,17 +612,32 @@ def scan_rom_for_tx_fars_and_insert(): for address_bundle in address_bundles: tx_far_address = address_bundle[1] tx_far_target_address = address_bundle[0] + if tx_far_address < 0x6150f: continue tx_far_label = "UnnamedText_%.2x" % (tx_far_address) tx_far_target_label = "_" + tx_far_label - result = insert_text(tx_far_target_address, tx_far_target_label, apply=True) - local_reset_incbins() - if result: + #let's also do a quick check if it might be in the file already + if not (": ; " + hex(tx_far_address) in analyze_incbins.asm): + result = insert_text(tx_far_target_address, tx_far_target_label, apply=True) + else: + #we can't just pretend like it worked, because we don't know what label was used + #so, figure out the label + for line in analyze_incbins.asm_lines: + if ": ; " + hex(tx_far_address) in line: + tx_far_target_label = line.split(":")[0] + result = "skip" + + if result == True: + local_reset_incbins() result2 = insert_text(tx_far_address, tx_far_label, apply=True) + local_reset_incbins() + elif result == "skip": + result2 = insert_text(tx_far_address, tx_far_label, apply=True) + local_reset_incbins() + if not result or not result2: sys.exit(0) - local_reset_incbins() if __name__ == "__main__": #load map headers and object data -- cgit v1.2.3 From ffdd92db777e410a0c365f7b301f0a5a5bdc56ca Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Tue, 17 Jan 2012 15:39:36 -0600 Subject: skip some incbins from analyze_texts for 0-size intervals hg-commit-id: a63d92b4534c --- extras/insert_texts.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'extras/insert_texts.py') diff --git a/extras/insert_texts.py b/extras/insert_texts.py index 53ff4841..d358db97 100644 --- a/extras/insert_texts.py +++ b/extras/insert_texts.py @@ -418,6 +418,12 @@ def insert_text(address, label, apply=False, try_fixing=True): print "skipping text at " + hex(start_address) + " with address " + label return "skip" + #another reason to skip is if the interval is 0 + processed_incbin = analyze_incbins.processed_incbins[line_number] + if processed_incbin["interval"] == 0: + print "skipping text at " + hex(start_address) + " with address " + label + " because the interval is 0" + return "skip" + text_asm, byte_count = text_pretty_printer_at(start_address, label) end_address = start_address + byte_count newlines = split_incbin_line_into_three(line_number, start_address, byte_count) @@ -612,7 +618,7 @@ def scan_rom_for_tx_fars_and_insert(): for address_bundle in address_bundles: tx_far_address = address_bundle[1] tx_far_target_address = address_bundle[0] - if tx_far_address < 0x6150f: continue + #if tx_far_address < 0x7627b: continue #because it stopped a few times for errors tx_far_label = "UnnamedText_%.2x" % (tx_far_address) tx_far_target_label = "_" + tx_far_label -- cgit v1.2.3 From b8100083ca8c8eda59f9fea200592cf81d5494a7 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Tue, 17 Jan 2012 20:37:55 -0600 Subject: insert many many more texts hg-commit-id: 50dfe24e0bad --- extras/insert_texts.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'extras/insert_texts.py') diff --git a/extras/insert_texts.py b/extras/insert_texts.py index d358db97..6d7b7b6d 100644 --- a/extras/insert_texts.py +++ b/extras/insert_texts.py @@ -618,6 +618,7 @@ def scan_rom_for_tx_fars_and_insert(): for address_bundle in address_bundles: tx_far_address = address_bundle[1] tx_far_target_address = address_bundle[0] + if tx_far_address in [0xeff2]: continue #skip #if tx_far_address < 0x7627b: continue #because it stopped a few times for errors tx_far_label = "UnnamedText_%.2x" % (tx_far_address) @@ -625,6 +626,7 @@ def scan_rom_for_tx_fars_and_insert(): #let's also do a quick check if it might be in the file already if not (": ; " + hex(tx_far_address) in analyze_incbins.asm): + print "inserting text at " + hex(tx_far_address) result = insert_text(tx_far_target_address, tx_far_target_label, apply=True) else: #we can't just pretend like it worked, because we don't know what label was used @@ -634,16 +636,18 @@ def scan_rom_for_tx_fars_and_insert(): tx_far_target_label = line.split(":")[0] result = "skip" - if result == True: + if result == True or result == None: local_reset_incbins() result2 = insert_text(tx_far_address, tx_far_label, apply=True) local_reset_incbins() elif result == "skip": - result2 = insert_text(tx_far_address, tx_far_label, apply=True) - local_reset_incbins() + print "skipping " + hex(tx_far_address) + # result2 = insert_text(tx_far_address, tx_far_label, apply=True) + # local_reset_incbins() - if not result or not result2: - sys.exit(0) + #just skip these for now + #if not result or not result2: + # sys.exit(0) if __name__ == "__main__": #load map headers and object data -- cgit v1.2.3