summaryrefslogtreecommitdiff
path: root/v4.0/src/CMD/FORMAT/FOREXEC.ASM
diff options
context:
space:
mode:
Diffstat (limited to 'v4.0/src/CMD/FORMAT/FOREXEC.ASM')
-rw-r--r--v4.0/src/CMD/FORMAT/FOREXEC.ASM637
1 files changed, 637 insertions, 0 deletions
diff --git a/v4.0/src/CMD/FORMAT/FOREXEC.ASM b/v4.0/src/CMD/FORMAT/FOREXEC.ASM
new file mode 100644
index 0000000..46026cb
--- /dev/null
+++ b/v4.0/src/CMD/FORMAT/FOREXEC.ASM
@@ -0,0 +1,637 @@
1page ,132 ;
2;
3
4;*****************************************************************************
5;*****************************************************************************
6;UTILITY NAME: FORMAT.COM
7;
8;MODULE NAME: FOREXEC.SAL
9;
10;
11;
12; ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
13; ³EXEC_FS_FORMAT³
14; ÀÄÂÄÄÄÄÄÄÄÄÄÄÄÄÙ
15; ³
16; ³ÚÄÄÄÄÄÄ¿
17; ôShrink³
18; ³ÀÄÄÄÄÄÄÙ
19; ³ÚÄÄÄÄÄÄÄÄÄÄ¿
20; ôSetup_EXEC³
21; ³ÀÄÄÄÄÄÄÄÄÄÄÙ
22; ³ÚÄÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄÄ¿
23; ôEXEC_ArgVÃÄÄÄÄÄÄÄÄÄÄ´EXEC_Program³
24; ³ÀÄÄÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÄÙ
25; ³ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄÄ¿
26; ôEXEC_Cur_DirectoryÃÄ´EXEC_Program³
27; ³ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÄÙ
28; ³ÚÄÄÄÄÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄÄ¿
29; À´EXEC_RoutineÃÄÄÄÄÄÄÄ´Build_Path_And_EXECÃÄ´EXEC_Program³
30; ÀÄÄÄÄÄÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÄÙ
31;
32; Change List: AN000 - New code DOS 3.3 spec additions
33; AC000 - Changed code DOS 3.3 spec additions
34;*****************************************************************************
35;*****************************************************************************
36
37title DOS 3.30 FORMAT EXEC Module
38
39IF1
40 %OUT ASSEMBLING: DOS 3.3 FORMAT EXEC LOADER
41 %OUT
42ENDIF
43
44code segment public para 'code'
45 assume cs:code
46code ends
47
48;
49;*****************************************************************************
50; Include files
51;*****************************************************************************
52;
53
54.xlist
55INCLUDE FORCHNG.INC
56INCLUDE FORMACRO.INC
57INCLUDE SYSCALL.INC
58INCLUDE FOREQU.INC
59.list
60
61;
62;*****************************************************************************
63; Public Data
64;*****************************************************************************
65;
66
67 Public Drive_Letter_Msg
68
69;
70;*****************************************************************************
71; Public Routines
72;*****************************************************************************
73;
74
75
76IF FSExec ;an018; dms;if /FS: desired
77
78 Public EXEC_FS_Format
79
80ENDIF ;FSExec ;an018; dms;end /FS: conditional
81
82 Extrn GetFSiz:near
83
84
85;
86;*****************************************************************************
87; External Data Declarations
88;*****************************************************************************
89;
90
91 extrn ExitStatus:Byte
92 extrn Fatal_Error:Byte
93 extrn FS_String_Buffer:Byte
94 extrn msgEXECFailure:Byte
95 extrn PSP_Segment:Word
96 extrn drive:byte
97
98;
99;****************************************************************************
100; Structures
101;****************************************************************************
102;
103
104
105Exec_Block_Parms struc
106Segment_Env dw 0
107Offset_Command dw 0
108Segment_Command dw 0
109Offset_FCB1 dw 0
110Segment_FCB1 dw 0
111Offset_FCB2 dw 0
112Segment_FCB2 dw 0
113
114Exec_Block_Parms ends
115
116
117;
118;****************************************************************************
119; Equates
120;****************************************************************************
121;
122
123
124String_Done equ 0
125No_Error equ 0
126Error equ 1
127Stderr equ 2
128Stack_Space equ 02eh ;an000; dms; IBM addition ROM paras
129
130;
131;****************************************************************************
132; PSP Area
133;****************************************************************************
134;
135
136PSP segment public para 'DUMMY'
137
138org 2Ch
139PSP_ENV_SEGMENT label word
140
141FCB1 equ 5Ch
142
143FCB2 equ 6Ch
144
145org 80h
146Command_Line label byte
147
148
149PSP ends
150
151;
152;****************************************************************************
153; Data Area
154;****************************************************************************
155;
156
157data segment public para 'DATA'
158 assume ds:data,es:nothing
159
160Exec_Block Exec_Block_Parms <>
161EXEC_Path db 66 dup(0)
162
163Drive_Letter_Msg db "A:",0 ;Drive for exec fail message
164
165SP_Save dw ? ;an000; dms;
166SS_Save dw ? ;an000; dms;
167
168
169;These next two should stay togather
170; ---------------------------------------
171 ;
172Path_String db "PATH=" ; ;AN000;
173Len_Path_String equ $ - Path_String ; ;AN000;
174 ;
175;----------------------------------------
176
177
178
179
180;These should stay togather
181; ---------------------------------------
182 ;
183Search_FORMAT db "FORMAT" ; ;AC000;
184Len_Search_FORMAT equ $ - Search_FORMAT ; ; ;
185Search_Format_End equ $
186 ; ; ;
187;----------------------------------------
188
189
190;These next two should stay togather
191; ---------------------------------------
192
193
194
195
196
197data ends
198
199code segment public para 'code'
200 assume cs:code,ds:data
201
202;
203;****************************************************************************
204; Main Routine
205;****************************************************************************
206;
207;
208;
209;
210;
211
212IF FSExec ;an018; dms;if /FS: desired
213
214
215Procedure Exec_FS_Format ; ;AC000;
216
217 Set_Data_Segment ;
218 call Set_FCB1_Drive ;an000;dms;
219 call Shrink ; ; ;
220 mov al,ExitStatus ;Setblock fail? ;AC000;
221 cmp al,Error ; " " " " ; ;
222; $IF NE ;Nah, keep crusin! ;AN000;
223 JE $$IF1
224 call Setup_Exec ; ; ;
225 call Exec_Argv ;try exec from dir BASIC loaded ; ;
226 mov al,ExitStatus ; ;AC000;
227 cmp al,Error ; ; ;
228; $IF E,AND ; ;AC000;
229 JNE $$IF2
230 call Exec_Cur_Directory ; ; ;
231 mov al,ExitStatus ;Try exec from cur directory ;AC000;
232 cmp al,Error ; ; ;
233; $IF E,AND ; ;AC000;
234 JNE $$IF2
235 call EXEC_Routine ; ; ;
236 mov al,ExitStatus ; ;AC000;
237 cmp al,Error ; ; ;
238; $IF E ; ;AC000;
239 JNE $$IF2
240 ; mov bl,FCB1 ;Get target drive from FCB
241 ; mov bl,Drive ;an000;dms;
242 push ds ;an000;dms;save ds
243 push si ;an000;dms;save si
244 mov si,PSP_Segment ;an000;dms;get psp
245 mov ds,si ;an000;dms;put psp in ds
246 assume ds:PSP ;an000;dms;
247
248 mov si,FCB1 ;an000;dms;ptr to 1st. FCB
249 mov bl,byte ptr ds:[si] ;an000;dms;get drive ID
250
251 pop si ;an000;dms;restore si
252 pop ds ;an000;dms;restore ds
253 Set_Data_Segment ;an000;dms;set segments
254
255 cmp bl,0 ;Is it default drive? ;AN000;
256; $IF E ;Yes, turn it into drive letter ;AN000;
257 JNE $$IF3
258 push ax ;Save exit code ;AN000;
259 DOS_Call Get_Default_Drive ;Get the default drive ;AN000;
260 add al,"A" ;Turn into drive letter ;AN000;
261 mov Drive_Letter_Msg,al ;Save it in message ;AN000;
262 pop ax ;Get return code back ;AN000;
263; $ELSE ;Not default, A=1 ;AN000;
264 JMP SHORT $$EN3
265$$IF3:
266 add bl,"A"-1 ;Convert to drive letter ;AN000;
267 mov Drive_Letter_Msg,bl ; ;AN000;
268; $ENDIF ;AN000;
269$$EN3:
270 Message msgEXECFailure ; ;AC000;
271; $ELSE ; ;AN000;
272 JMP SHORT $$EN2
273$$IF2:
274 DOS_Call WaitProcess ; ;AC000;
275 mov ExitStatus,al ; ; ;
276; $ENDIF ; ;AN000;
277$$EN2:
278; $ENDIF
279$$IF1:
280 mov Fatal_Error,YES ;Not really, indicates FS used ;AN000;
281 ret ; ; ;
282
283Exec_FS_Format endp
284
285
286;
287;****************************************************************************
288; Shrink
289;****************************************************************************
290;
291;
292;
293;
294
295
296Procedure Shrink ; ;AC000;
297
298 mov ax,cs ;an000; dms;get code segment
299 mov bx,ds ;an000; dms;get data segment
300 sub ax,bx ;an000; dms;data seg size
301 mov bx,ax ;an000; dms;save paras
302 mov ax,offset End_Program ;Get the offset of end of loader; ;
303 mov cl,4 ;Div by 16 to get para's ; ;
304 shr ax,cl ; ; ;
305 add bx,ax ;an000; dms;add in code space
306 add bx,Stack_Space ;an000; dms;adjust for stack
307 add bx,11h ;an000; dms;give PSP space
308 mov ax,PSP_Segment
309 mov es,ax
310 assume es:nothing
311
312 DOS_Call SetBlock ; ;AC000;
313; $IF C ;If didn't work, quit ;AC000;
314 JNC $$IF9
315 Message msgEXECFailure ; ; ;
316 mov ExitStatus,Error ;Bad stuff, time to quit ;AN000;
317; $ENDIF ; ;AN000;
318$$IF9:
319 ret ; ; ;
320
321Shrink endp ; ;AN000;
322
323
324;
325;****************************************************************************
326; Setup_Exec
327;****************************************************************************
328;
329;
330;
331;
332
333Procedure Setup_Exec ; ;AC000;
334
335 Set_Data_Segment
336 mov ax,PSP_Segment ;Get segment of PSP ;AN000;
337 mov ds,ax ; " " " " ;AN000;
338 ; ;
339 assume ds:PSP
340 ;Setup dword pointer to command line to be passed
341
342 mov es:Exec_Block.Segment_Command,ax ;Segment for command line ; ;
343 mov es:Exec_Block.Offset_Command,offset ds:Command_Line ; ; ;
344
345 ;Setup dword pointer to first FCB to be passed
346
347 mov es:Exec_Block.Segment_FCB1,ax ;Segment for FCB1 ; ;
348 mov es:Exec_Block.Offset_FCB1,offset ds:FCB1 ;Offset of FCB at 05Ch ; ;
349
350 ;Setup dword pointer to second FCB to be passed ; ;
351
352 mov es:Exec_Block.Segment_FCB2,ax ;Segment for FCB2 ; ;
353 mov es:Exec_Block.Offset_FCB2,offset ds:FCB2 ;Offset of FCB at 06Ch ; ;
354
355 ;Setup segment of Environment string, get from PSP ; ;
356
357 mov ax,ds:PSP_Env_Segment ; ; ;
358 mov es:Exec_Block.Segment_Env,ax ; ; ;
359 Set_Data_Segment
360 ret ; ; ;
361
362
363Setup_EXEC endp ; ;AN000;
364
365;
366;****************************************************************************
367; Exec_Argv
368;****************************************************************************
369;
370; Read the environment to get the Argv(0) string, which contains the drive,
371; path and filename that was loaded for FORMAT.COM. This will be used to find
372; the xxxxxfmt.exe, assuming that it is in the same location or path as
373; FORMAT.COM
374;
375
376Procedure EXEC_Argv ; ;AC000;
377
378 Set_Data_Segment ;DS,ES = DATA
379 cld ; ; ;
380 mov ax,Exec_Block.Segment_Env ;Get the environment ; ;
381 mov ds,ax ;Get addressability ; ;
382
383 assume ds:nothing
384
385 xor si,si ;Start at beginning ; ;
386; $DO ;Find argv(0) location ;AN000;
387$$DO11:
388; $DO ;Look for 0 ;AN000;
389$$DO12:
390 inc si ;Get character ; ;
391 cmp byte ptr [si-1],0 ;Find string seperator? ; ;
392; $ENDDO E ;Yep ;AC000;
393 JNE $$DO12
394 inc si ;Get next char ; ;
395 cmp byte ptr [si-1],0 ;Are we at Argv(0)? (00?) ; ;
396; $ENDDO E ;Yes if we found double 0's ;AC000;
397 JNE $$DO11
398 add si,2 ;Skip the word count ; ;
399 mov di,si ;Save where string starts ; ;
400; $DO ;Find length of Argv(0) string ;AN000;
401$$DO15:
402 inc si ;Get char ; ;
403 cmp byte ptr [si-1],0 ;Is it the end? ; ;
404; $ENDDO E ;End found if 0 found ;AC000;
405 JNE $$DO15
406 mov cx,si ;Get number of bytes in string ; ;
407 sub cx,di ;Put in cx reg for rep count ; ;
408 mov si,di ;Point to path ; ;
409 mov di,offset es:EXEC_Path ;Point to where to put it ; ;
410 rep movsb ;Move the string ; ;
411 Set_Data_Segment ; ;AN000'
412 dec di ;Point at end of ArgV string ; ;
413 std ;Look backwards ;AN000;
414; $DO ;Find 'FORMAT' in ARGV string ;AC000;
415$$DO17:
416 mov cx,Len_Search_FORMAT ;Get length to compare ;AC000;
417 mov si,offset Search_FORMAT_End-1 ;Look at comp string from end ;AC000;
418 repe cmpsb ;See if same string ;AC000;
419; $ENDDO E ; ;AC000;
420 JNE $$DO17
421 mov si,offset FS_String_Buffer ; ;AN000;
422 inc di ;DI = replacement point-1 ;AC000;
423 cld ;Set direction flag back ;AN000;
424 mov cx,Len_FS_String_Buffer ;Length of string to move ;AN000;
425 rep movsb ;Build part of the path ; ;
426 call EXEC_Program ; ; ;
427 ret ; ; ;
428
429EXEC_ArgV endp ; ;AN000;
430
431;
432;****************************************************************************
433; EXEC_Program
434;****************************************************************************
435;
436;
437;
438;
439
440Procedure EXEC_Program ; ;AC000;
441
442 Set_Data_Segment ; ;AN000;
443 mov ExitStatus,No_Error ;Setup to Exec the file ; ;
444 mov dx,offset Exec_Path ; ; ;
445 mov bx,offset Exec_Block ; ; ;
446 mov al,0 ; ; ;
447 mov word ptr SP_Save,sp ;an000; dms;save sp
448 mov word ptr SS_Save,ss ;an000; dms;save ss
449
450 DOS_Call Exec ; ;AC000;
451
452 cli ;an000; dms;turn off int's
453 mov sp,word ptr SP_Save ;an000; dms;retrieve sp
454 mov ss,word ptr SS_Save ;an000; dms;retrieve ss
455 sti ;an000; dms;turn on int's
456
457
458; $IF C ;CY means failure ;AC000;
459 JNC $$IF19
460 mov ExitStatus,Error ;Set error code ; ;
461; $ENDIF ; ;AN000;
462$$IF19:
463 ret ; ; ;
464
465EXEC_Program endp ; ;AN000;
466
467
468;
469;****************************************************************************
470; EXEC_Routine
471;****************************************************************************
472;
473;
474;
475;
476
477Procedure EXEC_Routine ; ;AN000;
478
479 Set_Data_Segment ; ;AN000;
480 mov ExitStatus,Error ;Assume the worst ; ;
481 cld ; ; ;
482 push ds ; ; ;
483 mov ax,Exec_Block.Segment_Env ;Get the environment ; ;
484 mov ds,ax ;Get addressability ; ;
485 assume ds:nothing ;
486
487 xor si,si ;Start at beginning ; ;
488; $SEARCH ; ;AC000;
489$$DO21:
490 cmp word ptr ds:[si],0 ;End of the Evironment? ; ;
491; $EXITIF E ;Reached end, no more look ;AC000;
492 JNE $$IF21
493 ; ; ;
494; $ORELSE ;Look for 'PATH=' in environment;AN000;
495 JMP SHORT $$SR21
496$$IF21:
497 mov di,offset Path_String ; " " " " ;AC000;
498 mov cx,Len_Path_String ; " " " " ;AC000;
499 repe cmpsb ; " " " " ;AC000;
500; $LEAVE E ;Found if EQ ;AC000;
501 JE $$EN21
502; $ENDLOOP ;Found PATH in environment ;AC000;
503 JMP SHORT $$DO21
504$$EN21:
505 call Build_Path_And_Exec ; ;AN000;
506; $ENDSRCH ; ; ;
507$$SR21:
508 pop ds ; ; ;
509 ret ; ; ;
510
511EXEC_Routine endp
512
513;
514;****************************************************************************
515; Build_Path_For_EXEC
516;****************************************************************************
517;
518;
519;
520;
521
522Procedure Build_Path_And_Exec ; ;AN000;
523
524; $DO ; ;AC000;
525$$DO27:
526 cmp byte ptr ds:[si],0 ;All path entries done? ; ;
527; $IF NE ; ;AC000;
528 JE $$IF28
529 mov di,offset EXEC_Path ;Point at where to put path ; ;
530 mov byte ptr es:[di],0 ;End path just in case ; ;
531; $DO ; ;AC000;
532$$DO29:
533 cmp byte ptr ds:[si],0 ;End of Path? ; ;
534; $LEAVE E ; ;AC000;
535 JE $$EN29
536 cmp byte ptr ds:[si],';' ;End of entry? ; ;
537; $if e ;yes ;an000; dms;
538 JNE $$IF31
539 inc si ;point to next character ;an000; dms;
540 jmp EXIT_BPE_LOOP ;exit loop ;an000; dms;
541; $endif ; ;an000; dms;
542$$IF31:
543 movsb ;Put char in path string ; ;
544; $ENDDO ; ;AN000;
545 JMP SHORT $$DO29
546$$EN29:
547
548EXIT_BPE_LOOP: ; ;an000; dms;
549 ;Path filled in,get backslash ; ;
550 cmp byte ptr ds:[si-1],0 ;Any path there? ; ;
551; $IF NE ; ;AC000;
552 JE $$IF34
553 ;Nope ; ;
554 cmp byte ptr ds:[si-1],"\" ;Need a backslash? ; ;
555; $IF NE ; ;AC000;
556 JE $$IF35
557 mov byte ptr es:[di],"\" ;Yes, put one in ; ;
558 inc di ;Line it up for next stuff ; ;
559 inc si ; ; ;
560; $ENDIF ; ;AN000;
561$$IF35:
562 push si ;Save place in path
563 push ds ;Save segment for environment ;AN000;
564 push es ;Xchange ds/es ;an000; dms;
565 pop ds ; ;an000; dms;
566 mov si,offset FS_String_Buffer ;Fill in filename ; ;
567 mov cx, Len_FS_String_Buffer ; ; ;
568 rep movsb ; ; ;
569 call Exec_Program ; ; ;
570 cmp ExitStatus,No_Error ;E if EXEC okay ;AN000;
571 pop ds ;Get Env segment back ; ;
572 pop si ;Get place in path back
573; $ENDIF ;E if all paths done ;AN000;
574$$IF34:
575; $ENDIF ;E if all paths done ;AN000;
576$$IF28:
577; $ENDDO E ;Exit if E ;AN000;
578 JNE $$DO27
579 ret ; ;AN000;
580
581Build_Path_And_EXEC Endp ; ;AN000;
582
583
584
585;
586;****************************************************************************
587; Exec_Cur_Directory
588;****************************************************************************
589;
590;
591;
592;
593
594Procedure Exec_Cur_Directory ; ;AC000;
595
596 Set_Data_Segment ; ;AN000;
597 mov si,offset FS_String_Buffer ;Setup path for current dir ; ;
598 mov di,offset EXEC_Path ; ; ;
599 mov cx,Len_FS_String_Buffer ; ; ;
600 rep movsb ; ; ;
601 call EXEC_Program ; ; ;
602 ret ; ; ;
603
604EXEC_Cur_Directory endp ; ;AN000;
605
606;=========================================================================
607; Set_FCB1_Drive : This routine sets the 1st. byte of the FCB1,
608; the drive identifier, to the default drive.
609;=========================================================================
610
611Procedure Set_FCB1_Drive ;an000;dms;set drive ID
612
613 push ds ;an000;dms;save ds
614 push si ;an000;dms;save si
615
616 mov si,PSP_Segment ;an000;dms;get segment of PSP
617 mov ds,si ;an000;dms;put it in ds
618 assume ds:PSP ;an000;dms;
619 mov si,FCB1 ;an000;dms;ptr to FCB1
620 mov byte ptr ds:[si],00h ;an000;dms;set drive ID to
621 ; default drive
622 pop si ;an000;dms;restore si
623 pop ds ;an000;dms;restore ds
624 Set_Data_Segment ;an000;dms;set up segmentation
625 ret ;an000;dms;
626
627Set_FCB1_Drive endp ;an000;dms;
628
629ENDIF ;FSExec ;an018; dms;end /FS: conditional
630 ; assembly
631
632public End_Program
633End_Program label byte
634
635code ends
636 end
637 \ No newline at end of file