home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / SAMPLES / INSTVER / DOS.AS_ / DOS.AS
Encoding:
Text File  |  1993-02-08  |  8.2 KB  |  268 lines

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