-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMAPGEN.MAC
343 lines (290 loc) · 9.81 KB
/
MAPGEN.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
; MAPGEN.MAC 23-Jun-82
; Purpose: Create a map.
.globl CURMES,LOCPRT,PATH,ARROW,FNDMAP,OPT,SEAHI,SEALO
.globl CMDCUR,TTclr,CURSOR,CURx,CURy,INSECT,TTcurs,BORDER
.globl MAPS,MAPNUM,MAPTAB,SECTOR,PCUR2,MAPPRT,LSTBAS
.globl MAP,CHAMAP,BELL,CRLF,TTout,DECIN,DECPRT,INLMES,CENTER
.mcall .regdef,.csigen,.readw,.ttyout,.writw,.exit,.close,.wait
.mcall .ttyin
.regdef
.radix 10
.macro push arg
mov arg,-(SP)
.endm
.macro pop arg
mov (SP)+,arg
.endm
CR = 13 ;carriage return
LF = 10 ;line feed
TAB = 9 ;horizontal tab
ESC = 27 ;escape
FF = 12 ;form feed
SPACE = 32
BCKSPC = 8 ;backspace
errwrd = ^O52 ;error word address
jsw = ^O44 ;job status word
loc: .word 0 ;map location
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; MAPGEN main program
MAPGEN:
mov #59*256,BORDER+12
mov #99*256,BORDER+22 ;border is now off the edge
jsr PC,setup ;get command string, open files
clr loc ;start with location 0
clrb MAPNUM ;work with map 0
.wait #3 ;see if we have an input file
bcs inimap ;nope, init map
jsr PC,INMAP ;input map
br mapset ;map is set up
inimap: mov #MAPS+4000,R1 ;# of bytes in a map
mov #^B100001000010,R0 ;3 dots
1$: mov R0,-(R1) ;init map
cmp R1,#MAPS
bne 1$
mapset: jsr PC,TTclr ;clear screen, reset CURSOR
mov #30*256+50,R0 ;screen center
jsr PC,CENTER ;type sector
mov R0,loc ;remember new loc
bis #^O10000,@#jsw ;special tty input mode
br cmdscn ;goto command scanner
;;;;;;;;;;;;;;;;;;;;;;;;;;;
; CMDSCN
; Purpose: Get and process commands
.macro Y ;table generator
x '+,MAPMOD
x '.,MAPMOD
x '*,MAPMOD
x 'F,FROM
x 'T,TO
x 'N,VERIFY
x 'L,LSTMOD
x SPACE,MAPMOD
x 'V,OUTMAP
.endm
.macro x A,B
.byte A
.endm
CMDTAB: Y ;command table
Ntab= .-CMDTAB ;# of entries
.even
.macro x A,B
.word B
.endm
SUBTAB: Y ;processing routines
CMDSCN: .ttyin ;get command
mov R0,R1
mov loc,R0 ;args for CMDCUR
jsr PC,CMDCUR ;do cursor movement
bcc notcur ;not cursor command
cmp loc,R0 ;see if we moved cursor
beq cmderr ;no
mov R0,loc ;store new loc
br cmdscn ;next command
cmderr: jsr PC,BELL ;get mad
br cmdscn
notcur: mov #Ntab,R0 ;# entries
1$: cmpb CMDTAB-1(R0),R1 ;is R1 in CMDTAB?
beq gotcmd ;yes
sob R0,1$ ;loop
br cmderr ;illegal command
gotcmd: asl R0 ;convert to index into SUBTAB
jsr PC,@SUBTAB-2(R0) ;call processing routine
br cmdscn
;;;;;;;;;;;;;
;
LSTMOD:
mov #-1,LSTBAS ;new screen
jmp TTclr ;clear screen
;;;;;;;;;;;;;;;;;;;;;;;;;;
; VERIFY
; Purpose: Center screen about loc.
; Use:
; call VERIFY
;
; Registers: R0 destroyed
;
VERIFY: mov loc,R0
jmp CENTER
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; FROM
; Purpose: Mark spot where we're coming from.
; Use:
; jsr PC,FROM
;
; Registers: R0 destroyed
FROM: mov #'F,R0
jsr PC,TTout
jsr R1,CURMES
.byte 0,40
.asciz /From:/
.even
mov LOC,R0 ;get loc
mov LOC,savbeg ;save for TO
jsr PC,LOCPRT ;type it
jsr PC,pcur2-4 ;put cursor back
rts PC
savbeg: .blkw 1
;------------------------------
; TO
; Purpose: Calculate a path from savbeg to LOC.
; Use:
; jsr PC,TO
;
; Registers: R0-R4 destroyed
TO: mov #'T,R0
jsr PC,TTout
jsr R1,CURMES
.byte 1,40
.asciz /To: /
.even
mov LOC,R0 ;get location
jsr PC,LOCPRT ;print it
mov R0,R1 ;set up end
mov savbeg,R0 ;set up beg
movb #-1,OPT ;optimize path
2$: jsr R5,PATH ;find a path
.word SEAHI,SEALO ;sea
.word 1 ;move dir
bcs 1$ ;failure
jsr PC,ARROW ;move to new spot
jsr PC,pcur2-4
push R0 ;save new spot
mov #'G,R0
jsr PC,TTout
pop R0
cmp R0,LOC ;see if we've arrived
bne 2$
1$: rts PC
;;;;;;;;;;;;;;;;;;;;;;;
; MAPMOD
; Purpose: Modify the map loc to agree with the char typed.
; Use:
; mov char,R1 ;character typed
; mov val,loc ;map location
; jsr PC,MAPMOD
; Results: loc is incremented (column), R0,R1,R3 destroyed.
MAPMOD: mov R1,R0 ;command
jsr PC,FNDMAP ;find map code in R1
bcs error ;not in MAPTAB!
mov loc,R0 ;location to change
jsr PC,CHAMAP ;change map
push R0 ;save loc
movb MAPTAB(R1),R0 ;get map char
jsr PC,TTout ;print contents of map on screen
pop R0 ;restore loc
inc R0 ;next column
jsr R5,INSECT ;in sector?
.word 2 ;border of 2
bcc 1$ ;yes
movb #BCKSPC,R0
.TTYOUT ;backup cursor
dec CURx ;reflect this
rts PC ;no change in loc
1$: inc loc ;next column
rts PC
error: jsr R1,INLMES
.asciz /Error MAPMOD/
.even
jsr PC,CRLF
rts PC
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; SETUP
; Purpose: Get command string from terminal. Open input and output files.
; Set up stuff so nxtchr will work properly.
; Use:
; jsr PC,setup
;
; Registers: preserved
setup: push R0
.csigen #dspace,#dext ;get string from terminal
tst (SP)+ ;pop junk off stack
mov R0,buff ;R0 has first free location
mov R0,bufpnt ;pointer to start of buffer
clr bcount ;# of bytes left in buffer
pop R0
rts PC
;;;;;;;;;;;;;;;;;;;;;;;
; INMAP
; Purpose: Read in map 0 from channel 3
; Use:
; jsr PC,INMAP
; R0,R1,R2,R5 destroyed.
INMAP: mov #MAPS,R1 ;map data
clr inblk ;input block number
mov #list,R5 ;EMT argument list
read: .readw R5,#3,buff,#256,inblk ;read channel 3
bcc noerr ;if no error
tstb @#errwrd ;what kind of error?
beq eof ;eof error
jsr R1,INLMES
.ascii /Input Error/
.byte CR,LF,0
.even
.exit
eof: jsr R1,INLMES
.ascii /EOF/
.byte CR,LF,0
.even
.exit
noerr: mov buff,R2 ;buffer pointer
1$: mov (R2)+,(R1)+ ;move from buffer to map
cmp #MAPS+4000,R1 ;see if done
beq done ;yes
sob R0,1$ ;buffer word count
inc inblk ;next block
br read ;read next block
done: rts PC
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; OUTMAP
; Purpose: Output the 2000 word packed map to the output file.
; Use:
; jsr PC,outmap
;
; Registers: R0,R1,R2,R3,R4,R5 destroyed
;
T1: dec R3 ;buffer word count
beq T3 ;until buffer is full
clr (R4)+ ;pack with 0
br T1
outmap: clr outblk ;output block number
mov #MAPS,R1 ;addr of packed map
mov #2000,R2 ;number of words in map
T4: mov #256,R3 ;# of words in buffer
mov buff,R4 ;buffer pointer
T2: mov (R1)+,(R4)+ ;transfer word from map to buffer
dec R2 ;word count
beq T1 ;if no words in map left
sob R3,T2 ;loop till buffer is full
T3: mov #list,R5 ;EMT argument list
.writw R5,#0,buff,#256,outblk ;write to channel 0
bcc nerr ;no error
jsr R1,TTcurs
.byte 23,0
jsr R1,INLMES
.byte CR,LF
.ascii /Output Error/
.byte CR,LF,0
.even
.exit
nerr: inc outblk ;next output block
tst R2 ;see if we're done
bne T4 ;nope
.close #0
jsr R1,TTcurs
.byte 23,0
jsr PC,CRLF
.exit
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; data
dext: .rad50 "MAP" ;input files
.rad50 "MAP" ;output file
.word 0,0 ;not needed
bcount: .word 0 ;byte count
buff: .word 0 ;I/O buffer start
bufpnt: .word 0 ;I/O buffer pointer
inblk: .word 0 ;relative block to read
outblk: .word 0 ;relative block to write
list: .blkw 5 ;EMT argument list
dspace: .blkw 2000 ;handler space
.end MAPGEN
.