forked from mist64/cbmsrc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lookup.src
403 lines (366 loc) · 10.3 KB
/
lookup.src
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
.page 'lookup-optsch'
;optsch optimal search for lookup
; and fndfil
optsch lda #0 ; determine optimal search
sta temp ; init drive mask
sta drvflg
pha
ldx f2cnt
os10 pla
ora temp
pha
lda #1
sta temp
dex
bmi os30
lda fildrv,x
bpl os15
asl temp
asl temp
os15 lsr a
bcc os10
asl temp
bne os10 ; (branch)
os30 pla
tax
lda schtbl-1,x
pha
and #3
sta drvcnt
pla
asl a
bpl os40
lda fildrv
os35 and #1
sta drvnum
;
lda drvcnt
beq os60 ; only one drive addressed
;
jsr autoi ; check drive for autoinit
beq os50 ; drive is active
;
jsr togdrv
lda #0 ; set 1 drive addressed
sta drvcnt
jsr autoi ; check drive for autoinit
beq os70 ; drive is active
os45
lda #nodriv
jsr cmderr
os50
jsr togdrv
jsr autoi ; check drive for autoinit
php
jsr togdrv
plp
beq os70 ; drive is active
;
lda #0 ; set 1 drive addressed
sta drvcnt
beq os70 ; bra
os60
jsr autoi ; check drive for autoinit
bne os45 ; drive is not active
os70
jmp setlds
os40 rol a
jmp os35
schtbl .byte 0,$80,$41
.byte 1,1,1,1
.byte $81,$81,$81,$81
.byte $42,$42,$42,$42
.page 'lookup/fndfil'
; look up all files in stream
; and fill tables w/ info
lookup jsr optsch
lk05 lda #0
sta delind
jsr srchst ; start search
bne lk25
lk10 dec drvcnt
bpl lk15
rts ; no more drive searches
lk15 lda #1 ; toggle drive #
sta drvflg
jsr togdrv
jsr setlds ; turn on led
jmp lk05
lk20 jsr search ; find valid fn
beq lk30 ; end of search
lk25 jsr compar ; compare dir w/ table
lda found ; found flag
beq lk26 ; all fn's not found, yet
rts
lk26 lda entfnd
bmi lk20
bpl lk25
lk30 lda found
beq lk10
rts
; find next file name matching
; any file in stream & return
; with entry found stuffed into
; tables
ffre jsr srre ; find file re-entry
beq ff10
bne ff25
ff15 lda #1
sta drvflg
jsr togdrv
jsr setlds
ffst lda #0 ; find file start entry
sta delind
jsr srchst
bne ff25
sta found
ff10 lda found
bne ff40
dec drvcnt
bpl ff15
rts
fndfil jsr search ; find file continuous...
beq ff10 ; ... re-entry, no channel activity
ff25 jsr compar ; compare file names
ldx entfnd
bpl ff30
lda found
beq fndfil
bne ff40
ff30 lda typflg
beq ff40 ; no type restriction
lda pattyp,x
and #typmsk
cmp typflg
bne fndfil
ff40 rts
.page 'lookup-compar'
;compare all filenames in stream table
; with each valid entry in the
; directory. matches are tabulated
compar ldx #$ff
stx entfnd
inx
stx patflg
jsr cmpchk
beq cp10
cp02 rts ; all are found
cp05 jsr cc10
bne cp02
cp10 lda drvnum
eor fildrv,x
lsr a
bcc cp20 ; right drive
and #$40
beq cp05 ; no default
lda #2
cmp drvcnt
beq cp05 ; don't use default
cp20 lda filtbl,x ; good drive match
tax
jsr fndlmt
ldy #3
jmp cp33
cp30
lda cmdbuf,x
cmp (dirbuf),y
beq cp32 ; chars are =
;
cmp #'?
bne cp05 ; no single pattern
lda (dirbuf),y
cmp #$a0
beq cp05 ; end of filename
cp32
inx
iny
cp33
cpx limit
bcs cp34 ; end of pattern
;
lda cmdbuf,x
cmp #'*
beq cp40 ; star matches all
bne cp30 ; keep checking
cp34
cpy #19
bcs cp40 ; end of filename
;
lda (dirbuf),y
cmp #$a0
bne cp05
cp40 ldx f2ptr ; filenames match
stx entfnd
lda pattyp,x ; store info in tables
and #$80
sta patflg
lda index
sta entind,x
lda sector
sta entsec,x
ldy #0
lda (dirbuf),y
iny
pha
and #$40
sta temp
pla
and #$ff-$20
bmi cp42
;
ora #$20
cp42
and #$27
ora temp
sta temp
lda #$80
and pattyp,x
ora temp
sta pattyp,x
lda fildrv,x
and #$80
ora drvnum
sta fildrv,x
;
lda (dirbuf),y
sta filtrk,x
iny
lda (dirbuf),y
sta filsec,x
lda rec
bne cp50
ldy #21
lda (dirbuf),y
sta rec
cp50
;jmp cmpchk
;rts
;check table for unfound files
cmpchk lda #$ff
sta found
lda f2cnt
sta f2ptr
cc10 dec f2ptr
bpl cc15
rts ; table exhausted
cc15 ldx f2ptr
lda pattyp,x
bmi cc20
lda filtrk,x
bne cc10
cc20 lda #0
sta found
rts
.page 'lookup-search'
;search directory
; returns with valid entry w/ delind=0
; or returns w/ 1st deleted entry
; w/ delind=1
;
; srchst will initiate a search
; search will continue a search
srchst
ldy #0 ; init deleted sector
sty delsec
dey
sty entfnd
lda dirtrk ; start search at beginning
sta track
lda #1
sta sector
sta lstbuf
jsr opnird ; open internal read chnl
sr10 lda lstbuf ; last buffer if 0
bne sr15
rts ; (z=1)
sr15 lda #7
sta filcnt
lda #0 ; read track #
jsr drdbyt
sta lstbuf ; update end flag
sr20 jsr getpnt
dec filcnt
ldy #0
lda (dirbuf),y ; read file type
bne sr30
lda delsec ; deleted entry found
bne search ; deleted entry already found
jsr curblk ; get current sector
lda sector
sta delsec
lda dirbuf ; get current index
ldx delind ; bit1: want deleted entry
sta delind
beq search ; need valid entry
rts ; (z=0)
sr30 ldx #1
cpx delind ; ?looking for deleted?
bne sr50 ; no!
beq search
srre lda dirtrk
sta track
lda dirsec
sta sector
jsr opnird
lda index
jsr setpnt
search lda #$ff
sta entfnd
lda filcnt ; adjust file count
bmi sr40
lda #32 ; incr by 32
jsr incptr
jmp sr20
sr40 jsr nxtbuf ; new buffer
jmp sr10 ; (branch)
sr50 lda dirbuf ; found valid entry
sta index ; save index
jsr curblk ; get sector
lda sector
sta dirsec
rts ; (z=0)
autoi
; check drive for active diskette
; init if needed
; return nodrv status
;
lda autofg
bne auto2 ; auto-init is disabled
;
ldx drvnum
lsr wpsw,x ; test & clear wpsw
bcc auto2 ; no change in diskette
;
lda #$ff
sta jobrtn ; set error return code
jsr itrial ; init-seek test
ldy #$ff ; .y= true
cmp #2
beq auto1 ; no sync= no diskette
;
cmp #3
beq auto1 ; no header= no directory
;
cmp #$f
beq auto1 ; no drive!!!!
;
ldy #0 ; set .y false
auto1
ldx drvnum
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
jmp ptch20 ; *rom ds 09/03/85* *GCB 11/20/86 SAVE @ fix*
; tya
; sta nodrv,x ; set condn of no-drive
rtch20
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
bne auto2 ; no need to init crud!
;
jsr initdr ; init that drive
auto2
ldx drvnum
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
jmp ptch17 ; *rom ds 09/03/85* *GCB 11/20/86 SAVE @ fix*
; lda nodrv,x ; return no-drive condn
; rts
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
; .end