home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / w3_syst / setup.arj / DOS.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-06-25  |  8.9 KB  |  278 lines

  1. ;****************************************************************************
  2. ;*                                                                          *
  3. ;*  WFDOSDIR.ASM -                                                          *
  4. ;*                                                                          *
  5. ;*      Directory searching primitives                                      *
  6. ;*                                                                          *
  7. ;****************************************************************************
  8.  
  9. ?PLM=1      ; PASCAL Calling convention is DEFAULT
  10. ?WIN=1      ; Windows calling convention
  11. ?386=0      ; Use 386 code?
  12.  
  13. include cmacros.inc
  14.  
  15. ; The following structure should be used to access high and low
  16. ; words of a DWORD.  This means that "word ptr foo[2]" -> "foo.hi".
  17.  
  18. externFP    <DOS3CALL>
  19.  
  20. LONG    struc
  21. lo      dw      ?
  22. hi      dw      ?
  23. LONG    ends
  24.  
  25. FARPOINTER      struc
  26. off     dw      ?
  27. sel     dw      ?
  28. FARPOINTER      ends
  29.  
  30. ifndef SEGNAME
  31.     SEGNAME equ <TEXT>
  32. endif
  33.  
  34. if ?386
  35.     createSeg _%SEGNAME, CodeSeg, word, use16, CODE
  36. else
  37.     createSeg _%SEGNAME, CodeSeg, word, public, CODE
  38. endif
  39.  
  40. NOT_SUPPORTED     =  2h      ; Return code from IsDeviceRemote function.
  41. REMOTE            =  3h      ; Return code for remote drive found.
  42. TRUE              =  1h      ; TRUE Definition
  43. FALSE             =  0h      ; False Definition.
  44.  
  45. ;=============================================================================
  46.  
  47. sBegin DATA
  48.  
  49. VolExtendedFCB  db  0FFh
  50.                 db  0, 0, 0, 0, 0
  51.                 db  1000b
  52.                 db  0
  53.                 db  11 dup('?')
  54.                 db  5 dup(0)
  55.                 db  11 dup('?')
  56.                 db  9 dup(0)
  57.  
  58. DTA             db  64 dup(0)
  59.  
  60. sEnd   DATA
  61.  
  62. ;=============================================================================
  63.  
  64. sBegin CodeSeg
  65.  
  66. assumes CS,CodeSeg
  67. assumes DS,DATA
  68.  
  69. ;*--------------------------------------------------------------------------*
  70. ;*                                                                          *
  71. ;*  DosMkDir()                                                              *
  72. ;*                                                                          *
  73. ;*--------------------------------------------------------------------------*
  74.  
  75. cProc DosMkDir, <FAR, PUBLIC>
  76. ParmD   szDir
  77. cBegin
  78.         lds     dx,szDir
  79.         mov     ah,39h
  80.         cCall   DOS3Call
  81.         jc      mderror
  82.         xor     ax,ax
  83.         jmp     short mdexit
  84.  
  85. mderror:
  86.         mov     ah,59h
  87.         xor     bx,bx
  88.         cCall   DOS3Call
  89.            
  90. mdexit:
  91.  
  92. cEnd
  93.  
  94. ;*--------------------------------------------------------------------------*
  95. ;*                                                                          *
  96. ;*  GetCurrentDrive() -                                                     *
  97. ;*                                                                          *
  98. ;*--------------------------------------------------------------------------*
  99.  
  100. cProc GetCurrentDrive, <FAR, PUBLIC>
  101.  
  102. cBegin
  103.         mov     ah,19h              ; Get Current Drive
  104.         cCall   DOS3Call
  105.         sub     ah,ah               ; Zero out AH
  106. cEnd
  107.  
  108. ;*--------------------------------------------------------------------------*
  109. ;*                                                                          *
  110. ;*  ResetController() -                                                     *
  111. ;*                                                                          *
  112. ;*--------------------------------------------------------------------------*
  113.  
  114. cProc ResetController, <FAR, PUBLIC>
  115.  
  116. cBegin
  117.         mov     ah,00h              ; Get Current Drive
  118.         mov     dl,00h
  119.         int     13h
  120. cEnd
  121.  
  122. ;*--------------------------------------------------------------------------*
  123. ;*                                                                          *
  124. ;*  GetCurrentDirectory() -                                                 *
  125. ;*                                                                          *
  126. ;*--------------------------------------------------------------------------*
  127.  
  128. cProc DosCwd, <FAR, PUBLIC>, <SI, DI>
  129.  
  130. ParmD lpDest
  131.  
  132. cBegin
  133.             push    ds                  ; Preserve DS
  134.  
  135.             call    GetCurrentDrive
  136.             mov     si,ax               ; SI = Current drive
  137.  
  138.             les     di,lpDest           ; ES:DI = lpDest
  139.             push    es
  140.             pop     ds                  ; DS:DI = lpDest
  141.             cld
  142.             mov     ax,si               ; AX = Current drive
  143.             inc     al                  ; Convert to logical drive number
  144.             mov     dl,al               ; DL = Logical Drive Number
  145.             add     al,'@'              ; Convert to ASCII drive letter
  146.             stosb
  147.             mov     al,':'
  148.             stosb
  149.             mov     al,'\'              ; Start string with a backslash
  150.             stosb
  151.             mov     byte ptr es:[di],0  ; Null terminate in case of error
  152.             mov     si,di               ; DS:SI = lpDest[1]
  153.             mov     ah,47h              ; Get Current Directory
  154.             cCall   DOS3Call
  155.             jc      CDExit              ; Skip if error
  156.             xor     ax,ax               ; Return FALSE if no error
  157. CDExit:
  158.             pop     ds                  ; Restore DS
  159. cEnd
  160.  
  161. ;*--------------------------------------------------------------------------*
  162. ;*                                                                          *
  163. ;*  SetCurrentDrive() -                                                     *
  164. ;*                                                                          *
  165. ;*--------------------------------------------------------------------------*
  166.  
  167. ; Returns the number of drives in AX.
  168.  
  169. cProc SetCurrentDrive, <FAR, PUBLIC>
  170.  
  171. ParmW Drive
  172.  
  173. cBegin
  174.             mov     dx,Drive
  175.             mov     ah,0Eh              ; Set Current Drive
  176.             cCall   DOS3Call
  177.             sub     ah,ah               ; Zero out AH
  178. cEnd
  179.  
  180. ;*--------------------------------------------------------------------------*
  181. ;*                                                                          *
  182. ;*  SetCurrentDirectory() -                                                 *
  183. ;*                                                                          *
  184. ;*--------------------------------------------------------------------------*
  185.  
  186. cProc DosChDir, <FAR, PUBLIC>
  187.  
  188. ParmD lpDirName
  189.  
  190. cBegin
  191.             push    ds                  ; Preserve DS
  192.             lds     dx,lpDirName        ; DS:DX = lpDirName
  193.  
  194.             mov     bx,dx
  195.             mov     ax,ds:[bx]
  196.             cmp     ah,':'
  197.             jnz     cdnodrive
  198.  
  199.             ;
  200.             ;       Convert drive letter to drive index
  201.             ;
  202.             or      al,20h
  203.             sub     al,'a'
  204.             xor     ah,ah
  205.  
  206.             push    dx
  207.             cCall   SetCurrentDrive,<ax>
  208.             pop     dx
  209. cdnodrive:
  210.             mov     ah,3Bh              ; Change Current Directory
  211.             cCall   DOS3Call
  212.             jc      SCDExit             ; Skip on error
  213.             xor     ax,ax               ; Return FALSE if successful
  214. SCDExit:
  215.             pop     ds                  ; Restore DS
  216. cEnd
  217.  
  218. ;*--------------------------------------------------------------------------*
  219. ;*                                                                          *
  220. ;*  DosValidDir()                                                           *
  221. ;*                                                                          *
  222. ;*--------------------------------------------------------------------------*
  223.  
  224. cProc DosValidDir, <FAR, PUBLIC>, <SI, DI>
  225. ParmD       szDir
  226. LocalV      szCwd, 128
  227. cBegin
  228.     lea     si,szCwd
  229.     cCall   DosCwd,<ss,si>
  230.     push    szDir.sel
  231.     push    szDir.off
  232.     call    DosChDir
  233.     or      ax,ax
  234.     pushf
  235.     cCall   DosChDir,<ss,si>
  236.     ;
  237.     ;   return TRUE if DosChdir returns 0, FALSE otherwise
  238.     ;
  239.     xor     ax,ax                ; don't care about this return val.
  240.     popf
  241.     jnz     vdexit
  242.     inc     ax
  243. vdexit:
  244.  
  245. cEnd
  246.  
  247. ;*--------------------------------------------------------------------------
  248. ;*
  249. ;*  LONG DosDiskFreeSpace(Drive)
  250. ;*
  251. ;*  note:
  252. ;*      Drive == 0      default
  253. ;*      Drive == 1      A
  254. ;*      Drive == 2      B
  255. ;*--------------------------------------------------------------------------
  256.  
  257. ; Returns the number of bytes free in DX:AX
  258.  
  259. cProc DosDiskFreeSpace, <FAR, PUBLIC>
  260. ParmW Drive
  261. cBegin
  262.             mov     dx,Drive
  263.             mov     ah,36h              ; Set Current Drive
  264.             cCall   DOS3Call
  265.             cmp     ax, 0ffffh          ; bogus drive?
  266.             je      error
  267.             mul     cx                  ;
  268.             mul     bx
  269.             jmp     done                ; DX:AX contains free space
  270. error:
  271.             mov     dx, ax              ; return dx:ax = -1L
  272. done:
  273. cEnd
  274.  
  275. sEnd CodeSeg
  276.  
  277. end
  278.