home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / turbo_c / ticktock.c < prev    next >
C/C++ Source or Header  |  1994-03-05  |  2KB  |  63 lines

  1.  
  2. /*
  3.      Name: ticktock.c
  4.      Author: Michael Tighe
  5.      System: IBM PC/XT/AT/PS2, MS-DOS 3.30
  6.    Language: Turbo C Version 2.00
  7. Description: Demo of the IBM-PC's high resolution clock
  8.  
  9.     INFO FOR TICKTOCK:
  10.  
  11.     The TICKTOCK programs demonstrate how to obtain accurate timing
  12. information from the IBM PC/XT/AT family of computers. The next few
  13. paragraphs should give you a basic idea of how the time is stored in these
  14. computer systems.
  15.  
  16.     In the PC family, an internal clock runs at 1.193180 Mhz. This clock
  17. is divided by 65536 to give 18.206482 clock pulses per second (.0549255
  18. seconds per clock pulse). Therefore, the clock 'ticks' every .0549255
  19. seconds.
  20.  
  21.     Two addresses in low memory are used to keep track of the tick count.
  22. They are both 1 word (two bytes) in length. The first is at address
  23. 0000:046C. It is incremented 18.2 times a second. When it overflows, it is
  24. reset to 0 and another word at address 0000:046E is incremented.
  25.  
  26.     It should be noted that the word at address 0000:046E is also the
  27. current hour, in 24 hour format. The address at 0000:046C when divided by
  28. 18.2, is the current time past the hour, in seconds.
  29.  
  30. */
  31. # include <stdio.h>
  32.  
  33. # define TIMER_LO 0X46C
  34. # define TIMER_HI 0X46E
  35.  
  36. void geticktock();
  37.  
  38. float tick, tock;
  39.  
  40. main()
  41. {
  42.   printf("[TICKTOCK Version 87.365]\n\n");
  43.   getticktock();
  44.   printf("tick value is %6.0f, tock value is %6.0f\n",tick,tock);
  45.   printf("Sleeping for 5 seconds (~91 ticks)...\n"); sleep(5);
  46.   getticktock();
  47.   printf("tick value is %6.0f, tock value is %6.0f\n",tick,tock);
  48.   return;
  49. }
  50.  
  51. getticktock()
  52. {
  53.   unsigned char t1,t2;
  54.  
  55.   t1 = 0; t2 = 0;
  56.   t1 = peekb(0,TIMER_LO); t2 = peekb(0,TIMER_LO+1);
  57.   tick = (float) t1 + (float) t2 * 256;
  58.   t1 = peekb(0,TIMER_HI); t2 = peekb(0,TIMER_HI+1);
  59.   tock = (float) t1 + (float) t2 * 256;
  60.   return;
  61. }
  62.  
  63.