

		include	"baselibs.i"
		include	"baselibs1.i
		include	"baseio.i"
		include	"baseexec.i"
		include "exec/nodes.i"
		include	"exec/libraries.i"
		include	"exec/ports.i"
		include	"exec/io.i"
		include "devices/timer.i"

	#define	LF,10
	#define	NULL,0

	DATAAREA

	{
	structset	tr,IOTV_SIZE	;timerequest
	}

	 main()
	
	CPTR	tport
	CPTR	msg
	CPTR	tr_time
   	int error;
   	int days,hrs,secs,mins,mics;
	int	year,month
   {
   ; Open the MICROHZ timer device */
   func	error,=,OpenDevice,"timer.device",UNIT_MICROHZ,tr,0;
   if	error,!=,0,1	; If the timer will not open then just return */
	{
	printf	<"no open devices",LF>
	exit	0
	}
	ifend	1

   func	tport,=,CreatePort,0,0;
   ; If we can't get a reply port then just quit */
   if	tport,==,0,2
        {
	printf	<"no create port",LF>
        CloseDevice	tr;
        exit	0;
        }
	ifend	2

   ; Fill in the IO block with command data */
   structput	tr,.,LN_TYPE,=,NT_MESSAGE;
   structput	tr,.,LN_PRI,=,0;
   structput	tr,.,LN_NAME,=,NULL;
   structput	tr,.,MN_REPLYPORT,=,tport;
   structput	tr,.,IO_COMMAND,=,TR_GETSYSTIME;

   ; Issue the command and wait for it to finish, then get the reply */
   DoIO	tr;

   ; Get the results and close the timer device */
   structput	tr_time,=&,tr,.,IOTV_TIME;
   structput	mics,=,tr_time,->,TV_MICRO;
   structput	secs,=,tr_time,->,TV_SECS;
   DeletePort	tport;
   CloseDevice	tr;

   ; Compute days, hours, etc. */
   calc	mins,=,secs,/,60;
   calc	hrs,=,mins,/,60;
   calc	days,=,hrs,/,24;
   calc	secs,=,secs,%,60;
   calc	mins,=,mins,%,60;
   calc	hrs,=,hrs,%,24;
   

   ; Display the time *
   printf	<"System Time measured from Jan.1,1978",LF>;
   printf	<"Days   Hours  Minutes Seconds Microseconds",LF>;
   printf	<" %6ld %6ld %6ld %6ld %10ld",LF>,days,hrs,mins,secs,mics;

  }      ; end of main *
	end
