home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / hc / turbopgl.sit / Peek.p < prev    next >
Encoding:
Text File  |  1988-03-05  |  1.9 KB  |  79 lines  |  [TEXT/TPAS]

  1. {$R-}
  2.  
  3. (*
  4.    peek -- a sample HyperCard external function (return the contents
  5.    of a memory location).
  6.    ⌐Apple Computer, Inc. 1987
  7.    All Rights Reserved.
  8.  
  9.  
  10.    Modified for Turbo Pascal by Brian Liebowitz
  11.  
  12.     You must install the DHDR resources called PasXFCN and PasXCMD 
  13.     into your copy of Turbo before compiling this XCMD.  You must also 
  14.      have compiled the unit HyperXCMD and moved it into the Turbo progam,
  15.       and the file XCMDGlue.inc must be accessible.  After compiling,use
  16.      ResEdit to change the ID from 300, and to copy the XCMD or XFCN into 
  17.     your stack or Hypercard.
  18. *)
  19.  
  20. {$U-}    { Don't include runtime units}
  21. {$D PasXFCN}    {Compile as XFCN}
  22.  
  23. Program Peek;
  24.  
  25.  
  26. USES MemTypes,QuickDraw,OsIntf,ToolIntf,HyperXCmd;
  27.   
  28. TYPE 
  29.     Str19 = String[19];
  30.      WordPtr = ^INTEGER;
  31.      LongPtr = ^LongInt;
  32.  
  33.   PROCEDURE PasXFCN(paramPtr: XCmdPtr);
  34.   VAR peekAddr,peekSize,peekVal: LongInt;
  35.         Wordtemp:WordPtr;LongTemp:LongPtr;   
  36.      str: Str255;
  37.  
  38.   {$I XCmdGlue.inc }
  39.  
  40.   BEGIN
  41.    WITH paramPtr^ DO
  42.      BEGIN
  43.       { first param is addr }
  44.       ZeroToPas(params[1]^,str);
  45.       peekAddr := StrToNum(str);
  46.       
  47.       { second param, if given, is size }
  48.       peekSize := 1;
  49.       IF paramCount = 2 THEN
  50.         BEGIN
  51.           ZeroToPas(params[2]^,str);
  52.           peekSize := StrToNum(str);
  53.         END;
  54.       
  55.       CASE peekSize OF
  56.         1: peekVal := BitAND($000000FF,Ptr(peekAddr)^);
  57.         2: begin
  58.             Wordtemp:=WordPtr(BitAND($FFFFFFFE,peekAddr));
  59.             peekVal := BitAND($0000FFFF,(Wordtemp^));
  60.            end;
  61.         4: begin
  62.             Longtemp:=LongPtr(BitAND($FFFFFFFE,peekAddr));
  63.             peekVal := Longtemp^;
  64.            end;
  65.         OTHERWISE peekVal := 0;
  66.       END;
  67.       
  68.       str := NumToStr(peekVal);
  69.       returnValue := PasToZero(str);
  70.      END;
  71.   END;
  72.  
  73. BEGIN
  74. END.
  75.  
  76. (*Remember to change the ID of this resource from 300*)
  77.  
  78.  
  79.