diff options
Diffstat (limited to 'extras')
-rw-r--r-- | extras/connection_helper.py | 51 | ||||
-rw-r--r-- | extras/replace_dimensions.py | 26 |
2 files changed, 54 insertions, 23 deletions
diff --git a/extras/connection_helper.py b/extras/connection_helper.py index 4c7e1ce0..e116347c 100644 --- a/extras/connection_helper.py +++ b/extras/connection_helper.py @@ -5,10 +5,16 @@ import extract_maps from pretty_map_headers import map_constants, map_name_cleaner, offset_to_pointer -def print_connections(map_id): +def print_connections(map_id, in_connection_id=None, do_output=False): map1 = extract_maps.map_headers[map_id] map1_name = map1["name"] connections = map1["connections"] + output = "" + + if in_connection_id != None: + connections2 = {} + connections2[in_connection_id] = connections[in_connection_id] + connections = connections2 for connection_id in connections: connection = connections[connection_id] @@ -24,11 +30,11 @@ def print_connections(map_id): map2_height = int(map2["y"], 16) map2_width = int(map2["x"], 16) - print map1_name + " (id=" + str(map_id) + ") " + direction + " to " + map2_name - print "map2 blocks pointer: " + hex(map2_blocks_pointer) - print "map2 height: " + str(map2_height) - print "map2 width: " + str(map2_width) - print "map1 connection pointer: " + hex(connected_pointer) + output += map1_name + " (id=" + str(map_id) + ") " + direction + " to " + map2_name + "\n" + output += "map2 blocks pointer: " + hex(map2_blocks_pointer) + "\n" + output += "map2 height: " + str(map2_height) + "\n" + output += "map2 width: " + str(map2_width) + "\n" + output += "map1 connection pointer: " + hex(connected_pointer) + "\n" shift = 0 #not sure about the calculated shift for NORTH or SOUTH @@ -38,7 +44,7 @@ def print_connections(map_id): if result != 0: shift = result #seems to always be 2? calculated = map2_blocks_pointer + (map2_height - 3) * map2_width + shift - print "shift: " + str(shift) + output += "shift: " + str(shift) + "\n" formula = map2_cname + "Blocks + (" + map2_cname + "Height - 3) * " + map2_cname + "Width + " + str(shift) else: formula = map2_cname + "Blocks + (" + map2_cname + "Height - 3) * " + map2_cname + "Width" @@ -49,36 +55,41 @@ def print_connections(map_id): if result != 0: shift = result calculated = map2_blocks_pointer + shift - print "shift: " + str(shift) - formula += " + " + str(shift) + output += "shift: " + str(shift) + "\n" + formula += "Blocks + " + str(shift) elif direction == "WEST": calculated = map2_blocks_pointer - 3 + (map2_width) result = connected_pointer - calculated - formula = map2_cname + " - 3 + (" + map2_cname + "Width)" + formula = map2_cname + "Blocks - 3 + (" + map2_cname + "Width)" if result != 0: shift = result / map2_width shift += 1 calculated = map2_blocks_pointer - 3 + (map2_width * shift) - print "shift: " + str(shift) - formula = map2_cname + " - 3 + (" + map2_cname + "Width * " + str(shift) + ")" + output += "shift: " + str(shift) + "\n" + formula = map2_cname + "Blocks - 3 + (" + map2_cname + "Width * " + str(shift) + ")" elif direction == "EAST": calculated = map2_blocks_pointer + (map2_width) result = connected_pointer - calculated - print ".. result is: " + str(result) - formula = map2_cname + " + (" + map2_cname + "Width)" + output += ".. result is: " + str(result) + "\n" + formula = map2_cname + "Blocks + (" + map2_cname + "Width)" if result != 0: shift = result / map2_width shift += 1 calculated = map2_blocks_pointer + (map2_width * shift) - print "shift: " + str(shift) - formula = map2_cname + " + (" + map2_cname + "Width * " + str(shift) + ")" + output += "shift: " + str(shift) + "\n" + formula = map2_cname + "Blocks" + " + (" + map2_cname + "Width * " + str(shift) + ")" - print "formula: " + formula + output += "formula: " + formula + "\n" result = connected_pointer - calculated - print "result: " + str(result) + output += "result: " + str(result) + "\n" - print "\n", + output += "\n\n" + + if in_connection_id != None: + return formula + if do_output == True: + return output if __name__ == "__main__": extract_maps.load_rom() @@ -91,4 +102,4 @@ if __name__ == "__main__": for map_id in extract_maps.map_headers.keys(): if map_id not in extract_maps.bad_maps: - print_connections(map_id) + print print_connections(map_id, do_output=True) diff --git a/extras/replace_dimensions.py b/extras/replace_dimensions.py index 86645e83..99692cce 100644 --- a/extras/replace_dimensions.py +++ b/extras/replace_dimensions.py @@ -4,7 +4,8 @@ #replace dimensions with constants import sys #for non-newline-terminated output :/ from add_map_labels_to_map_headers import find_with_start_of_line -from pretty_map_headers import map_name_cleaner, spacing +from pretty_map_headers import map_name_cleaner, spacing, offset_to_pointer, map_constants +from connection_helper import print_connections asm = None asm_lines = None @@ -23,7 +24,7 @@ def find_line_starting_with(value): id += 1 return False #not found -def replace_dimensions(): +def replace_values(): global asm_lines for map_id in extract_maps.map_headers.keys(): if map_id in extract_maps.bad_maps: continue #skip @@ -34,9 +35,28 @@ def replace_dimensions(): line_number = find_line_starting_with(label_name) if line_number == False: continue #skip, not found + #replace dimensions if necessary if "dimensions" in asm_lines[line_number + 2] and "$" in asm_lines[line_number + 2] and not "\t" in asm_lines[line_number+2]: asm_lines[line_number + 2] = spacing + "db " + clean_name + "Height, " + clean_name + "Width ; dimensions (y, x)" + #skip the rest of this if there are no connections + if len(map1["connections"]) == 0: continue + if not "; connections data" in asm_lines[line_number + 6]: continue + + connection_offset = line_number + 8 + + for connection_id in map1["connections"]: + if "dw $" in asm_lines[connection_offset + 1]: + formula = print_connections(map_id, in_connection_id=connection_id) + + temp_line = asm_lines[connection_offset + 1] + temp_line = spacing + "dw " + formula + temp_line[12:] + + asm_lines[connection_offset + 1] = temp_line + + connection_offset += 6 + + if __name__ == "__main__": import extract_maps extract_maps.load_rom() @@ -44,6 +64,6 @@ if __name__ == "__main__": extract_maps.read_all_map_headers() load_asm() - replace_dimensions() + replace_values() sys.stdout.write("\n".join(asm_lines)) |