home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / tsr.swg / 0012_Listing TSR's.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-05-25  |  3.1 KB  |  111 lines

  1. {
  2. Well, here it is, a program that lists TSRs loaded.
  3. Anybody willing to enhance it so that it checks the HMA for TSRs too?
  4.  
  5. Oh, were do I send this so that it gets into the next SWAGS release?  I was
  6. unable to find such a program in the all the SWAGS until (and inclusive) the
  7. latest February '94 release...
  8.  
  9. { ------------ Cut Here ----------- }
  10.  
  11. Program ListTSRs;
  12.  
  13. {
  14.    Written by Alex Karipidis on the 8th of March 1994.
  15.    Donated to the public domain.  Use this code freely.
  16.  
  17.    You can contact me at:
  18.      Fidonet  : 2:410/204.4
  19.      Hellasnet: 7:2000/50.4
  20.      SBCnet   : 14:2100/201.4
  21.      Zyxelnet : 16:800/108.4
  22.      Pascalnet: 115:3005/1.4
  23.  
  24.    If you enhance/improve this code in any way, I would appreciate it if you
  25.    sent me a copy of your version.
  26.  
  27.    I will not be responsible for any damage caused by this code.
  28.  
  29.    This program will print a list of all programs currently loaded in
  30.    memory.
  31. }
  32.  
  33. Type
  34.  
  35.   pMCB_Rec = ^MCB_Rec;
  36.   MCB_Rec = Record
  37.     ChainID    : Byte; { 77 if part of MCB chain, 90 if last MCB allocated }
  38.     Owner      : Word; { PSP segment address of the MCB's owner }
  39.     Paragraphs : Word; { Paragraphs related to this MCB }
  40.   end;
  41.  
  42. Var
  43.   MCB                  : pMCB_Rec;
  44.   InVarsSeg, InVarsOfs : Word;
  45.   EnvSeg, Counter      : Word;
  46.  
  47. begin
  48.   { Dos service 52h returns the address of the DOS "invars" table in ES:BX }
  49.            { !!! This is an undocumented DOS function !!! }
  50.   asm
  51.     MOV   AH,52h
  52.     INT   21h
  53.     MOV   InVarsSeg,ES
  54.     MOV   InVarsOfs,BX
  55.   end;
  56.  
  57.   {
  58.     The word before the "invars" table is the segment of the first MCB
  59.     allocated by DOS.
  60.   }
  61.   MCB := Ptr (MemW [InVarsSeg:InVarsOfs-2], 0);
  62.  
  63.   While MCB^.ChainID <> 90 do  { While valid MCBs exist... }
  64.   begin
  65.  
  66.     If MCB^.Owner = Seg (MCB^) + 1 then { If MCB owns itself, then... }
  67.     begin
  68.       Write ('In memory: ');  { We've found a program in memory }
  69.  
  70.       {
  71.         The word at offset 2Ch of the program's PSP contains the value of
  72.         the program's environment data area.  That's were the program's name
  73.         is located.
  74.       }
  75.       EnvSeg := MemW [MCB^.Owner:$2C];
  76.  
  77.       {
  78.         The environment also contains the environment variables as ASCIIZ
  79.         (null-terminated) strings.  Two consecutive null (0) bytes mean that
  80.         the environment variables have ended and the program name follows
  81.         after 4 bytes.  That is also an ASCIIZ string.
  82.       }
  83.       Counter := 0;
  84.       While (Mem [EnvSeg:Counter  ] <> 0) or  { Find 2 consecutive }
  85.             (Mem [EnvSeg:Counter+1] <> 0) do  { null bytes.        }
  86.         inc (counter);
  87.  
  88.       inc (counter,4); { Program name follows after 4 bytes }
  89.  
  90.       While Mem [EnvSeg:Counter] <> 0 do { Print program name }
  91.       begin
  92.         Write (Char (Mem [EnvSeg : Counter]));
  93.         Inc (counter);
  94.       end;
  95.  
  96.       WriteLn;
  97.  
  98.     end;
  99.  
  100.     { Point to next MCB }
  101.     MCB := Ptr (Seg (MCB^) + MCB^.Paragraphs + 1, 0);
  102.   end;
  103.  
  104.   {
  105.     Note: The last MCB is not processed!
  106.           It is assumed that it is this program's MCB.
  107.           In your programs, this may or may not be the case.
  108.   }
  109.  
  110. end.
  111.