This repository has been archived by the owner on Nov 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
berzerk-mmx.s
executable file
·2878 lines (2838 loc) · 48.7 KB
/
berzerk-mmx.s
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
;*********************************************************************
; BERZERK MMX
; written by Robert Hurst <robert@hurst-ri.us>
; updated version: 30-Oct-2011
.include "VIC-SSS-MMX.h"
.segment "SSSBUF"
.global HISCORE
;
; runtime variables
;
FRAME: .byte 0 ; video frame counter for action/animation timing
; bit# 4:FIRE, 3:UP, 2:LEFT, 1:DOWN, 0:RIGHT
ACTION: .byte 0 ; player's action this frame
ACTION2: .byte 0 ; player's action last frame
ACTIONS: .byte 0 ; frames this action was repeated
BONUS: .byte 0 ; bonus for clearing level
CORNERS: .res 24 ; maze wall corners
DEATH: .byte 0 ; hero death sequence
ENTRANCE: .word 0 ; JMP pointer
EXIT: .byte 0 ; closed bit# 3:UP, 2:LEFT, 1:DOWN, 0:RIGHT
EXTRA: .byte 0 ; extra life @ 5000-points, baby!
FIRE: .byte 0 ; >0: firing
HEROSHOT: .res 2 ;
HISCORE: .byte $00,$25,$00
KABOOM: .byte 0 ; exploding robot sound effect
LEVEL: .byte 0 ; 0-255
LIVES: .byte 0 ; 0-4
MAZE: .res 15 ; bit# 7:flag, 3:top, 2:left, 1:bottom, 0:right
MONO: .byte 0 ; monochrome color code used for this level
NMES: .byte 0 ; # of robots created for this level
NMEBITS: .res 10 ; which frame (1-3)
NMEPAUSE: .byte 0 ;
NMERELOAD: .byte 0 ; progressive reload
NMESHOT: .res 5 ;
NMESHOTS: .byte 0 ; # of bullets allowed for this level
NMESPEED: .byte 0 ; progressive walking
NMESSPEED: .byte 0 ; progressive shooting
NMEWAIT: .res 10 ; frame countdown
NMEX: .res 10 ;
NMEY: .res 10 ;
NMEZ: .res 10 ; 0=avail; 1=fixed; 8-15=sprite#
OTTO: .byte 0 ; speed (0-6)
OTTODY: .byte 0 ; 0:up, 1:down
OTTOJUMP: .byte 0 ; 0-1-3-7-15-31
OTTOTIMER: .byte 2 ; # of jiffym's (NTSC, PAL)
OTTOY: .byte 0 ;
SCORE: .res 3 ; hero's score in BCD
SHOOTING: .byte 0 ; hero shooting sound effect
SHOOTING2: .byte 0 ; robot shooting sound effect
VAPORIZE: .byte 0 ; hero vaporizing sound sequence
;
; other global symbols
;
PLAYER = 15 ; sprite# of player
ROBOT = 9 ; starting sprite# of robot(s)
ROBOTS = 6 ; number of robot sprites
.global CYCLOPS
.global FRAME
.global KABOOM
.global MYIRQ
.global RESTART
.global SHOOTING
.ifdef VOICES
.global INTRUDER_ALERT
.global WAH_THE_WAH
.endif
;*********************************************************************
; GAME INITIALIZATION
;
.segment "CODE"
RESTART:
LDA #$08
STA VIC+$0F ; black border / black screen
JSR SSSINIT ; initialize software sprite stack
.ifdef VOICES
JSR INTRUDER_ALERT
.endif
;
; evil otto
LDA #%01101100 ; disable an 8x8 sprite that floats X-Y
LDY #8 ; pixel height
JSR SSSCREATE ; sprite #0 (4-chars: $78-$7F)
LDX #<EVILOTTO
LDY #>EVILOTTO
JSR SSSANIM
; explosion
LDA #%00100001 ; disable an 8x16 fixed sprite
LDY #16 ; pixel height
JSR SSSCREATE ; sprite #1 (2-chars: $74-$77)
@nmeshots: ; setup robot shots
LDA #%01100100 ; disable an 8x8 sprite that floats X or Y
LDY #4 ; pixel height
JSR SSSCREATE
CPX #6 ; sprites #2-6 (10-chars: $60-$73)
BNE @nmeshots
@heroshots: ; setup hero shots
LDA #%01100100 ; disable an 8x8 sprite that floats X or Y
LDY #5 ; pixel height
JSR SSSCREATE
CPX #8 ; sprites #7-8 (4-chars: $58-$5F)
BNE @heroshots
; setup robots
@nmes: LDA #%01101101 ; disable an 8x16 sprite that roams freely
LDY #12 ; pixel height
JSR SSSCREATE
CPX #10 ; sprites #9-10 (12-chars: $40-$57)
BNE @nmes
@nmeh: LDA #%01101001 ; disable an 8x16 sprite that roams X only
LDY #12 ; pixel height
JSR SSSCREATE
CPX #12 ; sprites #11-12 (8-chars: $30-$3F)
BNE @nmeh
@nmev: LDA #%01100101 ; disable an 8x16 sprite that roams Y only
LDY #12 ; pixel height
JSR SSSCREATE
CPX #14 ; sprites #13-14 (6-chars: $24-$2F)
BNE @nmev
; our hero last
LDA #%01001101 ; disable an 8x16 sprite that floats X-Y
LDY #16 ; pixel height
JSR SSSCREATE ; sprite #15 (6-chars: $18-$23)
;*********************************************************************
; Start a new game
;
INITNEW:
LDA #-1
STA LEVEL
LDA #3
STA LIVES
LDA #0 ; reset bonus & score
STA EXTRA
STA SCORE
STA SCORE+1
STA SCORE+2
JSR NEXTLEVEL
.ifdef VOICES
JSR INTRUDER_ALERT
.endif
LDX #4 ; a seasoned player's observation
BNE MAYHEM
STARTLEVEL:
LDA JIFFYL
AND #$03
ASL
TAX
MAYHEM: LDA DOORWAY,X
STA ENTRANCE
LDA DOORWAY+1,X
STA ENTRANCE+1
JSR RNDNEXT
JMP (ENTRANCE)
DOORTOP:
AND #$07
CLC
ADC #(4*8)
TAY
LDA JIFFYL
AND #$18
CLC
ADC #88
TAX
BNE PLOTHERO
DOORBOT:
AND #$07
CLC
ADC #(18*8)
TAY
LDA JIFFYL
AND #$18
CLC
ADC #88
TAX
BNE PLOTHERO
DOORLFT:
AND #$07
CLC
ADC #(4*8)
TAX
LDA JIFFYL
AND #$1F
CLC
ADC #80
TAY
BNE PLOTHERO
DOORRHT:
AND #$07
CLC
ADC #(20*8)
TAX
LDA JIFFYL
AND #$1F
CLC
ADC #80
TAY
;
PLOTHERO:
STX SPRITEX+PLAYER
STY SPRITEY+PLAYER
LDX #PLAYER
STX sssNUM
LDA SPRITEDEF,X
ORA #$80
STA SPRITEDEF,X
LDA #$05 ; green
LDX #<HERO
LDY #>HERO
JSR SSSANIM
LDA #0 ; clear any pending shot(s) ...
STA HEROSHOT ; don't want to shoot ourselves from a
STA HEROSHOT+1 ; bullet dispensed from the last level
STA JIFFYL ; reset timer
STA JIFFYM
STA VIC+$0A ; voice #1
LDY #25
JSR SSSFLIP
;
PLOTNME:
LDA MONO
STA COLORCODE
LDA #8
JSR RND
CLC
ADC #3 ; min 3, max 10
STA NMES
;
LDA #0
LDX #10
@clr: STA NMEBITS-1,X
STA NMEWAIT-1,X
STA NMEZ-1,X
DEX
BNE @clr
;
LDX #24
@zero: STA CORNERS-1,X
DEX
BNE @zero
;
LDX #2
STX NMERELOAD ; watchdog
LDX #0
STX R0
STX DATANEXT
;
@loopx: LDY DATANEXT
LDA #21
JSR RND
CPY DATANEXT
BCC @goodx
INC NMERELOAD ; allow for robots on same X or Y axis
JMP @skip1
@goodx: STA ACOPY
TAX
INC CORNERS,X
LDA CORNERS,X
CMP NMERELOAD ; watchdog
BCS @loopx
LDA ACOPY
ASL
ASL
ASL ; x8
BNE @x
ADC #$08
@x: ADC #$10
LDX R0
STA NMEX,X
@loopy: LDY DATANEXT
LDA #21
JSR RND
CPY DATANEXT
BCC @goody
INC NMERELOAD ; allow for robots on same X or Y axis
BNE @skip1
@goody: STA ACOPY
TAX
INC CORNERS,X
LDA CORNERS,X
CMP NMERELOAD ; watchdog
BCS @loopy
LDA ACOPY
ASL
ASL
ASL ; x8
BNE @y
ADC #$08
@y: ADC #$10
LDX R0
STA NMEY,X
SEC
SBC SPRITEY+PLAYER
BCC @cc1
CMP #24
BCS @ok
BCC @ckx
@cc1: EOR #-1
CMP #24
BCS @ok
@ckx: LDA NMEX,X
SEC
SBC SPRITEX+PLAYER
BCC @cc2
CMP #16
BCS @ok
JMP @loopx
@cc2: EOR #-1
CMP #16
BCS @ok
@ng: JMP @loopx
@ok: JSR NMEFIX ; make this robot a fixture
CPX R0
BNE @ng ; oops, another robot in that spot
INC R0
;
@skip1: LDX R0
CPX NMES
BEQ @mt
JMP @loopx
@mt: CPX #10
BCS @ready
LDA #0
STA NMEX,X
STA NMEY,X
STA NMEZ,X
INX
BNE @mt
;
@ready: LDA #4
STA R0
@flash: LDA SPRITEDEF+PLAYER
EOR #$80
STA SPRITEDEF+PLAYER
LDY #25
JSR SSSFLIP
DEC R0
BNE @flash
;
LDA #12
SEC
SBC LEVEL
BCS @adv
@limit: LDA #3
@adv: CMP #3
BCC @limit
ASL
ASL
ASL ; x8
STA NMERELOAD
LDX #1 ; walking speed
LDY #3 ; shooting speed
LDA LEVEL
CMP #3
BCC @level0
LDA #3
INY
@level0:
STA NMESHOTS
BEQ @level
INX ; walking speed
LDA LEVEL
@level1:
CMP #7 ; 1st white level
BCC @level
INY ; shooting speed
@level2:
CMP #15 ; 2nd white level
BCC @level
INC NMESHOTS
INX ; walking speed
INY ; shooting speed
@level3:
LDA EXTRA
BEQ @level
INC NMESHOTS ; extra bullet
INY ; shooting speed
@level:
STX NMESPEED ; walking speed
STY NMESSPEED ; shooting speed
TXA
ASL
ASL
ASL
STA NMEPAUSE ; hero's head start
;
LDX #0 ; speed
STX JIFFYM ; timer
STX OTTO
STX OTTODY ; up
LDY #15
STY OTTOJUMP
LDA SPRITEX+PLAYER
SEC
SBC #$08
CMP #$80
BCC @ottox
CLC
ADC #$10
@ottox: STA SPRITEX
LDA SPRITEY+PLAYER
SEC
SBC #$10
CMP #$80
BCC @ottoy
CLC
ADC #$20
@ottoy: STA OTTOY
;
LDA #64 ; NTSC=-1.0
LDX MACHINE
CPX #$05
BEQ @ntsc
ASL ; PAL=-2.75
@ntsc: STA ACOPY
LDA LEVEL
LSR
ADC ACOPY
STA JIFFYL ; timer
LDA #2 ; add seconds: NTSC=+8.5, PAL=+10.25
STA OTTOTIMER
LDA NMES
CMP #7
BCC GAMELOOP
INC OTTOTIMER ; cut the player some slack
;*********************************************************************
; Main game playing loop
;
GAMELOOP:
; determine player, enemy, objects actions ...
JSR HEROMOVE
JSR NMEMOVE
JSR OTTOMOVE
JSR OLDHEROSHOT
JSR OLDNMESHOT
;
; update the action ...
LDY #1 ; keep pace in sync, if ...
LDA NMEPAUSE
BNE @flip ; robots are not sprites yet?
LDA NMES
BEQ @flip ; no more robots on this level?
LDY #0
@flip: JSR SSSFFLIP
INC FRAME
;
; determine results ...
JSR OTTOHIT
JSR HEROHIT
JSR NMEHIT
JSR NMEDYING
;
; last, check if our hero left the room ...
LDA SPRITEX+PLAYER
CMP #$11
BCC @esclft
CMP #$B8
BCS @escrht
LDA SPRITEY+PLAYER
CMP #$11
BCC @esctop
CMP #$B0
BCS @escbot
JMP GAMELOOP
@esclft:
JMP ESCLFT
@escrht:
JMP ESCRHT
@esctop:
JMP ESCTOP
@escbot:
JMP ESCBOT
;*********************************************************************
; Hero death sequence
;
DIES:
LDX #$10
STX VAPORIZE
LDX #$04
STX DEATH
@die: LDX #$00
STX R4
@sic: LDX #PLAYER ; hero sprite#
STX sssNUM
LDX R4
LDA CYCLE,X
STA COLORCODE
LDY #>DYING
TXA
AND #$03
ASL
ASL
ASL
ASL ; x16
CLC
ADC #<DYING
BCC @cc
INY
@cc: TAX
LDA COLORCODE
JSR SSSANIM
; keep other events alive
JSR OTTOMOVE
JSR OLDHEROSHOT
JSR OLDNMESHOT
LDY #2 ; burn some phosphor into the player's brain
JSR SSSFLIP
INC FRAME
; keep post events alive
JSR NMEHIT
INC R4
LDA R4
CMP #$08
BNE @sic
DEC DEATH
BNE @die
;
ASL SPRITEDEF+PLAYER
LSR SPRITEDEF+PLAYER
JSR SSSREFRESH
LDY #1 ; ashes-to-ashes
JSR SSSFLIP
LDY #10 ; dust-to-dust
JSR SSSFLIP
@wait: LDX VAPORIZE
BNE @wait ; sound effect complete?
RTS
;*********************************************************************
; level end sequences: left, right, top, and bottom doorways
;
ESCAPE:
STX ENTRANCE
STY ENTRANCE+1
JSR NEXTLEVEL
JMP (ENTRANCE)
ESCLFT:
JSR MAKEBLUE
LDX #$00
LDY SCRNLINE+1
STX VECTORBG ; rows 0-10
STY VECTORBG+1
LDX #(11*22)
STX VECTORFG ; rows 11-21
STY VECTORFG+1
LDA #22 ; shift 22x
STA R0
@bycol: LDX #11 ; 11-rows per half to scroll
LDY #0
STY R1
LDY #20
@shift: LDA (VECTORBG),Y
INY ; shift right
STA (VECTORBG),Y
DEY
LDA (VECTORFG),Y
INY ; shift right
STA (VECTORFG),Y
DEY
DEY
CPY R1
BPL @shift
INY
LDA #SSSNULL
STA (VECTORBG),Y
STA (VECTORFG),Y
LDA R1
CLC
ADC #22
STA R1
CLC
ADC #20
TAY
DEX
BNE @shift
LDA #4 ; load # of vsyncs
STA VSYNC
@vsync: LDA VSYNC
BNE @vsync ; and wait for it to occur
DEC R0
BNE @bycol
LDA #%00000001 ; close right exit
LDX #<DOORRHT
LDY #>DOORRHT
JMP ESCAPE
ESCRHT:
JSR MAKEBLUE
LDX #$00
LDY SCRNLINE+1
STX VECTORBG ; rows 0-10
STY VECTORBG+1
LDX #(11*22)
STX VECTORFG ; rows 11-21
STY VECTORFG+1
LDA #22 ; shift 22x
STA R0
@bycol: LDX #11 ; 11-rows per half to scroll
LDY #22
STY R1
LDY #1
@shift: LDA (VECTORBG),Y
DEY ; shift left
STA (VECTORBG),Y
INY
LDA (VECTORFG),Y
DEY ; shift left
STA (VECTORFG),Y
INY
INY
CPY R1
BCC @shift
DEY
LDA #SSSNULL
STA (VECTORBG),Y
STA (VECTORFG),Y
LDA R1
CLC
ADC #22
STA R1
SEC
SBC #21
TAY
DEX
BNE @shift
LDA #4 ; load # of vsyncs
STA VSYNC
@vsync: LDA VSYNC
BNE @vsync ; and wait for it to occur
DEC R0
BNE @bycol
LDA #%00000100 ; close left exit
LDX #<DOORLFT
LDY #>DOORLFT
JMP ESCAPE
ESCTOP:
JSR MAKEBLUE
LDA #22
STA R0 ; 22x
@loop: LDX #<(20*22)
LDY SCRNLINE+1
INY
STX VECTORBG
STY VECTORBG+1
LDX #<(21*22)
STX VECTORFG
STY VECTORFG+1
LDX #21 ; 21x
@byrow: LDY #21 ; 22-cols
@shift: LDA (VECTORBG),Y
STA (VECTORFG),Y
DEY
BPL @shift
LDA VECTORBG+1
STA VECTORFG+1
LDA VECTORBG
STA VECTORFG
SEC
SBC #22
BCS @nocc
DEC VECTORBG+1
@nocc: STA VECTORBG
DEX
BNE @byrow
LDY #21
LDA #SSSNULL
@clear: STA (VECTORFG),Y
DEY
BPL @clear
LDA #4 ; load # of vsyncs
STA VSYNC
@vsync: LDA VSYNC
BNE @vsync ; and wait for it to occur
DEC R0
BNE @loop
LDA #%00000010 ; close bottom exit
LDX #<DOORBOT
LDY #>DOORBOT
JMP ESCAPE
ESCBOT:
JSR MAKEBLUE
LDA #22
STA R0 ; 22x
@loop: LDX #22
LDY SCRNLINE+1
STX VECTORBG
STY VECTORBG+1
LDX #0
STX VECTORFG
STY VECTORFG+1
LDX #21 ; 21x
@byrow: LDY #21 ; 22-cols
@shift: LDA (VECTORBG),Y
STA (VECTORFG),Y
DEY
BPL @shift
LDA VECTORBG+1
STA VECTORFG+1
LDA VECTORBG
STA VECTORFG
CLC
ADC #22
BCC @cc
INC VECTORBG+1
@cc: STA VECTORBG
DEX
BNE @byrow
LDY #21
LDA #SSSNULL
@clear: STA (VECTORFG),Y
DEY
BPL @clear
LDA #4 ; load # of vsyncs
STA VSYNC
@vsync: LDA VSYNC
BNE @vsync ; and wait for it to occur
DEC R0
BNE @loop
LDA #%00001000 ; close top exit
LDX #<DOORTOP
LDY #>DOORTOP
JMP ESCAPE
MAKEBLUE:
LDA BONUS
CMP NMES
BNE @nobonus
@loop: LDA #$F8
STA VIC+$0C ; voice #3
LDX #2
LDA #$10
JSR SCOREUPDATE
LDY #3
JSR SSSFLIP
LDA #$00
STA VIC+$0C ; voice #3
LDY #2
JSR SSSFLIP
DEC BONUS
BNE @loop
@nobonus:
LDX #$00
LDY #$00
JSR SSSPLOTS
LDA SCRNLINE+1
PHA ;++
LDA COLORLINE+1
PHA ;++
LDY #10 ; gratuitous
JSR SSSFLIP
;
LDY #$00
STY COLORLINE
STY SCRNLINE
PLA ;--
STA COLORLINE+1
PLA ;--
STA SCRNLINE+1
LDA #$06 ; paint blue
@loop1: STA (COLORLINE),Y
INY
BNE @loop1
INC COLORLINE+1
@loop2: STA (COLORLINE),Y
INY
CPY #$E2
BNE @loop2
LDA #20 ; load # of vsyncs
STA VSYNC
@vsync: LDA VSYNC
BNE @vsync ; and wait for it to occur
;
ASL SPRITEDEF+PLAYER
LSR SPRITEDEF+PLAYER
LDA #0
STA JIFFYL ; reset timer
STA JIFFYM
STA VIC+$0A ; voice #1
.ifdef VOICES
JSR WAH_THE_WAH
.endif
RTS
;*********************************************************************
; process hero action(s)
;
HEROMOVE:
LDX #PLAYER ; setup our hero
STX sssNUM
LDY #$00
STY ACTION
STY $9113
LDA #$7F
STA $9122
;
LDA $9120
AND #$80
BNE @joy0
LDA #$01 ; RIGHT
STA ACTION
@joy0: LDA #$FF
STA $9122
LDY $9111
;
TYA
AND #$20 ; FIRE
BNE @xfire
LDA #$10
ORA ACTION
STA ACTION
;
@xfire: TYA
AND #$08
BNE @joy1
LDA #$02 ; DOWN
ORA ACTION
STA ACTION
;
@joy1: TYA
AND #$10
BNE @joy2
LDA #$04 ; LEFT
ORA ACTION
STA ACTION
;
@joy2: TYA
AND #$04
BNE @joy3
LDA #$08 ; UP
ORA ACTION
STA ACTION
@joy3:
LDA ACTION
CMP ACTION2
BEQ @oldact ; same as last poll
STA ACTION2
LDA #00 ; reset poll on new action request
STA ACTIONS
@oldact:
INC ACTIONS
LDA ACTIONS
AND #$01 ; repeat same action every other poll
BNE @do
@xhero: RTS
@do:
LDX FIRE
BEQ @do2
DEC FIRE
@do2: LDA ACTION
AND #%00010000
BEQ @moving
LDA ACTION
AND #%00001111 ; which direction?
BNE @firing
JMP @move ; just aiming (or posing)
@firing:
LDX FIRE
BNE @fired
LDX #11 ; timer event
STX FIRE
ASL
TAY
LDA FIREAT,Y
TAX
LDA FIREAT+1,Y
TAY
STX SPRITEIMGL+PLAYER
STY SPRITEIMGH+PLAYER
JSR NEWHEROSHOT
@fired: JMP @move
@moving:
LDX #<HERO
LDY #>HERO
STX SPRITEIMGL+PLAYER
STY SPRITEIMGH+PLAYER
LDA ACTION
AND #%00001111
BNE @doing
JMP @move
@doing: LDA ACTIONS
LSR
AND #$03
CMP #$03
BEQ @ck0
CMP #$02
BEQ @r2
@r1:
LDX #<(HERO+16)
LDY #>(HERO+16)
STX SPRITEIMGL+PLAYER
STY SPRITEIMGH+PLAYER
BNE @ck0
@r2:
LDX #<(HERO+32)
LDY #>(HERO+32)
STX SPRITEIMGL+PLAYER
STY SPRITEIMGH+PLAYER
@ck0: ; process RIGHT
LDA ACTION
AND #%00000001
BEQ @ck1
LDA SPRITEX+PLAYER
CLC
ADC #$08
CMP SSSCLIPX
BEQ @ck1
INC SPRITEX+PLAYER
@ck1: ; process DOWN
LDA ACTION
AND #%00000010
BEQ @ck2
LDA SPRITEY+PLAYER
CLC
ADC #$18
CMP SSSCLIPY
BEQ @ck2
INC SPRITEY+PLAYER
@ck2: ; process LEFT
LDA ACTION
AND #%00000100
BEQ @ck3
LDA SPRITEIMGL+PLAYER
CLC
ADC #$30
BCC @lcc
INC SPRITEIMGH+PLAYER
@lcc: STA SPRITEIMGL+PLAYER
LDA SPRITEX+PLAYER
CMP #$10
BEQ @ck3
DEC SPRITEX+PLAYER
@ck3: ; process UP
LDA ACTION
AND #%00001000
BEQ @move
LDA SPRITEY+PLAYER
CMP #$10
BEQ @move
DEC SPRITEY+PLAYER
@move:
LDX SPRITEX+PLAYER
LDY SPRITEY+PLAYER
JSR SSSMOVEXY
RTS
;*********************************************************************
; process a new Hero shot request, if possible
;
NEWHEROSHOT:
LDX #$01
@mt: LDA HEROSHOT,X
BEQ @okbyme
DEX
BEQ @mt
RTS
@okbyme:
LDA ACTION
AND #%00001111 ; bit# 3=up, 2=left, 1=down, 0=right
STA HEROSHOT,X ; save direction (1,2,3,4,6,8,9,12)
TAY
TXA
CLC
ADC #7 ; sprite# offset
TAX
LDA MISSILE,Y ; enable display & collision w/ direction
STA SPRITEDEF,X
JSR SSSTOUCH
TYA
ASL ; compute shot image & origin
TAY
LDA SHOTAT,Y
STA SPRITEIMGL,X
LDA SHOTAT+1,Y
STA SPRITEIMGH,X
LDA SPRITEX+PLAYER
CLC
ADC ORIGIN,Y
STA SPRITEX,X
LDA SPRITEY+PLAYER
CLC
ADC ORIGIN+1,Y
STA SPRITEY,X
LDA #$F0
STA SHOOTING
RTS
;*********************************************************************
; process Hero shot(s), if any
;
OLDHEROSHOT:
LDY #6 ; fixed bullet speed
LDA FRAME
AND #$07