#define class _class
#define template _template

extern "C" {
#include <exec/types.h>
#include <dos/dos.h>
#include <inline/stubs.h>
#include <clib/dos_protos.h>
#ifdef __OPTIMIZE__
#include <inline/exec.h>
#include <inline/dos.h>
#include <inline/utility.h>
#else
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/utility_protos.h>
#endif
}
#undef template
#undef class

#define  TIMER_ERROR_VALUE -1.0

static struct DateStamp Old_Time;
static struct DateStamp New_Time;
static int    Timer_Set = 0;


double start_timer()
{
	Timer_Set = 1;
	DateStamp(&Old_Time);

	/* can't happen in 1993, if Days==0 clock is unset */
	if(Old_Time.ds_Days==0)	return TIMER_ERROR_VALUE;

	return 0.0;		/* we needed no time yet. */
}

/* Returns process time since Last_Time.
   If parameter is 0.0, returns time since the Old_Time was set.
   Returns TIMER_ERROR_VALUE if `start_timer' is not called first.  */

double return_elapsed_time(double Last_Time)
{
   if (!Timer_Set) {
      return(TIMER_ERROR_VALUE);
   }
   else {
    /* get process time */
      DateStamp(&New_Time);
      if (Last_Time == 0.0)
	  {
		 return((double)
			(SMult32(New_Time.ds_Days-Old_Time.ds_Days,86400)+
             SMult32(New_Time.ds_Days-Old_Time.ds_Days,60)+
             (New_Time.ds_Tick-Old_Time.ds_Tick)
            ) / TICKS_PER_SECOND );
      }
      else
	  {
		 return((double)
			((SMult32(New_Time.ds_Days,86400)+
             SMult32(New_Time.ds_Days,60)+
             (New_Time.ds_Tick)
            ) / TICKS_PER_SECOND) - Last_Time);
      }
   }
}
