#include <TOS.H>

void
MessageLoop( void )
{
	short mx, my;			/* Mouse Position */
	short mb, mc;			/* Mouse button/# clicks */
	short ks, kc;			/* Key state/code */
	short quit;			/* Exit flag */
	short msg[8];			/* Message buffer */
	short events;			/* What events are valid? */

/* Mask for all events */
#define ALL_EVENTS	(MU_MESAG|MU_BUTTON|MU_KEYBD|MU_TIMER|MU_M1|MU_M2)

	quit = FALSE;
	while(!quit)
	{
		events = evnt_multi( ALL_EVENTS,
					2, 1, 1,   		/* Single/double clicks */
					0, 0, 0, 128, 128,	/* M1 event */
					1, 0, 0, 128, 128,  	/* M2 event */
					msg,	    		/* Pointer to msg */
					1000, 0,   		/* MU_TIMER every 1 sec. */
					&mx, &my, &ks, &kc,
					&mc );

		if( events & MU_MESAG )
		{
			switch( msg[0] )		/* msg[0] is message type */
			{
				case MN_SELECTED:
					HandleMenuClick( msg );
					break;
				case WM_CLOSED:
					CloseWindow( msg[3] );
					break;
				/*
				 * more message events...
				 */
			}
		}

		if( events & MU_BUTTON )
		{
			/*
			 * Handle mouse button event.
			 */
		}

		if( events & MU_KEYBD )
		{
			/*
			 * Handle keyboard events.
			 */
		}

		if( events & MU_TIMER )
		{
			/*
			 * Handle Timer events.
			 */
		}

		if( events & MU_M1 )
		{
			/*
			 * Handle mouse rectangle event 1.
			 */
		}

		if( events & MU_M2 )
		{
			/*
			 * Handle mouse rectangle event 2.
			 */
		}
	}

	/* Loop will terminate here when 'quit' is set to TRUE. */
}
