home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377b.lha / devices / timer / getsystime.c next >
Encoding:
C/C++ Source or Header  |  1980-02-03  |  3.0 KB  |  88 lines

  1. /* Copyright (c) 1990 Commodore-Amiga, Inc.
  2.  *
  3.  * This example is provided in electronic form by Commodore-Amiga, Inc. for
  4.  * use with the 1.3 revisions of the Addison-Wesley Amiga reference manuals. 
  5.  * The 1.3 Addison-Wesley Amiga Reference Manual series contains additional
  6.  * information on the correct usage of the techniques and operating system
  7.  * functions presented in this example.  The source and executable code of
  8.  * this example may only be distributed in free electronic form, via bulletin
  9.  * board or as part of a fully non-commercial and freely redistributable
  10.  * diskette.  Both the source and executable code (including comments) must
  11.  * be included, without modification, in any copy.  This example may not be
  12.  * published in printed form or distributed with any commercial product.
  13.  * However, the programming techniques and support routines set forth in
  14.  * this example may be used in the development of original executable
  15.  * software products for Commodore Amiga computers.
  16.  * All other rights reserved.
  17.  * This example is provided "as-is" and is subject to change; no warranties
  18.  * are made.  All use is at your own risk.  No liability or responsibility
  19.  * is assumed.
  20.  */
  21.  
  22. /* getsystime.c - get system time */
  23. /* Lattice use -b1 - cfist -v -y */
  24. /* Link with lc.lib, amiga.lib    */
  25.  
  26. #include <exec/types.h>
  27. #include <devices/timer.h>
  28. #include <proto/all.h>
  29. #include <stdlib.h>
  30. #include <stdio.h>
  31.  
  32. #ifdef LATTICE
  33. int CXBRK(void) { return(0); }  /* Disable Lattice CTRL/C handling */
  34. int chkabort(void) { return(0); }  /* really */
  35. #endif
  36.  
  37. struct timerequest tr;
  38. struct MsgPort *tport;
  39. struct Message *msg;
  40.  
  41. void main(int argc,char **argv)
  42. {
  43.    LONG error;
  44.    ULONG days,hrs,secs,mins,mics;
  45.  
  46.    /* Open the MICROHZ timer device */
  47.    error = OpenDevice(TIMERNAME,UNIT_MICROHZ,(struct IORequest *) &tr,0);
  48.    if(error) return;/* If the timer will not open then just return */
  49.  
  50.    tport=CreatePort(0,0);
  51.    /* If we can't get a reply port then just quit */
  52.    if(!tport)
  53.         {
  54.         CloseDevice((struct IORequest *) &tr );
  55.         return;
  56.         }
  57.  
  58.    /* Fill in the IO block with command data */
  59.    tr.tr_node.io_Message.mn_Node.ln_Type = NT_MESSAGE;
  60.    tr.tr_node.io_Message.mn_Node.ln_Pri  = 0;
  61.    tr.tr_node.io_Message.mn_Node.ln_Name = NULL;
  62.    tr.tr_node.io_Message.mn_ReplyPort    = tport;
  63.    tr.tr_node.io_Command                 = TR_GETSYSTIME;
  64.  
  65.    /* Issue the command and wait for it to finish, then get the reply */
  66.    DoIO((struct IORequest *) &tr);
  67.  
  68.    /* Get the results and close the timer device */
  69.    mics=tr.tr_time.tv_micro;
  70.    secs=tr.tr_time.tv_secs;
  71.    DeletePort(tport);
  72.    CloseDevice((struct IORequest *) &tr);
  73.  
  74.    /* Compute days, hours, etc. */
  75.    mins=secs/60;
  76.    hrs=mins/60;
  77.    days=hrs/24;
  78.    secs=secs%60;
  79.    mins=mins%60;
  80.    hrs=hrs%24;
  81.  
  82.    /* Display the time */
  83.    printf("\nSystem Time (measured from Jan.1,1978)\n");
  84.    printf("  Days   Hours  Minutes Seconds Microseconds\n");
  85.    printf("%6ld %6ld %6ld %6ld %10ld\n",days,hrs,mins,secs,mics);
  86.  
  87. }      /* end of main */
  88.