-
Notifications
You must be signed in to change notification settings - Fork 82
/
tst2
533 lines (533 loc) · 7.07 KB
/
tst2
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 '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
.SKIP
; 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
STA WPSW,X ;CLEAR WP SWITCH
STA NODRV,X ;CLEAR NOT ACTIVE FLAG
; 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 ; DONT 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 #$F
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 ;GET FILE TYPE
LDX LINDX
LDA FILTYP,X
LSR A
AND #7
CMP #RELTYP
RTS
;
GETPRE JSR GETACT
ASL A
TAX
LDY LINDX
RTS
.SKIP
; 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
.SKIP
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
.SKIP 2
.SKIP
; WRITE A CHAR TO CHANL AND WRITE
; BUFFER OUT TO DISK IF ITS FULL
;
WRTBYT JSR PUTBYT
BEQ WRT0
RTS
.SKIP
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