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 / TURBOPAS / SQZTURBO.LBR / DOS.INC < prev    next >
Text File  |  2000-06-30  |  6KB  |  165 lines

  1.  {
  2.  [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
  3.  []                                                                    []
  4.  [] The Squeeze/UnSqueeze MsDos routines.                              []
  5.  []                                                                    []
  6.  []   DOS files are "file of char", which keeps read/write procedures  []
  7.  []   simple. DOS Turbo 3.0 must close all file (handles), even if     []
  8.  []   read only. File sizes are determined with LongFileSize function. []
  9.  []                                                                    []
  10.  [][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
  11.  }
  12.  
  13. Const CommandLineLoc                  = $80;
  14.       DisplayCharacter                = $0200;
  15.       PrintCharacter                  = $0500;
  16.       ReturnLoggedDrive               = $1900;
  17.       SetDTA                          = $1A00;
  18.       FindFirstFile                   = $4E00;
  19.       FindNextFile                    = $4F00;
  20.  
  21. Type  AFile                           = File of Char;
  22.       FlagType       = (CarryFlag,     NoFlag2,
  23.                         ParityFlag,    NoFlag8,
  24.                         AuxCarryFlag,  NoFlag20,
  25.                         ZeroFlag,      SignFlag,
  26.                         StepTrapFlag,  InterruptFlag,
  27.                         DirectionFlag, OverflowFlag,
  28.                         NoFlag100,     NoFlag200,
  29.                         NoFlag400,     NoFlag800);
  30.       FlagSet        = Set of FlagType;
  31.       MsDosRegisters = Record Case Byte of
  32.                          0: (Ax,Bx,Cx,Dx,Bp,Si,Di,Ds,Es,Flags: Integer);
  33.                          1: (Al,Ah,Bl,Bh,Cl,Ch,Dl,Dh:          Byte);
  34.                          2: (RegArray: Array[1..9] of          Integer;
  35.                              FlagRegister:                     FlagSet);
  36.                        end;
  37.  
  38.       DTAType                         = Record
  39.                                           Reserved:  Array[1..21] of Byte;
  40.                                           Attribute: Byte;
  41.                                           FileTime,
  42.                                           FileDate:  Integer;
  43.                                           FileSize:  Array[0..1] of Integer;
  44.                                           FName:     Array[1..13] of Char;
  45.                                         end;
  46.  
  47. Var   CommandLine:                      String[127]
  48.                                                Absolute CSeg:CommandLineLoc;
  49.       InFile, OutFile:                  AFile;
  50.       DTA:                              DTAType;
  51.       DosRec:                           MsDosRegisters;
  52.  
  53. Procedure GetLoggedDrive;
  54.   begin
  55.     With DosRec do
  56.       begin
  57.         Ax:=ReturnLoggedDrive; MsDos(DosRec);
  58.         LoggedDrive:=chr(Lo(ax)+65);
  59.       end;
  60.   end; { Procedure GetLoggedDrive }
  61.  
  62. Procedure FindFiles(FileMask: FileName);
  63.   Var FindFile, FoundFile: FileName;
  64.   begin
  65.     With DosRec do
  66.       begin
  67.         Ax:=SetDTA; Ds:=Seg(DTA); Dx:=Ofs(DTA); MsDos(DosRec);
  68.         FindFile:=FileMask+#0;
  69.         FFirst:=Nil; FLast:=Nil;
  70.  
  71.         Ax:=FindFirstFile;
  72.         Repeat { Until CarryFlag in FlagRegister }
  73.           Ds:=Seg(FindFile[1]); Dx:=Ofs(FindFile[1]); Cx:=0; MsDos(DosRec);
  74.           If not (CarryFlag in FlagRegister) then
  75.             begin
  76.               FoundFile[0]:=#30;
  77.               Move(DTA.FName,FoundFile[1],13);
  78.               FoundFile[0]:=Chr(Pred(Pos(#0,FoundFile)));
  79.               New(FCurrent);
  80.               FCurrent^.FNme:=FoundFile; FCurrent^.NxtF:=Nil;
  81.               If FFirst=Nil then FFirst:=      FCurrent
  82.               else               FLast^.NxtF:= FCurrent;
  83.               FLast:=FCurrent;
  84.             end;
  85.           Ax:=FindNextFile;
  86.         Until CarryFlag in FlagRegister;
  87.  
  88.         FCurrent:=FFirst;
  89.       end;
  90.   end;   { Procedure FindFiles }
  91.  
  92. Function NextFile: FileName;
  93.   begin
  94.     If FCurrent=Nil then NextFile:=''
  95.     else
  96.       begin
  97.         NextFile:=FCurrent^.FNme; FCurrent:=FCurrent^.NxtF;
  98.       end;
  99.   end;   { Function NextFile }
  100.  
  101. Procedure WriteCharToCon(AChar: Char);
  102.   begin
  103.     With DosRec do
  104.       begin
  105.         Ax:=DisplayCharacter; Dl:=Ord(AChar); MsDos(DosRec);
  106.         Ax:=PrintCharacter;   Dl:=Ord(AChar); MsDos(DosRec);
  107.       end;
  108.   end;   { Procedure WriteCharToCon }
  109.  
  110. Procedure SetEchoToPrinter;
  111.   begin
  112.     ConOutPtr:=Ofs(WriteCharToCon);
  113.   end;   { Procedure SetEchoToPrinter }
  114.  
  115. Function TheSizeOf(Var TheFile: AFile): Real;      { DOS can use LongFileSize }
  116.   begin
  117.     TheSizeOf:=LongFileSize(TheFile);
  118.   end; { Function TheSizeOf }
  119.  
  120. Procedure ResetInFile;                               { DOS reads file of char }
  121.   begin
  122.     Reset(InFile);
  123.   end; { Procedure ResetInFile }
  124.  
  125. Procedure ReadInFile(Var C: Char);             { DOS just reads the next char }
  126.   begin
  127.     Read(InFile,C);
  128.   end; { Procedure ReadInFile }
  129.  
  130. Function GetC: Char;                                 { DOS get next character }
  131.   var C: Char;
  132.   begin
  133.     If EOF(InFile) then EOFile:=true
  134.     else begin ReadInFile(c); crc:=crc+ord(C); end;
  135.     GetC:=C;
  136.   end; { Function GetC }
  137.  
  138. Procedure CloseInFile;              { DOS Turbo 3.0 needs to close the handle }
  139.   begin
  140.     Close(InFile);
  141.   end;   { Procedure CloseInFile }
  142.  
  143. Procedure ReWriteOutFile;                    { DOS just writes a file of char }
  144.   begin
  145.     ReWrite(OutFile);
  146.   end; { Procedure ReWriteOutFile }
  147.  
  148. Procedure WriteOutFile(Var C: Char);                 { DOS just writes a char }
  149.   begin
  150.     Write(OutFile,C);
  151.   end; { Procedure WriteOutFile }
  152.  
  153. Procedure CloseOutFile;                                     { DOS just closes }
  154.   begin
  155.     Close(OutFile);
  156.   end; { Procedure CloseOutFile }
  157.  
  158. Function GetSizeOfOutFile: Real;    { DOS Turbo 3.0 needs to close the handle }
  159.   begin
  160.     Reset(OutFile);
  161.     GetSizeOfOutFile:=TheSizeOf(OutFile);
  162.     CloseOutFile;
  163.   end;   { Function GetSizeOfOutFile }
  164.  
  165.