home *** CD-ROM | disk | FTP | other *** search
- {
- **************************************************************************
- SNOOP.PAS -- Pascal interface to SNOOP.COM disk logging program
- Copyright 1989 L. Brett Glass -- All rights reserved.
- **************************************************************************
- }
- unit Snoop;
- {$A-} {No word alignment}
-
- interface
-
- uses DOS;
-
- const
- MAXTRANSACTIONS = 1024 * 8;
-
- type
- Transaction = record
- driveNum : Byte;
- headNum : Byte;
- secNum : Byte;
- cylNum : Byte;
- sectors : Byte;
- requestType : Byte;
- end;
-
- TransactionBuffer = array [0..MAXTRANSACTIONS - 1] of Transaction;
-
- SnoopObject = object
- numTransactions : Word;
- currTransaction : Word;
- buffer : TransactionBuffer;
-
- constructor Init;
- procedure Dump(var f : Text);
- function GetFirstTransaction(var t : Transaction) : Boolean;
- function GetNextTransaction(var t : Transaction) : Boolean;
- end;
-
- var
- Snooper : SnoopObject;
-
-
- implementation
-
- constructor SnoopObject.Init;
- {This subroutine attempts to locate the SNOOP TSR and its buffer
- in memory. If it finds the buffer, it makes a quick copy into the
- SnoopObject.}
-
- const
- FIRSTHARDDISK = $80;
- GETBUFADDR = $99AA;
- SENTINEL = $4321;
- CARRYBIT = 1;
-
- type
- SnoopBuffer = record
- wrapFlag : Boolean;
- nextLoc : Word;
- buffer : TransactionBuffer;
- end;
-
- SnoopBufferPtr = ^SnoopBuffer;
-
- var
- bufPtr : SnoopBufferPtr;
- regs : Registers;
- firstPart,secondPart : Word;
-
- begin
- with regs do
- begin
- dl := FIRSTHARDDISK;
- ax := GETBUFADDR;
- Intr($13,regs);
- if ((flags and CARRYBIT) <> 0) and
- (ah = 1) and
- (dx = SENTINEL) then
- begin
- currTransaction := 0;
- bufPtr := Ptr(es,bx);
- firstPart := (bufPtr^.nextLoc - Ofs(bufPtr^.buffer))
- div SizeOf(Transaction);
- secondPart := MAXTRANSACTIONS - firstPart;
- if bufPtr^.wrapFlag then
- begin
- numTransactions := MAXTRANSACTIONS;
- Move(bufPtr^.buffer[firstPart],self.buffer,
- secondPart * SizeOf(Transaction));
- if firstPart > 0 then
- Move(bufPtr^.buffer,self.buffer[secondPart],
- firstPart * SizeOf(Transaction))
- end
- else
- begin
- numTransactions := firstPart;
- Move(bufPtr^.buffer,self.buffer,firstPart * SizeOf(Transaction))
- end;
- Exit
- end;
- Fail
- end
- end; {Snoop.Init}
-
- function SnoopObject.GetFirstTransaction(var t : Transaction) : Boolean;
- begin
- currTransaction := 0;
- GetFirstTransaction := GetNextTransaction(t);
- end; {SnoopObject.GetFirstTransaction}
-
- function SnoopObject.GetNextTransaction(var t : Transaction) : Boolean;
- begin
- if numTransactions <= currTransaction then
- begin
- GetNextTransaction := FALSE;
- Exit
- end;
- GetNextTransaction := TRUE;
- t := buffer[currTransaction];
- Inc(currTransaction)
- end; {SnoopObject.GetNextTransaction}
-
- procedure SnoopObject.Dump(var f : Text);
- const
- requests : array [2..3] of String[6] = ('READ ','WRITE ');
- var
- t : Transaction;
- begin
- Writeln(f, 'There are ', numTransactions, ' transactions in the buffer.');
- if GetFirstTransaction(t) then
- repeat
- with t do
- Writeln(f,requests[requestType],
- 'Drive = ', Char(Ord('C') + driveNum and $7F), ' ',
- 'Head = ', headNum:2, ' ', 'Cylinder = ',cylNum:4, ' ',
- 'Sector = ', secNum:2, ' ', '# Sectors = ', sectors)
- until not GetNextTransaction(t)
- end; {SnoopObject.Dump}
-
- begin
- if not Snooper.Init then
- begin
- Writeln('The program SNOOP.COM must be run before this program can be used.');
- Writeln('Program aborting.');
- Halt
- end;
- end.