-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathARMYMV.MAC
206 lines (171 loc) · 5.93 KB
/
ARMYMV.MAC
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
; ARMYmv.MAC 16-Nov-82
; Globals defined: ARMYif,ARMYco
.globl AB,TYP,IFO,ILA,SURSEA,EXPLOR,RANDIR,ENEATT,AROUND,OPT,MAPN
.globl MAPNUM,CITMAX,RANDOM,TARGET,CITLOC,LOC,DIST,PATH,LOCI
.globl CHKOWN,CITLTR,PATBLK,ROUND,LOCMAX
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ARMYif
; Purpose: Select a new ifo and ila for an army.
; Use:
; call ARMYif
;
; R0,R1,R2,R4 destroyed
;
ARMYif::
movb AB(R5),R1
ifb #T ne TYP(R1) notabd ;if not aboard a T
movb #17,IFO(R5) ;set ifo to indicate we're aboard
call SURSEA ;surrounded by sea?
bcs ret ;yes
call ARMTAR ;cities to attack?
bcs ret ;yes
clr R2 ;for EXPLOR
call EXPLOR ;territory to explore?
bcc ret ;no
set16: movb #16,IFO(R5) ;follow shore
mov R2,ILA(R5) ;set direction
ret: rts PC
notabd: mov ROUND(R5),R0
xor R3,R0 ;get arbitrary but predictable #
bit #1,R0
bne 1$ ;don't call ARMTAR every time
call ARMTAR ;cities to attack?
bcs ret ;yes
1$: call ARMLOC ;LOCI to attack?
bcs ret ;yes
call ARMTT ;TTs to get aboard?
bcs ret ;yes
ifb #16 eq IFO(R5), ret ;if already following shore
call RANDIR ;select random direction
br set16
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ARMYco
; Purpose: Given trial move in R2, correct that move.
; Use:
; mov trialmove,R2
; call ARMYco
;
; R0,R1,R4 destroyed, R2 returns with proper move.
;
ARMYco::
call CITLTR ;unowned cities?
bcs ret ;yes
call EXPLOR ;anything to explore?
bcs ret ;yes
movb AB(R5),R1
ifb TYP(R1) ne #T, 1$ ;if not aboard a T
jsr R4,ENEATT ;enemies to attack?
.byte ^B11000000,0 ;attack As and Fs
bcs ret ;yes
br 2$
1$: jsr R4,ENEATT
.byte ^B11111000,0 ;attack AFDTS
bcs ret
2$: tst R2 ;stay put?
bmi ret ;yes
jmp AROUND ;turn around till okmove is found
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ARMTAR
; Purpose: Search for a target city for the army to attack. If found, C=1
; and IFO and ILA are set.
; Use:
; call ARMTAR
;
; R0,R1,R2,R4 destroyed
;
ARMTAR: mov #CITMAX,R0 ;max # of cities
call RANDOM ;select random city
push R0 ;terminating #
mov #TARGET,R4
add R5,R4 ;pointer into TARGET
mov R0,R2 ;R2=city #
loop1: mov R2,R0
add R4,R0 ;R0=pointer into TARGET
tstb (R0) ;is it a target?
beq eol1 ;no
mov R2,R1
asl R1
mov CITLOC(R1),R1 ;R1=loc of city
mov LOC(R5),R0 ;loc of unit
call DIST ;find distance between
if R0 hi #12, eol1 ;if dist>12
mov LOC(R5),R0 ;loc of unit
call PATBLK ;path to city?
bcs eol1 ;no
movb #15,IFO(R5) ;set ifo
mov R1,ILA(R5) ;set ila
tst (SP)+ ;pop loop end
sec
rts PC
eol1: inc R2 ;next city
if R2 ne #CITMAX, 1$ ;if no wrap around
clr R2 ;reset index
1$: if R2 ne (SP), loop1 ;if not done
tst (SP)+
clc
rts PC
;;;;;;;;;;;;;;;;;;;;;;;;;
; Find a target in LOCI. If found, C=1 and IFO, ILA are set.
; R0,R1,R2,R4 destroyed
;
ARMLOC: mov #LOCMAX,R4 ;# of elements in LOCI
mov #LOCI,R2
add R5,R2 ;R2=pointer to LOCI
loop2: mov (R2)+,R1 ;get loc from LOCI
beq eol2 ;no loc
mov LOC(R5),R0 ;get loc of unit
call DIST ;find dist to loci
if R0 hi #12, eol2 ;if dist > 12
mov LOC(R5),R0
call PATBLK ;path to LOCI?
bcs eol2 ;no
movb #5,IFO(R5) ;set ifo
mov R1,ILA(R5) ;set ila
sec
rts PC
eol2: sob R4,loop2
clc
rts PC
;;;;;;;;;;;;;;;;;;;;;;;;;;
; ARMTT
; Purpose: Search for a T for the army to get on. If found, set C and ifo,
; ila of army, and set ila of T such that the T will head towards
; the army.
; Use:
; call ARMTT
;
; R0,R1,R2,R4 destroyed
;
ARMTT: push R3
mov UNITOP,R0 ;max # of units
call RANDOM
push R0 ;terminating #
mov R0,R3 ;R3=unit #
loop3: mov R3,R2
asl R2
mov UNILOC(R2),R0 ;get loc of unit
beq eol3 ;unit doesn't exist
ifb UNIT2(R3) ne #<14*8>+T, eol3 ;if not T with ifo=14
call CHKOWN ;is it our unit?
bcs eol3 ;no
mov LOC(R5),R1 ;get loc of A
call DIST ;find dist to T
if R0 hi #10, eol3 ;if dist > 10
movb #1,IFO(R5) ;set ifo
mov R3,ILA(R5) ;set ila to TT #
mov R1,UNIILA(R2) ;set ila of T to LOC
tst (SP)+
pop R3
sec
rts PC
eol3: inc R3 ;next unit
if R3 ne UNITOP, 1$ ;if no overflow
clr R3 ;yes
1$: cmp R3,(SP) ;done?
bne loop3 ;no
tst (SP)+
pop R3
clc
rts PC
.end
.