home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / benchmar / cdrop / timer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1985-10-02  |  896 b   |  23 lines

  1. /* timer.c - use BIOS time-of-day interrupt */
  2. #include "stdio.h"
  3. #include "dos.h"
  4.  
  5. static long stime ;        /* time-of-day from last call*/
  6. #define TOD_INT  0x1A        /* BIOS time-of-day interrupt*/
  7.  
  8. int timer()            /* count elapsed time since */
  9.  {                /* last call (in ticks) */
  10.     struct XREG sreg , dreg ;
  11.     long etime , delta ;
  12.  
  13.     sreg.ax = 0 ;        /* operation = get time count */
  14.     int86(TOD_INT,&sreg,&dreg); /* do software interrupt */
  15.                 /* assemble 32-bit TOD value */
  16.     etime = ( ((long) dreg.cx) << 16 ) + dreg.dx ;
  17.     delta = etime - stime ;
  18.     if( (dreg.ax & 0xff) != 0)    /* new day since last call? */
  19.         delta = delta + 0x01800B0L ;/* yes-add 1 day in ticks*/
  20.     stime = etime ;        /* save TOD for next call */
  21.     return( (int) delta ) ;    /* return as an integer */
  22.  }
  23.