home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / DSKCACHE / EVALCACH.ZIP / SNOOP.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-10-26  |  3.6 KB  |  149 lines

  1. {
  2. **************************************************************************
  3. SNOOP.PAS -- Pascal interface to SNOOP.COM disk logging program
  4. Copyright 1989 L. Brett Glass -- All rights reserved.
  5. **************************************************************************
  6. }
  7. unit Snoop;
  8. {$A-} {No word alignment}
  9.  
  10. interface
  11.  
  12. uses DOS;
  13.  
  14. const
  15.   MAXTRANSACTIONS = 1024 * 8;
  16.  
  17. type
  18.   Transaction = record
  19.     driveNum : Byte;
  20.     headNum : Byte;
  21.     secNum : Byte;
  22.     cylNum : Byte;
  23.     sectors : Byte;
  24.     requestType : Byte;
  25.     end;
  26.  
  27.   TransactionBuffer = array [0..MAXTRANSACTIONS - 1] of Transaction;
  28.  
  29.   SnoopObject = object
  30.     numTransactions : Word;
  31.     currTransaction : Word;
  32.     buffer : TransactionBuffer;
  33.  
  34.     constructor Init;
  35.     procedure Dump(var f : Text);
  36.     function GetFirstTransaction(var t : Transaction) : Boolean;
  37.     function GetNextTransaction(var t : Transaction) : Boolean;
  38.     end;
  39.  
  40. var
  41.   Snooper : SnoopObject;
  42.  
  43.  
  44. implementation
  45.  
  46. constructor SnoopObject.Init;
  47. {This subroutine attempts to locate the SNOOP TSR and its buffer
  48.  in memory. If it finds the buffer, it makes a quick copy into the
  49.  SnoopObject.}
  50.  
  51. const
  52.   FIRSTHARDDISK = $80;
  53.   GETBUFADDR = $99AA;
  54.   SENTINEL = $4321;
  55.   CARRYBIT = 1;
  56.  
  57. type
  58.   SnoopBuffer = record
  59.     wrapFlag : Boolean;
  60.     nextLoc : Word;
  61.     buffer : TransactionBuffer;
  62.     end;
  63.  
  64.   SnoopBufferPtr = ^SnoopBuffer;
  65.  
  66. var
  67.   bufPtr : SnoopBufferPtr;
  68.   regs : Registers;
  69.   firstPart,secondPart : Word;
  70.  
  71. begin
  72. with regs do
  73.   begin
  74.   dl := FIRSTHARDDISK;
  75.   ax := GETBUFADDR;
  76.   Intr($13,regs);
  77.   if ((flags and CARRYBIT) <> 0) and
  78.      (ah = 1) and
  79.      (dx = SENTINEL) then
  80.     begin
  81.     currTransaction := 0;
  82.     bufPtr := Ptr(es,bx);
  83.     firstPart := (bufPtr^.nextLoc - Ofs(bufPtr^.buffer))
  84.                    div SizeOf(Transaction);
  85.     secondPart := MAXTRANSACTIONS - firstPart;
  86.     if bufPtr^.wrapFlag then
  87.       begin
  88.       numTransactions := MAXTRANSACTIONS;
  89.       Move(bufPtr^.buffer[firstPart],self.buffer,
  90.            secondPart * SizeOf(Transaction));
  91.       if firstPart > 0 then
  92.         Move(bufPtr^.buffer,self.buffer[secondPart],
  93.              firstPart * SizeOf(Transaction))
  94.       end
  95.     else
  96.       begin
  97.       numTransactions := firstPart;
  98.       Move(bufPtr^.buffer,self.buffer,firstPart * SizeOf(Transaction))
  99.       end;
  100.     Exit
  101.     end;
  102.   Fail
  103.   end
  104. end; {Snoop.Init}
  105.  
  106. function SnoopObject.GetFirstTransaction(var t : Transaction) : Boolean;
  107. begin
  108. currTransaction := 0;
  109. GetFirstTransaction := GetNextTransaction(t);
  110. end; {SnoopObject.GetFirstTransaction}
  111.  
  112. function SnoopObject.GetNextTransaction(var t : Transaction) : Boolean;
  113. begin
  114. if numTransactions <= currTransaction then
  115.   begin
  116.   GetNextTransaction := FALSE;
  117.   Exit
  118.   end;
  119. GetNextTransaction := TRUE;
  120. t := buffer[currTransaction];
  121. Inc(currTransaction)
  122. end; {SnoopObject.GetNextTransaction}
  123.  
  124. procedure SnoopObject.Dump(var f : Text);
  125. const
  126.   requests : array [2..3] of String[6] = ('READ  ','WRITE ');
  127. var
  128.   t : Transaction;
  129. begin
  130. Writeln(f, 'There are ', numTransactions, ' transactions in the buffer.');
  131. if GetFirstTransaction(t) then
  132.   repeat
  133.     with t do
  134.       Writeln(f,requests[requestType],
  135.               'Drive = ', Char(Ord('C') + driveNum and $7F), ' ',
  136.               'Head = ', headNum:2, ' ', 'Cylinder = ',cylNum:4, ' ',
  137.               'Sector = ', secNum:2, ' ', '# Sectors = ', sectors)
  138.     until not GetNextTransaction(t)
  139. end; {SnoopObject.Dump}
  140.  
  141. begin
  142. if not Snooper.Init then
  143.   begin
  144.   Writeln('The program SNOOP.COM must be run before this program can be used.');
  145.   Writeln('Program aborting.');
  146.   Halt
  147.   end;
  148. end.
  149.