/*
** vbcc-Amiga-PowerPC version of time.c
**
** v0.2 14.12.97 phx
**      PPCCallOS for DateStamp() included.
** v0.1 04.10.97 phx
*/

#include <time.h>
#include <dos/dos.h>
#include <powerup/gcclib/powerup_protos.h>

extern long __gmtoffset;
extern ULONG DOSBase;


time_t time(time_t *tloc)
{
  struct DateStamp t;
  time_t ti;
  struct Caos MyCaos;

  MyCaos.d1 = (ULONG)&t;
  MyCaos.M68kCacheMode = IF_CACHEFLUSHALL;
  MyCaos.PPCCacheMode = IF_CACHEFLUSHALL;
  MyCaos.caos_Un.Offset = -192;
  MyCaos.a6 = DOSBase;
  PPCCallOS(&MyCaos);  /* 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
 */ 
