forked from historicalsource/asteroids
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA35131.1A
2442 lines (2287 loc) · 50.5 KB
/
A35131.1A
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
.TITLE ASTROD (21503)
.ASECT
.ENABLE AMA
.RADIX 16
;***********************************************
;*
;*DATE INITIATED: 23-FEB-79
;*
;*PROJECT CHARGE #: 21503
;*
;*DISK #: 32 (BACKUP B46)
;*
;*HARDWARE REQUIREMENTS: VECTOR HARDWARE WITH PAGE SELECT ON 2
;*
;*
;*MEMORY REQUIREMENTS: VECTOR RAM: 4000-47FF (2K)
;* VECTOR ROM: 5000-57FF (2K)
;* PROGRAM ROM: 6800-7FFF (6K)
;* SCRATCH: PAGE 0
;* STACK: PAGE 1
;* PLAYER1: PAGE 2
;;* PLAYER2: PAGE 3
;*
;*INTERRUPTS: NMI (4 MS)
;*
;*ASSEMBLY COMMAND STRING: R MAC65
;* ASTROD/A/C
;*
;*LINK COMMAND: OUTPUT(S)=DX1:ASTVEC,ASTROD,ASTMSG,ASTNMI,VECUT,ASTTST
;*
;*PROGRAM DESCRIPTION: THIRD PERSON VIEW OF A SPACE SHIP
;* WITH ASTEROIDS THROUGHOUT SPACE.
;* LARGE ASTEROIDS BREAK UP WHEN
;* HIT AND SMALLER ASTEROIDS DISINTEGRATE
;* WHEN HIT. A LARGE AND SMALL
;* SAUCER ALSO APPEAR TO SHOOT AT
;* THE SHIP
;*
;*CONTROLS: ROTATE LEFT, ROTATE RIGHT, THRUST, FIRE
;* AND HYPERSPACE BUTTONS
;*
;*******************************************************
.SBTTL ************************
.SBTTL *
.SBTTL *PROGRAMMER: ED LOGG
.SBTTL *
.SBTTL ************************
.PAGE
.SBTTL GLOBAL SYMBOL DECLARATIONS
;
;ENTRY POINTS
;
.GLOBL START
;
;
;EXTERNAL ENTRY POINTS
;
.GLOBL VGHALT,VGVCTR,VGRTSL,VGMSGA ;UTILITY ROUTINES(SEE VECUT.MAC)
.GLOBL VGJMPL,VGJSRL,VGLABS
.GLOBL VGADD,VGWAIT
.GLOBL VGHEX,VGHEXZ,VGSABS,VGDOT
.GLOBL SHIPS,ROCKS,EXPPIC,SAUCER ;PICTURES OF SHIP AND ASTEROIDS
.GLOBL VGMSG ;MESSAGE PROCESSOR
.GLOBL PWRON ;ENTRY POINTS FOR ASTTST.MAC
.GLOBL EXPSHP,EXPDIR ;EXPLODING SHIP PICTURES
.GLOBL ASTMSG ;COPYRIGHT MESSAGE
.GLOBL SINCOS,SHIP17
;
;ZERO PAGE GLOBALS
;
.GLOBL VGSIZE,XCOMP,TEMP1,VGLIST,VGBRIT
.GLOBL SYNC,LOUT1,TEMP3,UPDFLG,SND3,FRAME,TEMP2,TEMP4
.GLOBL $CCTIM,$$CRDT,$CMODE,$PSTSL,$LMTIM,$CNCT,$CNSTT,$INTCT
.INCLUDE ASTDEC
.SBTTL PAGE 0 DECLARATIONS
VGSIZE: .BLKB 1 ;SCALING SIZE (0,10,20,...,F0)
VGBRIT: .BLKB 1 ;VECTOR BRIGHTNESS (0=OFF, F0=MAX, 10INC)
VGLIST: .BLKB 2 ;VECTOR LIST POINTER
XCOMP: .BLKB 4 ;X COMPONENT FOR VECTORS
TEMP1: .BLKB 2 ;SCRATCH
TEMP2: .BLKB 2
TEMP3: .BLKB 8 ;8 CKSUMS IN SELF TEST
TEMP4: .BLKB 3
PLAYR: .BLKB 1 ;PLAYER NUMBER (0 OR 1)
PLAYR2: .BLKB 1 ;PLAYER NUMBER *2 (0 OR 2)
LPLAYR: .BLKB 2 ;THE VALUE OF NPLAYR FOR LAST GAME
NPLAYR: .BLKB 1 ;NUMBER OF PLAYERS (1 OR 2)(0=END OF GAME)(-1=UPDATE HIGH SCORES)
HSCORE: .BLKB 2*10. ;HIGH SCORES (LSB,MSB)
UPDINT: .BLKB 1 ;0,1, OR 2 TO INDICATE WHICH INITIAL IS BEING SELECTED
UPDFLG: .BLKB 2 ;POSITIVE MEANS THIS PLAYER HAS SET NEW HIGH SCORE
INITL: .BLKB 3*10. ;INITIALS FOR HIGH SCORE (FIRST,SECOND,THRID)
SCORE: .BLKB 2*2 ;PLAYER 1 AND 2 SCORES (LSB1,MSB1,LSB2,MSB2)
NHITS: .BLKB 1 ;STARTING NUMBER OF HITS PER PLAYER
HITS: .BLKB 2 ;NUMBER OF HITS REMAINING (=0 FOR ATTRACT MODE)
RENTRY: .BLKB 1 ;BLOW UP ON REENTRY IF NEGATIVE (NON-ZERO
;IF HE JUST HYPERSPACED)
GDELAY: .BLKB 1 ;DELAY BEFORE STARTING GAME
SYNC: .BLKB 1 ;FRAME COUNTER SYNC
FRAME: .BLKB 2 ;FRAME COUNTER
$INTCT: .BLKB 1 ;INTERRUPT COUNTER
POLYL: .BLKB 1 ;POLY COUNTER VALUES
POLYH: .BLKB 1
ANGLE: .BLKB 2 ;ANGLE OF ROTATION OF SHIP AND SAUCER
LASTSW: .BLKB 1 ;LAST SWITCH READING
XINCL: .BLKB 1 ;SHIPS LSB FOR X INCREMENT
YINCL: .BLKB 1 ;SHIPS LSB FOR Y INCREMENT
SND1: .BLKB 1 ;NEGATIVE TO START SHIPS FIRE SOUND ELSE LENGTH OF SOUND
SND2: .BLKB 1 ;NEGATIVE TO START SAUCER FIRE SOUND ELSE LENGTH OF SOUND
SND3: .BLKB 1 ;LENGTH OF TONE SOUND
LEXPSND:.BLKB 1 ;LAST VALUE FOR EXPLOSION SOUND (SEE EXPSND)
LSND1: .BLKB 1 ;LAST VALUE FOR SHIP FIRE SOUND (SEE SHPFIR)
LSND2: .BLKB 1 ;LAST VALUE FOR SAUCER FIRE SOUND (SEE SCRFIR)
LTHUMP: .BLKB 1 ;LAST VALUE FOR THUMP SOUND (SEE THUMP)
THUMP1: .BLKB 1 ;LENGTH OF THUMP SOUNDS
THUMP2: .BLKB 1 ;LENGTH BETWEEN THUMP SOUNDS
LOUT1: .BLKB 1 ;LAST VALUE OF OUTPUT LATCH
$$CRDT: .BLKB 1 ;COIN ROUTINE DEFINITION (SEE COIN65.MAC)
$CMODE: .BLKB 1
$LMTIM: .BLKB 1
$CNCT: .BLKB 1
$CCTIM: .BLKB 3
$PSTSL: .BLKB 3
$CNSTT: .BLKB 3
SHIPX: .BLKB 2*6 ;EXPLOSION PICTURE X POSITION (LSB,MSB)
SHIPY: .BLKB 2*6 ; " " Y " "
.SBTTL PAGE 2 AND 3 DECLARATIONS
.=200
OBJ: .BLKB NOBJ+8 ;ZERO IF OBJECT NOT ACTIVE- OTHERWISE PICTURE NUMBER
;BITS 0-2=SIZE, 1=SMALL, 2=MEDIUM, 4=LARGE
;BITS 3-6=PICTURE NUMBER
XINC: .BLKB NOBJ+8 ;X INCREMENT FOR UPDATING POSITION(S8999.BBB)
YINC: .BLKB NOBJ+8 ;Y INCREMENT FOR UPDATING POSITION(S9999.BBB)
OBJXH: .BLKB NOBJ+8 ;X POSITION OF OBJECT (HIGH ORDER)(00099999)
OBJYH: .BLKB NOBJ+8 ;Y POSITION OF OBJECT (HIGH ORDER)(00099999)
OBJXL: .BLKB NOBJ+8 ;X POSITION OF OBJECT (LOW ORDER)(99999.BBB)
OBJYL: .BLKB NOBJ+8 ;Y POSITION OF OBJECT (LOW ORDER)(99999.BBB)
SROCKS: .BLKB 1 ;NUMBER OF ROCKS TO START WITH
NROCKS: .BLKB 1 ;CURRENT NUMBER OF ROCKS
EDELAY: .BLKB 1 ;DELAY BEFORE ENEMY ENTRY OR FIRING
SEDLAY: .BLKB 1 ;STARTING ENEMY DELAY
RTIMER: .BLKB 1 ;ROCK TIME - IF 0 SEND IN SAUCER ANYWAY
SDELAY: .BLKB 1 ;DELAY COUNT BEFORE ADDING SHIP (80=SHIP JUST DESTROYED)
RDELAY: .BLKB 1 ;DELAY COUNT BEFORE ADDING ROCKS
THUMP3: .BLKB 1 ;STARTING VALUE FOR THUMP2
DIFCTY: .BLKB 1 ;DIFFICULTY VALUE FOR STARTING SAUCERS
.PAGE
.SBTTL MAIN LINE LOOP
.=6800
; JMP PWRON
START: JSR INIT1 ;TURN OFF SOUNDS
JSR INIT ;INITIALIZE PLAYER 1 FOR START OF GAME
START1: JSR NEWAST ;START UP NEW ASTEROIDS
START2: LDA A,STSTSW ;NOTE NMI NOT ACTIVE IF STSTSW ON
5$: BMI 5$ ;IN SELF TEST-WANT FOR WATCHDOG TO RESET SOUNDS
LSR SYNC
BCC START2 ;WAIT FOR START OF FRAME
10$: LDA A,HALT
BMI 10$ ;WAIT FOR BEAM TO HALT
LDA A,VECRAM+1 ;SWITCH VECTOR BUFFERS
EOR I,02
STA A,VECRAM+1 ;CHANGE JMPL TO STARTING BUFFER
STA A,GOADD ;START VECTOR GENERATOR
STA A,WTDOG
INC FRAME ;INCREMENT FRAME COUNTER
BNE 11$ ;NO OVERFLOW
INC FRAME+1
11$: LDX I,VECRAM/100
AND I,02
BNE 12$ ;USE LOWER BUFFER
LDX I,VECRAM/100+04 ;USE UPPER BUFFER
12$: LDA I,VECRAM&0FF+2
STA VGLIST
STX VGLIST+1 ;RESET VECTOR LIST POINTER
JSR CHKST ;CHECK FOR START
BCS START ;START NEW GAME
JSR UPDATE ;UPDATE HIGH SCORE TABLES
JSR GETINT ;GET INITIALS FOR ANY NEW HIGH SCORE
BPL 20$ ;UPDATE IN PROGRESS
JSR SCORES ;DISPLAY HIGH SCORES
BCS 20$ ;WE ARE DISPLAYING SCORE TABLE
LDA GDELAY ;(NOT ENOUGH TIME FOR ASTEROIDS AND SCORE TABLES)
BNE 15$ ;STARTING A NEW PLAYER
JSR FIRE ;FIRE SHIPS TORPEDOS
JSR HYPER ;CHECK FOR HYPERSPACE
JSR MOVE ;MOVE SHIP BY CONTROLS
JSR ENEMY ;LAUNCH ENEMY SAUCER AND TORPEDOS
15$: JSR MOTION ;MOVE OBJECTS
JSR COLIDE ;CHECK FOR COLLISIONS
20$: JSR PARAMS ;DISPLAY SCORE AND OTHER PARAMETERS
JSR SOUNDS ;GENERATE SOUNDS
LDA I,1023./8
TAX
JSR VGSABS ;POSITION BEAM FOR MINIMUM CURRENT DRAW
JSR RAND ;KEEP RANDOM NUMBERS COMING
JSR VGHALT ;ADD HALT TO VECTOR LIST
LDA RDELAY
BEQ 30$ ;NO DELAY TO DECREMENT
DEC RDELAY
30$: ORA NROCKS
BNE START2 ;LOOP FOR NEXT PASS
BEQ START1 ;START NEW SET OF ASTEROIDS
.SBTTL CHKST-CHECK FOR START/END OF GAME
;CHKST -CHECK FOR START/END OF GAME
;
;EXIT (C)=SET IF STARTING A NEW GAME
CHKST: LDA NPLAYR
BEQ 10$ ;GAME NOT IN PROGRESS
LDA GDELAY
BNE 60$ ;STAY READY MODE
JMP CHKST1 ;WE ARE NOT IN PLAYER READY MODE
60$: DEC GDELAY
JSR CHKST2 ;DISPLAY PLAYER NUMBER MESSAGE
30$: CLC
RTS
35$: LDA I,2
STA $$CRDT ;FREE PLAY CREDIT
BNE 15$ ;ALWAYS
10$: LDA UPDFLG
AND UPDFLG+1
BPL 30$ ;IF UPDATING INITIALS
LDA $CMODE ;IF FREE PLAY
AND I,03
BEQ 35$
CLC
ADC I,07
TAY
JSR VGMSG ;GAME COST MESSAGE
15$: LAH ASTMSG
LXL ASTMSG
JSR VGJSRL ;PUT OUT "ASTEROIDS BY ATARI"
LDY $$CRDT
BEQ 30$ ;NO CREDIT-NO PLAY
LDX I,01
LDA A,STRT1
BMI 20$ ;ONE PLAYER START
CPY I,02
BCC 40$ ;ONLY 1 CREDIT
LDA A,STRT2
BPL 40$ ;NO START YET
LDA LOUT1 ;LAST VALUE TO OUT1
ORA I,04 ;SWITCH PAGE 2
STA LOUT1
STA A,OUT1
JSR INIT ;REINITIALIZE MEMORY
JSR NEWAST ;NEW ASTEROIDS
JSR NEWSHP ;PUT SHIP IN MIDDLE
LDA NHITS
STA HITS+1
LDX I,02
DEC $$CRDT ;ONE CREDIT LESS
20$: STX NPLAYR ;NUMBER OF PLAYERS
DEC $$CRDT ;ONE CREDIT LESS
LDA LOUT1
AND I,0F8 ;BE SURE WE ARE ON THE RIGHT SIDE
EOR NPLAYR ;LEAVE LITE ON FOR RIGHT GAME
STA LOUT1
STA A,OUT1 ;SET BANK FOR PLAYER 1
JSR NEWSHP ;PUT SHIP IN MIDDLE
LDA I,01
STA SDELAY
STA SDELAY+100
LDA I,92 ;ENOUGH FOR 3 LARGE SAUCERS
STA SEDLAY ;STARTING ENEMY DELAY
STA SEDLAY+100
STA EDELAY+100
STA EDELAY ;DELAY ENTRY OF SHIP
LDA I,7F
STA RDELAY ;DELAY FOR ROCKS
STA RDELAY+100
LDA I,05 ;INITIALIZE GAME DIFFICULTY
STA DIFCTY
STA DIFCTY+100
LDA I,-1
STA UPDFLG
STA UPDFLG+1
LDA I,80
STA GDELAY
ASL ;LDA I,0 SETS CARRY TOO
STA PLAYR
STA PLAYR2
LDA NHITS
STA HITS ;NUMBER OF HITS ALLOWED
LDA I,04
STA LTHUMP ;INITIALIZE THUMP SOUND AND COUNTERS
STA THUMP2
LDA I,30
STA THUMP3
STA THUMP3+100 ;RESET STARTING THUMP SOUND
STA A,NRESET ;RESET NOISE GENERATOR
RTS
40$: LDA FRAME
AND I,20
BNE 41$ ;NOT TIME TO DISPLAY MESSAGE
LDY I,6
JSR VGMSG ;DISPLAY "PUSH START" MESSAGE
41$: LDA FRAME
AND I,0F
BNE 45$ ;DO NOT CHANGE LITE
LDA I,01
CMP $$CRDT ;SET CARRY IF $$CRDT=1
ADC I,01 ;A=2 IF $$CRDT > 1 ELSE 3
EOR I,01 ;A=3 IF $$CRDT > 1 ELSE 2
EOR LOUT1
STA LOUT1 ;SET NMI WRITE TO OUT1
45$: CLC
RTS
CHKST1: LDA Z,FRAME
AND I,3F
BNE 70$ ;ONLY EVERY 1 SECOND
LDA THUMP3
CMP I,08
BEQ 70$ ;AT FASTEST RATE NOW
DEC THUMP3
70$: LDX PLAYR
LDA X,HITS
BNE 60$ ;IF HE STILL IN GAME
LDA OBJ+NOBJ+4
ORA OBJ+NOBJ+5
ORA OBJ+NOBJ+6
ORA OBJ+NOBJ+7
BNE 60$ ;TORPEDO STILL ALIVE
LDY I,7
JSR VGMSG ;GAME OVER MESSAGE
LDA NPLAYR
CMP I,02
BCC 60$ ;1 PLAYER GAME
JSR CHKST2 ;DISPLAY PLAYER NUMBER
60$: LDA OBJ+NOBJ
BNE 80$ ;IF SHIP ALIVE OR EXPLODING
LDA SDELAY
CMP I,80
BNE 80$ ;SHIP RETURNING TO LIFE
LDA I,10
STA SDELAY ;RESET DELAY BEFORE ENTERING SHIP
LDX NPLAYR
LDA HITS
ORA HITS+1
BEQ 90$ ;GAME IS ALL OVER
JSR RSAUCR ;RESET SAUCER VALUES
DEX
BEQ 80$ ;ONE PLAYER NO MESSAGE NEEDED
LDA I,80
STA GDELAY ;DELAY BEFORE STARTING PLAYER
LDA PLAYR
EOR I,01
TAX ;1 TO 0 AND 0 TO 1
LDA X,HITS
BEQ 80$ ;NO HITS FOR THIS PLAYER
STX PLAYR ;SET PLAYER NUMBER
LDA I,04
EOR LOUT1
STA LOUT1
STA A,OUT1 ;SET BANK FOR PLAYER
TXA
ASL
STA PLAYR2
80$: CLC
RTS
90$: STX LPLAYR ;SAVE NUMBER OF PLAYERS IN THIS GAME
LDA I,-1
STA NPLAYR ;FLAG TO UPDATE HIGH SCORES
JSR INIT1 ;TURN OFF SOUNDS
LDA I,03
ORA LOUT1 ;TURN OFF LIGHTS
STA LOUT1 ;LET NMI WRITE TO OUT1
CLC
RTS
CHKST2: LDY I,1
JSR VGMSG ;DISPLAY "PLAYER" MESSAGE
LDY PLAYR
INY
TYA ;1 OR 2
JSR VGHEX ;DISPLAY PLAYER NUMBER
RTS
CKSUM2: .BYTE 23 ;6800-6BFF
.SBTTL COLLIDE-COLLISION DETECTOR
COLIDE: LDX I,07
10$: LDA X,OBJ+NOBJ
BEQ 13$ ;IF INACTIVE TORPEDO
BPL 15$
13$: DEX
BPL 10$
RTS
15$: LDY I,NOBJ+1
CPX I,04
BCS 20$ ;NOT SAUCER OR SHIP OR SAUCERS TORPEDOES
DEY ;BYPASS SAUCER TO SAUCER COLISION
TXA
BNE 20$ ;SHIP DOESN'T COLIDE WITH SHIP
19$: DEY
BMI 13$ ;END OF LOOP
20$: LDA Y,OBJ
BEQ 19$ ;IF INACTIVE
BMI 19$ ;IF AN EXPLOSION
STA TEMP2
LDA Y,OBJXL ;TEST X DIRECTION
SEC
SBC X,OBJXL+NOBJ
STA TEMP1
LDA Y,OBJXH
SBC X,OBJXH+NOBJ
LSR
ROR TEMP1
ASL
BEQ 25$ ;IF WITHIN 64.
BPL 40$ ;TOO FAR AWAY
EOR I,0FE
BNE 40$ ;TOO FAR AWAY
LDA TEMP1
EOR I,0FF
STA TEMP1 ;DISTANCE FROM TORPEDO
25$: LDA Y,OBJYL
SEC
SBC X,OBJYL+NOBJ
STA TEMP1+1
LDA Y,OBJYH
SBC X,OBJYH+NOBJ
LSR
ROR TEMP1+1
ASL
BEQ 35$ ;IF WITHIN 64.
BPL 40$ ;TOO FAR AWAY
EOR I,0FE
BNE 40$ ;TOO FAR AWAY
LDA TEMP1+1
EOR I,0FF
STA TEMP1+1 ;DISTANCE-1 FROM TORPEDO
35$: LDA I,42.
LSR TEMP2
BCS 37$ ;SMALL SIZE
LDA I,72.
LSR TEMP2
BCS 37$ ;MEDIUM SIZE
LDA I,132. ;LARGE SIZE
37$: CPX I,01
BCS 36$ ;NOT THE SHIP
ADC I,28. ;CARRY CLEAR
36$: BNE 38$ ;NOT THE SAUCER
ADC I,18. ;FOR SMALL SAUCER
LDX OBJ+NOBJ+1
DEX
BEQ 34$ ;IF SMALL SAUCER
ADC I,18.
34$: LDX I,01 ;RESTORE X
38$: CMP TEMP1
BCC 40$ ;NO HIT
CMP TEMP1+1
BCC 40$ ;NO HIT
STA TEMP2
LSR
CLC
ADC TEMP2
STA TEMP2 ;3/2 DISTANCE (NO CARRY IF LESS THAN 172.)
LDA TEMP1+1 ;CARRY IS CLEAR
ADC TEMP1
BCS 40$ ;NUMBERS TOO LARGE
CMP TEMP2
BCS 40$ ;CHOP OFF CORNERS-A MISS ON OBJECT
JSR DSTRCT
39$: JMP 13$
40$: DEY
BMI 39$ ;NEXT TORPEDO, SAUCER OR SHIP
JMP 20$ ;NEXT ROCK
.SBTTL CPYPOS - COPY ATTRIBUTES OF ROCK
;CPYPOS - COPY ATTRIBUTES OF ROCK
;
;ENTRY (X)=NEW ROCK INDEX
; (Y)=OLD ROCK INDEX
CPYPOS: LDA Y,OBJ ;COPY PICTURE
AND I,07
STA TEMP1 ;SAVE SIZE
JSR RAND ;RANDOM NUMBER
AND I,18 ;PICTURE NUMBER
ORA TEMP1
STA X,OBJ
LDA Y,OBJXL ;COPY POSITION
STA X,OBJXL
LDA Y,OBJXH
STA X,OBJXH
LDA Y,OBJYL
STA X,OBJYL
LDA Y,OBJYH
STA X,OBJYH
LDA Y,XINC ;COPY VELOCITY
STA X,XINC
LDA Y,YINC
STA X,YINC
RTS
.SBTTL CPYVEC-COPY AND MODIFY VECTORS
;CPYVEC-COPY AND MODIFY VECTORS (UP TO ONE PAGE WORTH)
;
;ENTRY (TEMP1)=MASK FOR X SIGN (0 OR 4)
; (TEMP1+1)=MASK FOR Y SIGN (0 OR 4)
; (TEMP4+2)=VALUE TO BE ADDED TO INTENSITY (0,10,20...)
; (A)=LSB OF VECTOR TABLE TO COPY
; (X)=MSB OF VECTOR TABLE TO COPY
;EXIT (VGLIST,VGLIST+1)=UPDATED VECTOR LIST POINTER
; (TEMP2,TEMP2+1)=ADDRESS OF VECTOR TABLE
; (Y)=INDEX-1 INTO PICTURE (AT RTSL-1)
;USES (TEMP2,TEMP2+1),A,Y
CPYVEC: STA TEMP2
STX TEMP2+1 ;SETUP INDIRECT POINTER
LDY I,0
COPY: INY
LDA NY,TEMP2
EOR TEMP1+1 ;MASK SIGN TO MATCH Y
STA NY,VGLIST
DEY
CMP I,0F0
BCS 20$ ;IF AN ALPH INSTRUCTION
CMP I,0A0
BCS 30$ ;NOT A VECTOR INSTRUCTION-QUIT
LDA NY,TEMP2 ;COPY REST
STA NY,VGLIST
INY
INY
LDA NY,TEMP2
STA NY,VGLIST
INY
LDA NY,TEMP2
EOR TEMP1 ;MASK SIGN TO MATCH X
ADC TEMP4+2 ;CHANGE INTENSITY
STA NY,VGLIST
15$: INY
BNE COPY ;ALWAYS (I HOPE)
30$: DEY ;USE INDEX
JMP VGADD ;UPDATE VECTOR LIST POINTER
20$: LDA NY,TEMP2 ;ALPH INSTRUCTION
EOR TEMP1 ;MASK FOR X SIGN
CLC
ADC TEMP4+2 ;CHANGE INTENSITY
STA NY,VGLIST
INY
BNE 15$ ;ALWAYS
.SBTTL DSTRCT-DESTRUCTION DURING COLLISION
;DSTRCT-DESTRUCTION DURING COLLISION
;
;ENTRY (X)=SHIP, SAUCER OR TORPEDO INDEX-NOBJ
; (Y)=ROCK, SHIP OR SAUCER INDEX
;
DSTRCT: CPX I,01
BNE 60$ ;NOT SAUCER HITTING SHIP OR ROCKS
CPY I,NOBJ
BNE 62$ ;SAUCER HIT ROCK
LDX I,0
LDY I,NOBJ+1 ;SHIP HIT SAUCER
60$: TXA
BNE 63$ ;IF NOT SHIP HIT A ROCK
LDA I,081
STA SDELAY ;DELAY RESTARTING SHIP
LDX PLAYR
DEC X,HITS ;DECREASE NUMBER OF LIVES
LDX I,0
62$: LDA I,0A0
STA X,OBJ+NOBJ ;EXPLOSION TIMER
LDA I,0
STA X,XINC+NOBJ ;STOP SHIP
STA X,YINC+NOBJ
CPY I,NOBJ
BCC 65$ ;SHIP OR SAUCER HITTING ROCK
BCS 80$ ;SHIP & SAUCER COLLIDE
63$: LDA I,0
STA X,OBJ+NOBJ ;CLEAR TORPEDO
CPY I,NOBJ
BEQ 75$ ;HIT SHIP WITH TORPEDO
BCS 80$ ;HIT SAUCER WITH TORPEDO
65$: JSR SPLIT ;SPLIT UP ROCKS
70$: LDA Y,OBJ
AND I,03 ;SIZE 0=SMALL,1=MEDUIM,2=LARGE
EOR I,02 ;2=SMALL,3=MEDUIM,0=LARGE
LSR
ROR
ROR
ORA I,3F ;LENGTH OF EXPLOSION
STA LEXPSND
LDA I,0A0 ;TIMER FOR EXPLOSION
STA Y,OBJ ;STOP OBJECTS MOTION
LDA I,0
STA Y,XINC
STA Y,YINC
90$: RTS
75$: TXA
LDX PLAYR
DEC X,HITS ;DECREASE NUMBER OF LIVES
TAX ;RESTORE X
LDA I,081 ;DELAY BEFORE REENTERING SHIP
STA SDELAY
BNE 70$ ;ALWAYS
80$: LDA SEDLAY
STA EDELAY ;DELAY BEFORE ENTERING SAUCER
LDA NPLAYR
BEQ 70$ ;IF IN ATTRACT
STX TEMP3 ;SAVE X
LDX PLAYR2
LDA OBJ+NOBJ+1
LSR
LDA I,99 ;1000 FOR SMALL
BCS 85$ ;IF SMALL SAUCER
LDA I,20 ;200 POINTS FOR LARGE SAUCER
85$: JSR POINTS ;ADD 1000 PTS AND CHECK FOR 10K
LDX TEMP3 ;RESTORE X
JMP 70$
.SBTTL ENEMY-LAUNCH EMEMY SAUCER
;ENEMY -LAUNCH ENEMY SAUCER
;
ENEMY: LDA FRAME
AND I,03
BEQ 1$ ;EVERY FOURTH FRAME
50$: RTS
1$: LDA OBJ+NOBJ+1
BMI 50$ ;IF EXPLODING
BEQ 15$ ;IF NOT ALIVE YET
JMP EFIRE ;FIRE ENEMY TORPEDOES
15$: LDA NPLAYR
BEQ 6$ ;IF IN ATTRACT SEND IN SAUCER
LDA OBJ+NOBJ
BEQ 50$ ;IF YOU ARE NOT VISIBLE
BMI 50$ ;IF EXPLODING
6$: LDA RTIMER
BEQ 2$ ;IF TIMER ALREADY
DEC RTIMER ;DECREMENT ZERO TIMER
2$: DEC EDELAY
BNE 50$ ;NO TIME YET
LDA I,18.
STA EDELAY ;DELAY BEFORE SHOOTING OR ENTERING
LDA RTIMER
BEQ 5$ ;IF NO ROCKS HIT ENTER SAUCER
LDA NROCKS
BEQ 50$ ;IF NO ROCKS
CMP DIFCTY
BCS 50$ ;TOO MANY ROCKS
5$: LDA SEDLAY
SEC
SBC I,06
CMP I,20
BCC 8$ ;IF BELOW MINIMUM
STA SEDLAY
8$: LDA I,0
STA A,OBJXL+NOBJ+1
STA A,OBJXH+NOBJ+1
JSR RAND ;RANDOM NUMBER
LSR
ROR A,OBJYL+NOBJ+1
LSR
ROR A,OBJYL+NOBJ+1
LSR
ROR A,OBJYL+NOBJ+1
CMP I,18
BCC 10$ ;MUST BE 0 TO 767
AND I,17
10$: STA A,OBJYH+NOBJ+1 ;STARTING VERTICAL POSITION
LDX I,10
BIT POLYH
BVS 20$ ;PICK DIRECTION
LDA I,1F
STA A,OBJXH+NOBJ+1
LDA I,0FF
STA A,OBJXL+NOBJ+1 ;START ON RIGHT SIDE
LDX I,-10
20$: STX XINC+NOBJ+1
LDX I,02
LDA SEDLAY
BMI 40$ ;KEEP IT LARGE FOR FIRST FEW APPEARANCES
LDY PLAYR2
LDA Y,SCORE+1
CMP I,30
BCS 38$ ;IF SCORE LARGER, KEEP SMALL SAUCER
JSR RAND
STA TEMP1
LDA SEDLAY
LSR ;START AT 1/4 LARGE SAUCER
CMP TEMP1
BCS 40$ ;KEEP LARGE SAUCER
38$: DEX ;SMALL SAUCER
40$: STX OBJ+NOBJ+1 ;USE MEDUIM SIZE PICTURE
RTS
.SBTTL EFIRE-ENEMY FIRE CONTROL
;EFIRE-ENEMY FIRE CONTROL
;
EFIRE: LDA FRAME
ASL
BNE 10$ ;NOT TIME TO CHANGE DIRECTION
JSR RAND
AND I,03
TAX
LDA X,99$
STA YINC+NOBJ+1
10$: LDA NPLAYR
BEQ 30$ ;IF IN ATTRACT
LDA SDELAY
BNE 40$ ;DONT FIRE IF YOU ARE DEAD
30$: DEC EDELAY
BEQ 50$ ;NOT TIME TO SHOOT
40$: RTS
50$: LDA I,10.
STA EDELAY ;DELAY BEFORE NEXT SHOT
LDA OBJ+NOBJ+1
LSR
BEQ 80$ ;IF SMALL SAUCER
JSR RAND
JMP 96$ ;FIRE IN RANDOM DIRECTION
80$: LDA XINC+NOBJ+1
CMP I,80
ROR
STA TEMP2+1
LDA A,OBJXL+NOBJ ;GET X DISTANCE TO SHIP
SEC
SBC A,OBJXL+NOBJ+1
STA TEMP2
LDA A,OBJXH+NOBJ
SBC A,OBJXH+NOBJ+1
ASL TEMP2
ROL
ASL TEMP2
ROL ;-7F TO +7F
SEC ;REMEMBER TORPEDO VELOCITY DEPENDS ON
SBC TEMP2+1 ;SAUCER SPEED
TAX
LDA YINC+NOBJ+1
CMP I,80
ROR
STA TEMP2+1
LDA A,OBJYL+NOBJ
SEC
SBC A,OBJYL+NOBJ+1
STA TEMP2
LDA A,OBJYH+NOBJ
SBC A,OBJYH+NOBJ+1
ASL TEMP2
ROL
ASL TEMP2
ROL ;-5F TO +5F
SEC
SBC TEMP2+1 ;REMEMBER TO ACCOUNT FOR OUR MOTION
TAY ;-60 TO +60
JSR ATAN ;ARCTAN (Y/X)
STA ANGLE+1
JSR RAND ;RANDOM NUMBER
LDX PLAYR2
LDY X,SCORE+1
CPY I,35
LDX I,0
BCC 90$ ;IF NOT TO LIMIT YET
INX
90$: AND X,97$
BPL 95$ ;NO SIGN EXTENSION
ORA X,98$
95$: ADC ANGLE+1 ;DONT BE TOO GOOD-JUST CLOSE
96$: STA ANGLE+1 ;ANGLE TO AIM
LDY I,03 ;START LOOKING HERE
LDX I,01 ;FIRE FOR SAUCER
STX TEMP3+1 ;3 SAUCER TORPEDOS
JMP FIRE1 ;FIRE A TORPEDO
97$: .BYTE 8F,87 ;(GOOD,REAL GOOD) SMALL SAUCER
98$: .BYTE 70,78
99$: .BYTE -10,0,0,10 ;DIFFERENT SAUCER VELOCITIES
.SBTTL FIRE-FIRE SHIPS TORPEDOS
;FIRE- FIRE SHIP TORPEDOS
;
FIRE: LDA NPLAYR
BEQ FIRE2 ;IN ATTRACT
ASL A,FIRESW ;FULLY DECODED FOR R/W
ROR LASTSW
BIT LASTSW
BPL FIRE2 ;IF NOT ON
BVS FIRE2 ;IF NOT OFF BEFORE
LDA SDELAY
BNE FIRE2 ;SHIP NOT VISIBLE YET
TAX ;LDX I,0
LDA I,03
STA TEMP3+1 ;STOPPING INDEX FOR SHIP
LDY I,7 ;NUMBER OF TORPEDOS ALLOWED
FIRE1: LDA Y,OBJ+NOBJ
BEQ FIRE3 ;WE FOUND INACTIVE ONE
DEY
CPY TEMP3+1
BNE FIRE1
FIRE2: RTS ;FIND INACTIVE TORPEDO TO USE
FIRE3: STX TEMP3
LDA I,12
STA Y,OBJ+NOBJ ;SET TIMER FOR LENGTH OF LIFE
LDA X,ANGLE
JSR COS ;COS(ANGLE)-SHIPS SPEED=X CHANGE TO TORPEDO
LDX TEMP3
CMP I,80 ;DIVIDE BY 2
ROR ;SS999.BBB
STA TEMP1+1
CLC
ADC X,XINC+NOBJ
BMI 23$ ;IF NEGATVE
CMP I,70
BCC 30$ ;IF MAX NOT EXCEEDED
LDA I,6F
BNE 30$ ;ALWAYS
23$: CMP I,-6F
BCS 30$ ;IF MIN NOT EXCEEDED
LDA I,-6F
30$: STA Y,XINC+NOBJ ;SET X SPEED
LDA X,ANGLE
JSR SIN ;SIN (ANGLE)
LDX TEMP3
CMP I,80 ;DIVIDE BY 2
ROR ;SSAAA.BBB
STA TEMP2+1
CLC
ADC X,YINC+NOBJ
BMI 33$ ;IF NEGATIVE
CMP I,70
BCC 40$ ;IF IN RANGE
LDA I,6F ;SET MAX
BNE 40$ ;ALWAYS
33$: CMP I,-6F
BCS 40$ ;IF IN RANGE
LDA I,-6F
40$: STA Y,YINC+NOBJ
LDX I,0
LDA TEMP1+1 ;SCALE TO PUT TORP AT NOSE OF SHIP
BPL 45$ ;SIGN EXTENSION
DEX ;LDX I,0FF
45$: STX TEMP1
LDX TEMP3
CMP I,80
ROR
CLC
ADC TEMP1+1 ;MULTIPLY BY 3/2
CLC
ADC X,OBJXL+NOBJ ;ADD SHIPS POSITION TO GET STARTING POSITION
STA Y,OBJXL+NOBJ
LDA TEMP1
ADC X,OBJXH+NOBJ
STA Y,OBJXH+NOBJ
LDX I,0
LDA TEMP2+1 ;SCALE AGAIN TO PUT AT NOSE
BPL 50$ ;SIGN EXTENSION
DEX ;LDX I,0FF
50$: STX TEMP2
LDX TEMP3
CMP I,80
ROR
CLC
ADC TEMP2+1 ;MULTIPLY BY 3/2
CLC
ADC X,OBJYL+NOBJ ;ADD SHIPS POSITION TO GET STARTING POSITION
STA Y,OBJYL+NOBJ
LDA TEMP2
ADC X,OBJYH+NOBJ
STA Y,OBJYH+NOBJ
LDA I,80
STA X,SND1 ;START FIRE SOUND FOR SHIP OR SAUCER
RTS
CKSUM3: .BYTE 0DC ;6C00-6FFF
.SBTTL GETINT-GET PLAYERS INITIALS FOR HIGH SCORE
;GETINT-GET PLAYERS INITIALS FOR HIGH SCORE
;
GETINT: LDA UPDFLG
AND UPDFLG+1
BPL 10$ ;GET PLAYERS INITIALS
RTS
10$: LDA LPLAYR
LSR
BEQ 25$ ;IF LAST GAME WAS 1 PLAYER GAME
LDY I,1
JSR VGMSG ;DISPLAY MESSAGE 1
LDY I,02
LDX UPDFLG+1
BPL 20$ ;IF PLAYER 2
DEY ;LDY I,01
20$: STY PLAYR
LDA FRAME
AND I,10
BNE 25$ ;FLASH PLAYER NUMBER
TYA
JSR VGHEX ;DISPLAY PLAYER NUMBER
25$: LDY I,2
JSR VGMSG ;DISPLAY MESSAGE 2 - INSTRUCTIONS
LDY I,3
JSR VGMSG
LDY I,4
JSR VGMSG
LDY I,5
JSR VGMSG
LDA I,20
STA VGSIZE ;USE LARGER CHARACTER FOR INITIALS
LDA I,400./4
LDX I,228./4
JSR VGSABS ;POSITION BEAM
LDA I,70
JSR VGWAIT ;WAIT FOR BEAM
LSR PLAYR ;0 OR 1=PLAYER NUMBER-FOR FLASHING SCORE
LDX PLAYR
LDY X,UPDFLG
STY TEMP2
TYA
CLC
ADC UPDINT
STA TEMP2+1 ;INDEX FOR THE INITIAL WE ARE WORKING ON
JSR INITAL ;DISPLAY INITIAL
LDY TEMP2
INY
JSR INITAL ;DISPLAY INITIAL
LDY TEMP2
INY
INY
JSR INITAL ;DISPLAY THIRD INITIAL
50$: LDA A,HYPSW
ROL
ROL LASTSW ;SWITCH DEBOUNCE
LDA LASTSW
AND I,1F
CMP I,07
BNE 60$ ;NOT A VALID SWITCH
INC UPDINT ;ADVANCE TO NEXT LETTER
LDA UPDINT
CMP I,03
BCC 55$ ;IF WE ARE NOT DONE
LDX PLAYR
LDA I,-1
STA X,UPDFLG ;CLEAR UPDATING FLAG
LDX I,0
STX UPDINT ;START NEXT PLAYER
INX ;PREVENT TIMEOUT IF BOTH PLAYERS SET HIGH SCORE
STX FRAME+1 ;BRING UP HIGH SCORE TABLE NEXT
RTS
55$: INC TEMP2+1
LDX TEMP2+1
LDA I,0F0 ;ABOUT 64 SECONDS
STA FRAME+1 ;RESET TIMEOUT
LDA I,11.
STA X,INITL ;SET INITIAL TO A
60$: LDA FRAME+1
BNE 65$ ;NO TIMEOUT
LDA I,-1
STA UPDFLG
STA UPDFLG+1 ;STOP INITIALS
BMI 90$ ;ALWAYS
65$: LDA FRAME
AND I,07
BNE 90$ ;EVERY 8TH FRAME
LDA A,ROTL
BPL 70$ ;NOT ROTATING LEFT
LDA I,01
BNE 75$ ;ADD 1 TO LETTER NUMBER
70$: LDA A,ROTR
BPL 90$ ;NOT ROTATING RIGHT
LDA I,-1
75$: LDX TEMP2+1
CLC
ADC X,INITL ;CHANGE INITIAL
BMI 78$ ;BEFORE A BLANK MUST BE Z