home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 1.2 / amidev_cd_12.iso / reference_library / devices / dev_examples / get_systime.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-20  |  2.2 KB  |  86 lines

  1. /* Get_Systime.c
  2.  *
  3.  * Get system time example
  4.  *
  5.  * Compile with SAS C 5.10: LC -b1 -cfistq -v -y -L
  6.  *
  7.  * Run from CLI only
  8.  */
  9.  
  10. #include <exec/types.h>
  11. #include <exec/io.h>
  12. #include <exec/memory.h>
  13. #include <devices/timer.h>
  14.  
  15. #include <clib/exec_protos.h>
  16. #include <clib/alib_protos.h>
  17. #include <clib/dos_protos.h>
  18. #include <clib/intuition_protos.h>
  19.  
  20. #include <stdio.h>
  21.  
  22. #ifdef LATTICE
  23. int CXBRK(void) { return(0); }     /* Disable SAS CTRL/C handling */
  24. int chkabort(void) { return(0); }  /* really */
  25. #endif
  26.  
  27. struct timerequest *TimerIO;
  28. struct MsgPort *TimerMP;
  29. struct Message *TimerMSG;
  30.  
  31. VOID main(VOID);
  32.  
  33. void main()
  34. {
  35. LONG error;
  36. ULONG days,hrs,secs,mins,mics;
  37.  
  38. if (TimerMP = CreatePort(0,0))
  39.     {
  40.     if (TimerIO = (struct timerequest *)
  41.                    CreateExtIO(TimerMP,sizeof(struct timerequest)) )
  42.         {
  43.             /* Open with UNIT_VBLANK, but any unit can be used */
  44.         if (!(error=OpenDevice(TIMERNAME,UNIT_VBLANK,(struct IORequest *)TimerIO,0L)))
  45.             {
  46.             /* Issue the command and wait for it to finish, then get the reply */
  47.             TimerIO->tr_node.io_Command = TR_GETSYSTIME;
  48.             DoIO((struct IORequest *) TimerIO);
  49.  
  50.             /* Get the results and close the timer device */
  51.             mics=TimerIO->tr_time.tv_micro;
  52.             secs=TimerIO->tr_time.tv_secs;
  53.  
  54.             /* Compute days, hours, etc. */
  55.             mins=secs/60;
  56.             hrs=mins/60;
  57.             days=hrs/24;
  58.             secs=secs%60;
  59.             mins=mins%60;
  60.             hrs=hrs%24;
  61.  
  62.             /* Display the time */
  63.             printf("\nSystem Time (measured from Jan.1,1978)\n");
  64.             printf("  Days   Hours  Minutes Seconds Microseconds\n");
  65.             printf("%6ld %6ld %6ld %6ld %10ld\n",days,hrs,mins,secs,mics);
  66.  
  67.             /* Close the timer device */
  68.             CloseDevice((struct IORequest *) TimerIO);
  69.             }
  70.         else
  71.             printf("\nError: Could not open timer device\n");
  72.  
  73.         /* Delete the IORequest structure */
  74.         DeleteExtIO(TimerIO);
  75.         }
  76.     else
  77.         printf("\nError: Could not create I/O structure\n");
  78.  
  79.     /* Delete the port */
  80.     DeletePort(TimerMP);
  81.     }
  82. else
  83.     printf("\nError: Could not create port\n");
  84. }
  85.  
  86.