home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name utgetclk -- Read BIOS clock tick count
- *
- * Synopsis rollover = utgetclk(pcount);
- *
- * int rollover 1 if midnight rollover occurred
- * on the most recent clock tick;
- * 0 if not.
- * long *pcount The count of timer ticks since
- * midnight.
- *
- * Description This function returns the BIOS's four-byte count of
- * clock ticks since midnight. On standard IBM PCs, timer
- * ticks occur 1193180/65536 (about 18.2) times per second.
- *
- * If the value of the function is 1, then the midnight
- * rollover has occurred but has not yet been cleared.
- * This function does NOT clear the rollover flag, thus
- * allowing another program (presumably DOS) to respond to
- * the rollover and to clear it.
- *
- * Under conditions with an astronomically rare
- * probability, it is possible that UTGETCLK may cause an
- * interrupting routine to read the midnight count without
- * properly receiving the rollover flag.
- *
- * Returns rollover 1 if midnight rollover occurred
- * on the most recent clock tick;
- * 0 if not.
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1986
- *
- **/
-
- #include <butility.h>
-
- int utgetclk(pcount)
- long *pcount;
- {
-
- /* BIOS function 0x1a (Get/Set Time of Day) maintains a flag */
- /* which is set once per day when the count of clock ticks passes */
- /* 0x1800b0. This flag is CLEARED when BIOS function 0x1a */
- /* reports the daily rollover. Therefore the following code */
- /* restores the flag each time function 0x1a reports a rollover. */
-
- /* Address of BIOS's timer */
- /* overflow flag. */
- static ADS ovfl_flag_ads = {0x0070,0x0040};
-
- char ovfl_value = 1; /* Local copy of overflow flag */
- ADS value_ads; /* Address of ovfl_value */
-
- int were_on; /* Whether interrupts were */
- /* enabled before we */
- /* temporarily disable them. */
-
- int ax,bx,cx,dx,flags; /* General registers. */
- int rollover; /* Return value of function. */
-
- utabsptr(&ovfl_value,&value_ads);
-
- were_on = utintoff(); /* Turn interrupts off. */
-
- ax = 0;
- bios(0x1a,&ax,&bx,&cx,&dx,&flags);
-
- /* Note that BIOS function 0x1a clears the rollover flag then */
- /* temporarily re-enables interrupts. Any process that */
- /* interrupts right then and calls function 0x1a will get a */
- /* 0 rollover flag since we haven't restored it yet. */
-
- if (rollover = (utlobyte(ax) != 0))
- /* Restore overflow flag. */
- utslmove(&value_ads,&ovfl_flag_ads,1);
-
- if (were_on)
- utinton(); /* Turn interrupts back on. */
-
- *pcount = utwdlong(cx,dx);
-
- return rollover;
- }