{<<<< FreeBytes >>>>}
{ From: COMPLETE TURBO PASCAL by Jeff Duntemann  }
{ Scott, Foresman & Co. 1986  ISBN 0-673-18600-8 }
{ Described in section 20.6 -- Last mod 2/1/86   }
{ Specific to MS/PC DOS }

FUNCTION FreeBytes(Unit : Char) : Real;

TYPE
  RegPack = RECORD
              AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags : Integer
            END;

VAR
  Registers : RegPack;
  UnitByte  : Byte;
  R,A,B,C   : Real;

BEGIN
  Unit := UpCase(Unit);
  IF Unit IN ['A'..'D'] THEN   { A=1; B=2; C=3; D=4 else 0 }
    UnitByte := Ord(Unit)-64
  ELSE UnitByte := 0;
  Registers.DX := UnitByte;
  Registers.AX := $36 * 256;  { Call # must go in high byte}
  MSDOS(Registers);
  { Call $36 returns # of bytes per sector in CX; }
  { # of sectors per cluster in AX, and # of free }
  { clusters in BX, so free space in bytes is     }
  { AX * BX * CX.  This must be done in reals to  }
  { avoid integer overflow. }
  A := Registers.AX; B := Registers.BX; C := Registers.CX;
  R := A * B * C;
  FreeBytes := R
END;
