-
Notifications
You must be signed in to change notification settings - Fork 1
/
astro_turret_code.asm
453 lines (383 loc) · 12.2 KB
/
astro_turret_code.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
//////////////////////////////////////////////////////////////////////////////
// astro_turret_code.asm
// Copyright(c) 2021 Neal Smith.
// License: MIT. See LICENSE file in root directory.
//////////////////////////////////////////////////////////////////////////////
// The following subroutines should be called from the main engine
// as follows
// TurretInit: Call once before main loop and before other routines
// TurretStep: Call once every raster frame through the main loop
// TurretStart: Call to start the effect See subroutine header for params
// TurretActive: Call to determine if a turret active
// TurretForceStop: Call to force effect to stop if it is active
// TurretCleanup: Call at end of program after main loop to clean up
//////////////////////////////////////////////////////////////////////////////
#importonce
#import "../nv_c64_util/nv_c64_util_macs_and_data.asm"
#import "astro_vars_data.asm"
#import "astro_turret_data.asm"
#import "astro_stream_processor_code.asm"
//////////////////////////////////////////////////////////////////////////////
// call once to initialize turret variables and stuff
TurretInit:
lda #$00
sta turret_1_count
sta turret_2_count
sta turret_3_count
sta turret_4_count
sta turret_5_count
sta turret_6_count
ldx #<turret_init_stream // load stream LSB in x reg
ldy #>turret_init_stream // load stream MSB in y reg
jsr AstroStreamProcessor // stream include the byte to copy
// so don't load accum
rts
// TurretInit end
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// subroutine to start a turret shooting. The actual shooting will
// happen in TurretStep
// Params:
// Accum: set to the turret ID of the turret that should start
TurretStart:
// accum should be loaded by caller
sta turret_start_ids
TurretStartTry1:
lda #TURRET_1_ID
bit turret_start_ids
beq TurretStartTry2
TurretStartIs1:
lda #TURRET_1_FRAMES
sta turret_1_count
TurretStartTry2:
lda #TURRET_2_ID
bit turret_start_ids
beq TurretStartTry3
TurretStartIs2:
lda #TURRET_2_FRAMES
sta turret_2_count
TurretStartTry3:
lda #TURRET_3_ID
bit turret_start_ids
beq TurretStartTry4
TurretStartIs3:
lda #TURRET_3_FRAMES
sta turret_3_count
TurretStartTry4:
lda #TURRET_4_ID
bit turret_start_ids
beq TurretStartTry5
TurretStartIs4:
lda #TURRET_4_FRAMES
sta turret_4_count
TurretStartTry5:
lda #TURRET_5_ID
bit turret_start_ids
beq TurretStartTry6
TurretStartIs5:
lda #TURRET_5_FRAMES
sta turret_5_count
TurretStartTry6:
lda #TURRET_6_ID
bit turret_start_ids
beq TurretStartDone
TurretStartIs6:
lda #TURRET_6_FRAMES
sta turret_6_count
TurretStartDone:
rts
turret_start_ids: .byte 0
// TurretStart subroutine end
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// subroutine to determine if a turret is currently active
// Params:
// Accum: set to the turret ID of the turret to query,
// or TURRET_ALL_ID to know if any turret is active
// Return:
// Accum: will be zero if not active or non zero if is active
// TOOD: make it return a bit mask with one bit for each possible
// bullet so caller will know exactly which bullet is active
TurretLdaActive:
sta turret_active_ids
lda #$00
sta turret_active_retval
TurretActiveTry1:
lda #TURRET_1_ID
bit turret_active_ids
beq TurretActiveTry2
TurretActiveIs1:
ldx turret_1_count
beq TurretActiveTry2
ora turret_active_retval
sta turret_active_retval
TurretActiveTry2:
lda #TURRET_2_ID
bit turret_active_ids
beq TurretActiveTry3
TurretActiveIs2:
ldx turret_2_count
beq TurretActiveTry3
ora turret_active_retval
sta turret_active_retval
TurretActiveTry3:
lda #TURRET_3_ID
bit turret_active_ids
beq TurretActiveTry4
TurretActiveIs3:
ldx turret_3_count
beq TurretActiveTry4
ora turret_active_retval
sta turret_active_retval
TurretActiveTry4:
lda #TURRET_4_ID
bit turret_active_ids
beq TurretActiveTry5
TurretActiveIs4:
ldx turret_4_count
beq TurretActiveTry5
ora turret_active_retval
sta turret_active_retval
TurretActiveTry5:
lda #TURRET_5_ID
bit turret_active_ids
beq TurretActiveTry6
TurretActiveIs5:
ldx turret_5_count
beq TurretActiveTry6
ora turret_active_retval
sta turret_active_retval
TurretActiveTry6:
lda #TURRET_6_ID
bit turret_active_ids
beq TurretActiveDone
TurretActiveIs6:
ldx turret_6_count
beq TurretActiveDone
ora turret_active_retval
sta turret_active_retval
TurretActiveDone:
lda turret_active_retval
rts
turret_active_ids: .byte 0
turret_active_retval: .byte 0
// TurretActive subroutine end
//////////////////////////////////////////////////////////////////////////////
.macro turret_clear_rect(rect)
{
.var index
lda #$00
.for (index=0; index < 8; index++)
{
sta rect+index
}
}
.macro turret_force_stop_id_1()
{
turret_clear_rect(turret_1_bullet_rect)
lda #$00
sta turret_1_count
// all positions to background color
lda background_color
ldx #<turret_1_all_color_stream
ldy #>turret_1_all_color_stream
jsr AstroStreamProcessor
}
.macro turret_force_stop_id_2()
{
turret_clear_rect(turret_2_bullet_rect)
lda #0
sta turret_2_count
// all positions to background color
lda background_color
ldx #<turret_2_all_color_stream
ldy #>turret_2_all_color_stream
jsr AstroStreamProcessor
}
.macro turret_force_stop_id_3()
{
turret_clear_rect(turret_3_bullet_rect)
lda #0
sta turret_3_count
// all positions to background color
lda background_color
ldx #<turret_3_all_color_stream
ldy #>turret_3_all_color_stream
jsr AstroStreamProcessor
}
.macro turret_force_stop_id_4()
{
turret_clear_rect(turret_4_bullet_rect)
lda #$00
sta turret_4_count
// all positions to background color
lda background_color
ldx #<turret_4_all_color_stream
ldy #>turret_4_all_color_stream
jsr AstroStreamProcessor
}
.macro turret_force_stop_id_5()
{
turret_clear_rect(turret_5_bullet_rect)
lda #$00
sta turret_5_count
// all positions to background color
lda background_color
ldx #<turret_5_all_color_stream
ldy #>turret_5_all_color_stream
jsr AstroStreamProcessor
}
.macro turret_force_stop_id_6()
{
turret_clear_rect(turret_6_bullet_rect)
lda #0
sta turret_6_count
// all positions to background color
lda background_color
ldx #<turret_6_all_color_stream
ldy #>turret_6_all_color_stream
jsr AstroStreamProcessor
}
//////////////////////////////////////////////////////////////////////////////
// subroutine to force turret effect to stop if it is active. if not
// active then should do nothing
// Params:
// Accum: set to the turret ID of the turret to query,
// or TURRET_ALL_ID to know if any turret is active
//
TurretForceStop:
{
sta turret_force_stop_ids
TurretForceStopTry1:
lda #TURRET_1_ID
bit turret_force_stop_ids
bne TurretForceStopIs1
jmp TurretForceStopTry2
TurretForceStopIs1:
turret_force_stop_id_1()
TurretForceStopTry2:
lda #TURRET_2_ID
bit turret_force_stop_ids
bne TurretForceStopIs2
jmp TurretForceStopTry3
TurretForceStopIs2:
turret_force_stop_id_2()
TurretForceStopTry3:
lda #TURRET_3_ID
bit turret_force_stop_ids
bne TurretForceStopIs3
jmp TurretForceStopTry4
TurretForceStopIs3:
turret_force_stop_id_3()
TurretForceStopTry4:
lda #TURRET_4_ID
bit turret_force_stop_ids
bne TurretForceStopIs4
jmp TurretForceStopTry5
TurretForceStopIs4:
turret_force_stop_id_4()
TurretForceStopTry5:
lda #TURRET_5_ID
bit turret_force_stop_ids
bne TurretForceStopIs5
jmp TurretForceStopTry6
TurretForceStopIs5:
turret_force_stop_id_5()
TurretForceStopTry6:
lda #TURRET_6_ID
bit turret_force_stop_ids
bne TurretForceStopIs6
jmp TurretForceStopDone
TurretForceStopIs6:
turret_force_stop_id_6()
TurretForceStopDone:
lda turret_active_retval
rts
turret_force_stop_ids: .byte 0
}
// TurretForceStop end
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// subroutine to call at end of program when done with all other wind
// data and routines.
TurretCleanup:
lda #TURRET_ALL_ID
jsr TurretForceStop
rts
// TurretCleanup End
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// call once per frame to have turret shoot
TurretStep:
{
TurretStepTry1:
lda turret_1_count // check if turret is active (count != 0)
beq TurretStepTry2 // not zero so it is active
jsr Turret1DoStep
TurretStepTry2:
lda turret_2_count // check if turret is active (count != 0)
beq TurretStepTry3 // not zero so it is active
jsr Turret2DoStep
TurretStepTry3:
lda turret_3_count // check if turret is active (count != 0)
beq TurretStepTry4 // not zero so it is active
jsr Turret3DoStep
TurretStepTry4:
lda turret_4_count // check if turret is active (count != 0)
beq TurretStepTry5 // not zero so it is active
jsr Turret4DoStep
TurretStepTry5:
lda turret_5_count // check if turret is active (count != 0)
beq TurretStepTry6 // not zero so it is active
jsr Turret5DoStep
TurretStepTry6:
lda turret_6_count // check if turret is active (count != 0)
beq TurretStepDone // not zero so it is active
jsr Turret6DoStep
TurretStepDone:
rts
}
// TurretStep subroutine end
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// subroutine to call to step turret 1
Turret1DoStep:
astro_effect_step_sr(AstroStreamProcessor, turret_1_count,
TURRET_1_FRAMES, Turret1StreamAddrTable)
// Turret1DoStep - end
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// subroutine to call to step turret 2
Turret2DoStep:
astro_effect_step_sr(AstroStreamProcessor, turret_2_count,
TURRET_2_FRAMES, Turret2StreamAddrTable)
// Turret2DoStep - end
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// subroutine to call to step turret 3
Turret3DoStep:
astro_effect_step_sr(AstroStreamProcessor, turret_3_count,
TURRET_3_FRAMES, Turret3StreamAddrTable)
// Turret3DoStep - end
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// subroutine to call to step turret 4
Turret4DoStep:
astro_effect_step_sr(AstroStreamProcessor, turret_4_count,
TURRET_4_FRAMES, Turret4StreamAddrTable)
// Turret4DoStep - end
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// subroutine to call to step turret 5
Turret5DoStep:
astro_effect_step_sr(AstroStreamProcessor, turret_5_count,
TURRET_5_FRAMES, Turret5StreamAddrTable)
// Turret5DoStep - end
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// subroutine to call to step turret 6
Turret6DoStep:
astro_effect_step_sr(AstroStreamProcessor, turret_6_count,
TURRET_6_FRAMES, Turret6StreamAddrTable)
// Turret6DoStep - end
//////////////////////////////////////////////////////////////////////////////