-
Notifications
You must be signed in to change notification settings - Fork 0
/
invader_20.bas.asm
3265 lines (2743 loc) · 47.2 KB
/
invader_20.bas.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
; Provided under the CC0 license. See the included LICENSE.txt for details.
processor 6502
include "vcs.h"
include "macro.h"
include "multisprite.h"
include "2600basic_variable_redefs.h"
ifconst bankswitch
if bankswitch == 8
ORG $1000
RORG $D000
endif
if bankswitch == 16
ORG $1000
RORG $9000
endif
if bankswitch == 32
ORG $1000
RORG $1000
endif
if bankswitch == 64
ORG $1000
RORG $1000
endif
else
ORG $F000
endif
ifconst bankswitch_hotspot
if bankswitch_hotspot = $083F ; 0840 bankswitching hotspot
.byte 234 ; stop unexpected bankswitches
endif
endif
game
.
;
.
;
.
;
.
;
.
;
.
;
.
;
.L00 ; includesfile multisprite_bankswitch.inc
.L01 ; set kernel_options no_blank_lines
.
;
.L02 ; set kernel multisprite
.L03 ; set romsize 8k
.
;
.
;
.L04 ; const pfscore = 0
.
;
.
;
.
;
.L05 ; dim reducing_lives = p : p = 0
LDA #0
STA p
.
;
.L06 ; pfscore2 = %00101010
LDA #%00101010
STA pfscore2
.
;
.
;
.L07 ; dim inv_x = a : a = 84
LDA #84
STA a
.L08 ; dim inv_y = b : b = 76
LDA #76
STA b
.L09 ; dim inv_delay = c : c = 0
LDA #0
STA c
.L010 ; dim inv_dir = f : f = 1
LDA #1
STA f
.L011 ; dim inv_shot_x = g : g = inv_x
LDA inv_x
STA g
.L012 ; dim inv_shot_y = h : h = inv_y
LDA inv_y
STA h
.L013 ; dim inv_fire_delay = k : k = 0
LDA #0
STA k
.L014 ; dim inv_fired = l : l = 0
LDA #0
STA l
.L015 ; dim inv_hit = n : n = 0
LDA #0
STA n
.L016 ; dim inv_blast_delay = o : o = 0
LDA #0
STA o
.
;
.
;
.L017 ; dim tur_x = d : d = 84
LDA #84
STA d
.L018 ; dim tur_y = e : e = 14
LDA #14
STA e
.L019 ; dim shot_x = i : i = tur_x
LDA tur_x
STA i
.L020 ; dim shot_y = j : j = tur_y
LDA tur_y
STA j
.L021 ; dim tur_fired = m : m = 0
LDA #0
STA m
.L022 ; dim tur_hit = q : q = 0
LDA #0
STA q
.L023 ; dim tur_anim_playing = r : r = 0
LDA #0
STA r
.L024 ; dim tur_anim_frame = s : s = 0
LDA #0
STA s
.
;
.
;
.
;
.
;
.
;
.main
; main
.
;
.L025 ; if tur_hit = 0 then gosub draw__move_turret
LDA tur_hit
CMP #0
BNE .skipL025
.condpart0
jsr .draw__move_turret
.skipL025
.L026 ; if tur_hit = 0 then gosub draw__move_turret_shot
LDA tur_hit
CMP #0
BNE .skipL026
.condpart1
jsr .draw__move_turret_shot
.skipL026
.L027 ; gosub draw__move_invader
jsr .draw__move_invader
.L028 ; gosub draw__move_inv_shot
jsr .draw__move_inv_shot
.L029 ; gosub col_shot_inv
jsr .col_shot_inv
.L030 ; gosub col_inv_shot_turret
jsr .col_inv_shot_turret
.L031 ; if tur_hit = 1 then gosub play_tur_anim
LDA tur_hit
CMP #1
BNE .skipL031
.condpart2
jsr .play_tur_anim
.skipL031
.
;
.L032 ; if pfscore2 < 2 then goto game_over
LDA pfscore2
CMP #2
BCS .skipL032
.condpart3
jmp .game_over
.skipL032
.
;
.
;
.L033 ; pfscorecolor = 196
LDA #196
STA pfscorecolor
.
;
.
;
.L034 ; scorecolor = 152
LDA #152
STA scorecolor
.
;
.
;
.L035 ; drawscreen
sta temp7
lda #>(ret_point1-1)
pha
lda #<(ret_point1-1)
pha
lda #>(drawscreen-1)
pha
lda #<(drawscreen-1)
pha
lda temp7
pha
txa
pha
ldx #2
jmp BS_jsr
ret_point1
.
;
.L036 ; goto main
jmp .main
.
;
.
;
.
;
.
;
.
;
.
;
.
;
.draw__move_invader
; draw__move_invader
.
;
.L037 ; inv_delay = inv_delay + 1
INC inv_delay
.
;
.
;
.L038 ; if inv_delay = 15 && inv_hit = 0 then player0:
LDA inv_delay
CMP #15
BNE .skipL038
.condpart4
LDA inv_hit
CMP #0
BNE .skip4then
.condpart5
LDX #<player5then_0
STX player0pointerlo
LDA #>player5then_0
STA player0pointerhi
LDA #9
STA player0height
.skip4then
.skipL038
.
;
.
;
.L039 ; if inv_delay = 30 && inv_hit = 0 then player0:
LDA inv_delay
CMP #30
BNE .skipL039
.condpart6
LDA inv_hit
CMP #0
BNE .skip6then
.condpart7
LDX #<player7then_0
STX player0pointerlo
LDA #>player7then_0
STA player0pointerhi
LDA #9
STA player0height
.skip6then
.skipL039
.
;
.L040 ; if inv_delay > 30 then inv_delay = 0
LDA #30
CMP inv_delay
BCS .skipL040
.condpart8
LDA #0
STA inv_delay
.skipL040
.
;
.
;
.L041 ; COLUP0 = 52
LDA #52
STA COLUP0
.
;
.
;
.L042 ; if inv_hit = 0 && inv_dir = 1 && inv_delay = 15 then inv_x = inv_x + 1
LDA inv_hit
CMP #0
BNE .skipL042
.condpart9
LDA inv_dir
CMP #1
BNE .skip9then
.condpart10
LDA inv_delay
CMP #15
BNE .skip10then
.condpart11
INC inv_x
.skip10then
.skip9then
.skipL042
.L043 ; if inv_hit = 0 && inv_dir = 1 && inv_delay = 30 then inv_x = inv_x + 1
LDA inv_hit
CMP #0
BNE .skipL043
.condpart12
LDA inv_dir
CMP #1
BNE .skip12then
.condpart13
LDA inv_delay
CMP #30
BNE .skip13then
.condpart14
INC inv_x
.skip13then
.skip12then
.skipL043
.
;
.L044 ; if inv_x > 143 then inv_dir = 0 : inv_x = 143 : inv_y = inv_y - 5
LDA #143
CMP inv_x
BCS .skipL044
.condpart15
LDA #0
STA inv_dir
LDA #143
STA inv_x
LDA inv_y
SEC
SBC #5
STA inv_y
.skipL044
.
;
.
;
.L045 ; if inv_hit = 0 && inv_dir = 0 && inv_delay = 15 then inv_x = inv_x - 1
LDA inv_hit
CMP #0
BNE .skipL045
.condpart16
LDA inv_dir
CMP #0
BNE .skip16then
.condpart17
LDA inv_delay
CMP #15
BNE .skip17then
.condpart18
DEC inv_x
.skip17then
.skip16then
.skipL045
.L046 ; if inv_hit = 0 && inv_dir = 0 && inv_delay = 30 then inv_x = inv_x - 1
LDA inv_hit
CMP #0
BNE .skipL046
.condpart19
LDA inv_dir
CMP #0
BNE .skip19then
.condpart20
LDA inv_delay
CMP #30
BNE .skip20then
.condpart21
DEC inv_x
.skip20then
.skip19then
.skipL046
.
;
.L047 ; if inv_x < 26 then inv_dir = 1 : inv_x = 26 : inv_y = inv_y - 5
LDA inv_x
CMP #26
BCS .skipL047
.condpart22
LDA #1
STA inv_dir
LDA #26
STA inv_x
LDA inv_y
SEC
SBC #5
STA inv_y
.skipL047
.
;
.
;
.L048 ; player0x = inv_x - 8 : player0y = inv_y
LDA inv_x
SEC
SBC #8
STA player0x
LDA inv_y
STA player0y
.L049 ; return
tsx
lda 2,x ; check return address
eor #(>*) ; vs. current PCH
and #$E0 ; mask off all but top 3 bits
beq *+5 ; if equal, do normal return
JMP BS_return
RTS
.
;
.
;
.
;
.
;
.draw__move_inv_shot
; draw__move_inv_shot
.
;
.L050 ; player2:
LDX #<playerL050_2
STX player2pointerlo
LDA #>playerL050_2
STA player2pointerhi
LDA #9
STA player2height
.
;
.L051 ; COLUP2 = 14
LDA #14
STA COLUP2
.
;
.L052 ; inv_fire_delay = inv_fire_delay + 1
INC inv_fire_delay
.
;
.L053 ; if inv_fired = 0 && inv_fire_delay = 180 then inv_shot_x = inv_x : inv_shot_y = inv_y - 9
LDA inv_fired
CMP #0
BNE .skipL053
.condpart23
LDA inv_fire_delay
CMP #180
BNE .skip23then
.condpart24
LDA inv_x
STA inv_shot_x
LDA inv_y
SEC
SBC #9
STA inv_shot_y
.skip23then
.skipL053
.L054 ; if inv_fired = 0 && inv_fire_delay = 180 then player2x = inv_shot_x : player2y = inv_shot_y
LDA inv_fired
CMP #0
BNE .skipL054
.condpart25
LDA inv_fire_delay
CMP #180
BNE .skip25then
.condpart26
LDA inv_shot_x
STA player2x
LDA inv_shot_y
STA player2y
.skip25then
.skipL054
.L055 ; if inv_fired = 0 && inv_fire_delay = 180 then inv_fired = 1
LDA inv_fired
CMP #0
BNE .skipL055
.condpart27
LDA inv_fire_delay
CMP #180
BNE .skip27then
.condpart28
LDA #1
STA inv_fired
.skip27then
.skipL055
.
;
.L056 ; if inv_fired = 1 then inv_shot_y = inv_shot_y - 2 : player2y = inv_shot_y
LDA inv_fired
CMP #1
BNE .skipL056
.condpart29
LDA inv_shot_y
SEC
SBC #2
STA inv_shot_y
LDA inv_shot_y
STA player2y
.skipL056
.
;
.L057 ; if inv_shot_y < 12 then inv_fired = 0 : inv_fire_delay = 0 : inv_shot_y = 88 : player2y = inv_shot_y
LDA inv_shot_y
CMP #12
BCS .skipL057
.condpart30
LDA #0
STA inv_fired
STA inv_fire_delay
LDA #88
STA inv_shot_y
LDA inv_shot_y
STA player2y
.skipL057
.
;
.L058 ; return
tsx
lda 2,x ; check return address
eor #(>*) ; vs. current PCH
and #$E0 ; mask off all but top 3 bits
beq *+5 ; if equal, do normal return
JMP BS_return
RTS
.
;
.
;
.
;
.
;
.col_shot_inv
; col_shot_inv
.L059 ; if shot_x + 3 >= inv_x && shot_x + 3 <= inv_x + 6 && shot_y > inv_y then inv_hit = 1
; complex condition detected
LDA shot_x
CLC
ADC #3
; todo: this LDA is spurious and should be prevented -> LDA 1,x
CMP inv_x
BCC .skipL059
.condpart31
; complex condition detected
LDA inv_x
CLC
ADC #6
PHA
LDA shot_x
CLC
ADC #3
PHA
TSX
PLA
PLA
; todo: this LDA is spurious and should be prevented -> LDA 2,x
CMP 1,x
BCC .skip31then
.condpart32
LDA inv_y
CMP shot_y
BCS .skip32then
.condpart33
LDA #1
STA inv_hit
.skip32then
.skip31then
.skipL059
.
;
.L060 ; if inv_hit = 1 then inv_blast_delay = inv_blast_delay + 1
LDA inv_hit
CMP #1
BNE .skipL060
.condpart34
INC inv_blast_delay
.skipL060
.
;
.L061 ; if inv_blast_delay > 30 then score = score + 10 : inv_hit = 0 : gosub reset_blast
LDA #30
CMP inv_blast_delay
BCS .skipL061
.condpart35
SED
CLC
LDA score+2
ADC #$10
STA score+2
LDA score+1
ADC #$00
STA score+1
LDA score
ADC #$00
STA score
CLD
LDA #0
STA inv_hit
jsr .reset_blast
.skipL061
.
;
.L062 ; if inv_hit = 1 then player0:
LDA inv_hit
CMP #1
BNE .skipL062
.condpart36
LDX #<player36then_0
STX player0pointerlo
LDA #>player36then_0
STA player0pointerhi
LDA #9
STA player0height
.skipL062
.
;
.L063 ; return
tsx
lda 2,x ; check return address
eor #(>*) ; vs. current PCH
and #$E0 ; mask off all but top 3 bits
beq *+5 ; if equal, do normal return
JMP BS_return
RTS
.
;
.
;
.
;
.
;
.reset_blast
; reset_blast
.L064 ; player0:
LDX #<playerL064_0
STX player0pointerlo
LDA #>playerL064_0
STA player0pointerhi
LDA #9
STA player0height
.
;
.
;
.L065 ; inv_blast_delay = 0 : inv_x = ( rand & 117 ) + 26 : inv_y = 76
LDA #0
STA inv_blast_delay
; complex statement detected
sta temp7
lda #>(ret_point2-1)
pha
lda #<(ret_point2-1)
pha
lda #>(randomize-1)
pha
lda #<(randomize-1)
pha
lda temp7
pha
txa
pha
ldx #2
jmp BS_jsr
ret_point2
AND #117
CLC
ADC #26
STA inv_x
LDA #76
STA inv_y
.
;
.L066 ; return
tsx
lda 2,x ; check return address
eor #(>*) ; vs. current PCH
and #$E0 ; mask off all but top 3 bits
beq *+5 ; if equal, do normal return
JMP BS_return
RTS
.
;
.
;
.
;
.
;
.draw__move_turret
; draw__move_turret
.L067 ; player1:
LDX #<playerL067_1
STX player1pointerlo
LDA #>playerL067_1
STA player1pointerhi
LDA #9
STA player1height
.
;
.
;
.L068 ; _COLUP1 = 196
LDA #196
STA _COLUP1
.
;
.L069 ; if joy0left && tur_x >= 26 then tur_x = tur_x - 1
bit SWCHA
BVS .skipL069
.condpart37
LDA tur_x
CMP #26
BCC .skip37then
.condpart38
DEC tur_x
.skip37then
.skipL069
.L070 ; if joy0right && tur_x <= 143 then tur_x = tur_x + 1
bit SWCHA
BMI .skipL070
.condpart39
LDA #143
CMP tur_x
BCC .skip39then
.condpart40
INC tur_x
.skip39then
.skipL070
.
;
.
;
.
;
.
;
.L071 ; if tur_hit = 0 then player1x = tur_x : player1y = tur_y
LDA tur_hit
CMP #0
BNE .skipL071
.condpart41
LDA tur_x
STA player1x
LDA tur_y
STA player1y
.skipL071
.
;
.L072 ; return
tsx
lda 2,x ; check return address
eor #(>*) ; vs. current PCH
and #$E0 ; mask off all but top 3 bits
beq *+5 ; if equal, do normal return
JMP BS_return
RTS
.
;
.
;
.
;
.
;
.draw__move_turret_shot
; draw__move_turret_shot
.L073 ; player3:
LDX #<playerL073_3
STX player3pointerlo
LDA #>playerL073_3
STA player3pointerhi
LDA #9
STA player3height
.
;
.L074 ; COLUP3 = 14
LDA #14
STA COLUP3
.
;
.L075 ; if joy0fire && tur_fired = 0 then tur_fired = 1 : shot_x = tur_x : shot_y = tur_y + 1 : player3x = shot_x : player3y = shot_y
bit INPT4
BMI .skipL075
.condpart42
LDA tur_fired