home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / util / super_c / calib.c < prev    next >
Encoding:
Text File  |  1980-01-01  |  1.2 KB  |  32 lines

  1. /*                      Processor Speed Calibration Function
  2.  */
  3.  
  4. /*      calib()
  5.  
  6.         Function: Return the speed of this processor, as a percent of
  7.         the speed of a standard IBM-PC.
  8.  
  9.         Algorithm: Iterate for one system timer tic (as found in low
  10.         memory location 46C). Multiply the result by 100 (conver to %)
  11.         add in 50 (so the next divide will round rather than truncate),
  12.         and divide by the number of iterations on a normal PC. Do all
  13.         the calculations in long format to avoid overflow.
  14. */
  15.  
  16. calib()
  17.  
  18. {
  19.         /* Pointer to system timer in low memory: */
  20.         unsigned far *timerLow = {(unsigned far *) 0x46C};
  21.         unsigned lastTime;      /* Last value read from *timerLow. */
  22.         unsigned iter;          /* Iteration count. */
  23.  
  24.         /* Wait until timer has just ticked. */
  25.         for (lastTime = *timerLow; lastTime == *timerLow;);
  26.         /* Count iterations until the next tick. */
  27.         for (iter = 0, lastTime = *timerLow; lastTime == *timerLow; iter++);
  28.         /* Calculate and return the percent of a standard IBM-PC. */
  29.         return ((100L*((long) iter) + 50L)/1878L);
  30. }
  31.  
  32.