-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCOMMAND.ASM
2166 lines (2031 loc) · 63.4 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
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
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; COMMAND version 1.17
;
; This version of COMMAND is divided into three distinct parts. First
; is the resident portion, which includes handlers for interrupts
; 22H (terminate), 23H (Cntrl-C), 24H (fatal error), and 27H (stay
; resident); it also has code to test and, if necessary, reload the
; transient portion. Following the resident is the init code, which is
; overwritten after use. Then comes the transient portion, which
; includes all command processing (whether internal or external).
; The transient portion loads at the end of physical memory, and it may
; be overlayed by programs that need as much memory as possible. When
; the resident portion of command regains control from a user program,
; a checksum is performed on the transient portion to see if it must be
; reloaded. Thus programs which do not need maximum memory will save
; the time required to reload COMMAND when they terminate.
;Use the following booleans to set assembly flags
FALSE EQU 0
TRUE EQU NOT FALSE
IBMVER EQU FALSE ;Switch to build IBM version of Command
MSVER EQU TRUE ;Switch to build MS-DOS version of Command
HIGHMEM EQU TRUE ;Run resident part above transient (high memory)
LINPERPAG EQU 23
NORMPERLIN EQU 1
WIDEPERLIN EQU 5
IF IBMVER
SYM EQU ">"
COMDRV EQU 1
ENDIF
IF MSVER
SYM EQU ":"
COMDRV EQU 0
ENDIF
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
GETDATE EQU 2AH
SETDATE EQU 2BH
GETTIME EQU 2CH
SETTIME EQU 2DH
RR EQU 33
RECLEN EQU 14
FILLEN EQU 16
OFFDATE EQU 20
;The following are all of the segments used in the load order
CODERES SEGMENT
CODERES ENDS
DATARES SEGMENT BYTE
DATARES ENDS
INIT SEGMENT BYTE
INIT ENDS
TAIL SEGMENT PARA
TAIL ENDS
TRANCODE SEGMENT PARA
TRANCODE ENDS
TRANDATA SEGMENT BYTE
TRANDATA ENDS
TRANSPACE SEGMENT BYTE
TRANSPACE ENDS
RESGROUP GROUP CODERES,DATARES,INIT,TAIL
TRANGROUP GROUP TRANCODE,TRANDATA,TRANSPACE
;Data for resident portion
DATARES SEGMENT BYTE
ORG 0
ZERO = $
MESBAS DW OFFSET RESGROUP:ERR0
DW OFFSET RESGROUP:ERR2
DW OFFSET RESGROUP:ERR4
DW OFFSET RESGROUP:ERR6
DW OFFSET RESGROUP:ERR8
DW OFFSET RESGROUP:ERR10
DW OFFSET RESGROUP:ERR12
ERR0 DB "Write protect$"
ERR2 DB "Not ready$"
ERR4 DB "Data$"
ERR6 DB "Seek$"
ERR8 DB "Sector not found$"
ERR10 DB "Write fault$"
ERR12 DB "Disk$"
READ DB "read$"
WRITE DB "writ$"
ERRMES DB " error "
IOTYP DB "writing"
DRVNUM DB " drive "
DRVLET DB "A"
NEWLIN DB 13,10,"$"
REQUEST DB "Abort, Retry, Ignore? $"
BADFAT DB 13,10,"File allocation table bad,$"
COMBAD DB 13,10,"Invalid COMMAND.COM"
NEEDCOM DB 13,10,"Insert DOS disk in "
IF IBMVER
DB "drive A"
ELSE
DB "default drive"
ENDIF
PROMPT DB 13,10,"and strike any key when ready",13,10,"$"
NEEDBAT DB 13,10,"Insert disk with batch file$"
ENDBATMES DB 13,10,"Terminate batch job (Y/N)? $"
LOADING DB 0
BATFCB DB 1,"AUTOEXECBAT"
DB 21 DUP(?)
DW 0
DW 0 ;Initialize RR field to zero
PARMTAB DW 10 DUP(-1) ;No parameters initially
BATCH DB 1 ;Assume batch mode initially
COMFCB DB COMDRV,"COMMAND COM"
DB 25 DUP(?)
TRANS DW OFFSET TRANGROUP:COMMAND
TRNSEG DW ?
BATBYT DB ?
MEMSIZ DW ?
SUM DW ?
INITADD DB 4 DUP(?)
RESDATASIZE EQU $-ZERO
DATARES ENDS
;Data for transient portion
TRANDATA SEGMENT BYTE
ORG 0
ZERO EQU $
BADNAM DB "Bad command or file name",13,10,"$"
MISNAM DB "Missing file name$"
RENERR DB "Duplicate file name or "
NOTFND DB "File not found$"
EXEBAD DB "Error in EXE file$"
NOSPACE DB "Insufficient disk space",13,10,"$"
FULDIR DB "File creation error",13,10,"$"
OVERWR DB "File cannot be copied onto itself",13,10,"$"
LOSTERR DB "Content of destination lost before copy",13,10,"$"
COPIED DB " File(s) copied$"
DIRMES DB " File(s)$"
TOOBIG DB "Program too big to fit in memory$"
BADDRV DB "Invalid drive specification$"
PAUSMES DB "Strike a key when ready . . . $"
BADSWT DB "Illegal switch",13,10,"$"
WEEKTAB DB "SunMonTueWedThuFriSat"
BADDAT DB 13,10,"Invalid date$"
CURDAT DB "Current date is $"
NEWDAT DB 13,10,"Enter new date: $"
BADTIM DB 13,10,"Invalid time$"
CURTIM DB "Current time is $"
NEWTIM DB 13,10,"Enter new time: $"
SUREMES DB "Are you sure (Y/N)? $"
COMTAB DB 4,"DIR",1
DW OFFSET TRANGROUP:CATALOG
DB 7,"RENAME",1
DW OFFSET TRANGROUP:RENAME
DB 4,"REN",1
DW OFFSET TRANGROUP:RENAME
DB 6,"ERASE",1
DW OFFSET TRANGROUP:ERASE
DB 4,"DEL",1
DW OFFSET TRANGROUP:ERASE
DB 5,"TYPE",1
DW OFFSET TRANGROUP:TYPEFIL
DB 4,"REM",1
DW OFFSET TRANGROUP:COMMAND
DB 5,"COPY",1
DW OFFSET TRANGROUP:COPY
DB 6,"PAUSE",1
DW OFFSET TRANGROUP:PAUSE
DB 5,"DATE",0
DW OFFSET TRANGROUP:DATE
DB 5,"TIME",0
DW OFFSET TRANGROUP:TIME
DB 0 ;Terminate command table
COMBUF DB 128,1,13
TRANDATASIZE EQU $-ZERO
TRANDATA ENDS
;Uninitialized transient data
TRANSPACE SEGMENT BYTE
ORG 0
ZERO = $
DB 128 DUP(?)
TPA DW 1 DUP(?)
RESSEG DW 1 DUP(?)
CHKDRV DB 1 DUP(?)
FILTYP DB 1 DUP(?)
CURDRV DB 1 DUP(?)
PARM1 DB 1 DUP(?)
PARM2 DB 1 DUP(?)
COMSW DW 1 DUP(?)
ARG1S DW 1 DUP(?)
ARG2S DW 1 DUP(?)
FLAGER DB 1 DUP(?)
CFLAG DB 1 DUP(?)
SPECDRV DB 1 DUP(?)
BYTCNT DW 1 DUP(?)
NXTADD DW 1 DUP(?)
LINCNT DB 1 DUP(?)
LINLEN DB 1 DUP(?)
FILECNT DW 1 DUP(?)
EXEFCB LABEL WORD
IDLEN DB 1 DUP(?)
ID DB 8 DUP(?)
COM DB 3 DUP(?)
DEST DB 37 DUP(?)
DESTNAME DB 11 DUP(?)
DIRBUF DB 37 DUP(?)
BITS DW 1 DUP(?)
FULLSCR DW 1 DUP(?)
EXEEND DW 1 DUP(?)
;Header variables for EXE file load
;These are overlapped with COPY variables, below
RUNVAR LABEL WORD
RELPT DW 1 DUP(?)
RELSEG DW 1 DUP(?)
PSIZE LABEL WORD
PAGES DW 1 DUP(?)
RELCNT DW 1 DUP(?)
HEADSIZ DW 1 DUP(?)
DW 1 DUP(?)
LOADLOW DW 1 DUP(?)
INITSS DW 1 DUP(?)
INITSP DW 1 DUP(?)
DW 1 DUP(?)
INITIP DW 1 DUP(?)
INITCS DW 1 DUP(?)
RELTAB DW 1 DUP(?)
RUNVARSIZ EQU $-RUNVAR
DB 80H DUP(?)
STACK LABEL WORD
PRETRLEN EQU $-ZERO ;Used later to compute TRNLEN
ORG RUNVAR-ZERO ;Overlaps EXE variables
SRCPT DW 1 DUP(?)
INEXACT DB 1 DUP(?)
APPEND DB 1 DUP(?)
NOWRITE DB 1 DUP(?)
ASCII DB 1 DUP(?)
PLUS DB 1 DUP(?)
SOURCE DB 11 DUP(?)
TRANSPACESIZE EQU $-ZERO
TRANSPACE ENDS
;START OF RESIDENT PORTION
CODERES SEGMENT
ASSUME CS:RESGROUP,DS:RESGROUP,ES:RESGROUP,SS:RESGROUP
ORG 0
ZERO = $
PARMBUF LABEL WORD
ORG 100H
RSTACK LABEL WORD
PROGSTART:
JMP CONPROC
LTPA DW 0 ;WILL STORE TPA SEGMENT HERE
MYSEG DW 0 ;Put our own segment here
CONTC:
MOV AX,CS
MOV DS,AX
MOV SS,AX
MOV SP,OFFSET RESGROUP:RSTACK
STI
CALL SETVECT
MOV AH,DSKRESET
INT 33 ;Reset disks in case files were open
TEST [BATCH],-1
JZ LODCOM
ASKEND:
MOV DX,OFFSET RESGROUP:ENDBATMES
MOV AH,PRINTBUF
INT 33
MOV AX,0C00H+INCHAR
INT 33
AND AL,5FH
CMP AL,"N"
JZ LODCOM
CMP AL,"Y"
JNZ ASKEND
MOV [BATCH],0
LODCOM:
MOV AX,CS
MOV SS,AX
MOV SP,OFFSET RESGROUP:RSTACK
MOV DS,AX
CALL SETVECT
CALL CHKSUM
CMP DX,[SUM]
JZ HAVCOM
MOV [LOADING],1
CALL LOADCOM
CHKSAME:
CALL CHKSUM
CMP DX,[SUM]
JZ HAVCOM
CALL WRONGCOM
JMP SHORT CHKSAME
HAVCOM:
MOV [LOADING],0
MOV SI,OFFSET RESGROUP:LTPA
MOV DI,OFFSET TRANGROUP:TPA
MOV ES,[TRNSEG]
CLD
MOVSW ;Move TPA segment to transient storage
MOVSW ;Move resident segment too
MOV AX,[MEMSIZ]
MOV WORD PTR ES:[2],AX
JMP DWORD PTR [TRANS]
RESIDENT:
ADD DX,15
MOV CL,4
SHR DX,CL ;Number of paragraphs of new addition
ADD CS:[LTPA],DX
XOR AX,AX
MOV DS,AX
JMP DWORD PTR DS:[80H] ;Pretend user executed INT 20H
DSKERR:
;******************************************************
; THIS IS THE DEFAULT DISK ERROR HANDLING CODE
; AVAILABLE TO ALL USERS IF THEY DO NOT TRY TO
; INTERCEPT INTERRUPT 24H.
;******************************************************
STI
PUSH DS
PUSH CS
POP DS ;Set up local data segment
PUSH DX
CALL CRLF
POP DX
ADD AL,"A" ;Compute drive letter
MOV [DRVLET],AL
TEST AH,80H ;Check if hard disk error
JNZ FATERR
MOV SI,OFFSET RESGROUP:READ
TEST AH,1
JZ SAVMES
MOV SI,OFFSET RESGROUP:WRITE
SAVMES:
LODSW
MOV WORD PTR [IOTYP],AX
LODSW
MOV WORD PTR [IOTYP+2],AX
AND DI,0FFH
CMP DI,12
JBE HAVCOD
MOV DI,12
HAVCOD:
MOV DI,WORD PTR [DI+MESBAS] ;Get pointer to error message
XCHG DI,DX ;May need DX later
MOV AH,PRINTBUF
INT 33 ;Print error type
MOV DX,OFFSET RESGROUP:ERRMES
INT 33
CMP [LOADING],0
JNZ GETCOMDSK
ASK:
MOV DX,OFFSET RESGROUP:REQUEST
MOV AH,PRINTBUF
INT 33
MOV AX,0C00H+INCHAR
INT 33 ;Get response
CALL CRLF
OR AL,20H ;Convert to lower case
MOV AH,0 ;Return code for ignore
CMP AL,"i" ;Ignore?
JZ EXIT
INC AH
CMP AL,"r" ;Retry?
JZ EXIT
INC AH
CMP AL,"a" ;Abort?
JNZ ASK
EXIT:
MOV AL,AH
MOV DX,DI
POP DS
IRET
FATERR:
MOV DX,OFFSET RESGROUP:BADFAT
MOV AH,PRINTBUF
INT 33
MOV DX,OFFSET RESGROUP:DRVNUM
INT 33
MOV AL,2 ;Abort
POP DS
IRET
GETCOMDSK:
MOV DX,OFFSET RESGROUP:NEEDCOM
MOV AH,PRINTBUF
INT 33
MOV AX,0C07H ;Get char without testing or echo
INT 33
JMP LODCOM
CRLF:
MOV DX,OFFSET RESGROUP:NEWLIN
PUSH AX
MOV AH,PRINTBUF
INT 33
POP AX
RET10: RET
LOADCOM:
PUSH DS
MOV DS,[TRNSEG]
MOV DX,100H
MOV AH,SETDMA
INT 33
POP DS
MOV DX,OFFSET RESGROUP:COMFCB
MOV AH,OPEN
INT 33 ;Open COMMAND.COM
OR AL,AL
JZ READCOM
MOV DX,OFFSET RESGROUP:NEEDCOM
PROMPTCOM:
MOV AH,PRINTBUF
INT 33
MOV AX,0C07H ;Get char without testing or echo
INT 33
JMP SHORT LOADCOM
READCOM:
MOV WORD PTR[COMFCB+RR],OFFSET RESGROUP:TRANSTART
XOR AX,AX
MOV WORD PTR[COMFCB+RR+2],AX
MOV [COMFCB],AL ;Use default drive
INC AX
MOV WORD PTR[COMFCB+RECLEN],AX
MOV CX,COMLEN
MOV DX,OFFSET RESGROUP:COMFCB
MOV AH,RDBLK
INT 33
OR AL,AL
JZ RET10
WRONGCOM:
MOV DX,OFFSET RESGROUP:COMBAD
JMP SHORT PROMPTCOM
CHKSUM:
CLD
PUSH DS
MOV DS,[TRNSEG]
MOV SI,100H
MOV CX,COMLEN
SHR CX,1
XOR DX,DX
CHK:
LODSW
ADD DX,AX
LOOP CHK
POP DS
RET
SETVECT:
MOV DX,OFFSET RESGROUP:LODCOM
MOV AX,2522H ;Set Terminate address
INT 21H
MOV DX,OFFSET RESGROUP:CONTC
MOV AX,2523H ;Set Ctrl-C address
INT 21H
MOV DX,OFFSET RESGROUP:DSKERR
MOV AX,2524H ;Set Hard Disk Error address
INT 33
MOV DX,OFFSET RESGROUP:RESIDENT
MOV AX,2527H ;Set Terminate and Stay Resident address
INT 33
RET
RESCODESIZE EQU $-ZERO
CODERES ENDS
;*******************************************************************
;START OF INIT PORTION
;This code is overlayed the first time the TPA is used.
INIT SEGMENT BYTE
ORG 0
ZERO = $
CONPROC:
MOV SP,OFFSET RESGROUP:RSTACK
IF HIGHMEM
MOV AX,WORD PTR DS:[2]
SUB AX,((RESCODESIZE+RESDATASIZE)+15)/16 ;Subtract size of resident
MOV WORD PTR DS:[2],AX
MOV ES,AX
MOV SI,100H
MOV DI,SI
MOV CX,((RESCODESIZE+RESDATASIZE)-100H+1)/2 ;Length of resident in words
REP MOVSW ;Move to end of memory
MOV DS,AX
MOV [LTPA],CS
ENDIF
IF NOT HIGHMEM
MOV AX,CS
ADD AX,((RESCODESIZE+RESDATASIZE)+15)/16 ;Compute segment of TPA
MOV [LTPA],AX
MOV AX,WORD PTR DS:[2]
ENDIF
MOV [MYSEG],DS
MOV [MEMSIZ],AX
SUB AX,TRNLEN ;Subtract size of transient
MOV [TRNSEG],AX
CALL SETVECT
CALL LOADCOM
CALL CHKSUM
MOV [SUM],DX
IF MSVER
IF HIGHMEM
PUSH DS
PUSH CS
POP DS
ENDIF
MOV DX,OFFSET RESGROUP:HEADER
MOV AH,PRINTBUF
INT 33
IF HIGHMEM
POP DS
ENDIF
ENDIF
MOV DX,OFFSET RESGROUP:BATFCB
MOV AH,OPEN
INT 33 ;See if AUTOEXEC.BAT exists
MOV WORD PTR[BATFCB+RECLEN],1 ;Set record length to 1
OR AL,AL ;Zero means file found
JZ DRV0
MOV [BATCH],0 ;Not found--turn off batch job
MOV AX,OFFSET TRANGROUP:DATINIT
MOV WORD PTR[INITADD],AX
MOV AX,[TRNSEG]
MOV WORD PTR[INITADD+2],AX
CALL DWORD PTR DS:[INITADD]
IF IBMVER
MOV DX,OFFSET RESGROUP:HEADER
MOV AH,PRINTBUF
INT 33
ENDIF
DRV0:
JMP HAVCOM
IF MSVER
HEADER DB 13,10,"Command v. 1.17"
IF HIGHMEM
DB "H"
ENDIF
DB 13,10,"$"
ENDIF
IF IBMVER
HEADER DB 13,10,13,10,"The IBM Personal Computer DOS",13,10
DB "Version 1.10 (C)Copyright IBM Corp 1981, 1982",13,10,"$"
DB "Licensed Material - Program Property of IBM"
ENDIF
INITSIZE EQU $-ZERO
INIT ENDS
;This TAIL segment is used to produce a PARA aligned label in the resident
; group which is the location where the transient segments will be loaded
; initialy.
TAIL SEGMENT PARA
ORG 0
TRANSTART LABEL WORD
TAIL ENDS
;********************************************************************
;START OF TRANSIENT PORTION
;This code is loaded at the end of memory and may be overwritten by
;memory-intensive user programs.
TRANCODE SEGMENT PARA
ASSUME CS:TRANGROUP,DS:TRANGROUP,ES:TRANGROUP,SS:TRANGROUP
WSWITCH EQU 1 ;Wide display during DIR
PSWITCH EQU 2 ;Pause (or Page) mode during DIR
VSWITCH EQU 4 ;Verify during COPY
ASWITCH EQU 8 ;ASCII mode during COPY
BSWITCH EQU 10H ;Binary mode during COPY
ORG 0
ZERO = $
ORG 100H ;Allow for 100H parameter area
SETDRV:
MOV AH,SELDRV
INT 21H
COMMAND:
CLD
MOV AX,CS
MOV SS,AX
MOV SP,OFFSET TRANGROUP:STACK
MOV ES,AX
MOV DS,AX
STI
MOV AX,46*100H
MOV DL,0
INT 33 ;Turn off verify after write
MOV AX,CS ;Get segment we're in
SUB AX,[TPA] ;AX=size ot TPA in paragraphs
MOV DX,16
MUL DX ;DX:AX=size of TPA in bytes
OR DX,DX ;See if over 64K
JZ SAVSIZ ;OK if not
MOV AX,-1 ;If so, limit to 65535 bytes
SAVSIZ:
MOV [BYTCNT],AX ;Max no. of bytes that can be buffered
CALL CRLF2
GETCOM:
MOV AH,GETDRV
INT 21H
MOV [CURDRV],AL
ADD AL,"A"
CALL OUT ;Print letter for default drive
MOV AL,SYM
CALL OUT
MOV DS,[RESSEG] ;All batch work must use resident seg.
ASSUME DS:RESGROUP
TEST [BATCH],-1
JNZ READBAT
PUSH CS
POP DS ;Need local segment to point to buffer
ASSUME DS:TRANGROUP
MOV DX,OFFSET TRANGROUP:COMBUF
MOV AH,INBUF
INT 21H ;Get a command
JMP DOCOM
;All batch proccessing has DS set to segment of resident portion
ASSUME DS:RESGROUP
NEEDPARM:
CALL GETBATBYT
CMP AL,"%" ;Check for two consecutive %
JZ SAVBATBYT
CMP AL,13 ;Check for end-of-line
JZ SAVBATBYT
SUB AL,"0"
JB RDBAT ;Ignore parameter reference if invalid
CMP AL,9
JA RDBAT
CBW
MOV SI,AX
SHL SI,1 ;Two bytes per entry
MOV SI,[SI+OFFSET RESGROUP:PARMTAB] ;Get pointer to corresponding parameter
CMP SI,-1 ;Check if parameter exists
JZ RDBAT ;Ignore if it doesn't
MOV AH,OUTCH
RDPARM:
LODSB ;From resident segment
CMP AL,0DH ;Check for end of parameter
JZ RDBAT
STOSB ;To transient segment
MOV DL,AL
INT 33 ;Display paramters too
JMP SHORT RDPARM
PROMPTBAT:
MOV AH,PRINTBUF
MOV DX,OFFSET RESGROUP:NEEDBAT
INT 33 ;Prompt for batch file
MOV AH,PRINTBUF
MOV DX,OFFSET RESGROUP:PROMPT
INT 33
MOV AX,0C00H+INCHAR
INT 33
JMP COMMAND
BADCOMJ1:JMP BADCOM
READBAT:
MOV DX,OFFSET RESGROUP:BATFCB
MOV AH,OPEN
INT 33 ;Make sure batch file still exists
OR AL,AL
JNZ PROMPTBAT ;If OPEN fails, prompt for disk
MOV WORD PTR [BATFCB+RECLEN],1
MOV DX,OFFSET RESGROUP:BATBYT
MOV AH,SETDMA
INT 33
MOV DI,OFFSET TRANGROUP:COMBUF+2
RDBAT:
CALL GETBATBYT
CMP AL,"%" ;Check for parameter
JZ NEEDPARM
SAVBATBYT:
STOSB
CALL OUT ;Display batched command line
CMP AL,0DH
JNZ RDBAT
SUB DI,OFFSET TRANGROUP:COMBUF+3
MOV AX,DI
MOV ES:[COMBUF+1],AL ;Set length of line
CALL GETBATBYT ;Eat linefeed
PUSH CS
POP DS ;Go back to local segment
ASSUME DS:TRANGROUP
DOCOM:
;All segments are local for command line processing
MOV AL,10
CALL OUT
MOV SI,OFFSET TRANGROUP:COMBUF+2
MOV DI,OFFSET TRANGROUP:IDLEN
MOV AX,2901H ;Make FCB with blank scan-off
INT 21H
CMP AL,1 ;Check for ambiguous command name
JZ BADCOMJ1 ;Ambiguous commands not allowed
CMP AL,-1
JNZ DRVGD
JMP DRVBAD
DRVGD:
MOV AL,[DI]
MOV [SPECDRV],AL
MOV AL," "
MOV CX,9
INC DI
REPNE SCASB ;Count no. of letters in command name
MOV AL,9
SUB AL,CL
MOV [IDLEN],AL
MOV DI,81H
MOV CX,0
PUSH SI
COMTAIL:
LODSB
STOSB ;Move command tail to 80H
CMP AL,13
LOOPNZ COMTAIL
NOT CL
MOV BYTE PTR DS:[80H],CL
POP SI
;If the command has 0 parameters must check here for
;any switches that might be present.
;SI -> first character after the command.
MOV [FLAGER],0 ;Set error flag before any calls to switch
CALL SWITCH ;Is the next character a "/"
MOV [COMSW],AX
MOV DI,FCB
MOV AX,2901H
INT 21H
MOV [PARM1],AL ;Save result of parse
CALL SWITCH
MOV [ARG1S],AX
MOV DI,FCB+10H
MOV AX,2901H
INT 21H ;Parse file name
MOV [PARM2],AL ;Save result
CALL SWITCH
MOV [ARG2S],AX
MOV AL,[IDLEN]
MOV DL,[SPECDRV]
OR DL,DL ;Check if drive was specified
JZ OK
JMP DRVCHK
OK: DEC AL ;Check for null command
JNZ FNDCOM
JMP GETCOM
RETSW:
XCHG AX,BX ;Put switches in AX
RET
SWITCH:
XOR BX,BX ;Initialize - no switches set
SWLOOP:
CALL SCANOFF ;Skip any delimiters
CMP AL,"/" ;Is it a switch specifier?
JNZ RETSW ;No -- we're finished
INC SI ;Skip over "/"
CALL SCANOFF
INC SI
;Convert lower case input to upper case
CMP AL,"a"
JB SAVCHR
CMP AL,"z"
JA SAVCHR
SUB AL,20H ;Lower-case changed to upper-case
SAVCHR:
MOV DI,OFFSET TRANGROUP:SWLIST
MOV CX,SWCOUNT
REPNE SCASB ;Look for matching switch
JNZ BADSW
MOV AX,1
SHL AX,CL ;Set a bit for the switch
OR BX,AX
JMP SHORT SWLOOP
BADSW:
MOV [FLAGER],1 ;Record error in switch
JMP SHORT SWLOOP
SWLIST DB "BAVPW"
SWCOUNT EQU $-SWLIST
DRVBAD:
MOV DX,OFFSET TRANGROUP:BADDRV
JMP ERROR
FNDCOM:
MOV SI,OFFSET TRANGROUP:COMTAB ;Prepare to search command table
MOV CH,0
FINDCOM:
MOV DI,OFFSET TRANGROUP:IDLEN
MOV CL,[SI]
JCXZ EXTERNAL
REPE CMPSB
LAHF
ADD SI,CX ;Bump to next position without affecting flags
SAHF
LODSB ;Get flag for drive check
MOV [CHKDRV],AL
LODSW ;Get address of command
JNZ FINDCOM
MOV DX,AX
CMP [CHKDRV],0
JZ NOCHECK
MOV AL,[PARM1]
OR AL,[PARM2] ;Check if either parm. had invalid drive
CMP AL,-1
JZ DRVBAD
NOCHECK:CALL DX
COMJMP: JMP COMMAND
BADCOMJ:JMP BADCOM
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
MOV WORD PTR[COM],4F00H+"C" ;"CO"
MOV BYTE PTR[COM+2],"M"
MOV DX,OFFSET TRANGROUP:IDLEN
MOV AH,OPEN
INT 33 ;Check if command to be executed
MOV [FILTYP],AL ;0 for COM files, -1 for EXE files
OR AL,AL
JZ EXECUTE
MOV WORD PTR[COM],5800H+"E" ;"EX"
MOV BYTE PTR[COM+2],"E"
INT 33 ;Check for EXE file
OR AL,AL
JZ EXECUTE
MOV WORD PTR[COM],4100H+"B" ;"BA"
MOV BYTE PTR[COM+2],"T"
INT 33 ;Check if batch file to be executed
OR AL,AL
JNZ BADCOMJ
BATCOM:
;Batch parameters are read with ES set to segment of resident part
MOV ES,[RESSEG]
ASSUME ES:RESGROUP
MOV DI,OFFSET RESGROUP:PARMTAB
MOV AX,-1
MOV CX,10
REP STOSW ;Zero parameter pointer table
MOV SI,OFFSET TRANGROUP:COMBUF+2
MOV DI,OFFSET RESGROUP:PARMBUF
MOV BX,OFFSET RESGROUP:PARMTAB
EACHPARM:
CALL SCANOFF
CMP AL,0DH
JZ HAVPARM
MOV ES:[BX],DI ;Set pointer table to point to actual parameter
INC BX
INC BX
MOVPARM:
LODSB
CALL DELIM
JZ ENDPARM ;Check for end of parameter
STOSB
CMP AL,0DH
JZ HAVPARM
JMP SHORT MOVPARM
ENDPARM:
MOV AL,0DH
STOSB ;End-of-parameter marker
CMP BX,OFFSET RESGROUP:PARMTAB+20 ;Maximum number of parameters?
JB EACHPARM
HAVPARM:
MOV SI,OFFSET TRANGROUP:IDLEN
MOV DI,OFFSET RESGROUP:BATFCB
MOV CX,16
REP MOVSW ;Move into private batch FCB
XOR AX,AX
PUSH ES
POP DS ;Simply batch FCB setup
ASSUME DS:RESGROUP
MOV WORD PTR[BATFCB+RR],AX
MOV WORD PTR[BATFCB+RR+2],AX ;Zero RR field
INC AX
MOV WORD PTR[BATFCB+RECLEN],AX ;Set record length to 1 byte
MOV [BATCH],AL ;Flag batch job in progress
JMP COMMAND
ASSUME DS:TRANGROUP,ES:TRANGROUP
EXECUTE:
MOV AX,WORD PTR[IDLEN+16]
OR AX,WORD PTR[IDLEN+18] ;See if zero length
JZ BADCOM ;If so, error
XOR AX,AX
MOV WORD PTR[IDLEN+RR],AX
MOV WORD PTR[IDLEN+RR+2],AX ;Set RR field to zero
INC AX
MOV WORD PTR[IDLEN+RECLEN],AX ;Set record length field to 1
MOV DX,[TPA]
MOV BX,DX
MOV AH,SETBASE
INT 21H
TEST [FILTYP],-1 ;Check if file is COM or EXE
JZ COMLOAD
JMP EXELOAD
COMLOAD:PUSH DS
MOV DS,DX
MOV DX,100H
MOV AH,SETDMA
INT 21H
POP DS
MOV CX,[BYTCNT]
SUB CX,100H
MOV DX,OFFSET TRANGROUP:IDLEN
MOV AH,RDBLK
INT 21H
DEC AL
MOV DX,OFFSET TRANGROUP:TOOBIG
JNZ ERROR
;Set up exit conditions
MOV CX,[BYTCNT]
MOV DS,BX
MOV ES,BX
CLI
MOV SS,BX
MOV SP,CX
STI
SUB CX,100H ;Allow some stack space
XOR AX,AX
PUSH AX
MOV AX,100H
PUSH BX
PUSH AX
CALL SETUP
XXX PROC FAR
RET
XXX ENDP