home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / JOE_SOUR.LHA / Sources.lha / s!x / announce / time.c < prev   
Encoding:
C/C++ Source or Header  |  1996-02-16  |  2.4 KB  |  82 lines

  1. /*
  2.  * Copyright (c) 1992 Commodore-Amiga, Inc.
  3.  * 
  4.  * This example is provided in electronic form by Commodore-Amiga, Inc. for 
  5.  * use with the "Amiga ROM Kernel Reference Manual: Devices", 3rd Edition, 
  6.  * published by Addison-Wesley (ISBN 0-201-56775-X).
  7.  * 
  8.  * The "Amiga ROM Kernel Reference Manual: Devices" contains additional 
  9.  * information on the correct usage of the techniques and operating system 
  10.  * functions presented in these examples.  The source and executable code 
  11.  * of these examples may only be distributed in free electronic form, via 
  12.  * bulletin board or as part of a fully non-commercial and freely 
  13.  * redistributable diskette.  Both the source and executable code (including 
  14.  * comments) must be included, without modification, in any copy.  This 
  15.  * example may not be published in printed form or distributed with any
  16.  * commercial product.  However, the programming techniques and support
  17.  * routines set forth in these examples may be used in the development
  18.  * of original executable software products for Commodore Amiga computers.
  19.  * 
  20.  * All other rights reserved.
  21.  * 
  22.  * This example is provided "as-is" and is subject to change; no
  23.  * warranties are made.  All use is at your own risk. No liability or
  24.  * responsibility is assumed.
  25.  *
  26.  *****************************************************************************
  27.  *
  28.  * Get_Systime.c
  29.  *
  30.  * Get system time example
  31.  *
  32.  * Compile with SAS C 5.10: LC -b1 -cfistq -v -y -L
  33.  *
  34.  * Run from CLI only
  35.  */
  36.  
  37. #include <exec/types.h>
  38. #include <exec/io.h>
  39. #include <exec/memory.h>
  40. #include <devices/timer.h>
  41.  
  42. #include <clib/exec_protos.h>
  43. #include <clib/alib_protos.h>
  44. #include <clib/dos_protos.h>
  45. #include <clib/intuition_protos.h>
  46.  
  47. #include <stdio.h>
  48.  
  49.  
  50. BOOL main(VOID);
  51.  
  52. BOOL main ()
  53. {
  54. struct timerequest *TimerIO;
  55. struct MsgPort *TimerMP;
  56. struct Message *TimerMSG;
  57. LONG error;
  58. LONG hrs,secs,mins;
  59. char buffer[50];
  60.  
  61. TimerMP = CreatePort(0,0);
  62. if(!TimerMP) return(NULL);
  63. TimerIO = (struct timerequest *)CreateExtIO(TimerMP,sizeof(struct timerequest));
  64. if (!TimerIO) return(NULL);
  65. error=OpenDevice(TIMERNAME,UNIT_VBLANK,(struct IORequest *)TimerIO,0L);
  66. if (error) return (NULL);
  67. TimerIO->tr_node.io_Command = TR_GETSYSTIME;
  68. DoIO((struct IORequest *) TimerIO);
  69. secs=TimerIO->tr_time.tv_secs;
  70. mins=secs/60;
  71. hrs=mins/60;
  72. secs=secs%60;
  73. mins=mins%60;
  74. hrs=hrs%60;
  75.  
  76. CloseDevice((struct IORequest *) TimerIO);
  77. DeleteExtIO((struct IORequest *) TimerIO);
  78. DeletePort(TimerMP);
  79. sprintf(buffer,"%2d:%2d:%2d\n",hrs,mins,secs);
  80. printf(buffer);
  81. }
  82.