-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathelite-loader.asm
2072 lines (1649 loc) · 68.1 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
\ ******************************************************************************
\
\ ACORN ELECTRON ELITE LOADER SOURCE
\
\ Acorn Electron Elite was written by Ian Bell and David Braben and is copyright
\ Acornsoft 1984
\
\ The code in this file has been reconstructed from a disassembly of the version
\ released on Ian Bell's personal website at http://www.elitehomepage.org/
\
\ 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 Acorn Electron Elite.
\
\ ------------------------------------------------------------------------------
\
\ This source file produces the following binary file:
\
\ * ELITEDA.bin
\
\ ******************************************************************************
INCLUDE "1-source-files/main-sources/elite-build-options.asm"
_IB_SUPERIOR = (_VARIANT = 1)
_IB_ACORNSOFT = (_VARIANT = 2)
GUARD &5800 \ Guard against assembling over screen memory
\ ******************************************************************************
\
\ Configuration variables
\
\ ******************************************************************************
CODE% = &4400 \ The address where the code will be run
LOAD% = &4400 \ The address where the code will be loaded
N% = 17 \ N% is set to the number of bytes in the VDU table, so
\ we can loop through them in part 2 below
USERV = &0200 \ The address of the user vector
BRKV = &0202 \ The address of the break vector
IRQ1V = &0204 \ The address of the interrupt vector
WRCHV = &020E \ The address of the write character vector
RDCHV = &0210 \ The address of the read character vector
KEYV = &0228 \ The address of the keyboard vector
LE% = &0B00 \ LE% is the address to which the code from UU% onwards
\ is copied in part 3
C% = &0D00 \ C% is set to the location that the main game code gets
\ moved to after it is loaded
IF _DISC
L% = &2000 \ L% is the load address of the main game code file
ELSE
L% = &0E00 \ L% is the load address of the main game code file
ENDIF
S% = C% \ S% points to the entry point for the main game code
VIA = &FE00 \ Memory-mapped space for accessing internal hardware,
\ such as the video ULA, 6845 CRTC and 6522 VIAs (also
\ known as SHEILA)
OSWRCH = &FFEE \ The address for the OSWRCH routine
OSBYTE = &FFF4 \ The address for the OSBYTE routine
OSWORD = &FFF1 \ The address for the OSWORD routine
OSCLI = &FFF7 \ The address for the OSCLI routine
\ ******************************************************************************
\
\ Name: ZP
\ Type: Workspace
\ Address: &0004 to &0005 and &0070 to &0086
\ Category: Workspaces
\ Summary: Important variables used by the loader
\
\ ******************************************************************************
ORG &0004
.TRTB%
SKIP 2 \ Contains the address of the keyboard translation
\ table, which is used to translate internal key
\ numbers to ASCII
ORG &0070
.ZP
SKIP 2 \ Stores addresses used for moving content around
.P
SKIP 1 \ Temporary storage, used in a number of places
.Q
SKIP 1 \ Temporary storage, used in a number of places
.YY
SKIP 1 \ Temporary storage, used in a number of places
.T
SKIP 1 \ Temporary storage, used in a number of places
.SC
SKIP 1 \ Screen address (low byte)
\
\ Elite draws on-screen by poking bytes directly into
\ screen memory, and SC(1 0) is typically set to the
\ address of the character block containing the pixel
\ we want to draw
.SCH
SKIP 1 \ Screen address (high byte)
.BLPTR
SKIP 2 \ Gets set to &03CA as part of the obfuscation code
.V219
SKIP 2 \ Gets set to &0218 as part of the obfuscation code
SKIP 4 \ These bytes appear to be unused
.K3
SKIP 1 \ Temporary storage, used in a number of places
.BLCNT
SKIP 2 \ Stores the tape loader block count as part of the copy
\ protection code in IRQ1
.BLN
SKIP 2 \ Gets set to &03C6 as part of the obfuscation code
.EXCN
SKIP 2 \ Gets set to &03C2 as part of the obfuscation code
\ ******************************************************************************
\
\ ELITE LOADER
\
\ ******************************************************************************
ORG CODE%
\ ******************************************************************************
\
\ Name: Elite loader (Part 1 of 5)
\ Type: Subroutine
\ Category: Loader
\ Summary: Include binaries for recursive tokens and images
\
\ ------------------------------------------------------------------------------
\
\ The loader bundles a number of binary files in with the loader code, and moves
\ them to their correct memory locations in part 3 below.
\
\ There is one file containing code:
\
\ * WORDS9.bin contains the recursive token table, which is moved to &0400
\ before the main game is loaded
\
\ and four files containing images, which are all moved into screen memory by
\ the loader:
\
\ * P.A-SOFT.bin contains the "ACORNSOFT" title across the top of the loading
\ screen, which gets moved to screen address &5960, on the second character
\ row of the space view
\
\ * P.ELITE.bin contains the "ELITE" title across the top of the loading
\ screen, which gets moved to screen address &5B00, on the fourth character
\ row of the space view
\
\ * P.(C)ASFT.bin contains the "(C) Acornsoft 1984" title across the bottom
\ of the loading screen, which gets moved to screen address &73A0, the
\ penultimate character row of the space view, just above the dashboard
\
\ * P.DIALS.bin contains the dashboard, which gets moved to screen address
\ &7620, which is the starting point of the dashboard, just below the space
\ view
\
\ The routine ends with a jump to the start of the loader code at ENTRY.
\
\ ******************************************************************************
PRINT "WORDS9 = ", ~P%
INCBIN "3-assembled-output/WORDS9.bin"
ALIGN 256
PRINT "P.DIALS = ", ~P%
INCBIN "1-source-files/images/P.DIALS.bin"
PRINT "P.ELITE = ", ~P%
INCBIN "1-source-files/images/P.ELITE.bin"
PRINT "P.A-SOFT = ", ~P%
INCBIN "1-source-files/images/P.A-SOFT.bin"
PRINT "P.(C)ASFT = ", ~P%
INCBIN "1-source-files/images/P.(C)ASFT.bin"
.run
JMP ENTRY \ Jump to ENTRY to start the loading process
\ ******************************************************************************
\
\ Name: B%
\ Type: Variable
\ Category: Drawing the screen
\ Summary: VDU commands for changing to a standard mode 4 screen
\
\ ------------------------------------------------------------------------------
\
\ This block contains the bytes that get written by OSWRCH to set up the screen
\ mode (this is equivalent to using the VDU statement in BASIC).
\
\ The Electron version of Elite is unique in that it uses a standard mode 4
\ screen, rather than the custom square mode used in the BBC versions. This is
\ because the Electron lacks the 6845 CRTC chip, which the BBC versions use to
\ customise the mode.
\
\ To make the Electron screen appear square like the BBC versions, there is a
\ blank 32-byte (&20-byte) margin on each end of each character row, so each
\ character row consists of 32 blank bytes on the left, then a page (256 bytes)
\ of screen memory containing the game display, then another 32 blank bytes on
\ the right. Screen memory is from &5800 to &7FFF, and the bottom row from &7EC0
\ to &7FFF is left blank, again to be consistent with look of the BBC version.
\ This means the screen takes up more memory on the Electron version than on the
\ BBC versions, despite showing the same amount of content.
\
\ On top of this, the Electron also lacks the Video ULA of the BBC Micro, so the
\ famous split-screen mode of the BBC versions can't be implemented in the
\ Electron version, as the BBC versions reprogram the ULA to create the coloured
\ dashboard. As a result, not only does the Electron suffer from the bigger
\ memory footprint of the screen, it also has to stick to the same palette for
\ the whole screen, so while the space view is the same monochrome mode 4 view
\ as in the BBC versions, the dashboard has to be in the same screen mode, so
\ it's also monochrome (though it has twice the number of horizontal pixels as
\ the four-colour mode 5 dashboard of the BBC versions, so it is noticeably
\ sharper, at least).
\
\ The following are also set up:
\
\ * The text window is 9 rows high and 15 columns wide, and is at (8, 10)
\
\ * The cursor is disabled
\
\ ******************************************************************************
.B%
EQUB 22, 4 \ Switch to screen mode 4
IF _DISC
EQUB 28 \ Define a text window as follows:
EQUB 8, 19, 23, 10 \
\ * Left = 8
\ * Right = 23
\ * Top = 10
\ * Bottom = 19
\
\ i.e. 9 rows high, 15 columns wide at (8, 10)
ELSE
EQUB 28 \ Define a text window as follows:
EQUB 8, 23, 23, 14 \
\ * Left = 8
\ * Right = 23
\ * Top = 14
\ * Bottom = 23
\
\ i.e. 9 rows high, 15 columns wide at (8, 14)
\
\ This is slightly lower than the default window, as
\ otherwise the cassette's loading message overwrites
\ the main code file as it loads into screen memory
ENDIF
EQUB 23, 1, 0, 0 \ Disable the cursor
EQUB 0, 0, 0
EQUB 0, 0, 0
\ ******************************************************************************
\
\ Name: E%
\ Type: Variable
\ Category: Sound
\ Summary: Sound envelope definitions
\
\ ------------------------------------------------------------------------------
\
\ This table contains the sound envelope data, which is passed to OSWORD by the
\ FNE macro to create the four sound envelopes used in-game. Refer to chapter 22
\ of the Acorn Electron User Guide for details of sound envelopes and what all
\ the parameters mean.
\
\ The envelopes are as follows:
\
\ * Envelope 1 is the sound of our own laser firing
\
\ * Envelope 2 is the sound of lasers hitting us, or hyperspace
\
\ * Envelope 3 is the first sound in the two-part sound of us dying, or the
\ second sound in the two-part sound of us hitting or killing an enemy ship
\
\ * Envelope 4 is the sound of E.C.M. firing
\
\ ******************************************************************************
.E%
EQUB 1, 1, 0, 111, -8, 4, 1, 8, 126, 0, 0, -126, 126, 126
EQUB 2, 1, 14, -18, -1, 44, 32, 50, 6, 1, 0, -2, 120, 126
EQUB 3, 1, 1, -1, -3, 17, 32, 128, 1, 0, 0, -1, 1, 1
EQUB 4, 1, 4, -8, 44, 4, 6, 8, 22, 0, 0, -127, 126, 0
\ ******************************************************************************
\
\ Name: swine
\ Type: Subroutine
\ Category: Copy protection
\ Summary: Resets the machine if the copy protection detects a problem
\
\ ******************************************************************************
.swine
JMP (&FFFC) \ Jump to the address in &FFFC to reset the machine
\ ******************************************************************************
\
\ Name: OSB
\ Type: Subroutine
\ Category: Utility routines
\ Summary: A convenience routine for calling OSBYTE with Y = 0
\
\ ******************************************************************************
.OSB
LDY #0 \ Call OSBYTE with Y = 0, returning from the subroutine
JMP OSBYTE \ using a tail call (so we can call OSB to call OSBYTE
\ for when we know we want Y set to 0)
\ ******************************************************************************
\
\ Name: Authors' names
\ Type: Variable
\ Category: Copy protection
\ Summary: The authors' names, buried in the code
\
\ ------------------------------------------------------------------------------
\
\ Contains the authors' names, plus an unused OS command string that would
\ *RUN the main game code, which isn't what actually happens (so presumably
\ this is to throw the crackers off the scent).
\
\ ******************************************************************************
EQUS "RUN ELITEcode"
EQUB 13
EQUS "By D.Braben/I.Bell"
EQUB 13
EQUB &B0
\ ******************************************************************************
\
\ Name: oscliv
\ Type: Variable
\ Category: Utility routines
\ Summary: Contains the address of OSCLIV, for executing OS commands
\
\ ******************************************************************************
.oscliv
EQUW &FFF7 \ Address of OSCLIV, for executing OS commands
\ (specifically the *LOAD that loads the main game code)
\ ******************************************************************************
\
\ Name: David9
\ Type: Variable
\ Category: Copy protection
\ Summary: Address used as part of the stack-based decryption loop
\
\ ------------------------------------------------------------------------------
\
\ This address is used in the decryption loop starting at David2 in part 4, and
\ is used to jump back into the loop at David5.
\
\ ******************************************************************************
.David9
EQUW David5 \ The address of David5
CLD \ This instruction is not used
\ ******************************************************************************
\
\ Name: David23
\ Type: Variable
\ Category: Copy protection
\ Summary: Address pointer to the start of the 6502 stack
\
\ ------------------------------------------------------------------------------
\
\ This two-byte address points to the start of the 6502 stack, which descends
\ from the end of page 2, less LEN bytes, which comes out as &01DF. So when we
\ push 33 bytes onto the stack (LEN being 33), this address will point to the
\ start of those bytes, which means we can push executable code onto the stack
\ and run it by calling this address with a JMP (David23) instruction. Sneaky
\ stuff!
\
\ ******************************************************************************
.David23
EQUW 6 \ This value is not used in this unprotected version of
\ the loader, though why the crackers set it to 6 is a
\ mystery
\ ******************************************************************************
\
\ Name: doPROT1
\ Type: Subroutine
\ Category: Copy protection
\ Summary: Routine to self-modify the loader code
\
\ ------------------------------------------------------------------------------
\
\ This routine modifies various bits of code in-place as part of the copy
\ protection mechanism. It is called with A = &48 and X = 255.
\
\ ******************************************************************************
.doPROT1
LDY #&DB \ Store &EFDB in TRTB%(1 0) to point to the keyboard
STY TRTB% \ translation table for OS 0.1 (which we will overwrite
LDY #&EF \ with a call to OSBYTE later)
STY TRTB%+1
LDY #2 \ Set the high byte of V219(1 0) to 2
STY V219+1
CMP swine-5,X \ This part of the loader has been disabled by the
\ crackers, by changing an STA to a CMP (as this is an
\ unprotected version)
LDY #&18 \ Set the low byte of V219(1 0) to &18 (as X = 255), so
STY V219+1,X \ V219(1 0) now contains &0218
RTS \ Return from the subroutine
\ ******************************************************************************
\
\ Name: MHCA
\ Type: Variable
\ Category: Copy protection
\ Summary: Used to set one of the vectors in the copy protection code
\
\ ------------------------------------------------------------------------------
\
\ This value is used to set the low byte of BLPTR(1 0), when it's set in PLL1
\ as part of the copy protection.
\
\ ******************************************************************************
.MHCA
EQUB &CA \ The low byte of BLPTR(1 0)
\ ******************************************************************************
\
\ Name: David7
\ Type: Subroutine
\ Category: Copy protection
\ Summary: Part of the multi-jump obfuscation code in PROT1
\
\ ------------------------------------------------------------------------------
\
\ This instruction is part of the multi-jump obfuscation in PROT1 (see part 2 of
\ the loader), which does the following jumps:
\
\ David8 -> FRED1 -> David7 -> Ian1 -> David3
\
\ ******************************************************************************
.David7
BCC Ian1 \ This instruction is part of the multi-jump obfuscation
\ in PROT1
\ ******************************************************************************
\
\ Name: FNE
\ Type: Macro
\ Category: Sound
\ Summary: Macro definition for defining a sound envelope
\
\ ------------------------------------------------------------------------------
\
\ The following macro is used to define the four sound envelopes used in the
\ game. It uses OSWORD 8 to create an envelope using the 14 parameters in the
\ I%-th block of 14 bytes at location E%. This OSWORD call is the same as BBC
\ BASIC's ENVELOPE command.
\
\ See variable E% for more details of the envelopes themselves.
\
\ ******************************************************************************
MACRO FNE I%
LDX #LO(E%+I%*14) \ Set (Y X) to point to the I%-th set of envelope data
LDY #HI(E%+I%*14) \ in E%
LDA #8 \ Call OSWORD with A = 8 to set up sound envelope I%
JSR OSWORD
ENDMACRO
\ ******************************************************************************
\
\ Name: Elite loader (Part 2 of 5)
\ Type: Subroutine
\ Category: Loader
\ Summary: Perform a number of OS calls, set up sound, push routines on stack
\
\ ------------------------------------------------------------------------------
\
\ This part of the loader does a number of calls to OS routines, sets up the
\ sound envelopes, and pushes 33 bytes onto the stack. A lot of the code in this
\ routine has been removed or hobbled to remove the protection; for a full
\ picture of the protection that's missing, see the source code for the BBC
\ Micro cassette version, which contains almost exactly the same protection code
\ as the original Electron version.
\
\ ------------------------------------------------------------------------------
\
\ Other entry points:
\
\ Ian1 Re-entry point following the wild goose chase
\ obfuscation
\
\ ******************************************************************************
.ENTRY
NOP \ This part of the loader has been disabled by the
NOP \ crackers, as this is an unprotected version NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
LDA #&60 \ This appears to be a lone instruction left over from
STA &0088 \ the unprotected code, as this value is never used
NOP \ This part of the loader has been disabled by the
NOP \ crackers, as this is an unprotected version
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
LDA #&20 \ Set A to the op code for a JSR call with absolute
\ addressing
NOP \ This part of the loader has been disabled by the
\ crackers, as this is an unprotected version
.Ian1
NOP \ This part of the loader has been disabled by the
NOP \ crackers, as this is an unprotected version
NOP
NOP
NOP
LSR A \ Set A = 16
LDX #3 \ Set the high bytes of BLPTR(1 0), BLN(1 0) and
STX BLPTR+1 \ EXCN(1 0) to &3. We will fill in the high bytes in
STX BLN+1 \ the PLL1 routine, and will then use these values in
STX EXCN+1 \ the IRQ1 handler
LDX #0 \ Call OSBYTE with A = 16 and X = 0 to set the joystick
LDY #0 \ port to sample 0 channels (i.e. disable it)
JSR OSBYTE
LDX #255 \ Call doPROT1 to change an instruction in the PROT1
LDA #&95 \ routine and set up another couple of variables
JSR doPROT1
LDA #144 \ Call OSBYTE with A = 144, X = 255 and Y = 0 to move
JSR OSB \ the screen down one line and turn screen interlace on
EQUB &2C \ Skip the next instruction by turning it into
\ &2C &D0 &92, or BIT &92D0, which does nothing apart
\ from affect the flags
.FRED1
BNE David7 \ This instruction is skipped if we came from above,
\ otherwise this is part of the multi-jump obfuscation
\ in PROT1
LDA #247 \ Call OSBYTE with A = 247 and X = Y = 0 to disable the
LDX #0 \ BREAK intercept code by poking 0 into the first value
JSR OSB
LDA #143 \ Call OSBYTE 143 to issue a paged ROM service call of
LDX #&C \ type &C with argument &FF, which is the "NMI claim"
LDY #&FF \ service call that asks the current user of the NMI
JSR OSBYTE \ space to clear it out
LDA #13 \ Set A = 13 for the next OSBYTE call
.abrk
LDX #0 \ Call OSBYTE with A = 13, X = 0 and Y = 0 to disable
JSR OSB \ the "output buffer empty" event
LDA #225 \ Call OSBYTE with A = 225, X = 128 and Y = 0 to set
LDX #128 \ the function keys to return ASCII codes for SHIFT-fn
JSR OSB \ keys (i.e. add 128)
LDA #172 \ Call OSBYTE 172 to read the address of the MOS
LDX #0 \ keyboard translation table into (Y X)
LDY #255
JSR OSBYTE
STX TRTB% \ Store the address of the keyboard translation table in
STY TRTB%+1 \ TRTB%(1 0)
NOP \ This part of the loader has been disabled by the
NOP \ crackers, as this is an unprotected version
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
LDA #13 \ Call OSBYTE with A = 13, X = 2 and Y = 0 to disable
LDX #2 \ the "character entering keyboard buffer" event
JSR OSB
.OS01
LDX #&FF \ Set the stack pointer to &01FF, which is the standard
TXS \ location for the 6502 stack, so this instruction
\ effectively resets the stack
INX \ Set X = 0, to use as a counter in the following loop
\ The following loop copies the crunchit routine into
\ zero page, though this unprotected version of the
\ loader doesn't call it there, so this has no effect
LDY #0 \ Set a counter in Y for the copy
.David3
LDA crunchit,Y \ Copy the Y-th byte of crunchit
.PROT1
STA TRTB%+2,X \ And store it in the X-th byte of zero page after the
\ TRTB%(1 0) variable
INX \ Increment both byte counters
INY
CPY #33 \ Loop back to copy the next byte until we have copied
BNE David3 \ all 33 bytes
LDA #LO(B%) \ Set the low byte of ZP(1 0) to point to the VDU code
STA ZP \ table at B%
LDA #&95 \ This part of the loader has been disabled by the
BIT PROT1 \ crackers, as this is an unprotected version (the BIT
\ instruction is an STA instruction in the full version,
\ but it has been hobbled here)
LDA #HI(B%) \ Set the high byte of ZP(1 0) to point to the VDU code
STA ZP+1 \ table at B%
LDY #0 \ We are now going to send the N% VDU bytes in the table
\ at B% to OSWRCH to set up the screen mode
.LOOP
LDA (ZP),Y \ Pass the Y-th byte of the B% table to OSWRCH
JSR OSWRCH
INY \ Increment the loop counter
CPY #N% \ Loop back for the next byte until we have done them
BNE LOOP \ all (the number of bytes was set in N% above)
LDA #1 \ This part of the loader has been disabled by the
TAX \ crackers, as this is an unprotected version (the CMP
TAY \ instruction is an STA instruction in the full version,
LDA abrk+1 \ but it has been hobbled here)
CMP (V219),Y
LDA #4 \ Call OSBYTE with A = 4, X = 1 and Y = 0 to disable
JSR OSB \ cursor editing, so the cursor keys return ASCII values
\ and can therefore be used in-game
LDA #9 \ Call OSBYTE with A = 9, X = 0 and Y = 0 to disable
LDX #0 \ flashing colours
JSR OSB
LDA #&6C \ This part of the loader has been disabled by the
NOP \ crackers, as this is an unprotected version (the BIT
NOP \ instruction is an STA instruction in the full version,
NOP \ but it has been hobbled here)
BIT &544F
FNE 0 \ Set up sound envelopes 0-3 using the FNE macro
FNE 1
FNE 2
FNE 3
\ ******************************************************************************
\
\ Name: Elite loader (Part 3 of 5)
\ Type: Subroutine
\ Category: Loader
\ Summary: Move recursive tokens and images
\
\ ------------------------------------------------------------------------------
\
\ Move the following memory blocks:
\
\ * WORDS9: move 4 pages (1024 bytes) from &4400 (CODE%) to &0400
\
\ * P.ELITE: move 1 page (256 bytes) from &4F00 (CODE% + &0B00) to &5BE0
\
\ * P.A-SOFT: move 1 page (256 bytes) from &5000 (CODE% + &0C00) to &5960
\
\ * P.(C)ASFT: move 1 page (256 bytes) from &5100 (CODE% + &0D00) to &73A0
\
\ * P.DIALS: move 7 pages (1792 bytes) from &4800 (CODE% + &0400) to &7620
\
\ * Move 1 page (256 bytes) from &5615 (UU%) to &0B00-&0BFF
\
\ and call the routine to draw Saturn between P.(C)ASFT and P.DIALS.
\
\ The dashboard image (P.DIALS) is moved into screen memory one page at a time,
\ but not in a contiguous manner - it has to take into account the &20 bytes of
\ blank margin at each edge of the screen (see the description of the screen
\ mode in B% above). So the seven rows of the dashboard are actually moved into
\ screen memory like this:
\
\ 1 page from &4800 to &7620 = &7620
\ 1 page from &4900 to &7720 + &40 = &7760
\ 1 page from &4A00 to &7820 + 2 * &40 = &78A0
\ 1 page from &4B00 to &7920 + 3 * &40 = &79E0
\ 1 page from &4C00 to &7A20 + 4 * &40 = &7B20
\ 1 page from &4D00 to &7B20 + 5 * &40 = &7C60
\ 1 page from &4E00 to &7C20 + 6 * &40 = &7DA0
\
\ See part 1 above for more details on the above files and the locations that
\ they are moved to.
\
\ The code at UU% (see below) forms part of the loader code and is moved before
\ being run, so it's tucked away safely while the main game code is loaded and
\ decrypted.
\
\ In the unprotected version of the loader, the images are encrypted and this
\ part also decrypts them, but this is an unprotected version of the game, so
\ the encryption part of the crunchit routine is disabled.
\
\ ******************************************************************************
LDX #4 \ Set the following:
STX P+1 \
LDA #HI(CODE%) \ P(1 0) = &0400
STA ZP+1 \ ZP(1 0) = CODE%
LDY #0 \ (X Y) = &400 = 1024
LDA #256-232 \
CMP (V219-4,X) \ The CMP instruction is an STA instruction in the
STY ZP \ protected version of the loader, but this version has
STY P \ been hacked to remove the protection, and the crackers
\ just switched the STA to a CMP to disable this bit of
\ the protection code
JSR crunchit \ Call crunchit to move &400 bytes from CODE% to &0400.
\ We loaded WORDS9.bin to CODE% in part 1, so this moves
\ WORDS9
LDX #1 \ Set the following:
LDA #(HI(CODE%)+&B) \
STA ZP+1 \ P(1 0) = &5BE0
LDA #&5B \ ZP(1 0) = CODE% + &B
STA P+1 \ (X Y) = &100 = 256
LDA #&E0
STA P
LDY #0
JSR crunchit \ Call crunchit to move &100 bytes from CODE% + &B to
\ &5BE0, so this moves P.ELITE
LDX #1 \ Set the following:
LDA #(HI(CODE%)+&C) \
STA ZP+1 \ P(1 0) = &5960
LDA #&59 \ ZP(1 0) = CODE% + &C
STA P+1 \ (X Y) = &100 = 256
LDA #&60
STA P
LDY #0
JSR crunchit \ Call crunchit to move &100 bytes from CODE% + &C to
\ &5960, so this moves P.A-SOFT
LDX #1 \ Set the following:
LDA #(HI(CODE%)+&D) \
STA ZP+1 \ P(1 0) = &73A0
LDA #&73 \ ZP(1 0) = CODE% + &D
STA P+1 \ (X Y) = &100 = 256
LDA #&A0
STA P
LDY #0
JSR crunchit \ Call crunchit to move &100 bytes from CODE% + &D to
\ &73A0, so this moves P.(C)ASFT
JSR PLL1 \ Call PLL1 to draw Saturn
LDA #(HI(CODE%)+4) \ Set the following:
STA ZP+1 \
LDA #&76 \ P(1 0) = &7620
STA P+1 \ ZP(1 0) = CODE% + &4
LDY #0 \ Y = 0
STY ZP \
LDX #&20 \ Also set BLCNT = 0
STY BLCNT
STX P
.dialsL
LDX #1 \ Set (X Y) = &100 = 256
JSR crunchit \ Call crunchit to move &100 bytes from ZP(1 0) to
\ P(1 0), so this moves P.DIALS one row at a time
CLC \ Set P(1 0) = P(1 0) + &40 to skip the screen margins
LDA P
ADC #&40
STA P
LDA P+1
ADC #0
STA P+1
CMP #&7E \ Loop back to copy the next row of the dashboard until
BCC dialsL \ we have poked the last one into screen memory
LDX #1 \ Set the following:
LDA #HI(UU%) \
STA ZP+1 \ P(1 0) = LE%
LDA #LO(UU%) \ ZP(1 0) = UU%
STA ZP \ (X Y) = &100 = 256
LDA #HI(LE%)
STA P+1
LDY #0
STY P
JSR crunchit \ Call crunchit to move &100 bytes from UU% to LE%
\ ******************************************************************************
\
\ Name: Elite loader (Part 4 of 5)
\ Type: Subroutine
\ Category: Loader
\ Summary: Call part 5 of the loader now that is has been relocated
\
\ ------------------------------------------------------------------------------
\
\ In the protected version of the loader, this part copies more code onto the
\ stack and decrypts a chunk of loader code before calling part 5, but in the
\ unprotected version it's mostly NOPs.
\
\ ******************************************************************************
JMP &0B11 \ Call relocated UU% routine to load the main game code
\ at &2000, move it down to &0D00 and run it
NOP \ This part of the loader has been disabled by the
NOP \ crackers, as this is an unprotected version
NOP
NOP
NOP
NOP
NOP
NOP
NOP