home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / QBAS / WNDTOOL5.ZIP / DIR.ASM < prev    next >
Assembly Source File  |  1989-05-24  |  9KB  |  181 lines

  1. ;
  2. ;Title:DIR.ASM
  3.  
  4. BASIC_SETUP MACRO
  5.               PUSH    BP
  6.               MOV     BP,SP
  7.  
  8.  
  9.               PUSH    AX
  10.               PUSH    BX
  11.               PUSH    CX
  12.               PUSH    DX
  13.               PUSH    SI
  14.               PUSH    DI
  15.               PUSH    DS
  16.               PUSH    ES
  17.               ENDM
  18.  
  19. BASIC_CLEANUP MACRO
  20.               CLD
  21.               POP     ES
  22.               POP     DS
  23.               POP     DI
  24.               POP     SI
  25.               POP     DX
  26.               POP     CX
  27.               POP     BX
  28.               POP     AX
  29.  
  30.               POP     BP
  31.               ENDM
  32.  
  33. Stk            STRUC
  34. Bbp            DW       ?                                       ;basic's bp
  35. Retadd         DD       ?                                       ;return address
  36. Count          DW       ?                                       ;basic p3 = count of filenames
  37. File$0         DW       ?                                       ;basic p2 = output filenames
  38. Path$          DW       ?                                       ;basic p1 = pathname to search
  39. Stk            ENDS
  40.  
  41. Strdes         STRUC                                            ;basic string descriptor structure
  42. Len            DW       ?                                       ;word length of string
  43. Strptr         DW       ?                                       ;pointer to string space
  44. Strdes         ENDS
  45.  
  46. ;
  47. Code           SEGMENT  BYTE PUBLIC 'CODE'
  48.                ASSUME   CS:Code,DS:Code
  49.  
  50.                PUBLIC   Dir                                     ;let link know about this one
  51.  
  52. Dir            PROC     FAR                                     ;it's a far proc to basic
  53.  
  54.                Basic_setup                                      ;save basic's bp
  55.  
  56.                MOV      CS:[Filcnt],0                           ;initialize file count
  57.  
  58.                MOV      SI,Path$[BP]                            ;get pointer to string descriptor
  59.                MOV      CX,Len[SI]                              ;cx = path length
  60.                MOV      SI,Strptr[SI]                           ;si -> path string data
  61.                MOV      DI,OFFSET Path                          ;di -> place to fill
  62.                PUSH     CS                                      ;make es point at our seg
  63.                POP      ES                                      ;
  64.                REP      MOVS BYTE PTR [SI],BYTE PTR [DI]
  65.                MOV      BYTE PTR ES:[DI],0                      ;make sure it's an asciiz string
  66.  
  67.                MOV      DI,Count[BP]                            ;get pointer to fill flag in di
  68.                MOV      BX,[DI]                                 ;bx = fill flag
  69.                PUSH     DS                                      ;save basic's ds
  70.                PUSH     CS
  71.                POP      DS                                      ;address this segment
  72.                MOV      BYTE PTR [Fillflg],0FFH                 ;assume we're filling the strings
  73.                TEST     BX,08000H                               ;negative?
  74.                JZ       Fillem                                  ;no, we *are* filling
  75.  
  76.                MOV      BYTE PTR[Fillflg],0                     ;yes, indicate with flag
  77. fillem:
  78.                MOV      [Search_attr],BL                        ;save attribute locally
  79.                MOV      DI,File$0[BP]                           ;di -> first string descriptor
  80.                MOV      DI,SS:[DI]                              ;di = first string descriptor address
  81.                ADD      DI,2                                    ;di -> first string data area
  82.  
  83.                PUSH     ES
  84.                MOV      AH,2FH                                  ;get basic's dta
  85.                INT      21H
  86.                MOV      [Dta_ofs],BX
  87.                MOV      [Dta_seg],ES                            ;and save it
  88.                POP      ES                                      ;restore es = ds = cs
  89.                MOV      DX,OFFSET Dta                           ;set dta to our area here
  90.                MOV      AH,1AH
  91.                INT      21H
  92.  
  93.                MOV      AH,4EH                                  ;find first matching file
  94.                XOR      CX,CX                                   ;clear attribute
  95.                MOV      CL,[Search_attr]                        ;attribute from lobyte of count parm
  96.                MOV      DX,OFFSET Path                          ;ds:dx points to search path
  97.                INT      21H
  98.                JNC      Ok                                      ;if error, cy set
  99.  
  100.                CMP      AX,18                                   ;no files found?
  101.                JZ       Exit                                    ;yes, don't report error
  102.  
  103.                MOV      [Filcnt],0FFFFH                         ;set count to -1 to report path error
  104.                JMP      SHORT Exit                              ;and leave
  105.  
  106. ;
  107. ok:
  108.                PUSH     SS
  109.                POP      ES                                      ;es -> basic's ds
  110.                INC      [Filcnt]                                ;bump file counter for first find
  111.                TEST     BYTE PTR [Fillflg],0FFH                 ;check "fill array" flag
  112.                JZ       Findnext                                ;zero, don't put first name in array
  113.  
  114.                CALL     Move_filename                           ;do the move
  115.  
  116. findnext:
  117.                MOV      AH,4FH                                  ;find next function
  118.                INT      21H                                     ;do it
  119.                JC       Exit                                    ;if error, must be no more files
  120.  
  121.                INC      [Filcnt]                                ;no error, we found another file
  122.                TEST     BYTE PTR [Fillflg],0FFH                 ;are we moving string data?
  123.                JZ       Findnext                                ;loop if not
  124.  
  125.                CALL     Move_filename                           ;move it
  126.  
  127.                JMP      SHORT Findnext                          ;and keep hunting
  128.  
  129. exit:
  130.                LDS      DX,DWORD PTR [Dta_ofs]                  ;get basic's dta
  131.                MOV      AH,1AH                                  ;set dta fn.
  132.                INT      21H
  133.                MOV      DI,Count[BP]                            ;di -> count parameter
  134.                MOV      AX,CS:[Filcnt]                          ;get file count
  135.                POP      DS                                      ;reset to basic's data seg
  136.                MOV      [DI],AX                                 ;put file count in count%
  137.  
  138.                Basic_cleanup                                    ;restore basic's bp
  139.  
  140.                RET      6                                       ;return and pop parameter pointers
  141. Dir            ENDP
  142.  
  143. ;
  144. Move_filename  PROC     NEAR
  145. ;
  146. ;di points to string descriptor to fill with filename from DTA
  147. ;
  148.                PUSH     DI                                      ;save pointer to descriptor length part
  149.                MOV      DI,ES:[DI]                              ;and point instead to string data
  150.                MOV      SI,OFFSET Fname                         ;si -> filename (asciiz)
  151. moveloop:
  152.                LODS     BYTE PTR [SI]                           ;get filename character
  153.                OR       AL,AL                                   ;is it 0? (end of string?)
  154.                JZ       Done                                    ;yes, quit moving data
  155.  
  156.                STOS     BYTE PTR [DI]                           ;no, store
  157.                JMP      SHORT Moveloop                          ;and continue
  158. done:
  159.                POP      DI                                      ;di -> length in s.d. again
  160.                ADD      DI,4                                    ;move to next s.d. pointer
  161.                RET
  162. Move_filename  ENDP
  163.  
  164. ;
  165. Dta_ofs        DW       0                                       ;save old dta for basic just in case
  166. Dta_seg        DW       0
  167. Fillflg        DB       0                                       ;"fill array" flag
  168. Search_attr    DB       0                                       ;files' search attribute
  169. Filcnt         DW       0                                       ;count of files found
  170. Path           DB       64 Dup (0)                              ;search path, passed from basic
  171.  
  172. Dta            DB       21 Dup (0)                              ;reserved area (used for findnext)
  173. Attrib         DB       0                                       ;attribute of file found
  174. Time           DW       0                                       ;time of last write
  175. Date           DW       0                                       ;date
  176. Fsize          DD       0                                       ;filesize (32 bit integer)
  177. Fname          DB       13 Dup (0)                              ;asciiz filename, no blanks-name.ext,00
  178.  
  179. Code           ENDS
  180.                END
  181.