
#include "pop.h"

int setuptime( void )
{
	timer_mp = CreateMsgPort();

	if (timer_mp == NULL )
	{
		doreq("CreateMsgPort() failed\n",bum);
		return(0);
	}

	timerio=(struct timerequest *)CreateExtIO(timer_mp,sizeof(struct timerequest));

	if ( OpenDevice(TIMERNAME,UNIT_VBLANK,(struct IORequest *)timerio,0) )
	{
		doreq("OpenDevice() failed\n",bum);
		return(0);
	}
        return(1);
}

int closetime( void )
{
	if (timer_mp)
	{
		if (timerio)
		{
			AbortIO( (struct IORequest *)timerio);
			WaitIO( (struct IORequest *)timerio);
			CloseDevice( (struct IORequest *)timerio );
			DeleteExtIO( (struct IORequest *)timerio);
		}

                DeleteMsgPort(timer_mp);
	}

	timer_mp=NULL;
	timerio=NULL;

	return(0);
}

void timereq(void)
{
	timerio->tr_node.io_Command	= TR_ADDREQUEST;
	timerio->tr_time.tv_secs	= (60*timecheck);
	timerio->tr_time.tv_micro	= 0;
	SendIO( (struct IORequest *)timerio );
}



