10 ;EFT VERSION 1.8T (THINKING) 11/30/81 COPYRIGHT CHRIS CRAWFORD 1981
20 ;
30 ;Page zero RAM
40 ;
50 ;These locations are for the mainline routines
60 ;
70 CHUNKX=$BE
80 CHUNKY=$BF
90 CORPS=$B4
0100  *=$C0
0110 MAPPTR *=*+2
0120 ARMY *=*+1
0130 UNITNO *=*+1
0140 DEFNDR *=*+1
0150 TEMPR *=*+1
0160 TEMPZ *=*+1
0170 ACCLO *=*+1
0180 ACCHI *=*+1
0190 TURN *=*+1
0200 LAT *=*+1
0210 LONG *=*+1
0220 RFR *=*+1
0230 TRNTYP *=*+1
0240 SQVAL *=*+1
0250 ;
0260 ;
0270 TRIG0=$D010
0280 CONSOL=$D01F
0290 AUDF1=$D200
0300 AUDC1=$D201
0310 RANDOM=$D20A
0320 NMIEN=$D40E
0330 SETVBV=$E45C
0340 ;
0350 ;THESE VALUES ARE USED BY MAINLINE ROUTINE ONLY
0360 ;
0370  *=$605
0380 TRCOLR *=*+1
0390 EARTH *=*+1
0400 ICELAT *=*+1
0410 SEASN1 *=*+1
0420 SEASN2 *=*+1
0430 SEASN3 *=*+1
0440 DAY *=*+1
0450 MONTH *=*+1
0460 YEAR *=*+1
0470  *=$62A
0480 OLDLAT *=*+1
0490 TRNCOD *=*+1
0500 TLO *=*+1
0510 THI *=*+1
0520 TICK *=*+1
0530 UNTCOD *=*+1
0540 UNTCD1 *=*+1
0550 BVAL *=*+1 best value
0560 BONE *=*+1 best index
0570 DIR *=*+1 direction
0580 TARGX *=*+1 square under consideration
0590 TARGY *=*+1
0600 SQX *=*+1 adjacent square
0610 SQY *=*+1
0620 JCNT *=*+1 counter for adjacent squares
0630 LINCOD *=*+1 code value of line configuration
0640 NBVAL *=*+1 another best value
0650 RORD1 *=*+1 Russian orders
0660 RORD2 *=*+1
0670 HDIR *=*+1 horizontal direction
0680 VDIR *=*+1 vertical direction
0690 LDIR *=*+1 larger direction
0700 SDIR *=*+1 smaller direction
0710 HRNGE *=*+1 horizontal range
0720 VRNGE *=*+1 vertical range
0730 LRNGE *=*+1 larger range
0740 SRNGE *=*+1 smaller range
0750 CHRIS *=*+1 midway counter
0760 RANGE *=*+1 just that
0770 RCNT *=*+1 counter for Russian orders
0780 SECDIR *=*+1 secondary direction
0790 POTATO *=*+1 a stupid temporary
0800 BAKARR *=*+25
0810 LINARR *=*+25
0820 IFR0 *=*+1
0830 IFR1 *=*+1
0840 IFR2 *=*+1
0850 IFR3 *=*+1
0860 XLOC *=*+1
0870 YLOC *=*+1
0880 TEMPX *=*+1
0890 TEMPY *=*+1
0900 LV *=*+5
0910 LPTS *=*+1
0920 COLUM *=*+1
0930 OCOLUM *=*+1
0940 IFRHI *=*+1
0950 PASSCT *=*+1
0960 DELAY *=*+1
0970 HANDCP *=*+1
0980 TOTGS *=*+1
0990 TOTRS *=*+1
1000 OFR *=*+1
1010 ;
1020 ;declarations of routines in other modules
1030 DEFNC=$79B4
1040 ROTARR=$7A78
1050 OBJX=$7A91
1060 JSTP=$799C
1070  *=$7BD9
1080 NDX *=*+24
1090 YINC *=*+1
1100 XINC *=*+4
1110 OFFNC *=*+10
1120 OBJY=$5398
1130 IFR=$698
1140 TERR=$7240
1150 Y00=$72DE
1160 ;
1170  *=$5400
1180 CORPSX *=*+159 x-coords of all units (pixel frame)
1190 CORPSY *=*+159 y-coords of all units (pixel frame)
1200 MSTRNG *=*+159 muster strengths
1210 CSTRNG *=*+159 combat strengths
1220 SWAP *=*+159 terrain code underneath unit
1230 ARRIVE *=*+159 turn of arrival
1240 WORDS *=*+272 various words for messages
1250 CORPT *=*+159 codes for unit types
1260 CORPNO *=*+159 ID numbers of units
1270 HDIGIT *=*+256 tables for displaying numbers (hundreds)
1280 TDIGIT *=*+256 tens tables
1290 ODIGIT *=*+256 ones tables
1300 TXTTBL *=*+96 more text
1310 MONLEN *=*+13 table of month lengths
1320 HMORDS *=*+159 how many orders each unit has in queue
1330 WHORDS *=*+159 what the orders are
1340 WHORDH *=*+159
1350 BEEPTB *=*+4 table of beep tones
1360 ERRMSG *=*+128 table of error messages
1370 XOFF *=*+4 offsets for moving maltakreuze
1380 YOFF *=*+4
1390 MASKO *=*+4 mask values for decoding orders
1400 XADD *=*+4 offsets for moving arrow
1410 YADD *=*+4
1420 TRTAB *=*+13 tree color table
1430 MLTKRZ *=*+8 maltese cross shape
1440 ;
1450 ;RAM from $6000 to $6430 is taken up by
1460 ;character sets and the display list
1470 ;
1480  *=$6431
1490 ARRTAB *=*+32 arrow shapes
1500  *=$6450
1510 TXTWDW *=$6CB1
1520 STKTAB *=*+16 a joystick decoding table
1530 SSNCOD *=*+12 season codes
1540 TRNTAB *=*+60 terrain cost tables
1550 BHX1 *=*+22 intraversible square pair coordinates
1560 BHY1 *=*+22
1570 BHX2 *=*+22
1580 BHY2 *=*+22
1590 EXEC *=*+159 execution times
1600 ;
1610 ;
1620 ;Russian artificial intelligence routine
1630 ;
1640  *=$4700
1650 ;
1660 ;initialization loop
1670 ;
1680  LDX #$01
1690  STA TEMPR
1700  STA TOTRS
1710  STA TOTGS
1720  LDY #$9E
1730 LOOP80 LDA ARRIVE,Y
1740  CMP TURN
1750  BCS Z50
1760  LDA TEMPR
1770  CLC
1780  ADC CSTRNG,Y
1790  STA TEMPR
1800  BCC Z50
1810  INC TOTGS,X
1820 Z50 DEY
1830  CPY #$37
1840  BCS LOOP80
1850  LDX #$00
1860  CPY #$00
1870  BNE LOOP80
1880 ;
1890 ;now shift values 4 places right
1900 ;
1910  LDA TOTRS
1920  STA TEMPR
1930  LDA TOTGS
1940  LDX #$04
1950 LOOP81 ASL A
1960  BCC Z51
1970  ROR A
1980 LOOP82 LSR TEMPR
1990  DEX
2000  BNE LOOP82
2010  BEQ Z52
2020 Z51 DEX
2030  BNE LOOP81
2040 ;
2050 ;now calculate overall force ratio
2060 ;
2070 Z52 LDY #$FF
2080  LDX TEMPR
2090  BEQ Z53
2100  SEC
2110 LOOP83 INY
2120  SBC TEMPR
2130  BCS LOOP83
2140 Z53 STY OFR
2150 ;
2160 ;now calculate individual force ratios
2170 ;
2180  LDX #$9E
2190 LOOP50 STX ARMY
2200  LDA ARRIVE,X
2210  CMP TURN
2220  BCS Y44
2230  JSR CALIFR
2240  LDA CORPSX,X
2250  STA OBJX-55,X
2260  LDA CORPSY,X
2270  STA OBJY-55,X
2280 Y44 DEX
2290  CPX #$37
2300  BCS LOOP50
2310 ;
2320 ;here begins the main loop
2330 ;
2340 MLOOP LDX #$9E outer loop for entire Russian army
2350 LOOP51 STX ARMY inner loop for individual armies
2360  LDA ARRIVE,X
2370  CMP TURN
2380  BCC Z26
2390 Z54 JMP TOGSCN
2400 Z26 LDA CORPT,X
2410  CMP #$04
2420  BEQ Z54
2430  LDA OFR is army near the front?
2440  LSR A
2450  CMP IFR-55,X
2460  BNE Y51 yes
2470  STA BVAL no, treat as reinforcement
2480 ;
2490 ;find nearby beleaguered army
2500 ;
2510  LDY #$9E
2520 LOOP52 LDA ARRIVE,Y
2530  CMP TURN
2540  BCS Y54
2550  LDA CORPSX,Y
2560  SEC
2570  SBC CORPSX,X
2580  JSR INVERT
2590  STA TEMPR
2600  LDA CORPSY,Y
2610  SEC
2620  SBC CORPSY,X
2630  JSR INVERT
2640  CLC
2650  ADC TEMPR
2660  LSR A
2670  LSR A
2680  LSR A
2690  BCS Y54
2700  STA TEMPR
2710  LDA IFR-55,Y
2720  SEC
2730  SBC TEMPR
2740  BCC Y54 no good using nearby armies
2750  CMP BVAL
2760  BCC Y54
2770  STA BVAL
2780  STY BONE
2790 Y54 DEY
2800  CPY #$37
2810  BCS LOOP52
2820  LDY BONE beleagueredest army
2830  LDA CORPSX,Y
2840  STA OBJX-55,X
2850  LDA CORPSY,Y
2860  STA OBJY-55,X
2870  JMP TOGSCN
2880 ;
2890 ;front line armies
2900 ;
2910 Y51 LDA #$FF
2920  STA DIR a direction of $FF means 'stay put'
2930  STA BONE
2940  LDA #$00
2950  STA BVAL
2960 ;
2970 ;ad hoc logic for surrounded people
2980 ;
2990  LDA IFRE-55,X
3000  CMP #$10
3010  BCS Z55
3020  LDA MSTRNG,X
3030  LSR A
3040  CMP CSTRNG,X out of supply?
3050  BCC DRLOOP
3060 Z55 LDA CORPSX,X head due east!
3070  SEC
3080  SBC #$05
3090  BCS Z96
3100  LDA #$00
3110 Z96 STA OBJX-55,X
3120  JMP TOGSCN
3130 DRLOOP LDA OBJX-55,X
3140  LDY DIR
3150  BMI Y55
3160  CLC
3170  ADC XINC,Y
3180 Y55 STA TARGX
3190  LDA OBJY-55,X
3200  LDY DIR
3210  BMI Y56
3220  CLC
3230  ADC YINC,Y
3240 Y56 STA TARGY
3250  LDA #$00
3260  STA SQVAL
3270  LDA DIR
3280  BMI Y57
3290  STA WHORDS,X
3300  JSR Y00
3310  LDY ARMY
3320  LDA EXEC,Y is square accessible?
3330  BPL Y57 yes
3340  JMP EVALSQ no, skip this square
3350 ;
3360 ;now fill in the direct line array
3370 ;
3380 Y57 LDA #$00
3390  STA LINCOD
3400  LDA TARGX
3410  STA SQX
3420  LDA TARGY
3430  STA SQY
3440  LDY #$17
3450 LOOP56 STY JCNT
3460  LDA JSTP,Y
3470  TAY
3480  LDA SQX
3490  CLC
3500  ADC XINC,Y
3510  STA SQX
3520  LDA SQY
3530  CLC
3540  ADC YINC,Y
3550  STA SQY
3560 ;
3570  LDX #$9E
3580 LOOP55 LDA ARRIVE,X
3590  CMP TURN
3600  BEQ Z25
3610  BCS Y58
3620 Z25 LDA OBJX-55,X
3630  CMP SQX
3640  BNE Y58
3650  LDA OBJY-55,X
3660  CMP SQY
3670  BNE Y58
3680  CPX ARMY
3690  BEQ Y31
3700  LDA MSTRNG,X
3710  BNE Y59
3720 Y58 DEX
3730  CPX #$37
3740  BCS LOOP55
3750 Y31 LDA #$00
3760 Y59 LDY JCNT
3770  LDX NDX,Y
3780  STA LINARR,X
3790  DEY
3800  BPL LOOP56
3810 ;
3820  LDX ARMY
3830  LDA MSTRNG,X
3840  STA LINARR+12
3850  LDA #$00
3860  STA ACCLO
3870  STA ACCHI
3880  STA SECDIR
3890 ;
3900 ;build LV array
3910 ;
3920 Y88 LDX #$00
3930  STX POTATO
3940 Y92 LDY #$00
3950 Y90 LDA LINARR,X
3960  BNE Y89
3970  INX
3980  INY
3990  CPY #$05
4000  BNE Y90
4010 Y89 LDX POTATO
4020  TYA
4030  STA LV,X
4040  INX
4050  STX POTATO
4060  CPX #$01
4070  BNE Y91
4080  LDX #$05
4090  BNE Y92
4100 Y91 CPX #$02
4110  BNE Y93
4120  LDX #$0A
4130  BNE Y92
4140 ;
4150 Y93 CPX #$03
4160  BNE Z40
4170  LDX #$0F
4180  BNE Y92
4190 Z40 CPX #$04
4200  BNE Z41
4210  LDX #$14
4220  BNE Y92
4230 ;
4240 Z41 LDA #$00
4250  LDY #$04
4260 LOOP76 LDX LV,Y
4270  CPX #$05
4280  BEQ Z42
4290  CLC
4300  ADC #$28
4310 Z42 DEY
4320  BPL LOOP76
4330 ;
4340 ;now add bonus if central column is otherwise empty
4350 ;
4360  LDY LINARR+10
4370  BNE Y95
4380  LDY LINARR+11
4390  BNE Y95
4400  LDY LINARR+13
4410  BNE Y95
4420  LDY LINARR+14
4430  BNE Y95
4440  CLC
4450  ADC #$30
4460 Y95 STA LPTS
4470 ;
4480 ;now evaluate blocking penalty
4490 ;
4500  LDX #$00
4510 LOOP72 LDA LV,X
4520  CMP #$04
4530  BCS Y96
4540  STA TEMPR
4550  STX TEMPZ
4560  TXA
4570  ASL A
4580  ASL A
4590  ADC TEMPZ
4600  ADC TEMPR
4610  TAY
4620  INY
4630  LDA LINARR,Y
4640  BEQ Y96
4650  LDA LPTS
4660  SEC
4670  SBC #$20
4680  BCS A91
4690  LDA #$00
4700 A91 STA LPTS
4710 Y96 INX
4720  CPX #$05
4730  BNE LOOP72
4740 ;
4750 ;now evaluate vulnerability to penetrations
4760 ;
4770  LDY #$00
4780 LOOP54 STY OCOLUM
4790  LDX #$00
4800 LOOP73 STX COLUM
4810  CPX OCOLUM
4820  BEQ NXCLM
4830  LDA LV,X
4840  SEC
4850  SBC LV,Y
4860  BEQ NXCLM
4870  BMI NXCLM
4880  TAX
4890  LDA #$01
4900 LOOP74 ASL A
4910  DEX
4920  BNE LOOP74
4930  STA TEMPR
4940  LDA LPTS
4950  SEC
4960  SBC TEMPR
4970  BCS Y32
4980  LDA #$00
4990 Y32 STA LPTS
5000 NXCLM LDX COLUM
5010  INX
5020  CPX #$05
5030  BNE LOOP73
5040  INY
5050  CPY #$05
5060  BNE LOOP54
5070 ;
5080 ;now get overall line value weighted by danger vector
5090 ;
5100  LDX ARMY
5110  LDY SECDIR
5120  BNE Z18
5130  LDA IFRN-55,X
5140  JMP Z20
5150 Z18 CPY #$01
5160  BNE Z19
5170  LDA IFRE-55,X
5180  JMP Z20
5190 Z19 CPY #$02
5200  BNE Z17
5210  LDA IFRS-55,X
5220  JMP Z20
5230 Z17 LDA IFRW-55,X
5240 Z20 STA TEMPR
5250  LDX LPTS
5260  BEQ Z49
5270  LDA ACCLO
5280  CLC
5290 LOOP75 ADC TEMPR
5300  BCC Y34
5310  INC ACCHI
5320  CLC
5330  BNE Y34
5340  LDA #$FF
5350  STA ACCHI
5360 Y34 DEX
5370  BNE LOOP75
5380 ;
5390 ;next secondary direction
5400 ;
5410 Z49 INY
5420  CPY #$04
5430  BEQ Y35
5440  STY SECDIR
5450 ;
5460 ;rotate array
5470 ;
5480  LDX #$18
5490 LOOP70 LDA LINARR,X
5500  STA BAKARR,X
5510  DEX
5520  BPL LOOP70
5530  LDX #$18
5540 LOOP71 LDY ROTARR,X
5550  LDA BAKARR,X
5560  STA LINARR,Y
5570  DEX
5580  BPL LOOP71
5590  JMP Y88
5600 ;
5610 ;
5620 Y35 LDA ACCHI
5630  STA SQVAL
5640 ;
5650 ;get range to closest German into NBVAL
5660 ;
5670 Y65 LDY #$36
5680  LDA #$FF
5690  STA NBVAL
5700 LOOP59 LDA ARRIVE,Y
5710  CMP TURN
5720  BEQ Z45
5730  BCS Y68
5740 Z45 LDA CORPSX,Y
5750  SEC
5760  SBC TARGX
5770  JSR INVERT
5780  STA TEMPR
5790  LDA CORPSY,Y
5800  SEC
5810  SBC TARGY
5820  JSR INVERT
5830  CLC
5840  ADC TEMPR
5850  CMP NBVAL
5860  BCS Y68
5870  STA NBVAL
5880 Y68 DEY
5890  BPL LOOP59
5900 ;
5910 ;now determine whether to use offensive or defensive strategy
5920 ;
5930  LDX ARMY
5940  LDA IFR-55,X
5950  STA TEMPR
5960  LDA #$0F
5970  SEC
5980  SBC TEMPR
5990  BCC A40
6000  ASL A OK, let's fool the routine
6010  STA TEMPR
6020  LDA #$09
6030  SEC
6040  SBC NBVAL I know that NBVAL<9 for all front line units
6050  STA NBVAL
6060 ;
6070 ;now add NBVAL*IFR to SQVAL with defensive bonus
6080 ;
6090 A40 LDY NBVAL
6100  BNE Z24 this square occupied by a German?
6110  STY SQVAL yes, do not enter!!!
6120  JMP EVALSQ
6130 Z24 LDY TRNTYP
6140  LDA DEFNC,Y
6150  CLC
6160  ADC NBVAL
6170  TAY
6180  LDA #$00
6190  CLC
6200 LOOP60 ADC TEMPR
6210  BCC Y69
6220 Z22 LDA #$FF
6230  BMI Y71
6240 Y69 DEY
6250  BNE LOOP60
6260 ;
6270 Y71 CLC
6280  ADC SQVAL
6290  BCC X00
6300  LDA #$FF
6310 X00 STA SQVAL
6320 ;
6330 ;extract penalty if somebody else has dibs on this square
6340 ;
6350  LDY #$9E
6360 LOOP58 LDA OBJX-55,Y
6370  CMP TARGX
6380  BNE Y63
6390  LDA OBJY-55,Y
6400  CMP TARGY
6410  BNE Y63
6420  CPY ARMY
6430  BEQ Y63
6440  LDA ARRIVE,Y
6450  CMP TURN
6460  BEQ Z44
6470  BCS Y63
6480 Z44 LDA SQVAL
6490  SBC #$20
6500  STA SQVAL
6510  JMP EVALSQ
6520 Y63 DEY
6530  CPY #$37
6540  BCS LOOP58
6550 ;
6560 ;now extract distance penalty
6570 ;
6580 Y60 LDA CORPSX,X
6590  SEC
6600  SBC TARGX
6610  JSR INVERT
6620  STA TEMPR
6630  LDA CORPSY,X
6640  SEC
6650  SBC TARGY
6660  JSR INVERT
6670  CLC
6680  ADC TEMPR
6690  CMP #$07
6700  BCC Z48
6710  LDA #$00
6720  STA SQVAL this square is too far away
6730  BEQ EVALSQ
6740 ;
6750 Z48 TAX
6760  LDA #$01
6770 LOOP77 ASL A
6780  DEX
6790  BPL LOOP77
6800  STA TEMPR
6810  LDA SQVAL
6820  SEC
6830  SBC TEMPR
6840  STA SQVAL
6850  BCS EVALSQ
6860  LDA #$00
6870  STA SQVAL
6880 ;
6890 ;now evaluate this square
6900 ;
6910 EVALSQ LDY DIR
6920  LDX ARMY
6930  LDA SQVAL
6940  CMP BVAL
6950  BCC Y72
6960  STA BVAL
6970  STY BONE
6980 Y72 INY
6990  CPY #$04
7000  BEQ Y73
7010  STY DIR
7020  JMP DRLOOP
7030 ;
7040 Y73 LDA OBJX-55,X
7050  LDY BONE
7060  BMI Y74
7070  CLC
7080  ADC XINC,Y
7090 Y74 STA OBJX-55,X
7100  LDA OBJY-55,X
7110  LDY BONE
7120  BMI Y75
7130  CLC
7140  ADC YINC,Y
7150 Y75 STA OBJY-55,X
7160 ;
7170 ;
7180 TOGSCN LDA TRIG0
7190  BEQ A30 ignore game console if red button is down
7200  LDA #$08
7210  STA CONSOL
7220  LDA CONSOL
7230  AND #$01
7240  BEQ WRAPUP
7250 A30 DEX
7260  CPX #$37
7270  BCC Y76
7280  JMP LOOP51
7290 Y76 JMP MLOOP
7300 ;
7310 WRAPUP LDX #$9E
7320 LOOP62 STX ARMY
7330  LDA ARRIVE,X
7340  CMP TURN
7350  BCC Y78
7360  JMP Y77
7370 Y78 LDA OBJX-55,X
7380  LDY #$03
7390  SEC
7400  SBC CORPSX,X
7410  BPL Y79
7420  LDY #$01
7430  JSR INVERT+2
7440 Y79 STY HDIR
7450  STA HRNGE
7460  LDY #$00
7470  LDA OBJY-55,X
7480  SEC
7490  SBC CORPSY,X
7500  BPL Y80
7510  LDY #$02
7520  JSR INVERT+2
7530 Y80 STY VDIR
7540  STA VRNGE
7550  CMP HRNGE
7560  BCC Y81
7570  STA LRNGE
7580  LDA HRNGE
7590  STA SRNGE
7600  LDA HDIR
7610  STA SDIR
7620  STY LDIR
7630  JMP Y82
7640 Y81 STA SRNGE
7650  STY SDIR
7660  LDA HRNGE
7670  STA LRNGE
7680  LDY HDIR
7690  STY LDIR
7700 Y82 LDA #$00
7710  STA RCNT
7720  STA RORD1
7730  STA RORD2
7740  LDA LRNGE
7750  CLC
7760  ADC SRNGE
7770  STA RANGE
7780  BEQ Y86
7790  LDA LRNGE
7800  LSR A
7810  STA CHRIS
7820 ;
7830 LOOP61 LDA CHRIS
7840  CLC
7850  ADC SRNGE
7860  STA CHRIS
7870  SEC
7880  SBC RANGE
7890  BCS OVRFLO
7900  LDA LDIR
7910  BCC STIP
7920 OVRFLO STA CHRIS
7930  LDA SDIR
7940 STIP STA DIR
7950  LDA RCNT
7960  AND #$03
7970  TAY
7980  STA TEMPR
7990  LDA RCNT
8000  LSR A
8010  LSR A
8020  TAX
8030  LDA DIR
8040 Y85 DEY
8050  BMI Y84
8060  ASL A
8070  ASL A
8080  JMP Y85
8090 ;
8100 Y84 LDY TEMPR
8110  EOR RORD1,X
8120  AND MASKO,Y
8130  EOR RORD1,X
8140  STA RORD1,X
8150  LDX RCNT
8160  INX
8170  STX RCNT
8180  CPX #$08
8190  BCS Y86
8200  CPX RANGE
8210  BCC LOOP61
8220 Y86 LDX ARMY
8230  LDA RORD1
8240  STA WHORDS,X
8250  LDA RORD2
8260  STA WHORDH,X
8270  LDA RCNT
8280  STA HMORDS,X
8290 ;
8300 Y77 DEX
8310  CPX #$37
8320  BCC Y87
8330  JMP LOOP62
8340 Y87 RTS
8350 ;
8360 ;Subroutine CALIFR determines individual force ratios
8370 ;in all four directions
8380 ;
8390 CALIFR LDY #$00 initialize vectors
8400  STY IFR0
8410  STY IFR1
8420  STY IFR2
8430  STY IFR3
8440  STY IFRHI
8450  INY
8460  STY RFR
8470  LDA CORPSX,X
8480  STA XLOC
8490  LDA CORPSY,X
8500  STA YLOC
8510  LDY #$9E
8520 LOOP53 LDA ARRIVE,Y
8530  CMP TURN
8540  BCS Z07
8550  LDA CORPSY,Y
8560  SEC
8570  SBC YLOC
8580  STA TEMPY save signed vector
8590  JSR INVERT
8600  STA TEMPR
8610  LDA CORPSX,Y
8620  SEC
8630  SBC XLOC
8640  STA TEMPX
8650  JSR INVERT
8660  CLC
8670  ADC TEMPR
8680 Z21 CMP #$09 no point in checking if he's too far
8690 Z07 BCS Y48
8700  LSR A
8710  STA TEMPR this is half of range to unit
8720 ;
8730 ;now select which IFR gets this German
8740 ;
8750  LDA TEMPX
8760  BPL Z00
8770  LDA TEMPY
8780  BPL Z01
8790  LDX #$02
8800  CMP TEMPX
8810  BCS Z02
8820  LDX #$01
8830  BCC Z02
8840 Z00 LDA TEMPY
8850  BPL Z03
8860  JSR INVERT+2
8870  LDX #$02
8880  CMP TEMPX
8890  BCS Z02
8900  LDX #$03
8910  BCC Z02
8920 Z03 LDX #$00
8930  CMP TEMPX
8940  BCS Z02
8950  LDX #$03
8960  BCC Z02
8970 Z01 LDA TEMPX
8980  JSR INVERT+2
8990  LDX #$01
9000  CMP TEMPY
9010  BCS Z02
9020  LDX #$00
9030 Z02 LDA CSTRNG,Y
9040  LSR A
9050  LSR A
9060  LSR A
9070  LSR A
9080 Z11 CPY #$37
9090  BCC Z12
9100  CLC
9110  ADC RFR
9120  BCC Z13
9130  LDA #$FF
9140 Z13 STA RFR
9150  JMP Y48
9160 Z12 CLC
9170  ADC IFR0,X
9180  BCC Z05
9190  LDA #$FF
9200 Z05 STA IFR0,X
9210 Y48 DEY
9220  BEQ Z06
9230  JMP LOOP53
9240 ;
9250 Z06 LDX #$03
9260  LDA #$00
9270 Y37 CLC
9280  ADC IFR0,X
9290  BCC Y36
9300  LDA #$FF
9310 Y36 DEX
9320  BPL Y37
9330 ;
9340 ;
9350  ASL A
9360  ROL IFRHI
9370  ASL A
9380  ROL IFRHI
9390  ASL A
9400  ROL IFRHI
9410  ASL A
9420  ROL IFRHI
9430  LDX #$00
9440  SEC
9450 Z16 SBC RFR
9460  BCS Z14
9470  DEC IFRHI
9480  SEC
9490  BMI Z15
9500 Z14 INX
9510  JMP Z16
9520 Z15 TXA
9530  LDX ARMY
9540  CLC
9550  ADC OFR remember strategic situation
9560  ROR A average strategic with tactical
9570  STA IFR-55,X
9580 ;
9590 ;keep a record of danger vector
9600 ;
9610  LDA IFR0
9620  STA IFRN-55,X
9630  LDA IFR1
9640  STA IFRE-55,X
9650  LDA IFR2
9660  STA IFRS-55,X
9670  LDA IFR3
9680  STA IFRW-55,X
9690  RTS
9700 ;
9710 INVERT BPL Z46
9720  EOR #$FF
9730  CLC
9740  ADC #$01
9750 Z46 RTS
9760 ;
9770 IFRN *=*+104
9780 IFRE *=*+104
9790 IFRS *=*+104
9800 IFRW *=*+104
9810  .END
