-
Notifications
You must be signed in to change notification settings - Fork 18
/
elite-loader.asm
1656 lines (1293 loc) · 64.6 KB
/
elite-loader.asm
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
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; ******************************************************************************
;
; COMMODORE 64 ELITE GAME LOADER SOURCE
;
; Commodore 64 Elite was written by Ian Bell and David Braben and is copyright
; D. Braben and I. Bell 1985
;
; The code in this file is identical to the source disks released on Ian Bell's
; personal website at http://www.elitehomepage.org/ (it's just been reformatted
; to be more readable)
;
; The commentary is copyright Mark Moxon, and any misunderstandings or mistakes
; in the documentation are entirely my fault
;
; The terminology and notations used in this commentary are explained at
; https://elite.bbcelite.com/terminology
;
; The deep dive articles referred to in this commentary can be found at
; https://elite.bbcelite.com/deep_dives
;
; ------------------------------------------------------------------------------
;
; This source file contains the game loader for Commodore 64 Elite, which itself
; gets loaded by the disk loader.
;
; ------------------------------------------------------------------------------
;
; This source file produces the following binary file:
;
; * COMLOD.unprot.bin
;
; after reading in the following files:
;
; * LODATA.bin
; * SHIPS.bin
; * CODIALS.bin
; * SPRITE.bin
; * DATE4.bin
;
; ******************************************************************************
INCLUDE "1-source-files/main-sources/elite-build-options.asm"
_GMA85_NTSC = (_VARIANT = 1)
_GMA86_PAL = (_VARIANT = 2)
_GMA_RELEASE = (_VARIANT = 1) OR (_VARIANT = 2)
_SOURCE_DISK_BUILD = (_VARIANT = 3)
_SOURCE_DISK_FILES = (_VARIANT = 4)
_SOURCE_DISK = (_VARIANT = 3) OR (_VARIANT = 4)
; ******************************************************************************
;
; Configuration variables
;
; ******************************************************************************
CODE% = $4000 ; The address where the code will be run
LOAD% = $4000 ; The address where the code will be loaded
KEY3 = $8E ; The seed for decrypting COMLOD from U% to V%, which is
; the second block of data, after the decryption routine
KEY4 = $6C ; The seed for decrypting COMLOD from W% to X%, which is
; the first block of data, before the decryption routine
L1 = $0001 ; The 6510 input/output port register, which we can use
; to configure the Commodore 64 memory layout (see page
; 260 of the Programmer's Reference Guide)
SCBASE = $4000 ; The address of the screen bitmap
IF _GMA_RELEASE
DSTORE% = SCBASE + $AF90 ; The address of a copy of the dashboard bitmap,
; which gets copied into screen memory when
; setting up a new screen
SPRITELOC% = SCBASE + $2800 ; The address where the sprite bitmaps get
; copied to during the loading process
ELIF _SOURCE_DISK
DSTORE% = SCBASE + $2800 ; The address of a copy of the dashboard bitmap,
; which gets copied into screen memory when
; setting up a new screen
SPRITELOC% = SCBASE + $3100 ; The address where the sprite bitmaps get
; copied to during the loading process
ENDIF
SPOFF% = (SPRITELOC% - SCBASE) / 64 ; Sprite pointers are defined as the
; offset from the start of the VIC-II
; screen bank to start of the sprite
; definitions, divided by 64, so SPOFF%
; is the offset for the first sprite
; definition at SPRITELOC%
D% = $D000 ; The address where the ship data will be loaded
; (i.e. XX21)
VIC = $D000 ; Registers for the VIC-II video controller chip, which
; are memory-mapped to the 46 bytes from $D000 to $D02E
; (see page 454 of the Programmer's Reference Guide)
COLMEM = $D800 ; Colour RAM, which is used (along with screen RAM) to
; define the colour map of the dashboard in multicolour
; bitmap mode
CIA = $DC00 ; Registers for the CIA1 I/O interface chip, which
; are memory-mapped to the 16 bytes from $DC00 to $DC0F
; (see page 428 of the Programmer's Reference Guide)
CIA2 = $DD00 ; Registers for the CIA2 I/O interface chip, which
; are memory-mapped to the 16 bytes from $DD00 to $DD0F
; (see page 428 of the Programmer's Reference Guide)
; ******************************************************************************
;
; Name: ZP
; Type: Workspace
; Address: $0018 to $001B
; Category: Workspaces
; Summary: Important variables used by the loader
;
; ******************************************************************************
ORG $0018
.ZP
SKIP 2 ; Stores addresses used for moving content around
.ZP2
SKIP 2 ; Stores addresses used for moving content around
; ******************************************************************************
;
; ELITE LOADER
;
; ******************************************************************************
ORG CODE%
; ******************************************************************************
;
; Name: W%
; Type: Variable
; Category: Utility routines
; Summary: Denotes the start of the first block of loader code, as used in
; the encryption/decryption process
;
; ******************************************************************************
.W%
SKIP 0
; ******************************************************************************
;
; Name: LODATA
; Type: Subroutine
; Category: Loader
; Summary: The binaries for recursive tokens and the game font
;
; ******************************************************************************
.LODATA
INCBIN "3-assembled-output/LODATA.bin"
; ******************************************************************************
;
; Name: SHIPS
; Type: Subroutine
; Category: Loader
; Summary: The binaries for the ship blueprints
;
; ******************************************************************************
.SHIPS
INCBIN "3-assembled-output/SHIPS.bin"
IF _GMA_RELEASE
EQUB $1F, $3F ; These bytes appear to be unused and just contain
EQUB $58 ; random workspace noise left over from the BBC Micro
; assembly process
ELIF _SOURCE_DISK_BUILD
EQUB $B3, $1F, $3F, $58, $98, $A0, $40, $20 ; These bytes appear to be
EQUB $1F, $F0, $8C, $98, $1A, $46, $10, $8C ; unused and just contain random
EQUB $CF, $3C, $B2, $CF, $C2, $7D, $FF, $2A ; workspace noise left over from
EQUB $92, $AB, $A8, $BD, $3E, $85, $9E, $19 ; the BBC Micro assembly process
EQUB $85, $F5, $3A, $EF, $06, $E6, $E4, $04
EQUB $07, $E7, $E5, $EA, $AA, $2E, $98, $2F
EQUB $10, $F0, $E2, $02, $12, $F2, $E3, $03
EQUB $DA, $BA, $E4, $04, $DB, $BB, $E5, $19
EQUB $39, $85, $25, $2E, $98, $3A, $BB, $B0
EQUB $12, $13, $03, $E3, $F3, $F2, $E2, $7D
EQUB $1A, $B2, $5D, $02, $E2, $F0, $10, $03
EQUB $E3, $F2, $8D, $1A, $B2, $40, $78, $2F
EQUB $E4, $01, $2C, $ED, $E3, $21, $2B, $5C
EQUB $52, $22, $A8, $CB, $07, $2E, $DB, $BB
EQUB $E5, $05, $DC, $BC
ELIF _SOURCE_DISK_FILES
EQUB $38, $E0, $60, $3F, $0F, $7C, $24, $B2 ; These bytes appear to be
EQUB $60, $56, $9C, $67, $23, $FA, $81, $91 ; unused and just contain random
EQUB $3F, $7C, $29, $BC, $3D, $53, $65, $FB ; workspace noise left over from
EQUB $C3, $23, $B7, $9E, $7A, $2F, $29, $F5 ; the BBC Micro assembly process
EQUB $EC, $CA, $E8, $0B, $EE, $CC, $CF, $94
EQUB $D8, $C6, $C7, $3F, $00, $D2, $E4, $14
EQUB $04, $D5, $E6, $DD, $94, $9E, $E8, $DF
EQUB $96, $A0, $FE, $52, $BE, $AA, $53, $C6
EQUB $D2, $F5, $6B, $C2, $25, $16, $E6, $D6
EQUB $E5, $D4, $5F, $A3, $E5, $1D, $60, $E4
EQUB $D2, $00, $13, $E6, $D5, $7F, $B3, $E5
EQUB $00, $B9, $A7, $13, $E5, $2D, $19, $D0
EQUB $04, $4C, $87, $AE, $74, $CA, $73, $D2
EQUB $35, $09, $96, $A0, $EA, $E1, $98, $A2
EQUB $66, $AE, $C6, $04
ENDIF
; ******************************************************************************
;
; Name: X%
; Type: Variable
; Category: Utility routines
; Summary: Denotes the end of the first block of loader code, as used in the
; encryption/decryption process
;
; ******************************************************************************
.X%
JMP $0185 ; This code is never run, but it was presumably added
; to the code to act as a red herring to confuse any
; crackers exploring the loader code
; ******************************************************************************
;
; Name: FRIN
; Type: Variable
; Category: Loader
; Summary: A temporary variable that's used for storing addresses
;
; ******************************************************************************
.FRIN
JSR $0134 ; This code is never run (it is overwritten when the
; FRIN variable is used), but it was presumably added
; to the code to act as a red herring to confuse any
; crackers exploring the loader code
; ******************************************************************************
;
; Name: Elite loader (Part 1 of 7)
; Type: Subroutine
; Category: Loader
; Summary: Unscramble the loader code and game data
;
; ******************************************************************************
.ENTRY
CLD ; Clear the decimal flag, so we're not in decimal mode
LDA #LO(U%-1) ; Set FRIN(1 0) = U%-1 as the low address of the
STA FRIN ; decryption block, so we decrypt the loader routine
LDA #HI(U%-1) ; at U% below
STA FRIN+1
LDA #HI(V%-1) ; Set (A Y) to V% as the high address of the decryption
LDY #LO(V%-1) ; block, so we decrypt to V% at the end of the loader
; routine
LDX #KEY3 ; Set X = KEY3 as the decryption seed (the value used to
; encrypt the code, which is done in elite-checksum.py)
IF _REMOVE_CHECKSUMS
NOP ; If we have disabled checksums, skip the call to DEEORS
NOP
NOP
ELSE
JSR DEEORS ; Call DEEORS to decrypt between U% and V%
ENDIF
LDA #LO(W%-1) ; Set FRIN(1 0) = W%-1 as the low address of the
STA FRIN ; decryption block, so we decrypt the game data at
LDA #HI(W%-1) ; at W% above
STA FRIN+1
LDA #HI(X%-1) ; Set (A Y) to X% as the high address of the decryption
LDY #LO(X%-1) ; block, so we decrypt to X% at the end of the game data
LDX #KEY4 ; Set X = KEY4 as the decryption seed (the value used to
; encrypt the code, which is done in elite-checksum.py)
IF _REMOVE_CHECKSUMS
NOP ; If we have disabled checksums, skip the call to DEEORS
NOP
NOP
ELSE
JSR DEEORS ; Call DEEORS to decrypt between W% and X%
ENDIF
JMP U% ; Now that both the game data and the loader routine
; have been decrypted, jump to the loader routine at U%
; to load the game
; ******************************************************************************
;
; Name: DEEORS
; Type: Subroutine
; Category: Loader
; Summary: Decrypt a multi-page block of memory
;
; ------------------------------------------------------------------------------
;
; Arguments:
;
; FRIN(1 0) The start address of the block to decrypt
;
; (A Y) The end address of the block to decrypt
;
; X The decryption seed
;
; ******************************************************************************
.DEEORS
STX ZP2 ; Store the decryption seed in ZP2 as our starting point
STA ZP+1 ; Set ZP(1 0) = (A 0) to point to the start of page A,
LDA #0 ; so we can use ZP(1 0) + Y as our pointer to the next
STA ZP ; byte to decrypt
.DEEORL
LDA (ZP),Y ; Set A to the Y-th byte of ZP(1 0)
SEC ; Set A = A - ZP2
SBC ZP2
STA (ZP),Y ; Update the Y-th byte of ZP to the new value in A
STA ZP2 ; Update ZP2 with the new value in A
TYA ; Set A to the current byte index in Y
BNE P%+4 ; If A <> 0 then decrement the high byte of ZP(1 0) to
DEC ZP+1 ; point to the previous page
DEY ; Decrement the byte pointer
CPY FRIN ; Loop back to decrypt the next byte, until Y = the low
BNE DEEORL ; byte of FRIN(1 0), at which point we have decrypted a
; whole page
LDA ZP+1 ; Check whether ZP(1 0) matches FRIN(1 0) and loop back
CMP FRIN+1 ; to decrypt the next byte until it does, at which point
BNE DEEORL ; we have decrypted the whole block
RTS ; Return from the subroutine
; ******************************************************************************
;
; Name: Elite loader (Part 2 of 7)
; Type: Subroutine
; Category: Loader
; Summary: Copy the game data to their correct locations
;
; ******************************************************************************
.U%
LDX #$16 ; Set X = $16 so we copy 22 pages of data from LODATA
; into $0700 to $1CFF
LDA #0 ; Set ZP(1 0) = $0700
STA ZP
LDA #$7
STA ZP+1
LDA #LO(LODATA) ; Set (A ZP2) = LODATA
STA ZP2
LDA #HI(LODATA)
JSR mvblock ; Call mvblock to copy 22 pages of data from LODATA to
; $0700, so this copies the following data:
;
; * QQ18 to $0700, the text token table
;
; * SNE to $0AC0, the sine lookup table
;
; * ACT to $0AE0, the arctan lookup table
;
; * FONT to $0B00, the game's text font
;
; * TKN1 to $0E00, the extended token table
;
; The data at TKN1 ends at $1CFF
SEI ; Disable interrupts while we set the 6510 input/output
; port register and configure the VIC-II chip
LDA L1 ; Set bits 0 to 2 of the 6510 port register at location
AND #%11111000 ; L1 to %100 to set the input/output port to the
ORA #%00000100 ; following:
STA L1 ;
; * LORAM = 0
; * HIRAM = 0
; * CHAREN = 1
;
; and return from the subroutine using a tail call
;
; This sets the entire 64K memory map to RAM
;
; See the memory map at the top of page 265 in the
; Programmer's Reference Guide
IF _GMA_RELEASE
LDX #$29 ; Set X = $29 so we copy 41 pages of data from SHIPS
; into D% ($D000 to $F8FF)
;
; It isn't necessary to copy this number of pages, as
; the ship data only takes up 32 pages of memory, and
; the extra data that's copied from $F000 to $F8FF is
; just ignored
ELIF _SOURCE_DISK
LDX #$20 ; Set X = $20 so we copy 32 pages of data from SHIPS
; to D% ($D000 to $EFFF)
ENDIF
LDA #LO(D%) ; Set ZP(1 0) = D% = $D000
STA ZP
LDA #HI(D%)
STA ZP+1
LDA #LO(SHIPS) ; Set (A ZP2) = SHIPS
STA ZP2
LDA #HI(SHIPS)
JSR mvblock ; Call mvblock to copy X pages of data from SHIPS to D%
; ($D000), so this copies the following data:
;
; * XX21 to $D000, the ship blueprints
;
; The data at XX21 ends at $EF8C
; ******************************************************************************
;
; Name: Elite loader (Part 3 of 7)
; Type: Subroutine
; Category: Loader
; Summary: Configure the memory layout and the CIA chips
;
; ******************************************************************************
LDA L1 ; Set bits 0 to 2 of the 6510 port register at location
AND #%11111000 ; L1 to %101 to set the input/output port to the
ORA #%00000101 ; following:
STA L1 ;
; * LORAM = 1
; * HIRAM = 0
; * CHAREN = 1
;
; This sets the entire 64K memory map to RAM except for
; the I/O memory map at $D000-$DFFF, which gets mapped
; to registers in the VIC-II video controller chip, the
; SID sound chip, the two CIA I/O chips, and so on
;
; See the memory map at the top of page 264 in the
; Programmer's Reference Guide
LDA CIA2+2 ; Set bits 0-1 of CIA2 port A to the output direction
ORA #%00000011 ; so we can write to the VIC-II bank selector, which is
STA CIA2+2 ; mapped here (0 means input, 1 means output)
LDA CIA2+0 ; Set bits 0-1 of CIA2 port A to configure the VIC-II to
AND #%11111100 ; use bank 1 ($4000 to $7FFF)
ORA #%00000010 ;
STA CIA2+0 ; The bank number is inverted, so setting bits 0-1 to
; %10 actually sets bank %01
LDA #%00000011 ; Set CIA1 register $0D to enable and disable interrupts
STA CIA+$D ; as follows:
;
; * Bit 0 set = configure interrupts generated by
; timer A underflow
;
; * Bit 1 set = configure interrupts generated by
; timer B underflow
;
; * Bits 2-4 clear = do not change configuration of
; other interrupts
;
; * Bit 7 clear = disable interrupts whose
; corresponding bits are set
;
; So this disables interrupts that are generated by
; timer A underflow and timer B underflow, while leaving
; other interrupts as they are
STA CIA2+$D ; Set CIA2 register $0D to enable and disable interrupts
; as follows:
;
; * Bit 0 set = configure interrupts generated by
; timer A underflow
;
; * Bit 1 set = configure interrupts generated by
; timer B underflow
;
; * Bits 2-4 clear = do not change configuration of
; other interrupts
;
; * Bit 7 clear = disable interrupts whose
; corresponding bits are set
;
; So this disables interrupts that are generated by
; timer A underflow and timer B underflow, while leaving
; other interrupts as they are
; ******************************************************************************
;
; Name: Elite loader (Part 4 of 7)
; Type: Subroutine
; Category: Loader
; Summary: Configure the VIC-II for screen memory and sprites
; Deep dive: The split-screen mode in Commodore 64 Elite
; Sprite usage in Commodore 64 Elite
;
; ******************************************************************************
LDA #$81 ; Set VIC register $18 to set the address of screen RAM
STA VIC+$18 ; to offset $2000 within the VIC-II bank at $4000 (so
; the screen's colour data is at $6000)
LDA #0 ; Set VIC register $20 to set the border colour to the
STA VIC+$20 ; colour number in bits 0-3 (i.e. colour 0, black)
LDA #0 ; Set VIC register $21 to set the background colour to
STA VIC+$21 ; the colour number in bits 0-3 (i.e. colour 0, black)
LDA #%00111011 ; Set VIC register $11 to configure the screen control
STA VIC+$11 ; register as follows:
;
; * Bits 0-2 = vertical raster scroll of 3
;
; * Bit 3 set = screen height of 25 rows
;
; * Bit 4 set = enable screen
;
; * Bit 5 set = bitmap mode
;
; * Bit 6 clear = extended background mode off
;
; * Bit 7 = bit 9 of raster line for interrupt
LDA #%11000000 ; Set VIC register $11 to configure the screen control
STA VIC+$16 ; register as follows:
;
; * Bits 0-2 = horizontal raster scroll of 0
;
; * Bit 3 clear = screen width of 38 columns
;
; * Bit 4 clear = standard bitmap mode
;
; Bits 6 and 7 don't appear to have any effect, so I'm
; not sure why they are being set
LDA #%00000000 ; Clear bits 0 to 7 of VIC register $15 to disable all
STA VIC+$15 ; eight sprites
LDA #9 ; Set VIC register $29 to set the colour of sprite 2 to
STA VIC+$29 ; the colour number in bits 0-3 (i.e. colour 9, brown),
; so this makes Trumble 0 brown
LDA #12 ; Set VIC register $2A to set the colour of sprite 3 to
STA VIC+$2A ; the colour number in bits 0-3 (i.e. colour 12, grey),
; so this makes Trumble 1 grey
LDA #6 ; Set VIC register $2B to set the colour of sprite 4 to
STA VIC+$2B ; the colour number in bits 0-3 (i.e. colour 6, blue),
; so this makes Trumble 2 blue
LDA #1 ; Set VIC register $2C to set the colour of sprite 5 to
STA VIC+$2C ; the colour number in bits 0-3 (i.e. colour 1, white),
; so this makes Trumble 3 white
LDA #5 ; Set VIC register $2D to set the colour of sprite 6 to
STA VIC+$2D ; the colour number in bits 0-3 (i.e. colour 5, green),
; so this makes Trumble 4 green
LDA #9 ; Set VIC register $2E to set the colour of sprite 7 to
STA VIC+$2E ; the colour number in bits 0-3 (i.e. colour 9, brown),
; so this makes Trumble 5 brown
LDA #8 ; Set VIC register $25 to set sprite extra colour 1 to
STA VIC+$25 ; the colour number in bits 0-3 (i.e. colour 8, orange),
; for the explosion sprite
LDA #7 ; Set VIC register $26 to set sprite extra colour 2 to
STA VIC+$26 ; the colour number in bits 0-3 (i.e. colour 7, yellow),
; for the explosion sprite
LDA #%00000000 ; Clear bits 0 to 7 of VIC register $1C to set all seven
STA VIC+$1C ; sprites to single colour
LDA #%11111111 ; Set bits 0 to 7 of VIC register $17 to set all seven
STA VIC+$17 ; sprites to double height
STA VIC+$1D ; Set bits 0 to 7 of VIC register $1D to set all seven
; sprites to double width
LDA #0 ; Clear bits 0 to 7 of VIC register $10 to zero bit 9 of
STA VIC+$10 ; the x-coordinate for all seven sprite
LDX #161 ; Position sprite 0 (the laser sights) at pixel
LDY #101 ; coordinates (161, 101), in the centre of the space
STX VIC+0 ; view
STY VIC+1
LDA #18 ; Position sprite 1 (the explosion sprite) at pixel
LDY #12 ; coordinates (18, 12)
STA VIC+2
STY VIC+3
ASL A ; Position sprite 2 (Trumble 0) at pixel coordinates
STA VIC+4 ; (36, 12)
STY VIC+5
ASL A ; Position sprite 3 (Trumble 1) at pixel coordinates
STA VIC+6 ; (72, 12)
STY VIC+7
ASL A ; Position sprite 4 (Trumble 2) at pixel coordinates
STA VIC+8 ; (144, 12)
STY VIC+9
LDA #14 ; Position sprite 5 (Trumble 3) at pixel coordinates
STA VIC+10 ; (14, 12)
STY VIC+11
ASL A ; Position sprite 6 (Trumble 4) at pixel coordinates
STA VIC+12 ; (28, 12)
STY VIC+13
ASL A ; Position sprite 7 (Trumble 5) at pixel coordinates
STA VIC+14 ; (56, 12)
STY VIC+15
LDA #%00000010 ; Set VIC register $1B to all clear bits apart from bit
STA VIC+$1B ; 1, so that:
;
; * Sprite 0 (the laser sights) are drawn in front of
; the screen contents
;
; * Sprite 1 (the explosion sprite) is drawn in behind
; the screen contents
;
; * Sprites 2 to 7 (the Trumble sprites) are drawn in
; front of the screen contents
;
; This ensures that when we change views in-game, the
; BLUEBAND routine will hide any part of the explosion
; sprite that's in the screen border area, as it fills
; the border with colour 1
; ******************************************************************************
;
; Name: Elite loader (Part 5 of 7)
; Type: Subroutine
; Category: Loader
; Summary: Configure the screen bitmap and copy colour data into screen RAM
; Deep dive: Colouring the Commodore 64 bitmap screen
;
; ******************************************************************************
; We start by clearing the screen bitmap from $4000 to
; $5FFF by zeroing this part of memory
LDA #0 ; Set the low byte of ZP(1 0) to 0
STA ZP
TAY ; Set Y = 0 to act as a byte counter
LDX #$40 ; Set X = $40 to use as the high byte of ZP(1 0), so the
; next instruction initialises ZP(1 0) to $4000
.LOOP2
STX ZP+1 ; Set the high byte of ZP(1 0) to X
.LOOP1
STA (ZP),Y ; Zero the Y-th byte of ZP(1 0)
INY ; Increment the byte counter in Y
BNE LOOP1 ; Loop back until we have zeroed a whole page at ZP(1 0)
LDX ZP+1 ; Set X to the high byte of ZP(1 0)
INX ; Increment X to point to the next page in memory
CPX #$60 ; Loop back to zero the next page in memory until we
BNE LOOP2 ; have zeroed all the way to $5FFF
; We now reset the two banks of screen RAM from $6000 to
; $63FF and $6400 to $67FF, so we can then populate them
; with colour data for the text view ($6000 to $63FF)
; and the space view ($6400 to $67FF)
LDA #$10 ; Set A to the colour byte that we want to fill both
; blocks of screen RAM with, which is $10 to set the
; palette to foreground colour 1 (red) and background
; colour 0 (black)
; At this point, X = $60 from above, which we use as the
; high byte of ZP(1 0), and ZP hasn't changed from zero,
; so the next instruction initialises ZP(1 0) to $6000
.LOOP3
STX ZP+1 ; Set the high byte of ZP(1 0) to X
.LOOP4
STA (ZP),Y ; Set the Y-th byte of ZP(1 0) to $10
INY ; Increment the byte counter
BNE LOOP4 ; Loop back until we have filled a whole page with the
; red/black palette byte
LDX ZP+1 ; Set X to the high byte of ZP(1 0)
INX ; Increment X to point to the next page in memory
CPX #$68 ; Loop back to zero the next page in memory until we
BNE LOOP3 ; have zeroed all the way to $67FF
; Next, we populate screen RAM for the space view ($6400
; to $67FF), starting with the dashboard in the lower
; part of the screen
LDA #LO(SCBASE+$2400+$2D0) ; Set ZP(1 0) to the address within the space
STA ZP ; view's screen RAM that corresponds to the
LDA #HI(SCBASE+$2400+$2D0) ; dashboard (i.e. offset $2D0 within the screen
STA ZP+1 ; RAM at SCBASE + $2400, or $6400)
LDA #LO(sdump) ; Set (A ZP2) = sdump
STA ZP2
LDA #HI(sdump)
JSR mvsm ; Call mvsm to copy 280 bytes of data from sdump to the
; dashboard's screen RAM for the space view, so this
; sets the correct colour data for the dashboard (along
; with the data that we copy into colour RAM in part 6)
;LDX #0 ; These instructions are commented out in the original
; ; source
;.LOOP20
;
;LDA date,X
;STA SCBASE+$7A0,X
;
;DEX
;
;BNE LOOP20
; Now we populate screen RAM for the text view ($6000
; to $63FF) to set the correct colour for the border box
; around the edges of the screen
;
; The screen borders are four character blocks wide on
; each side of the screen (so the 256-pixel wide game
; screen gets shown in the middle of the 320-pixel wide
; screen mode)
;
; The outside three character blocks show nothing and
; are plain black, which we achieve by setting both the
; foreground and background colours to black for these
; character blocks
;
; The innermost of the four character blocks on each
; side is used to draw the border box, with the border
; being right up against the game screen, so for this we
; need a palette of yellow on black, so we can draw the
; border box in yellow
LDA #0 ; Set ZP(1 0) = $6000
STA ZP ;
LDA #$60 ; So ZP(1 0) points to screen RAM for the text view
STA ZP+1
LDX #25 ; The text view is 25 character rows high, so set a row
; counter in X
.LOOP10
LDA #$70 ; Set A to the colour byte that we want to apply to the
; border box, which is $70 to set the palette to
; foreground colour 7 (yellow) and background colour 0
; (black)
LDY #36 ; Set the colour data for column 36 (i.e. the right edge
STA (ZP),Y ; of the border box) to the yellow/black palette
LDY #3 ; Set the colour data for column 3 (i.e. the left edge
STA (ZP),Y ; of the border box) to the yellow/black palette
; Next, we set the palette to black on black for the
; outside three character blocks on the left side of the
; screen, so they don't show anything at all
DEY ; Set Y = 2 to use as a column counter for the three
; character blocks, so we work our way through columns
; 2, 1 and 0
LDA #$00 ; Set A to the colour byte that we want to apply to the
; outer border area, which is $00 to set the palette to
; foreground colour 0 (black) and background colour 0
; (black)
.frogl
STA (ZP),Y ; Set the colour data for column Y to the black/black
; palette
DEY ; Decrement the column counter
BPL frogl ; Loop back until we have set all three character blocks
; on the left edge of this character row to the
; black/black palette
; And now we set the palette to black on black for the
; outside three character blocks on the right side of
; the screen, so they also show nothing
LDY #37 ; Set Y = 2 to use as a column counter for the three
; character blocks, so we work our way through columns
; 37, 38 and 39
STA (ZP),Y ; Set the colour data for column 37 to the black/black
; palette
INY ; Set the colour data for column 38 to the black/black
STA (ZP),Y ; palette
INY ; Set the colour data for column 39 to the black/black
STA (ZP),Y ; palette
LDA ZP ; Set ZP(1 0) = ZP(1 0) + 40
CLC ;
ADC #40 ; So ZP(1 0) points to the next character row in screen
STA ZP ; RAM (as there are 40 character blocks on each row)
BCC P%+4
INC ZP+1
DEX ; Decrement the row counter in X
BNE LOOP10 ; Loop back until we have set the colour data for the
; left and right border box edges in the text view
; Now we populate screen RAM for the text view ($6000
; to $63FF) to set the correct colour for the border box
; around the edges of the space view
LDA #0 ; Set ZP(1 0) = $6400
STA ZP ;
LDA #$64 ; So ZP(1 0) points to screen RAM for the space view
STA ZP+1
LDX #18 ; The space view is 18 character rows high, so set a row
; counter in X
.LOOP11
LDA #$70 ; Set A to the colour byte that we want to apply to the
; border box, which is $70 to set the palette to
; foreground colour 7 (yellow) and background colour 0
; (black)
LDY #36 ; Set the colour data for column 36 (i.e. the right edge
STA (ZP),Y ; of the border box) to the yellow/black palette
LDY #3 ; Set the colour data for column 3 (i.e. the left edge
STA (ZP),Y ; of the border box) to the yellow/black palette
; Next, we set the palette to black on black for the
; outside three character blocks on the left side of the
; screen, so they don't show anything at all
DEY ; Set Y = 2 to use as a column counter for the three
; character blocks, so we work our way through columns
; 2, 1 and 0
LDA #$00 ; Set A to the colour byte that we want to apply to the
; outer border area, which is $00 to set the palette to
; foreground colour 0 (black) and background colour 0
; (black)
.newtl
STA (ZP),Y ; Set the colour data for column Y to the black/black
; palette
DEY ; Decrement the column counter
BPL newtl ; Loop back until we have set all three character blocks
; on the left edge of this character row to the
; black/black palette
; And now we set the palette to black on black for the
; outside three character blocks on the right side of
; the screen, so they also show nothing
LDY #37 ; Set Y = 2 to use as a column counter for the three
; character blocks, so we work our way through columns
; 37, 38 and 39
STA (ZP),Y ; Set the colour data for column 37 to the black/black
; palette
INY ; Set the colour data for column 38 to the black/black
STA (ZP),Y ; palette
INY ; Set the colour data for column 39 to the black/black
STA (ZP),Y ; palette
LDA ZP ; Set ZP(1 0) = ZP(1 0) + 40
CLC ;
ADC #40 ; So ZP(1 0) points to the next character row in screen
STA ZP ; RAM (as there are 40 character blocks on each row)
BCC P%+4
INC ZP+1
DEX ; Decrement the row counter in X
BNE LOOP11 ; Loop back until we have set the colour data for the
; left and right border box edges in the space view
; Finally, we set the colour data for the bottom row in
; the text view, so the bottom of the border box is also
; shown in yellow
LDA #$70 ; Set A to the colour byte that we want to apply to the
; border box, which is $70 to set the palette to
; foreground colour 7 (yellow) and background colour 0
; (black)
LDY #31 ; Set a counter in Y to work through the 31 character
; columns in the text view
.LOOP16
STA $63C4,Y ; Set the colour data for column Y + 4 on row 24 to
; yellow on black
;
; The address breaks down as follows:
;
; $63C4 = $6000 + 24 * 40 + 4
;
; So $63C4 + Y is column Y + 4 on row 24 and this loop
; sets the colour for the bottom character row of the
; text view
DEY ; Decrement the column counter
BPL LOOP16 ; Loop back until we have set the colour for the bottom
; border box in the text view
; ******************************************************************************
;
; Name: Elite loader (Part 6 of 7)
; Type: Subroutine
; Category: Loader
; Summary: Copy colour data into colour RAM and configure more screen RAM