forked from pkali/scorch_src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgame.asm
1517 lines (1324 loc) · 33.8 KB
/
game.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; @com.wudsn.ide.asm.mainsourcefile=scorch.asm
.IF *>0 ;this is a trick that prevents compiling this file alone
; All main procedures of the game not dependent on hardware (I hope) :)
START
jsr MakeDarkScreen
; Startup sequence
jsr Initialize
;jsr GameOverScreen ; only for test !!!
RMTSong song_main_menu
jsr Options ;startup screen
jsr SetVariablesFromOptions
jsr MakeDarkScreen
bit escFlag
bpl @+
jsr CheckStartKey ; START KEY
bne START
jmp StartAfterSplash ; reset all game option if Start key pressed (and Esc)
@
jsr EnterPlayerNames
jsr MakeDarkScreen
bit escFlag
bmi START
jsr RandomizeSequence
; for the round #1 shooting sequence is random
MainGameLoop
jsr SetWallsType
; first set default barrel lengths (fix for Long Schlong activation :) )
; we must do it before purchase/activate
; and set Auto Defense to off
jsr SetStandardBarrels
jsr CallPurchaseForEveryTank
jsr MakeDarkScreen
bit escFlag
bmi START
jsr GetRandomWind
jsr RoundInit
jsr MainRoundLoop
mva #$ff MeteorsFlag
bit escFlag
jvs GoGameOver
bmi START
jsr CalculateGains
jsr SortSequence
mva #0 TankNr ;
sta COLBAKS ; set background color to black
jsr SetJoystickPort ; set joystick port for player
; Hide all (easier than hide last ;) ) tanks
jsr cleartanks ; A=0
; here gains and losses should be displayed (dollars)
; finally we have changed our minds and money of players
; is displayed only in weapons shop
; Results are number of other deaths
; before the player dies itself
RmtSong song_round_over
jsr DisplayResults
jsr DemoModeOrKey
jsr MakeDarkScreen
lda GameIsOver
beq NoGameOverYet
GoGameOver
jsr GameOverScreen
jmp START
NoGameOverYet
inc CurrentRoundNr
mva #sfx_silencer sfx_effect
jmp MainGameLoop
;--------------------------------------------------
.proc CalculateGains
;--------------------------------------------------
; add gains and substract losses
; gain is what player gets for lost energy of opponents
; energy lost by opponents is added during Round and
; little below in source, multiplied by 2 to get "dollars".
; By analogy, loss is energy that given player losses during
; each Round.
; Important! If player has 10 energy and gets a central hit
; from nuke that would take 90 energy points, his loss
; is 90, not 10
ldx NumberOfPlayers
dex
CalculateGainsLoop
; adding the remaining energy of the tank to gain
; winner gets more ! :)
lda Energy,x
adc gainL,x
sta gainL,x
bcc @+
inc gainH,x
@
; add gain * 2
asl gainL,x
rol gainH,x
clc
lda moneyL,x
adc gainL,x
sta moneyL,x
lda moneyH,x
adc gainH,x
sta moneyH,x
; substract lose
; if lose is greater than money then zero money
lda moneyH,x
cmp loseH,x
bne @+
lda moneyL,x
cmp loseL,x
@ bcs substractlose
zeromoney
lda #0
sta moneyL,x
sta moneyH,x
beq skipzeroing
substractlose
; sec ; C is allways set at this point
lda moneyL,x
sbc loseL,x
sta moneyL,x
lda moneyH,x
sbc loseH,x
sta moneyH,x
skipzeroing
; and earned money for summary
clc
lda EarnedMoneyL,x
adc gainL,x
sta EarnedMoneyL,x
lda EarnedMoneyH,x
adc gainH,x
sta EarnedMoneyH,x
; substract lose
; if lose is greater than money then zero money
lda EarnedMoneyH,x
cmp loseH,x
bne @+
lda EarnedMoneyL,x
cmp loseL,x
@ bcs esubstractlose
ezeromoney
lda #0
sta EarnedMoneyL,x
sta EarnedMoneyH,x
beq eskipzeroing
esubstractlose
; sec ; C is allways set at this point
lda EarnedMoneyL,x
sbc loseL,x
sta EarnedMoneyL,x
lda EarnedMoneyH,x
sbc loseH,x
sta EarnedMoneyH,x
eskipzeroing
dex
jpl CalculateGainsLoop
rts
.endp
;--------------------------------------------------
.proc RoundInit
;--------------------------------------------------
; at the beginning of each Round we set energy
; of all players to 99
; the maximum shooting energy to 990 (it is 10*energy)
; the default shooting energy to 350
; the shooting angle is randomized
; of course gains an loses are zeroed
RmtSong song_ingame
jsr SetPMWidthAndColors ; A=0
lda #0
sta AfterBFGflag ; reset BFG flag
sta COLOR2 ; status line "off"
sta COLOR1
tax
@ sta singleRoundVars,x
inx
cpx #(singleRoundVarsEnd-singleRoundVars)
bne @-
ldx #(MaxPlayers-1)
SettingEnergies
lda #$00
sta gainL,x
sta gainH,x
sta loseL,x
sta loseH,x
lda #99
sta Energy,x
sta eXistenZ,x
sta LASTeXistenZ,x
; anything in eXistenZ table means that this tank exist
; in the given round
jsr MaxForceCalculate
lda #<350
sta ForceTableL,x
lda #>350
sta ForceTableH,x
;lda #(255-45)
;it does not look good when all tanks have
;barrels pointing the same direction
;so it would be nice to have more or less random
;angles
jsr RandomizeAngle
sta AngleTable,x
dex
bpl SettingEnergies
; set mountain type if ...
lda RandomMountains
beq noRandomMountains
@ ldy RANDOM
cpy #5
bcs @-
jsr SetVariablesFromOptions.setMountainsType
noRandomMountains
;generating the new landscape
jsr PMoutofScreen ;let P/M disappear
jsr clearscreen ;let the screen be clean
jsr ClearPMmemory
jsr placetanks ;let the tanks be evenly placed
jsr calculatemountains ;let mountains be easy for the eye
;jsr calculatemountains0 ;only for tests - makes mountains flat and 0 height
mwa #StatusBufferROM temp
mwa #StatusBufferCopy temp2
mwa #StatusBufferCopyEnd+1 modify
jsr CopyFromROM
jsr SetMainScreen
jsr drawmountains ;draw them
jsr drawtanks ;finally draw tanks
mva #$00 TankSequencePointer
lda random
;lda #$00 ; allways
sta MeteorsRound ; Turns meteors on or off during the next round.
;---------round screen is ready---------
mva #TextForegroundColor COLOR1 ; status line "on"
rts
.endp
;--------------------------------------------------
.proc MainRoundLoop
; here we must check if by a chance there is only one
; tank with energy greater than 0 left
;--------------------------------------------------
ldy #0 ; in Y - number of tanks with energy greater than zero
sty ATRACT ; reset atract mode
ldx NumberOfPlayers
dex
CheckingIfRoundIsFinished
lda eXistenZ,x
beq NoEnergy
iny
NoEnergy
dex
bpl CheckingIfRoundIsFinished
cpy #2 ; is it less than 2 tanks have energy >0 ?
bcs DoNotFinishTheRound
;points for the last living tank
ldx NumberOfPlayers
dex
WhichTankWonLoop
lda eXistenZ,x
bne ThisOneWon
dex
bpl WhichTankWonLoop
;error was here!!!
; somehow I believed program will be never here
; but it was a bad assumption
; god knows when there is such a situation
; (we've got a SITUATION here, if you know what I mean)
; there are two tanks left.
; one of them is killed by the second tank
; second tank explodes and kills the first one.
; and code lands here...
; looks like no one won!
rts
ThisOneWon
lda CurrentResult
clc
adc ResultsTable,x
sta ResultsTable,x
rts ; this Round is finished
DoNotFinishTheRound
; Seppuku here
lda noDeathCounter
cmp seppukuVal
bcc @+
mva #0 noDeathCounter
mva #sfx_seppuku sfx_effect
jsr DisplaySeppuku
jmp Seppuku
@
; Auto Defense - activates defensives
ldx NumberOfPlayers
dex
CheckNextTankAD
lda Energy,x ; only active players
beq @+
lda AutoDefenseFlag,x ; with Auto Defence activated
beq @+
; run auto defense for tank in X
jsr AutoDefense
@ dex
bpl CheckNextTankAD
jsr DrawTanks ; redraw tanks with new defences
;
ldx TankSequencePointer
lda TankSequence,x
sta TankNr
tax
lda Energy,x ;skip if no energy
jeq NextPlayerShoots
mva #$ff plot4x4color
jsr DisplayTankNameAbove
mva #1 color ;to display flying point
ldx tankNr
lda TankStatusColoursTable,x
sta COLOR2 ; set color of status line
jsr RandomizeForce.LimitForce
jsr PutTankNameOnScreen
; jsr DisplayStatus ; There is no need anymore, it is always after PutTankNameOnScreen
lda MeteorsRound
bmi @+
; A = 0
sta MeteorsFlag
@
lda SkillTable,x
beq ManualShooting
RoboTanks
; robotanks shoot here
; TankNr still in X
jsr ArtificialIntelligence
; after calliing AI we allways have TankNr in X
;ldx TankNr
jsr DisplayStatus ; to make visible AI selected defensive (and offensive :) )
jsr MoveBarrelToNewPosition
jsr CheckExitKeys
spl:rts ; keys Esc or O
jmp AfterManualShooting
ManualShooting
lda JoyNumber,x
jsr SetJoystickPort ; set joystick port for player
jsr WaitForKeyRelease
lda #%00000000
sta TestFlightFlag ; set "Test Fight" off
jsr BeforeFire
bit escFlag
spl:rts ; keys Esc or O
AfterManualShooting
ldy #$00
sty plot4x4color
dey
sty MeteorsFlag ; $ff
jsr DisplayTankNameAbove
; defensive weapons without flight handling
ldx TankNr
lda ActiveDefenceWeapon,x
cmp #ind_Hovercraft
beq GoFloat
cmp #ind_White_Flag ; White Flag
beq ShootWhiteFlag
cmp #ind_Nuclear_Winter_
bne StandardShoot
ShootAtomicWinter
; --- atomic winter ---
jsr AtomicWinter
jmp NextPlayerShoots ; and we skip shoot
ShootWhiteFlag
; --- white flag ---
jsr WhiteFlag
jsr TankFlying.SoilDownAfterLanding ; Soildown like after Hovercraf landing :)
jmp NextPlayerShoots ; and we skip shoot
GoFloat
jsr TankFlying
lda #0
sta ActiveDefenceWeapon,x ; deactivate after use
bit escFlag
bpl ManualShooting ; after floating tank can shoot
rts
StandardShoot
inc noDeathCounter
jsr DecreaseWeaponBeforeShoot
jsr DisplayStatus
; ldx TankNr
dec Energy,x ; lower energy to eventually let tanks commit suicide
ShootNow
lda ActiveWeapon,x
cmp #ind_Buy_me ; BFG
beq WeponNoFlight ; but with explosion
cmp #ind_Punch ; Punch
beq WeponNoFlight ; but with explosion
lda MeteorsRound
bmi @+
; A = 0
sta MeteorsFlag
@
jsr Shoot ; bullet flight
mva #$ff MeteorsFlag
bit escFlag
spl:rts ; keys Esc or O
lda HitFlag ;0 if missed
beq missed
bne GoExplosion
WeponNoFlight
jsr NoShoot ; no bullet flight
GoExplosion
jsr Explosion
continueMainRoundLoopAfterSeppuku
mva #sfx_silencer sfx_effect
AfterExplode
jsr SoilDown ; allways
NoFallDown2
;here tanks are falling down
mva tankNr tempor2
ldx NumberOfPlayers
dex
TanksFallDown
stx TankNr
lda eXistenZ,x
beq NoExistNoFall
jsr TankFalls
NoExistNoFall
dex
bpl TanksFallDown
mvx tempor2 TankNr
missed
ldy WeaponDepleted
bne @+
ldx TankNr
tya
sta ActiveWeapon,x
@
;here we clear offensive text (after a shoot) - is cleared !! :)
; ldy TankNr
; jsr DisplayOffensiveTextNr
NextPlayerShoots
;before it shoots, the eXistenZ table must be updated
;accordingly to actual energy (was forgotten, sorry to ourselves)
ldx #(MaxPlayers-1)
SeteXistenZ
lda Energy,x
sta eXistenZ,x
jsr MaxForceCalculate
dex
bpl SeteXistenZ
;was setup of maximum energy for players
PlayersAgain
; In LASTeXistenZ there are values of eXistenZ before shoot
; from the next tank.
; Now it must be checked if by a chance something that had
; LASTeXistenZ>0 is not equal to 0 right now,
; because it means this tank died during this round.
; Most important thing is:
; after each explosion of the tank these operations must be
; performed from the beginning!
; (it is made by another jump into the after explosion routines)
; It is because exploding tank can destroy their neighbours,
; additionally this tank just have had LASTeXistenZ set to 0,
; otherwise it would explode again and again.
; OK, text how to do it is ready, now comes coding .
; Aaaah! - in the main loop we have to set eXistenZ and LASTeXistenZ
mva #sfx_next_player sfx_effect
ldx NumberOfPlayers
dex
CheckingPlayersDeath
lda LASTeXistenZ,x
beq NoPlayerNoDeath
lda eXistenZ,x
beq PlayerXdeath
NoPlayerNoDeath
dex
bpl CheckingPlayersDeath
; if processor is here it means there are no more explosions
inc:lda TankSequencePointer
cmp NumberOfPlayers
bne NotLastPlayerInRound
mva #0 TankSequencePointer
lda WindChangeInRound
beq NoWindChangeNow
jsr GetRandomWind ; wind change after each turn (not round only)
NoWindChangeNow
NotLastPlayerInRound
jmp MainRoundLoop
.endp
;---------------------------------
.proc PlayerXdeath
; this tank should not explode anymore:
; there is 0 in A, and Tank Number in X, so...
;---------------------------------
sta LASTeXistenZ,x
; save x somewhere
stx TankTempY
;clear NoDeathCounter here
sta noDeathCounter
mva #sfx_death_begin sfx_effect
; display defensive text here (well, defensive
; is not the real meaning, it should be pre-death,
; but I am too lazy to change names of variables)
; in X there is a number of tank that died
lda #talk.VeryFunnyText ; mumber of defensive text after BFG! ("VERY FUNNY.")
bit AfterBFGflag ; check BFG flag
bmi TextAfterBFG
; if BFG then no points for dead tanks ...
lda CurrentResult
clc
adc ResultsTable,x
sta ResultsTable,x
;inc CurrentResult
; RandomizeDeffensiveText
randomize talk.NumberOfOffensiveTexts (talk.NumberOfDeffensiveTexts+talk.NumberOfOffensiveTexts-1)
TextAfterBFG
sta TextNumberOff
inc CurrentResult ; ... but increase result of winner (BFG)
ldy TankTempY
lda #$ff
jsr DisplayOffensiveTextNr.notZero
; tank flash
ldy TankTempY
mva TankNr temp2 ; not elegant, and probably unnecessary
sty TankNr
jsr FlashTank ; blinking and pausing (like PAUSE 72 - 18x(2+2) )
mva temp2 TankNr
;Deffensive text cleanup
;here we clear Deffensive text (after a shoot)
ldy TankTempY
jsr DisplayOffensiveTextNr
; calculate position of the explosion (the post-death one)
ldx TankTempY
clc
lda xtankstableL,x
adc #4 ; more or less in the middle of the tank
sta xdraw
lda xtankstableH,x
adc #0
sta xdraw+1
sec
lda ytankstable,x
sbc #4
sta ydraw
lda #0
sta ydraw+1 ; there is 0 left in A, so... TODO: bad code above. revisit
;cleanup of the soil fall down ranges (left and right)
jsr ClearScreenSoilRange
; We are randomizing the weapon now.
; jumping into the middle of the explosion
; routine
MetodOfDeath
lda random
and #%00011111 ; range 0-31
cmp #(weaponsOfDeathEnd-weaponsOfDeath) ; we have 20 weapons in table (from 0 to 19)
bcs MetodOfDeath
tay
lda weaponsOfDeath,y
;lda #32 ; plasma blast only
jsr ExplosionDirect
mva #sfx_silencer sfx_effect
; Clear current Shooter settings. After that, Shooter will "search" for the target again
ldx NumberOfPlayers
dex
@ lda skillTable,x
cmp #2 ; clear variables only if Shooter
bne NotShooter
lda #0
sta PreviousAngle,x
sta PreviousEnergyL,x
sta PreviousEnergyH,x
NotShooter
dex
bpl @-
; jump to after explosion routines (soil fallout, etc.)
; After going through these routines we are back
; to checking if a tank exploded and maybe we have
; a deadly shot here again.
jmp MainRoundLoop.AfterExplode
.endp
;--------------------------------------------------
.proc DecreaseEnergyX
;Decreases energy of player nr X by the value Y
;increases his financial loss
;increases gain of tank TankNr
;--------------------------------------------------
sty EnergyDecrease
; Lose increase
lda loseL,x
clc
adc EnergyDecrease
sta loseL,x
scc
inc loseH,x
; Energy now, not less than 0
sec
lda Energy,x
sbc EnergyDecrease
bcs NotNegativeEnergy
; if less than 0 then 0
lda #0
NotNegativeEnergy
sta Energy,x
;now increase the gain of the shooting tank
ldy TankNr
clc
lda gainL,y
adc EnergyDecrease
sta gainL,y
lda gainH,y
adc #0
sta gainH,y
rts
.endp
;--------------------------------------------------
.proc DecreaseShieldEnergyX
; Decreases energy of shield player nr X by the value Y
; if shield energy is 0 after decrease then in Y we have
; rest of the energy - to decrease tank energy
;--------------------------------------------------
sty EnergyDecrease
ldy #0 ; if Shield survive then no decrease tank anergy
; Energy cannot be less than 0
sec
lda ShieldEnergy,x
sbc EnergyDecrease
bcs NotNegativeShieldEnergy
; now calculate rest of energy for future tank energy decrease
sec
lda EnergyDecrease
sbc ShieldEnergy,x
tay
; ShieldEnargy less than 0 then .. 0
lda #0
NotNegativeShieldEnergy
sta ShieldEnergy,x
rts
.endp
;---------------------------------
.proc Seppuku
;---------------------------------
lda #0
; get position of the tank
ldx TankNr
; lda #0 ; turn off defense weapons when hara-kiring
sta ActiveDefenceWeapon,x
sta ShieldEnergy,x
jsr SetupXYdraw
lda #ind_Missile ; Missile
jsr ExplosionDirect
jmp MainRoundLoop.continueMainRoundLoopAfterSeppuku
.endp
;--------------------------------------------------
.proc GetRandomWind
;in: MaxWind (byte)
;out: Wind (word)
;uses: _
;--------------------------------------------------
mva #$00 Wind+1
sta Wind+2
sta Wind+3
@ lda random
sta Wind
beq noWind ; if 0 then nothing to do
cmp MaxWind
bcs @- ; if more than MaxWind then randomize again
; multiply Wind by 16
; two bytes of Wind are treated as a decimal part of vx variable
:4 aslw Wind
; decide the direction
lda random
bmi noWindDirectionChange
sec ; Wind = -Wind
.rept 2
lda #$00
sbc Wind+#
sta Wind+#
.endr
lda #$ff
sta Wind+2
sta Wind+3
noWind
noWindDirectionChange
rts
.endp
;--------------------------------------------------
.proc MaxForceCalculate
; calculates max force for tank (tanknr in X)
; Energy of tank X in A
;--------------------------------------------------
sta L1
lda #0
ldy #9
clc
CYK ror
ror L1
bcc NIE
clc
adc #10 ; multiplication by 10
NIE dey
bne CYK
sta MaxForceTableH,x
lda L1
sta MaxForceTableL,x
rts
.endp
;--------------------------------------------------
.proc WeaponCleanup
; cleaning of the weapon possesion tables
; 99 of Baby Missles and White Flags, all other weapons=0)
;--------------------------------------------------
ldx #(number_of_weapons - 1)
@ lda #$0
cpx #ind_White_Flag ; White Flag
bne no99
set99 lda #99
no99
.REPT MaxPlayers, #+1
sta TanksWeapon:1,x
.ENDR
dex
beq set99 ; Baby Missile (index=0)
bpl @-
rts
.endp
;--------------------------------------------------
.proc Initialize
;Initialization sequence
;uses: temp, ...
;--------------------------------------------------
deletePtr = temp
; clean variables
lda #0
sta escFlag
tay
mwa #variablesStart deletePtr
@ tya
sta (deletePtr),y
inw deletePtr
cpw deletePtr #ClearedvariablesEnd
bne @-
tya
jsr SetJoystickPort
; ser initial shapes for each tank (tanks 0-5 has shape 0 now)
ldy #1
sty TankShape+1
sty TankShape+4
iny
sty TankShape+2
sty TankShape+5
mwa #1024 RandBoundaryHigh
mva #$ff LastWeapon
sta HowMuchToFall
mva #1 color
jsr SetStandardBarrels
jsr WeaponCleanup
mva #>WeaponFont chbas
;parameter for old plot (unPlot) max 5 points
ldx #4
SetunPlots
lda #<display
sta oldplotL,x
lda #>display
sta oldplotH,x
lda #0
sta oldply,x
lda #$ff
sta oldora,x
dex
bpl SetunPlots
;setting up P/M graphics
lda #>pmgraph
sta pmbase
lda #$03 ; P/M on
sta GRACTL
jsr SetPMWidthAndColors
lda #%00100001 ; P/M priorities (multicolor players on) - prior=1
sta GPRIOR
jsr PMoutofScreen
;let the tanks be visible!
ldx #(maxPlayers-1)
lda #99 ; tank is visible
MakeTanksVisible
sta eXistenZ,x
dex
bpl MakeTanksVisible
mva #1 CurrentRoundNr ;we start from round 1
mva #6 NTSCcounter
rts
.endp
;--------------------------------------------------
.proc SetStandardBarrels
; set standart barrel length and deactivate Auto Defense
; for all tanks
;--------------------------------------------------
ldx #maxPlayers-1
@ lda #StandardBarrel ; standard barrel length
sta BarrelLength,x
lda #$00 ; deactivate Auto Defense
sta AutoDefenseFlag,x
dex
bpl @-
rts
.endp
;----------------------------------------------
/* .proc RandomizeSequence0
ldx #0
@ txa
sta TankSequence,x
inx
cpx #MaxPlayers
bne @-
rts
.endp */
;--------------------------------------------------
.proc RandomizeSequence
; in: NumberOfPlayers
; out: TankSequence
; how: get random number lower than NumberOfPlayers
; put it in the first slot.
; get another random number lower than NumberOfPlayers
; check if was previously saved in first slot
; if not then save it in second slot
; repeat untill NumberOfPlayers
ldx #0
GetRandomAgainX
txy ; destroy A!
dey
lda RANDOM
cmp NumberOfPlayers
bcs GetRandomAgainX
cpx #0
bne NotFirstSlot
sta TankSequence,x ;now first slot is ready
inx
bne GetRandomAgainX
NotFirstSlot
;now we have to check if the value was not used
;in previous slots
UsageLoop
cmp TankSequence,y
beq GetRandomAgainX ;apparently we have already used this value
dey
bpl UsageLoop
;well, looks like this value is new!
sta TankSequence,x
inx
cpx NumberOfPlayers
bcc GetRandomAgainX
rts
.endp
;----------------------------------------------
.proc RandomizeAngle
; routine returns in A
; a valid angle for the tank's barrel.
; X is not changed
;----------------------------------------------
; lets randomize someting between 0 and 180
randomize 0 180
rts
.endp
;----------------------------------------------
.proc RandomizeForce
; routine returns in ForceTable/L/H
; valid force of shooting for TankNr
; in X must be TankNr
; low and high randomize boundary passed as word value
; RandBoundaryLow
; RandBoundaryHigh
;----------------------------------------------
lda RANDOM
sta temp2
lda RANDOM
and #%00000011 ;(0..1023)
sta temp2+1
cpw RandBoundaryLow temp2
seq:bcs RandomizeForce
cpw RandBoundaryHigh temp2
bcc RandomizeForce
lda temp2
sta ForceTableL,x
lda temp2+1
sta ForceTableH,x
;---------
LimitForce
; in X must be TankNr
; cuts force to MaxForceTable
lda MaxForceTableH,x