summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--extras/analyze_incbins.py1
-rw-r--r--extras/gbz80disasm.py14
-rw-r--r--extras/insert_texts.py14
3 files changed, 20 insertions, 9 deletions
diff --git a/extras/analyze_incbins.py b/extras/analyze_incbins.py
index 4ffd5ec6..7f748d47 100644
--- a/extras/analyze_incbins.py
+++ b/extras/analyze_incbins.py
@@ -234,6 +234,7 @@ def apply_diff(diff):
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
diff --git a/extras/gbz80disasm.py b/extras/gbz80disasm.py
index 041531cf..e237441d 100644
--- a/extras/gbz80disasm.py
+++ b/extras/gbz80disasm.py
@@ -538,8 +538,6 @@ end_08_scripts_with = [
]
relative_jumps = [0x38, 0x30, 0x20, 0x28, 0x18]
-byte_labels = {}
-
def random_asm_label():
return ".ASM_" + random_hash()
@@ -558,6 +556,8 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000):
#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 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000):
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 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000):
#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 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000):
current_byte_number += 1
offset += 1
+ insertion = ""
current_byte_number += 1
offset += 1
@@ -685,10 +686,11 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000):
#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 @@ if __name__ == "__main__":
#0x18f96 is PalletTownText1
#0x19B5D is BluesHouseText1
- print output_bank_opcodes(0x19B5D + 1)
+ print output_bank_opcodes(0x1e374 + 1)
diff --git a/extras/insert_texts.py b/extras/insert_texts.py
index bc2feca6..75be89a6 100644
--- a/extras/insert_texts.py
+++ b/extras/insert_texts.py
@@ -13,6 +13,7 @@ import os, sys
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 @@ def insert_08_asm(map_id, text_id):
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,7 +318,10 @@ def insert_08_asm(map_id, text_id):
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 = []
@@ -333,6 +337,7 @@ def insert_all_08s():
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 @@ if __name__ == "__main__":
#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)