home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 183_01 / dirgt.asm < prev    next >
Assembly Source File  |  1985-10-29  |  14KB  |  325 lines

  1. page ,132
  2. title **** DIRGT.ASM ***
  3. comment *
  4.  
  5. =========================================================================
  6. DIRGT.ASM
  7. 03-06-85  by  Thomas E. Link
  8.  
  9.      Procedure to be called from IBM PASCAL V2.0 or function in LATTICE C
  10. to get disk directory including VOLUME NAME, file LENGTH,DATE, and TIME.
  11.  
  12. To use in PASCAL first:
  13.         type  dirrect = record
  14.                 fname:string(12);
  15.                 ftime:word;
  16.                 fdate:word;
  17.                 flen:array[0..1] of word;
  18.                 end;
  19.               lookst = string(40);
  20.               volst = string(13);
  21.               countt = word;
  22.         var   dir_rec : array[0..111] of dirrect;
  23.  
  24.        looks := 'drive id:\path\filename.ext'+CHR(0)
  25.            ' name to search for, same as with DIR command
  26.            ' path works only when used with DOS 2.x
  27.            ' This string must terminate with a CHR$(0) !
  28.  
  29.    procedure DIRGET(var looks lookst; var dir_rec[0]:dirrect;
  30.                     var vols:volst; var count:countt);extern;
  31.         If Assembling for PASCAL leave the equate (pascal equ 1) below.
  32.         If using LATTICE C delete that line.
  33. =========================================================================
  34. *
  35. pascal equ 1
  36. page
  37. workstruc       struc
  38.         dircount        dw      (?)
  39.         dos_version     db      (?)
  40.         filler          db      (?)
  41.         saved_sp        dw      (?)
  42.         fcb             db      48 dup (?)
  43.         dta             db      48 dup (?)
  44. workstruc       ends
  45.  
  46. ifdef   pascal  ;-------------------------------------------------------
  47. stack   struc                        ; Define the stack area for PASCAL
  48.         workarea        db      type workstruc dup (?)
  49.         pushed_bp       dw      (?)
  50.         return          dw      (?)
  51.         address         dw      (?)
  52.         countnumad      dw      (?)
  53.         volstrgad       dw      (?)
  54.         dirrecarad      dw      (?)
  55.         lookstringad    dw      (?)
  56. stack   ends
  57.         poplen  equ     lookstringad - address
  58.  
  59. else    ;----------------- 
  60.  
  61. stack   struc                      ; Define the stack area for C.
  62.         workarea        db      type workstruc dup (?)
  63.         pushed_bp       dw      (?)
  64.         address         dw      (?)
  65.         countnumad      dw      (?)
  66.         volstrgad       dw      (?)
  67.         dirrecarad      dw      (?)
  68.         lookstringad    dw      (?)
  69. stack   ends
  70.         poplen  equ     0
  71.  
  72. endif   ;---------------------------------------------------------------
  73.  
  74. data    segment public  'DATA'
  75. data    ends
  76. dgroup  group   data
  77.  
  78. ifdef   pascal ;---------- Pascal --------------------------------------
  79. prog    segment public 'CODE'
  80.         assume CS:prog, DS:nothing, ES:nothing
  81.         public  DIRGET
  82. DIRGET  proc    far
  83.  
  84. else    ;----------------- C definitions
  85. pgroup  group   prog
  86.         assume  CS:pgroup, DS:nothing, ES:nothing
  87. prog    segment public  'PROG'
  88.         public  DIRGET,_DIRGET,DIRGET_
  89. DIRGET  proc    near
  90.  
  91. endif   ;----------------------------------------------------------------
  92.  
  93. page
  94. DIRGET_:
  95. _DIRGET:
  96.         cld                          ; Clear direction flag.
  97.         push    bp
  98.         mov     bp,sp                ; Point to arguments on stack.
  99.         sub     bp,type workstruc    ; Give us room to work
  100.         mov     [bp].saved_sp,sp     ; Save the stack pointer
  101.         mov     sp,bp                ; and move it below workarea.
  102.         mov     [bp].dircount,0      ; Move zero to directory count.
  103.  
  104. ;----------------- determine DOS version, store in variable
  105.         mov     ah,48                ; find DOS version number
  106.         int     21h
  107.         mov     [bp].dos_version,al  ; and store in variable
  108.  
  109. ;-----------------  parse filename
  110.         mov     ax,ss
  111.         mov     es,ax           ; Have ES point at STACK **************
  112.         mov     di,bp           ; and DI point 
  113.         add     di,offset fcb   ;            to FCB area.
  114.         mov     si,[bp].lookstringad    ; Point SI at file specifier
  115.         mov     ah,29H          ; DOS function to parse filename
  116.         mov     al,1            ; scan off leading separators
  117.         int     21H             ; DOS function call
  118.         push    ds              ; Get DATA seg into ES.***************
  119.         pop     es
  120.         cmp     al,0FFH         ; Any errors on parsing ?
  121.         jne     dir2            ; No - continue
  122.         jmp     done            ; YES - end.
  123.  
  124. ;----------------- get addresses of the parms
  125. dir2:
  126.         mov     dx,bp           ; Put address of workspace into DX
  127.         add     dx,offset dta   ; Bump to DTA
  128.         push    ds              ; Save value of DS
  129.         mov     ax,ss           ; and move STACK into DS.**************
  130.         mov     ds,ax
  131.         mov     ah,1AH          ; Set AH for *SET DTA* function call.
  132.         int     21H             ; Use DOS interrupt.
  133.  
  134.         cmp     [bp].dos_version,2 ; if DOS 2.0 or greater
  135.         jae     dos2_search        ; use special routine
  136.  
  137. ;----------------- DOS 1.0, 1.1 search
  138.         mov     dx,bp           ; Point DX at workspace
  139.         add     dx,offset fcb   ;       bump to FCB area.
  140.         mov     ah,11H          ; Set AH for directory search.
  141.         int     21H             ; Use DOS interrupt.
  142.         cmp     al,0FFH         ; Any matches found ?
  143.         je      done1           ; No - so end
  144.         inc     [bp].dircount   ; Yes - count first entry.
  145.         call    move            ; Go move entry into fnames().
  146. dirloop:
  147.         mov     ah,12H          ; Set AH for continuation of search.
  148.         int     21H             ; Use DOS interrupt.
  149.         cmp     al,0FFH         ; Any matches found ?
  150.         je      done1           ; No - jump to exit
  151.         inc     [bp].dircount   ; Yes - count this entry.
  152.         call    move            ; Go move entry into arrays.
  153.         jmp     dirloop         ; Do again.
  154.  
  155. ;----------------- DOS 2.x  search
  156. dos2_search:
  157.         mov     dx,[bp].lookstringad    ; Point DX at file specifier
  158.         mov     ah,4EH          ; Set AH for directory search.
  159.         mov     cx,10H          ; search for files and directories.
  160.         int     21H             ; Use DOS interrupt.
  161.         jc      findlabel       ; No matches - so look for a label
  162.         inc     [bp].dircount   ; found - count first entry.
  163.         call    move2           ; Go move entry into arrays.
  164. dir2loop:
  165.         mov     cx,10H
  166.         mov     ah,4FH          ; Set AH for continuation of search.
  167.         int     21H             ; Use DOS interrupt.
  168.         jc      findlabel       ; No matches - so look for a label
  169.         inc     [bp].dircount   ; match - count this entry.
  170.         call    move2           ; Go move entry into arrays.
  171.         jmp     dir2loop        ; Do again.
  172. findlabel:
  173.         call    get_label       ; look for a volume label
  174. done1:
  175.         pop     ds              ; restore DS to DATA  ****************
  176. done:
  177.         mov     ax,[bp].dircount      ; Move entries count to AX.
  178.         mov     di,[bp].countnumad    ; Get address of COUNT%
  179.         mov     [di],ax         ; Put entry count in COUNT%.
  180.         mov     sp,[bp].saved_sp      ; Restore SP.
  181.         pop     bp              ; Restore BP.
  182.         ret     poplen          ; Return and throw away parms if PASCAL
  183.  
  184. ;........................................................................
  185. ;----------------- procedure to store results from DOS 1.x search
  186. move    proc    near
  187. ;----------------- first move filename into string array
  188.         mov     di,[bp].dirrecarad   ; Move name address to DI and BX.
  189.         mov     bx,di
  190.         add     bx,20           ; Have BX point at next record
  191.         mov     [bp].dirrecarad,bx   ; and save in variable
  192.         mov     si,bp
  193.         add     si,offset dta+1 ; put file name(in DTA) address into SI
  194.         mov     cx,4            ; Length of name in words
  195.         rep     movsw           ; Move name into array.
  196.         mov     byte ptr [di],'.' ; Put period in filename.
  197.         inc     di              ; Bump DI past '.'
  198.         mov     cx,3            ; Length of extension in bytes
  199.         rep     movsb           ; Move extension into array.
  200. ;-----------------  get the file time into array
  201.         add     si,11           ; move to file time area
  202.                 movsw           ; Move time into array.
  203. ;-----------------  get the file date into array
  204.                 movsw           ; Move size into array.
  205. ;-----------------  get the file length into array
  206.         add     si,2            ; Point SI at file size.
  207.                 movsw           ; Move size into array.
  208.                 movsw
  209.         ret
  210. move    endp
  211.  
  212. ;........................................................................
  213. ;----------------- procedure to store results of DOS 2.x search
  214. move2   proc    near
  215. ;----------------- first get the file time into array
  216.         mov     si,bp
  217.         add     si,offset dta +22 ; Point AX at DTA + 22
  218.         mov     bx,[bp].dirrecarad    ; Move record address to BX and DI.
  219.         mov     di,bx
  220.         add     di,12           ; Bump DI to time.
  221.                 movsw           ; Move time into array.
  222. ;----------------- now get the file date into array
  223.                 movsw           ; Move size into array.
  224. ;----------------- get the file length into array
  225.                 movsw           ; Move size into array.
  226.                 movsw
  227. ;-----------------  move filename into string array
  228.         mov     di,bx           ; Point DI at name.
  229.         add     bx,20           ; Bump BX to next record.
  230.         mov     [bp].dirrecarad,bx ; Save it in variable space.
  231.         mov     cx,8            ; Length of name in bytes
  232. move201:
  233.                 lodsb           ; Move character into al
  234.         cmp     al,'.'          ; If is it a period ... jump.
  235.         je      move202
  236.         cmp     al,0            ; If zero - dont jump.
  237.         jne     move201A
  238.         add     cx,4
  239.         mov     al,' '          ; Fill with spaces
  240.         rep     stosb           ; till 12 characters filled.
  241.         jmp     move203         ; Skip to subdir check.
  242. move201A:
  243.                 stosb           ; A character - store it in output string
  244.         loop    move201
  245.         inc     si              ; We found 8 characters - bump SI past .
  246.         jmp     move2020
  247. move202:
  248.         mov     al,' '          ; Pad short name with spaces.
  249.         rep     stosb
  250. move2020:
  251.         inc     di
  252.         mov     cx,3            ; Length of extension in bytes
  253. move202A:
  254.                 lodsb           ; Move character into AL.
  255.         cmp     al,0            ; Is it a zero ?
  256.         je      move202B        ; Yes .. jump.
  257.                 stosb           ; No .. Store it and loop
  258.         loop    move202A
  259.         jmp     move203
  260. move202B:
  261.         mov     al,' '
  262.         rep     stosb
  263. move203:
  264.         mov     byte ptr[di]-4,'.'      ; Store a period.
  265.         cmp     byte ptr [bp].dta+21,10H        ; is it a subdirectory ?
  266.         jne     move23          ; no - jump
  267.         std                     ; change direction to decrement SI and DI
  268.         dec     di              ; Back up to last character of extension
  269.         mov     cx,3            ; Store `...' as the extension name when
  270.         mov     al,'.'          ; a subdirectory entry.
  271.         rep     stosb
  272.         cld                     ; clear direction flag (increment)
  273. move23:
  274.         ret
  275. move2   endp
  276.  
  277. ;........................................................................
  278.  
  279. get_label proc near             ;Display the label for the
  280.                                 ;disk in the selected drive 
  281.         push    es              ; Save ES
  282.         push    ss              ; Get STACK into ES **************
  283.         pop     es
  284. ;----------------- first change the FCB to an extended FCB
  285.         mov     di,bp 
  286.         add     di,offset fcb   ; Move FCB address to DI
  287.         mov     dx,di           ; And also put into DX.
  288.         mov     al,byte ptr[di] ; Get drive id
  289.         mov     byte ptr [di+7],al    ; move it to offset 7
  290.         mov     byte ptr [di],0FFH    ; indicate extended FCB
  291.         inc     di
  292.         mov     cx,5            ; Store 5 zeros
  293.         xor     al,al
  294.         rep     stosb
  295.         mov     byte ptr [di],08H   ; Store volume attribute
  296.         inc     di
  297.         inc     di              ; bump past drive id
  298.         mov     cx,11
  299.         mov     al,'?'          ; Store 11 `?' in filename
  300.         rep     stosb
  301.         mov     cx,25           ; End with 25 zeros
  302.         xor     al,al
  303.         rep     stosb
  304.         pop     es              ; restore ES
  305. ;----------------- now search for volume
  306.         mov     ah,11H          ; using DOS function 11H
  307.         int     21h
  308.         cmp     al,0FFH         ;any volume label found?
  309.         je      get_label2      ;no,jump
  310. ;----------------- store volume name in variable
  311.         mov     di,[bp].volstrgad    ; Point DI at VOLUMES
  312.         mov     si,bp
  313.         add     si,offset dta +8; Point AX at File name in DTA
  314.         mov     cx,11           ; Length of name in bytes
  315.         rep     movsb           ; Move name into string
  316. get_label2:
  317.         ret
  318. get_label endp
  319.  
  320. ;........................................................................
  321.  
  322. dirget          endp
  323. prog            ends
  324.                 end
  325.