/************************************************************************
 *
 *	sometask.h	This B the code for the task we're creating.
 *
 ************************************************************************/

#include <clib/macros.h>
#include <intuition/intuition.h>
 
/************************************************************************
 *	G L O B A L     V A R I A B L E S
 ************************************************************************/

struct	NewWindow	new = {
	300, 20, 320, 25, (UBYTE) 0, (UBYTE) 1,
	NULL, (ULONG) (WINDOWDRAG | WINDOWDEPTH), NULL, NULL,
	(UBYTE *) "This b a test...", NULL, NULL, 0, 0, 0, 0,
	WBENCHSCREEN 
};

/************************************************************************
 *	S O M E    T A S K
 ************************************************************************/

SomeTask()
{
	struct	TaskInfo	*me;	/* Task struct for this Unit	*/
	struct	SomeMsg		*sm;	/* Pointer to messages we recv.	*/
	struct	Window		*win;
	struct	RastPort	*rp;	/* the RastPort for our Winder	*/
	LONG			waitMask, /* mask passed to Wait()      */
				gotMask,  /* mask returned by Wait()    */
				len;
 
	/****************************************************************
	 *	Initialization code
	 ****************************************************************/
 
#ifdef	AZTEC
	geta4();	/* set A4 to once again point into the center
			of our data segment. It was saved in init_all	*/
#endif

		/*** Find out who I am and allocate some resources ***/
 
	me = (struct TaskInfo *) FindTask((char *) 0);

	me->ti_MsgPort = CreatePort("Some Task",(LONG) 0);

	win = OpenWindow(&new);

	rp = win->RPort;

	SetDrMd(rp, (LONG) JAM2);
	SetAPen(rp, 1L);
	SetBPen(rp, 0L);

	Move(rp, 4L, 19L);
	Text(rp, "Hello World!!!", 14L);

	FOREVER {
		WaitPort(me->ti_MsgPort);
		while (sm = (struct SomeMsg *) GetMsg(me->ti_MsgPort))
			switch (sm->sm_Command) {
				case CMD_DOYOURTHING:
					len = MIN((LONG)strlen(sm->sm_Whatever),
						(LONG) 20);
					Move(rp, 4L, 19L);
					Text(rp, "                     ", 20L);
					Move(rp, 4L, 19L);
					Text(rp, sm->sm_Whatever, (LONG) len);
					ReplyMsg(sm);
					break;
				case CMD_CURLUPANDDIE:
					Disable();
					CloseWindow(win);
					ReplyMsg(sm);
					DeletePort(me->ti_MsgPort);
					Wait(NULL);
					break;
			} /* switch */
	} /* FOREVER */
} /* SomeTask */
