home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 4.ddi / TOOLS.4 / TCTSRC1.EXE / UTTK2TIM.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  1.7 KB  |  63 lines

  1. /**
  2. *
  3. * Name        UTTK2TIM -- Compute the time of day for a given IBM
  4. *                clock tick value.
  5. *
  6. * Synopsis    uttk2tim (ticks, phrs, pmins, psecs, phunds);
  7. *
  8. *        unsigned long ticks    Tick value for which to
  9. *                    compute a time of day.
  10. *        int *phrs, *pmins,    Returned time of day.
  11. *             *psecs, *phunds
  12. *
  13. * Description    UTTK2TIM computes the time of day which corresponds to
  14. *        the IBM clock tick value given.
  15. *
  16. *        The time value generated is within 1.4 seconds of the
  17. *        correct value, as long as the number of ticks passed to
  18. *        UTTK2TIM is between 0 and 1,573,066 (the number of ticks
  19. *        in one day).
  20. *
  21. *        On standard IBM PCs, timer ticks occur 1193180/65536
  22. *        (about 18.2) times per second.
  23. *
  24. * Returns    None.
  25. *
  26. * Version    6.00 (C)Copyright Blaise Computing Inc.  1987,1989
  27. *
  28. **/
  29.  
  30. #include <butil.h>
  31.  
  32. #define UL (unsigned long)
  33.  
  34. void uttk2tim (ticks, phrs, pmins, psecs, phunds)
  35. unsigned long ticks;
  36. int *phrs, *pmins, *psecs, *phunds;
  37. {
  38.     unsigned long fudge;
  39.  
  40.     *phrs   = (int) (ticks / 65543L);
  41.     fudge   = (*phrs)
  42.           ? ((UL (*phrs) * 33494L) / 100000L)
  43.           : (0L);
  44.     ticks  -= UL (*phrs) * 65543L;
  45.     ticks   = (ticks > fudge) ? (ticks - fudge) : (0L);
  46.  
  47.     *pmins  = (int) (ticks / 1092L);
  48.     fudge   = (*pmins)
  49.           ? ((UL (*pmins) * 388915L) / 1000000L)
  50.           : (0L);
  51.     ticks  -= UL (*pmins) * 1092L;
  52.     ticks   = (ticks > fudge) ? (ticks - fudge) : (0L);
  53.  
  54.     *psecs  = (int) (ticks / 18L);
  55.     fudge   = (*psecs)
  56.           ? ((UL (*psecs) * 206482L) / 1000000L)
  57.           : (0L);
  58.     ticks  -= UL (*psecs) * 18L;
  59.     ticks   = (ticks > fudge) ? (ticks - fudge) : (0L);
  60.  
  61.     *phunds = (int) (ticks * 4L);
  62. }
  63.