-
Notifications
You must be signed in to change notification settings - Fork 84
/
tst2
468 lines (468 loc) · 6.65 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
.PAGE 'TST2'
.SKIP
;
; MARK TRACK,SECTOR,(BMPNT) AS USED
;
USEDTS JSR FREUSE ;CALC IN DEX INTO BAM
BEQ USERTS ;USED, NO ACTION
LDA (BMPNT),Y ;GET BITS
EOR BMASK,X ;MARK SEC USED
STA (BMPNT),Y
LDY TEMP ;IN DEX TO FREE SEC CNT
LDA (BMPNT),Y ;GET COUNT
SBC #0 ; DEC ONE (C=0)
STA (BMPNT),Y ;SAVE IT
USERTS RTS
;
; CALCULATES INDEX INTO BAM
; FOR FRETS AND USEDTS
;
FREUSE LDA TRACK ;A=TRACK*4
ASL A
ASL A ;4 BYTES IN BAM PER TRACK
STA TEMP ;SAVE INDEX
LDA SECTOR ;A=SECTOR/8
LSR A
LSR A
LSR A ;FOR WHICH OF THREE BYTES
SEC
ADC TEMP ;CALC INDEX
TAY
LDA SECTOR ;BIT IN THAT BYTE
AND #7
TAX
LDA (BMPNT),Y ;GET THE BYTE
AND BMASK,X ;TEST IT
RTS ;Z=1=USED,Z=0=FREE
;
;
BMASK .BYTE 1,2,4,8,16,32,64,128
;
;
;
; TOGGLE ACTIVE BUFFER # IN BUFNUM
;
DBLBUF LDX LINDX
LDA BUF0,X ;TOGGLE ACTIVE FLAG
EOR #$80
STA BUF0,X
DBL1 LDA BUF1,X ;TOGGLE ACTIVE FLAG
EOR #$80
STA BUF1,X
DBL2 JSR GETACT ;GET ACTIVE BUF#
TAX
JMP WATJOB ; AND WAIT FOR BUFFER READY
;
PIBYTE
LDX #IWSA
STX SA
PBYTE
JSR FNDWCH
JSR SETLDS
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 #41
BEQ L50 ;IT IS FULL (>40)
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
;
;TEST IF JOB(.X) IS DONE YET
;IF NOT DONE RETURN
;IF OK THEN RETURN ELSE REDO IT
;
TSTJOB LDA JOBS,X
BMI NOTYET
CMP #2
BCC OK
DEC ERRCNT,X ;REDO UNTIL ERRCNT=0
BPL AGAIN
BIT JOBRTN ;RETURN WITH .A=ERROR?
BMI OK
;
RECOV
BIT REVCNT
BMI REC4 ;NO RECOVERY
;
TYA ;SAVE .Y
PHA
LDA LSTJOB,X ;RESTORE HEAD TO TRACK 1
AND #1
ORA #BUMP
STA JOBS,X
REC1
LDA JOBS,X
BMI REC1
;
LDA REVCNT ;RECOVERY COUNT
AND #$3F
TAY
REC2
LDA LSTJOB,X ;SET LAST JOB
STA JOBS,X
REC3
LDA JOBS,X ;WAIT
BMI REC3
;
CMP #2
BCC REC5
DEY ;TRY IT A # OF TIMES
BNE REC2
REC4
JMP ERROR ;GIVE UP!!
;
REC5 ;IT WORKED!
PLA ;RESTORE .Y
TAY
OK CLC ;C=0 DONE OK
RTS
;
AGAIN LDA LSTJOB,X
STA JOBS,X
NOTYET SEC ;C=1 NOT YET
RTS
;
;
; WAIT UNTIL JOB(.X) IS DONE
; RETURN WHEN DONE
;
WATJOB JSR TSTJOB
BCS WATJOB
PHA ;CLR JOBRTN FLAG
LDA #0
STA JOBRTN
PLA
RTS
;
; SET HEADER OF ACTIVE BUFFER OF THE
; CURRENT LINDX TO TRACK,SECTOR,ID
;
SETHDR JSR GETACT
SETH
ASL A
ASL A
ASL A
TAY
LDA TRACK
STA HDRS+2,Y ;SET TRACK
LDA SECTOR
STA HDRS+3,Y ;SET SECTOR
LDA DRVNUM ;GET PROPER ID(DRVNUM)
ASL A
TAX
LDA DSKID,X
STA HDRS,Y
LDA DSKID+1,X
STA HDRS+1,Y
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
LDA IMAGE ;USED AS FLAG FOR BOTH DRIVES
BPL ID20
JSR TOGDRV
JSR SETLDS
JSR INITDR
JSR TOGDRV
ID20 JMP ENDCMD
.SKIP
; INITIALIZE DRIVE (DRVNUM)
;
INITSU
LDA DRVNUM ;DO A BUMP TO TRK 1
CLC ;READ IN BIT MAP (18.00)
ADC #BAMJOB ; AND SAVE DISK ID
STA JOBNUM
LDX #18
STX TRACK
LDX #0
STX SECTOR
JSR SETH
LDX JOBNUM
LDA DRVNUM
ORA #SEEK
JMP DOIT
;
INITDR JSR CLDCHN
JSR INITSU
LDA #0
STA HDRS+3,Y
LDA DRVNUM
ORA #READ
JSR DOIT
LDA DRVNUM
ASL A
TAX
LDA HDRS,Y
STA DSKID,X
LDA HDRS+1,Y
STA DSKID+1,X
RTS
;
;
; START DOUBLE BUFFERING
; USE TRACK,SECTOR AS STARTING BLOACK
;
STRDBL
JSR SETHDR
JSR RDBUF
JSR WATJOB
JSR GETBYT
STA TRACK
JSR GETBYT
STA SECTOR
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