shithub: pokered

Download patch

ref: be34aed58e24303a9d8dee6cf36009cbc2653568
parent: e5f9d4a1444d7a5dcb755ab1304b9be3ee4db6ed
author: Bryan Bishop <kanzure@gmail.com>
date: Tue Jan 17 09:54:06 EST 2012

fix some offset errors in insert_texts.py

hg-commit-id: b131d049ecd3


--- a/extras/analyze_incbins.py
+++ b/extras/analyze_incbins.py
@@ -235,7 +235,7 @@
 
     #confirm it's working
     try:
-        subprocess.check_call("cd ../; make clean; LC_CTYPE=UTF-8 make", shell=True)
+        subprocess.check_call("cd ../; make clean; LC_CTYPE=C make", shell=True)
         return True
     except Exception, exc:
         if try_fixing:
--- a/extras/analyze_texts.py
+++ b/extras/analyze_texts.py
@@ -496,6 +496,7 @@
             if first and needs_to_begin_with_0:
                 output += "$0, "
                 first = False
+                byte_count += 1
          
             quotes_open = False
             first_byte = True
@@ -550,7 +551,7 @@
     include_newline = "\n"
     if output[-1] == "\n":
         include_newline = ""
-    output += include_newline + "; " + hex(start_address + byte_count + 1)
+    output += include_newline + "; " + hex(start_address) + " + " + str(byte_count) + " bytes"
     print output
     return (output, byte_count)
 
--- a/extras/insert_texts.py
+++ b/extras/insert_texts.py
@@ -15,6 +15,19 @@
 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 @@
     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 @@
     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 @@
     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 @@
         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