ref: c7331ebd19b97b07bd019e6d4c05a232830c19c8
parent: 52e723ae656a1b8584f6624b9c0551d3c51ff393
author: Bryan Bishop <[email protected]>
date: Mon Jan 9 18:12:28 EST 2012
updates to asm injection code hg-commit-id: 6748c9773b32
--- a/extras/analyze_incbins.py
+++ b/extras/analyze_incbins.py
@@ -234,6 +234,7 @@
subprocess.check_call("cd ../; make clean; LC_CTYPE=UTF-8 make", shell=True)
except Exception, exc:
os.system("mv ../pokered1.asm ../pokered.asm")
+ return False
if __name__ == "__main__":
#load map headers
--- a/extras/gbz80disasm.py
+++ b/extras/gbz80disasm.py
@@ -538,8 +538,6 @@
]
relative_jumps = [0x38, 0x30, 0x20, 0x28, 0x18]
-byte_labels = {}
-
def random_asm_label():
return ".ASM_" + random_hash()
@@ -558,6 +556,8 @@
#we don't actually have an end address, but we'll just say $4000
end_address = original_offset + max_byte_count
+
+ byte_labels = {}
output = ""
keep_reading = True
@@ -576,7 +576,7 @@
line_label = random_asm_label()
byte_labels[offset] = {}
byte_labels[offset]["name"] = line_label
- byte_labels[offset]["usage"] = 1
+ byte_labels[offset]["usage"] = 0
output += line_label + " ; " + hex(offset) + "\n"
#find out if there's a two byte key like this
@@ -616,7 +616,7 @@
#generate a label for the byte we're jumping to
target_address = offset + 2 + ord(rom[offset + 1])
if target_address in byte_labels.keys():
- byte_labels[target_address]["usage"] += 1
+ byte_labels[target_address]["usage"] = 1 + byte_labels[target_address]["usage"]
line_label2 = byte_labels[target_address]["name"]
else:
line_label2 = random_asm_label()
@@ -634,6 +634,7 @@
current_byte_number += 1
offset += 1
+ insertion = ""
current_byte_number += 1
offset += 1
@@ -685,10 +686,11 @@
#current_byte_number += 1
#clean up unused labels
+ print "byte_labels is: " + str(byte_labels)
for label_line in byte_labels.keys():
address = label_line
label_line = byte_labels[label_line]
- if label_line["usage"] == 1:
+ if label_line["usage"] == 0:
output = output.replace(label_line["name"] + " ; " + hex(address) + "\n", "")
return (output.lower(), offset)
@@ -710,4 +712,4 @@
#0x18f96 is PalletTownText1
#0x19B5D is BluesHouseText1
- print output_bank_opcodes(0x19B5D + 1)
+ print output_bank_opcodes(0x1e374 + 1)
--- a/extras/insert_texts.py
+++ b/extras/insert_texts.py
@@ -13,6 +13,7 @@
import subprocess
spacing = " "
tx_fars = None
+failed_attempts = {}
def find_tx_far_entry(map_id, text_id):
for tx_far_line in tx_fars:
@@ -294,7 +295,7 @@
return
#also do a name check
- if 1 < ("\n".join(analyze_incbins.asm)).count(label + ":"):
+ if 1 <= ("\n".join(analyze_incbins.asm)).count("\n" + label + ":"):
print "skipping text label for a $08 on map_id=" + str(map_id) + " text_id=" + str(text_id) + " because the label is already taken (" + label + ":)"
return
@@ -317,8 +318,11 @@
diff = generate_diff_insert(line_number, newlines)
print "working on map_id=" + str(map_id) + " text_id=" + str(text_id)
print diff
- apply_diff(diff)
+ result = apply_diff(diff)
+ if result == False:
+ failed_attempts[len(failed_attempts.keys())] = {"map_id": map_id, "text_id": text_id}
+
def find_all_08s():
all_08s = []
for map_id in all_texts:
@@ -333,6 +337,7 @@
all_08s = find_all_08s()
for the_08_line in all_08s:
map_id = the_08_line[0]
+ if map_id <= 86: continue #speed things up
text_id = the_08_line[1]
print "processing map_id=" + str(map_id) + " text_id=" + str(text_id)
@@ -386,5 +391,8 @@
#insert_text_label_tx_far(240, 1)
#insert_all_text_labels()
- #insert_08_asm(1, 2)
+ #insert_08_asm(83, 1)
insert_all_08s()
+
+ print "-- FAILED ATTEMPTS --"
+ print str(failed_attempts)