-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare_build.py
121 lines (101 loc) · 3.21 KB
/
prepare_build.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# coding: utf-8
import os
from decimal import *
from time import *
import re
out_file = open(os.path.join('output', 'bg.s'), "r")
string = out_file.read()
out_file.close()
max_frames = 100
num_frames = len(os.listdir(os.path.join('input'))) - 3 # Remove gitkeep, . and ..
start_bank = 2
j = 1
start = 0
pos = 0
limits = []
while pos < num_frames:
limits.append(pos)
s = string.split("_frame"+str(start + pos), 1)
distance = max_frames
prev_sign = False
while True:
if distance + pos > num_frames:
s = s[1]
break
s2 = s[1].split(".globl _frame"+str(start + pos + distance), 1)
s3 = s2[0]
count = len(re.findall(r"0x[0-9a-fA-F][0-9a-fA-F]", s3))
if count < 15799:
if prev_sign:
s = s3
break
distance += 1
elif count > 15800:
distance -= 1
prev_sign = True
else:
s = s3
break
out_file = open(os.path.join("project", "background", "frames"+str(j)+".s"), "w")
out_file.write(".area _CODE_"+str(j+1)+"\n\n.globl _frame"+str(start + pos)+s)
pos += distance
out_file.close()
j += 1
j = start_bank
s = '#include "frame_banks.h"'
s += "\n\nvoid use_frame_bank(UINT16 frame, unsigned char * b) NONBANKED {\n"
s += "\tswitch(frame)\n\t{\n"
for l in limits:
s+="\t\tcase "+str(l)+": *b = "+str(j)+"; break;\n"
j+=1
s+="\t\tdefault: break;\n\t}\n"
s+="}\n"
out_file = open(os.path.join("project", "frame_banks.c"), "w")
out_file.write(s)
out_file.close()
# def generaNomi1(n):
# s = "{"
# s+="frame0"
# for i in range(1, n+1):
# s+=",frame"+str(i)
# return s+"}"
def build_frames(n):
s = "extern unsigned char frame0[];\n"
for i in range(1, n+1):
s += "extern unsigned char frame"+str(i)+"[];\n"
return s
def build_indexes(n):
s = ".area _CODE_30\n\n.globl _frame0\n"
for i in range(1, n+1):
s += ".globl _frame"+str(i)+"\n"
s+="\n\n.globl _frames\n.dw _frames\n_frames:\n"
for i in range(n+1):
if (i % 4) == 0:
s+="\n.dw #_frame"+str(i)
else:
s += ",#_frame"+str(i)
return s
def build_makefile(n):
s1 = ""
s2 = ""
s1 += "..\\gbdk\\bin\\lcc -Wa-l -Wf-ba0 -c -o saveslot1.o saves/saveslot1.c\n"
s1 += "..\\gbdk\\bin\\lcc -Wa-l -Wf-bo1 -c -o bg.o background/bg.s\n"
s2 += "..\\gbdk\\bin\\lcc -Wl-yt3 -Wl-yo32 -Wl-ya4 -o video.gb indexes.o main.o saveslot1.o rle_lib.o frame_banks.o bg.o"
for i in range(len(n)):
s1 += "..\\gbdk\\bin\\lcc -Wa-l -Wf-bo"+str(i+2)+" -c -o frames"+str(i+1)+".o background/frames"+str(i+1)+".s\n"
s2 += " frames"+str(i+1)+".o"
s1 += "..\\gbdk\\bin\\lcc -Wa-l -Wf-bo30 -c -o indexes.o background/indexes.s\n"
s1 += "..\\gbdk\\bin\\lcc -Wa-l -c -o rle_lib.o gbdk-lib-extension/rle_lib.c\n"
s1 += "..\\gbdk\\bin\\lcc -Wa-l -c -o frame_banks.o frame_banks.c\n"
s1 += "..\\gbdk\\bin\\lcc -Wa-l -c -o main.o main.c"
s2 += "\n\ndel *.o\ndel *.lst\n\n"
return s1 + "\n\n" + s2
out_file = open(os.path.join("project", "background", "frames.h"), "w")
out_file.write(build_frames(num_frames))
out_file.close()
out_file = open(os.path.join("project", "background", "indexes.s"), "w")
out_file.write(build_indexes(num_frames))
out_file.close()
out_file = open(os.path.join("project", "makefile.bat"), "w")
out_file.write(build_makefile(limits))
out_file.close()