-
Notifications
You must be signed in to change notification settings - Fork 12
/
build.sh
532 lines (457 loc) · 17.1 KB
/
build.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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
#!/usr/bin/sh
# Elite C64 disassembly / Elite : Harmless, cc-by-nc-sa 2018-2023,
# see LICENSE.txt. "Elite" is copyright / trademark David Braben & Ian Bell,
# All Rights Reserved. <github.com/Kroc/elite-harmless>
#===============================================================================
# stop further processing on any error
set -e
cl65="cl65 \
--debug-info \
--include-dir src \
--include-dir build \
--bin-include-dir build \
--feature leading_dot_in_identifiers \
--feature bracket_as_indirect \
--asm-args --large-alignment"
ca65="ca65 \
--debug-info \
--target c64 \
--debug-info \
--include-dir src \
--include-dir build \
--bin-include-dir build \
--feature leading_dot_in_identifiers \
--feature bracket_as_indirect \
--large-alignment"
ld65="ld65"
mkd64="mkd64"
encrypt="python3 link/encrypt.py"
exomizer="./bin/exomizer/src/exomizer sfx \$0400 -q"
#===============================================================================
clear
echo "building Elite : Harmless"
echo
clean() {
echo -n "- cleaning up... "
rm -rf build/*.o
rm -rf build/*.s
rm -rf build/*.bin
rm -rf build/*.prg
rm -rf build/*.exo
rm -rf build/*.d64
rm -rf build/*.crt
# annoyingly `cl65` will always place object files in the same directory
# as the source file, so we need to clean these out of "src" ourselves
rm -f src/*.o
rm -f src/boot/*.o
rm -f src/c64/*.o
rm -f src/gfx/*.o
rm -f src/orig/*.o
rm -f src/text/*.o
echo "[OK]"
}
clean
# build an original version of the game, including the original fast-loader
echo
echo "* build original Elite"
echo " ======================================"
# assemble 'original' version of the code; the `BUILD_ORIGINAL` symbol
# is used within the files to exlcude changed code from the original
options="-DBUILD_ORIGINAL -DFEATURE_AUDIO -DFEATURE_TRUMBLES"
# assemble the HUD bitmap into a Koala file we can pick bytes from.
# we won't use a linker script for this as we don't need to include
# any external symbols or definitions
echo -n "- assemble 'screen_main.koa' "
$cl65 $options \
--target none \
--start-addr \$4000 \
-o "build/screen_main.koa" \
"src/orig/gfx_koala_main.asm"
echo "[OK]"
echo -n "- assemble 'screen_menu.koa' "
$cl65 $options \
--target none \
--start-addr \$4000 \
-o "build/screen_menu.koa" \
"src/orig/gfx_koala_menu.asm"
echo "[OK]"
# assemble the super-object containing
# the majority of the original Elite code
echo -n "- assemble 'elite-original.asm' "
$ca65 $options -o build/elite-original.o src/elite-original.asm
# the text database has to be assembled separately from the main code
# due to the rather insane complexity which is best not leaked into
# the global scope along with the main source code
echo "[OK]"; echo -n "- assemble 'text_pairs.asm' "
$ca65 $options -o build/text_pairs.o src/text/text_pairs.asm
echo "[OK]"; echo -n "- assemble 'text_flight.asm' "
$ca65 $options -o build/text_flight.o src/text/text_flight.asm
echo "[OK]"; echo -n "- assemble 'text_docked.asm' "
$ca65 $options -o build/text_docked.o src/text/text_docked.asm
echo "[OK]"
# let's build an original floppy disk to verify that we haven't broken
# the code or failed to preserve the original somewhere along the line
echo " --------------------------------------"
echo "* assemble GMA86 loader"
echo " --------------------------------------"
echo -n "- assemble 'boot/gma/stage0.asm' "
$ca65 -o build/boot_gma_stage0.o src/boot/gma/stage0.asm
echo "[OK]"; echo -n "- assemble 'boot/gma/stage1.asm' "
$ca65 -o build/boot_gma_stage1.o src/boot/gma/stage1.asm
echo "[OK]"; echo -n "- assemble 'boot/gma/stage2.asm' "
$ca65 -o build/boot_gma_stage2.o src/boot/gma/stage2.asm
echo "[OK]"; echo -n "- assemble 'boot/gma/stage3.asm' "
$ca65 -o build/boot_gma_stage3.o src/boot/gma/stage3.asm
echo "[OK]"; echo -n "- assemble 'boot/gma/stage4.asm' "
$ca65 -o build/boot_gma_stage4.o src/boot/gma/stage4.asm
echo "[OK]"; echo -n "- assemble 'boot/gma/gma4_7C3A.asm' "
$ca65 -o build/boot_gma_stage4_7C3A.o src/boot/gma/stage4_7C3A.asm
echo "[OK]"; echo -n "- assemble 'boot/gma/stage5.asm' "
$ca65 -o build/boot_gma_stage5.o src/boot/gma/stage5.asm
echo "[OK]"; echo -n "- assemble 'boot/gma/stage6.asm' "
$ca65 -o build/boot_gma_stage6.o src/boot/gma/stage6.asm
echo "[OK]"
echo " --------------------------------------"
echo "* link 'elite-original-gma86.cfg'"
echo " --------------------------------------"
echo -n "- link objects... "
$ld65 \
-C "link/elite-original-gma86.cfg" \
-m "build/elite-original-gma86.map" -vm \
-Ln "build/elite-original-gma86.ll" \
--obj "build/elite-original.o" \
--obj "build/boot_gma_stage0.o" \
--obj "build/boot_gma_stage1.o" \
--obj "build/boot_gma_stage2.o" \
--obj "build/boot_gma_stage3.o" \
--obj "build/boot_gma_stage4.o" \
--obj "build/boot_gma_stage5.o" \
--obj "build/boot_gma_stage6.o" \
--obj "build/boot_gma_stage4_7C3A.o" \
--obj "build/text_pairs.o" \
--obj "build/text_flight.o" \
--obj "build/text_docked.o"
echo "[OK]"
# encrypt GMA4.PRG:
#-------------------------------------------------------------------------------
# verify that the packed data is correct:
# (this will be harder to debug once encrypted)
echo -n "- verify 'gma4_data1.bin' "
if [[
# note that this hash was produced by dumping $4000...$758F,
# just after decryption (but before relocation)
$(md5sum -b < build/gma4_data1.bin) \
== "049a1004768ed1de4e220923ea865f78 *-"
]]; then
echo "[OK]"
else
echo "FAIL"
exit 1
fi
# run the binary through the encrypt script, which will spit out an assembler
# file we can then re-link into the stage 4 loader ("GMA4.PRG")
echo -n "- encrypt 'gma4_data1.bin' "
$encrypt 6C \
build/gma4_data1.bin \
build/gma4_data1.bin
echo "[OK]"
# verify that the packed data is correct:
# (this will be harder to debug once encrypted)
echo -n "- verify 'gma4_data2.bin' "
if [[
# note that this hash was produced by dumping $75E4...$865F,
# just after decryption (but before relocation)
$(md5sum -b < build/gma4_data2.bin) \
== "32cba4aa5d3ee363c0bdfb77e95c1fc3 *-"
]]; then
echo "[OK]"
else
echo "FAIL"
exit 1
fi
# encrypt the second block
echo -n "- encrypt 'gma4_data2.bin' "
$encrypt 8E \
build/gma4_data2.bin \
build/gma4_data2.bin
echo "[OK]"
echo -n "- concat 'gma4.prg' "
cat "build/gma4_prg.bin" \
"build/gma4_data1.bin" \
"build/gma4_junk1.bin" \
"build/gma4_code.bin" \
"build/gma4_data2.bin" \
"build/gma4_junk2.bin" \
> "build/gma4.prg"
echo "[OK]"
# encrypt GMA5.PRG:
#-------------------------------------------------------------------------------
echo -n "- encrypt 'gma5_data.bin' "
$encrypt 36 \
build/gma5_data.bin \
build/gma5_data.bin
echo "[OK]"
echo -n "- concat 'gma5.prg' "
cat "build/gma5_code.prg" \
"build/gma5_data.bin" \
"build/gma5_junk.bin" \
> "build/gma5.prg"
echo "[OK]"
# encrypt GMA6.PRG:
#-------------------------------------------------------------------------------
echo -n "- encrypt 'gma6_data.bin' "
$encrypt 49 \
build/gma6_data.bin \
build/gma6_data.bin
echo "[OK]"
echo -n "- concat 'gma6.prg' "
cat "build/gma6_prg.bin" \
"build/gma6_data.bin" \
"build/gma6_junk.bin" \
> "build/gma6.prg"
echo "[OK]"
#-------------------------------------------------------------------------------
echo " --------------------------------------"
echo -n "- write floppy disk image "
$mkd64 \
-o release/elite-original-gma86.d64 \
-m xtracks -XDS \
-m cbmdos -d "ELITE 040486" -i "GMA86" \
-f build/firebird.prg -t 17 -s 0 -n "FIREBIRD" -P -S 1 -w \
-f build/gma1.prg -t 17 -s 1 -n "GMA1" -P -S 2 -w \
-f build/byebyejulie.prg -t 17 -s 4 -n "BYEBYEJULIE" -P -S 3 -w \
-f build/gma3.prg -t 17 -s 5 -n "GMA3" -P -S 4 -w \
-f build/gma4.prg -t 17 -s 6 -n "GMA4" -P -S 5 -w \
-f build/gma5.prg -t 19 -s 0 -n "GMA5" -P -S 6 -w \
-f build/gma6.prg -t 20 -s 8 -n "GMA6" -P -S 7 -w \
1>/dev/null
echo "[OK]"
#-------------------------------------------------------------------------------
echo -n "- verifying checksums "
cd build
md5sum --ignore-missing --quiet --check ../link/checksums.md5
if [ $? -eq 0 ]; then echo "[OK]"; fi
cd ..
#===============================================================================
echo " ======================================"
echo "* build Elite : Harmless (disk images)"
echo " ======================================"
echo "* assemble:"
echo " --------------------------------------"
clean
# copy the elite : harmless screen bitmap images into the build directory.
# note that elite-harmless does not assemble the screens from a source file
cp "src/gfx/screen_main.koa" \
"build/screen_main.koa"
# elite-harmless-orig:
#-------------------------------------------------------------------------------
echo -n "- elite-harmless-orig.cfg "
options="--cpu 6502X -Wa -DFEATURE_AUDIO,-DFEATURE_TRUMBLES,-DFEATURE_FLICKERFREE"
# note that the text database has to be assembled separately from the main code
# due to the rather insane complexity which is best not leaked into the global
# scope along with the main source code
$cl65 $options \
--config "link/elite-harmless-orig.cfg" \
--start-addr \$0400 \
-m "build/elite-harmless-orig.map" -vm \
-Ln "build/elite-harmless-orig.ll" \
-o "build/harmless-orig.prg" \
"src/elite-harmless.asm" \
"src/text/text_pairs.asm" \
"src/text/text_flight.asm" \
"src/text/text_docked.asm" \
"src/c64/prgheader.asm"
echo "[OK]"
# elite-harmless:
#-------------------------------------------------------------------------------
echo -n "- elite-harmless.cfg "
options="--cpu 6502X -Wa -DFEATURE_AUDIO,-DFEATURE_TRUMBLES,-DFEATURE_FLICKERFREE"
# note that the text database has to be assembled separately from the main code
# due to the rather insane complexity which is best not leaked into the global
# scope along with the main source code
$cl65 $options \
--config "link/elite-harmless.cfg" \
--start-addr \$0400 \
-m "build/elite-harmless.map" -vm \
-Ln "build/elite-harmless.ll" \
-o "build/harmless.prg" \
"src/elite-harmless.asm" \
"src/text/text_pairs.asm" \
"src/text/text_flight.asm" \
"src/text/text_docked.asm" \
"src/c64/prgheader.asm"
echo "[OK]"
# elite-harmless-fastlines:
#-------------------------------------------------------------------------------
echo -n "- elite-harmless-fastlines.cfg "
options="--cpu 6502X -Wa -DFEATURE_AUDIO,-DFEATURE_TRUMBLES,-DFEATURE_FASTLINES,-DFEATURE_FLICKERFREE"
# note that the text database has to be assembled separately from the main code
# due to the rather insane complexity which is best not leaked into the global
# scope along with the main source code
$cl65 $options \
--config "link/elite-harmless.cfg" \
--start-addr \$0400 \
-m "build/elite-harmless-fastlines.map" -vm \
-Ln "build/elite-harmless-fastlines.ll" \
-o "build/harmless-fastlines.prg" \
"src/elite-harmless.asm" \
"src/text/text_pairs.asm" \
"src/text/text_flight.asm" \
"src/text/text_docked.asm" \
"src/c64/prgheader.asm"
echo "[OK]"
# elite-harmless-hiram:
#-------------------------------------------------------------------------------
#echo -n "- elite-harmless-hiram.cfg "
#
#options="--cpu 6502X -Wa -DFEATURE_AUDIO,-DFEATURE_MATHTABLES,#-DFEATURE_TRUMBLES,-DFEATURE_FLICKERFREE"
#
## note that the text database has to be assembled separately from the main code
## due to the rather insane complexity which is best not leaked into the global
## scope along with the main source code
#
#$cl65 $options \
# --config "link/elite-harmless-hiram.cfg" \
# --start-addr \$0400 \
# -m "build/elite-harmless-hiram.map" -vm \
# -Ln "build/elite-harmless-hiram.ll" \
# -o "build/harmless-hiram.prg" \
# "src/elite-harmless.asm" \
# "src/text/text_pairs.asm" \
# "src/text/text_flight.asm" \
# "src/text/text_docked.asm" \
# "src/c64/prgheader.asm"
#
#echo "[OK]"
# elite-harmless-hiram-fastlines:
#-------------------------------------------------------------------------------
#echo -n "- elite-harmless-hiram-fastlines.cfg"
#
#options="--cpu 6502X -Wa -DFEATURE_AUDIO,-DFEATURE_MATHTABLES,#-DFEATURE_FASTLINES,-DFEATURE_TRUMBLES,-DFEATURE_FLICKERFREE"
#
## note that the text database has to be assembled separately from the main code
## due to the rather insane complexity which is best not leaked into the global
## scope along with the main source code
#
#$cl65 $options \
# --config "link/elite-harmless-hiram.cfg" \
# --start-addr \$0400 \
# -m "build/elite-harmless-hiram-fastlines.map" -vm \
# -Ln "build/elite-harmless-hiram-fastlines.ll" \
# -o "build/harmless-hiram-fastlines.prg" \
# "src/elite-harmless.asm" \
# "src/text/text_pairs.asm" \
# "src/text/text_flight.asm" \
# "src/text/text_docked.asm" \
# "src/c64/prgheader.asm"
#
#echo "[OK]"
#===============================================================================
echo " --------------------------------------"
echo "* elite-harmless-orig.d64:"
echo " --------------------------------------"
# NB: `lda #$00 sta $d011` turns the screen "off" so no background is
# displayed. it also speeds up the processor (no VIC wait-states).
# we don't need to turn the screen back on afterwards as Elite
# does this itself during initialisation
echo -n "- compress binaries... "
$exomizer \
-s "lda #\$00 sta \$d011 sta \$d020" \
-X "inc \$d020 dec \$d020" \
-o "build/harmless-orig.exo" \
-- "build/harmless-orig.prg"
echo "[OK]"
echo -n "- make floppy disk... "
$mkd64 \
-o release/elite-harmless-orig.d64 \
-m cbmdos -d "ELITE:HARMLESS" -i "KROC " \
-f build/harmless-orig.exo -t 17 -s 0 -n "HARMLESS" \
-P -w 1>/dev/null
echo "[OK]"
echo " --------------------------------------"
echo "* elite-harmless.d64:"
echo " --------------------------------------"
echo -n "- compress binaries... "
$exomizer \
-s "lda #\$00 sta \$d011 sta \$d020" \
-X "inc \$d020 dec \$d020" \
-o "build/harmless.exo" \
-- "build/harmless.prg"
echo "[OK]"
echo -n "- make floppy disk... "
$mkd64 \
-o release/elite-harmless.d64 \
-m cbmdos -d "ELITE:HARMLESS" -i "KROC " \
-f build/harmless.exo -t 17 -s 0 -n "HARMLESS" \
-P -w 1>/dev/null
echo "[OK]"
echo " --------------------------------------"
echo "* elite-harmless-fastlines.d64:"
echo " --------------------------------------"
echo -n "- compress binaries... "
$exomizer \
-s "lda #\$00 sta \$d011 sta \$d020" \
-X "inc \$d020 dec \$d020" \
-o "build/harmless-fastlines.exo" \
-- "build/harmless-fastlines.prg"
echo "[OK]"
echo -n "- make floppy disk... "
$mkd64 \
-o release/elite-harmless-fastlines.d64 \
-m cbmdos -d "ELITE:HARMLESS" -i "KROC " \
-f build/harmless-fastlines.exo -t 17 -s 0 -n "HARMLESS" \
-P -w 1>/dev/null
echo "[OK]"
#echo " --------------------------------------"
#echo "* elite-harmless-hiram.d64:"
#echo " --------------------------------------"
#
#echo -n "- compress binaries... "
#$exomizer \
# -s "lda #\$00 sta \$d011 sta \$d020" \
# -X "inc \$d020 dec \$d020" \
# -o "build/harmless-hiram.exo" \
# -- "build/harmless-hiram.prg"
#echo "[OK]"
#
#echo -n "- make floppy disk... "
#$mkd64 \
# -o release/elite-harmless-hiram.d64 \
# -m cbmdos -d "ELITE:HARMLESS" -i "KROC " \
# -f build/harmless-hiram.exo -t 17 -s 0 \
# -n "HARMLESS" -P -w 1>/dev/null
#echo "[OK]"
#
#echo " --------------------------------------"
#echo "* elite-harmless-hiram-fastlines.d64:"
#echo " --------------------------------------"
#
#echo -n "- harmless-hiram-fastlines.prg "
#$exomizer \
# -s "lda #\$00 sta \$d011 sta \$d020" \
# -X "inc \$d020 dec \$d020" \
# -o "build/harmless-hiram-fastlines.exo" \
# -- "build/harmless-hiram-fastlines.prg"
#echo "[OK]"
#
#echo -n "- make floppy disk... "
#$mkd64 \
# -o release/elite-harmless-hiram-fastlines.d64 \
# -m cbmdos -d "ELITE:HARMLESS" -i "KROC " \
# -f build/harmless-hiram-fastlines.exo -t 17 -s 0 \
# -n "HARMLESS" -P -w 1>/dev/null
#echo "[OK]"
#===============================================================================
# annoyingly `cl65` will always place object files in the same directory
# as the source file, so we need to clean these out of "src" ourselves
echo " ======================================"
echo -n "- cleaning up... "
rm -f src/*.o
rm -f src/boot/*.o
rm -f src/c64/*.o
rm -f src/gfx/*.o
rm -f src/text/*.o
echo "[OK]"
echo "* complete."
echo
exit 0