-
Notifications
You must be signed in to change notification settings - Fork 84
/
tst2.src
533 lines (438 loc) · 7.34 KB
/
tst2.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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
.page
.subttl tst2
;*******************************
;************ l r u i n t ****
;*******************************
;
; initialize the lru tabel
;
;*******************************
lruint ldx #0
lruilp txa
sta lrutbl,x
inx
cpx #cmdchn
bne lruilp
lda #blindx
sta lrutbl,x
rts
;*******************************
;************* l r u u p d ***
;*******************************
;
; least recently used table update
;
; input parameters:
; lindx - current channel
;
; output parameters:
; lrutbl - updated
;
;*******************************
lruupd ldy #cmdchn
ldx lindx
lrulp1 lda lrutbl,y
stx lrutbl,y
cmp lindx
beq lruext
dey
bmi lruint
tax
jmp lrulp1
lruext rts
;*******************************
;************* d b l b u f ***
;*******************************
;
; double buffer
; rtn to switch the active and inactive buffers
;
;*******************************
dblbuf jsr lruupd
jsr getina
bne dbl15
jsr setdrn
jsr getbuf
bmi dbl30 ;no buffers
jsr putina ;store inactive buff #
lda track
pha
lda sector
pha
lda #1
jsr drdbyt
sta sector
lda #0
jsr drdbyt
sta track
beq dbl10
jsr typfil
beq dbl05 ;it's rel
jsr tstwrt
bne dbl05 ;read ahead
jsr tglbuf ;just switch on write
jmp dbl08
dbl05 jsr tglbuf
jsr rdab
dbl08 pla
sta sector
pla
sta track
jmp dbl20
dbl10 pla
sta sector
pla
sta track
dbl15 jsr tglbuf
dbl20 jsr getact
tax
jmp watjob
;there are no buffers to steal
dbl30 lda #nochnl
jmp cmderr
;********************************
dbset jsr lruupd
jsr getina
bne dbs10
jsr getbuf
bmi dbl30 ;no buffers
jsr putina ;store inactive buff #
dbs10 rts
;********************************
;************ t g l b u f *****
;********************************
;
; toggel the inactive and active buffers.
;
; input parameters:
; lindx - channel #
;
;********************************
tglbuf ldx lindx
lda buf0,x
eor #$80
sta buf0,x
lda buf1,x
eor #$80
sta buf1,x
rts
pibyte ldx #iwsa
stx sa
jsr fndwch
jsr setlds
jsr typfil
bcc pbyte
lda #ovrflo
jsr clrflg
pbyte lda sa
cmp #15
beq l42
bne l40
;main routine to write to chanl
put lda orgsa ;is chanl cmd or data
and #$8f
cmp #15 ;<15
bcs l42
l40 jsr typfil ;data byte to store
bcs l41 ;branch if rnd
lda data ;seq file
jmp wrtbyt ;write byte to chanl
l41 bne l46
jmp wrtrel
l46 lda data ;rnd file write
jsr putbyt ;write to chanl
ldy lindx ; prepare nxt byte
jmp rnget2
l42 lda #cmdchn ;write to cmd chanl
sta lindx
jsr getpnt ;test if comm and buffer full
cmp #<cmdbuf+cmdlen+1
beq l50 ;it is full (>cmdlen)
lda data ;not full yet
jsr putbyt ;store the byte
l50 lda eoiflg ;tst if lst byte of msg
beq l45 ;it is
rts ;not yet , return
l45 inc cmdwat ;set cmd waiting flag
rts
;put .a into active buffer of lindx
putbyt pha ; save .a
jsr getact ;get active buf#
bpl putb1 ;brach if there is one
pla ;no buffer error
lda #filnop
jmp cmderr ; jmp to error routine
putb1 asl a ;save the byte in buffer
tax
pla
sta (buftab,x)
inc buftab,x ; inc the buffer pointer
rts ;z=1 if last char slot in buffer
; find the active buffer # (lindx)
;
; initialize drives (command)
intdrv jsr simprs
jsr initdr
id20 jmp endcmd
; initialize drive (drvnum)
itrial jsr bam2a
tay ;bam lindx from buf0
ldx buf0,y
cpx #$ff
bne it30 ;valid buffer #
pha ;save bam-lindx
jsr getbuf ;get a buffer
tax ;test it
bpl it20 ;no error
lda #nochnl
jsr cmder3
it20 pla
tay ;restore bam-lindx
txa
ora #$80 ;set inactive
sta buf0,y
it30 txa
and #$f ;stip to buf #
sta jobnum
ldx #0
stx sector
ldx dirtrk
stx track
jsr seth ;set the bam header
lda #seek
jmp dojob ;do a seek
initdr jsr clnbam
jsr cldchn
jsr itrial
ldx drvnum
lda #0
sta mdirty,x
txa
asl a
tax
lda header
sta dskid,x
lda header+1
sta dskid+1,x
jsr doread
lda jobnum
asl a
tax
lda #2
sta buftab,x
lda (buftab,x)
ldx drvnum
sta dskver,x ;set up disk version #
lda #0
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
jmp ptch21 ;*rom ds 09/03/85* *GCB 11/20/86*
nop ;fill
; sta wpsw,x ;clear wp switch
; sta nodrv,x ;clear not active flag
rtch21
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
; count the number of free blocks here
nfcalc jsr setbpt
ldy #4
lda #0
tax ;0 hi byte
numf1 clc
adc (bmpnt),y
bcc numf2
inx
numf2 iny
iny
iny
iny
cpy #$48 ; don't count the dir
beq numf2
cpy #$90
bne numf1
pha
txa
ldx drvnum
sta ndbh,x
pla
sta ndbl,x
rts
; start double buffering
; use track,sector as starting bloack
strrd jsr sethdr
jsr rdbuf
jsr watjob
jsr getbyt
sta track
jsr getbyt
sta sector
rts
strdbl jsr strrd
lda track
bne str1
rts
str1 jsr dblbuf
jsr sethdr
jsr rdbuf
jmp dblbuf
; start a read job on track,sector
rdbuf lda #read
bne strtit
; start a write job on track,sector
wrtbuf lda #write
strtit sta cmd
jsr getact
tax
jsr setljb
txa
pha
asl a
tax
lda #0
sta buftab,x
jsr typfil
cmp #4
bcs wrtc1 ;not sequential type
inc nbkl,x
bne wrtc1
inc nbkh,x
wrtc1 pla
tax
rts
;****************************
;*
;* fndrch
;******************************
fndrch lda sa
cmp #maxsa+1
bcc fndc20
and #$f
fndc20 cmp #cmdsa
bne fndc25
lda #errsa
fndc25 tax
sec
lda lintab,x
bmi fndc30
and #$f
sta lindx
tax
clc
fndc30 rts
;*****************************
;*
;* fndwch
;*
;*****************************
fndwch lda sa
cmp #maxsa+1
bcc fndw13
and #$0f
fndw13 tax
lda lintab,x
tay
asl a
bcc fndw15
bmi fndw20
fndw10 tya
and #$0f
sta lindx
tax
clc
rts
fndw15 bmi fndw10
fndw20 sec
rts
typfil ldx lindx ;get file type
lda filtyp,x
lsr a
and #7
cmp #reltyp
rts
getpre jsr getact
asl a
tax
ldy lindx
rts
; read byte from active buffer and set flag if last data byte
; if last then z=1 else z=0
getbyt jsr getpre
lda lstchr,y
beq getb1
lda (buftab,x)
pha
lda buftab,x
cmp lstchr,y
bne getb2
lda #$ff
sta buftab,x
getb2 pla
inc buftab,x
rts
getb1 lda (buftab,x)
inc buftab,x
rts
; read a char from file and read next block of file if needed.
; set chnrdy=eoi if end of file
rdbyt jsr getbyt
bne rd3
sta data
rd0 lda lstchr,y
beq rd1
lda #eoiout
rd01 sta chnrdy,y
lda data
rts
rd1 jsr dblbuf
lda #0
jsr setpnt
jsr getbyt
cmp #0
beq rd4
sta track
jsr getbyt
sta sector
jsr dblbuf
jsr setdrn
jsr sethdr
jsr rdbuf
jsr dblbuf
lda data
rd3 rts
rd4 jsr getbyt
ldy lindx
sta lstchr,y
lda data
rts
;write a char to chanl and write buffer out to disk if its full
wrtbyt jsr putbyt
beq wrt0
rts
wrt0 jsr setdrn
jsr nxtts
lda #0
jsr setpnt
lda track
jsr putbyt
lda sector
jsr putbyt
jsr wrtbuf
jsr dblbuf
jsr sethdr
lda #2
jmp setpnt
; inc pointer of active buffer by .a
incptr ;scott patch
incpnt sta temp
jsr getpnt
clc
adc temp
sta buftab,x
sta dirbuf
rts
; set drvnum to drive indicated by lstjob of active buffer
setdrn jsr getact
tax
lda lstjob,x
and #1
sta drvnum
rts
; .end