home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / ZCPR33 / A-R / FOR-SUPP.LBR / CPMSTATS.IZC / CPMSTATS.INÃ
Text File  |  2000-06-30  |  4KB  |  88 lines

  1. {
  2.   Turbo Pascal Include file to display space remaining on disk.
  3.   Nov. 19, 1986 by Carson Wilson. For all CP/M 2.2 systems.
  4.   ByteMask works on the principle that, e.g., if ByteMask = 00100000 (binary),
  5.   ByteMask AND AllocByte = 1 only if the third bit in AllocByte = 1.
  6.  
  7. CALLING CONVENTIONS:
  8.  
  9. writeln(CPMStats('d',space));
  10.                        ...If 'd' is a legal drive letter (see "LegalDrives"
  11.                           below), get space on that drive. If 'd' is an
  12.                           ILLEGAL drive letter, get space remaining on
  13.                           current drive. Output is a number representing
  14.                           the number of kilobytes left.
  15.  
  16. BLSize := CPMStats('d',size);
  17.                        ...Gets block size of drive, or current drive, where
  18.                           "BLSize" is an integer variable.
  19. }
  20. type
  21.   calltype = (space,size);   { return space on disk, or block size? }
  22.  
  23. function CPMStats(DriveLtr : char; command : calltype) : integer;
  24.   const
  25.     GetParams = 31;   { BDOS Get Disk Parameters Address }
  26.     GetAlloc  = 27;   {   "  Get Allocation Address      }
  27.     MaxByte   = $80;  { 10000000 binary }
  28.     LegalDrives : set of char = ['A'..'P'];
  29.   type
  30.     table = record         { holds disk parameters block for selected disk }
  31.       SPT : integer;
  32.       BSH, BLM, EXM : byte;
  33.       DSM, DRM : integer;
  34.       AL0, AL1 : byte;
  35.       CKS, OFF : integer;
  36.       end;
  37.   var
  38.     TableArray : table;
  39.     BlockSize,          { size, in Kb, of each data block on disk }
  40.     ByteMask,
  41.     AllocBit,           { 1 bit     within allocation  block }
  42.     AllocByte : byte;   { 1 byte       "       "         "   }
  43.     TableSize,          { length, in bits, of the allocation table }
  44.     offset,
  45.     AllocAddr,          { address of start of allocation block }
  46.     TableAddr,          {    "     "   "   "  disk parameters }
  47.     K : integer;        { calculated disk space in Kb }
  48.  
  49.   begin
  50.   DriveLtr := upcase(DriveLtr);
  51.   if DriveLtr in LegalDrives then
  52.     bdos(14,ord(DriveLtr) - $41);    { select drive - else use default drive }
  53.   K := 0;
  54.   TableAddr := bdoshl(GetParams);
  55.   AllocAddr := bdoshl(GetAlloc);
  56.   for offset := 0 to 14 do
  57.     mem[addr(TableArray) + offset] :=
  58.     mem[TableAddr + offset];      { move disk parameters into record variable }
  59.                                   {      "TableArray"                         }
  60.   with TableArray do begin
  61.     if DSM > 255 then BlockSize := EXM * 2 + 2
  62.     else BlockSize := EXM + 1;     { see p. 147 of Dig. Res. CP/M 2.2 Manual }
  63.     TableSize := DSM + 1;
  64.     end;
  65.  
  66.   for offset := 0 to (TableSize div 8 - 1) do begin  { do full bytes in }
  67.     AllocByte := mem[AllocAddr + offset];            { allocation block }
  68.     ByteMask := MaxByte;                    { 10000000B }
  69.     for AllocBit := 1 to 8 do begin
  70.       if AllocByte AND ByteMask = 0 then
  71.         K := K + BlockSize;                 { doesn't match mask }
  72.       ByteMask :=  ByteMask SHR 1;
  73.       end;
  74.     end;
  75.  
  76.   offset := offset + 1;
  77.   AllocByte := mem[AllocAddr + offset];
  78.   ByteMask := MaxByte;
  79.   for AllocBit := 1 to (TableSize mod 8) do begin   { do remaining allocation }
  80.     if AllocByte AND ByteMask = 0 then K := K + BlockSize;     { bits, if any }
  81.     ByteMask :=  ByteMask SHR 1;
  82.     end;
  83.   case command of
  84.     space : CPMStats := K;
  85.     size  : CPMStats := BlockSize;
  86.     end;
  87.   end;           { function CPMStats }
  88.