[comp.sys.amiga.tech] WaitPort, GetMsg, ReplyMsg

thomson@utah-cs.UUCP (Richard A Thomson) (04/18/88)

I have been playing around with parsing IntuiMessages in FORTH and I've noticed
something a little peculiar.  I use WaitPort on the window's IDCMP and then
GetMsg to get the message itself.  I then copy the code and class fields and
then reply to the message via ReplyMsg.

The ROM Kernel docs describe the behavior of WaitPort as follows:

	message = WaitPort(port);

	port: Pointer to message port to wait on
	message: Pointer to first message in the port's message list

This tells me that after the WaitPort call, message will point to the
first message in the list.  The funny thing is that when I do a GetMsg(port)
I get a different address, although it also is listed as returning a pointer
to the first message in the port's message list.  What's going on here?
I wanted to see if I could do just the following:

	message = WaitPort(port);
	code = message->Code;
	class = message->Class;
	ReplyMsg(message);

Basically I thought that if WaitPort gives me the pointer to the first
message in the list, then I could use that pointer to ReplyMsg after I
got out the things from the message I cared about.  Since the pointers
returned by WaitPort and GetMsg are different, I'm still doing the GetMsg
while assuming that GetMsg is doing some internal list manipulation.
Any clues as to why these two give different pointers?

[ FORTH Plug ]
By the way, it was easy to figure this out using the interactive capavbilities
of the FORTH interpreter; I just called the routines and looked at their
results on the stack!  I have found FORTH to be a really productive environment
on the Amiga so far; and yes, I tried C first.  On a 512K dual floppy system
C just took tooooooo loooooong.  In the same amount of time I spent trying to
get a beginning C program to compile [and I'm no novice to C] and run properly,
I've been able to understand ALOT about the Amiga internals even though I'm
learning FORTH in the process.  This isn't the combination for everyone, but
I find it really great!
[ End plug ]
						-- Rich Thomson
-- 
					-- Rich
Richard Thomson		3190 MEB, University of Utah, Salt Lake City, UT 84112
thomson@cs.utah.edu	(801) 584-4555: Talk to a machine, they're lonely.

dillon@CORY.BERKELEY.EDU (Matt Dillon) (04/19/88)

:This tells me that after the WaitPort call, message will point to the
:first message in the list.  The funny thing is that when I do a GetMsg(port)
:I get a different address, although it also is listed as returning a pointer
:to the first message in the port's message list.  What's going on here?
:I wanted to see if I could do just the following:
:
:	message = WaitPort(port);
:	code = message->Code;
:	class = message->Class;
:	ReplyMsg(message);

	WaitPort() does NOT remove the message from the port.  you should
NEVER ReplyMsg() without GetMsg() it first.  I.E.:

	WaitPort(port);
	message = GetMsg(port);
 	code = message->Code;
 	class = message->Class;
 	ReplyMsg(message);

					-Matt

thomson@utah-cs.UUCP (Richard A Thomson) (04/19/88)

In article <8804182050.AA15158@cory.Berkeley.EDU> dillon@CORY.BERKELEY.EDU (Matt Dillon) writes:
>:In article <GumbyFooArticleNumber> I (Richard Thomson) wrote:
>:This tells me that after the WaitPort call, message will point to the
>:first message in the list.  The funny thing is that when I do a GetMsg(port)
>:I get a different address, although it also is listed as returning a pointer
>:to the first message in the port's message list.  What's going on here?
>
>	WaitPort() does NOT remove the message from the port.  you should
>NEVER ReplyMsg() without GetMsg() it first.  I.E.:
>
>	WaitPort(port);
>	message = GetMsg(port);
> 	code = message->Code;
> 	class = message->Class;
> 	ReplyMsg(message);
>
>					-Matt

The part about WaitPort not removing the message is clear and Matt's above
example is what I used, although it actually looks like this:

    [ FORTHer's version ]		[ C hack's version :-]
    port GetMsg ?DUP 0= IF		if ((message = GetMsg(port)) == 0) {
	port WaitPort DROP		    WaitPort(port);
	port GetMsg THEN		    message = GetMsg(port); }
    DUP +imCode MsgCode !		MsgCode = message->Code;
    DUP +imClass @			class = message->Class;
    SWAP ReplyMsg			ReplyMsg(message);

My question still remains unanswered, though.  The documentation for WaitPort
and GetMsg says that they both "return a pointer to the first message", but
they return different pointers!

					-- Rich Thomson
-- 
					-- Rich
Richard Thomson		3190 MEB, University of Utah, Salt Lake City, UT 84112
thomson@cs.utah.edu	(801) 584-4555: Talk to a machine, they're lonely.

ewhac@well.UUCP (Leo 'Bols Ewhac' Schwab) (04/21/88)

In article <5417@utah-cs.UUCP> thomson@cs.utah.edu.UUCP (Richard A Thomson) writes:
>My question still remains unanswered, though.  The documentation for WaitPort
>and GetMsg says that they both "return a pointer to the first message", but
>they return different pointers!
>
	The way I always interpreted WaitPort()'s return value was that it
returned a pointer to the message that woke you up.  This could be useful if
you wanted to Remove() that message explicitly, leaving the remainder of the
list intact.

	I have no proof that this is the case, however.  This is just an
educated guess...

_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
Leo L. Schwab -- The Guy in The Cape  ihnp4!pacbell -\
 \_ -_		Recumbent Bikes:	      dual ---> !{well,unicom}!ewhac
O----^o	      The Only Way To Fly.	      hplabs / (pronounced "AE-wack")
"Work FOR?  I don't work FOR anybody!  I'm just having fun."  -- The Doctor