-
Notifications
You must be signed in to change notification settings - Fork 82
/
dos1.src
543 lines (401 loc) · 9.22 KB
/
dos1.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
534
535
536
537
538
539
540
541
542
543
.page
.subttl DOS 1
doslfn = 0
; this set of routines takes tokens and values after the
; following basic keywords
;
; dopen, dclose, record, format, collect, backup, copy, bload
; concat, dsave, dload, catlog, rename, append, scrtch, bsave
;
; it then parses the following line and finds syntax errors, checks for
; out of range values, and sets variables in the zero-page to be passed
; to the disk message generator (dmg).
catalog ;catalog a device (==directory)
jsr dospar ;parse the line
lda parsts ;check options
and #$e6
beq 10$
jmp snerr
10$ ldy #fcat ;table offset
ldx #1 ;just $
lda parsts ;chk for default
and #$11 ;no drive?
beq dcat2
lsr a
bcc dcat1 ;just drive
inx ;drive and filename
inx
dcat1 inx
dcat2 txa ;a now has length
jsr sendp ;build
lda #0
tax
jsr k_setbank
ldy #$60 ;sa, load floppy
ldx dosfa
lda #doslfn ;lfn
jsr k_setlfs ;set file parameters
sec
jsr k_open ;open it...
bcc 10$ ;ok
pha
jsr dcat10
pla
tax
jmp error
; get length in blocks
10$ ldx #doslfn
jsr put_io_in_map
jsr _chkin
ldy #3 ;loop counter
dcat3 sty t3 ;save counter
10$ jsr k_basin ;get char
sta t4
jsr k_readst
bne dcat10 ;if bad status
jsr k_basin ;get char
sta t4+1
jsr k_readst
bne dcat10 ;if bad status
dec t3
bne 10$ ;if not done
; output blocks number
ldx t4
lda t4+1
jsr linprt ;output number
lda #' '
jsr k_bsout ;output a space
; loop reading name and output
dcat4 jsr k_basin ;get char
pha ;save char
jsr k_readst ;get status
bne dcat9 ;if bad status
pla ;get back char
beq dcat5 ;if eol
jsr k_bsout ;echo char
jmp dcat4 ;continue to process name
; here on end of name
dcat5 lda #cr
jsr k_bsout ;output new line
; check for halt
jsr k_stop ;get status of stop key
beq dcat10 ;if stop request
; process next
ldy #2 ;perform 2 times
bne dcat3 ;jmp
dcat9 pla ;clean up stack
dcat10 jsr k_clrch
lda #doslfn
clc ;a real close
jmp k_close ;close special channel
.page
; dopen code dfn(,t(,r))
dopen lda #$22 ;set error flag
jsr dosprs ;parse the line
jsr chk6 ;chk req'd parms
jsr fndsca ;find secondary address
ldy #fopn ;fcb format pointer
ldx #4 ;normal length
bit parsts ;relative record
bvc dop2 ;if not random access
ldx #8 ;random access length
bne dop2 ;alway jump
; append code
append lda #$e2 ;set error flags
jsr dosprs ;parse the line
jsr chk6 ;chk req'd parms
jsr fndsca ;find secondary address
ldy #fapn ;tabld index
ldx #5 ;length
dop2 txa ;set length into a
jsr sendp
jsr k_clrch
lda #0
tax
jsr k_setbank
jsr k_open
nop ;placeholder
jmp dopen_patch ;318019-03 fix; FAB
; find an available secondary address
fndsca ldy #$61
fsca10 iny
cpy #$6f
beq fsca20 ;if none available
jsr put_io_in_map
jsr _lkupsa ;get physical unit from secondary
bcc fsca10 ;if secondary address used
sty dossa ;save secondary address
rts ;return .y = sa
fsca20 ldx #errtmf ;too many files open
jmp error
.page
; close disk file
dclose
lda #$f3 ;set error flags
jsr dosprs ;parse the line
jsr oldclr
lda parsts ;any la given?
and #$04
beq dclall ;no....
lda dosla
jmp k_close ;close file
dclall lda dosfa ;get disk #
jsr put_io_in_map
jmp _close_all ;close all channels
; dsave dfn
dsave lda #$66 ;set error flags
jsr dosprs ;parse the line
jsr chk2 ;check required parms
ldy #fopn ;table offset
lda #4 ;..length,
jsr sendp
lda #0 ;set up banks
tax
jsr k_setbank
jmp savenp
.page
; dverify
dverify lda #1 ;flag 'verify'
.byt $2c
; dload dfn
dload lda #0 ;flag 'load'
sta verck ;eventually the 'load' routine will look here
lda #$e6 ;set error flags
jsr dosprs ;parse the line
jsr chk2 ;check required parms
lda #0
sta dossa ;tell 'em to relocate, s'il vous plait.
ldy #fopn ;table offset
lda #4 ;..length,
jsr sendp
lda #0 ;set up banks
tax
jsr k_setbank
jmp cld10 ;finish load, using 'LOAD' code.
; bsave dfn
bsave lda #$66 ;std error flag
ldx #$f8 ;auxiliary error flag
jsr dosprx ;parse options
jsr chk2 ;check required parms
lda parstx ;check for styarting & ending addresses
and #6
cmp #6
beq 10$
jmp snerr ;..if not present, syntax error
10$ lda dosofh+1 ;check that ea>sa
cmp dosofl+1
bcc 30$ ;...error
bne 20$
lda dosofh
cmp dosofl
bcc 30$ ;...error
beq 30$
20$ ldy #fopn ;table offset
lda #4 ;..length,
jsr sendp
lda dosbnk ;get requested bank
ldx #0 ;..and name will be in system bank
jsr k_setbank ;..and go set up bank
ldx dosofl ;start addr
ldy dosofl+1
lda #highds ;..and a pointer to start address
stx highds
sty highds+1
ldx dosofh ;end addr
ldy dosofh+1
jmp savenb
30$ jmp fcerr ;bad quantity
; bload dfn
bload lda #$e6 ;std error flag
ldx #$fc ;aux error flag
jsr dosprx ;parse options (entry for BOOT filename)
bload_1 jsr chk2 ;check required parms
ldx dosofl ;get starting address high
ldy dosofl+1 ;..and lo
lda #0 ;assume x & y not both=ff (means real add., not def)
cpx #$ff
bne 10$
cpy #$ff
bne 10$
lda #$ff ;use defaults
10$ sta dossa
ldy #fopn ;table offset
lda #4 ;..length,
jsr sendp ;...and go send parms
lda dosbnk
ldx #0
jsr k_setbank
lda #0 ;flag "LOAD",
ldx dosofl ;get starting address high
ldy dosofl+1 ;..and lo (in case this isn't a 'default' load)
jsr _loadsp ;..and go do it!
php ;save carry
jsr dschk ;clear old status
plp
bcc 15$ ;branch if ok,
jmp erexit ;..else error
15$ jsr k_readst
and #$ff-$40 ;ignore e-o-i
beq 20$
jmp load_error
20$ clc ;flag 'good return'
rts
; header nddn (,id)
header jsr dospar ;parse the line
jsr chk1 ;check parameter errors
and #$01
cmp #$01
bne rec5 ;if required parameters not present
jsr k_clall ;close all files
jsr are_you_sure
bne 30$ ;if no and direct mode
ldy #fhed ;tabld index
lda #4 ;length
ldx dosdid ;check for diskid
beq 10$
lda #6 ;length with id
10$ jsr trans ;build and send
jsr errchl ;get error status
bit runmod ;test if direct mode
bmi 30$ ;it is direct mode
ldy #0
lda #dsdesc+1
jsr indsub_ram1
cmp #'2'
bcc 30$ ;if error occured
20$ ldx #errbdk ;bad disk
jmp error
30$ rts
; scratch sdfn
scratc jsr dospar ;parse the line
jsr chk1
jsr are_you_sure
bne 30$ ;if no and direct mode
ldy #fscr ;offset
lda #4 ;length
jsr trans
jsr errchl ;read error channel
bit runmod
bmi 30$ ;if not direct mode
lda #cr
jsr k_bsout ;output cr
ldy #0 ;clr to read errchl
10$ lda #dsdesc+1
jsr indsub_ram1
beq 20$ ;if end of error message
jsr k_bsout
iny
bne 10$ ;always
20$ lda #cr
jsr outch
30$ rts
rec5 jmp snerr ;syntax error
; record - random record access.
record lda #'#'
jsr synchr ;syntax error if not 'record#'
jsr getbyt ;get lfn in x
cpx #0
beq rec4 ;cannot be zero
stx dosla ;save logical address
jsr comwrd ;check for comma, get record number in 'poker'
ldx #1 ;set up to get starting byte # - default is 1
jsr optbyt
cpx #0
beq rec4 ;if out of range
cpx #$ff
beq rec4 ;if out of range
stx dosrcl ;save byte position (pos)
lda dosla ;get logical address
jsr put_io_in_map
jsr _lkupla ;logical to physical map
bcs rec6 ;if file not found
sty dossa_temp ;save secondary address
stx dosfa ;set up device number for trans routine
lda #0
sta dosla ;set up logical address for trans routine
lda #$6f
sta dossa ;and secondary address, too!
ldy #frec ;set pointer
lda #4 ;process five bytes
bne trans ;transfer on channel 15
rec4 jmp fcerr ;illegal value error
rec6 ldx #errfnf ;file not found err
jmp error
dclear jsr dospar ;parse the line
ldy #fclr ;set code
lda #2
jsr trans
jmp dclall
; collect v<drive#>
collect jsr dospar ;parse the line
jsr chk3 ;chk opt parms
jsr k_clall ;close all files
ldy #fcoll ;tabld offset
ldx #1 ;length
lda parsts
and #$10
beq 10$
inx ;include drive
10$ txa ;place in a
bne trans ;always (x <> 0)
; copy routines cdddfn=sdsfn
dcopy jsr dospar ;parse the line
and #$30
cmp #$30 ;chk req'd parms
bne 10$
lda parsts
and #$c7
beq 20$
10$ lda parsts
jsr chk4
lda parsts
20$ ldy #fcopy ;tabld offset
lda #8 ;length
bne trans ;go do it
; concat routines
concat jsr dospar ;parse the line
jsr chk4
ldy #fconc ;offset
lda #12 ;length
bne trans ;go do it
; rename rdddfn=sdsfn
rename lda #$e4 ;set error flags
jsr dosprs ;parse the line
jsr chk5
ldy #fren ;offset
lda #8 ;length
bne trans ;go do it
; backup d<dd>=<sd>
backup lda #$c7 ;set error flags
jsr dosprs ;parse the line
and #$30 ;req'd parms
cmp #$30
beq 5$
jmp snerr
5$ jsr are_you_sure
beq 10$ ;if run mode or not 'yes'
rts
10$ jsr dclall ;close disk
ldy #fbak
lda #4 ;length
;fall thru to trans
; trans subroutine
trans jsr sendp ;build string to output
jsr k_clrch
lda #0 ;name is in bank 0
tax
jsr k_setbank
sec
jsr k_open ;send it...
php ;save error status (.c)
pha ;save error code (if any)
lda dosla
sec
jsr k_close ;special close...
pla ;pop error
plp ;pop error status
dopen_patch
bcs 10$ ;...branch if there was an error opening
rts
10$ jmp erexit
;end