-
Notifications
You must be signed in to change notification settings - Fork 1
/
COMMAND.ASM
475 lines (453 loc) · 6.5 KB
/
COMMAND.ASM
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
FCB EQU 5CH
DSKRESET EQU 13
SETBASE EQU 38
SRCHFRST EQU 17
SRCHNXT EQU 18
RENAM EQU 23
INCHAR EQU 1
GETFAT EQU 27
OPEN EQU 15
CLOSE EQU 16
MAKE EQU 22
DELETE EQU 19
RDBLK EQU 39
WRBLK EQU 40
SETDMA EQU 26
SELDRV EQU 14
GETDRV EQU 25
PRINTBUF EQU 9
OUTCH EQU 2
INBUF EQU 10
RR EQU 33
SYSTEM EQU 5
ORG 100H
PUT 100H
MOV SP,STACK
CLD
MOV DL,0 ;Start with A:
SETDRV:
MOV CL,SELDRV
CALL SYSTEM
COMMAND:
MOV SP,STACK
CLD
MOV AX,CS
MOV SS,AX
MOV ES,AX
MOV DS,AX
MOV CX,[6]
SUB CX,TPA
AND CL,80H ;Round down
ROL CX
XCHG CH,CL
MOV [NUMREC],CX ;Number of records each time
MOV DX,CRLF
MOV CL,PRINTBUF
CALL SYSTEM
MOV DX,COMMAND
MOV AX,2522H ;Set vector 34 (terminate)
INT 33
MOV AX,2523H ;Set vector 35 (CTRL-C)
INT 33
GETCOM:
MOV CL,GETDRV
CALL SYSTEM
ADD AL,"A"
MOV CL,OUTCH
MOV DL,AL
CALL SYSTEM ;Print drive letter
MOV DL,":"
MOV CL,OUTCH
CALL SYSTEM ;Print :
MOV DX,LINBUF
MOV CL,INBUF
CALL SYSTEM
MOV DL,10
MOV CL,OUTCH
CALL SYSTEM ;New line
MOV CH,0
MOV SI,FILIFO ;8 spaces
MOV DI,ID
CALL FILLBUF
MOV DI,FCB
CALL FILLBUF
MOV SI,LINBUF+2
MOV DI,ID
CALL FILEDRV ;Get COM drive
MOV [SPECDRV],AL
MOV CX,8
CALL COPYNAM ;Copy file name
MOV AL,9
SUB AL,CL
MOV [IDLEN],AL
MOV DI,81H
MOV CX,0
PUSH SI
COMTAIL:
LODB
STOB ;Move command tail to 80H
CMP AL,13
LOOPNZ COMTAIL
NOT CL
MOV [80H],CL
POP SI
MOV DI,FCB
CALL PARSENAM
MOV DI,FCB+10H
CALL PARSENAM
MOV AL,[IDLEN]
MOV DL,[SPECDRV]
OR DL,DL ;Check if drive was specified
JNZ DRVCHK
DEC AL ;Check for null command
JZ GETCOM
MOV SI,COMTAB
FINDCOM:
MOV DI,IDLEN
MOV CL,[SI]
JCXZ EXTERNAL
REPE
CMPB
LAHF
ADD SI,CX ;Bump to next position without affecting flags
SAHF
LODW ;Get address of command
JNZ FINDCOM
CALL AX ;Call command
JMP COMMAND
SETDRV1:
JMP SETDRV
DRVCHK:
DEC DL ;Adjust for correct drive number
DEC AL ;Check if anything else is on line
JZ SETDRV1
EXTERNAL:
MOV AL,[SPECDRV]
MOV [IDLEN],AL
PUSH DS
MOV DX,TPA
ADD DX,0FH ;Round to next paragraph
SHR DX
SHR DX
SHR DX
SHR DX ;Divide 16
MOV CX,CS
ADD DX,CX ;New segment
MOV DS,DX
MOV AH,SETBASE
INT 33
MOV DX,100H
MOV CL,SETDMA
CALL SYSTEM
MOV BX,DS ;New segment into BX
POP DS
MOV DX,IDLEN
MOV AH,OPEN
INT 33
OR AL,AL
JNZ BADCOM
MOV [IDLEN+RR],0
MOV CX,512 ;512 records
MOV AH,RDBLK
INT 33
MOV DS,BX
MOV ES,BX
MOV SS,BX
MOV SP,40H
MOV AX,0
PUSH AX
MOV AX,100H
PUSH BX
PUSH AX
MOV CL,SETDMA
MOV DX,80H
CALL SYSTEM
RET L
BADCOM:
MOV DX,BADNAM
MOV CL,PRINTBUF
CALL SYSTEM
JMP COMMAND
NEXTCHR:
;Convert lower case input to upper case
LODB
CMP AL,"a"-1
JB DELIM
CMP AL,"z"
JA DELIM
SUB AL,20H ;Lower-case changed to upper-case
DELIM:
CMP AL," "
JZ RET
CMP AL,"="
JZ RET
CMP AL,","
JZ RET
CMP AL,";"
JZ RET
CMP AL,9 ;Check for TAB character
RET
FILEDRV:
CALL NEXTCHR
JZ FILEDRV ;Skip delim
CMP AL,13
JZ NOMATCH
CMP B,[SI],":"
JNZ NOMATCH
SUB AL,40H ;A => 1, B => 2
INC SI
RET
PARSENAM:
CALL NEXTCHR
JZ ISDELIM
CMP AL,13
JNZ PARSENAM
DEC SI
ISDELIM:
CALL FILEDRV
STOB
MOV CX,11
CALL COPYNAM
ADD DI,CX
CMP CX,3
JB RET
SUB DI,3
CMP AL,"."
JNZ NOMATCH
MOV CX,3
COPYNAM:
CALL NEXTCHR
JZ NOMATCH
CMP AL,13
JZ NOMATCH
CMP AL,"."
JZ RET
STOB
LOOP COPYNAM
NOMATCH:
XOR AL,AL
DEC SI
RET
FILLBUF:
LODB
MOV CL,AL
JCXZ RET
LODB
REP
STOB
JP FILLBUF
DIR:
CMP B,[FCB+1]," "
JNZ HASNAME
MOV SI,FCBFIL
MOV DI,FCB+1
CALL FILLBUF ;Fill 11 bytes with "?"
HASNAME:
MOV DX,LINBUF+2+1
MOV CL,SETDMA
CALL SYSTEM
MOV CL,SRCHFRST
MOV DX,FCB
EACHFILE:
CALL SYSTEM
INC AL ;FF = file not found
JZ RET
MOV SI,LINBUF+2+1
MOV CX,8
CALL OUTCNT ;Print 8 chars (name)
MOV CL,OUTCH
MOV DL," "
CALL SYSTEM ;Print space
MOV SI,LINBUF+2+9
MOV CX,3
CALL OUTCNT ;Print 3 chars (ext)
MOV DX,CRLF
MOV CL,PRINTBUF
CALL SYSTEM ;Print new line
MOV CL,SRCHNXT
JP EACHFILE
OUTCNT:
LODB
PUSH CX
PUSH SI
MOV DL,AL
MOV CL,OUTCH
CALL SYSTEM
POP SI
POP CX
LOOP OUTCNT
RET
RENAME:
MOV CL,RENAM
MOV DX,FCB
JMP 5
ERASE:
MOV CL,DELETE
MOV DX,FCB
JMP 5
CREATE:
MOV CL,MAKE
MOV DX,FCB
JMP 5
TYPE:
MOV DX,TPA
MOV CL,SETDMA
CALL SYSTEM
MOV DX,FCB
MOV AH,OPEN
INT 33
OR AL,AL
JNZ RET ; Not found
MOV [FCB+RR],0
MOV CX,512
MOV AH,RDBLK
INT 33
MOV SI,TPA
OUTLP:
LODB
CMP AL,1AH ;Is EOF?
JZ RET
MOV CL,OUTCH
MOV DL,AL
CALL SYSTEM
JP OUTLP
RET
CLEAR:
MOV DX,ERAMES
MOV CL,PRINTBUF
CALL SYSTEM ;Confirm erase
MOV CL,INCHAR
CALL SYSTEM
CMP AL,"Y"
JZ DOCLEAR
CMP AL,"y"
JZ DOCLEAR
RET
DOCLEAR:
MOV DL,[FCB]
OR DL,DL
JZ CLRDSK
DEC DL
MOV CL,SELDRV
CALL SYSTEM
CLRDSK:
MOV CL,GETFAT
CALL SYSTEM
MOV CX,DX
INC DX
SHR DX
ADD CX,DX
MOV AX,DS
MOV ES,AX
MOV DI,BX
MOV AX,0FFFFH
STOW
STOB ;Fill first 3 bytes with FF
INC AX ;AX = 0
SHR CX
JNC DOFILL
STOB ;Odd byte
DOFILL:
REP
STOW
MOV AX,CS
MOV DS,AX
MOV ES,AX
MOV SI,FCBFIL
MOV DI,FCB+1
CALL FILLBUF
MOV DX,FCB
MOV CL,DELETE
CALL SYSTEM ;Delete all files
MOV CL,DSKRESET
JMP 5
COPY:
MOV SI,FCB+10H
MOV DI,DSTFCB
MOVB
CMP B,[SI]," " ;Has file name?
JNZ HASDSTNAM
MOV SI,FCB+1
HASDSTNAM:
MOVB
MOV CX,7
REP
MOVW
MOV DX,FCB
MOV AH,OPEN
INT 33
OR AL,AL
JNZ NOSRC
MOV DX,DSTFCB
MOV AH,DELETE
INT 33
MOV AH,MAKE
INT 33
MOV DX,TPA
MOV AH,SETDMA
INT 33
MOV [FCB+RR],0
MOV [DSTFCB+RR],0
CPYBLK:
MOV DX,FCB
MOV CX,[NUMREC]
MOV AH,RDBLK
INT 33
JCXZ CPYDONE
MOV DX,DSTFCB
MOV AH,WRBLK
INT 33
OR AL,AL
JZ CPYBLK
MOV DX,NOSPCE
MOV AH,PRINTBUF
INT 33
CPYDONE:
MOV DX,DSTFCB
MOV AH,CLOSE
INT 33
RET
NOSRC:
MOV DX,NOTFND
MOV AH,PRINTBUF
INT 33
RET
DS 40
STACK:
BADNAM: DB "Bad command or file name"
CRLF: DB 13,10,"$"
ERAMES: DB "Erase all files (Y/N)? $"
NOTFND: DB "Source file not found$"
NOSPCE: DB "Insufficient disk space$"
FCBFIL: DB 11,"?"
DB 0
SPECDRV: DS 1
NUMREC: DS 2
IDLEN: DS 1
ID: DS 8
COM: DB "COM"
DSTFCB: DS 36
LINBUF: DB 80H,1,13
DS 80H
FILIFO: DB 8," "
DB 0
DB 12," ",4,0
DB 12," ",8,0
DB 0
COMTAB: DB 4,"DIR"
DW DIR
DB 7,"RENAME"
DW RENAME
DB 6,"ERASE"
DW ERASE
DB 7,"CREATE"
DW CREATE
DB 5,"TYPE"
DW TYPE
DB 6,"CLEAR"
DW CLEAR
DB 5,"COPY"
DW COPY
DB 0
TPA: