home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / c / quikc21.zip / TIMERD12.C < prev    next >
Text File  |  1989-07-06  |  3KB  |  76 lines

  1. /*===========================================================================*\
  2. | TIMERD12.C                                                ver 2.1, 07-06-89 |
  3. |                                                                             |
  4. | DOS event timer                                                             |
  5. | by James H. LeMay                                                           |
  6. | Conversion to Turbo C by Jordan Gallagher / Wisdom Research                 |
  7. |                                                                             |
  8. | A 24 hour timer with resolution of 1/18.2... seconds to measure elapsed     |
  9. | time in seconds.  Works on all IBM compatible machines.                     |
  10. |                                                                             |
  11. | TO USE:  Place "timer( T_START );"  and  "timer( T_STOP );"  as             |
  12. |          desired in your program.  The global variable elapsed_time         |
  13. |          gives the result in seconds.                                       |
  14. \*===========================================================================*/
  15.  
  16. #include <stdio.h>
  17. #include <conio.h>
  18. #include <dos.h>
  19.  
  20. #include "qwikc21.h"
  21.  
  22. float ticks_per_day = 1573040.0;             /* DOS timer ticks/day. */
  23. float ticks_per_sec = 18.2;                  /* equal to CLK_TCK in time.h */
  24. float elapsed_time;
  25. long t1, t2;
  26.  
  27. #define T_START 1
  28. #define T_STOP 0
  29.  
  30. #ifdef __TURBOC__
  31. #define tclock() (*(long far *)0x0040006CL)
  32. #else
  33. #define tclock() (*(long far *)(0x46CL+_z))
  34. #endif
  35.  
  36. /*********************************| timer |**********************************\
  37. Called to start or stop the timer.
  38. \****************************************************************************/
  39. void timer( int ss )
  40. {
  41.     switch(ss) {
  42.         case T_START:
  43.             elapsed_time = 0;      /* in case they reference before T_STOP */
  44.             t1=tclock(); break;
  45.  
  46.         case T_STOP:
  47.             t2=tclock();
  48.             if(t2<t1) t2 += ticks_per_day;
  49.             elapsed_time = (t2-t1) / ticks_per_sec; break;
  50.     }
  51. }
  52.  
  53. /*
  54. char ch;
  55.  
  56. main()
  57. {
  58.     clrscr();
  59.     printf( "Press any key for a lap; <ESC> to stop.\n" );
  60.  
  61.     timer( T_START );
  62.  
  63.     do {
  64.         ch=getch();
  65.         timer( T_STOP );
  66.         printf( "time = %10.2f secs: ticks2=%ld\n", elapsed_time, t2 );
  67.         gotoxy( 24, wherey() );
  68.         printf( "-ticks1=%ld\n", t1 );
  69.         gotoxy( 21, wherey() );
  70.         printf( "time ticks=%ld\n\n", (t2-t1) );
  71.     } while(ch != 27);
  72.  
  73.     return;
  74. }
  75. */
  76.