home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 5.ddi / C / UTGETCLK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-08-05  |  2.8 KB  |  85 lines

  1. /**
  2. *
  3. * Name        utgetclk -- Read BIOS clock tick count
  4. *
  5. * Synopsis    rollover = utgetclk(pcount);
  6. *
  7. *        int rollover      1 if midnight rollover occurred
  8. *                  on the most recent clock tick;
  9. *                  0 if not.
  10. *        long *pcount      The count of timer ticks since
  11. *                  midnight.
  12. *
  13. * Description    This function returns the BIOS's four-byte count of
  14. *        clock ticks since midnight.  On standard IBM PCs, timer
  15. *        ticks occur 1193180/65536 (about 18.2) times per second.
  16. *
  17. *        If the value of the function is 1, then the midnight
  18. *        rollover has occurred but has not yet been cleared.
  19. *        This function does NOT clear the rollover flag, thus
  20. *        allowing another program (presumably DOS) to respond to
  21. *        the rollover and to clear it.
  22. *
  23. *        Under conditions with an astronomically rare
  24. *        probability, it is possible that UTGETCLK may cause an
  25. *        interrupting routine to read the midnight count without
  26. *        properly receiving the rollover flag.
  27. *
  28. * Returns    rollover      1 if midnight rollover occurred
  29. *                  on the most recent clock tick;
  30. *                  0 if not.
  31. *
  32. * Version    3.0  (C)Copyright Blaise Computing Inc.  1986
  33. *
  34. **/
  35.  
  36. #include <butility.h>
  37.  
  38. int utgetclk(pcount)
  39. long *pcount;
  40. {
  41.  
  42.     /* BIOS function 0x1a (Get/Set Time of Day) maintains a flag      */
  43.     /* which is set once per day when the count of clock ticks passes */
  44.     /* 0x1800b0.  This flag is CLEARED when BIOS function 0x1a          */
  45.     /* reports the daily rollover.  Therefore the following code      */
  46.     /* restores the flag each time function 0x1a reports a rollover.  */
  47.  
  48.                       /* Address of BIOS's timer      */
  49.                       /* overflow flag.           */
  50.     static ADS ovfl_flag_ads = {0x0070,0x0040};
  51.  
  52.     char ovfl_value = 1;          /* Local copy of overflow flag  */
  53.     ADS  value_ads;              /* Address of ovfl_value          */
  54.  
  55.     int  were_on;              /* Whether interrupts were      */
  56.                       /* enabled before we          */
  57.                       /* temporarily disable them.    */
  58.  
  59.     int  ax,bx,cx,dx,flags;          /* General registers.          */
  60.     int  rollover;              /* Return value of function.    */
  61.  
  62.     utabsptr(&ovfl_value,&value_ads);
  63.  
  64.     were_on = utintoff();          /* Turn interrupts off.          */
  65.  
  66.     ax = 0;
  67.     bios(0x1a,&ax,&bx,&cx,&dx,&flags);
  68.  
  69.     /* Note that BIOS function 0x1a clears the rollover flag then     */
  70.     /* temporarily re-enables interrupts.  Any process that          */
  71.     /* interrupts right then and calls function 0x1a will get a       */
  72.     /* 0 rollover flag since we haven't restored it yet.              */
  73.  
  74.     if (rollover = (utlobyte(ax) != 0))
  75.                       /* Restore overflow flag.       */
  76.     utslmove(&value_ads,&ovfl_flag_ads,1);
  77.  
  78.     if (were_on)
  79.     utinton();              /* Turn interrupts back on.     */
  80.  
  81.     *pcount = utwdlong(cx,dx);
  82.  
  83.     return rollover;
  84. }
  85.