#include <exec/types.h>
#include <exec/ports.h>
#include <exec/memory.h>

#include <clib/exec_protos.h>
#include <clib/alib_protos.h>

#include "defs.h"

void blank( struct bMessage * );
void defaults( UBYTE *prefData );
void prefs( UBYTE *prefData );

struct	MsgPort		*modPort, *sendPort;
struct	bMessage	*modMsg;
extern	UBYTE		infoString[];

void main( void )
{
	if( sendPort = FindPort( "BlankerCC" )) {
		modPort = CreatePort(0,0);

		modMsg = AllocMem( sizeof( struct bMessage ), MEMF_PUBLIC|MEMF_CLEAR );
		modMsg->bMess.mn_ReplyPort = modPort;
		modMsg->bMess.mn_Length = sizeof( struct bMessage );
		modMsg->prefData = (UBYTE *)FindTask( 0L );

		Forbid();
		CopyMem( "Blanker Task", (( struct Task * )modMsg->prefData)->tc_Node.ln_Name, 13 );
		Permit();

		if( sendPort ) PutMsg( sendPort, ( struct Message * )modMsg );
		WaitPort( modPort );
		GetMsg( modPort );
		FreeMem( modMsg, sizeof( struct bMessage ));

		while( 1 ) {
			WaitPort( modPort );
			modMsg = ( struct bMessage * )GetMsg( modPort );
			if( modMsg->bm_Type & BM_UNLOAD ) {
				ReplyMsg(( struct Message * )modMsg );
				break;
			}
			if( !modMsg->bm_Valid ) defaults( modMsg->prefData );
			if( modMsg->bm_Type & BM_BLANK ) {
				blank( modMsg );
				ReplyMsg(( struct Message * )modMsg );
			} else if( modMsg->bm_Type & BM_INFO ) {
				modMsg->prefData = infoString;
				ReplyMsg(( struct Message * )modMsg );
			} else if( modMsg->bm_Type & BM_PREFS ) {
				prefs( modMsg->prefData );
				ReplyMsg(( struct Message * )modMsg );
			}
			if( modMsg->bm_Type & BM_QUIT ) break;
		}
		DeletePort( modPort );
	}
}
