home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / windows / baswind8.zip / DIR.ASM < prev    next >
Assembly Source File  |  1990-09-14  |  8KB  |  209 lines

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