/*
** vbcc-PowerOpen/WarpOS version of time.c
**
** v0.1 06.03.98 phx
*/

#include <time.h>
#include <dos/dos.h>
#include <powerpc/powerpc.h>
#include <clib/powerpc_protos.h>

extern long __gmtoffset;
extern ULONG DOSBase;


time_t time(time_t *tloc)
{
  struct DateStamp t;
  time_t ti;
  struct PPCArgs pa;

  pa.PP_Code = (APTR)DOSBase;
  pa.PP_Offset = -192;  /* _LVODateStamp */
  pa.PP_Flags = pa.PP_StackSize = 0;
  pa.PP_Stack = NULL;
  pa.PP_Regs[PPREG_D1] = (ULONG)&t;
  pa.PP_Regs[PPREG_A6] = (ULONG)DOSBase;
  Run68K(&pa);  /* Get timestamp */
  ti=((t.ds_Days+2922)*1440+t.ds_Minute+__gmtoffset)*60+
      t.ds_Tick/TICKS_PER_SECOND;
  if(tloc!=NULL)
    *tloc=ti;
  return ti;
}

/*
 * 2922 is the number of days between 1.1.1970 and 1.1.1978 (2 leap years and 6
normal)
 * 1440 is the number of minutes per day
 *   60 is the number of seconds per minute
 */ 
