     1                                  ;	SCCSID = @(#)search.asm 1.1 85/04/10
     2                                  ;TITLE	SEARCH - Directory scan system calls
     3                                  ;NAME	SEARCH
     4                                  
     5                                  ;
     6                                  ;
     7                                  ; Directory search system calls.  These will be passed direct text of the
     8                                  ; pathname from the user.  They will need to be passed through the macro
     9                                  ; expander prior to being sent through the low-level stuff.  I/O specs are
    10                                  ; defined in DISPATCH.	The system calls are:
    11                                  ;
    12                                  ;
    13                                  ;   $Dir_Search_First	  written
    14                                  ;   $Dir_Search_Next	  written
    15                                  ;   $Find_First 	  written
    16                                  ;   $Find_Next		  written
    17                                  ;   PackName		  written
    18                                  ;
    19                                  ;   Modification history:
    20                                  ;
    21                                  ;	Created: ARR 4 April 1983
    22                                  ;
    23                                  
    24                                  [list -]
    24          ******************       warning: redefining multi-line macro `struc' [-w+pp-macro-redef-multi]
    14                              <4> [list -]
    14                              <3> [list -]
     3                              <2> 
     4                              <2> addsection DOSSTART, align=16 PUBLIC class=DOSSTART
     5                              <2> ; (no prior section) ; DOSSTART		ENDS
     6                              <2> 
     7                              <2> addsection DOSSTARTJUMP, align=1 PUBLIC class=START
     8                              <2> ; (no prior section) ; DOSSTARTJUMP		ENDS
     9                              <2> 
    10                              <2> addsection CONSTANTS, align=2 PUBLIC class=CONST
    11                              <2> ; (no prior section) ; CONSTANTS	ENDS
    12                              <2> 
    13                              <2> addsection DATA, align=2 PUBLIC class=DATA
    14                              <2> ; (no prior section) ; DATA		ENDS
    15                              <2> 
    16                              <2> addsection TABLE, align=2 PUBLIC class=TABLE
    17                              <2> ; (no prior section) ; TABLE		ENDS
    18                              <2> 
    19                              <2> addsection DOSDATATABLE, align=2 PUBLIC class=DOSDATACODE
    20                              <2> ; (no prior section) ; DOSDATATABLE		ENDS
    21                              <2> 
    22                              <2> addsection DOSDATACODE, align=1 PUBLIC class=DOSDATACODE
    23                              <2> ; (no prior section) ; DOSDATACODE		ENDS
    24                              <2> 
    25                              <2> addsection DOSBIODATA, align=2 PUBLIC class=DOSBIODATA
    26                              <2> 
    27                              <2> addsection LAST, align=16 PUBLIC class=LAST
    28                              <2> ; (no prior section) ; LAST		ENDS
    29                              <2> 
    30                              <2> group DOSGROUP DOSSTART DOSSTARTJUMP CONSTANTS DATA TABLE DOSDATATABLE DOSDATACODE DOSBIODATA LAST
     8                              <1> 
     9                              <1> %include "dcodeseg.nas"
     1                              <2> 
     2                              <2> %ifndef DCODESEGNAS
     3                              <2> %assign DCODESEGNAS 1
     4                              <2> 
     5                              <2> section DOSCODETABLE align=2 PUBLIC class=DOSCODE
     6                              <2> ; (no prior section) ; DOSCODETABLE		ENDS
     7                              <2> section DOSCODECODE align=1 PUBLIC class=DOSCODE
     8                              <2> ; (no prior section) ; DOSCODECODE		ENDS
     9                              <2> section DOSBIOCODE align=2 PUBLIC class=DOSCODE
    10                              <2> section BIOCODE	align=2 PUBLIC class=DOSCODE
    11                              <2> 
    12                              <2> %ifnidni DOSENTRYGROUP, DOSCODEGROUP
    13                              <2>  group DOSCODEGROUP DOSCODETABLE DOSCODECODE DOSBIOCODE BIOCODE
    14                              <2> %endif
    15                              <2> 
    16                              <2> %endif
    10                              <1> 
    11                              <1> section LAST
    12                              <1> ; (no prior section) ; LAST		ENDS
    29                                  
    30                                  [list +]
    31                                  section DOSCODECODE
    32                                  [list -]
    32          ******************       warning: out: ... for DOS Version 4.00 ... [-w+user]
    32          ******************       warning: out: BPB.INC... [-w+user]
    32          ******************       warning: out: ... CLONE version build switch on ... [-w+user]
    32          ******************       warning: out: DEVSYM.INC... [-w+user]
    41                                  
    42                                  	i_need	SEARCHBUF,53
    43                                  	i_need	SATTRIB,BYTE
    44                                  	I_Need	OpenBuf,128
    45                                  	I_need	DMAAdd,DWORD
    46                                  	I_need	THISFCB,DWORD
    47                                  	I_need	CurDrv,BYTE
    48                                  	I_need	EXTFCB,BYTE
    49                                  	I_need	Fastopenflg,BYTE
    50                                  	I_need	DOS34_FLAG,WORD
    51                                  
    52                                  ; Inputs:
    53                                  ;	DS:DX Points to unopenned FCB
    54                                  ; Function:
    55                                  ;	Directory is searched for first matching entry and the directory
    56                                  ;	entry is loaded at the disk transfer address
    57                                  ; Returns:
    58                                  ;	AL = -1 if no entries matched, otherwise 0
    59                                  
    60                                  	procedure D_DIR_SEARCH_FIRST,NEAR
    60          ******************       warning: proc D_DIR_SEARCH_FIRST... [-w+user]
    61                                  ASSUME	DS:NOTHING,ES:NOTHING,SS:DOSGroup
    62                                  
    63 00000000 368916[0000]            	MOV	WORD PTR [ss:THISFCB],DX
    64 00000005 368C1E[0200]            	MOV	WORD PTR [ss:THISFCB+2],DS
    65 0000000A 89D6                    	MOV	SI,DX
    66 0000000C 803CFF                  	CMP	BYTE PTR [SI],0FFH
    67 0000000F 7503                    	JNZ	NORMFCB4
    68 00000011 83C607                  	ADD	SI,7			; Point to drive select byte
    69                                  NORMFCB4:
    70 00000014 FF34                    	SaveReg <word [SI]>			; Save original drive byte for later
    71 00000016 1607                    	Context ES			; get es to address DOSGroup
    72                                  DOSGroup equ DOSGROUP	; NASM port equate
    73 00000018 BF[0000]                	MOV	DI,OFFSET OpenBuf wrt DOSGroup  ; appropriate buffer
    74 0000001B E8(0000)                	invoke	TransFCB		; convert the FCB, set SATTRIB EXTFCB
    75 0000001E 7304                    	JNC	SearchIt		; no error, go and look
    76 00000020 5B                      	RestoreReg <BX> 		; Clean stack
    77                                  ;
    78                                  ; Error code is in AX
    79                                  ;
    80 00000021 E9(0000)                	transfer FCB_Ret_Err		; error
    81                                  
    82                                  SearchIt:
    83 00000024 161F                    	Context DS			; get ready for search
    84 00000026 FF36[0000]FF36-         	SaveReg <<WORD PTR [DMAAdd]>, <WORD PTR [DMAAdd+2]>>
    84 0000002C [0200]             
    85 0000002E C706[0000][0000]        	MOV	WORD PTR [DMAAdd],OFFSET SEARCHBUF wrt DOSGroup
    86 00000034 8C1E[0200]              	MOV	WORD PTR [DMAAdd+2],DS
    87 00000038 E88B01                  	invoke	GET_FAST_SEARCH 	; search
    88 0000003B 8F06[0200]8F06-         	RestoreReg <<WORD PTR [DMAAdd+2]>, <WORD PTR [DMAAdd]>>
    88 00000041 [0000]             
    89 00000043 7303                    	JNC	SearchSet		; no error, transfer info
    90 00000045 5B                      	RestoreReg <BX> 		; Clean stack
    91                                  ;
    92                                  ; Error code is in AX
    93                                  ;
    94 00000046 EBD9                    	transfer FCB_Ret_Err
    95                                  
    96                                  ;
    97                                  ; The search was successful (or the search-next).  We store the information
    98                                  ; into the user's FCB for continuation.
    99                                  ;
   100                                  SearchSet:
   101 00000048 BE[0000]                	MOV	SI,OFFSET SEARCHBUF wrt DOSGroup
   102 0000004B C43E[0000]              	LES	DI,[THISFCB]		; point to the FCB
   103 0000004F F606[0000]FF            	TEST	byte [EXTFCB],0FFH		;
   104 00000054 7403                    	JZ	NORMFCB1
   105 00000056 83C707                  	ADD	DI,7			; Point past the extension
   106                                  NORMFCB1:
   107 00000059 5B                      	RestoreReg <BX> 		; Get original drive byte
   108 0000005A 08DB                    	OR	BL,BL
   109 0000005C 7506                    	JNZ	SearchDrv
   110 0000005E 8A1E[0000]              	MOV	BL,[CurDrv]
   111 00000062 FEC3                    	INC	BL
   112                                  SearchDrv:
   113 00000064 AC                      	LODSB				; Get correct search contin drive byte
   114 00000065 86C3                    	XCHG	AL,BL			; Search byte to BL, user byte to AL
   115 00000067 47                      	INC	DI
   116                                  ;	STOSB				; Store the correct "user" drive byte
   117                                  					;  at the start of the search info
   118 00000068 B90A00                  	MOV	CX,20/2
   119 0000006B F3A5                    	REP	MOVSW			; Rest of search cont info, SI -> entry
   120 0000006D 86C3                    	XCHG	AL,BL			; User drive byte back to BL, search
   121                                  					;   byte to AL
   122 0000006F AA                      	STOSB				; Search contin drive byte at end of
   123                                  					;   contin info
   124 00000070 C43E[0000]              	LES	DI,[DMAAdd]
   125 00000074 F606[0000]FF            	TEST	byte [EXTFCB],0FFH
   126 00000079 740E                    	JZ	NORMFCB2
   127 0000007B B0FF                    	MOV	AL,0FFH
   128 0000007D AA                      	STOSB
   129 0000007E FEC0                    	INC	AL
   130 00000080 B90500                  	MOV	CX,5
   131 00000083 F3AA                    	REP	STOSB
   132 00000085 A0[0000]                	MOV	AL,[SATTRIB]
   133 00000088 AA                      	STOSB
   134                                  NORMFCB2:
   135 00000089 88D8                    	MOV	AL,BL			; User Drive byte
   136 0000008B AA                      	STOSB
   137                                   %IF  DBCS									;AN000;
   138                                  	MOVSW				; 2/13/KK				;AN000;
   139                                  	CMP	BYTE PTR [ES:DI-2],5	; 2/13/KK				;AN000;
   140                                  	JNZ	NOTKTRAN		; 2/13/KK				;AN000;
   141                                  	MOV	BYTE PTR [ES:DI-2],0E5H ; 2/13/KK				;AN000;
   142                                  NOTKTRAN:				; 2/13/KK				;AN000;
   143                                  	MOV	CX,15			; 2/13/KK				;AN000;
   144                                   %ELSE										;AN000;
   145 0000008C B91000                  	MOV	CX,16			; 32 / 2 words of dir entry		;AN000;
   146                                   %ENDIF										;AN000;
   147 0000008F F3A5                    	REP	MOVSW
   148 00000091 E9(0000)                	transfer FCB_Ret_OK
   149                                  
   150                                  EndProc D_DIR_SEARCH_FIRST
   150          ******************       warning: ***** Possible stack size error in D_DIR_SEARCH_FIRST ***** [-w+user]
   151                                  
   152                                  ; Inputs:
   153                                  ;	DS:DX points to unopenned FCB returned by $DIR_SEARCH_FIRST
   154                                  ; Function:
   155                                  ;	Directory is searched for the next matching entry and the directory
   156                                  ;	entry is loaded at the disk transfer address
   157                                  ; Returns:
   158                                  ;	AL = -1 if no entries matched, otherwise 0
   159                                  
   160                                  	procedure D_DIR_SEARCH_NEXT,NEAR
   160          ******************       warning: proc D_DIR_SEARCH_NEXT... [-w+user]
   161                                  ASSUME	DS:NOTHING,ES:NOTHING,SS:DOSGroup
   162                                  
   163 00000094 368916[0000]            	MOV	WORD PTR [ss:THISFCB],DX
   164 00000099 368C1E[0200]            	MOV	WORD PTR [ss:THISFCB+2],DS
   165 0000009E 36C606[0000]00          	MOV	byte [ss:SATTRIB],0
   166 000000A4 36C606[0000]00          	MOV	byte [ss:EXTFCB],0
   167 000000AA 1607                    	Context ES
   168 000000AC BF[0000]                	MOV	DI,OFFSET SEARCHBUF wrt DOSGroup
   169 000000AF 89D6                    	MOV	SI,DX
   170 000000B1 803CFF                  	CMP	BYTE PTR [SI],0FFH
   171 000000B4 750D                    	JNZ	NORMFCB6
   172 000000B6 83C606                  	ADD	SI,6
   173 000000B9 AC                      	LODSB
   174 000000BA 36A2[0000]              	MOV	[ss:SATTRIB],AL
   175 000000BE 36FE0E[0000]            	DEC	byte [ss:EXTFCB]
   176                                  NORMFCB6:
   177 000000C3 AC                      	LODSB				; Get original user drive byte
   178 000000C4 50                      	SaveReg <AX>			; Put it on stack
   179 000000C5 8A4414                  	MOV	AL,[SI+20]		; Get correct search contin drive byte
   180 000000C8 AA                      	STOSB				; Put in correct place
   181 000000C9 B90A00                  	MOV	CX,20/2
   182 000000CC F3A5                    	REP	MOVSW			; Transfer in rest of search contin info
   183 000000CE 161F                    	Context DS
   184 000000D0 FF36[0000]FF36-         	SaveReg <<WORD PTR [DMAAdd]>, <WORD PTR [DMAAdd+2]>>
   184 000000D6 [0200]             
   185 000000D8 C706[0000][0000]        	MOV	WORD PTR [DMAAdd],OFFSET SEARCHBUF wrt DOSGroup
   186 000000DE 8C1E[0200]              	MOV	WORD PTR [DMAAdd+2],DS
   187 000000E2 E8(0000)                	invoke	DOS_SEARCH_NEXT 	; Find it
   188 000000E5 8F06[0200]8F06-         	RestoreReg <<WORD PTR [DMAAdd+2]>, <WORD PTR [DMAAdd]>>
   188 000000EB [0000]             
   189 000000ED 7203                    	JC	SearchNoMore
   190 000000EF E956FF                  	JMP	SearchSet		; Ok set return
   191                                  
   192                                  SearchNoMore:
   193 000000F2 C43E[0000]              	LES	DI,[THISFCB]
   194 000000F6 F606[0000]FF            	TEST	byte [EXTFCB],0FFH
   195 000000FB 7403                    	JZ	NORMFCB8
   196 000000FD 83C707                  	ADD	DI,7			; Point past the extension
   197                                  NORMFCB8:
   198 00000100 5B                      	RestoreReg <BX> 		; Get original drive byte
   199 00000101 26881D                  	MOV	[ES:DI],BL		; Store the correct "user" drive byte
   200                                  					;  at the right spot
   201                                  ;
   202                                  ; error code is in AX
   203                                  ;
   204 00000104 E9(0000)                	transfer FCB_Ret_Err
   205                                  
   206                                  EndProc D_DIR_SEARCH_NEXT
   207                                  
   208                                  ;   Assembler usage:
   209                                  ;	    MOV AH, FindFirst
   210                                  ;	    LDS DX, name
   211                                  ;	    MOV CX, attr
   212                                  ;	    INT 21h
   213                                  ;	; DMA address has datablock
   214                                  ;
   215                                  ;   Error Returns:
   216                                  ;	    AX = error_path_not_found
   217                                  ;	       = error_no_more_files
   218                                  
   219                                  	procedure D_FIND_FIRST,NEAR
   219          ******************       warning: proc D_FIND_FIRST... [-w+user]
   220                                  ASSUME	DS:NOTHING,ES:NOTHING,SS:DOSGroup
   221                                  
   222 00000107 89D6                    	MOV	SI,DX			; get name in appropriate place
   223 00000109 36880E[0000]            	MOV	[ss:SATTRIB],CL		; Search attribute to correct loc
   224 0000010E BF[0000]                	MOV	DI,OFFSET OpenBuf wrt DOSGroup  ; appropriate buffer
   225 00000111 E8(0000)                	invoke	TransPathSet		; convert the path
   226 00000114 7305                    	JNC	Find_it 		; no error, go and look
   227                                  FindError:
   228 00000116 B003E9(0000)            	error	error_path_not_found	; error and map into one.
   229                                  Find_it:
   230 0000011B 161F                    	Context DS
   231 0000011D FF36[0000]FF36-         	SaveReg <<WORD PTR [DMAAdd]>, <WORD PTR [DMAAdd+2]>>
   231 00000123 [0200]             
   232 00000125 C706[0000][0000]        	MOV	WORD PTR [DMAAdd],OFFSET SEARCHBUF wrt DOSGroup
   233 0000012B 8C1E[0200]              	MOV	WORD PTR [DMAAdd+2],DS
   234 0000012F E89400                  	invoke	GET_FAST_SEARCH 	; search
   235 00000132 8F06[0200]8F06-         	RestoreReg <<WORD PTR [DMAAdd+2]>, <WORD PTR [DMAAdd]>>
   235 00000138 [0000]             
   236 0000013A 7302                    	JNC	FindSet 		; no error, transfer info
   237 0000013C EBDA                    	transfer Sys_Ret_Err
   238                                  
   239                                  FindSet:
   240 0000013E BE[0000]                	MOV	SI,OFFSET SEARCHBUF wrt DOSGroup
   241 00000141 C43E[0000]              	LES	DI,[DMAAdd]
   242 00000145 B91500                  	MOV	CX,21
   243 00000148 F3A4                    	REP	MOVSB
   244 0000014A 56                      	PUSH	SI			; Save pointer to start of entry
   245 0000014B 8A440B                  	MOV	AL,[SI + dir_attr]
   246 0000014E AA                      	STOSB
   247 0000014F 83C616                  	ADD	SI,dir_time
   248 00000152 A5                      	MOVSW				; dir_time
   249 00000153 A5                      	MOVSW				; dir_date
   250 00000154 46                      	INC	SI
   251 00000155 46                      	INC	SI			; Skip dir_first
   252 00000156 A5                      	MOVSW				; dir_size (2 words)
   253 00000157 A5                      	MOVSW
   254 00000158 5E                      	POP	SI			; Point back to dir_name
   255                                   %IF  DBCS									;AN000;
   256                                  	PUSH	DI			; XXXX save dest name 2/13/KK		;AN000;
   257                                  	CALL	PackName							;AN000;
   258                                  	POP	DI			; XXXX Recover dest name 2/13/KK	;AN000;
   259                                  	CMP	BYTE PTR [ES:DI],05H	; XXXX Need fix?	 2/13/KK	;AN000;
   260                                  	JNZ	FNXXX			; XXXX No		 2/13/KK	;AN000;
   261                                  	MOV	BYTE PTR [ES:DI],0E5H	; XXXX Yes, Fix 	 2/13/KK	;AN000;
   262                                  FNXXX:					; 2/13/KK				;AN000;
   263                                   %ELSE										;AN000;
   264 00000159 E83500                  	CALL	PackName
   265                                   %ENDIF
   266 0000015C E9(0000)                	transfer    Sys_Ret_OK		; bye with no errors
   267                                  EndProc D_FIND_FIRST
   268                                  
   269                                  	procedure D_FIND_NEXT,NEAR
   269          ******************       warning: proc D_FIND_NEXT... [-w+user]
   270                                  ASSUME	DS:NOTHING,ES:NOTHING,SS:DOSGroup
   271                                  
   272                                  ;   Assembler usage:
   273                                  ;	; dma points at area returned by find_first
   274                                  ;	    MOV AH, findnext
   275                                  ;	    INT 21h
   276                                  ;	; next entry is at dma
   277                                  ;
   278                                  ;   Error Returns:
   279                                  ;	    AX = error_no_more_files
   280                                  
   281 0000015F 1607                    	Context ES
   282 00000161 BF[0000]                	MOV	DI,OFFSET SEARCHBUF wrt DOSGroup
   283 00000164 36C536[0000]            	LDS	SI,[ss:DMAAdd]
   284 00000169 B91500                  	MOV	CX,21
   285 0000016C F3A4                    	REP	MOVSB			; Put the search continuation info
   286                                  					;  in the right place
   287 0000016E 161F                    	Context DS			; get ready for search
   288 00000170 FF36[0000]FF36-         	SaveReg <<WORD PTR [DMAAdd]>, <WORD PTR [DMAAdd+2]>>
   288 00000176 [0200]             
   289 00000178 C706[0000][0000]        	MOV	WORD PTR [DMAAdd],OFFSET SEARCHBUF wrt DOSGroup
   290 0000017E 8C1E[0200]              	MOV	WORD PTR [DMAAdd+2],DS
   291 00000182 E8(0000)                	invoke	DOS_SEARCH_NEXT 	; Find it
   292 00000185 8F06[0200]8F06-         	RestoreReg <<WORD PTR [DMAAdd+2]>, <WORD PTR [DMAAdd]>>
   292 0000018B [0000]             
   293 0000018D 73AF                    	JNC	FindSet 		; No error, set info
   294 0000018F EBAB                    	transfer Sys_Ret_Err
   295                                  
   296                                  EndProc D_FIND_NEXT
   297                                  
   298                                  Break	<PackName - convert file names from FCB to ASCIZ>
   299                                  ;
   300                                  ;   PackName - transfer a file name from DS:SI to ES:DI and convert it to
   301                                  ;	the ASCIZ format.
   302                                  ;
   303                                  ;   Input:	DS:SI points to an 11 character FCB or dir entry name
   304                                  ;		ES:DI points to a destination area (13 bytes)
   305                                  ;   Output:	Above pointers advanced
   306                                  ;   Registers modified: SI,DI,CX,AL
   307                                  	Procedure PackName,NEAR
   307          ******************       warning: proc PackName... [-w+user]
   308                                  	ASSUME	DS:NOTHING,ES:NOTHING,SS:DOSGroup
   309 00000191 B90800                  	MOV	CX,8			; Pack the name
   310 00000194 F3A4                    	REP	MOVSB			; Move all of it
   311                                  main_kill_tail:
   312 00000196 26807DFF20              	CMP	BYTE PTR [ES:DI-1]," "
   313 0000019B 7507                    	JNZ	find_check_dot
   314 0000019D 4F                      	DEC	DI			; Back up over trailing space
   315 0000019E 41                      	INC	CX
   316 0000019F 83F908                  	CMP	CX,8
   317 000001A2 72F2                    	JB	main_kill_tail
   318                                  find_check_dot:
   319 000001A4 813C2020                	CMP	WORD PTR [SI],(" " << 8) | " "
   320 000001A8 7506                    	JNZ	got_ext 		; Some chars in extension
   321 000001AA 807C0220                	CMP	BYTE PTR [SI+2]," "
   322 000001AE 7412                    	JZ	find_done		; No extension
   323                                  got_ext:
   324 000001B0 B02E                    	MOV	AL,"."
   325 000001B2 AA                      	STOSB
   326 000001B3 B90300                  	MOV	CX,3
   327 000001B6 F3A4                    	REP	MOVSB
   328                                  ext_kill_tail:
   329 000001B8 26807DFF20              	CMP	BYTE PTR [ES:DI-1]," "
   330 000001BD 7503                    	JNZ	find_done
   331 000001BF 4F                      	DEC	DI			; Back up over trailing space
   332 000001C0 EBF6                    	JMP	ext_kill_tail
   333                                  find_done:
   334 000001C2 31C0                    	XOR	AX,AX
   335 000001C4 AA                      	STOSB				; NUL terminate
   336 000001C5 C3                      	return
   337                                  EndProc PackName
   338                                  
   339                                  	procedure   GET_FAST_SEARCH,NEAR
   339          ******************       warning: proc GET_FAST_SEARCH... [-w+user]
   340                                  	ASSUME	DS:NOTHING,ES:NOTHING
   341                                  
   342 000001C6 36810E[0000]0004        	OR	word [ss:DOS34_FLAG],SEARCH_FASTOPEN  ;FO.trigger fastopen		;AN000;
   343 000001CD E8(0000)                	invoke	DOS_SEARCH_FIRST
   344 000001D0 C3                      	return
   345                                  
   346                                  EndProc GET_FAST_SEARCH
   347                                  END
