-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEFT18Thinking.asm
1083 lines (1045 loc) · 29.6 KB
/
EFT18Thinking.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
;==================================================================
;==================================================================
;EFT VERSION 1.8T (THINKING) 11/30/81 COPYRIGHT CHRIS CRAWFORD 1981
;==================================================================
;======================================
;Page zero RAM
;======================================
;
;These locations are for the mainline routines
;
CHUNKX = $BE
CHUNKY = $BF
CORPS = $B4
;--------------------------------------
;--------------------------------------
* = $C0
;--------------------------------------
MAPPTR .word ?
ARMY .byte ?
UNITNO .byte ?
DEFNDR .byte ?
TEMPR .byte ?
TEMPZ .byte ?
ACCLO .byte ?
ACCHI .byte ?
TURN .byte ?
LAT .byte ?
LONG .byte ?
RFR .byte ?
TRNTYP .byte ?
SQVAL .byte ?
;
;
TRIG0 = $D010
CONSOL = $D01F
AUDF1 = $D200
AUDC1 = $D201
RANDOM = $D20A
NMIEN = $D40E
SETVBV = $E45C
;
;THESE VALUES ARE USED BY MAINLINE ROUTINE ONLY
;
;--------------------------------------
;--------------------------------------
* = $605
;--------------------------------------
TRCOLR .byte ?
EARTH .byte ?
ICELAT .byte ?
SEASN1 .byte ?
SEASN2 .byte ?
SEASN3 .byte ?
DAY .byte ?
MONTH .byte ?
YEAR .byte ?
;--------------------------------------
;--------------------------------------
* = $62A
;--------------------------------------
OLDLAT .byte ?
TRNCOD .byte ?
TLO .byte ?
THI .byte ?
TICK .byte ?
UNTCOD .byte ?
UNTCD1 .byte ?
BVAL .byte ? ; best value
BONE .byte ? ; best index
DIR .byte ? ; direction
TARGX .byte ? ; square under consideration
TARGY .byte ?
SQX .byte ? ; adjacent square
SQY .byte ?
JCNT .byte ? ; counter for adjacent squares
LINCOD .byte ? ; code value of line configuration
NBVAL .byte ? ; another best value
RORD1 .byte ? ; Russian orders
RORD2 .byte ?
HDIR .byte ? ; horizontal direction
VDIR .byte ? ; vertical direction
LDIR .byte ? ; larger direction
SDIR .byte ? ; smaller direction
HRNGE .byte ? ; horizontal range
VRNGE .byte ? ; vertical range
LRNGE .byte ? ; larger range
SRNGE .byte ? ; smaller range
CHRIS .byte ? ; midway counter
RANGE .byte ? ; just that
RCNT .byte ? ; counter for Russian orders
SECDIR .byte ? ; secondary direction
POTATO .byte ? ; a stupid temporary
BAKARR .fill 25
LINARR .fill 25
IFR0 .byte ?
IFR1 .byte ?
IFR2 .byte ?
IFR3 .byte ?
XLOC .byte ?
YLOC .byte ?
TEMPX .byte ?
TEMPY .byte ?
LV .fill 5
LPTS .byte ?
COLUM .byte ?
OCOLUM .byte ?
IFRHI .byte ?
PASSCT .byte ?
DELAY .byte ?
HANDCP .byte ?
TOTGS .byte ?
TOTRS .byte ?
OFR .byte ?
;
;declarations of routines in other modules
DEFNC = $79B4
ROTARR = $7A78
OBJX = $7A91
JSTP = $799C
;--------------------------------------
;--------------------------------------
* = $7BD9
;--------------------------------------
NDX .fill 24
YINC .byte ?
XINC .fill 4
OFFNC .fill 10
OBJY = $5398
IFR = $698
TERR = $7240
Y00 = $72DE
;--------------------------------------
;--------------------------------------
* = $5400
;--------------------------------------
CorpsX .fill 159 ; x-coords of all units (pixel frame)
CorpsY .fill 159 ; y-coords of all units (pixel frame)
MusterStrength .fill 159 ; muster strengths
CombatStrength .fill 159 ; combat strengths
SWAP .fill 159 ; terrain code underneath unit
ArrivalTurn .fill 159 ; turn of arrival
WordsTbl .fill 272 ; various words for messages
CorpType .fill 159 ; codes for unit types
CorpNumber .fill 159 ; ID numbers of units
HundredDigit .fill 256 ; tables for displaying numbers (hundreds)
TensDigit .fill 256 ; tens tables
OnesDigit .fill 256 ; ones tables
TxtTbl .fill 96 ; more text
DaysInMonth .fill 13 ; table of month lengths
HowManyOrders .fill 159 ; how many orders each unit has in queue
WhatOrders .fill 159 ; what the orders are
WHORDH .fill 159
BEEPTB .fill 4 ; table of beep tones
ERRMSG .fill 128 ; table of error messages
XOFF .fill 4 ; offsets for moving maltakreuze
YOFF .fill 4
MASKO .fill 4 ; mask values for decoding orders
XADD .fill 4 ; offsets for moving arrow
YADD .fill 4
TreeColors .fill 13 ; tree color table
MLTKRZ .fill 8 ; maltese cross shape
;
;RAM from $6000 to $6430 is taken up by
;character sets and the display list
;
;--------------------------------------
;--------------------------------------
* = $6431
;--------------------------------------
ArrowTbl .fill 32 ; arrow shapes
;--------------------------------------
;--------------------------------------
* = $6450
;--------------------------------------
;--------------------------------------
;--------------------------------------
TXTWDW * = $6CB1
;--------------------------------------
STKTAB .fill 16 ; a joystick decoding table
SSNCOD .fill 12 ; season codes
TRNTAB .fill 60 ; terrain cost tables
BHX1 .fill 22 ; intraversible square pair coordinates
BHY1 .fill 22
BHX2 .fill 22
BHY2 .fill 22
EXEC .fill 159 ; execution times
;
;Russian artificial intelligence routine
;
;--------------------------------------
;--------------------------------------
* = $4700
;--------------------------------------
;
;initialization loop
;
LDX #$01
STA TEMPR
STA TOTRS
STA TOTGS
LDY #$9E
LOOP80 LDA ArrivalTurn,Y
CMP TURN
BCS Z50
LDA TEMPR
CLC
ADC CombatStrength,Y
STA TEMPR
BCC Z50
INC TOTGS,X
Z50 DEY
CPY #$37
BCS LOOP80
LDX #$00
CPY #$00
BNE LOOP80
;
;now shift values 4 places right
;
LDA TOTRS
STA TEMPR
LDA TOTGS
LDX #$04
LOOP81 ASL A
BCC Z51
ROR A
LOOP82 LSR TEMPR
DEX
BNE LOOP82
BEQ Z52
Z51 DEX
BNE LOOP81
;
;now calculate overall force ratio
;
Z52 LDY #$FF
LDX TEMPR
BEQ Z53
SEC
LOOP83 INY
SBC TEMPR
BCS LOOP83
Z53 STY OFR
;
;now calculate individual force ratios
;
LDX #$9E
LOOP50 STX ARMY
LDA ArrivalTurn,X
CMP TURN
BCS Y44
JSR CALIFR
LDA CorpsX,X
STA OBJX-55,X
LDA CorpsY,X
STA OBJY-55,X
Y44 DEX
CPX #$37
BCS LOOP50
;
;here begins the main loop
;
MLOOP LDX #$9E ; outer loop for entire Russian army
LOOP51 STX ARMY ; inner loop for individual armies
LDA ArrivalTurn,X
CMP TURN
BCC Z26
Z54 JMP TOGSCN
Z26 LDA CorpType,X
CMP #$04
BEQ Z54
LDA OFR ; is army near the front?
LSR A
CMP IFR-55,X
BNE Y51 ; yes
STA BVAL ; no, treat as reinforcement
;
;find nearby beleaguered army
;
LDY #$9E
LOOP52 LDA ArrivalTurn,Y
CMP TURN
BCS Y54
LDA CorpsX,Y
SEC
SBC CorpsX,X
JSR INVERT
STA TEMPR
LDA CorpsY,Y
SEC
SBC CorpsY,X
JSR INVERT
CLC
ADC TEMPR
LSR A
LSR A
LSR A
BCS Y54
STA TEMPR
LDA IFR-55,Y
SEC
SBC TEMPR
BCC Y54 ; no good using nearby armies
CMP BVAL
BCC Y54
STA BVAL
STY BONE
Y54 DEY
CPY #$37
BCS LOOP52
LDY BONE ; beleagueredest army
LDA CorpsX,Y
STA OBJX-55,X
LDA CorpsY,Y
STA OBJY-55,X
JMP TOGSCN
;
;front line armies
;
Y51 LDA #$FF
STA DIR ; a direction of $FF means 'stay put'
STA BONE
LDA #$00
STA BVAL
;
;ad hoc logic for surrounded people
;
LDA IFRE-55,X
CMP #$10
BCS Z55
LDA MusterStrength,X
LSR A
CMP CombatStrength,X ; out of supply?
BCC DRLOOP
Z55 LDA CorpsX,X ; head due east!
SEC
SBC #$05
BCS Z96
LDA #$00
Z96 STA OBJX-55,X
JMP TOGSCN
DRLOOP LDA OBJX-55,X
LDY DIR
BMI Y55
CLC
ADC XINC,Y
Y55 STA TARGX
LDA OBJY-55,X
LDY DIR
BMI Y56
CLC
ADC YINC,Y
Y56 STA TARGY
LDA #$00
STA SQVAL
LDA DIR
BMI Y57
STA WhatOrders,X
JSR Y00
LDY ARMY
LDA EXEC,Y ; is square accessible?
BPL Y57 ; yes
JMP EVALSQ ; no, skip this square
;
;now fill in the direct line array
;
Y57 LDA #$00
STA LINCOD
LDA TARGX
STA SQX
LDA TARGY
STA SQY
LDY #$17
LOOP56 STY JCNT
LDA JSTP,Y
TAY
LDA SQX
CLC
ADC XINC,Y
STA SQX
LDA SQY
CLC
ADC YINC,Y
STA SQY
LDX #$9E
LOOP55 LDA ArrivalTurn,X
CMP TURN
BEQ Z25
BCS Y58
Z25 LDA OBJX-55,X
CMP SQX
BNE Y58
LDA OBJY-55,X
CMP SQY
BNE Y58
CPX ARMY
BEQ Y31
LDA MusterStrength,X
BNE Y59
Y58 DEX
CPX #$37
BCS LOOP55
Y31 LDA #$00
Y59 LDY JCNT
LDX NDX,Y
STA LINARR,X
DEY
BPL LOOP56
LDX ARMY
LDA MusterStrength,X
STA LINARR+12
LDA #$00
STA ACCLO
STA ACCHI
STA SECDIR
;
;build LV array
;
Y88 LDX #$00
STX POTATO
Y92 LDY #$00
Y90 LDA LINARR,X
BNE Y89
INX
INY
CPY #$05
BNE Y90
Y89 LDX POTATO
TYA
STA LV,X
INX
STX POTATO
CPX #$01
BNE Y91
LDX #$05
BNE Y92
Y91 CPX #$02
BNE Y93
LDX #$0A
BNE Y92
Y93 CPX #$03
BNE Z40
LDX #$0F
BNE Y92
Z40 CPX #$04
BNE Z41
LDX #$14
BNE Y92
Z41 LDA #$00
LDY #$04
LOOP76 LDX LV,Y
CPX #$05
BEQ Z42
CLC
ADC #$28
Z42 DEY
BPL LOOP76
;
;now add bonus if central column is otherwise empty
;
LDY LINARR+10
BNE Y95
LDY LINARR+11
BNE Y95
LDY LINARR+13
BNE Y95
LDY LINARR+14
BNE Y95
CLC
ADC #$30
Y95 STA LPTS
;
;now evaluate blocking penalty
;
LDX #$00
LOOP72 LDA LV,X
CMP #$04
BCS Y96
STA TEMPR
STX TEMPZ
TXA
ASL A
ASL A
ADC TEMPZ
ADC TEMPR
TAY
INY
LDA LINARR,Y
BEQ Y96
LDA LPTS
SEC
SBC #$20
BCS A91
LDA #$00
A91 STA LPTS
Y96 INX
CPX #$05
BNE LOOP72
;
;now evaluate vulnerability to penetrations
;
LDY #$00
LOOP54 STY OCOLUM
LDX #$00
LOOP73 STX COLUM
CPX OCOLUM
BEQ NXCLM
LDA LV,X
SEC
SBC LV,Y
BEQ NXCLM
BMI NXCLM
TAX
LDA #$01
LOOP74 ASL A
DEX
BNE LOOP74
STA TEMPR
LDA LPTS
SEC
SBC TEMPR
BCS Y32
LDA #$00
Y32 STA LPTS
NXCLM LDX COLUM
INX
CPX #$05
BNE LOOP73
INY
CPY #$05
BNE LOOP54
;
;now get overall line value weighted by danger vector
;
LDX ARMY
LDY SECDIR
BNE Z18
LDA IFRN-55,X
JMP Z20
Z18 CPY #$01
BNE Z19
LDA IFRE-55,X
JMP Z20
Z19 CPY #$02
BNE Z17
LDA IFRS-55,X
JMP Z20
Z17 LDA IFRW-55,X
Z20 STA TEMPR
LDX LPTS
BEQ Z49
LDA ACCLO
CLC
LOOP75 ADC TEMPR
BCC Y34
INC ACCHI
CLC
BNE Y34
LDA #$FF
STA ACCHI
Y34 DEX
BNE LOOP75
;
;next secondary direction
;
Z49 INY
CPY #$04
BEQ Y35
STY SECDIR
;
;rotate array
;
LDX #$18
LOOP70 LDA LINARR,X
STA BAKARR,X
DEX
BPL LOOP70
LDX #$18
LOOP71 LDY ROTARR,X
LDA BAKARR,X
STA LINARR,Y
DEX
BPL LOOP71
JMP Y88
Y35 LDA ACCHI
STA SQVAL
;
;get range to closest German into NBVAL
;
Y65 LDY #$36
LDA #$FF
STA NBVAL
LOOP59 LDA ArrivalTurn,Y
CMP TURN
BEQ Z45
BCS Y68
Z45 LDA CorpsX,Y
SEC
SBC TARGX
JSR INVERT
STA TEMPR
LDA CorpsY,Y
SEC
SBC TARGY
JSR INVERT
CLC
ADC TEMPR
CMP NBVAL
BCS Y68
STA NBVAL
Y68 DEY
BPL LOOP59
;
;now determine whether to use offensive or defensive strategy
;
LDX ARMY
LDA IFR-55,X
STA TEMPR
LDA #$0F
SEC
SBC TEMPR
BCC A40
ASL A ;OK, let's fool the routine
STA TEMPR
LDA #$09
SEC
SBC NBVAL ; I know that NBVAL<9 for all front line units
STA NBVAL
;
;now add NBVAL*IFR to SQVAL with defensive bonus
;
A40 LDY NBVAL
BNE Z24 ; this square occupied by a German?
STY SQVAL ; yes, do not enter!!!
JMP EVALSQ
Z24 LDY TRNTYP
LDA DEFNC,Y
CLC
ADC NBVAL
TAY
LDA #$00
CLC
LOOP60 ADC TEMPR
BCC Y69
Z22 LDA #$FF
BMI Y71
Y69 DEY
BNE LOOP60
Y71 CLC
ADC SQVAL
BCC X00
LDA #$FF
X00 STA SQVAL
;
;extract penalty if somebody else has dibs on this square
;
LDY #$9E
LOOP58 LDA OBJX-55,Y
CMP TARGX
BNE Y63
LDA OBJY-55,Y
CMP TARGY
BNE Y63
CPY ARMY
BEQ Y63
LDA ArrivalTurn,Y
CMP TURN
BEQ Z44
BCS Y63
Z44 LDA SQVAL
SBC #$20
STA SQVAL
JMP EVALSQ
Y63 DEY
CPY #$37
BCS LOOP58
;
;now extract distance penalty
;
Y60 LDA CorpsX,X
SEC
SBC TARGX
JSR INVERT
STA TEMPR
LDA CorpsY,X
SEC
SBC TARGY
JSR INVERT
CLC
ADC TEMPR
CMP #$07
BCC Z48
LDA #$00
STA SQVAL ; this square is too far away
BEQ EVALSQ
Z48 TAX
LDA #$01
LOOP77 ASL A
DEX
BPL LOOP77
STA TEMPR
LDA SQVAL
SEC
SBC TEMPR
STA SQVAL
BCS EVALSQ
LDA #$00
STA SQVAL
;
;now evaluate this square
;
EVALSQ LDY DIR
LDX ARMY
LDA SQVAL
CMP BVAL
BCC Y72
STA BVAL
STY BONE
Y72 INY
CPY #$04
BEQ Y73
STY DIR
JMP DRLOOP
Y73 LDA OBJX-55,X
LDY BONE
BMI Y74
CLC
ADC XINC,Y
Y74 STA OBJX-55,X
LDA OBJY-55,X
LDY BONE
BMI Y75
CLC
ADC YINC,Y
Y75 STA OBJY-55,X
TOGSCN LDA TRIG0
BEQ A30 ; ignore game console if red button is down
LDA #$08
STA CONSOL
LDA CONSOL
AND #$01
BEQ WRAPUP
A30 DEX
CPX #$37
BCC Y76
JMP LOOP51
Y76 JMP MLOOP
WRAPUP LDX #$9E
LOOP62 STX ARMY
LDA ArrivalTurn,X
CMP TURN
BCC Y78
JMP Y77
Y78 LDA OBJX-55,X
LDY #$03
SEC
SBC CorpsX,X
BPL Y79
LDY #$01
JSR INVERT+2
Y79 STY HDIR
STA HRNGE
LDY #$00
LDA OBJY-55,X
SEC
SBC CorpsY,X
BPL Y80
LDY #$02
JSR INVERT+2
Y80 STY VDIR
STA VRNGE
CMP HRNGE
BCC Y81
STA LRNGE
LDA HRNGE
STA SRNGE
LDA HDIR
STA SDIR
STY LDIR
JMP Y82
Y81 STA SRNGE
STY SDIR
LDA HRNGE
STA LRNGE
LDY HDIR
STY LDIR
Y82 LDA #$00
STA RCNT
STA RORD1
STA RORD2
LDA LRNGE
CLC
ADC SRNGE
STA RANGE
BEQ Y86
LDA LRNGE
LSR A
STA CHRIS
LOOP61 LDA CHRIS
CLC
ADC SRNGE
STA CHRIS
SEC
SBC RANGE
BCS OVRFLO
LDA LDIR
BCC STIP
OVRFLO STA CHRIS
LDA SDIR
STIP STA DIR
LDA RCNT
AND #$03
TAY
STA TEMPR
LDA RCNT
LSR A
LSR A
TAX
LDA DIR
Y85 DEY
BMI Y84
ASL A
ASL A
JMP Y85
Y84 LDY TEMPR
EOR RORD1,X
AND MASKO,Y
EOR RORD1,X
STA RORD1,X
LDX RCNT
INX
STX RCNT
CPX #$08
BCS Y86
CPX RANGE
BCC LOOP61
Y86 LDX ARMY
LDA RORD1
STA WhatOrders,X
LDA RORD2
STA WHORDH,X
LDA RCNT
STA HowManyOrders,X
Y77 DEX
CPX #$37
BCC Y87
JMP LOOP62
Y87 RTS
;
;Subroutine CALIFR determines individual force ratios
;in all four directions
;
CALIFR LDY #$00 ; initialize vectors
STY IFR0
STY IFR1
STY IFR2
STY IFR3
STY IFRHI
INY
STY RFR
LDA CorpsX,X
STA XLOC
LDA CorpsY,X
STA YLOC
LDY #$9E
LOOP53 LDA ArrivalTurn,Y
CMP TURN
BCS Z07
LDA CorpsY,Y
SEC
SBC YLOC
STA TEMPY ; save signed vector
JSR INVERT
STA TEMPR
LDA CorpsX,Y
SEC
SBC XLOC
STA TEMPX
JSR INVERT
CLC
ADC TEMPR
Z21 CMP #$09 ;no point in checking if he's too far
Z07 BCS Y48
LSR A
STA TEMPR ; this is half of range to unit
;
;now select which IFR gets this German
;
LDA TEMPX
BPL Z00
LDA TEMPY
BPL Z01
LDX #$02
CMP TEMPX
BCS Z02
LDX #$01
BCC Z02
Z00 LDA TEMPY
BPL Z03
JSR INVERT+2
LDX #$02
CMP TEMPX
BCS Z02
LDX #$03
BCC Z02
Z03 LDX #$00
CMP TEMPX
BCS Z02
LDX #$03
BCC Z02
Z01 LDA TEMPX
JSR INVERT+2
LDX #$01
CMP TEMPY
BCS Z02
LDX #$00
Z02 LDA CombatStrength,Y
LSR A
LSR A
LSR A
LSR A
Z11 CPY #$37
BCC Z12
CLC
ADC RFR
BCC Z13
LDA #$FF
Z13 STA RFR
JMP Y48
Z12 CLC
ADC IFR0,X
BCC Z05
LDA #$FF
Z05 STA IFR0,X
Y48 DEY
BEQ Z06
JMP LOOP53
Z06 LDX #$03
LDA #$00
Y37 CLC
ADC IFR0,X
BCC Y36
LDA #$FF
Y36 DEX
BPL Y37
ASL A
ROL IFRHI
ASL A
ROL IFRHI
ASL A
ROL IFRHI
ASL A
ROL IFRHI
LDX #$00
SEC
Z16 SBC RFR
BCS Z14
DEC IFRHI
SEC
BMI Z15
Z14 INX
JMP Z16
Z15 TXA
LDX ARMY
CLC
ADC OFR ; remember strategic situation
ROR A ; average strategic with tactical
STA IFR-55,X
;
;keep a record of danger vector