forked from Decompollaborate/zelda64_compare
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstruct_spec.py
executable file
·59 lines (41 loc) · 1.7 KB
/
construct_spec.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
import sys
import csv
import argparse
def printf(fmt, *args, **kwargs):
print(fmt.format(*args), end="", **kwargs)
def fprintf(file, *args, **kwargs):
printf(*args, file=file, **kwargs)
def constructSpec(dmadataFile, outFile):
with open(dmadataFile, "r") as f:
dmadata = list(csv.reader(f))
# dmaTable = []
# for entry in dmadata:
# dmaTable.append(entry)
print("/*\n * ROM spec file\n */\n", file=outFile)
i = 0
while i < len(dmadata):
entry = dmadata[i]
print("beginseg", file=outFile)
print(" name \"" + entry[0] + "\"", file=outFile)
if int(entry[4],16) != 0:
print(" compress", file=outFile)
if ((int(entry[1],16) % 0x1000 == 0) and ((i == len(dmadata) - 1) or (int(dmadata[i+1][1],16) % 0x1000 == 0))):
print(" romalign 0x1000", file=outFile)
print(" include \"build/baserom/" + entry[0] + ".o\"", file=outFile )
print("endseg", file=outFile)
print("", file=outFile)
i += 1
def main():
description = "Construct a basic spec from dmadata"
parser = argparse.ArgumentParser(description=description, formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("dmadataFile", help="dmadata file to read")
parser.add_argument("--outFile", help="File to write to", default=sys.stdout)
args = parser.parse_args()
if args.outFile != sys.stdout:
with open(args.outFile, "w") as f:
constructSpec(args.dmadataFile, f)
else:
constructSpec(args.dmadataFile, args.outFile)
if __name__ == "__main__":
main()