ref: 4c59064f9f65eabbf72c247d78d5607ce1b5409f
parent: 983b87069d1037bb4ad4eedb2ef769c398e0d084
author: Bryan Bishop <kanzure@gmail.com>
date: Mon Jan 9 20:18:18 EST 2012
insert_asm in insert_texts for function asm hg-commit-id: dc34a93f0f47
--- a/extras/analyze_incbins.py
+++ b/extras/analyze_incbins.py
@@ -214,7 +214,7 @@
isolate_incbins()
process_incbins()
-def apply_diff(diff):
+def apply_diff(diff, try_fixing=True):
print "... Applying diff."
#write the diff to a file
@@ -233,7 +233,8 @@
try:
subprocess.check_call("cd ../; make clean; LC_CTYPE=UTF-8 make", shell=True)
except Exception, exc:
- os.system("mv ../pokered1.asm ../pokered.asm")
+ if try_fixing:
+ os.system("mv ../pokered1.asm ../pokered.asm")
return False
if __name__ == "__main__":
--- a/extras/gbz80disasm.py
+++ b/extras/gbz80disasm.py
@@ -694,10 +694,11 @@
return (output.lower(), offset)
-def text_asm_pretty_printer(label, address_of_08):
+def text_asm_pretty_printer(label, address_of_08, include_08=True):
"""returns (output, end_address)"""
output = label + ": ; " + hex(address_of_08) + "\n"
- output += spacing + "db $08 ; asm\n"
+ if include_08:
+ output += spacing + "db $08 ; asm\n"
results = output_bank_opcodes(address_of_08 + 1)
output += results[0]
end_address = results[1]
@@ -711,4 +712,4 @@
#0x18f96 is PalletTownText1
#0x19B5D is BluesHouseText1
- print output_bank_opcodes(0x3748)[0]
+ print output_bank_opcodes(0x3e48)[0]
--- a/extras/insert_texts.py
+++ b/extras/insert_texts.py
@@ -357,6 +357,36 @@
isolate_incbins()
process_incbins()
+def insert_asm(start_address, label):
+ (text_asm, end_address) = text_asm_pretty_printer(label, start_address, include_08=False)
+ print "end address is: " + hex(end_address)
+
+ #find where to insert the assembly
+ line_number = find_incbin_to_replace_for(start_address)
+ if line_number == None:
+ print "skipping asm because the address is taken"
+ return
+
+ newlines = split_incbin_line_into_three(line_number, start_address, end_address - start_address )
+
+ newlines = newlines.split("\n")
+ if len(newlines) == 2: index = 0 #replace the 1st line with new content
+ elif len(newlines) == 3: index = 1 #replace the 2nd line with new content
+
+ newlines[index] = text_asm
+
+ if len(newlines) == 3 and newlines[2][-2:] == "$0":
+ #get rid of the last incbin line if it is only including 0 bytes
+ del newlines[2]
+ #note that this has to be done after adding in the new asm
+ newlines = "\n".join(line for line in newlines)
+
+ newlines = newlines.replace("$x", "$")
+
+ diff = generate_diff_insert(line_number, newlines)
+ print diff
+ result = apply_diff(diff, try_fixing=False)
+
if __name__ == "__main__":
#load map headers and object data
extract_maps.load_rom()
@@ -392,7 +422,9 @@
#insert_all_text_labels()
#insert_08_asm(83, 1)
- insert_all_08s()
+ #insert_all_08s()
+
+ insert_asm(0x3e48, "GivePokemon")
print "-- FAILED ATTEMPTS --"
print str(failed_attempts)