-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.sh
executable file
·288 lines (239 loc) · 5.55 KB
/
make.sh
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/bin/bash
usage() {
echo -e "Usage:\t$0 ACTION [OPTION]"
echo
echo 'ACTION:'
echo -e '\tbuild [--32kb-rom]'
echo -e '\tclean'
echo -e '\thelp'
echo -e '\trun'
}
TARGET=amado
ROM_FILE_NAME=${TARGET}.gb
RAM_FILE_NAME=${TARGET}.sav
EMU=bgb
if [ $# -eq 0 ]; then
usage >&2
exit 1
fi
case "$1" in
'build')
action="$1"
if [ $# -eq 2 ]; then
opt="$2"
else
opt=''
fi
;;
'clean')
action="$1"
;;
'help')
usage
exit 0
;;
'run')
$EMU $ROM_FILE_NAME
exit 0
;;
*)
usage >&2
exit 1
;;
esac
# set -uex
set -ue
. include/gb.sh
. src/main.sh
print_boot_kern() {
if [ -f boot_kern.bin ]; then
cat boot_kern.bin
return
fi
(
# 0x0000 - 0x00ff: リスタートと割り込みのベクタテーブル (256バイト)
gbos_vec
# 0x0100 - 0x014f: カートリッジヘッダ (80バイト)
gbos_const >gbos_const.o
local offset=$(stat -c '%s' gbos_const.o)
local offset_hex=$(echo "obase=16;${offset}" | bc)
local bc_form="obase=16;ibase=16;${GB_ROM_FREE_BASE}+${offset_hex}"
local entry_addr=$(echo $bc_form | bc)
bc_form="obase=16;ibase=16;${entry_addr}+10000"
local entry_addr_4digits=$(echo $bc_form | bc | cut -c2-5)
if [ "$opt" == "--32kb-rom" ]; then
gb_cart_header_no_title $entry_addr_4digits
else
gb_cart_header_no_title_mbc1 $entry_addr_4digits
fi
# 0x0150 - 0x3fff: カートリッジROM(Bank 00) (16048バイト)
gbos_main >gbos_main.o
cat gbos_const.o gbos_main.o
## 16KBのサイズにするために残りをゼロ埋め
local num_const_bytes=$(stat -c '%s' gbos_const.o)
local num_main_bytes=$(stat -c '%s' gbos_main.o)
local padding=$((GB_ROM_BANK_SIZE_NOHEAD - num_const_bytes \
- num_main_bytes))
dd if=/dev/zero bs=1 count=$padding 2>/dev/null
) >boot_kern.bin
cat boot_kern.bin
}
print_fs_system() {
if [ -f fs_system.img ]; then
cat fs_system.img
return
fi
(
mkdir -p fs_system
# binedit.exe
if [ ! -f fs_system/0100.exe ]; then
make -C apps/binedit
cp apps/binedit/binedit.exe fs_system/0100.exe
fi
# har22a_cover.2bpp
if [ ! -f fs_system/0200.2bpp ]; then
cp imgs/har22a_cover.2bpp fs_system/0200.2bpp
fi
# sound_ch2_rand_description.2bpp
if [ ! -f fs_system/0300.2bpp ]; then
cp imgs/sound_ch2_rand_description.2bpp fs_system/0300.2bpp
fi
# sound_ch2_rand.exe
if [ ! -f fs_system/0400.exe ]; then
make -C apps/sound_ch2_rand
cp apps/sound_ch2_rand/sound_ch2_rand.exe fs_system/0400.exe
fi
# colophon_har22a.txt
if [ ! -f fs_system/0500.txt ]; then
make -C docs/colophon_har22a
cp docs/colophon_har22a/colophon_har22a.txt fs_system/0500.txt
fi
# # cartram_formatter.exe
# if [ ! -f fs_system/0200.exe ]; then
# make -C apps/cartram_formatter
# cp apps/cartram_formatter/cartram_formatter.exe fs_system/0200.exe
# fi
# # welcome.txt
# if [ ! -f fs_system/0300.txt ]; then
# make -C docs/welcome
# cp docs/welcome/welcome.txt fs_system/0300.txt
# fi
# # version.2bpp
# if [ ! -f fs_system/0400.2bpp ]; then
# cp imgs/version.2bpp fs_system/0400.2bpp
# fi
# # appendix.txt
# if [ ! -f fs_system/0450.txt ]; then
# make -C docs/appendix
# cp docs/appendix/appendix.txt fs_system/0450.txt
# fi
# # lifegame_glider.exe
# if [ ! -f fs_system/0500.exe ]; then
# make -C apps/lifegame_glider
# cp apps/lifegame_glider/lifegame_glider.exe fs_system/0500.exe
# fi
# # lifegame_random.exe
# if [ ! -f fs_system/0600.exe ]; then
# make -C apps/lifegame_random
# cp apps/lifegame_random/lifegame_random.exe fs_system/0600.exe
# fi
tools/make_fs fs_system fs_system.img
) >/dev/null
cat fs_system.img
}
print_fs_ram0_orig() {
if [ -f fs_ram0_orig.img ]; then
cat fs_ram0_orig.img
return
fi
(
tools/make_ram0_files.sh
tools/make_fs fs_ram0_orig fs_ram0_orig.img
) >/dev/null
cat fs_ram0_orig.img
}
print_rom() {
# 0x00 0000 - 0x00 3fff: Bank 000 (16KB)
print_boot_kern
# 0x00 4000 - 0x00 7fff: Bank 001 (16KB)
print_fs_system
if [ "$opt" == "--32kb-rom" ]; then
return
fi
# 0x00 8000 - 0x00 bfff: Bank 002 (16KB)
print_fs_ram0_orig
# 0x00 c000 - 0x1f bfff: Bank 003 - 126 (1984KB)
dd if=/dev/zero bs=K count=1984 2>/dev/null
# 0x1f c000 - 0x1f ffff: Bank 127 (16KB)
dd if=/dev/zero bs=1 count=260 2>/dev/null
dd if=logo.gb bs=1 count=48 ibs=1 skip=260
dd if=/dev/zero bs=1 count=$(((16 * 1024) - 260 - 48)) 2>/dev/null
}
print_fs_ram0() {
if [ -f fs_ram0.img ]; then
cat fs_ram0.img
return
fi
tools/make_fs fs_ram0_orig fs_ram0.img ram >/dev/null
cat fs_ram0.img
}
print_ram() {
# 0x0000 - 0x1fff: Bank 0 (8KB)
print_fs_ram0
# 0x2000 - 0x7fff: Bank 1 - 3 (24KB)
dd if=/dev/zero bs=K count=24 2>/dev/null
}
build() {
print_rom >$ROM_FILE_NAME
if [ "$opt" == "--32kb-rom" ]; then
return
fi
print_ram >$RAM_FILE_NAME
}
clean_boot_kern() {
rm -f boot_kern.bin
}
clean_apps() {
# binedit.exe
make -C apps/binedit clean
# cartram_formatter.exe
make -C apps/cartram_formatter clean
# lifegame_glider.exe
make -C apps/lifegame_glider clean
# lifegame_random.exe
make -C apps/lifegame_random clean
# # sound_ch2_C4D4E4F4G4A4B4C5.exe
# make -C apps/sound_ch2_C4D4E4F4G4A4B4C5 clean
# sound_ch2_rand.exe
make -C apps/sound_ch2_rand clean
}
clean_docs() {
# welcome.txt
make -C docs/welcome clean
}
clean_fs_system() {
clean_apps
clean_docs
rm -rf fs_system.img fs_system
}
clean_fs_ram0_orig() {
rm -rf fs_ram0_orig.img fs_ram0_orig
}
clean_rom() {
clean_boot_kern
clean_fs_system
clean_fs_ram0_orig
rm -f $ROM_FILE_NAME
}
clean_fs_ram0() {
rm -f fs_ram0.img
}
clean_ram() {
clean_fs_ram0
rm -f $RAM_FILE_NAME
}
clean() {
clean_rom
clean_ram
}
$action