mirror of
https://github.com/thornAvery/kep-hack.git
synced 2025-09-17 02:40:50 +12:00
insert_asm in insert_texts for function asm
hg-commit-id: dc34a93f0f47
This commit is contained in:
parent
983b87069d
commit
4c59064f9f
|
@ -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__":
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue