1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-12-05 17:25:58 +00:00
oot/tools/asmsplitter/asmsplitter.py

70 lines
1.8 KiB
Python
Raw Normal View History

2020-03-17 04:31:30 +00:00
import os
class FileEntry:
def __init__(self, nFuncName):
self.funcName = nFuncName
self.lines = list()
def ReadAllLines(filename):
with open(filename) as f:
lines = f.read().splitlines()
return lines;
def WriteAllLines(filename, lines):
with open(filename, 'w') as f:
for item in lines:
f.write("%s\n" % item)
return lines;
if not os.path.exists("asm"):
os.makedirs("asm")
if not os.path.exists("c"):
os.makedirs("c")
dirs = os.listdir("asm")
for directory in dirs:
if (os.path.isdir("asm//" + directory)):
2020-03-17 04:31:30 +00:00
continue
print("Processing asm//" + directory)
2020-03-17 04:31:30 +00:00
folderName = os.path.splitext(directory)[0]
lines = ReadAllLines("asm//" + directory)
2020-03-17 04:31:30 +00:00
functions = list()
currentFunction = None
for line in lines:
if (line.startswith("glabel")):
if (currentFunction != None):
functions.insert(len(functions), currentFunction)
currentFunction = FileEntry(line.split("glabel ")[1])
if (currentFunction != None):
currentFunction.lines.insert(len(currentFunction.lines), line)
if (currentFunction != None):
functions.insert(len(functions), currentFunction)
if not os.path.exists("asm//" + folderName):
os.makedirs("asm//" + folderName)
2020-03-17 04:31:30 +00:00
for func in functions:
WriteAllLines("asm//" + folderName + "//" + func.funcName + ".s", func.lines)
2020-03-17 04:31:30 +00:00
cLines = list()
cLines.insert(len(cLines), "#include <ultra64.h>")
cLines.insert(len(cLines), "#include <global.h>\n")
for func in functions:
cLines.insert(len(cLines), "#pragma GLOBAL_ASM(\"asm/non_matchings/code/" + folderName + "/" + func.funcName + ".s\")\n")
WriteAllLines("c//" + folderName + ".c", cLines)
2020-03-17 04:31:30 +00:00
print("Done!")