     1                                  ;	SCCSID = @(#)dir.asm	1.1 85/04/10
     2                                  ;	SCCSID = @(#)dir.asm	1.1 85/04/10
     3                                  ;TITLE	DIR - Directory and path cracking
     4                                  ;NAME	Dir
     5                                  ; Main Path cracking routines, low level search routines
     6                                  ;
     7                                  ;   FindEntry
     8                                  ;   SEARCH
     9                                  ;   Srch
    10                                  ;   NEXTENT
    11                                  ;   MetaCompare
    12                                  ;   dos_NEXTENTRY
    13                                  ;   GETENTRY
    14                                  ;   GETENT
    15                                  ;   SETDIRSRCH
    16                                  ;   SETROOTSRCH
    17                                  ;
    18                                  ;   Revision history:
    19                                  ;
    20                                  ;	A000   version 4.00    Jan. 1988
    21                                  ;
    22                                  
    23                                  ;
    24                                  ; get the appropriate segment definitions
    25                                  ;
    26                                  [list -]
    26          ******************       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
    28                                  %include "fastopen.mac"
     1                              <1> ;
     2                              <1> ; EXPORT DATE: 9/11
     3                              <1> ;Equates for FASTOPEN.
     4                              <1> 
     5                              <1> ;FASTOPEN NAME CACHING Subfunctions
     6                              <1> FONC_Look_up	equ	1
     7                              <1> FONC_insert	equ	2
     8                              <1> FONC_delete	equ	3
     9                              <1> FONC_update	equ	4
    10                              <1> FONC_purge	equ	5		;reserved for the future use.
    11                              <1> 
    12                              <1> ;FASTOPEN EXTENT  CACHING Subfunctions
    13                              <1> FSK_Open       equ     11					       ;AN000;
    14                              <1> FSK_Close      equ     12					       ;AN000;
    15                              <1> FSK_Delete     equ     13					       ;AN000;
    16                              <1> FSK_Lookup     equ     14					       ;AN000;
    17                              <1> FSK_Insert     equ     15					       ;AN000;
    18                              <1> FSK_Trunc      equ     16					       ;AN000;
    19                              <1> 
    20                              <1> HeaderSize     equ    8        ; size of file header (8 bytes)	       ;AN000;
    21                              <1> ExtendSize     equ    8        ; size of extend (8 bytes)	       ;AN000;
    22                              <1> Num_Of_Pages   equ    1        ; number of pages		       ;AN000;
    23                              <1> Num_Of_Segs    equ    2        ; number of frame segments	       ;AN000;
    24                              <1> Stayresident  equ    04ch     ; terminate and stay resident function code
    25                              <1> 
    26                              <1> 
    27                              <1> ;Equates used in DOS.
    28                              <1> FastOpen_Set	       equ     00000001B
    29                              <1> FastOpen_Reset	       equ     11111110B
    30                              <1> Lookup_Success	       equ     00000010B
    31                              <1> Lookup_Reset	       equ     11111101B
    32                              <1> Special_Fill_Set       equ     00000100B
    33                              <1> Special_Fill_Reset     equ     11111011B
    34                              <1> No_Lookup	       equ     00001000B
    35                              <1> Set_For_Search	       equ     00010000B	     ;DCR 167
    36                              <1> 
    37                              <1> 
    38                              <1> ;============= FastOpen Data Structures =====================
    39                              <1> 
    40                              <1> Fastopen_Entry	STRUC			;Fastopen Entry pointer in DOS
    41 00000000 ????                <1> Fastopen_Entry_size	dw	?	;size of the following
    42 00000002 ????????            <1> Fastopen_Name_Caching	dd	?
    43                              <1> ;Fastopen_FatChain_Caching dd	  ?	;reserved for future use
    44                              <1> Fastopen_Entry	ENDS
    45                              <1> ;
    46                              <1> 
    47                              <1> 
    48                              <1> CMPCT_DIR_INFO	STRUC			;compact version of Dir Info.
    49 00000000 <res Bh>            <1> CDI_file_name	db	11 dup (?)
    50 0000000B ??                  <1> CDI_file_attr	db	?
    51 0000000C ????                <1> CDI_codepage	dw	?
    52 0000000E ????                <1> CDI_extcluster	dw	?
    53 00000010 ??                  <1> CDI_attr2	db	?
    54 00000011 ????                <1> CDI_time	dw	?
    55 00000013 ????                <1> CDI_date	dw	?
    56 00000015 ????                <1> CDI_cluster	dw	?
    57 00000017 ????????            <1> CDI_filesize	dd	?
    58                              <1> CMPCT_DIR_INFO	ENDS
    59                              <1> ;
    60                              <1> 
    61                              <1> ORIG_DIR_INFO	STRUC
    62 00000000 <res 11h>           <1> ODI_head	db	17 dup (?)
    63 00000011 ??????????          <1> ODI_skip	db	5  dup (?)	;reserved for DOS. FASTOPEN does not
    64 00000016 <res Ah>            <1> ODI_tail	db	10 dup (?)	;  use ODI_skip part.
    65                              <1> ORIG_DIR_INFO	ENDS
    66                              <1> ;
    67                              <1> 
    68                              <1> ODI_head_leng	equ	17
    69                              <1> ODI_skip_leng	equ	5
    70                              <1> ODI_tail_leng	equ	10
    71                              <1> ;
    72                              <1> 
    73                              <1> FASTOPEN_EXTENDED_INFO	STRUC
    74 00000000 ??                  <1> FEI_dirpos	db	?
    75 00000001 ????????            <1> FEI_dirsec	dd	?
    76 00000005 ????                <1> FEI_clusnum	dw	?
    77 00000007 ????                <1> FEI_lastent	dw	?		; for search first
    78 00000009 ????                <1> FEI_dirstart	dw	?		; for search first
    79                              <1> FASTOPEN_EXTENDED_INFO	ENDS
    80                              <1> ;
    81                              <1> 
    82                              <1> NAME_RECORD	STRUC
    83 00000000 ????                <1> nLRU_ptr	dw	?
    84 00000002 ????                <1> nMRU_ptr	dw	?		;reverse of nLRU_ptr
    85 00000004 ????                <1> nChild_ptr	dw	?
    86 00000006 ????                <1> nSibling_ptr	dw	?
    87 00000008 ????                <1> nBackward_ptr	dw	?		;points to preceding node
    88                              <1> Cmpct_Dir_Info_struc_size equ CMPCT_DIR_INFO_struc_size	; NASM port equate
    89 0000000A <res 1Bh>           <1> nCmpct_Dir_Info db	Cmpct_Dir_Info_struc_size dup (?)
    90                              <1> Fastopen_Extended_Info_struc_size equ FASTOPEN_EXTENDED_INFO_struc_size	; NASM port equate
    91 00000025 <res Bh>            <1> nExtended_Info	db	Fastopen_Extended_Info_struc_size dup (?)
    92                              <1> NAME_RECORD	ENDS
    93                              <1> ;
    94                              <1> 
    95                              <1> DRIVE_CACHE_HEADER	STRUC		;drive cache header
    96 00000000 ????                <1> DCH_LRU_ROOT	 dw	 ?		;Header of the LRU chain of this drive
    97 00000002 ????                <1> DCH_MRU_ROOT	 dw	 ?		;offset to the last entry of LRU chain
    98 00000004 ????                <1> DCH_Child_ptr	 dw	 ?		;the first child in Name cache seg.
    99 00000006 ????                <1> DCH_Sibling_ptr  dw	 ?		;points to the next drive cache header
   100 00000008 ??                  <1> DCH_Drive_letter db	?             ;drive letter
   101 00000009 ????                <1> DCH_Num_Entries  dw	 ?		;Number of entries in the Name cache.
   102 0000000B ????                <1> DCH_Name_Buff	 dw	 ?		;pointer to name cahe buffer
   103                              <1> DRIVE_CACHE_HEADER	ENDS
   104                              <1> ;
   105                              <1> 
   106                              <1> 
   107                              <1> 
   108                              <1> 
   109                              <1> 
   110                              <1> ;======== FAST SEEK FUNCTION  DATA  STRUCTURES =======================
   111                              <1> 
   112                              <1> DRIVE_HEADER	STRUC		   ; Drive header structure		;AN000;
   113 00000000 ????                <1> Drive_Number	     dw     ?	   ; drive number			;AN000;
   114 00000002 ????                <1> Extent_Count	     dw     ?	   ; reserved for debugging
   115 00000004 ????                <1> MRU_Hdr_Ptr	     dw     ?	   ; pointer to OPEN Queue
   116 00000006 ????                <1> Free_ptr	     dw     ?	   ; pointer to FREE buffer		;AN000;
   117 00000008 ????                <1> Close_Ptr	     dw     ?	   ; pointer to CLOSE Queue	     ;AN000;
   118 0000000A ????                <1> Buff_Size	     dw     ?	   ; cache buffer size including header ;AN000;
   119 0000000C ????                <1> Free_Size	     dw     ?	   ; size of Free area in bytes
   120 0000000E ????                <1> Next_Drv_Hdr_Ptr     dw     ?	   ; pointer to next drive header
   121                              <1> DRIVE_HEADER   ENDS
   122                              <1> 
   123                              <1> 
   124                              <1> 
   125                              <1> FILE_HEADER	STRUC		   ; File header structure		;AN000;
   126 00000000 ????                <1> FH_Phys_Clus_Num     dw     ?	   ; starting physcial clustnum of file ;AN000;
   127 00000002 ????                <1> FH_Refer_Count	     dw     ?	   ; reference count			;AN000;
   128 00000004 ????                <1> FH_Next_Extn_Ptr     dw     ?	   ; pointer to first extent of the file;AN000;
   129 00000006 ????                <1> FH_Next_Hdr_Ptr      dw     ?	   ; pointer to next file header	;AN000;
   130 00000008 ????                <1> FH_MRU_Extn_Ptr      dw     ?	   ; pointer to  MRU extent
   131 0000000A ????                <1> 		     dw     ?
   132 0000000C ????                <1> 		     dw     ?
   133 0000000E ????                <1> 		     dw     ?
   134                              <1> FILE_HEADER	ENDS							;AN000;
   135                              <1> 
   136                              <1> 
   137                              <1> 
   138                              <1> EXTENT_HEADER	STRUC		   ; extend header structure		;AN000;
   139 00000000 ????                <1> EH_Logic_Clus_Num    dw     ?	   ; starting logical clus num of extent;AN000;
   140 00000002 ????                <1> EH_Phys_Clus_Num     dw     ?	   ; starting physical clus numof  extnt;AN000;
   141 00000004 ????                <1> EH_Count	     dw     ?	   ; range of logical clusnum in the extnt
   142 00000006 ????                <1> EH_Next_Extn_Ptr     dw     ?	   ; pointer to next extent		;AN000;
   143 00000008 ????                <1> EH_Prev_Extn_Ptr     dw     ?	   ; pointer to previous extent  ;AN000;
   144 0000000A ????                <1> EH_Next_LRU_Ptr      dw     ?	   ; pointer to next LRU extent
   145 0000000C ????                <1> EH_Prev_LRU_Ptr      dw     ?	   ; pointer tp previous LRU extent
   146 0000000E ????                <1> 		     dw     ?
   147                              <1> EXTENT_HEADER	ENDS
   148                              <1> 
   149                              <1> 
   150                              <1> 
    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]
    38                                  
    39                                  %ifndef Kanji
    40                                   %iassign Kanji 0
    41                                  %endif
    42                                  
    43                                  	i_need	EntFree,WORD
    44                                  	i_need	DirStart,WORD
    45                                  	i_need	LastEnt,WORD
    46                                  	i_need	ClusNum,WORD
    47                                  	i_need	CurBuf,DWORD
    48                                  	i_need	Attrib,BYTE
    49                                  	i_need	DelAll,BYTE
    50                                  	i_need	VolID,BYTE
    51                                  	i_need	Name1,BYTE
    52                                  	i_need	ThisDPB,DWORD
    53                                  	i_need	EntLast,WORD
    54                                  	i_need	Creating,BYTE
    55                                  	i_need	SecClusPos,BYTE
    56                                  	i_need	ClusFac,BYTE
    57                                  	i_need	Cluster_Factor_EDR,WORD
    58                                  	i_need	NxtClusNum,WORD
    59                                  	i_need	DirSec,DWORD			;AN000;
    60                                  	I_need	FastOpenFlg,BYTE		;AN000;
    61                                  	I_need	HIGH_SECTOR,WORD		;AN000;
    62                                  
    63                                   assume nocheck, ss:DOSGROUP
    64                                  
    65                                  Break	<FINDENTRY -- LOOK FOR AN ENTRY>
    66                                  
    67                                  ; Inputs:
    68                                  ;	[THISDPB] set
    69                                  ;	[SECCLUSPOS] = 0
    70                                  ;	[DIRSEC] = Starting directory sector number
    71                                  ;	[CLUSNUM] = Next cluster of directory
    72                                  ;	[CLUSFAC] = Sectors/Cluster
    73                                  ;	[NAME1] = Name to look for
    74                                  ; Function:
    75                                  ;	Find file name in disk directory.
    76                                  ;	"?" matches any character.
    77                                  ; Outputs:
    78                                  ;	Carry set if name not found
    79                                  ;	ELSE
    80                                  ;	Zero set if attributes match (always except when creating)
    81                                  ;	AH = Device ID (bit 7 set if not disk)
    82                                  ;	[THISDPB] = Base of drive parameters
    83                                  ;	DS = DOSGROUP
    84                                  ;	ES = DOSGROUP
    85                                  ;	[CURBUF+2]:BX = Pointer into directory buffer
    86                                  ;	[CURBUF+2]:SI = Pointer to First Cluster field in directory entry
    87                                  ;	[CURBUF] has directory record with match
    88                                  ;	[NAME1] has file name
    89                                  ;	[LASTENT] is entry number of the entry
    90                                  ; All other registers destroyed.
    91                                  
    92                                  	procedure   SEARCH,near
    92          ******************       warning: proc SEARCH... [-w+user]
    93                                  
    94                                  	entry	FindEntry
    95                                  	DOSAssume   CS,<DS>,"FindEntry"
    96                                  	ASSUME	ES:NOTHING
    97                                  
    98 00000000 E8(0000)                	invoke	STARTSRCH
    99 00000003 A0[0000]                	MOV	AL,[Attrib]
   100 00000006 249E                    	AND	AL,~ attr_ignore	; Ignore useless bits
   101 00000008 3C08                    	CMP	AL,attr_volume_id	; Looking for vol ID only ?
   102 0000000A 7503                    	JNZ	NOTVOLSRCH		; No
   103 0000000C E88F01                  	CALL	SETROOTSRCH		; Yes force search of root
   104                                  NOTVOLSRCH:
   105 0000000F E81601                  	CALL	GETENTRY
   106 00000012 7303                    	JNC	Srch
   107 00000014 E9A000                  	JMP	SETESRET
   108                                  
   109                                  	entry	Srch
   110                                  
   111 00000017 1E                      	PUSH	DS
   112                                  CURBUF equ CurBuf	; NASM port label
   113 00000018 8E1E[0200]              	MOV	DS,WORD PTR [CURBUF+2]
   114                                  ASSUME	DS:NOTHING
   115 0000001C 8A27                    	MOV	AH,BYTE PTR [BX]
   116 0000001E 08E4                    	OR	AH,AH			; End of directory?
   117 00000020 7440                    	JZ	FREE
   118                                  DELALL equ DelAll	; NASM port label
   119 00000022 363A26[0000]            	CMP	AH,BYTE PTR [ss:DELALL]	; Free entry?
   120 00000027 7439                    	JZ	FREE
   121 00000029 F6470B08                	TEST	BYTE PTR [BX+11],attr_volume_id
   122                                  					; Volume ID file?
   123 0000002D 740B                    	JZ	CHKFNAM 		; NO
   124 0000002F F6470BD7                	test byte [bx + 11], ~ (attr_volume_id | attr_archive)
   125 00000033 7505                    	jnz CHKFNAM			; possible LFN ? then skip -->
   126                                  VOLID equ VolID	; NASM port label
   127 00000035 36FE06[0000]            	INC	BYTE PTR [ss:VOLID]
   128                                  CHKFNAM:
   129                                  ;	Context ES
   130 0000003A 8CD6                    	MOV	SI,SS
   131 0000003C 8EC6                    	MOV	ES,SI
   132                                  	ASSUME	ES:DOSGroup
   133 0000003E 89DE                    	MOV	SI,BX
   134                                  NAME1 equ Name1	; NASM port label
   135 00000040 BF[0000]                	MOV	DI,OFFSET NAME1 wrt DOSGROUP
   136                                  ;;;;; 7/29/86
   137 00000043 36803E[0000]E5          	CMP	BYTE PTR [ss:NAME1],0E5H	 ; special char check
   138 00000049 7506                    	JNZ	NO_E5
   139 0000004B 36C606[0000]05          	MOV	BYTE PTR [ss:NAME1],05H
   140                                  NO_E5:
   141                                  ;;;;; 7/29/86
   142 00000051 E86600                  	CALL	MetaCompare
   143 00000054 7428                    	JZ	FOUND
   144 00000056 1F                      	POP	DS
   145                                   assume ds:DOSGROUP
   146                                  
   147                                  	entry	NEXTENT
   148                                  	DOSAssume   CS,<DS>,"NextEnt"
   149                                  
   150                                  	Assert	ISDPB,<<WORD PTR THISDPB+2>,<WORD PTR THISDPB>>,"NextEnt"
   151                                  THISDPB equ ThisDPB	; NASM port label
   152 00000057 C42E[0000]              	LES	BP,[THISDPB]
   153                                  ASSUME	ES:NOTHING
   154                                  dos_NEXTENTRY equ dos_NextEntry	; NASM port label
   155 0000005B E86B00                  	CALL	dos_NEXTENTRY
   156                                  SRCH equ Srch	; NASM port label
   157 0000005E 73B7                    	JNC	SRCH
   158 00000060 EB55                    	JMP	SHORT SETESRET
   159                                  
   160                                  FREE:
   161 00000062 1F                      	POP	DS
   162                                  	DOSAssume   CS,<DS>,"DIR/Free"
   163                                  LASTENT equ LastEnt	; NASM port label
   164 00000063 8B0E[0000]              	MOV	CX,[LASTENT]
   165                                  ENTFREE equ EntFree	; NASM port label
   166 00000067 3B0E[0000]              	CMP	CX,[ENTFREE]
   167 0000006B 7304                    	JAE	TSTALL
   168 0000006D 890E[0000]              	MOV	[ENTFREE],CX
   169                                  TSTALL:
   170 00000071 3A26[0000]              	CMP	AH,BYTE PTR [DELALL]	; At end of directory?
   171                                  NextEntJ:
   172 00000075 74E0                    	JZ	NEXTENT 		; No - continue search
   173                                  ENTLAST equ EntLast	; NASM port label
   174 00000077 890E[0000]              	MOV	[ENTLAST],CX
   175 0000007B F9                      	STC
   176 0000007C EB39                    	JMP	SHORT SETESRET
   177                                  
   178                                  FOUND:
   179                                  ;
   180                                  ; We have a file with a matching name.	We must now consider the attributes:
   181                                  ; ATTRIB	Action
   182                                  ; ------	------
   183                                  ; Volume_ID	Is Volume_ID in test?
   184                                  ; Otherwise	If no create then Is ATTRIB+extra superset of test?
   185                                  ;		If create then Is ATTRIB equal to test?
   186                                  ;
   187 0000007E 8A2C                    	MOV	CH,[SI] 		; Attributes of file
   188 00000080 1F                      	POP	DS
   189                                  	DOSAssume   CS,<DS>,"DIR/found"
   190 00000081 8A26[0000]              	MOV	AH,[Attrib]		; Attributes of search
   191 00000085 80E49E                  	AND	AH,~ attr_ignore
   192                                  Dir_First equ dir_first	; NASM port equate
   193                                  Dir_Attr equ dir_attr	; NASM port equate
   194 00000088 8D740F                  	LEA	SI,[SI+Dir_First-Dir_Attr]  ; point to firclus field
   195 0000008B F6C508                  	TEST	CH,attr_volume_id	; Volume ID file?
   196 0000008E 740E                    	JZ	check_one_volume_id	; Nope check other attributes
   197 00000090 F6C408                  	TEST	AH,attr_volume_id	; Can we find Volume ID?
   198                                  NEXTENTJ equ NextEntJ	; NASM port label
   199 00000093 74E0                    	JZ	NEXTENTJ		; Nope, (not even $FCB_CREATE)
   200 00000095 F6C5D7                  	test ch, ~ (attr_volume_id | attr_archive)
   201                                  					; possible LFN ?
   202 00000098 75BD                    	jnz NEXTENT			; yes, skip -->
   203 0000009A 30E4                    	XOR	AH,AH			; Set zero flag for $FCB_CREATE
   204 0000009C EB11                    	JMP	SHORT RETFF		; Found Volume ID
   205                                  check_one_volume_id:
   206 0000009E 80FC08                  	CMP	AH,attr_volume_id	; Looking only for Volume ID?
   207 000000A1 74D2                    	JZ	NEXTENTJ		; Yes, continue search
   208 000000A3 E8(0000)                	invoke	MatchAttributes
   209 000000A6 7407                    	JZ	RETFF
   210                                  CREATING equ Creating	; NASM port label
   211 000000A8 F606[0000]FF            	TEST	BYTE PTR [CREATING],-1	; Pass back mismatch if creating
   212 000000AD 74C6                    	JZ	NEXTENTJ		; Otherwise continue searching
   213                                  RETFF:
   214 000000AF C42E[0000]              	LES	BP,[THISDPB]
   215 000000B3 268A6600                	MOV	AH,[ES:BP + dpb_drive]
   216                                  SETESRET:
   217 000000B7 16                      	PUSH	SS
   218 000000B8 07                      	POP	ES
   219                                   assume es:DOSGROUP
   220 000000B9 C3                      	return
   221                                  EndProc Search
   222                                  
   223                                  ; Inputs:
   224                                  ;	DS:SI -> 11 character FCB style name NO '?'
   225                                  ;	    Typically this is a directory entry.  It MUST be in upper case
   226                                  ;	ES:DI -> 11 character FCB style name with possible '?'
   227                                  ;	    Typically this is a FCB or SFT.  It MUST be in upper case
   228                                  ; Function:
   229                                  ;	Compare FCB style names allowing for ? match to any char
   230                                  ; Outputs:
   231                                  ;	Zero if match else NZ
   232                                  ; Destroys CX,SI,DI all others preserved
   233                                  
   234                                  	procedure   MetaCompare,near
   234          ******************       warning: proc MetaCompare... [-w+user]
   235                                  ASSUME	DS:NOTHING,ES:NOTHING
   236 000000BA B90B00                  	MOV	CX,11
   237                                   %IF  DBCS				;AN000;
   238                                  ;-------------------- Start of DBCS	;AN000;
   239                                  	CMP	BYTE PTR [SI],05H	;AN000;; Special case for lead byte of 05h
   240                                  	JNE	WILDCRD2		;AN000;; Compare as normal if not an 05h
   241                                  	CMP	BYTE PTR [ES:DI],0E5H	;AN000;; 05h and 0E5h equivalent for lead byte
   242                                  	JNE	WILDCRD2		;AN000;; Compare as normal if not an 05h
   243                                  	DEC	CX			;AN000;; One less byte to compare
   244                                  	INC	SI			;AN000;; Bypass lead byte in source and
   245                                  	INC	DI			;AN000;;  destination when 05h and 0E5h found.
   246                                  WILDCRD2:				;AN000;
   247                                  	PUSH	AX			;AN000;;KK. save ax
   248                                  cagain: 				;AN000;;KK.
   249                                  	CMP	CX,0			;AN000;;KK. end of compare ?
   250                                  	JLE	metaend2		;AN000;;KK. yes
   251                                  	MOV	AL,[SI] 		;AN000;;KK. is it a Kanji
   252                                  	invoke	testkanj		;AN000;;KK.
   253                                  	JZ	notdb			;AN000;;KK. no
   254                                  	MOV	AX,'??'                 ;AN000;;KK.
   255                                  	CMP	[ES:DI],AX		;AN000;;KK. is es:di pointing to '??'
   256                                  	JNZ	metaend3		;AN000;;KK. no
   257                                  	ADD	SI,2			;AN000;;KK.
   258                                  	ADD	DI,2			;AN000;;KK. update pointers and count
   259                                  subcx:					;AN000;
   260                                  	SUB	CX,2			;AN000;;KK.
   261                                  	JMP	cagain			;AN000;;KK.
   262                                  metaend3:				;AN000;;KK.
   263                                  	CMPSW				;AN000;;KK.
   264                                  	JNZ	metaend2		;AN000;;KK.
   265                                  	JMP	subcx			;AN000;;KK.
   266                                  notdb:					;AN000;
   267                                  	CMPSB				;AN000;;KK. same code ?
   268                                  	JZ	sameco			;AN000;;KK. yes
   269                                  	CMP	BYTE PTR [ES:DI-1],"?"  ;AN000;;KK. ?
   270                                  	JNZ	metaend2		;AN000;;KK. no
   271                                  sameco: 				;AN000;
   272                                  	DEC	CX			;AN000;;KK. decrement count
   273                                  	JMP	cagain			;AN000;;KK.
   274                                  
   275                                  metaend2:				;AN000;
   276                                  	POP	AX			;AN000;;KK.
   277                                  ;-------------------- End of DBCS	;AN000; KK.
   278                                   %ELSE					;AN000;
   279                                  WILDCRD:
   280 000000BD F3A6                    	REPE	CMPSB
   281 000000BF 7407                    	JZ	MetaRet 		; most of the time we will fail.
   282                                  CHECK_META:
   283 000000C1 26807DFF3F              	CMP	BYTE PTR [ES:DI-1],"?"
   284                                  WildCrd equ WILDCRD	; NASM port label
   285 000000C6 74F5                    	JZ	WildCrd
   286                                  MetaRet:
   287                                   %ENDIF					;AN000;
   288 000000C8 C3                      	return				; Zero set, Match
   289                                  EndProc MetaCompare
   290                                  
   291                                  Break	<dos_NEXTENTRY -- STEP THROUGH DIRECTORY>
   292                                  
   293                                  ; Inputs:
   294                                  ;	Same as outputs of GETENTRY, above
   295                                  ; Function:
   296                                  ;	Update BX, and [LASTENT] for next directory entry.
   297                                  ;	Carry set if no more.
   298                                  
   299                                  Procedure dos_NextEntry
   299          ******************       warning: proc dos_NextEntry... [-w+user]
   300                                  	DOSAssume   CS,<DS>,"dos_NextEntry"
   301                                  	ASSUME	ES:NOTHING
   302                                  
   303 000000C9 A1[0000]                	MOV	AX,[LASTENT]
   304 000000CC 3B06[0000]              	CMP	AX,[ENTLAST]
   305 000000D0 7426                    	JZ	NONE
   306 000000D2 40                      	INC	AX
   307 000000D3 8D5F20                  	LEA	BX,[BX+32]
   308 000000D6 39D3                    	CMP	BX,DX
   309 000000D8 7220                    	JB	HAVIT
   310 000000DA B700                    	mov bh, 0
   311                                  SECCLUSPOS equ SecClusPos	; NASM port label
   312 000000DC 8A1E[0000]              	MOV	BL,BYTE PTR [SECCLUSPOS]
   313 000000E0 43                      	inc bx
   314                                  CLUSTER_FACTOR_EDR equ Cluster_Factor_EDR	; NASM port label
   315 000000E1 3B1E[0000]              	cmp bx, word ptr [CLUSTER_FACTOR_EDR]
   316 000000E5 7218                    	JB	SAMECLUS
   317                                  NXTCLUSNUM equ NxtClusNum	; NASM port label
   318 000000E7 8B1E[0000]              	MOV	BX,[NXTCLUSNUM]
   319 000000EB E8(0000)                	Invoke	IsEOF
   320 000000EE 7308                    	JAE	NONE
   321 000000F0 83FB02                  	CMP	BX,2
   322 000000F3 7203                    	JB	NONE
   323 000000F5 EB34                    	JMP	GETENT
   324 000000F7 90                      	nop	; identicalise
   325                                  
   326                                  NONE:
   327 000000F8 F9                      	STC
   328 000000F9 C3                      	return
   329                                  
   330                                  HAVIT:
   331 000000FA A3[0000]                	MOV	[LASTENT],AX
   332 000000FD F8                      	CLC
   333 000000FE C3                      	return
   334                                  
   335                                  SAMECLUS:
   336 000000FF 881E[0000]              	MOV	BYTE PTR [SECCLUSPOS],BL
   337 00000103 A3[0000]                	MOV	[LASTENT],AX
   338 00000106 1E                      	PUSH	DS
   339 00000107 C53E[0000]              	LDS	DI,[CURBUF]
   340                                  ASSUME	DS:NOTHING
   341 0000010B 8B550A                  	MOV	DX,WORD PTR [DI + buf_sector+2]	;AN000; >32mb
   342 0000010E 368916[0000]            	MOV	[ss:HIGH_SECTOR],DX		;AN000; >32mb
   343 00000113 8B5508                  	MOV	DX,WORD PTR [DI + buf_sector]	;AN000; >32mb
   344                                  
   345 00000116 83C201                  	ADD	DX,1				;AN000; >32mb
   346 00000119 368316[0000]00          	ADC	word [ss:HIGH_SECTOR],0 		;AN000; >32mb
   347 0000011F 1F                      	POP	DS
   348                                  	DOSAssume   CS,<DS>,"DIR/SameClus"
   349 00000120 E8(0000)                	invoke	FIRSTCLUSTER
   350 00000123 31DB                    	XOR	BX,BX
   351 00000125 EB25                    	JMP	SETENTRY
   352 00000127 90                      	nop	; identicalise
   353                                  EndProc dos_NextEntry
   354                                  
   355                                  ; Inputs:
   356                                  ;	[LASTENT] has directory entry
   357                                  ;	ES:BP points to drive parameters
   358                                  ;	[DIRSEC],[CLUSNUM],[CLUSFAC],[ENTLAST] set for DIR involved
   359                                  ; Function:
   360                                  ;	Locates directory entry in preparation for search
   361                                  ;	GETENT provides entry for passing desired entry in AX
   362                                  ; Outputs:
   363                                  ;	[CURBUF+2]:BX = Pointer to next directory entry in CURBUF
   364                                  ;	[CURBUF+2]:DX = Pointer to first byte after end of CURBUF
   365                                  ;	[LASTENT] = New directory entry number
   366                                  ;	[NXTCLUSNUM],[SECCLUSPOS] set via DIRREAD
   367                                  ;	Carry set if error (currently user FAILed to I 24)
   368                                  
   369                                  Procedure GETENTRY,NEAR
   369          ******************       warning: proc GETENTRY... [-w+user]
   370                                  	DOSAssume   CS,<DS>,"GetEntry"
   371                                  	ASSUME	ES:NOTHING
   372                                  
   373 00000128 A1[0000]                	MOV	AX,[LASTENT]
   374                                  
   375                                  	entry	GETENT
   376                                  
   377                                  	Assert	ISDPB,<ES,BP>,"GetEntry/GetEnt"
   378 0000012B A3[0000]                	MOV	[LASTENT],AX
   379                                  ;
   380                                  ; Convert the entry number in AX into a byte offset from the beginning of the
   381                                  ; directory.
   382                                  ;
   383 0000012E B105                    	mov	cl,5			; shift left by 5 = mult by 32
   384 00000130 D3C0                    	rol	ax,cl			; keep hight order bits
   385 00000132 89C2                    	mov	dx,ax
   386 00000134 83E0E0                  	and	ax, ~ (32-1)		; mask off high order bits
   387 00000137 83E21F                  	and	dx, 32-1		; mask off low order bits
   388                                  ;
   389                                  ; DX:AX contain the byte offset of the required directory entry from the
   390                                  ; beginning of the directory.  Convert this to a sector number.  Round the
   391                                  ; sector size down to a multiple of 32.
   392                                  ;
   393 0000013A 268B5E02                	MOV	BX,[ES:BP + dpb_sector_size]
   394 0000013E 80E3E0                  	AND	BL,255-31		; Must be multiple of 32
   395 00000141 F7F3                    	DIV	BX
   396 00000143 89D3                    	MOV	BX,DX			; Position within sector
   397 00000145 53                      	PUSH	BX
   398 00000146 E8(0000)                	invoke	DIRREAD
   399 00000149 5B                      	POP	BX
   400 0000014A 72B2                    	retc
   401                                  SETENTRY:
   402 0000014C 8B16[0000]              	MOV	DX,WORD PTR [CURBUF]
   403 00000150 83C210                  	ADD	DX,BUFINSIZ
   404 00000153 01D3                    	ADD	BX,DX
   405 00000155 26035602                	ADD	DX,[ES:BP + dpb_sector_size]  ; Always clears carry
   406 00000159 C3                      	return
   407                                  EndProc GetEntry
   408                                  
   409                                  Break	<SETDIRSRCH SETROOTSRCH -- Set Search environments>
   410                                  
   411                                  ; Inputs:
   412                                  ;	BX cluster number of start of directory
   413                                  ;	ES:BP Points to DPB
   414                                  ;	DI next cluster number from fastopen extended info. DOS 3.3 only
   415                                  ; Function:
   416                                  ;	Set up a directory search
   417                                  ; Outputs:
   418                                  ;	[DIRSTART] = BX
   419                                  ;	[CLUSFAC],[CLUSNUM],[SECCLUSPOS],[DIRSEC] set
   420                                  ;	Carry set if error (currently user FAILed to I 24)
   421                                  ; destroys AX,DX,BX
   422                                  
   423                                  	procedure SETDIRSRCH
   423          ******************       warning: proc SETDIRSRCH... [-w+user]
   424                                  	DOSAssume   CS,<DS>,"SetDirSrch"
   425                                  	ASSUME	ES:NOTHING
   426                                  
   427                                  	Assert	ISDPB,<ES,BP>,"SetDirSrch"
   428 0000015A 09DB                    	OR	BX,BX
   429 0000015C 7440                    	JZ	SETROOTSRCH
   430                                  DIRSTART equ DirStart	; NASM port label
   431 0000015E 891E[0000]              	MOV	[DIRSTART],BX
   432 00000162 31C0                    	xor ax, ax
   433 00000164 268A4604                	MOV	AL,[ES:BP + dpb_cluster_mask]
   434 00000168 40                      	inc ax
   435                                  CLUSFAC equ ClusFac	; NASM port label
   436 00000169 A2[0000]                	MOV	BYTE PTR [CLUSFAC],AL
   437 0000016C A3[0000]                	mov word ptr [CLUSTER_FACTOR_EDR], ax
   438                                  ; DOS 3.3 for FastOPen	F.C. 6/12/86
   439 0000016F 56                      	SaveReg <SI>
   440 00000170 F606[0000]02            	TEST	byte [FastOpenFlg],Lookup_Success
   441 00000175 7507                    	JNZ	UNP_OK
   442                                  
   443                                  ; DOS 3.3 for FastOPen	F.C. 6/12/86
   444 00000177 E8(0000)                	invoke	UNPACK
   445 0000017A 7302                    	JNC	UNP_OK
   446 0000017C 5E                      	RestoreReg  <SI>
   447 0000017D C3                      	return
   448                                  
   449                                  UNP_OK:
   450                                  CLUSNUM equ ClusNum	; NASM port label
   451 0000017E 893E[0000]              	MOV	[CLUSNUM],DI
   452 00000182 89DA                    	MOV	DX,BX
   453 00000184 30DB                    	XOR	BL,BL
   454 00000186 881E[0000]              	MOV	BYTE PTR [SECCLUSPOS],BL
   455 0000018A E8(0000)                	invoke	FIGREC
   456 0000018D 5E                      	RestoreReg  <SI>
   457 0000018E 52                      	PUSH	DX			   ;AN000; >32mb
   458 0000018F 8B16[0000]              	MOV	DX,[HIGH_SECTOR]	   ;AN000; >32mb
   459                                  DIRSEC equ DirSec	; NASM port label
   460 00000193 8916[0200]              	MOV	WORD PTR [DIRSEC+2],DX	   ;AN000; >32mb
   461 00000197 5A                      	POP	DX			   ;AN000; >32mb
   462 00000198 8916[0000]              	MOV	WORD PTR [DIRSEC],DX
   463 0000019C F8                      	CLC
   464 0000019D C3                      	return
   465                                  
   466                                  entry	SETROOTSRCH
   467                                  	DOSAssume   CS,<DS>,"SetRootSrch"
   468                                  	ASSUME	ES:NOTHING
   469 0000019E 31C0                    	XOR	AX,AX
   470 000001A0 A3[0000]                	MOV	[DIRSTART],AX
   471 000001A3 A2[0000]                	MOV	BYTE PTR [SECCLUSPOS],AL
   472 000001A6 48                      	DEC	AX
   473 000001A7 A3[0000]                	MOV	[CLUSNUM],AX
   474 000001AA 268B460B                	MOV	AX,[ES:BP + dpb_first_sector]
   475 000001AE 268B5611                	MOV	DX,[ES:BP + dpb_dir_sector]
   476 000001B2 29D0                    	SUB	AX,DX
   477 000001B4 A2[0000]                	MOV	BYTE PTR [CLUSFAC],AL
   478 000001B7 A3[0000]                	mov word ptr [CLUSTER_FACTOR_EDR], ax
   479 000001BA 8916[0000]              	MOV	WORD PTR [DIRSEC],DX		      ;F.C. >32mb
   480 000001BE 8326[0200]00            	and	WORD PTR [DIRSEC+2],0		      ;F.C. >32mb
   481                                  		; NC from and
   482 000001C3 C3                      	return
   483                                  EndProc SETDIRSRCH
   483          ******************       warning: ***** Possible stack size error in SETDIRSRCH ***** [-w+user]
   484                                  
   485                                      END
