home *** CD-ROM | disk | FTP | other *** search
/ Phoenix CD 2.0 / Phoenix_CD.cdr / 02a / pctj1186.zip / FSPACE.ASM < prev    next >
Assembly Source File  |  1986-09-25  |  3KB  |  71 lines

  1.  
  2.  
  3. ;                TITLE DISK FREE SPACE SUBROUTINE
  4. ;                COMMENT *      5-26-85
  5. ;                Basic subroutine to determine free space left on disk.
  6. ;                CALLING SYNTAX:
  7.  
  8. ;                      CALL XX(DRIVE%,SPACE)
  9.  
  10. ;                where: XX=the address of the subroutine
  11. ;                DRIVE% = An integer variable designating the disk drive.
  12. ;                         0=default, 1=a:, 2=b:, etc.
  13. ;                SPACE  = A single-precision variable to get the result.
  14.  
  15. ;                Written by Burks A. Smith
  16. ;                           Datasmith, In.
  17. ;                           Box 8036
  18. ;                           Shawnee Mission KS   66208
  19. ;                *
  20. ;
  21. cseg            segment                    ;run in Basic's data seg
  22.                 assume  cs:cseg, ds:cseg
  23.                 org     100h               ;for testing.
  24. space           proc    far
  25.                 push    bp                 ;save base
  26.                 mov     bp,sp              ;point at stack
  27.                 mov     ah,30h             ;test version
  28.                 int     21h
  29.                 cmp     al,0               ;is it 1.x?
  30.                 jnz     okver              ;jump if not
  31.                 mov     ax,8000h           ;force floating point -1
  32.                 xor     dx,dx              ;least significant bits
  33.                 mov     cl,ah              ;exponent is 80h  (128)
  34.                 jmp     short done         ;version 1 exit
  35. ;       version 2.0 or later, test free space
  36. okver:          mov     si,[bp]+8          ;get drive # address
  37.                 mov     dx,[si]            ;set drive id
  38.                 mov     ah,36h             ;free space command
  39.                 int     21h
  40.                 mul     cx                 ;bytes/sec*sec/cluster
  41.                 mul     bx                 ;avail clusters*bytes/cluster
  42.                 xor     cx,cx              ;init shift count = 0
  43.                 push    ax                 ;save while comparing
  44.                 or      ax,dx              ;space left zero?
  45.                 pop     ax                 ;restore original value
  46.                 jz      done               ;jump if so
  47. ;       normalize floating point
  48.                 xchg    ax,dx              ;format change DX:AX->AX:DX
  49. shift:          inc     ch                 ;count the shift
  50.                 shl     dx,1               ;shift lsw left
  51.                 rcl     ax,1               ;shift msw & pick up carry
  52.                 jnc     shift              ;loop if it was a zero
  53. ;      32 bits normalized.  fix exponent & mantissa.
  54.                 mov     cl,128+32+1        ;bias+max shift+assumed bit
  55.                 sub     cl,ch              ;less actual shifts=exponen
  56.                 shr     ax,1               ;shift mantissa for + sign
  57.                 rcr     dx,1               ;pick up bit & shift lsw
  58. ;       store result
  59. done:           mov     di,[bp]+6          ;get addr of result
  60.                 mov     [di],dh            ;least significant byte
  61.                 inc     di
  62.                 stosw                      ;most significant word
  63.                 mov     [di],cl            ;and finally exponent
  64.                 pop     bp                 ;restore bp
  65.                 ret     4                  ;normal return
  66. space           endp
  67. cseg            ends
  68. ;
  69.                 end     space
  70.  
  71.