home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / batutl / ifexist.arc / DIROF.ASM next >
Assembly Source File  |  1987-10-05  |  5KB  |  126 lines

  1. Title   DirOf   Check for a directory - 10/05/87 - Davy Crockett
  2.  
  3. ;       ╔═══╦═══════════════════════════════╦═══╗
  4. ;       ║▒▒▒║   Davy Crockett Productions   ║▒▒▒║
  5. ;       ║▒▒▒║   5807 Cherrywood Lane, 104   ║▒▒▒║
  6. ;       ║▒▒▒║   Greenbelt, Maryland 20770   ║▒▒▒║
  7. ;       ╚═══╩═══════════════════════════════╩═══╝
  8.  
  9. RetNear Macro
  10.         DB      0C3H
  11.         Endm
  12.  
  13. Cseg    Segment
  14.         Assume  DS:Cseg, SS:Cseg, CS:Cseg, ES:Cseg
  15.  
  16.         Org     100H
  17.  
  18. Null    Equ     00H
  19. CR      Equ     0DH
  20. LF      Equ     0AH
  21. Parms   Equ     80H
  22.  
  23. DirOf:
  24.         Mov     BX,Parms                ; point to trailer
  25.         Cmp     Byte Ptr [BX],Null      ; anything there?
  26.         Jnz     GetDefault              ; yes, continue
  27.         Jmp     DisplayHelp             ; no, display help screen
  28.  
  29. GetDefault:
  30.         Mov     AH,19H                  ; function code to
  31.         Int     21H                     ;  obtain default drive
  32.         Add     AL,'A'                  ; adjust to ascii
  33.         Mov     DriveName,AL            ;  and save for later
  34.  
  35.         Mov     SI,Offset 2[Parms]      ; point to trailer
  36.         Mov     DI,Offset DriveName     ; point to buffer
  37.         Cmp     Byte Ptr 1[SI],':'      ; drive included?
  38.         Jz      MoveTrailer             ; yes, use it
  39.         Mov     DI,Offset 2[DriveName]  ; no, use default drive
  40.  
  41. MoveTrailer:
  42.         Lodsb                           ; pick up a byte
  43.         Cmp     AL,CR                   ; end of trailer?
  44.         Jz      TerminateTrailer        ; yes, go make ASCIIZ
  45.         Stosb                           ; no, store this byte
  46.         Jmp     Short   MoveTrailer     ;  and look for more
  47.  
  48. TerminateTrailer:
  49.         Xor     al,al                   ; terminate the string
  50.         Stosb
  51.  
  52. CheckForDisk:
  53.         Call    Ready                   ; disk in drive?
  54.         Jc      NoDiskExit              ; no, exit stage left
  55. SetDTA:
  56.         Mov     DX,Offset DiskBuffer    ; point to DTA
  57.         Mov     AH,1AH                  ; Set DTA function
  58.         Int     21H                     ; set Data Transfer Address
  59. FindFirst:
  60.         Mov     DX,Offset DriveName     ; point to path name
  61.         Mov     CX,10H                  ; attribute = dir's only
  62.         Mov     AH,4EH                  ; FindFirst Function
  63.         Int     21H                     ; find the directory
  64.         Jc      NotFoundExit            ; error, exit stage left
  65. StatusTest:
  66.         Cmp     Byte Ptr 21[DiskBuffer],10H ; Dir?
  67.         Jz      FoundExit
  68. FindNext:
  69.         Mov     AH,4FH                  ; FindNext Function
  70.         Int     21H                     ; get another one
  71.         Jnc     StatusTest              ; go check this one
  72.  
  73. NotFoundExit:
  74.         Mov     AL,1                    ; not found return code
  75.         Jmp     Short   DirOfExit       ; exit state left
  76. FoundExit:
  77.         Mov     AL,2                    ; found the bugger!
  78.         Jmp     Short   DirOfExit       ; exit state left
  79. DisplayHelp:
  80.         Mov     DX,Offset FileName      ; point to message
  81.         Mov     AH,09H                  ; display string function
  82.         Int     21H                     ; StdOut
  83. NoDiskExit:
  84.         Mov     AL,0                    ; no disk return code
  85. DirOfExit:
  86.         Mov     AH,4CH                  ; terminate a process
  87.         Int     21H                     ; exit stage left
  88.  
  89. Ready:
  90.         Mov     AL,DriveName            ; drive letter
  91.         And     AL,5FH                  ; upper case
  92.         Sub     AL,'A'                  ; adjust to binary
  93.         Mov     BX,Offset DiskBuffer    ; disk buffer address
  94.         Mov     CX,1                    ; number of sectors
  95.         Mov     DX,0                    ; beginning sector number
  96.         Int     25H                     ; absolute disk read
  97.         Pop     BX                      ; remove flags from stack
  98.         RetNear                         ; exit stage right
  99.  
  100. DriveName       DB      '?:'
  101. FileName        Equ     $
  102.                 DB      CR,LF,LF
  103.                 DB      '«*» DirOf «*» Version 1.0 «*» 05 Oct 1987 '
  104.                 DB      '«*» Davy Crockett «*»',CR,LF,LF
  105.                 DB      'Tests for the existence of a Sub-Directory. ',CR,LF,LF
  106.                 DB      '    Execute:  DirOf [pathname]  ',CR,LF,LF
  107. DiskBuffer      Equ     $
  108.                 DB      '    Return Code = 0, no diskie in the drive.',CR,LF
  109.                 DB      '    Return Code = 1, directory does not exist.',CR,LF
  110.                 DB      '    Return Code = 2, directory was found.',CR,LF,LF
  111.                 DB      '$'
  112.  
  113. DirOfLen        Equ     (This Byte) - (Offset DirOf)
  114. Filler          Equ     432 - DirOfLen
  115.                 DB      Filler DUP(0)
  116. CopyRight       Equ     $
  117.                 DB      '╔═════════════╗ '
  118.                 DB      '║Davy Crockett║ '
  119.                 DB      '║ Productions ║ '
  120.                 DB      '║ 05 Oct 1987 ║ '
  121.                 DB      '╚═════════════╝'
  122.  
  123. Cseg    Ends
  124.  
  125. End     DirOf
  126.