$compact
gaston$code: DO;

$if r_32
	DECLARE	SIZE$OF$OFF_SET	LITERALLY	'DWORD';
$else
	DECLARE	SIZE$OF$OFF_SET	LITERALLY	'WORD';
$endif

DECLARE token				LITERALLY		'SELECTOR';
DECLARE gaston$ds			WORD PUBLIC;

$include(:rmx:inc/nuclus.ext)
$include(:rmx:inc/eios.ext)
$include(:rmx:inc/hi.ext)

gaston: PROCEDURE PUBLIC;

DECLARE CR						LITERALLY	'13';
DECLARE LF						LITERALLY	'10';
DECLARE fifo					LITERALLY	'0';
DECLARE wait$forever			LITERALLY	'0FFFFH';
DECLARE parent$task				TOKEN;
DECLARE calling$tasks$job		TOKEN;
DECLARE master$mbox				TOKEN;
DECLARE response$mbox			TOKEN;
DECLARE status					WORD;
DECLARE time$limit				WORD;
DECLARE count					WORD;
DECLARE final$count				WORD;
DECLARE seg$token				TOKEN;
DECLARE seg$size				SIZE$OF$OFF_SET;
DECLARE main$message(*) 		BYTE		DATA(
	CR,LF, 'After you, Alphonse', CR, LF);

DECLARE final$message(*) 		BYTE		DATA(
	CR,LF, 'If you insist, Alphonse', CR, LF);

DECLARE message BASED seg$token	STRUCTURE(
				count			BYTE,
				text(27)		BYTE);

	count = 0;								/* Initialize count           */
	final$count = 6;						/* Set number of loops        */
	time$limit = 25;						/* Delay factor for display   */
											/* to screen                  */
	seg$size = 32;							/* Size of message segment    */
	calling$tasks$job = SELECTOR$OF(NIL);	/* Directory in which to  */
											/* look up object             */

	master$mbox = RQ$LOOKUP$OBJECT (		/* Look up message mailbox   */
		calling$tasks$job,
		@(6,'master'),
		wait$forever,
		@status);

	response$mbox = RQ$CREATE$MAILBOX (		/* Create response mailbox   */
		fifo,
		@status);

	seg$token = RQ$CREATE$SEGMENT(			/* Create message segment    */
		seg$size,
		@status);

	DO WHILE count < final$count;
		message.count = 23;
		CALL MOVW (@main$message, @message.text, SIZE(main$message));
		CALL RQ$C$SEND$CO$RESPONSE (		/* Send message to screen    */
			NIL,
			0,
			@message.count,
			@status);

		CALL RQ$SLEEP(						/* Wait a while to give user */
			time$limit,						/* time to see the message   */
			@status);

		CALL RQ$SEND$MESSAGE (				/* Send message to mailbox   */
			master$mbox,
			seg$token,
			response$mbox,
			@status);

		seg$token = RQ$RECEIVE$MESSAGE (		/* Receive response from  */
			response$mbox,					/* Alphonse               */
			wait$forever,
			NIL,
			@status);

		count = count + 1;
	END;									/* WHILE                  */

	message.count = 27;
	CALL MOVB (@final$message, @message.text, SIZE(final$message));

		CALL RQ$C$SEND$CO$RESPONSE (		/* Send final message to  */
		NIL,								/* screen                 */
		0,
		@message.count,
		@status);

	CALL RQ$SEND$MESSAGE (					/* Send token for mailbox */
		master$mbox,						/* to mailbox.  This will */
		master$mbox,						/* stop other task.       */
		SELECTOR$OF(NIL),
		@status);

	parent$task = RQ$LOOKUP$OBJECT (		/* Look up token for      */
		calling$tasks$job,					/* calling task           */
		@(4,'init'),
		wait$forever,
		@status);

	CALL RQ$RESUME$TASK (					/* Resume calling task    */
		parent$task,						/* for cleanup            */
		@status);

	END gaston;
END gaston$code;
