summaryrefslogtreecommitdiff
path: root/v4.0/src/DOS/SEARCH.ASM
diff options
context:
space:
mode:
authorGravatar Mark Zbikowski2024-04-25 21:24:10 +0100
committerGravatar Microsoft Open Source2024-04-25 22:32:27 +0000
commit2d04cacc5322951f187bb17e017c12920ac8ebe2 (patch)
tree80ee017efa878dfd5344b44249e6a241f2a7f6e2 /v4.0/src/DOS/SEARCH.ASM
parentMerge pull request #430 from jpbaltazar/typoptbr (diff)
downloadms-dos-main.tar.gz
ms-dos-main.tar.xz
ms-dos-main.zip
MZ is back!HEADmain
Diffstat (limited to 'v4.0/src/DOS/SEARCH.ASM')
-rw-r--r--v4.0/src/DOS/SEARCH.ASM346
1 files changed, 346 insertions, 0 deletions
diff --git a/v4.0/src/DOS/SEARCH.ASM b/v4.0/src/DOS/SEARCH.ASM
new file mode 100644
index 0000000..1f23942
--- /dev/null
+++ b/v4.0/src/DOS/SEARCH.ASM
@@ -0,0 +1,346 @@
1; SCCSID = @(#)search.asm 1.1 85/04/10
2TITLE SEARCH - Directory scan system calls
3NAME 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.xlist
25;
26; get the appropriate segment definitions
27;
28include dosseg.asm
29
30CODE SEGMENT BYTE PUBLIC 'CODE'
31 ASSUME SS:DOSGroup,CS:DOSGroup
32
33.xcref
34INCLUDE DOSSYM.INC
35INCLUDE DEVSYM.INC
36INCLUDE fastopen.inc
37INCLUDE fastxxxx.inc
38.cref
39.list
40
41 i_need SEARCHBUF,53
42 i_need SATTRIB,BYTE
43 I_Need OpenBuf,128
44 I_need DMAAdd,DWORD
45 I_need THISFCB,DWORD
46 I_need CurDrv,BYTE
47 I_need EXTFCB,BYTE
48 I_need Fastopenflg,BYTE
49 I_need DOS34_FLAG,WORD
50
51; Inputs:
52; DS:DX Points to unopenned FCB
53; Function:
54; Directory is searched for first matching entry and the directory
55; entry is loaded at the disk transfer address
56; Returns:
57; AL = -1 if no entries matched, otherwise 0
58
59 procedure $DIR_SEARCH_FIRST,NEAR
60ASSUME CS:DOSGroup,DS:NOTHING,ES:NOTHING,SS:DOSGroup
61
62 MOV WORD PTR [THISFCB],DX
63 MOV WORD PTR [THISFCB+2],DS
64 MOV SI,DX
65 CMP BYTE PTR [SI],0FFH
66 JNZ NORMFCB4
67 ADD SI,7 ; Point to drive select byte
68NORMFCB4:
69 SaveReg <[SI]> ; Save original drive byte for later
70 Context ES ; get es to address DOSGroup
71 MOV DI,OFFSET DOSGroup:OpenBuf ; appropriate buffer
72 invoke TransFCB ; convert the FCB, set SATTRIB EXTFCB
73 JNC SearchIt ; no error, go and look
74 RestoreReg <BX> ; Clean stack
75;
76; Error code is in AX
77;
78 transfer FCB_Ret_Err ; error
79
80SearchIt:
81 Context DS ; get ready for search
82 SaveReg <<WORD PTR [DMAAdd]>, <WORD PTR [DMAAdd+2]>>
83 MOV WORD PTR [DMAAdd],OFFSET DOSGroup:SEARCHBUF
84 MOV WORD PTR [DMAAdd+2],DS
85 invoke GET_FAST_SEARCH ; search
86 RestoreReg <<WORD PTR [DMAAdd+2]>, <WORD PTR [DMAAdd]>>
87 JNC SearchSet ; no error, transfer info
88 RestoreReg <BX> ; Clean stack
89;
90; Error code is in AX
91;
92 transfer FCB_Ret_Err
93
94;
95; The search was successful (or the search-next). We store the information
96; into the user's FCB for continuation.
97;
98SearchSet:
99 MOV SI,OFFSET DOSGroup:SEARCHBUF
100 LES DI,[THISFCB] ; point to the FCB
101 TEST [EXTFCB],0FFH ;
102 JZ NORMFCB1
103 ADD DI,7 ; Point past the extension
104NORMFCB1:
105 RestoreReg <BX> ; Get original drive byte
106 OR BL,BL
107 JNZ SearchDrv
108 MOV BL,[CurDrv]
109 INC BL
110SearchDrv:
111 LODSB ; Get correct search contin drive byte
112 XCHG AL,BL ; Search byte to BL, user byte to AL
113 INC DI
114; STOSB ; Store the correct "user" drive byte
115 ; at the start of the search info
116 MOV CX,20/2
117 REP MOVSW ; Rest of search cont info, SI -> entry
118 XCHG AL,BL ; User drive byte back to BL, search
119 ; byte to AL
120 STOSB ; Search contin drive byte at end of
121 ; contin info
122 LES DI,[DMAAdd]
123 TEST [EXTFCB],0FFH
124 JZ NORMFCB2
125 MOV AL,0FFH
126 STOSB
127 INC AL
128 MOV CX,5
129 REP STOSB
130 MOV AL,[SATTRIB]
131 STOSB
132NORMFCB2:
133 MOV AL,BL ; User Drive byte
134 STOSB
135 IF DBCS ;AN000;
136 MOVSW ; 2/13/KK ;AN000;
137 CMP BYTE PTR ES:[DI-2],5 ; 2/13/KK ;AN000;
138 JNZ NOTKTRAN ; 2/13/KK ;AN000;
139 MOV BYTE PTR ES:[DI-2],0E5H ; 2/13/KK ;AN000;
140NOTKTRAN: ; 2/13/KK ;AN000;
141 MOV CX,15 ; 2/13/KK ;AN000;
142 ELSE ;AN000;
143 MOV CX,16 ; 32 / 2 words of dir entry ;AN000;
144 ENDIF ;AN000;
145 REP MOVSW
146 transfer FCB_Ret_OK
147
148EndProc $DIR_SEARCH_FIRST
149
150; Inputs:
151; DS:DX points to unopenned FCB returned by $DIR_SEARCH_FIRST
152; Function:
153; Directory is searched for the next matching entry and the directory
154; entry is loaded at the disk transfer address
155; Returns:
156; AL = -1 if no entries matched, otherwise 0
157
158 procedure $DIR_SEARCH_NEXT,NEAR
159ASSUME CS:DOSGroup,DS:NOTHING,ES:NOTHING,SS:DOSGroup
160
161 MOV WORD PTR [THISFCB],DX
162 MOV WORD PTR [THISFCB+2],DS
163 MOV [SATTRIB],0
164 MOV [EXTFCB],0
165 Context ES
166 MOV DI,OFFSET DOSGroup:SEARCHBUF
167 MOV SI,DX
168 CMP BYTE PTR [SI],0FFH
169 JNZ NORMFCB6
170 ADD SI,6
171 LODSB
172 MOV [SATTRIB],AL
173 DEC [EXTFCB]
174NORMFCB6:
175 LODSB ; Get original user drive byte
176 SaveReg <AX> ; Put it on stack
177 MOV AL,[SI+20] ; Get correct search contin drive byte
178 STOSB ; Put in correct place
179 MOV CX,20/2
180 REP MOVSW ; Transfer in rest of search contin info
181 Context DS
182 SaveReg <<WORD PTR [DMAAdd]>, <WORD PTR [DMAAdd+2]>>
183 MOV WORD PTR [DMAAdd],OFFSET DOSGroup:SEARCHBUF
184 MOV WORD PTR [DMAAdd+2],DS
185 invoke DOS_SEARCH_NEXT ; Find it
186 RestoreReg <<WORD PTR [DMAAdd+2]>, <WORD PTR [DMAAdd]>>
187 JC SearchNoMore
188 JMP SearchSet ; Ok set return
189
190SearchNoMore:
191 LES DI,[THISFCB]
192 TEST [EXTFCB],0FFH
193 JZ NORMFCB8
194 ADD DI,7 ; Point past the extension
195NORMFCB8:
196 RestoreReg <BX> ; Get original drive byte
197 MOV ES:[DI],BL ; Store the correct "user" drive byte
198 ; at the right spot
199;
200; error code is in AX
201;
202 transfer FCB_Ret_Err
203
204EndProc $DIR_SEARCH_NEXT
205
206; Assembler usage:
207; MOV AH, FindFirst
208; LDS DX, name
209; MOV CX, attr
210; INT 21h
211; ; DMA address has datablock
212;
213; Error Returns:
214; AX = error_path_not_found
215; = error_no_more_files
216
217 procedure $FIND_FIRST,NEAR
218ASSUME CS:DOSGroup,DS:NOTHING,ES:NOTHING,SS:DOSGroup
219
220 MOV SI,DX ; get name in appropriate place
221 MOV [SATTRIB],CL ; Search attribute to correct loc
222 MOV DI,OFFSET DOSGroup:OpenBuf ; appropriate buffer
223 invoke TransPathSet ; convert the path
224 JNC Find_it ; no error, go and look
225FindError:
226 error error_path_not_found ; error and map into one.
227Find_it:
228 Context DS
229 SaveReg <<WORD PTR [DMAAdd]>, <WORD PTR [DMAAdd+2]>>
230 MOV WORD PTR [DMAAdd],OFFSET DOSGroup:SEARCHBUF
231 MOV WORD PTR [DMAAdd+2],DS
232 invoke GET_FAST_SEARCH ; search
233 RestoreReg <<WORD PTR [DMAAdd+2]>, <WORD PTR [DMAAdd]>>
234 JNC FindSet ; no error, transfer info
235 transfer Sys_Ret_Err
236
237FindSet:
238 MOV SI,OFFSET DOSGroup:SEARCHBUF
239 LES DI,[DMAAdd]
240 MOV CX,21
241 REP MOVSB
242 PUSH SI ; Save pointer to start of entry
243 MOV AL,[SI.dir_attr]
244 STOSB
245 ADD SI,dir_time
246 MOVSW ; dir_time
247 MOVSW ; dir_date
248 INC SI
249 INC SI ; Skip dir_first
250 MOVSW ; dir_size (2 words)
251 MOVSW
252 POP SI ; Point back to dir_name
253 IF DBCS ;AN000;
254 PUSH DI ; XXXX save dest name 2/13/KK ;AN000;
255 CALL PackName ;AN000;
256 POP DI ; XXXX Recover dest name 2/13/KK ;AN000;
257 CMP BYTE PTR ES:[DI],05H ; XXXX Need fix? 2/13/KK ;AN000;
258 JNZ FNXXX ; XXXX No 2/13/KK ;AN000;
259 MOV BYTE PTR ES:[DI],0E5H ; XXXX Yes, Fix 2/13/KK ;AN000;
260FNXXX: ; 2/13/KK ;AN000;
261 ELSE ;AN000;
262 CALL PackName
263 ENDIF
264 transfer Sys_Ret_OK ; bye with no errors
265EndProc $FIND_FIRST
266
267 procedure $FIND_NEXT,NEAR
268ASSUME CS:DOSGroup,DS:NOTHING,ES:NOTHING,SS:DOSGroup
269
270; Assembler usage:
271; ; dma points at area returned by find_first
272; MOV AH, findnext
273; INT 21h
274; ; next entry is at dma
275;
276; Error Returns:
277; AX = error_no_more_files
278
279 Context ES
280 MOV DI,OFFSET DOSGroup:SEARCHBUF
281 LDS SI,[DMAAdd]
282 MOV CX,21
283 REP MOVSB ; Put the search continuation info
284 ; in the right place
285 Context DS ; get ready for search
286 SaveReg <<WORD PTR [DMAAdd]>, <WORD PTR [DMAAdd+2]>>
287 MOV WORD PTR [DMAAdd],OFFSET DOSGroup:SEARCHBUF
288 MOV WORD PTR [DMAAdd+2],DS
289 invoke DOS_SEARCH_NEXT ; Find it
290 RestoreReg <<WORD PTR [DMAAdd+2]>, <WORD PTR [DMAAdd]>>
291 JNC FindSet ; No error, set info
292 transfer Sys_Ret_Err
293
294EndProc $FIND_NEXT
295
296Break <PackName - convert file names from FCB to ASCIZ>
297;
298; PackName - transfer a file name from DS:SI to ES:DI and convert it to
299; the ASCIZ format.
300;
301; Input: DS:SI points to an 11 character FCB or dir entry name
302; ES:DI points to a destination area (13 bytes)
303; Output: Above pointers advanced
304; Registers modified: SI,DI,CX,AL
305 Procedure PackName,NEAR
306 ASSUME CS:DOSGroup,DS:NOTHING,ES:NOTHING,SS:DOSGroup
307 MOV CX,8 ; Pack the name
308 REP MOVSB ; Move all of it
309main_kill_tail:
310 CMP BYTE PTR ES:[DI-1]," "
311 JNZ find_check_dot
312 DEC DI ; Back up over trailing space
313 INC CX
314 CMP CX,8
315 JB main_kill_tail
316find_check_dot:
317 CMP WORD PTR [SI],(" " SHL 8) OR " "
318 JNZ got_ext ; Some chars in extension
319 CMP BYTE PTR [SI+2]," "
320 JZ find_done ; No extension
321got_ext:
322 MOV AL,"."
323 STOSB
324 MOV CX,3
325 REP MOVSB
326ext_kill_tail:
327 CMP BYTE PTR ES:[DI-1]," "
328 JNZ find_done
329 DEC DI ; Back up over trailing space
330 JMP ext_kill_tail
331find_done:
332 XOR AX,AX
333 STOSB ; NUL terminate
334 return
335EndProc PackName
336
337 procedure GET_FAST_SEARCH,NEAR
338 ASSUME DS:NOTHING,ES:NOTHING
339
340 OR [DOS34_FLAG],SEARCH_FASTOPEN ;FO.trigger fastopen ;AN000;
341 invoke DOS_SEARCH_FIRST
342 return
343
344EndProc GET_FAST_SEARCH
345CODE ENDS
346END