summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan Bishop <kanzure@gmail.com>2012-01-15 15:45:09 -0600
committerBryan Bishop <kanzure@gmail.com>2012-01-15 15:45:09 -0600
commit1f1f31ff9cc45ffe1777d78975c0022d14233ab9 (patch)
treeb119cdf9a03f5f297721065e0ba8433150696052
parent1f38d74c65b9c5ccc9a792c7df73853fc64fbd55 (diff)
connection_helper - print out a formula for connection math
hg-commit-id: 27e8096bb251
-rw-r--r--common.asm2
-rw-r--r--extras/connection_helper.py94
-rw-r--r--extras/extract_maps.py2
3 files changed, 95 insertions, 3 deletions
diff --git a/common.asm b/common.asm
index c08c4b1a..5bc2e611 100644
--- a/common.asm
+++ b/common.asm
@@ -8138,7 +8138,7 @@ PalletTown_h:
db NORTH | SOUTH ; connections
db ROUTE_1
- dw $4192,$C6EB ; pointers
+ dw Route1Blocks + 150,$C6EB ; pointers
db $0A,$0A ; bigness, width
db $23,$00 ; alignments
dw $C809 ; window
diff --git a/extras/connection_helper.py b/extras/connection_helper.py
new file mode 100644
index 00000000..4c7e1ce0
--- /dev/null
+++ b/extras/connection_helper.py
@@ -0,0 +1,94 @@
+#!/usr/bin/python
+#author: Bryan Bishop <kanzure@gmail.com>
+#date: 2012-01-15
+#help with connection math
+import extract_maps
+from pretty_map_headers import map_constants, map_name_cleaner, offset_to_pointer
+
+def print_connections(map_id):
+ map1 = extract_maps.map_headers[map_id]
+ map1_name = map1["name"]
+ connections = map1["connections"]
+
+ for connection_id in connections:
+ connection = connections[connection_id]
+ direction = connection["direction"]
+ connected_pointer = int(connection["connected_map_tile_pointer"], 16)
+ current_pointer = int(connection["current_map_tile_pointer"], 16)
+ map2_id = connection["map_id"]
+ map2 = extract_maps.map_headers[map2_id]
+ map2_name = map2["name"]
+ map2_cname = map_name_cleaner(map2["name"], None)[:-2]
+ map2_bank = int(map2["bank"], 16)
+ map2_blocks_pointer = offset_to_pointer(int(map2["map_pointer"], 16))
+ 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)
+
+ shift = 0
+ #not sure about the calculated shift for NORTH or SOUTH
+ if direction == "NORTH":
+ calculated = map2_blocks_pointer + (map2_height - 3) * map2_width
+ result = connected_pointer - calculated
+ if result != 0:
+ shift = result #seems to always be 2?
+ calculated = map2_blocks_pointer + (map2_height - 3) * map2_width + shift
+ print "shift: " + str(shift)
+ 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"
+ elif direction == "SOUTH":
+ calculated = map2_blocks_pointer
+ result = connected_pointer - calculated
+ formula = map2_cname + "Blocks"
+ if result != 0:
+ shift = result
+ calculated = map2_blocks_pointer + shift
+ print "shift: " + str(shift)
+ formula += " + " + str(shift)
+ elif direction == "WEST":
+ calculated = map2_blocks_pointer - 3 + (map2_width)
+ result = connected_pointer - calculated
+ formula = map2_cname + " - 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) + ")"
+ elif direction == "EAST":
+ calculated = map2_blocks_pointer + (map2_width)
+ result = connected_pointer - calculated
+ print ".. result is: " + str(result)
+ formula = map2_cname + " + (" + 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) + ")"
+
+ print "formula: " + formula
+
+ result = connected_pointer - calculated
+ print "result: " + str(result)
+
+ print "\n",
+
+if __name__ == "__main__":
+ extract_maps.load_rom()
+ extract_maps.load_map_pointers()
+ extract_maps.read_all_map_headers()
+
+ #trouble:
+ #print_connections(13)
+ #print_connections(15)
+
+ for map_id in extract_maps.map_headers.keys():
+ if map_id not in extract_maps.bad_maps:
+ print_connections(map_id)
diff --git a/extras/extract_maps.py b/extras/extract_maps.py
index 25a6ee9c..81a64bf6 100644
--- a/extras/extract_maps.py
+++ b/extras/extract_maps.py
@@ -560,8 +560,6 @@ def get_direction(connection_byte, connection_id):
#prune results
while "" in results:
results.remove("")
- print results
- print "connection_id is: " + str(connection_id) + " and byte is: " + hex(connection_byte)
return results[connection_id]
def read_map_header(address, bank):