home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / S12334.ZIP / GETDIR.ASM < prev    next >
Assembly Source File  |  1989-03-20  |  3KB  |  82 lines

  1. ;----- GetDir.Asm - retrieves current directory
  2.  
  3. ;Syntax -
  4. ;
  5. ; Drive$ = "A"
  6. ; Dir$ = GetDir$(Drive$)
  7. ; PRINT "Current directory is: " Dir$
  8. ;
  9. ; Where Drive$ = "" for the default drive, or "A" or "a" or "B", etc.
  10. ; and Dir$ receives the current directory path.  If an error occurs,
  11. ; Dir$ will be assigned to a null string.
  12.  
  13. .286
  14. .Model Medium, Basic
  15. .Data
  16.     DescrLen   DW ?
  17.     DescrAdr   DW Offset DirName
  18.     DirName    DB "\", 64 Dup (?)
  19.  
  20. .Code
  21.     Extrn DosQCurDir:Proc    ;declare the OS/2 call as external
  22.  
  23. GetDir Proc, Drive:Ptr
  24.  
  25.     Local LenName:Word       ;create a local variable
  26.  
  27.     Cld                      ;clear direction flag so 
  28.                              ;string moves are forward
  29.     Mov  DescrLen, 0         ;assume a null string in case 
  30.                              ;there's an error
  31.     Mov  LenName,65          ;tells OS/2 the available buffer length
  32.  
  33.  
  34.     Mov  DI,Drive            ;put address of Drive$ into DI
  35.     Mov  DX,[DI]             ;assume they want the default 
  36.                              ;drive for now
  37.     Or   DX,DX               ;check LEN(Drive$)
  38.     Je   Do_It               ;it's null, leave DX holding 0 
  39.                              ;and skip ahead
  40.  
  41.     Mov  DI,[DI+02]          ;put address of first character 
  42.                              ;in Drive$ into DI
  43.     Mov  DL,[DI]             ;put ASC(Drive$) into DL
  44.     Cmp  DL,"a"              ;is it less than "a"?
  45.     Jb   Continue            ;yes, skip
  46.     Sub  DL,32               ;no, convert to upper case
  47.  
  48. Continue:
  49.     Sub  DL,64               ;"A" now equals 1, "B" = 2, etc.
  50.  
  51. Do_It:
  52.     Mov  DI,Offset DirName   ;get address for the string descriptor
  53.     Inc  DI                  ;bump past the leading backslash
  54.     Mov  SI,DI               ;save it in SI too for later
  55.  
  56.     Push DX                  ;pass the drive number
  57.     Push DS                  ;show which segment receives the name
  58.  
  59.     Push DI                  ;and which address
  60.     Push SS                  ;pass segment for LenName 
  61.                              ;(SS because it's local)
  62.     Lea  CX,LenName          ;get address for LenName
  63.     Push CX                  ;and pass that too
  64.  
  65.     Call DosQCurDir          ;ask OS/2 to do the dirty work
  66.     Or   AX,AX               ;was there an error?
  67.     Jnz  Exit                ;yes, get out with DescrLen 
  68.                              ;showing a null string
  69.  
  70. AddLen:                      ;scan for zero byte that marks the end
  71.     Inc  DescrLen            ;show the string as being one longer
  72.     Lodsb                    ;get a character from directory string
  73.     Or   AL,AL               ;are we at the end of directory name?
  74.     Jnz  AddLen              ;no, keep searching
  75.  
  76. Exit:
  77.     Mov  AX,Offset DescrLen  ;tell BASIC where to find the descriptor
  78.     Ret                      ;return to BASIC
  79.  
  80. GetDir Endp
  81. End
  82.