-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanimatedtiles.s
More file actions
575 lines (437 loc) · 12.1 KB
/
animatedtiles.s
File metadata and controls
575 lines (437 loc) · 12.1 KB
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
// animated tiles, crumble, projectile, projectile emitter, bounce up tile
.const MAX_ANIMATED_TILES = 64
AddAnimatedTile: {
// save x..use y instead??
stx temp1
sta temp2
ldx #(MAX_ANIMATED_TILES-1)
// find a free animated tile slot
add_animated_tile_loop:
lda animated_tile,x
beq add_animated_tile_slot_found
dex
bmi add_animated_tile_done // no slot found...
jmp add_animated_tile_loop
add_animated_tile_done:
// no slot found..
// restore x
ldx temp1
lda #$00 // fail
rts
add_animated_tile_slot_found:
lda temp2
sta animated_tile,x
// lda #$03 // timer
lda animated_tile_time
sta animated_tile_counter,x
lda row
sta animated_tile_row,x
lda col
sta animated_tile_col,x
lda tile_type
sta animated_tile_type,x
// store what is currently in the tile position
lda (address_low),y
sta animated_tile_prev,x
// y has offset from address_low/high
// add it to address_low/high
clc
tya
adc address_low
sta animated_tile_l,x
lda #$00
adc address_high
sta animated_tile_h,x
// restore x
ldx temp1
lda #$01 // success
rts
}
AddProjectile: {
lda #$30
sta animated_tile_counter,x
// position where to add projectile should be in row/col
jsr GetScreenAddress
// check if cell is free
lda (address_low),y
cmp #TILE_BLANK
bne add_projectile_done
lda #$03
sta animated_tile_time
lda #TILE_PROJECTILE
clc
adc tile_type
jsr AddAnimatedTile
lda #TILE_PROJECTILE
clc
adc tile_type
sta (address_low),y
add_projectile_done:
rts
}
// loop through all the animated tiles and animated them
AnimateTiles: {
ldx #(MAX_ANIMATED_TILES-1)
ldy #$0
animate_tiles_loop:
// if animated tile is zero, then slot is empty
lda animated_tile,x
bne animate_tiles_ok
jmp animate_tiles_next
animate_tiles_ok:
// only animate the tile if the counter is zero
dec animated_tile_counter,x
// lda animated_tile_counter,x
beq do_animate_tile
jmp animate_tiles_next
do_animate_tile:
// animated tile counter is zero
// screen address of the tile
lda animated_tile_l,x
sta address_low
lda animated_tile_h,x
sta address_high
// check what the tile is to determine what to put there next
lda animated_tile,x
cmp #TILE_CRUMBLE1
bne animated_tile_check_crumble_2
// turn it into a crumble 2 tile
lda #TILE_CRUMBLE2
sta (address_low),y
sta animated_tile,x
lda #TILE_CRUMBLE_TIME_2
sta animated_tile_counter,x
jmp animate_tiles_next
animated_tile_check_crumble_2:
cmp #TILE_CRUMBLE2 // crumble 2
bne animated_tile_check_crumble_3
lda #TILE_CRUMBLE3
sta (address_low),y
sta animated_tile,x
lda #TILE_CRUMBLE_TIME_3
sta animated_tile_counter,x
jmp animate_tiles_next
animated_tile_check_crumble_3:
cmp #TILE_CRUMBLE3
bne animated_tile_check_crumble_4
lda #TILE_CRUMBLE4
sta (address_low),y
sta animated_tile,x
lda #TILE_CRUMBLE_TIME_4
sta animated_tile_counter,x
jmp animate_tiles_next
animated_tile_check_crumble_4:
cmp #TILE_CRUMBLE4
bne animate_tile_check_tile_up_1
lda #TILE_CRUMBLE1
sta (address_low),y
// clear the animated tile slot
lda #$0
sta animated_tile,x
jmp animate_tiles_next
animate_tile_check_tile_up_1:
cmp #TILE_UP_1
bne animate_tile_check_tile_up_2
lda #TILE_UP_2
sta (address_low),y
sta animated_tile,x
lda #$1
sta animated_tile_counter,x
jmp animate_tiles_next
animate_tile_check_tile_up_2:
cmp #TILE_UP_2
bne animate_tile_check_tile_up_3
lda #TILE_UP_3
sta (address_low),y
sta animated_tile,x
lda #$10
sta animated_tile_counter,x
jmp animate_tiles_next
animate_tile_check_tile_up_3:
cmp #TILE_UP_3
bne animate_tile_check_tile_left_1
lda #TILE_UP
sta (address_low),y
lda #$0
sta animated_tile,x
jmp animate_tiles_next
animate_tile_check_tile_left_1:
cmp #TILE_LEFT_1
bne animate_tile_check_tile_left_2
lda #TILE_LEFT_2
sta (address_low),y
sta animated_tile,x
lda #$1
sta animated_tile_counter,x
jmp animate_tiles_next
animate_tile_check_tile_left_2:
cmp #TILE_LEFT_2
bne animate_tile_check_tile_left_3
lda #TILE_LEFT_3
sta (address_low),y
sta animated_tile,x
lda #$10
sta animated_tile_counter,x
jmp animate_tiles_next
animate_tile_check_tile_left_3:
cmp #TILE_LEFT_3
bne animate_tile_check_tile_right_1
lda #TILE_LEFT
sta (address_low),y
lda #$0
sta animated_tile,x
jmp animate_tiles_next
animate_tile_check_tile_right_1:
cmp #TILE_RIGHT_1
bne animate_tile_check_tile_right_2
lda #TILE_RIGHT_2
sta (address_low),y
sta animated_tile,x
lda #$1
sta animated_tile_counter,x
jmp animate_tiles_next
animate_tile_check_tile_right_2:
cmp #TILE_RIGHT_2
bne animate_tile_check_tile_right_3
lda #TILE_RIGHT_3
sta (address_low),y
sta animated_tile,x
lda #$10
sta animated_tile_counter,x
jmp animate_tiles_next
animate_tile_check_tile_right_3:
cmp #TILE_RIGHT_3
bne animate_tile_check_emitter_up
lda #TILE_RIGHT
sta (address_low),y
lda #$0
sta animated_tile,x
jmp animate_tiles_next
animate_tile_check_emitter_up:
cmp #TILE_EMITTER_UP
bne animate_tile_check_emitter_active_up
// change it to active
lda #TILE_EMITTER_ACTIVE_UP
sta (address_low),y
sta animated_tile,x
// put a projectile tile in row above
lda animated_tile_row,x
sta row
dec row
lda animated_tile_col,x
sta col
lda #PROJECTILE_UP
sta tile_type
jsr AddProjectile
lda #TIME_EMITTER_ACTIVE
sta animated_tile_counter,x
jmp animate_tiles_next
animate_tile_check_emitter_active_up:
cmp #TILE_EMITTER_ACTIVE_UP
bne animate_tile_check_emitter_down
lda #TILE_EMITTER
sta (address_low),y
sta animated_tile,x
lda #TIME_EMITTER
sta animated_tile_counter,x
jmp animate_tiles_next
animate_tile_check_emitter_down:
cmp #TILE_EMITTER_DOWN
bne animate_tile_check_emitter_active_down
// change it to active
lda #TILE_EMITTER_ACTIVE_DOWN
sta (address_low),y
sta animated_tile,x
// put a projectile tile in row above
lda animated_tile_row,x
sta row
inc row
lda animated_tile_col,x
sta col
lda #PROJECTILE_DOWN
sta tile_type
jsr AddProjectile
lda #TIME_EMITTER_ACTIVE
sta animated_tile_counter,x
jmp animate_tiles_next
animate_tile_check_emitter_active_down:
cmp #TILE_EMITTER_ACTIVE_DOWN
bne animate_tile_check_emitter_left
lda #TILE_EMITTER_DOWN
sta (address_low),y
sta animated_tile,x
lda #TIME_EMITTER
sta animated_tile_counter,x
jmp animate_tiles_next
animate_tile_check_emitter_left:
cmp #TILE_EMITTER_LEFT
bne animate_tile_check_emitter_active_left
// change it to active
lda #TILE_EMITTER_ACTIVE_LEFT
sta (address_low),y
sta animated_tile,x
// put a projectile tile in row above
lda animated_tile_row,x
sta row
lda animated_tile_col,x
sta col
dec col
lda #PROJECTILE_LEFT
sta tile_type
jsr AddProjectile
lda #TIME_EMITTER_ACTIVE
sta animated_tile_counter,x
jmp animate_tiles_next
animate_tile_check_emitter_active_left:
cmp #TILE_EMITTER_ACTIVE_LEFT
bne animate_tile_check_emitter_right
lda #TILE_EMITTER_LEFT
sta (address_low),y
sta animated_tile,x
lda #TIME_EMITTER
sta animated_tile_counter,x
jmp animate_tiles_next
animate_tile_check_emitter_right:
cmp #TILE_EMITTER_RIGHT
bne animate_tile_check_emitter_active_right
// change it to active
lda #TILE_EMITTER_ACTIVE_RIGHT
sta (address_low),y
sta animated_tile,x
// put a projectile tile in row above
lda animated_tile_row,x
sta row
lda animated_tile_col,x
sta col
inc col
lda #PROJECTILE_RIGHT
sta tile_type
jsr AddProjectile
lda #TIME_EMITTER_ACTIVE
sta animated_tile_counter,x
jmp animate_tiles_next
animate_tile_check_emitter_active_right:
cmp #TILE_EMITTER_ACTIVE_RIGHT
bne animate_tile_check_projectile
lda #TILE_EMITTER_RIGHT
sta (address_low),y
sta animated_tile,x
lda #TIME_EMITTER
sta animated_tile_counter,x
jmp animate_tiles_next
animate_tile_check_projectile:
cmp #TILE_PROJECTILE_UP
beq !+
cmp #TILE_PROJECTILE_DOWN
beq !+
cmp #TILE_PROJECTILE_LEFT
beq !+
cmp #TILE_PROJECTILE_RIGHT
beq !+
// bne animate_tiles_next
jmp animate_tiles_next
!:
lda #$03
sta animated_tile_counter,x
// set cell back to what it was
lda animated_tile_row,x
sta row
lda animated_tile_col,x
sta col
jsr GetScreenAddress
lda animated_tile_prev,x
sta (address_low),y
lda animated_tile_type,x
cmp #PROJECTILE_UP
bne check_projectile_down
dec row
jmp draw_projectile_new_position
check_projectile_down:
cmp #PROJECTILE_DOWN
bne check_projectile_left
inc row
jmp draw_projectile_new_position
check_projectile_left:
cmp #PROJECTILE_LEFT
bne check_projectile_right
dec col
jmp draw_projectile_new_position
check_projectile_right:
inc col
draw_projectile_new_position:
jsr GetScreenAddress
lda (address_low),y
cmp #TILE_BLANK
beq draw_projectile_new
cmp #TILE_BLANK_RED
beq draw_projectile_new
cmp #TILE_BLANK_GREEN
beq draw_projectile_new
cmp #TILE_BLANK_BLUE
beq draw_projectile_new
// projectile reached end, so disable animated tile
lda #$00
sta animated_tile,x
jmp animate_tiles_next
draw_projectile_new:
// save the previous character
lda (address_low),y
sta animated_tile_prev,x
clc
lda #TILE_PROJECTILE
adc animated_tile_type,x
sta (address_low),y
lda row
sta animated_tile_row,x
lda col
sta animated_tile_col,x
draw_projectile_new_done:
animate_tiles_next:
dex
bmi animate_tiles_done
jmp animate_tiles_loop
animate_tiles_done:
rts
}
// animated tiles
animated_tile:
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
animated_tile_counter:
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
animated_tile_l:
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
animated_tile_h:
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
animated_tile_col:
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
animated_tile_row:
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
animated_tile_type:
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
// what the tile was previously
animated_tile_prev:
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00