-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinvaders_from_andromeda.dasm
More file actions
2383 lines (2195 loc) · 48.8 KB
/
invaders_from_andromeda.dasm
File metadata and controls
2383 lines (2195 loc) · 48.8 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
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
;Copyright 2022 Cisano Carmelo
;
;This file is part of Invaders From Andromeda
;
; Invaders From Andromeda is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; Invaders From Andromeda is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with Invaders From Andromeda. If not, see <http://www.gnu.org/licenses/>.
processor 6502
include "vcs.h"
include "macro.h"
include "my_macro.h"
include "energy_macro.h"
include "joystick_macro.h"
include "timer.h"
;===============================================================================
; Define Constants
;===============================================================================
Volume0 = #4
Volume1 = #6
LeftLimitSpaceShip = #30
RightLimitSpaceShip = #135
LeftLimitAliens = #28
RightLimitAliens = #160
ColorPlanet = #$92
ColorLandPlanet = #$f2
ColorOrizonPlanet = #$90
ColorMissiles = #$fe
XPosGRP0Energia = #$4c
ColorEnergyCounter = #$0f
ColorEnergyCounterWhenOneIsLost = #$00
WhereStop = #40
EndPointBallSpaceShip = #2
HeightInvader = #10
ColorBall = #$ae
StartSpaceShip = #150
ColorLogo = #$98
MaxShields = #5
TimeForChangeScreen = #255
PreBarriers = #126
EndBarriers = #135
RedBarriers = #$41
EnergySingleBarrier = #5
ColorEndGame = #$46
LastLevelEndGame = #10
RightLimitBarriers = #56
LeftLimitBarriers = #40
;===============================================================================
; Define Zero Page RAM Usage
;----------------------------------------
; ZP RAM variables can only be seen by the 6507 CPU.
; C variables can only be seen by the ARM CPU.
; The 4K Display Data bank is used for any variables both CPUs need access to.
;===============================================================================
SEG.U VARS
ORG $80
echo "----",($00FE - *) , "bytes of RAM left (space reserved for 2 byte stack)"
; dgs - use DS to define # of bytes for storage.
; ShieldNumber will end up in $80
; InvadersLine0 in $81
; etc
ShieldNumber ds 1
InvadersLine0 ds 1
InvadersLine1 ds 1
InvadersLine2 ds 1
InvadersLine3 ds 1
InvadersLine4 ds 1
OffsetXInvaders ds 1
CoordXInvaders ds 1
CoordYInvaders ds 1
CursorLeftInvaders ds 1
CursorRightInvaders ds 1
CursorRowInvaders ds 1
CursorColumnInvaders ds 1
CursorSpringLeftRight ds 1
CursorYMissile1 ds 1
CursorYMissile2 ds 1
CoordXSpaceShip ds 1
CoordXUfo ds 1
PointerGRP0Low ds 1
PointerGRP0Hi ds 1
PointerGRP1Low ds 1
PointerGRP1Hi ds 1
PntrColorGRPLow ds 1
PntrColorGRPHi ds 1
PointerNumberLow ds 1
PointerNumberHi ds 1
PointerGFXPlanet ds 1
Temp ds 1
TempX ds 1
Tmp ds 1
TimerForAll ds 1
BooleanGameOver ds 1 ;if 0 then game over
BooleanAtBeginOfEveryLevel ds 1
BooleanShiftInvadersColumn ds 1
CursorYBallSpaceShip ds 1
CoordXBallSpaceShip ds 1
BooleanFireSpaceShip ds 1
BooleanHitInvader ds 1
BooleanFirePressed ds 1
UfoCollision ds 1
CollisionInvader ds 1
ArrayPointerGRP0Line0 ds 1
ArrayPointerGRP0Line1 ds 1
ArrayPointerGRP0Line2 ds 1
ArrayPointerGRP0Line3 ds 1
ArrayPointerGRP0Line4 ds 1
ArrayPointerGRP1Line0 ds 1
ArrayPointerGRP1Line1 ds 1
ArrayPointerGRP1Line2 ds 1
ArrayPointerGRP1Line3 ds 1
ArrayPointerGRP1Line4 ds 1
BooleanGRP1AllGone ds 1
CursorSound0 ds 1
CursorSound1 ds 1
TempoCH0 ds 1
TempoCH1 ds 1
MarchSequencer ds 1
TimerTitleScreen ds 1
ActiveInvadersLines ds 1
Bullet ds 1
TimerShiftInvadersColumn ds 1
StepBall ds 1
CurosorMaskInvaders ds 1
TimerMask ds 1
TotalInvaders ds 1
AlternateFrameInvader ds 1
PointerSpaceShipLow ds 1
PointerSpaceShipHi ds 1
CoordYMissile1 ds 1
CoordYMissile2 ds 1
TimerWhenInvaderStrike ds 1
CursorWhoBombs ds 1
CoordXMissile1 ds 1
CoordXMissile2 ds 1
BooleanNoBulletInGame ds 1
BooleanShieldLost ds 1
LevelNumber ds 1 ;incremented in FIND_HIT_INVADER_MACRO
LevelBarriers ds 1
PowerSingleBarrier ds 1
DefineBarriers ds 1
MaskDeleteBarrier ds 1
PointerGRP1UfoLow ds 1
PointerGRP1UfoHi ds 1
BooleanVictorySongCh1 ds 1
KindOfBarriers ds 1
Direction ds 1
CoordXBarries ds 1
SoundDataLow ds 1
SoundDataH ds 1
SoundMarchDataLow ds 1
SoundMarchDataHi ds 1
BooleanVictorySongCh0 ds 1
SEG CODE
org $f000
;---Graphics Data---
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
FirstInvader0
.byte $80 ; |X |
.byte $5B ; | X XX XX|
.byte $3C ; | XXXX |
.byte $5A ; | X XX X |
.byte $FF ; |XXXXXXXX|
.byte $FF ; |XXXXXXXX|
.byte $42 ; | X X |
.byte $66 ; | XX XX |
.byte $08 ; | X |
.byte $00 ; | |
FirstInvader1
.byte $42 ; | X X |
.byte $5A ; | X XX X |
.byte $3C ; | XXXX |
.byte $5A ; | X XX X |
.byte $FF ; |XXXXXXXX|
.byte $FF ; |XXXXXXXX|
.byte $42 ; | X X |
.byte $66 ; | XX XX |
.byte $10 ; | X |
.byte $00 ; | |
SecondInvader0
.byte $81 ; |X X|
.byte $C3 ; |XX XX|
.byte $A5 ; |X X X X|
.byte $DB ; |XX XX XX|
.byte $DB ; |XX XX XX|
.byte $FF ; |XXXXXXXX|
.byte $7E ; | XXXXXX |
.byte $A5 ; |X X X X|
.byte $24 ; | X X |
.byte $00 ; | |
SecondInvader1
.byte $81 ; |X X|
.byte $E7 ; |XXX XXX|
.byte $A5 ; |X X X X|
.byte $DB ; |XX XX XX|
.byte $DB ; |XX XX XX|
.byte $FF ; |XXXXXXXX|
.byte $7E ; | XXXXXX |
.byte $A5 ; |X X X X|
.byte $81 ; |X X|
.byte $00 ; | |
ThirdInvader0
.byte $66 ; | XX XX |
.byte $24 ; | X X |
.byte $7E ; | XXXXXX |
.byte $99 ; |X XX X|
.byte $DB ; |XX XX XX|
.byte $DB ; |XX XX XX|
.byte $7E ; | XXXXXX |
.byte $3C ; | XXXX |
.byte $AA ; |X X X X |
.byte $00 ; | |
ThirdInvader1
.byte $2C ; | X XX |
.byte $24 ; | X X |
.byte $7E ; | XXXXXX |
.byte $99 ; |X XX X|
.byte $DB ; |XX XX XX|
.byte $FF ; |XXXXXXXX|
.byte $7E ; | XXXXXX |
.byte $3C ; | XXXX |
.byte $55 ; | X X X X|
.byte $00 ; | |
ForthInvader0
.byte $42 ; | X X |
.byte $7E ; | XXXXXX |
.byte $7E ; | XXXXXX |
.byte $7E ; | XXXXXX |
.byte $3C ; | XXXX |
.byte $FF ; |XXXXXXXX|
.byte $18 ; | XX |
.byte $81 ; |X X|
.byte $81 ; |X X|
.byte $00 ; | |
ForthInvader1
.byte $E7 ; |XXX XXX|
.byte $BD ; |X XXXX X|
.byte $BD ; |X XXXX X|
.byte $FF ; |XXXXXXXX|
.byte $3C ; | XXXX |
.byte $7E ; | XXXXXX |
.byte $18 ; | XX |
.byte $42 ; | X X |
.byte $42 ; | X X |
.byte $00 ; | |
FifthInvader0
.byte $99 ; |X XX X|
.byte $A5 ; |X X X X|
.byte $FF ; |XXXXXXXX|
.byte $B5 ; |X XX X X|
.byte $3C ; | XXXX |
.byte $3C ; | XXXX |
.byte $24 ; | X X |
.byte $2E ; | X XXX |
.byte $70 ; | XXX |
.byte $00 ; | |
FifthInvader1
.byte $18 ; | XX |
.byte $24 ; | X X |
.byte $BD ; |X XXXX X|
.byte $EF ; |XXX XXXX|
.byte $BD ; |X XXXX X|
.byte $3C ; | XXXX |
.byte $24 ; | X X |
.byte $74 ; | XXX X |
.byte $0E ; | XXX |
.byte $00 ; | |
SixthInvader0
.byte $6A ; | XX X X |
.byte $81 ; |X X|
.byte $99 ; |X XX X|
.byte $BD ; |X XXXX X|
.byte $24 ; | X X |
.byte $BD ; |X XXXX X|
.byte $99 ; |X XX X|
.byte $81 ; |X X|
.byte $56 ; | X X XX |
.byte $00 ; | |
SixthInvader1
.byte $6A ; | XX X X |
.byte $C3 ; |XX XX|
.byte $5A ; | X XX X |
.byte $7E ; | XXXXXX |
.byte $99 ; |X XX X|
.byte $7E ; | XXXXXX |
.byte $5A ; | X XX X |
.byte $C3 ; |XX XX|
.byte $56 ; | X X XX |
.byte $00 ; | |
SeventhInvader0
.byte $24 ; | X X |
.byte $5A ; | X XX X |
.byte $5A ; | X XX X |
.byte $7E ; | XXXXXX |
.byte $7E ; | XXXXXX |
.byte $7E ; | XXXXXX |
.byte $99 ; |X XX X|
.byte $4A ; | X X X |
.byte $89 ; |X X X|
.byte $00 ; | |
SeventhInvader1
.byte $66 ; | XX XX |
.byte $DB ; |XX XX XX|
.byte $7E ; | XXXXXX |
.byte $FF ; |XXXXXXXX|
.byte $7E ; | XXXXXX |
.byte $99 ; |X XX X|
.byte $4A ; | X X X |
.byte $52 ; | X X X |
.byte $81 ; |X X|
.byte $00 ; | |
EighthInvader0
.byte $42 ; | X X |
.byte $BD ; |X XXXX X|
.byte $FF ; |XXXXXXXX|
.byte $DB ; |XX XX XX|
.byte $7E ; | XXXXXX |
.byte $7E ; | XXXXXX |
.byte $5A ; | X XX X |
.byte $49 ; | X X X|
.byte $94 ; |X X X |
.byte $00 ; | |
EighthInvader1
.byte $81 ; |X X|
.byte $BD ; |X XXXX X|
.byte $FF ; |XXXXXXXX|
.byte $5A ; | X XX X |
.byte $7E ; | XXXXXX |
.byte $7E ; | XXXXXX |
.byte $5A ; | X XX X |
.byte $92 ; |X X X |
.byte $29 ; | X X X|
.byte $00 ; | |
NinethInvader0
.byte $99 ; |X XX X|
.byte $B5 ; |X XX X X|
.byte $DB ; |XX XX XX|
.byte $EF ; |XXX XXXX|
.byte $BD ; |X XXXX X|
.byte $1C ; | XXX |
.byte $B5 ; |X XX X X|
.byte $30 ; | XX |
.byte $B1 ; |X XX X|
.byte $00 ; | |
NinethInvader1
.byte $99 ; |X XX X|
.byte $AD ; |X X XX X|
.byte $DB ; |XX XX XX|
.byte $EF ; |XXX XXXX|
.byte $BD ; |X XXXX X|
.byte $38 ; | XXX |
.byte $AD ; |X X XX X|
.byte $0D ; | XX X|
.byte $0C ; | XX |
.byte $00 ; | |
TenthInvader0
.byte $24 ; | X X |
.byte $7E ; | XXXXXX |
.byte $56 ; | X X XX |
.byte $FF ; |XXXXXXXX|
.byte $BC ; |X XXXX |
.byte $3D ; | XXXX X|
.byte $A4 ; |X X X |
.byte $2F ; | X XXXX|
.byte $F0 ; |XXXX |
.byte $00 ; | |
TenthInvader1
.byte $41 ; | X X|
.byte $7E ; | XXXXXX |
.byte $6A ; | XX X X |
.byte $FF ; |XXXXXXXX|
.byte $3D ; | XXXX X|
.byte $BC ; |X XXXX |
.byte $25 ; | X X X|
.byte $F4 ; |XXXX X |
.byte $0F ; | XXXX|
InvaderGhost
.byte $00 ; | |
.byte $00 ; | |
.byte $00 ; | |
.byte $00 ; | |
.byte $00 ; | |
.byte $00 ; | |
.byte $00 ; | |
.byte $00 ; | |
.byte $00 ; | |
.byte $00 ; | |
;Colors
FirstInvaderColor
.byte $BE
.byte $BE
.byte $BE
.byte $BA
.byte $C8
.byte $C8
.byte $C2
.byte $C2
.byte $Ce
SecondInvaderColor
.byte $20
.byte $22
.byte $22
.byte $24
.byte $24
.byte $24
.byte $26
.byte $2A
.byte $2E
ThirdInvaderColor
.byte $12
.byte $14
.byte $16
.byte $18
.byte $18
.byte $18
.byte $18
.byte $12
.byte $14
ForthInvaderColor
.byte $62
.byte $64
.byte $64
.byte $64
.byte $62
.byte $68
.byte $68
.byte $68
.byte $68
.byte #ColorMissiles ;color of grp1 missile and missile1
FifthInvaderColor
.byte $A6
.byte $A6
.byte $A6
.byte $A2
.byte $A2
.byte $A4
.byte $A4
.byte $A6
.byte $A6
.byte #ColorMissiles ;nice trick, grp1 missile and missile1 color
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
TablePtrNumbLow
.byte #<Number0, #<Number1, #<Number2, #<Number3, #<Number4, #<Number5
TablePtrNumbHi
.byte #>Number0, #>Number1, #>Number2, #>Number3, #>Number4, #>Number5
TablePntrInvadersFrame0Low
.byte #<FirstInvader0, #<SecondInvader0, #<ThirdInvader0, #<ForthInvader0, #<FifthInvader0
.byte #<SixthInvader0, #<SeventhInvader0, #<EighthInvader0, #<NinethInvader0, #<TenthInvader0, #<InvaderGhost
TablePntrInvadersFrame1Low
.byte #<FirstInvader1, #<SecondInvader1, #<ThirdInvader1, #<ForthInvader1, #<FifthInvader1
.byte #<SixthInvader1, #<SeventhInvader1, #<EighthInvader1, #<NinethInvader1, #<TenthInvader1, #<InvaderGhost
TablePntrInvadersFrame0Hi
.byte #>FirstInvader0, #>SecondInvader0, #>ThirdInvader0, #>ForthInvader0, #>FifthInvader0
.byte #>SixthInvader0, #>SeventhInvader0, #>EighthInvader0, #>NinethInvader0, #>TenthInvader0, #>InvaderGhost
TablePntrInvadersFrame1Hi
.byte #>FirstInvader0, #>SecondInvader0, #>ThirdInvader0, #>ForthInvader0, #>FifthInvader0
.byte #>SixthInvader0, #>SeventhInvader0, #>EighthInvader0, #>NinethInvader0, #>TenthInvader0, #>InvaderGhost
TableColorInvadersLow
.byte #<FirstInvaderColor, #<SecondInvaderColor, #<ThirdInvaderColor, #<ForthInvaderColor, #<FifthInvaderColor
TableColorInvadersHi
.byte #>FirstInvaderColor, #>SecondInvaderColor, #>ThirdInvaderColor, #>ForthInvaderColor, #>FifthInvaderColor
TableSoundsLow
.byte #<InvadersMarch, #<Fire, #<InvaderExplosion, #<UfoHit, #<SpaceShipHit, #<VictorySongCh0, #<VictorySongCh1
TableSoundsHi
.byte #>InvadersMarch, #>Fire, #>InvaderExplosion, #>UfoHit, #>SpaceShipHit, #>VictorySongCh0, #>VictorySongCh1
TableNusiz
;0 1 2 3 4 5 6 7
.byte #0, #0, #0, #1, #0, #2, #1, #3
TableOffsetInvaders
.byte #0, #32, #16, #16, #0, #0, #0, #0 ;for NUSIZX
TableOffsetInvadersGRP1
.byte #48, #80, #64, #64, #48, #48, #48, #48
TableTimerBombing
.byte #126, #90, #70, #60
TableCoordXMissile
.byte #78, #62, #46, #30, #14, #$fd;.byte #80, #64, #48, #32, #16, #0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Start
CLEAN_START
initializingMainVariables
;when turns on...
;draw logo
lda #TimeForChangeScreen
sta TimerTitleScreen
;set Volumes to 0 for no sound when reset is pressed
lda #0
sta AUDV0
sta AUDV1
;define some pointers
lda #>SpaceShip0
sta PointerSpaceShipHi
lda TableColorInvadersHi
sta PntrColorGRPHi
lda #<Ufo
sta PointerGRP1UfoLow
lda #>Ufo
sta PointerGRP1UfoHi
lda #$36
sta KindOfBarriers
lda #>FirstInvader0
sta PointerGRP0Hi
sta PointerGRP1Hi
;define playfiend features
lda #1
sta CTRLPF ;Playfield mirror 1+0 GRP has priority over PF
sta Direction
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
NextFrame
VERTICAL_SYNC
sta HMCLR
;set zero Cursor
;lda #0
sta CursorRowInvaders
verifyReset
lsr SWCHB ;test Game Reset switch
bcs setTimer ;reset?
jmp Start
setTimer
lda #45 ;37 lines x 76 cycles per line = 2812 cycles / 64 = 43
sta TIM64T
increaseMyTimers
;increase Timer for every thing in the game
inc TimerForAll
inc TimerShiftInvadersColumn
checkGameCompleted
lda LevelNumber
cmp #LastLevelEndGame
bne checkForTitleScreen
jmp drawLogo
checkForTitleScreen
lda TimerTitleScreen ;first start has the value for the logo screen
cmp #TimeForChangeScreen
bne increaseTimerTitleScreen
jmp drawLogo
increaseTimerTitleScreen
lda BooleanGameOver
bne setZeroSomeVariables
inc TimerTitleScreen ;increase timer
setZeroSomeVariables
lda BooleanAtBeginOfEveryLevel
bne setFrameSpaceShip ;no firt start
;only at the first start and at change level
InitializeValues
lda #0
sta CursorSound0
sta TempoCH0
lda #82
sta CoordXSpaceShip ;center of the screen - relatively speaking
lda #%11111100 ;252
sta MaskDeleteBarrier
lda #MaxShields
ldx LevelNumber ;if the game is going, no shields are modified
bne .gameInProgress ;otherwhise, the shields are restored
sta ShieldNumber
sta CoordXUfo
sta BooleanGameOver
lda #48
sta CoordXBarries
lda #1
sta StepBall
.gameInProgress
lda #%10101010
sta DefineBarriers
sta LevelBarriers
lda #%00100000
sta CursorLeftInvaders
lda #%00000001
sta CursorRightInvaders
sta BooleanAtBeginOfEveryLevel
sta CursorWhoBombs
lda #2
sta CursorSpringLeftRight
lda #40 ;coordinate where invaders start
sta CoordXInvaders
lda #96
sta OffsetXInvaders ;relative coordinate last invader
lda #%00111111
sta InvadersLine0
sta InvadersLine1
sta InvadersLine2
sta InvadersLine3
sta InvadersLine4
lda #12
sta CoordYInvaders
sta PowerSingleBarrier ;every barrier shield
lda #152
sta CursorYBallSpaceShip
lda #%00011111
sta TimerMask
lda #31 ;1 more for a best sound when 1 invader remains
sta TotalInvaders
lda #140
sta CoordYMissile1
sta CoordYMissile2
sta CoordXMissile2 ;must not under 15 - necessary for the positionig routine at the first time
sta BooleanNoBulletInGame
sta TimerWhenInvaderStrike ;to delete
;end InitializeValues
;alternate frame of SpaceShip
setFrameSpaceShip
ldy #<SpaceShip0
lda TimerForAll
and #%00000010
bne storeSpaceShipPointer
ldy #<SpaceShip1
storeSpaceShipPointer
sty PointerSpaceShipLow
manageTimers
;TIMER_INVADERS_BOMBING
;before spaceship and aliens can shot
lda BooleanNoBulletInGame
beq postNoBulletInGame
dec BooleanNoBulletInGame
postNoBulletInGame
lda TimerMask
bne decrementTimer
lda TotalInvaders
sta TimerMask
jmp manageCollisionBallUfo
decrementTimer
dec TimerMask
;end manageTimer
manageCollisionBallUfo
lda UfoCollision
beq noCollisionBallUfo
increaseShield
lda ShieldNumber
cmp #MaxShields
bpl noIncreaseShield
inc ShieldNumber
noIncreaseShield
jsr ResetBallMissileGRP0
jmp checkJoystick
noCollisionBallUfo
lda BooleanFireSpaceShip
beq checkJoystick
lda CursorYBallSpaceShip
cmp #EndPointBallSpaceShip ;arrived at the end of the missile path=ball arrived at the top of the screen
bne incrementBallMissile
jsr ResetBallMissileGRP0
jmp checkJoystick
incrementBallMissile
;increment pointer ball/missile SpaceShip
;only if BooleanFireSpaceShip is true
;1 pixel one frame, 2 pixel next frame = 3 pixel in 2 frames
lda TimerForAll
and #%00000001
beq .stepOne
lda CursorYBallSpaceShip
sbc StepBall ;1 or 2 pixel set at alternate level
jmp .stepTwo
.stepOne
lda CursorYBallSpaceShip
sbc #1
.stepTwo
sta CursorYBallSpaceShip
checkJoystick
JOYSTICK_MACRO
checkHitInvader
FIND_HIT_INVADER_MACRO
lda InvadersLine0
ora InvadersLine1
ora InvadersLine2
ora InvadersLine3
ora InvadersLine4
;sta Temp
and CurosorMaskInvaders ;set inside FIND_HIT_INVADER_MACRO
beq .setBooleanToFalse
lda BooleanShiftInvadersColumn
beq checkGameOver
lda TimerShiftInvadersColumn ;delay the shift of the column
bne checkGameOver ;if timer!=0
;shift column of aliens
ldy #$05
shiftColumn
dey ;start from 4
lda InvadersLine0,y ;the hit invader can be everywhere
and CurosorMaskInvaders
bne shiftColumn ;loop for to find where is the alien missing
lda CurosorMaskInvaders
ora InvadersLine0,y
sta InvadersLine0,y ;fill the last line
ldy #$ff
.setColumn
iny ;start from 0
lda InvadersLine0,y
and CurosorMaskInvaders
beq .setColumn ;loop until finds the line with the invader to delete
lda InvadersLine0,y
eor CurosorMaskInvaders ;it is deleted
sta InvadersLine0,y ;new line generated
.setBooleanToFalse
lda #0
sta BooleanShiftInvadersColumn
;end shift column
checkGameOver
lda ShieldNumber
sta BooleanGameOver
bne checkNoMoreInvaders
;set gameover
checkNoMoreInvaders
lda InvadersLine0
ora InvadersLine1
ora InvadersLine2
ora InvadersLine3
ora InvadersLine4
sta Temp
;end level
bne defLeftXInvaders
jmp letInvadersBombing
;end level
defLeftXInvaders
and CursorLeftInvaders
bne defRightXInvaders
newLeftX
;InvaderLineX = 00011111
;the first column is gone
;asl InvaderLineX = 00111110
;all invaders are shifted on the left
;CoordXInvaders+16
;for continue to show in the right position
asl InvadersLine0
asl InvadersLine1
asl InvadersLine2
asl InvadersLine3
asl InvadersLine4
lda CoordXInvaders
adc #16
sta CoordXInvaders
jmp checkNoMoreInvaders
;check the right column. If !=0 the new coloumn and X coordinate are the next - offset of -16px
defRightXInvaders
lda Temp ;ORA operation above
and CursorRightInvaders
bne noNewX
newRightX
asl CursorRightInvaders
lda OffsetXInvaders ;for check right limits
sbc #16
sta OffsetXInvaders
jmp defRightXInvaders
noNewX
;check in GRP1 is alla gone for set the same X coordinate of GRP0
lda Temp
and #%00000111
sta BooleanGRP1AllGone
loadPointersInvaders
LOAD_POINTERS_INVADERS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
moveInvaders
lda TimerMask
bne letInvadersBombing
.checkLeft
lda CoordXInvaders
cmp #LeftLimitAliens ;if 0 changes direction
bpl .checkRight;bne .checkRight
lda #2
sta CursorSpringLeftRight
jmp .doIt
.checkRight
;lda CoordXInvaders ;loaded above
adc OffsetXInvaders
cmp #RightLimitAliens ;when 0 changes direction
bmi .doIt
lda #$fe ;-2
sta CursorSpringLeftRight
.doIt
lda CursorSpringLeftRight
clc
adc CoordXInvaders
sta CoordXInvaders ;this variable can stuck the invaders
;alternate frame animation of the invaders
lda AlternateFrameInvader
eor #1
sta AlternateFrameInvader
;alternate frame animation of the invaders
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
letInvadersBombing
TIMER_INVADERS_BOMBING
setSpeedUfo
lda TimerForAll
and #%00000001 ;it moves at alternate frames
bne prePositionUfo
inc CoordXUfo ;set speed of Ufo 1px every 2 frames
prePositionUfo
lda CoordXUfo
cmp #160
bne setPositionUfo
lda #0
sta CoordXUfo
setPositionUfo
ldy #1 ;parameter (GRP1) for subroutine
jsr PositionElement
setPositionBall
lda CoordXBallSpaceShip
ldy #4 ;parameter (BALL) for subroutine - it is used as missile for the spaceship
jsr PositionElement
setPositionMissile1
lda CoordXMissile1
ldy #3 ;parameter (MISSILE1) for subroutine
jsr PositionElement
setPositionBarriers
lda CoordXBarries
ldy #2 ;parameter (MISSILE0) for subroutine
jsr PositionElement
;;;;;;;;;;;;;;
Loop
lda INTIM
bne Loop
; Disable VBLANK
lda #$0
sta VBLANK
;last line before of scanloop
;Draw the 192 scanlines
ldx #3
sta CXCLR
sta WSYNC ;wait for next scanline
sta HMOVE
ldy #0
;kernel grafico
drawUfo
inx
DRAWBALL_WITHOUT_STA_MACRO2
DRAW_GRP1_UFO_MACRO
cpx CoordYInvaders;#12 - start invaders
bne drawUfo
;get collision GRP1 - BALL
lda #%01000000
and CXP1FB
sta UfoCollision
sta CXCLR
setInvaders
sta WSYNC
inx
DRAWBALL_MACRO2
inx
DRAWBALL_WITHOUT_STA_MACRO2
inx ;for the drawball after stawsync used in positionGRP0
sta HMCLR
sta WSYNC
sta ENABL
DRAWBALL_WITHOUT_STA_MACRO2
ldy CursorRowInvaders
copiesOfInvaders
lda InvadersLine0,y
lsr
lsr
lsr
;and #%00000111
tay
lda TableNusiz,y
sta NUSIZ0
clc
lda CoordXInvaders ;position - parameter for subroutine
adc TableOffsetInvaders,y
positionGRP0
sec
sta WSYNC ;start a new line
; one cycle of .DivideLoopGRP0 is saved
sbc #15
;;;;;;;;;;;;;
;and the saved cycle is used for these
ldy Bullet
sty ENABL
;;;;;;;;;;;;;
.DivideLoopGRP0
sbc #15 ;subtract 15
bcs .DivideLoopGRP0 ;branch until negative
eor #7 ;calculate fine offset
asl
asl
asl
asl
sta RESP0 ;fix coarse position
sta HMP0
endPositionGRP0
;inx ;incremented above
inx ;used after sta wsync
sta WSYNC
DRAWBALL_MACRO2
inx ;anticipate inx in positioGRP1
DRAWBALL_WITHOUT_STA_MACRO2
ldy CursorRowInvaders
lda InvadersLine0,y
and #%00000111
tay
lda TableNusiz,y
sta NUSIZ1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
lda BooleanGRP1AllGone
bne someInvaders
lda CoordXInvaders ;if GRP1 is empty, set same GRP0 coordinate
jmp positionGRP1
someInvaders
;end add
clc
lda CoordXInvaders