-
Notifications
You must be signed in to change notification settings - Fork 0
/
invader_24.bas.asm
3377 lines (2840 loc) · 48.5 KB
/
invader_24.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 sound = t : sound = 32
LDA #32
STA sound
.
;
.L06 ; dim reducing_lives = p : p = 0
LDA #0
STA p
.
;
.L07 ; pfscore2 = %00101010
LDA #%00101010
STA pfscore2
.
;
.
;
.L08 ; dim inv_x = a : a = 84
LDA #84
STA a
.L09 ; dim inv_y = b : b = 76
LDA #76
STA b
.L010 ; dim inv_delay = c : c = 0
LDA #0
STA c
.L011 ; dim inv_dir = f : f = 1
LDA #1
STA f
.L012 ; dim inv_shot_x = g : g = inv_x
LDA inv_x
STA g
.L013 ; dim inv_shot_y = h : h = inv_y
LDA inv_y
STA h
.L014 ; dim inv_fire_delay = k : k = 0
LDA #0
STA k
.L015 ; dim inv_fired = l : l = 0
LDA #0
STA l
.L016 ; dim inv_hit = n : n = 0
LDA #0
STA n
.L017 ; dim inv_blast_delay = o : o = 0
LDA #0
STA o
.
;
.
;
.L018 ; dim tur_x = d : d = 84
LDA #84
STA d
.L019 ; dim tur_y = e : e = 14
LDA #14
STA e
.L020 ; dim shot_x = i : i = tur_x
LDA tur_x
STA i
.L021 ; dim shot_y = j : j = tur_y
LDA tur_y
STA j
.L022 ; dim tur_fired = m : m = 0
LDA #0
STA m
.L023 ; dim tur_hit = q : q = 0
LDA #0
STA q
.L024 ; dim tur_anim_playing = r : r = 0
LDA #0
STA r
.L025 ; dim tur_anim_frame = s : s = 0
LDA #0
STA s
.
;
.
;
.
;
.
;
.
;
.main
; main
.
;
.
;
.L026 ; AUDV0 = 0
LDA #0
STA AUDV0
.
;
.
;
.
;
.L027 ; if sound <= 31 then sound = sound + 1 : AUDC0 = 8 : AUDV0 = 4 : AUDF0 = sound - 2
LDA #31
CMP sound
BCC .skipL027
.condpart0
INC sound
LDA #8
STA AUDC0
LDA #4
STA AUDV0
LDA sound
SEC
SBC #2
STA AUDF0
.skipL027
.
;
.L028 ; if sound >= 33 && sound <= 64 then sound = sound + 1 : AUDC0 = 4 : AUDV0 = 3 : AUDF0 = sound - 34
LDA sound
CMP #33
BCC .skipL028
.condpart1
LDA #64
CMP sound
BCC .skip1then
.condpart2
INC sound
LDA #4
STA AUDC0
LDA #3
STA AUDV0
LDA sound
SEC
SBC #34
STA AUDF0
.skip1then
.skipL028
.
;
.L029 ; if sound >= 66 && sound <= 97 then sound = sound + 1 : AUDC0 = 2 : AUDV0 = 6 : AUDF0 = sound - 67
LDA sound
CMP #66
BCC .skipL029
.condpart3
LDA #97
CMP sound
BCC .skip3then
.condpart4
INC sound
LDA #2
STA AUDC0
LDA #6
STA AUDV0
LDA sound
SEC
SBC #67
STA AUDF0
.skip3then
.skipL029
.
;
.
;
.L030 ; if !joy0fire then u{3} = 1
bit INPT4
BPL .skipL030
.condpart5
LDA u
ORA #8
STA u
.skipL030
.
;
.
;
.L031 ; if tur_hit = 0 then gosub draw__move_turret
LDA tur_hit
CMP #0
BNE .skipL031
.condpart6
jsr .draw__move_turret
.skipL031
.L032 ; if tur_hit = 0 then gosub draw__move_turret_shot
LDA tur_hit
CMP #0
BNE .skipL032
.condpart7
jsr .draw__move_turret_shot
.skipL032
.L033 ; gosub draw__move_invader
jsr .draw__move_invader
.L034 ; gosub draw__move_inv_shot
jsr .draw__move_inv_shot
.L035 ; gosub col_shot_inv
jsr .col_shot_inv
.L036 ; gosub col_inv_shot_turret
jsr .col_inv_shot_turret
.L037 ; if tur_hit = 1 then gosub play_tur_anim
LDA tur_hit
CMP #1
BNE .skipL037
.condpart8
jsr .play_tur_anim
.skipL037
.
;
.L038 ; if pfscore2 < 2 then goto game_over
LDA pfscore2
CMP #2
BCS .skipL038
.condpart9
jmp .game_over
.skipL038
.
;
.
;
.L039 ; pfscorecolor = 196
LDA #196
STA pfscorecolor
.
;
.
;
.L040 ; scorecolor = 152
LDA #152
STA scorecolor
.
;
.
;
.L041 ; 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
.
;
.L042 ; goto main
jmp .main
.
;
.
;
.
;
.
;
.
;
.
;
.
;
.draw__move_invader
; draw__move_invader
.
;
.L043 ; inv_delay = inv_delay + 1
INC inv_delay
.
;
.
;
.L044 ; if inv_delay = 15 && inv_hit = 0 then player0:
LDA inv_delay
CMP #15
BNE .skipL044
.condpart10
LDA inv_hit
CMP #0
BNE .skip10then
.condpart11
LDX #<player11then_0
STX player0pointerlo
LDA #>player11then_0
STA player0pointerhi
LDA #9
STA player0height
.skip10then
.skipL044
.
;
.
;
.L045 ; if inv_delay = 30 && inv_hit = 0 then player0:
LDA inv_delay
CMP #30
BNE .skipL045
.condpart12
LDA inv_hit
CMP #0
BNE .skip12then
.condpart13
LDX #<player13then_0
STX player0pointerlo
LDA #>player13then_0
STA player0pointerhi
LDA #9
STA player0height
.skip12then
.skipL045
.
;
.L046 ; if inv_delay > 30 then inv_delay = 0
LDA #30
CMP inv_delay
BCS .skipL046
.condpart14
LDA #0
STA inv_delay
.skipL046
.
;
.
;
.L047 ; COLUP0 = 52
LDA #52
STA COLUP0
.
;
.
;
.L048 ; if inv_hit = 0 && inv_dir = 1 && inv_delay = 15 then inv_x = inv_x + 1
LDA inv_hit
CMP #0
BNE .skipL048
.condpart15
LDA inv_dir
CMP #1
BNE .skip15then
.condpart16
LDA inv_delay
CMP #15
BNE .skip16then
.condpart17
INC inv_x
.skip16then
.skip15then
.skipL048
.L049 ; if inv_hit = 0 && inv_dir = 1 && inv_delay = 30 then inv_x = inv_x + 1
LDA inv_hit
CMP #0
BNE .skipL049
.condpart18
LDA inv_dir
CMP #1
BNE .skip18then
.condpart19
LDA inv_delay
CMP #30
BNE .skip19then
.condpart20
INC inv_x
.skip19then
.skip18then
.skipL049
.
;
.L050 ; if inv_x > 143 then inv_dir = 0 : inv_x = 143 : inv_y = inv_y - 5
LDA #143
CMP inv_x
BCS .skipL050
.condpart21
LDA #0
STA inv_dir
LDA #143
STA inv_x
LDA inv_y
SEC
SBC #5
STA inv_y
.skipL050
.
;
.
;
.L051 ; if inv_hit = 0 && inv_dir = 0 && inv_delay = 15 then inv_x = inv_x - 1
LDA inv_hit
CMP #0
BNE .skipL051
.condpart22
LDA inv_dir
CMP #0
BNE .skip22then
.condpart23
LDA inv_delay
CMP #15
BNE .skip23then
.condpart24
DEC inv_x
.skip23then
.skip22then
.skipL051
.L052 ; if inv_hit = 0 && inv_dir = 0 && inv_delay = 30 then inv_x = inv_x - 1
LDA inv_hit
CMP #0
BNE .skipL052
.condpart25
LDA inv_dir
CMP #0
BNE .skip25then
.condpart26
LDA inv_delay
CMP #30
BNE .skip26then
.condpart27
DEC inv_x
.skip26then
.skip25then
.skipL052
.
;
.L053 ; if inv_x < 26 then inv_dir = 1 : inv_x = 26 : inv_y = inv_y - 5
LDA inv_x
CMP #26
BCS .skipL053
.condpart28
LDA #1
STA inv_dir
LDA #26
STA inv_x
LDA inv_y
SEC
SBC #5
STA inv_y
.skipL053
.
;
.
;
.L054 ; player0x = inv_x - 8 : player0y = inv_y
LDA inv_x
SEC
SBC #8
STA player0x
LDA inv_y
STA player0y
.L055 ; 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
.
;
.L056 ; player2:
LDX #<playerL056_2
STX player2pointerlo
LDA #>playerL056_2
STA player2pointerhi
LDA #9
STA player2height
.
;
.L057 ; COLUP2 = 14
LDA #14
STA COLUP2
.
;
.L058 ; inv_fire_delay = inv_fire_delay + 1
INC inv_fire_delay
.
;
.L059 ; 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 .skipL059
.condpart29
LDA inv_fire_delay
CMP #180
BNE .skip29then
.condpart30
LDA inv_x
STA inv_shot_x
LDA inv_y
SEC
SBC #9
STA inv_shot_y
.skip29then
.skipL059
.L060 ; if inv_fired = 0 && inv_fire_delay = 180 then player2x = inv_shot_x : player2y = inv_shot_y
LDA inv_fired
CMP #0
BNE .skipL060
.condpart31
LDA inv_fire_delay
CMP #180
BNE .skip31then
.condpart32
LDA inv_shot_x
STA player2x
LDA inv_shot_y
STA player2y
.skip31then
.skipL060
.L061 ; if inv_fired = 0 && inv_fire_delay = 180 then inv_fired = 1
LDA inv_fired
CMP #0
BNE .skipL061
.condpart33
LDA inv_fire_delay
CMP #180
BNE .skip33then
.condpart34
LDA #1
STA inv_fired
.skip33then
.skipL061
.
;
.L062 ; if inv_fired = 1 then inv_shot_y = inv_shot_y - 2 : player2y = inv_shot_y
LDA inv_fired
CMP #1
BNE .skipL062
.condpart35
LDA inv_shot_y
SEC
SBC #2
STA inv_shot_y
LDA inv_shot_y
STA player2y
.skipL062
.
;
.L063 ; 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 .skipL063
.condpart36
LDA #0
STA inv_fired
STA inv_fire_delay
LDA #88
STA inv_shot_y
LDA inv_shot_y
STA player2y
.skipL063
.
;
.L064 ; 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
.L065 ; if shot_x + 3 >= inv_x && shot_x + 3 <= inv_x + 6 && shot_y > inv_y then inv_hit = 1 : sound = 0
; 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 .skipL065
.condpart37
; 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 .skip37then
.condpart38
LDA inv_y
CMP shot_y
BCS .skip38then
.condpart39
LDA #1
STA inv_hit
LDA #0
STA sound
.skip38then
.skip37then
.skipL065
.
;
.L066 ; if inv_hit = 1 then inv_blast_delay = inv_blast_delay + 1
LDA inv_hit
CMP #1
BNE .skipL066
.condpart40
INC inv_blast_delay
.skipL066
.
;
.L067 ; if inv_blast_delay > 40 then score = score + 10 : inv_hit = 0 : gosub reset_blast
LDA #40
CMP inv_blast_delay
BCS .skipL067
.condpart41
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
.skipL067
.
;
.L068 ; if inv_hit = 1 then player0:
LDA inv_hit
CMP #1
BNE .skipL068
.condpart42
LDX #<player42then_0
STX player0pointerlo
LDA #>player42then_0
STA player0pointerhi
LDA #9
STA player0height
.skipL068
.
;
.L069 ; 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
.L070 ; player0:
LDX #<playerL070_0
STX player0pointerlo
LDA #>playerL070_0
STA player0pointerhi
LDA #9
STA player0height
.
;
.
;
.L071 ; 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
.
;
.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
; draw__move_turret
.L073 ; player1:
LDX #<playerL073_1
STX player1pointerlo
LDA #>playerL073_1
STA player1pointerhi
LDA #9
STA player1height
.