-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSHIPMV.MAC
422 lines (366 loc) · 12.1 KB
/
SHIPMV.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
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
; SHIPmv.MAC 12-May-83
; Globals defined:
.globl TROOif,SHIPif,CARRif,SHIPco,PORT
.globl AB,TYP,IFO,ILA,SURSEA,EXPLOR,RANDIR,ENEATT,AROUND,OPT,MAPN
.globl MAPNUM,CITMAX,RANDOM,TARGET,CITLOC,LOC,DIST,PATHn,UNIMAX
.globl UNILOC,UNIT2,CHKOWN,UNIILA,EDGER,CITPHS,CITOWN,ABD,ARROW
.globl EXPSHP,TYPE,PLYNUM,TROOPT,UNITOP,LTR,OWN,FNDUNI
;;;;;;;;;;;;;;;;;;;;;;;;;;;
; TROOif
; Purpose: Find new ifo and ila for a T.
; Use:
; call TROOif
;
; R0,R1,R2,R4 destroyed.
;
TROOif: tstb ABD(R5) ;any armies aboard?
bne armabd ;yes
call ARMCIT ;look for army producing city
bcs ret ;got one
call RANDIR ;random direction
movb #14,IFO(R5) ;set ifo
mov R2,ILA(R5) ;set ila
ret: rts PC
armabd: mov #2,R0
call RANDOM
beq 1$
call TROTAR ;target city?
bcs ret ;yes
call EXPSHP ;explore?
bcc 2$ ;no
3$: movb #13,IFO(R5)
mov R0,ILA(R5)
rts PC
2$: ifb IFO(R5) eq #3, ret ;if already 3
call RANDIR ;random direction
movb #3,IFO(R5)
mov R2,ILA(R5)
rts PC
1$: call EXPSHP ;explore?
bcs 3$ ;yes
call TROTAR ;target city?
bcs ret ;yes
br 2$
.page
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; SHIPif
; Purpose: Select ifo & ila for D,S,R,B
; Use:
; call SHIPif
;
; R0,R1,R2,R4 destroyed
;
SHIPif: call SHIPTR ;look for enemy ships to attack
bcs ret3 ;got one
movb #2,R0
call RANDOM
beq L50 ;50% chance
;sh2 is also entry point from CARRif
sh2: call SHIPTA ;look for target city
bcs ret3 ;yes
br L2
L50: call SHIPTT ;escort TT?
bcs ret3 ;yes
L2: call EXPSHP ;look for places to explore
bcc 3$ ;no
movb #13,IFO(R5)
mov R0,ILA(R5) ;set ifo,ila
rts PC
3$: ifb IFO(R5) eq #3, ret3 ;if already in RANDIR
call RANDIR ;pick random direction
movb #3,IFO(R5)
mov R0,ILA(R5) ;set ifo,ila
ret3: rts PC
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; CARRif
; Purpose: Same as TROOif, but for carriers.
; Use:
; call CARRif
;
; R0,R1,R2,R4 destroyed
;
CARRif: call SHIPTR ;look for enemy ships
bcc sh2 ;goto SHIPif
movb #10,IFO(R5) ;station loc
rts PC
.page
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; SHIPco
; Purpose: For a ship, given a move in R2, correct the move and return it
; in R2.
; Use:
; mov direction,R2
; call SHIPco
;
; R0,R1,R4 destroyed
;
SHIPco: call LODARM ;load up armies?
bcs ret ;yes
cmpb #14,IFO(R5) ;looking for armies?
beq 1$ ;yes, don't go exploring & don't stay put
cmp #-1,R2 ;stay put?
beq ret ;yes, no correction
call EXPLOR ;territory to explore?
bcs ret ;yes
1$: movb TYPE(R5),R1 ;get unit type
movb attmsk-2(R1),2$ ;mask of things to attack
movb escmsk-2(R1),3$ ;mask of things to escape from
jsr R4,ENEATT ;anything to attack?
2$: .blkb 2
bcs ret ;yes
jsr R4,ENEATT ;anything to escape from?
3$: .blkb 2
bcc 4$ ;no
mov #3,R0
call RANDOM
add #3,R0
add R0,R2 ;move in opposite direction
bic #^O177770,R2 ;normalize
4$: jmp AROUND
; AFDTSRCB
attmsk: .byte ^B01111000 ;D
.byte ^B00000000 ;T
.byte ^B00111111 ;S
.byte ^B01111111 ;R
.byte ^B00110010 ;C
.byte ^B01111111 ;B
escmsk: .byte ^B10000111 ;D
.byte ^B11101111 ;T
.byte ^B11000000 ;S
.byte ^B00000000 ;R
.byte ^B10001101 ;C
.byte ^B00000000 ;B
.page
;;;;;;;;;;;;;;;;;;;;;;;;;;;
; PORT,ARMCIT,TROTAR,SHIPTA
; Purpose: Look for city for a ship to go to under various conditions.
; Set C, IFO, and ILA if successful.
; MAPNUM must be set, and OPT=0.
;
; PORT Look for a port city to make repairs.
; ARMCIT Look for an army producing city.
; TROTAR Look for city target for T.
; SHIPTA Look for city target for ships.
;
; Use:
; movb MAPN(R5),MAPNUM
; clrb OPT
; call subr
;
; R0,R2,R4 destroyed.
;
switch: .blkb 1 ;which subroutine is calling
ifo2: .blkb 1 ;what ifo to set things to
PORT: clrb switch
movb #8,ifo2
br start
ARMCIT: movb #1,switch
movb #14,ifo2
br start
TROTAR: movb #2,switch
movb #11,ifo2
br start
SHIPTA: movb #3,switch
movb #11,ifo2 ;note: same as for TROTAR
start: push R1
push R3
push #1000 ;arbitrary # larger than any distance
mov #CITMAX-1,R3 ;city #
loop1: cmpb #1,switch ;PORT or ARMCIT?
bcs 1$ ;no
cmpb CITOWN(R3),PLYNUM(R5) ;owned city?
bne eol1 ;no
tstb switch ;ARMCIT?
beq 2$ ;no
cmpb #A,CITPHS(R3) ;army producing city?
bne eol1 ;no
br 2$
1$: mov R3,R1
add R5,R1 ;player index
tstb TARGET(R1) ;is city a target?
beq eol1 ;no
ifb #3 ne switch, 2$ ;if not SHIPTA
tstb CITOWN(R3) ;enemy city?
beq eol1 ;no, merely unowned
2$: mov R3,R1
asl R1
mov CITLOC(R1),R1 ;get loc of city
beq eol1 ;doesn't exist
mov LOC(R5),R0 ;get loc of unit
call DIST ;R0=DIST(LOC,CITLOC)
cmp R0,(SP) ;is dist < previous dist?
bcc eol1 ;no
mov R0,R4 ;save dist
mov R1,R0 ;loc of city
call EDGER ;port city?
beq eol1 ;no
mov LOC(R5),R0 ;get loc of unit
jsr R5,PATHn
; *.+OXAFFDTSRCBa ffdtsrcb
.word ^B1010110011111110,^B0111111100000000,1
bcs eol1 ;no path
mov R1,ILA(R5) ;set ILA
movb ifo2,IFO(R5) ;set IFO
mov R4,(SP) ;set new min distance
eol1: dec R3
bpl loop1
cmp #1000,(SP)+ ;find anything?
clc
beq 1$ ;no, C=0
sec ;yes
1$: pop R3
pop R1
rts PC
.page
;;;;;;;;;;;;;;;;;;;;;;;;;;;
; SHIPTT
; Purpose: Search for a TT to escort. If found, set C, IFO and ILA.
; Use:
; movb MAPN(R5),MAPNUM
; clrb OPT
; call SHIPTT
;
; R0,R1,R2,R4 destroyed
;
SHIPTT: push R3
mov UNITOP,R0 ;# of units
call RANDOM
push R0 ;end #
mov R0,R3 ;R3=unit #
asl R0
add #UNILOC+2,R0
mov R0,R4 ;R4= UNILOC pointer
loop2: mov -(R4),R1 ;get unit loc
beq eol2 ;doesn't exist
movb UNIT2(R3),R0
bic #^O177770,R0 ;get unit type
cmpb #T,R0 ;is it a T?
bne eol2 ;no
call CHKOWN ;do we own it?
bcs eol2 ;no
mov LOC(R5),R0 ;loc of unit
jsr R5,PATHn
; *.+OXAFFDTSRCBa ffdtsrcb
.word ^B1010110011111110,^B0111111100000000,1
bcs eol2 ;no path
movb #12,IFO(R5) ;set ifo
mov R3,ILA(R5) ;ila=TT#
sec
done2: pop R3 ;trash end
pop R3
rts PC
eol2: dec R3
bpl 1$
mov #UNIMAX-1,R3 ;wrap around
mov #UNILOC+<UNIMAX*2>,R4 ;ditto
1$: cmp R3,(SP) ;done?
bne loop2 ;no
clc
br done2
.page
;;;;;;;;;;;;;;;;;;;;;;;;;
; SHIPTR
; Purpose: For ships, look thru TROOPT for the closest one to attack. If one
; is found, set C, IFO, ILA.
; Use:
; set MAPNUM,OPT
; call SHIPTR
;
; R0,R1,R2,R4 destroyed
;
;Here are bitmaps for each ship to indicate what rows in TROOPT to look at.
; DTSRCB--
nshprf: .byte ^B11100000 ;D
.byte ^B01000000 ;T
.byte ^B11100000 ;S
.byte ^B11111000 ;R
.byte ^B11101000 ;C
.byte ^B11111100 ;B attack everything!
SHIPTR: push R3
push #1000 ;number larger than max distance
mov #TROOPT,R4
add R5,R4 ;pointer to TROOPT
movb TYPE(R5),R3 ;get unit type
movb nshprf-2(R3),R3 ;get mask (no As or Fs)
movb #6,R1 ;6 rows
loopo: aslb R3 ;check bit 7
bcs 1$ ;look at this row
add #5*2,R4 ;next row
br eolo
1$: push R1
movb #5,R2 ;5 entries in row
mov LOC(R5),R1 ;get loc of unit
loopi: mov (R4)+,R0 ;get loc of target
beq eoli ;no entry
call DIST ;find dist to target
cmp R0,(SP) ;is it < min dist?
bcc eoli ;no
mov R0,(SP) ;set new min dist
movb #5,IFO(R5) ;set ifo
mov -2(R4),ILA(R5) ;set ila
eoli: sob R2,loopi
pop R1
eolo: sob R1,loopo
cmp #1000,(SP)+ ;find anything?
clc
beq 1$ ;no
sec
1$: pop R3
rts PC
.page
;;;;;;;;;;;;;;;;;;;;;;;;;;;
; If ship is a T with IFO=14 (loading armies), and there is an
; army in LTR, stay put so the army can get aboard.
;
; Returns:
; C=0: R2 preserved.
; C=1: R2=-1, i.e. stay put.
; R0,R1,R4 destroyed.
;
LODARM: ifb #14 ne IFO(R5), 1$ ;only Ts can have ifo=14
movb AB(R5),R1 ;get map val
ifb #-2 eq TYP(R1), 1$ ;if in city, don't stay put
movb #8,R4 ;8 directions
mov #LTR+8,R0 ;step backwards
add R5,R0 ;R0 points to LTR
2$: movb -(R0),R1 ;get unit
tstb TYP(R1) ;is it an army?
bne 3$ ;no
ifb OWN(R1) ne PLYNUM(R5), 3$ ;we don't own it
push R3
push R2
mov R4,R2
dec R2 ;convert R2 to direction
push R0
mov LOC(R5),R0 ;get loc of unit
call ARROW ;get loc of army
call FNDUNI ;get # of army
mov R3,R1 ;R1=army #
pop R0
pop R2
pop R3
ifb #<1*8>+A ne UNIT2(R1), 3$ ;if not IFO=1 for army
mov #-1,R2 ;don't move
sec
rts PC
3$: sob R4,2$
1$: clc
rts PC
push R3
push R2
mov R4,R2
dec R2 ;convert R2 to direction
push R0
mov LOC(R5),R0 ;get loc of unit
call ARROW ;get loc of army
call FNDUNI ;get # of army
mov R3,R1 ;R1=army #
pop R0 ;restore R0
pop R2
pop R3
cmpb #<1*8>+A,UNIT2(R1) ;IFO=1 for army?
mov #-1,R2 ;don't move
sec
rts PC
.end
.