/********************************************************************
 *																	*
 *	Timer module													*
 *																	*
 *	Copyright (c) Clever Bits and Bitgate Software 1993 - 1994		*
 *	All Rights Reserved.											*
 *																	*
 *	Deals with timers in a task-switching method.					*
 *																	*
 ********************************************************************
 *																	*
 *	Update log:														*
 *																	*
 *	[27.03.94 - 30.03.94] Ken Hollis								*
 *		WTimerStat			- removed								*
 *		(global)			- updated all timer routines to handle	*
 *								timers in window structures			*
 *							- added WCallTMDDispatcher to timers	*
 *																	*
 ********************************************************************/

#include <time.h>

#include "winlib.h"

#ifdef __TURBOC__
#pragma warn -pia
#endif

#ifndef __TIMER__
#define __TIMER__
#endif

/*
 *	Start timer
 */
GLOBAL void WStartTimer(WINDOW *win)
{
	win->timer.clock = clock() * 1000 / CLK_TCK + win->timer.ev_mtcount;
	win->timer.status = TRUE;

	WCallTMDDispatcher(win, T_RUNNING);
}

/*
 *	Stop timer
 */
GLOBAL void WStopTimer(WINDOW *win)
{
	win->timer.status = FALSE;

	WCallTMDDispatcher(win, T_STOPPED);
}

/*
 *	Register new timer
 *
 *	status = status of timer
 *	ev_tcount = counter time in milliseconds
 *	TmrDispatcher = timer dispatcher
 *	user = pointer to user defined structure
 */
GLOBAL void WCreateTimer(WINDOW *win, int status, long ev_tcount, void *user)
{
	win->timer.ev_mtcount = ev_tcount;
	win->timer.user = user;

	if (status)
		WStartTimer(win);
	else
		WStopTimer(win);
}
