diff options
author | Bryan Bishop <kanzure@gmail.com> | 2012-01-10 01:18:18 -0600 |
---|---|---|
committer | Bryan Bishop <kanzure@gmail.com> | 2012-01-10 01:18:18 -0600 |
commit | 4c59064f9f65eabbf72c247d78d5607ce1b5409f (patch) | |
tree | ac92fcadf5f0521ae851ffaca81b1b0875aed859 | |
parent | 983b87069d1037bb4ad4eedb2ef769c398e0d084 (diff) |
insert_asm in insert_texts for function asm
hg-commit-id: dc34a93f0f47
-rw-r--r-- | extras/analyze_incbins.py | 5 | ||||
-rw-r--r-- | extras/gbz80disasm.py | 7 | ||||
-rw-r--r-- | extras/insert_texts.py | 34 |
3 files changed, 40 insertions, 6 deletions
diff --git a/extras/analyze_incbins.py b/extras/analyze_incbins.py index 7f748d47..4d0c3fce 100644 --- a/extras/analyze_incbins.py +++ b/extras/analyze_incbins.py @@ -214,7 +214,7 @@ def reset_incbins(): 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 @@ def apply_diff(diff): 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__": diff --git a/extras/gbz80disasm.py b/extras/gbz80disasm.py index 43e93715..c9f9602e 100644 --- a/extras/gbz80disasm.py +++ b/extras/gbz80disasm.py @@ -694,10 +694,11 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000): 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 @@ if __name__ == "__main__": #0x18f96 is PalletTownText1 #0x19B5D is BluesHouseText1 - print output_bank_opcodes(0x3748)[0] + print output_bank_opcodes(0x3e48)[0] diff --git a/extras/insert_texts.py b/extras/insert_texts.py index 75be89a6..1e190545 100644 --- a/extras/insert_texts.py +++ b/extras/insert_texts.py @@ -357,6 +357,36 @@ def insert_all_08s(): 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 @@ if __name__ == "__main__": #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) |