-
Notifications
You must be signed in to change notification settings - Fork 0
/
miner3.a
466 lines (401 loc) · 15.2 KB
/
miner3.a
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
;
; miner3.a ($3c00)
;
; Execution starts at 'miner3EntryPoint'
!src "constants.a"
; constants
; OS memory locations
currentLevel = $80 ;
; memory locations
* = $3000
; ***************************************************************************************
;
; called on vsync to update the audio
;
; ***************************************************************************************
mainEventRoutine
pha ;
php ;
txa ;
pha ; save registers
tya ;
pha ;
jsr checkForChannel3Update ;
lda channel2Frequency ;
cmp #$ff ;
beq silenceChannel2 ;
lda vsyncCounter ;
cmp #$ff ;
beq silenceChannel2 ;
lda #$b0 ;
jsr soundDirect ; Set channel 2 maximum volume
lda #$a0 ;
jsr soundDirect ; Set channel 2 frequency first byte
lda channel2Frequency ;
jsr soundDirect ; Set channel 2 frequency second byte
lda #$ff ;
sta channel2Frequency ;
exitEvent
pla ;
tay ;
pla ;
tax ; restore registers
plp ;
pla ;
rts ;
silenceChannel2
lda #$bf ;
jsr soundDirect ; set zero volume on channel 2
jmp exitEvent ;
checkForChannel3Update
inc vsyncCounter ;
lda vsyncCounter ;
cmp #1 ; 1 = duration of note
beq quietChannel3 ;
cmp #6 ; 6 = time between notes
beq updateChannel3 ; update channel 3
rts ;
updateChannel3
lda #0 ;
sta vsyncCounter ;
inc channel3Frequency ;
lda #$92 ;
jsr soundDirect ; Channel 3 volume
lda #$80 ;
jsr soundDirect ; Channel 3 frequency
lda channel3Frequency ;
lsr ;
tax ;
lda $00,x ;
cmp #0 ; [redundant]
beq finishChannel3Notes ;
jmp soundDirect ;
finishChannel3Notes
lda #$ff ;
sta channel3Frequency ; end channel 3 notes
rts ;
quietChannel3
lda #$9f ;
jmp soundDirect ; set zero volume on channel 3
; ***************************************************************************************
; send a byte to the sound chip (as seen in the advanced user guide)
soundDirect
sei ;
pha ; remember A
lda #151 ;
ldx #$43 ; Data direction register A
ldy #$ff ; Set all 8 bits as output
jsr OSBYTE ; Write to SHEILA OSBYTE CALL
ldx #$41 ; Output register A
pla ;
tay ; Y holds byte to sound chip
lda #151 ; Write to SHEILA OSBYTE CALL
jsr OSBYTE ; Output to slow data bus
ldx #$40 ; Output register B
ldy #0 ; Set sound chip write pin low
jsr OSBYTE ;
ldy #8 ; Set sound chip write pin high
jsr OSBYTE ;
cli ; Enable interrupts
rts ;
; ***************************************************************************************
vsyncCounter
!byte $ea ;
channel3Frequency
!byte $00 ;
channel2Frequency
!byte $ff ;
; ***************************************************************************************
playAttractLoop
lda #1 ;
sta currentLevel ; start attract loop on level 1
lda #2 ;
sta lives ; start with 2 remaining lives (3 lives total)
; clear the score (6 digits in 3 BCD bytes)
lda #0 ;
ldx #0 ;
-
sta score,x ;
inx ;
cpx #3 ;
bne - ;
attractLoop
lda currentLevel ;
jsr showLevel ;
lda #0 ;
sta attractModeTimer ;
showALevelLoop
jsr drawConveyors ;
jsr animateKeysUpdateHorizontalGuardiansAndLevel19EnergyFields ;
jsr updateVerticalGuardians ;
; pointless delay loop
ldx #0 ; 0
ldy #208 ; 208
-
inx ;
bne - ;
iny ;
bne - ;
inc attractModeTimer ;
lda attractModeTimer ;
cmp #$40 ;
beq showNextLevel ;
ldy #$ff ;
ldx #$b6 ;
lda #$81 ; check for RETURN
jsr OSBYTE ;
cpy #$ff ;
beq + ;
jmp showALevelLoop ;
+
jmp startGame ;
attractModeTimer
!byte $ea ;
showNextLevel
inc currentLevel ;
lda currentLevel ;
cmp #19 ;
beq endOfAttractLoop ;
jmp attractLoop ;
endOfAttractLoop
nop ;
nop ;
nop ;
nop ;
jmp miner3EntryPoint ;
; ***************************************************************************************
checkCheatCode
lda $ed ;
cmp #0 ;
bne resetCheatProgress ; if (two keys pressed) then branch (reset progress)
lda $ec ; read key pressed
and #$7f ; remove top bit set
cmp #0 ;
beq return2 ; if (nothing pressed) then branch (return)
ldx cheatCodeCounter ;
cmp cheatCode,x ;
beq incrementCheatCode ; if (next key in code pressed) then branch
dex ;
cmp cheatCode,x ;
beq return2 ; if (current key in code still pressed) then branch (return)
resetCheatProgress
lda #0 ;
sta cheatCodeCounter ;
rts ;
incrementCheatCode
inc cheatCodeCounter ;
lda cheatCodeCounter ;
cmp #cheatCodeEnd - cheatCode ;
beq toggleCheatMode ;
rts ;
toggleCheatMode
lda cheatModeEnabled ;
eor #1 ;
sta cheatModeEnabled ;
lda #$03 ; }
ldx #$64 ; }
ldy #$03 ; } SOUND
jmp playSoundAXY ; }
return2
rts ;
; ***************************************************************************************
cheatCodeCounter
!byte $00
cheatCode
; code: A <space> S, E, C, R, E, T
;
; key codes as stored in memory address $ec (by the OS) when pressed, all with top bit set:
; $C1, $E2, $D1, $A2, $D2, $B3, $A2, $A3
; stored here without top bit set:
!byte $41, $62, $51, $22, $52, $33, $22, $23
cheatCodeEnd
; ***************************************************************************************
!byte $60, $60 ; [UNUSED]
; ***************************************************************************************
updateVerticalGuardiansAndJumpAndFallSounds
jsr updateVerticalGuardians ;
lda isJumping ;
cmp #1 ;
bne notInAir ; if (not in air) then branch
lda jumpPhase ;
cmp #1 ;
bne notInAir ;
lda #$04 ; }
ldx #$64 ; }
ldy #$02 ; } play jump sound
jmp playSoundAXY ; }
notInAir
lda isJumping ;
cmp #1 ;
beq return5 ;
lda willyIsOnGround ;
cmp #0 ;
bne return5 ;
lda #$ff ;
sta oswordSoundBlock + 3 ;
lda newPlayerPixelY ; }
sec ; }
sbc playerHeightOnTakeOff ; }
asl ; }
eor #$7f ; } play descending falling sound
tax ; }
lda #$f1 ; }
ldy #1 ; }
jsr playSoundAXY ; }
lda #0 ;
sta oswordSoundBlock + 3 ;
return5
rts ;
!text "8:JSR" ; [UNUSED]
; ***************************************************************************************
miner3EntryPoint
jsr clearScreen ;
lda #17 ; VDU 17,3 (COLOUR 3)
jsr OSWRCH ;
lda #3 ;
jsr OSWRCH ;
jsr pauseMusic ;
; Show credits
ldx #0 ; loop counter
-
lda creditsMessage,x ;
jsr OSWRCH ;
inx ;
cpx #creditsMessageEnd - creditsMessage ;
bne - ;
; Show 'BY MATTHEW SMITH' line
ldx #0 ;
-
lda bylineMessage,x ;
jsr OSWRCH ;
inx ;
cpx #bylineMessageEnd - bylineMessage ;
bne - ;
; swap in the flowery logo
jsr swapPages700andC00 ;
; draw the flowery logo
ldx #$80 ; loop counter (and character to print)
-
txa ;
jsr OSWRCH ;
inx ;
cpx #$91 ;
bne - ;
; swap out the flowery logo
jsr swapPages700andC00 ;
; Colour the background on screen from $4030 in a rectangle
lda #$30 ;
sta $70 ;
lda #$40 ;
sta $71 ;
rectLoop
ldy #0 ;
-
lda ($70),y ;
ora #$f0 ;
sta ($70),y ;
iny ;
bne - ;
inc $71 ;
ldy #0 ;
-
lda ($70),y ;
ora #$f0 ;
sta ($70),y ;
iny ;
cpy #$18 ;
bne - ;
lda $70 ;
clc ;
adc #$80 ;
sta $70 ;
lda $71 ;
adc #1 ;
sta $71 ;
cmp #$51 ;
bne rectLoop ;
; plot triangle logo
ldx #$ff ;
plotLoop
jsr getNextByte ;
cmp #$ff ;
beq finishPlot ;
cmp #$fe ;
beq gcol ;
sta plotType ; PLOT type
jsr getNextByte ; Y coordinate low (top 2 bits) and X low (top two bits)
tay ;
lsr ;
lsr ;
lsr ;
lsr ;
lsr ;
lsr ;
sta plotXHigh ;
tya ;
asl ;
asl ;
sta plotXLow ;
jsr getNextByte ;
tay ;
lsr ;
lsr ;
lsr ;
lsr ;
lsr ;
lsr ;
sta plotYHigh ;
tya ;
asl ;
asl ;
sta plotYLow ;
; PLOT
ldy #0 ; loop counter
-
lda plotMessageStart,y ;
jsr OSWRCH ;
iny ;
cpy #plotMessageEnd - plotMessageStart ;
bne - ;
jmp plotLoop ;
finishPlot
jmp showTitleScreenMessageAndWaitForRETURN ;
gcol
lda #18 ;
jsr OSWRCH ;
lda #0 ; GCOL 0,next byte
jsr OSWRCH ;
jsr getNextByte ;
jsr OSWRCH ;
jmp plotLoop ;
getNextByte
inx ;
lda penroseTriangle,x ;
rts ;
swapPages700andC00
ldx #0 ; loop counter
-
lda $0700,x ;
tay ;
lda softCharacterDefinitions,x ;
sta $0700,x ;
tya ; swap $700->$7ff with $0c00->$0cff
sta softCharacterDefinitions,x ;
inx ;
bne - ;
rts ;
plotMessageStart
!byte 25 ; VDU 25
fiveValues
plotType
!byte $ea ;
plotXLow
!byte $ea ;
plotXHigh
!byte $ea ;
plotYLow
!byte $ea ;
plotYHigh
!byte $ea ;
plotMessageEnd
!byte $00, $00, $00, $00, $00, $00, $00 ; [UNUSED]