-
Notifications
You must be signed in to change notification settings - Fork 1
/
elite-loader2.asm
335 lines (266 loc) · 11 KB
/
elite-loader2.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
\ ******************************************************************************
\
\ 6502 SECOND PROCESSOR ELITE I/O LOADER (PART 2) SOURCE
\
\ 6502 Second Processor Elite was written by Ian Bell and David Braben and is
\ copyright Acornsoft 1985
\
\ The code on this site is identical to the source discs 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 produces the following binary file:
\
\ * ELITEa.bin
\
\ after reading in the following files:
\
\ * P.DIALS2P.bin
\ * P.DATE2P.bin
\ * Z.ACSOFT.bin
\ * Z.ELITE.bin
\ * Z.(C)ASFT.bin
\
\ ******************************************************************************
INCLUDE "1-source-files/main-sources/elite-build-options.asm"
_SOURCE_DISC = (_VARIANT = 1)
_SNG45 = (_VARIANT = 2)
_EXECUTIVE = (_VARIANT = 3)
GUARD &4000 \ Guard against assembling over screen memory
\ ******************************************************************************
\
\ Configuration variables
\
\ ******************************************************************************
CODE% = &2000 \ The address where the code will be run
LOAD% = &2000 \ The address where the code will be loaded
D% = &D000 \ The address where the ship blueprints get moved to
\ after loading, so they go from &D000 to &F200
OSCLI = &FFF7 \ The address for the OSCLI routine
\ ******************************************************************************
\
\ Name: ZP
\ Type: Workspace
\ Address: &0090 to &0093
\ Category: Workspaces
\ Summary: Important variables used by the loader
\
\ ******************************************************************************
ORG &0090
.Z1
SKIP 2 \ Temporary storage, used when moving code
.Z2
SKIP 2 \ Temporary storage, used when moving code
\ ******************************************************************************
\
\ ELITE LOADER
\
\ ******************************************************************************
ORG CODE%
\ ******************************************************************************
\
\ Name: MVE
\ Type: Macro
\ Category: Utility routines
\ Summary: Move a one-page block of memory from one location to another
\
\ ------------------------------------------------------------------------------
\
\ The following macro is used to move a block of memory from one location to
\ another:
\
\ MVE S%, D%, PA%
\
\ It is used to move the component parts of the loading screen into screen
\ memory, such as the dashboard background and Acornsoft copyright message.
\
\ ------------------------------------------------------------------------------
\
\ Arguments:
\
\ S% The source address of the block to move
\
\ D% The destination address of the block to move
\
\ PA% Number of pages of memory to move (1 page = 256 bytes)
\
\ ******************************************************************************
MACRO MVE S%, D%, PA%
LDA #LO(S%) \ Set Z1(1 0) = S%
STA Z1
LDA #HI(S%)
STA Z1+1
LDA #LO(D%) \ Set Z1(1 0) = D%
STA Z2
LDA #HI(D%)
STA Z2+1
LDX #PA% \ Set X = PA%
JSR MVBL \ Call MVBL to copy X pages from S% to D%
ENDMACRO
\ ******************************************************************************
\
\ Name: Elite loader (Part 1 of 2)
\ Type: Subroutine
\ Category: Loader
\ Summary: Move loading screen binaries into screen memory and load and run
\ the main game code
\
\ ******************************************************************************
.ENTRY
MVE DIALS, &7000, &E \ Move the binary at DIALS (the dashboard background) to
\ locations &7000-&7DFF in screen memory (14 pages)
\MVE DATE, &6000, &1 \ This instruction is commented out in the original
\ course, but it would move the binary at DATE to
\ locations &6000-&60FF in screen memory (1 page),
\ which would display the following message on the
\ loading screen: "2nd Pro ELITE -Finished 13/12/84"
MVE ASOFT, &4200, &1 \ Move the binary at ASOFT (the "Acornsoft" heading) to
\ locations &4200-&42FF in screen memory (1 page)
MVE ELITE, &4600, &1 \ Move the binary at ELITE (the "ELITE" heading) to
\ locations &4600-&46FF in screen memory (1 page)
MVE CpASOFT, &6C00, &1 \ Move the binary at CpASOFT (the Acornsoft copyright
\ message) to locations &6C00-&6CFF in screen memory
\ (1 page)
LDX #LO(MESS2) \ Set (Y X) to point to MESS2 ("R.I.CODE")
LDY #HI(MESS2)
JSR OSCLI \ Call OSCLI to run the OS command in MESS2, which *RUNs
\ the main I/O processor game code in I.CODE
LDX #LO(MESS3) \ Set (Y X) to point to MESS3 ("R.P.CODE")
LDY #HI(MESS3)
JMP OSCLI \ Call OSCLI to run the OS command in MESS3, which *RUNs
\ the main parasite game code in P.CODE, returning from
\ the subroutine using a tail call
\ ******************************************************************************
\
\ Name: MESS2
\ Type: Variable
\ Category: Loader
\ Summary: The OS command string for running the I/O processor's main game
\ code in file I.CODE
\
\ ******************************************************************************
.MESS2
EQUS "R.I.CODE" \ This is short for "*RUN I.CODE"
EQUB 13
\ ******************************************************************************
\
\ Name: MESS3
\ Type: Variable
\ Category: Loader
\ Summary: The OS command string for running the parasite's main game code
\ in file P.CODE
\
\ ******************************************************************************
.MESS3
EQUS "R.P.CODE" \ This is short for "*RUN P.CODE"
EQUB 13
\ ******************************************************************************
\
\ Name: MVBL
\ Type: Subroutine
\ Category: Utility routines
\ Summary: Move a multi-page block of memory from one location to another
\
\ ------------------------------------------------------------------------------
\
\ Arguments:
\
\ Z1(1 0) The source address of the block to move
\
\ Z2(1 0) The destination address of the block to move
\
\ X Number of pages of memory to move (1 page = 256 bytes)
\
\ ******************************************************************************
.MVPG
\ This subroutine is called from below to copy one page
\ of memory from the address in Z1(1 0) to the address
\ in Z2(1 0)
LDY #0 \ We want to move one page of memory, so set Y as a byte
\ counter
.MPL
LDA (Z1),Y \ Copy the Y-th byte of the Z1(1 0) memory block to the
STA (Z2),Y \ Y-th byte of the Z2(1 0) memory block
DEY \ Decrement the byte counter
BNE MPL \ Loop back to copy the next byte until we have done a
\ whole page of 256 bytes
RTS \ Return from the subroutine
.MVBL
JSR MVPG \ Call MVPG above to copy one page of memory from the
\ address in Z1(1 0) to the address in Z2(1 0)
INC Z1+1 \ Increment the high byte of the source address to point
\ to the next page
INC Z2+1 \ Increment the high byte of the destination address to
\ point to the next page
DEX \ Decrement the page counter
BPL MVBL \ Loop back to copy the next page until we have done X
\ pages
RTS \ Return from the subroutine
\ ******************************************************************************
\
\ Name: Elite loader (Part 2 of 2)
\ Type: Subroutine
\ Category: Loader
\ Summary: Include binaries for loading screen and dashboard images
\
\ ------------------------------------------------------------------------------
\
\ The loader bundles a number of binary files in with the loader code, and moves
\ them to their correct memory locations in part 1 above.
\
\ There are five files, all containing images, which are all moved into screen
\ memory by the loader:
\
\ * Z.ACSOFT.bin contains the "ACORNSOFT" title across the top of the loading
\ screen, which gets moved to screen address &4200, on the second character
\ row of the mode 1 part of the screen (the top part)
\
\ * Z.ELITE.bin contains the "ELITE" title across the top of the loading
\ screen, which gets moved to screen address &4600, on the fourth character
\ row of the mode 1 part of the screen (the top part)
\
\ * Z.(C)ASFT.bin contains the "(C) Acornsoft 1984" title across the bottom
\ of the loading screen, which gets moved to screen address &6C00, the
\ penultimate character row of the top part of the screen, just above the
\ dashboard
\
\ * P.DIALS2P.bin contains the dashboard, which gets moved to screen address
\ &7000, which is the starting point of the eight-colour mode 2 portion at
\ the bottom of the split screen
\
\ * P.DATE2P.bin contains the version text "2nd Pro ELITE -Finished 13/12/84",
\ though the code to show this on-screen in part 1 is commented out, as this
\ was presumably used to identify versions of the game during development.
\ If the MVE macro instruction in part 1 is uncommented, then this binary
\ gets moved to screen address &6000, which displays the version message in
\ the middle of the top part of the screen
\
\ ******************************************************************************
.DIALS
INCBIN "1-source-files/images/P.DIALS2P.bin"
.DATE
INCBIN "1-source-files/images/P.DATE2P.bin"
.ASOFT
INCBIN "1-source-files/images/Z.ACSOFT.bin"
.ELITE
INCBIN "1-source-files/images/Z.ELITE.bin"
.CpASOFT
INCBIN "1-source-files/images/Z.(C)ASFT.bin"
\ ******************************************************************************
\
\ Save ELITEa.bin
\
\ ******************************************************************************
PRINT "S.ELITEa ", ~CODE%, " ", ~P%, " ", ~LOAD%, " ", ~LOAD%
SAVE "3-assembled-output/ELITEa.bin", CODE%, P%, LOAD%