-
Notifications
You must be signed in to change notification settings - Fork 10
/
choplifter.s
11703 lines (10039 loc) · 352 KB
/
choplifter.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
.include "zeropage.s"
.macro UNUSED byteCount
.repeat byteCount
.byte $00
.endrepeat
.endmacro
.segment "STARTUP"
.segment "LOCODE"
.org $0800
; The sector 0 loader on the floppy jumps to here, but it has not been disassembled for this reverse engineer.
; We will replace it with our own ProDOS-based loader. Since this is a single-load game, we don't need to
; write a full RWTS nor replace any such code in the game.
loaderEntry: ; $0800
cld
sei
sei
sta ZP_RND ; Seeds random with whatever is in the accumulator after loader is done. Probably not very random.
jsr checkButtonInput
jsr jumpInitRendering
;;;;;;;;;;;;;;;;;;;;;;;;;;;
; This appears to be leftover testing code that Dan was playing with. The game
; appears to have supported vertical scrolling at one point, but it either didn't work well
; for gameplay or he never got it working, so it has been removed. All the vertical scrolling
; parameters are hardcoded later on and never changed, but here in the loader we find these
; two little test lines that shipped.
jsr jumpSetScrollBottom
.byte $18,$70
jsr jumpSetScrollTop
.byte $1e,$70
;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Resume normal initialization
jsr jumpInitHelicopter
lda #$00
sta ZP_GAMEACTIVE
jmp (ZP_LOADERVECTOR_L) ; Points to $09c7 (startDemoMode)
; Begins the animated title sequence, starting with the animated Choplifter logo
startTitleSequence: ; $081f
jsr renderStartingGameStateForLoss ; End previous demo sequence
jsr jumpInitHelicopter
lda #$00
sta ZP_FRAME_COUNT
jsr jumpSetSpriteAnimPtr
.word $a0f2 ; Set animation pointer to Broderbund Presents
jsr jumpSetAnimLoc ; Set animation screen position ; $082e
.byte $1f ; X pos (low byte)
.byte $00 ; X pos (high byte)
.byte $8C ; Y pos, bottom-relative
lda #$ff ; Set high palette bit for this animation
jsr jumpSetPalette
lda #$0A ; Broderbund Presents animation is 10 frames long
sta animCounterBrod
animLoopBrod:
jsr jumpUpdateSlideAnim ; Render next frame of Broderbund Presents animation
.byte $00 ; Left clip
.byte $00 ; Right clip
animCounterBrod: .byte $ff ; Amount of image height to render
.byte $00 ; Bottom clip amount
jsr jumpBlitImage ; $0845
jsr jumpFlipPageMask
jsr jumpBlitImage
jsr jumpFlipPageMask
dec animCounterBrod
bmi animBeginChoplifter ; Wait for Broderbund Presents to finish
jsr checkButtonInput ; Check for button during demo to start game
bcc animLoopBrod
jmp (ZP_GAMESTART_JMP_L) ; Points to $b5f, to start game
animBeginChoplifter: ; Starts the layered Choplifter logo animation
clc
lda ZP_SCROLLPOS_L
adc #$1F
sta choplifterLogoState
lda ZP_SCROLLPOS_H
adc #$00
sta choplifterLogoState+1
lda choplifterLogoState ; X position for crossed logos
sta ZP_RENDERPOS_XL
lda choplifterLogoState+1
sta ZP_RENDERPOS_XH
lda #$69 ; Height at which to place crossed logos
sta ZP_RENDERPOS_Y
jsr jumpSetWorldspace
.word $001C ; Pointer to animation data for crossed Choplifter logos (not a real animation, just one frame)
jsr jumpSetSpriteAnimPtr ; $880
.word $a0f0 ; Set animation graphic pointer to Choplifter logo
jsr jumpClipToScroll
lda #$02
jsr jumpSetSpriteTilt
jsr jumpFlipPageMask
jsr jumpRenderTiltedSpriteLeft ; Render first logo, tilted left (buffer 0)
jsr jumpFlipPageMask
jsr jumpRenderTiltedSpriteLeft ; Render first logo, tilted left (buffer 1)
jsr checkButtonInput
bcc animChopNoInput0
jmp (ZP_GAMESTART_JMP_L) ; Points to $b5f, to start game
animChopNoInput0:
lda #$FE
jsr jumpSetSpriteTilt
jsr jumpFlipPageMask
jsr jumpRenderTiltedSpriteLeft ; Render second logo, tilted left (buffer 0)
jsr jumpFlipPageMask
jsr jumpRenderTiltedSpriteLeft ; Render second logo, tilted left (buffer 1)
jsr checkButtonInput
bcc animChopNoInput1
jmp (ZP_GAMESTART_JMP_L) ; Points to $b5f, to start game
animChopNoInput1:
lda #$02
jsr jumpSetSpriteTilt
jsr jumpFlipPageMask
jsr jumpRenderTiltedSpriteRight ; Render third logo, tilted right (buffer 0)
jsr jumpFlipPageMask
jsr jumpRenderTiltedSpriteRight ; Render third logo, tilted right (buffer 1)
jsr checkButtonInput
bcc animChopNoInput2
jmp startNewGame ; Start the game when button pushed. Why is this direct, when the other two jumps above are indirect? No idea.
animChopNoInput2:
lda #$FE
jsr jumpSetSpriteTilt
jsr jumpFlipPageMask
jsr jumpRenderTiltedSpriteRight ; Render fourth logo, tilted right (buffer 0)
jsr jumpFlipPageMask
jsr jumpRenderTiltedSpriteRight ; Render fourth logo, tilted right (buffer 1)
jsr jumpInitEntityTable
slidingChoplifterLoop: ; $08e7
inc ZP_FRAME_COUNT
lda ZP_FRAME_COUNT
cmp #$38
bcc animChopStartGame
jmp startDemoMode ; After $38 frames, escape title animation and start the demo
animChopStartGame:
lda ZP_FRAME_COUNT
cmp #$02
bcc animChopNoInput3 ; Not allowed to start game during first two frames of sliding animation. This feels like a hacky bug fix for something. :D
jsr checkButtonInput
bcc animChopNoInput3
jmp startNewGame ; Start the game when button pushed. Why is this direct, when the other two jumps above are indirect? No idea.
animChopNoInput3:
lda ZP_FRAME_COUNT
cmp #$22
bcs animChopDemoNextBuffer
cmp #$14
bcc animChopDemoNextBuffer
ldx #$5D ; Erase all the titles to start demo
ldy #$69
lda #$80
jsr jumpScreenFill
animChopDemoNextBuffer:
jsr jumpEraseAllSprites
jsr jumpRenderMoonChunk ; Replace the piece of moon we erased above
lda ZP_FRAME_COUNT ; Calculate X position of lefthand Choplifter logo based on frame counter
cmp #$20
bcc animChopLowFrameCount
lda #$00
jmp animChopRenderSlideLogos
animChopLowFrameCount:
lda ZP_FRAME_COUNT
eor #$1F
asl
asl
asl
animChopRenderSlideLogos:
sta ZP_SCRATCH56
sec
lda choplifterLogoState
sbc ZP_SCRATCH56
sta ZP_RENDERPOS_XL
lda choplifterLogoState+1
sbc #$00
sta ZP_RENDERPOS_XH
lda #$69 ; Y position of left-hand sliding choplifter logo
sta ZP_RENDERPOS_Y
jsr jumpSetWorldspace
.word $001C ; Pointer to animation data for left-hand sliding Choplifter logo
jsr jumpSetSpriteAnimPtr ; $0945
.word $a0f0 ; Set animation graphic pointer to Choplifter logo
jsr jumpClipToScroll
bcs animChopRenderSlideAnimDone
lda #$FF ; Set high palette bit for this animation
jsr jumpSetPalette
jsr jumpBlitImage
animChopRenderSlideAnimDone:
inc ZP_SCRATCH56 ; Advance X position
clc
lda choplifterLogoState
adc ZP_SCRATCH56
sta ZP_RENDERPOS_XL
lda choplifterLogoState+1
adc #$00
sta ZP_RENDERPOS_XH
lda #$69 ; Y position of right-hand sliding choplifter logo
sta ZP_RENDERPOS_Y
jsr jumpSetWorldspace
.word $001C ; Pointer to animation data for right-hand sliding Choplifter logo
jsr jumpClipToScroll ; $0971
bcs chopSlideFinished
lda ZP_FRAME_COUNT
cmp #$14
bcs animChopRenderHighFrames
jsr jumpBlitImage
jmp chopSlideFinished
animChopRenderHighFrames:
jsr jumpRenderSpriteRight
chopSlideFinished:
lda ZP_FRAME_COUNT ; Wait $20 frames before next animation
cmp #$20
bne slidingChoplifterContinue
jsr jumpSetSpriteAnimPtr ; Animate the copyright message
.word $a0f4 ; Set animation pointer to Dan Gorlin copyright
jsr jumpSetAnimLoc ; Set animation parameters
.byte $30 ; X pos (low byte)
.byte $00 ; X pos (high byte)
.byte $44 ; Y pos, bottom-relative
lda #$FF ; $0996
jsr jumpSetPalette ; Set high palette bit for this animation
ldx #$10
chopSlideLoop:
stx animCounterChop
jsr jumpUpdateSlideAnim
.byte $00 ; Left clip
.byte $00 ; Right clip
animCounterChop: .byte $00 ; Amount of image height to render $09a5
.byte $00 ; Bottom clip amount
jsr jumpBlitImage
jsr jumpFlipPageMask
jsr jumpBlitImage
jsr jumpFlipPageMask
dex
bpl chopSlideLoop
slidingChoplifterContinue:
jsr jumpPageFlip
jsr jumpFlipPageMask
lda ZP_BUFFER ; Swap double buffer
eor #$FF
sta ZP_BUFFER
jmp slidingChoplifterLoop
choplifterLogoState: ; $09c5
.byte $00,$00
; Start the self playing demo. This is basically a copy of the main game loop
; with the addition of a big controls table to simulate flying the helicopter
startDemoMode: ; $09c7
jsr renderStartingGameStateForLoss ; Reset game state to a good place
jsr jumpInitGameState
jsr jumpInitHelicopter
lda #$00 ; Initialize some state
sta ZP_FRAME_COUNT
sta mainLoopDemoAction ; Start with "positive" actions which send us out to hostages
jsr jumpSpawnInitialHostages
lda #$00
sta CURR_LEVEL
jsr jumpInitSlideAnim ; Show Your Mission: Rescue Hostages
jsr jumpSetSpriteAnimPtr
.word $a0ee ; Pointer to Rescue Hostages graphic
jsr jumpSetAnimLoc
.byte $52 ; X pos (low byte)
.byte $00 ; X pos (high byte)
.byte $6e ; Y pos, bottom-relative
lda #$ff
jsr jumpSetPalette ; Set palette for this animation
jsr jumpBlitImage ; Show the Rescue Hostages graphic (as a one frame "animation")
jsr jumpPageFlip
jsr jumpFlipPageMask
jsr jumpBlitImage
jsr jumpPageFlip
jsr jumpFlipPageMask
; Main demo loop- this is duplicate of the main game loop, slightly stripped down for just what the self-playing demo needs
mainLoopDemo: ; $0a04
inc ZP_FRAME_COUNT ; Check if self-play is done
lda ZP_FRAME_COUNT
cmp #$E0 ; Demo is 224 frames out, then 224 frames back. Same flight control table is used both ways. Neat!
bne mainLoopDemoDeathCheck
bit mainLoopDemoAction
bpl mainLoopDemoHeadHome
jmp (ZP_STARTTITLE_JMP_L) ; Points to startTitleSequence ($081f)
mainLoopDemoHeadHome: ; After first 224 frames, we turn around and head home
lda #$FF
sta mainLoopDemoAction ; Switch to "negative" actions
lda #$00 ; Reinitialize various things to return home
sta ZP_VELX_16_L
sta ZP_VELX_16_H
sta ZP_VELY_16_L
lda #$FE
sta ZP_VELY_16_H
mainLoopDemoDeathCheck:
lda ZP_DYING
beq mainLoopDemoFetchControls
lda #$02 ; During death, kill all control inputs
sta ZP_ACCELY ; I think this is insurance because it shouldn't be possible to die in the demo, but maybe the tanks get lucky sometimes
lda #$00
sta ZP_STICKX
jsr processChopTurn
jmp mainLoopDemoDeathCheck2
mainLoopDemoFetchControls: ; 0a37
lda ZP_FRAME_COUNT ; Fetch next demo control actions based on time
and #$F8 ; Calculate row in flight control table
lsr
tax
lda mainLoopDemoTable,x ; Y acceleration taken directly from table
sta ZP_ACCELY
lda mainLoopDemoTable+1,x ; X acceleration is magnitude only in the table
bit mainLoopDemoAction ; Take sign from current action
bpl mainLoopDemoPosX ; Positive X acceleration
eor #$FF ; Otherwise negate acceleration to match action
clc
adc #$01
mainLoopDemoPosX:
sta ZP_STICKX
lda mainLoopDemoTable+2,x ; Facing is taken from the table, but also modified
bit mainLoopDemoAction
bpl mainLoopDemoPosFace ; Negate facing if action is negative
eor #$FF
clc
adc #$01
mainLoopDemoPosFace:
sta CHOP_FACE
lda mainLoopDemoTable+3,x ; Decide when to shoot
beq mainLoopDemoNoShoot
eor mainLoopDemoAction ; We shoot at different times going out or back, but using same control table
bmi mainLoopDemoNoShoot
jsr joystick0Push ; Fake joystick buttons to shoot. A wee-bit hacky, but I guess it was easiest :)
jsr clearButton0
mainLoopDemoNoShoot: ; $0a71
lda ZP_AIRBORNE ; If we're on the ground, sit and wait for hostages to load or unload
beq mainLoopDemoDeathCheck2
jsr processChopTurn
mainLoopDemoDeathCheck2:
lda ZP_DEATHTIMER
beq mainLoopDemoStillAlive
clc ; Process death animation during demo, just in case we did die somehow
lda ZP_DEATHTIMER
adc #$05
sta ZP_DEATHTIMER
bpl mainLoopDemoStillAlive
jmp startTitleSequence ; Go back to titles when we finish dying
mainLoopDemoStillAlive:
jsr checkButtonInput ; Watch for player starting game
bcc mainLoopDemoNoInput
jmp (ZP_GAMESTART_JMP_L)
mainLoopDemoNoInput:
jsr jumpEraseAllSprites ; Erase everything so we can render again
jsr jumpRenderStars ; Render starfield
jsr jumpRenderMoon ; Render the moon
jsr jumpTableScroll ; Handle terrain scrolling
jsr jumpRenderMountains ; Render the mountains
jsr jumpRenderBase ; Render the home base
jsr jumpRenderFence ; Render the security fence
jsr jumpRenderHouses ; Render the hostage houses
jsr jumpUpdateHostages ; Renders the little dudes
jsr jumpSpawnEnemies ; Spawns enemies, as needed
jsr jumpUpdateEntities ; Updates all game objects
jsr jumpDefragmentEntityList
jsr jumpPageFlip ; Swap render buffers
jsr jumpFlipPageMask
lda #$FF
eor ZP_BUFFER
sta ZP_BUFFER
bit mainLoopDemoAction
bmi mainLoopDemoContinue
lda ZP_FRAME_COUNT ; After $30 frames, erase the Rescue Hostages banner shown while demo runs
cmp #$30
beq mainLoopDemoEraseBanner
cmp #$31 ; Kind of a hack to make sure both buffers get erased :)
beq mainLoopDemoEraseBanner ; $0acd
mainLoopDemoContinue:
jmp mainLoopDemo
mainLoopDemoEraseBanner:
ldx #$50 ; Erases "Rescue Hostages" banner once demo starts self-playing
ldy #$70
lda #$80
jsr jumpScreenFill
jmp mainLoopDemo
mainLoopDemoAction: ; $0ade
.byte $ff ; $00 = On our way out to get hostages, or $ff = On our way home. The same control table does both!
; A table of flight control actions for running the demo. Current action is "going out" or "heading home"
; Each frame, a struct of four bytes is used:
; 0: Y Velocity
; 1: X Acceleration, with sign taken from high bit of current action
; 2: Facing, with sign taken from high bit of current action
; 3: Shooting, modified with current action
mainLoopDemoTable: ; $0adf
.byte $0D,$05,$00,$FF
.byte $0B,$05,$FF,$00
.byte $0A,$05,$FF,$00
.byte $0B,$05,$FF,$FF
.byte $0A,$05,$FF,$00
.byte $08,$05,$FF,$00
.byte $0B,$05,$FF,$00
.byte $0A,$05,$FF,$00
.byte $0A,$05,$FF,$00
.byte $0B,$05,$FF,$00
.byte $0B,$05,$FF,$00
.byte $0B,$05,$FF,$00
.byte $09,$03,$FF,$00
.byte $0A,$FE,$FF,$44
.byte $0B,$05,$FF,$00
.byte $0B,$05,$FF,$00
.byte $09,$00,$FF,$00
.byte $0A,$FB,$01,$44
.byte $09,$FB,$01,$00
.byte $09,$05,$00,$00
.byte $06,$00,$00,$00
.byte $06,$00,$00,$00
.byte $06,$00,$00,$00
.byte $06,$00,$00,$00
.byte $06,$00,$00,$00
.byte $06,$00,$00,$00
.byte $06,$00,$00,$00
.byte $06,$00,$00,$00
.byte $06,$00,$00,$00
.byte $06,$00,$00,$00
.byte $06,$00,$00,$00
.byte $06,$00,$00,$00
startNewGame: ; $0b5f
jsr renderStartingGameState ; Initialize game state
lda #$FF
sta ZP_GAMEACTIVE
jsr jumpInitGameState
lda #$03 ; Play a little game start medley
sta ZP_SCRATCH56
startNewGameSoundLoop:
lda ZP_SCRATCH56
asl
asl
asl
asl
asl
clc
adc #$30
tax ; Frequency
ldy #$30 ; Duration
lda #$00 ; Decay
jsr jumpPlaySound
ldx #$43 ; Frequency
ldy #$30 ; Duration
lda #$00 ; Decay
jsr jumpPlaySound
ldx #$61 ; Frequency
ldy #$30 ; Duration
lda #$00 ; Decay
jsr jumpPlaySound
dec ZP_SCRATCH56
bne startNewGameSoundLoop
jsr jumpSpawnInitialHostages
jmp (ZP_GAMEINIT_L) ; Holds $0b9b. Seems unnecessary, but maybe was a debugging tool
beginSortie:
lda SORTIE ; $0b9b
cmp #$03 ; Three lives for you
bne sortiesAvailable
jmp gameOverLoss ; Game over man, game over!
sortiesAvailable:
jsr renderStartingGameState
jsr jumpInitHelicopter
lda #$00 ; Reset frame time for the new sortie
sta ZP_FRAME_COUNT
sortieBannerLoop:
inc ZP_FRAME_COUNT
lda ZP_FRAME_COUNT
cmp #$18
bcc beginSortieWait ; Pause for $18 frames before next sortie really starts
inc SORTIE ; Increment sortie and let's go!
jmp (ZP_NEWSORTIE_JMP_L) ; Holds $0c13
beginSortieWait:
jsr checkButtonInput
jsr jumpEraseAllSprites
jsr jumpRenderStars
jsr jumpRenderMoon
jsr jumpRenderMountains
jsr jumpRenderBase
jsr jumpInitSlideAnim ; Render "X Sortie" banner
lda #$FF
jsr jumpSetPalette
lda SORTIE
cmp #$01
beq renderSortieTwo
jsr jumpSetAnimLoc
.byte $5f ; X pos (low byte)
.byte $00 ; X pos (high byte)
.byte $6B ; Y pos, bottom-relative
jmp renderSortieBanner
renderSortieTwo: ; Second sortie renders shifted so we get a different palette
jsr jumpSetAnimLoc
.byte $59 ; X pos (low byte)
.byte $00 ; X pos (high byte)
.byte $6B ; Y pos, bottom-relative
renderSortieBanner:
lda SORTIE ; Find correct sortie banner art
asl
tax
lda sortieGraphicsTable,x
sta ZP_SPRITE_PTR_L
lda sortieGraphicsTable+1,x
sta ZP_SPRITE_PTR_H
jsr jumpSetSpriteAnimPtr ; Set title art pointer to what we just found
.word $001a
jsr jumpBlitImage ; Render the banner (as a single frame "animation")
jsr jumpPageFlip
jsr jumpFlipPageMask
lda #$FF
eor ZP_BUFFER
sta ZP_BUFFER
jmp sortieBannerLoop
; When sortie banner is done, we jump indirectly to here and fall through to main game loop
jsr renderStartingGameState ; $0c13
lda #$00
sta ZP_FRAME_COUNT
;
; MAIN GAME LOOP
;
mainLoop: ; $0c1a
inc ZP_FRAME_COUNT
lda #$00
sta HOSTAGE_FIRSTLOAD
sta HOSTAGE_FIRSTDEATH
sta ALIEN_ODDFRAME
lda TOTAL_RESCUES ; Check for victory condition
cmp #$40
bne mainLoopNormal
jmp mainLoopEndGame
mainLoopNormal:
clc
adc HOSTAGES_KILLED ; Check for game failure on hostage deaths
cmp #$40
bne mainLoopNoLossYet
jmp (ZP_INDIRECT_JMP_L) ; Goes to 0c92 (gameOverLoss) in normal gameplay
mainLoopNoLossYet:
lda ZP_DEATHTIMER ; Track death animation
beq mainLoopRoutines
clc
adc #$06
sta ZP_DEATHTIMER
bpl mainLoopRoutines
jmp beginSortie
mainLoopRoutines:
jsr checkButtonInput ; Check keyboard (and kinda joystick buttons)
jsr jumpTableJoystickY ; Check current joystick Y axis
jsr checkJoystick1 ; Handle joystick button 1
jsr checkJoystick0 ; Handle joystick button 0
jsr jumpEraseAllSprites ; Erase everything so we can draw again
jsr jumpRenderStars ; Renders background starfield
jsr jumpRenderMoon ; That's no... nevermind
jsr jumpTableScroll ; Appears to handle map scrolling?
jsr jumpRenderMountains ; Renders the mountain ranges
jsr checkJoystick0 ; Handle joystick button 0 again
jsr jumpRenderBase ; Renders the base building and landing pad
jsr jumpRenderFence ; Renders the fence line left of the base
jsr jumpRenderHouses ; Renders the houses holding the hostages
jsr jumpUpdateHostages ; Renders the little dudes
jsr checkJoystick0 ; Handle joystick button 0 yet again
jsr jumpTableJoystickX ; Check current joystick X axis
jsr jumpSpawnEnemies ; Spawns enemies, as needed
jsr jumpUpdateEntities ; Update all game objects
jsr jumpDefragmentEntityList ; Maintains a master entity ID array
jsr jumpPageFlip ; Flip graphics buffers in hardware
jsr jumpFlipPageMask ; Flip page mask
lda ZP_BUFFER ; Swap render buffers in game state
eor #$FF
sta ZP_BUFFER
jmp mainLoop ; Shazam, it's a game
gameOverLoss: ; $0c92 Victory condition indirect jump arrives here
lda #$00
sta ZP_FRAME_COUNT
lda #$00 ; Player has lost due to hostages
sta mainLoopEndGameWon
lda #$00
sta ZP_GAMEACTIVE
jmp mainLoopEndGameLoop
mainLoopEndGame: ; $0ca2 Called when 64th hostage is rescued
lda #$00
sta ZP_FRAME_COUNT
lda #$FF ; Player has won!
sta mainLoopEndGameWon
lda #$00
sta ZP_GAMEACTIVE
mainLoopEndGameLoop:
inc ZP_FRAME_COUNT
lda ZP_FRAME_COUNT
cmp #$20
bcc mainLoopEndGameRoutines
jmp startTitleSequence ; Go back to title animations
mainLoopEndGameRoutines:
lda #$02 ; Force helicopter to settle down for victory sequence
sta ZP_ACCELY
lda #$00
sta ZP_STICKX
jsr processChopTurn ; A subset copy of the main loop routines run during the end game sequence
jsr checkButtonInput
jsr jumpEraseAllSprites
jsr jumpRenderStars
jsr jumpRenderMoon
jsr jumpTableScroll
jsr jumpRenderMountains
jsr jumpRenderBase
jsr jumpRenderFence
jsr jumpRenderHouses
jsr jumpUpdateHostages
jsr jumpUpdateEntities
jsr jumpDefragmentEntityList
jsr jumpInitSlideAnim
lda #$FF ; Set high palette bit
jsr jumpSetPalette
jsr jumpSetAnimLoc
.byte $75 ; X pos (low byte)
.byte $00 ; X pos (high byte)
.byte $70 ; Y pos
bit mainLoopEndGameWon ; $0cf7
bmi mainLoopEndGameWinSprite
jsr jumpSetSpriteAnimPtr
.word $a0f6 ; Pointer to The End sprite
jmp mainLoopEndGameFinalize
mainLoopEndGameWinSprite: ; $0d04
jsr jumpSetSpriteAnimPtr
.word $a0f8 ; Pointer to Broderbund Crown logo
mainLoopEndGameFinalize:
jsr jumpBlitImage ; Render, flip buffers, and loop
jsr jumpPageFlip
jsr jumpFlipPageMask
lda #$FF
eor ZP_BUFFER
sta ZP_BUFFER
jmp mainLoopEndGameLoop
mainLoopEndGameWon: ; $0d1b ; $00 = Player lost, $ff = Player won
.byte $00
; Renders everything needed to get the game into the initial state for gameplay (back at the base, etc)
renderStartingGameState: ; $0d1c
lda #$FF ; Assume victory on all new games
sta mainLoopEndGameWon1
jmp renderGameSetup
renderStartingGameStateForLoss: ; Called after time passes on loss condition (The End screen) $0d24
lda #$00
sta mainLoopEndGameWon1
renderGameSetup:
lda SCROLL_START_L ; Initialize scrolling position
sta ZP_SCROLLPOS_L
lda SCROLL_START_H
sta ZP_SCROLLPOS_H
jsr jumpSetLocalScroll
.word $0072 ; Points to ZP_SCROLLPOS anyway
jsr jumpEraseAllSprites
ldx TITLEREGION_TOP ; Erase any titles that might still be there
inx
ldy TITLEREGION_BOT
lda #$80
jsr jumpScreenFill
jsr jumpRenderStars1
jsr jumpRenderMoon
jsr jumpRenderMountains
bit mainLoopEndGameWon1 ; Hide the base at demo end
bpl renderGameSetupSkipBase
jsr jumpRenderBase
renderGameSetupSkipBase:
jsr jumpPageFlip
jsr jumpFlipPageMask
lda #$FF
eor ZP_BUFFER
sta ZP_BUFFER
jsr jumpEraseAllSprites
ldx TITLEREGION_TOP ; Erase any titles that might still be there
inx
ldy TITLEREGION_BOT
lda #$80
jsr jumpScreenFill
jsr jumpRenderStars1
jsr jumpRenderMoon
jsr jumpRenderMountains
bit mainLoopEndGameWon1 ; Hide the base at demo end
bpl renderGameSetupSkipBase2
jsr jumpRenderBase
renderGameSetupSkipBase2:
jsr jumpPageFlip ; Flip the buffers and we're done
jsr jumpFlipPageMask
lda #$FF
eor ZP_BUFFER
sta ZP_BUFFER
rts ; 0d90
mainLoopEndGameWon1:
.byte $ff ; 0d91 ; $00 = Player lost/demo, $ff = Player won
; Checks for any form of button input (keyboard or joystick buttons).
; Returns carry set if something was detected. For keyboard, we do some
; processing of that input as well. Cheat keys will be checked, etc
checkButtonInput: ; $0d92
lda $C000 ; Check any key
cmp #$80
bcs keyPushed
lda $C061 ; Button 0
cmp #$80
bcs joystickPushed
lda $C062 ; Button 1
cmp #$80
bcs joystickPushed
clc ; Nothing pushed - clear carry and return
rts
joystickPushed: ; Joystick button- set carry and return
sec
rts
keyPushed: ; High bit will still be set on these
bit $C010 ; Clear strobe
cmp #$93 ; Ctrl-S toggles sound
bne checkV
lda #$FF
eor PREFS_SOUND
sta PREFS_SOUND
jmp doneHandled
checkV:
cmp #$96 ; Ctrl-V flips vertical joystick
bne checkA
lda #$FF
eor PREFS_JOY_Y
sta PREFS_JOY_Y
jmp doneHandled
checkA:
cmp #$81 ; Ctrl-A flips horizontal joystick
bne checkESC
lda #$FF
eor PREFS_JOY_X
sta PREFS_JOY_X
jmp doneHandled
checkESC:
cmp #$9B ; ESC pauses game
bne checkL
pauseLoop:
lda $C000 ; Wait for another key to unpause
bpl pauseLoop
cmp #$9B
bne keyPushed ; Handle preference keys while paused
bit $C010 ; Clear strobe
clc ; Don't count this second unpause key as "input detected"
rts
checkL:
cmp #$8C ; Ctrl-L is a secret debug tool to set difficulty level
bne doneHandled
pauseLoopL:
lda $C000
bpl pauseLoopL ; Wait for level selection
and #$03 ; Any key with 0-7 low bits will work, including number keys, conveniently
sta CURR_LEVEL
bit $C010
clc ; Don't count this second unpause key as "input detected"
rts
doneHandled:
sec ; Carry set means key was detected, even if we handled it
rts
; Checks the state of joystick button 0, and reacts to it during gameplay
checkJoystick0: ; $0e02
lda $C061 ; Check button 0
cmp #$80
bcs joystick0Push
clearButton0: ; Demo code JSRs into here, piggyback style
lda #$00 ; Button not down, so clear state and we're done
sta buttonZeroDown
rts
joystick0Push: ; Demo code JSRs into here, piggyback style
bit ZP_BTN0DOWN
bmi joystickDone ; Joystick button already down
lda buttonZeroDown
bne joystickDone
lda #$FF
sta buttonZeroDown
; Slightly hacky, but shooting conditions are checked directly here instead of in shooting routines
lda ZP_AIRBORNE ; Can't shoot on the ground
beq joystickDone
lda ZP_DYING ; Can't shoot while dying
bne joystickDone
lda CURR_SHOTS ; Can't shoot more than five times at once
cmp #$05
bcs joystickDone
lda #$FF ; Track that button zero is down
sta ZP_BTN0DOWN
ldx #$30 ; Play shoot sound
ldy #$20
lda #$01
jsr jumpPlaySound
joystickDone:
rts
buttonZeroDown: ; $0e3a
.byte $00 ; $ff if button zero is down
; Checks the state of joystick button 1, and reacts to it during gameplay
checkJoystick1: ; 0e3b:
lda $C062 ; Check joystick button 1
cmp #$80
; Slightly hacky, but rotation conditions are checked directly here, instead of in flight control routines
bcc checkJoystick1NoTurn ; Button not down so we're done
lda ZP_AIRBORNE
beq checkJoystick1NoTurn ; Can't rotate when on the ground
lda ZP_DYING
bne checkJoystick1NoTurn ; Can't rotate during death animation
lda buttonOneDown
bne processChopTurn ; Button already down
lda #$FF
sta buttonOneDown ; Button 1 now down
lda ZP_TURN_STATE
beq beginTurn
cmp #$01
beq beginTurn
cmp #$FF
beq beginTurn
jmp continueTurn
beginTurn:
lda #$00 ; Clear turn request so turn can begin
sta CHOP_TURN_REQUEST
bit CHOP_STICKX ; Determine direction to go
bmi turnToLeft
jmp turnToRight
continueTurn:
lda ZP_TURN_STATE
sta CHOP_TURN_REQUEST ; During turn, we cache state in the request
bmi turnToRight
jmp turnToLeft
turnToRight:
lda #$01
sta CHOP_FACE ; Turn chopper to the right (internally the turn is instant)
jmp processChopTurn
turnToLeft:
lda #$FF
sta CHOP_FACE ; Turn chopper to the left (internally the turn is instant)
jmp processChopTurn
checkJoystick1NoTurn: ; No new turn permitted, but finish any existing one that is underway
lda buttonOneDown
beq processChopTurn
lda #$00
sta buttonOneDown
lda ZP_TURN_STATE
beq neutralStick
cmp #$01
beq neutralStick
cmp #$FF
beq neutralStick
lda CHOP_TURN_REQUEST
beq checkRight
eor ZP_TURN_STATE
bmi checkRight
neutralStick:
lda #$00
sta CHOP_FACE ; Turn chopper to face camera
jmp processChopTurn
checkRight:
bit ZP_TURN_STATE
bmi leftStick
lda #$01
sta CHOP_FACE ; Turn chopper to the right
jmp processChopTurn
leftStick:
lda #$FF
sta CHOP_FACE ; Turn chopper to the left
; Processes a chopper turn that is underway. We fall through to here from above,
; but this is also a self-contained subroutine called from elsewhere in the game
processChopTurn: ; 0ec2
lda CHOP_FACE
beq facingCamera
bpl facingRight
bmi facingLeft
facingCamera:
clc ; When facing camera, turn direction is mapped from acceleration
lda ZP_ACCELX
adc #$05
tax
lda facingTurnTable,x
jmp checkTurn
facingRight:
lda #$05
jmp checkTurn
facingLeft:
lda #$FB
checkTurn:
cmp ZP_TURN_STATE ; Never turn through zero all at once
beq turningDone
clc ; Check where we are in the turn and where we need to go
adc #$05
sta ZP_SCRATCH58
clc
lda ZP_TURN_STATE
adc #$05
sec