home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / UTILITY / DIR / LS_N_DF.ZIP / DF.A86 next >
Encoding:
Text File  |  1990-09-15  |  2.2 KB  |  122 lines

  1. ;    DF    Print disk free space.
  2.  
  3. ;    Usage:  df [drive: ...]
  4.  
  5. ;    By default it reports free space for the current disk drive.  If you
  6. ;    specify a drive explicitly, the colon is optional, so you can do
  7. ;    `df acd' to get free space for drives a:, c:, and d:.
  8.  
  9. ;    Assemble with A86.  Version 1.00 (9/15/90)
  10.  
  11. CR    equ    0dh
  12. LF    equ    0ah
  13.  
  14.     cld
  15.     mov    si,81h
  16.  
  17. ;    Loop over drives.
  18.  
  19. df1:    lodsb
  20.     cmp    al,CR
  21.     je    df3        ;if end of argument(s)
  22.     or    al,20h
  23.     sub    al,'a'
  24.     jae    df4        ;if a letter found
  25.     jmp    df1
  26.  
  27. df2:    ret
  28.  
  29. df3:    cmp    byte msg1a,'$'
  30.     jne    df2        ;if we did something already
  31.     dec    si        ;go back here when done
  32.     mov    ah,19h        ;get current disk
  33.     int    21h
  34.  
  35. ;    Print stats for drive given in AL.
  36.  
  37. df4:    push    si
  38.     mov    dl,al
  39.     inc    dx
  40.     add    al,'a'
  41.     mov    msg1a,al
  42.     mov    msg2a,al
  43.     mov    ah,36h        ;get disk free space
  44.     int    21h
  45.     cmp    ax,-1
  46.     jne    df5        ;if not invalid drive
  47.     mov    dx,offset msg2    ;error message
  48.     jmp    short df6    ;print it and go on
  49.  
  50. df5:    push    dx,bx        ;save total, avail number of clusters
  51.     mul    cx        ;number of bytes per cluster
  52.     mul    bx        ;number of bytes available, period
  53.     mov    di,offset msg1b
  54.     mov    cx,9
  55.     call    dprintdxax
  56.     pop    bx        ;number of clusters available
  57.     push    bx
  58.     xor    ax,ax
  59.     mov    di,offset msg1c
  60.     mov    cx,5
  61.     call    dprint
  62.     mov    ax,100        ;print percentage free
  63.     pop    bx        ;number of clusters free
  64.     mul    bx
  65.     pop    bx        ;number of clusters total
  66.     mov    cx,bx        ;round off
  67.     shr    cx,1
  68.     add    ax,cx
  69.     div    bx
  70.     xor    dx,dx
  71.     mov    di,offset msg1d
  72.     mov    cx,3
  73.     call    dprintdxax
  74.     mov    dx,offset msg1
  75.  
  76. df6:    mov    ah,9        ;print string
  77.     int    21h
  78.     pop    si
  79.     jmp    df1        ;loop back to the next one
  80.  
  81. ;    DPRINTDXAX - Print (CX)-digit number in DX:AX.
  82. ;    DPRINT    Print (CX)-digit number in AX:BX.
  83.  
  84. dprintdxax:
  85.     xchg    ax,bx        ;move dx:ax into ax:bx
  86.     xchg    ax,dx
  87.  
  88. dprint:    mov    bp,sp
  89.     mov    si,10
  90. dp1:    xor    dx,dx
  91.     div    si
  92.     xchg    ax,bx
  93.     div    si
  94.     add    dl,'0'
  95.     push    dx
  96.     dec    cx
  97.     xchg    ax,bx
  98.     or    bx,bx
  99.     jnz    dp1
  100.     or    ax,ax
  101.     jnz    dp1
  102.     or    cx,cx
  103.     js    dp2
  104.     mov    al,' '
  105.     rep    stosb
  106. dp2:    pop    ax
  107.     stosb
  108.     cmp    sp,bp
  109.     jne    dp2
  110.     ret
  111.  
  112. msg1    db    'Drive '
  113. msg1a    db    '$: has'
  114. msg1b    db    'XXXXXXXXX bytes = '
  115. msg1c    db    'XXXXX clusters ('
  116. msg1d    db    'XXX%) free.',CR,LF,'$'
  117.  
  118. msg2    db    'Drive '
  119. msg2a    db    '$: is invalid.',CR,LF,'$'
  120.  
  121.     end
  122.