Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

266 lines
6.5 KiB

  1. title dosa.asm
  2. ;
  3. ; ASM routines lifted from WINCOM
  4. ;
  5. ; ToddLa & RussellW
  6. ;
  7. ; DavidLe removed all but current drive/directory functions
  8. ;
  9. ?PLM=1 ; PASCAL Calling convention is DEFAULT
  10. ?WIN=0 ; Windows calling convention
  11. PMODE=1 ; Enable enter/leave
  12. .xlist
  13. include cmacros.inc
  14. .list
  15. ; -------------------------------------------------------
  16. ; DATA SEGMENT DECLARATIONS
  17. ; -------------------------------------------------------
  18. ifndef SEGNAME
  19. SEGNAME equ <_TEXT>
  20. endif
  21. createSeg %SEGNAME, CodeSeg, word, public, CODE
  22. sBegin CodeSeg
  23. assumes CS,CodeSeg
  24. assumes DS,Data
  25. assumes ES,nothing
  26. ; ----------------------------------------------------------------
  27. ;
  28. ; @doc INTERNAL
  29. ; @api int | DosChangeDir | This function changes the current drive
  30. ; and directory.
  31. ;
  32. ; @parm LPSTR | lpszPath | Points to the desired drive and directory path.
  33. ; The optional drive identifier must be the first character, followed by
  34. ; a colon. The drive identifier is followed by an optional path
  35. ; specification, which may be relative or absolute.
  36. ;
  37. ; @rdesc Returns one of the following values:
  38. ;
  39. ; @flag 1 The drive and directory were successfully changed.
  40. ; @flag 0 The specified pathname is invalid. The drive and
  41. ; current directory is restored
  42. ; to the default values when the function was called.
  43. ; @flag -1 The specified drive is invalid. The drive and directory
  44. ; current directory is restored to the default values when the
  45. ; function was called.
  46. ;
  47. ; @xref DosGetCurrentDir, DosGetCurrentPath, DosGetCurrentDrive
  48. ;
  49. szCurDir:
  50. db '.',0
  51. cProc DosChangeDir,<PUBLIC, FAR, PASCAL>, <ds>
  52. parmD lpszPath
  53. LocalW fDriveChange
  54. LocalW wLastDrive
  55. LocalW wReturn
  56. LocalV szPoint, 2
  57. cBegin
  58. mov fDriveChange, 0
  59. lds dx, lpszPath
  60. mov bx, dx
  61. ; Check if a drive was specified. If not, then go direct to ChDir
  62. cmp BYTE PTR ds:[bx+1],':' ; no drive allowed
  63. jnz chdnodrive
  64. ; get the current drive to save it in case the drive change/
  65. ; dir change fails, so we can restore it.
  66. mov ah, 19h
  67. int 21h
  68. mov wLastDrive, ax
  69. mov fDriveChange, 1 ; flag the drive change
  70. ; Now, change the drive to that specified in the input
  71. ; string.
  72. mov dl, ds:[bx] ; Get the drive letter
  73. or dl, 20h ; lower case it
  74. sub dl, 'a' ; and adjust so 0 = a:, 1 = b:, etc
  75. mov ah, 0eh ; set current drive
  76. int 21h
  77. mov ah, 19h ; get current drive
  78. int 21h
  79. cmp al, dl ; check that chDrive succeeded
  80. jne chdDriveError
  81. ; as a further test of whether the drive change took, attempt
  82. ; to change to the current directory on the new drive.
  83. mov ax, cs
  84. mov ds, ax
  85. mov dx, CodeSegOFFSET szCurDir
  86. mov ah, 3bh
  87. int 21h
  88. jc chdDriveError
  89. lds dx, lpszPath
  90. add dx, 2 ; skip over the drive identifier
  91. mov bx, dx
  92. ;; if they passed only drive: without dir path, then end now
  93. cmp BYTE PTR ds:[bx], 0 ; if path name is "", we are there
  94. jz chdok
  95. chdnodrive:
  96. mov ah, 3bh
  97. int 21h
  98. jc chdPathError
  99. chdok:
  100. mov ax, 1
  101. chdexit:
  102. cEnd
  103. chdPathError:
  104. mov wReturn, 0
  105. jmp short chderror
  106. chdDriveError:
  107. mov wReturn, -1
  108. chderror:
  109. ; if a drive change occurred, but the CD failed, change
  110. ; the drive back to that which was the original drive
  111. ; when entered.
  112. mov ax, fDriveChange
  113. or ax, ax
  114. jz chdNoCD
  115. mov dx, wLastDrive
  116. mov ah, 0eh
  117. int 21h
  118. mov ax, wReturn
  119. jmp short chdexit
  120. chdNoCD:
  121. xor ax, ax ; return zero on error
  122. jmp short chdexit
  123. ; ----------------------------------------------------------------
  124. ;
  125. ; @doc INTERNAL
  126. ; @api WORD | DosGetCurrentDrive | This function returns the drive identifier
  127. ; of the current drive.
  128. ; @rdesc Returns the drive code of the current drive: 0 is drive
  129. ; A:, 1 is drive B:, etc.
  130. ;
  131. ; @comm This function assumes that drive A: is zero. Some
  132. ; other DOS functions assume drive A: is one.
  133. ;
  134. ; @xref DosSetCurrentDrive
  135. ;
  136. cProc DosGetCurrentDrive,<PUBLIC, FAR, PASCAL>
  137. cBegin
  138. mov ah, 19h ; Get Current Drive
  139. int 21h
  140. sub ah, ah ; Zero out AH
  141. cEnd
  142. ; ----------------------------------------------------------------
  143. ;
  144. ; @doc INTERNAL WINCOM
  145. ; @api WORD | DosSetCurrentDrive | This function sets the current DOS
  146. ; drive to be the specified drive.
  147. ;
  148. ; @parm WORD | wDrive | Specifies the drive to be set as the current drive.
  149. ; 0 indicates drive A:, 1 is B:, etc.
  150. ;
  151. ; @rdesc Returns TRUE if the drive change was successful, or FALSE
  152. ; if the current drive was not changed.
  153. ;
  154. ; @comm This is the same range returned by <f DosGetCurrentDrive>.
  155. ; Other functions assume drive A: is 1.
  156. ;
  157. ;
  158. ; @xref DosGetCurrentDrive
  159. ;
  160. cProc DosSetCurrentDrive,<FAR, PUBLIC, PASCAL>
  161. ParmW Drive
  162. cBegin
  163. mov dx, Drive
  164. mov ah, 0Eh ; Set Current Drive
  165. int 21h
  166. ; Check if successful
  167. mov ah, 19h ; get current drive
  168. int 21h
  169. cmp al, dl ; check that chDrive succeeded
  170. jne SetDriveError
  171. mov ax, 1h ; return true on success
  172. SetDriveExit:
  173. cEnd
  174. SetDriveError:
  175. xor ax, ax ; return false on error
  176. jmp short SetDriveExit
  177. ; ----------------------------------------------------------------
  178. ;
  179. ; @doc INTERNAL WINCOM
  180. ;
  181. ; @api WORD | DosGetCurrentDir | This function copies the current
  182. ; directory of the specified drive into a caller-supplied buffer. This
  183. ; function differs from the <f DosGetCurrentPath> function in that it
  184. ; copies only the current directory of the specified drive, whereas
  185. ; <f DosGetCurrentPath> copies the current drive and its current directory
  186. ; into the caller's buffer.
  187. ;
  188. ; @parm WORD | wCurdrive | Specifies the drive. 0 is the default drive,
  189. ; 1 is drive A, 2 is drive B, etc.
  190. ;
  191. ; @parm LPSTR | lpszBuf | Points to the buffer in which to place the
  192. ; current directory. This buffer must be 66 bytes in length.
  193. ; The returned directory name will always have a leading '\' character.
  194. ;
  195. ; @rdesc Returns NULL if the function succeeded. Otherwise, it returns
  196. ; the DOS error code.
  197. ;
  198. ; @comm The drive identifier value specified by <p wCurdrive>
  199. ; assumes that drive A: is one, whereas the <f DosGetCurrentDrive>
  200. ; function assumes that drive A: is zero.
  201. ;
  202. ; @xref DosGetCurrentDrive, DosChangeDir, DosGetCurrentPath
  203. ;
  204. cProc DosGetCurrentDir,<PUBLIC,FAR,PASCAL>,<si,di,ds>
  205. parmW wCurdrive
  206. parmD lpDest
  207. cBegin
  208. cld
  209. les di, lpDest ; es:di = lpDest
  210. mov al, '\'
  211. stosb
  212. push es
  213. pop ds ; ds = es
  214. mov si, di ; ds:si = lpDest + 1
  215. ; Add NULL char for case of error
  216. xor al, al
  217. stosb ; null terminate in case of error
  218. mov ah, 47h ; GetCurrentDirectory
  219. mov dx, wCurdrive ; of this drive
  220. int 21h
  221. jc CWDexit ; return error code for failure
  222. xor ax, ax ; return NULL on success
  223. CWDexit:
  224. cEnd
  225. sEnd CodeSeg
  226. end