home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 5.ddi / CLIBSRC2.ZIP / CLOCK.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  1.9 KB  |  65 lines

  1. /*------------------------------------------------------------------------
  2.  * filename - clock.cas
  3.  *
  4.  * function(s)
  5.  *        clock     - ANSI standard; returns number of timer ticks
  6.  *                    that have elapsed since this program started.
  7.  *-----------------------------------------------------------------------*/
  8.  
  9. /*
  10.  *      C/C++ Run Time Library - Version 5.0
  11.  *
  12.  *      Copyright (c) 1987, 1992 by Borland International
  13.  *      All Rights Reserved.
  14.  *
  15.  */
  16.  
  17.  
  18. #pragma inline
  19. #include <asmrules.h>
  20. #include <dos.h>
  21. #include <time.h>
  22. #include <RtlData.h>
  23.  
  24. #if !defined( _RTLDLL )
  25. extern unsigned long _StartTime;        /* beginning of program execution  */
  26.                                         /*   initialized in C0.ASM         */
  27. #endif
  28.  
  29. static unsigned char DayFlip;           /* keeps track                     */
  30.  
  31. #pragma inline
  32.  
  33. #define I asm
  34.  
  35. clock_t clock(void)
  36. {
  37.    clock_t NowTime;
  38.  
  39. I   xor    ah,ah
  40. I   int    1ah                          /* call BIOS for timer ticks       */
  41.  
  42. I   add    BY0(DayFlip), al             /* record whether day has changed  */
  43.  
  44. I   mov    W0 (NowTime), DX             /* save return values              */
  45. I   mov    W1 (NowTime), CX             /*  which is current time in ticks */
  46.  
  47.  
  48.    if (_AL != 0)                        /* did day change just now?        */
  49.    {
  50.       /* Set the BIOS midnight flag to 1 again, then call DOS get-date
  51.        * function to force DOS to update its internal date counter.
  52.        */
  53.       *((unsigned char far *)MK_FP(0x40,0x70)) = 1;
  54.       _AH = 0x2a;                       /* get DOS date to force DOS       */
  55.       geninterrupt(0x21);               /*  to recognize date change       */
  56.    }
  57.  
  58.    if(DayFlip)
  59.       NowTime += 0x1800b0L;             /* number of clock ticks in day    */
  60.  
  61.    return(NowTime - _RTLInstanceData(_StartTime));
  62.                                         /* return count of ticks           */
  63. }
  64.  
  65.