mirror of https://github.com/pret/pokecrystal.git
better graph-generating routines
This commit is contained in:
parent
fcf43b13da
commit
85d26e31a5
|
@ -28,7 +28,7 @@ class RomGraph(nx.DiGraph):
|
||||||
start_address = 0x150
|
start_address = 0x150
|
||||||
|
|
||||||
# and where is a good place to stop?
|
# and where is a good place to stop?
|
||||||
end_address = 0x4000 * 0x01 # only do the first bank? sure..
|
end_address = 0x4000 * 0x03 # only do the first bank? sure..
|
||||||
|
|
||||||
# where is the rom stored?
|
# where is the rom stored?
|
||||||
rompath = "../baserom.gbc"
|
rompath = "../baserom.gbc"
|
||||||
|
@ -68,10 +68,10 @@ class RomGraph(nx.DiGraph):
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
if count > 100:
|
if count > 3000:
|
||||||
break
|
break
|
||||||
|
|
||||||
if address < self.end_address and address not in functions.keys():
|
if address < self.end_address and (address not in functions.keys()) and address >= 0x150:
|
||||||
# address is okay to parse at, keep going
|
# address is okay to parse at, keep going
|
||||||
pass
|
pass
|
||||||
elif len(other_addresses) > 0:
|
elif len(other_addresses) > 0:
|
||||||
|
@ -84,6 +84,17 @@ class RomGraph(nx.DiGraph):
|
||||||
# parse the asm
|
# parse the asm
|
||||||
func = self.rom.to_asm(address)
|
func = self.rom.to_asm(address)
|
||||||
|
|
||||||
|
# check if there are any nops (probably not a function)
|
||||||
|
nops = 0
|
||||||
|
for (id, command) in func.asm_commands.items():
|
||||||
|
if command.has_key("id") and command["id"] == 0x0:
|
||||||
|
nops += 1
|
||||||
|
|
||||||
|
# skip this function
|
||||||
|
if nops > 1:
|
||||||
|
address = 0
|
||||||
|
continue
|
||||||
|
|
||||||
# store this parsed function
|
# store this parsed function
|
||||||
functions[address] = func
|
functions[address] = func
|
||||||
|
|
||||||
|
@ -97,7 +108,8 @@ class RomGraph(nx.DiGraph):
|
||||||
other_addresses.update([used_address])
|
other_addresses.update([used_address])
|
||||||
|
|
||||||
# add this other address to the graph
|
# add this other address to the graph
|
||||||
self.add_node(used_address)
|
if used_address > 100:
|
||||||
|
self.add_node(used_address)
|
||||||
|
|
||||||
# add this as an edge between the two nodes
|
# add this as an edge between the two nodes
|
||||||
self.add_edge(address, used_address)
|
self.add_edge(address, used_address)
|
||||||
|
@ -120,10 +132,15 @@ class RomGraph(nx.DiGraph):
|
||||||
"""
|
"""
|
||||||
import networkx.readwrite.json_graph as json_graph
|
import networkx.readwrite.json_graph as json_graph
|
||||||
content = json_graph.dumps(self)
|
content = json_graph.dumps(self)
|
||||||
fh = open("graphs.json", "w")
|
fh = open("crystal/crystal.json", "w")
|
||||||
fh.write(content)
|
fh.write(content)
|
||||||
fh.close()
|
fh.close()
|
||||||
|
|
||||||
|
def to_gephi(self):
|
||||||
|
""" Generates a gexf file.
|
||||||
|
"""
|
||||||
|
nx.write_gexf(self, "graph.gexf")
|
||||||
|
|
||||||
class RedGraph(RomGraph):
|
class RedGraph(RomGraph):
|
||||||
""" Not implemented. Go away.
|
""" Not implemented. Go away.
|
||||||
"""
|
"""
|
||||||
|
@ -140,4 +157,4 @@ class CryGraph(RomGraph):
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
crygraph = CryGraph()
|
crygraph = CryGraph()
|
||||||
crygraph.pretty_printer()
|
crygraph.pretty_printer()
|
||||||
crygraph.to_d3()
|
crygraph.to_gephi()
|
||||||
|
|
Loading…
Reference in New Issue