home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / diskspac.zip / DISKSPAC.ASM next >
Assembly Source File  |  1986-05-09  |  4KB  |  116 lines

  1. comment /
  2. DISKSPAC.ASM--get disk space on any drive--as a bonus, you can check
  3.               for validity-readiness of drive.  Disk space is returned
  4.               in Bytes if less then 65536 (with leading "B"), otherwise
  5.               in Kbytes (no leading letter)
  6. syntax:
  7. load diskspac
  8. memvar=spac(6) && for default, or
  9. memvar="A     " && check drive A
  10. call diskspac with memvar
  11.  
  12. returns:
  13. "E     "        && you did not specify a CAPITAL letter    (ERROR)
  14. "I     "        && invalid drive or drive not ready        (INVALID)
  15. "B  999"        && disk drive has exactly 999 bytes free
  16. "   999"        && disk drive has 999*1024 bytes available
  17.                && (at least, amount smaller than 1K disregarded)
  18.  
  19.  
  20.                   ******** WARNING **********
  21. WILL TERMINATE WITH "DIVIDE OVERFLOW" (AND GO BACK TO DOS) IF AVAIL. DISK
  22. SPACE IS GREATER THAN 65M.
  23. I have not tested this extensively.  No guarantees or responsibility  taken.
  24. Feedback appreciated.
  25. R. Russell Freeland (Synergy Corp.) 305-792-1866 (voice)
  26. Compuserve 76146,371
  27.  
  28. /
  29. CODESEG SEGMENT BYTE PUBLIC 'CODE'
  30.       assume cs:codeseg,es:codeseg
  31.  
  32. DISKSPAC PROC FAR
  33.  
  34.  
  35. START:
  36.         push    ax
  37.         push    ds
  38.         push    es
  39.         push    dx
  40.         push    cx
  41.         push    bx
  42. ;first let's convert the drive letter to a number
  43.         cmp     byte ptr [bx],20h
  44.         je      default                 ;must be default drive, huh?
  45.         sub     byte ptr [bx],40h       ;change CAPITAL letter to number
  46.         cmp     byte ptr [bx],00h       ;check to see if it's a letter (lower)
  47.         jna     error
  48.         cmp     byte ptr [bx],1bh       ;(upper)
  49.         jnb     error
  50.         mov     dl,byte ptr [bx]        ;tell DOS what drive
  51.         jmp     notdefault
  52. default:
  53.         mov     dl,0
  54. notdefault:
  55.         mov     ah,36h                  ;diskspace function call
  56.         int     21h                     ;call DOS
  57.         cmp     ax,65535                ;invalid drive?
  58.         je      invalid
  59.         ;--------------ax=sects/cluster
  60.         ;--------------cx=bytes/sector
  61.         ;--------------bx=available clusters
  62.         ;--------------(dx=clusters/drive--next version??)
  63.         mul     cx                      ;unsigned mult. bx*ax, result in dx/ax
  64.                                         ;will give bytes/cluster, all in AX (now)
  65.         mul     bx                      ;times available clusters
  66. ;test: jmp test
  67.         pop     bx                      ;get back the pointer to memvar
  68.         mov     byte ptr [bx],' '       ;clear out the converted drive number
  69. checksize:
  70.         cmp     dx,0
  71.         jg      Kbytes                  ;calculate in Kbytes, it's big enough
  72.         mov     byte ptr [bx],'B'
  73.         jmp     Bytes
  74.  
  75. Kbytes:
  76.         mov     si,1024d                ;let's get it in "K" this version, too
  77.                                         ;much work to divide large numbers
  78.         div     si
  79.         ;xor    dx,dx                   ;clear the remainder
  80.  
  81. Bytes:
  82.         ;-----------now convert number to a six-digit ASCII string
  83.         add     bx,6                    ;we'll do it backwards
  84.         mov     cx,6
  85.         mov     si,10                   ;prepare to divide by 10
  86. nexdgt: div     si                      ;divide dx:ax by si
  87.         or      dx,30H                  ;convert remainder to ASCII digit
  88.         dec     bx                      ;backup in string
  89.         mov     [bx],dl                 ;store character
  90.         xor     dx,dx                   ;clear remainder
  91.         dec     cx
  92.         or      ax,ax                   ;all done?
  93.         jnz     nexdgt                  ;do next digit
  94.         sub     bx,cx                   ;backup to right spot
  95.         jmp     wrapit                  ;wrap it up
  96. invalid:
  97.         pop     bx                      ;get back pointer
  98.         mov     byte ptr [bx],'I'       ;(INVALID)
  99.         jmp     wrapit
  100. error:
  101.         pop     bx                      ;get back pointer
  102.         mov     byte ptr [bx],'E'       ;(ERROR)
  103. wrapit:
  104.         pop     cx
  105.         pop     dx
  106.         pop     es                      ;pop the regs back
  107.         pop     ds
  108.         pop     ax
  109.         ret
  110. DISKSPAC ENDP
  111. CODESEG ENDS
  112.         END  START
  113.  
  114.  
  115.  
  116.