home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Carousel
/
CAROUSEL.cdr
/
mactosh
/
hc
/
xcmd_glu.sit
/
Peek.p
< prev
next >
Wrap
Text File
|
1987-08-06
|
2KB
|
86 lines
{$R-}
(*
peek -- a sample HyperCard external function (return the contents
of a memory location).
⌐Apple Computer, Inc. 1987
All Rights Reserved.
To compile and link this file using Macintosh Programmer's Workshop
(HyperXCmd.p and XCmdGlue.inc must be accessible).
pascal -w Peek.p
link -o HyperCommands -rt XFCN=0 -sn Main=Peek Peek.p.o
then use ResEdit to copy the resulting XCMD from HyperCommands
and paste it into the Home stack, or your own stack.
When you build your own XFCNs, if you need to load
"{MPW}"Libraries:interface.o, then say -m ENTRYPOINT in the link statement
to filter out all routines you don't use.
*)
{$S Peek } { Segment name must be the same as the command name. }
UNIT DummyUnit;
INTERFACE
USES MemTypes, HyperXCmd;
PROCEDURE EntryPoint(paramPtr: XCmdPtr);
IMPLEMENTATION
TYPE Str31 = String[31];
Str19 = String[19];
WordPtr = ^INTEGER;
LongPtr = ^LongInt;
PROCEDURE Peek(paramPtr: XCmdPtr); FORWARD;
PROCEDURE EntryPoint(paramPtr: XCmdPtr);
BEGIN
Peek(paramPtr);
END;
PROCEDURE Peek(paramPtr: XCmdPtr);
VAR peekAddr,peekSize,peekVal: LongInt;
str: Str255;
{$I XCmdGlue.inc }
BEGIN
WITH paramPtr^ DO
BEGIN
{ first param is addr }
ZeroToPas(params[1]^,str);
peekAddr := StrToNum(str);
{ second param, if given, is size }
peekSize := 1;
IF paramCount = 2 THEN
BEGIN
ZeroToPas(params[2]^,str);
peekSize := StrToNum(str);
END;
CASE peekSize OF
1: peekVal := BAND($000000FF,Ptr(peekAddr)^);
2: peekVal := BAND($0000FFFF,WordPtr(BAND($FFFFFFFE,peekAddr))^);
4: peekVal := LongPtr(BAND($FFFFFFFE,peekAddr))^;
OTHERWISE peekVal := 0;
END;
str := NumToStr(peekVal);
returnValue := PasToZero(str);
END;
END;
END.