home *** CD-ROM | disk | FTP | other *** search
- /*
- * Program to read the time from the DTK clock/calendar board.
- * (C) Copyright 1989 Richard B. Wales. All Rights Reserved.
- */
-
- #include <stdio.h>
- #include "clkdefs.h"
-
-
- static char copyright[] =
- "READCLK -- Read DTK clock/calendar board, version 1.10\r\n\
- (C) Copyright 1989 Richard B. Wales";
-
-
- void main (int argc, char **argv)
- { struct clockval *cv;
- struct date *da;
- struct time *ti;
- int freeze_offset;
-
- /*
- * Identify the program.
- */
- printf ("%s\n", copyright);
-
- /*
- * If there is an argument, convert it into a number.
- * This number of seconds will be added to the value
- * read from the clock board before setting the system time.
- * This overcomes a hardware misfeature that causes the
- * board to "freeze" at power-up. The number of seconds
- * should be set equal to however long your system takes
- * to get to the READCLK command in AUTOEXEC.BAT after a
- * power-up.
- */
- if (argc > 1)
- freeze_offset = atoi (argv[1]);
- else freeze_offset = 0;
-
- /*
- * Read the clock/calendar board.
- */
- cv = read_clock ();
- if (cv == NULL_CLOCK)
- { printf ("Error reading clock\n");
- exit (1);
- }
-
- /*
- * Add the "frozen boot interval" correction.
- * If the byte at 0040:0072 is 034H, however,
- * this is a "warm boot"; skip this correction.
- */
- if (freeze_offset > 0
- && *((unsigned char far *)0x00472L) != 0x34)
- { advance_time (cv, freeze_offset);
- if (write_clock (cv) == NULL_CLOCK)
- { printf ("%s %s\n",
- "Couldn't rewrite clock with",
- "frozen boot offset");
- exit (1);
- }
- cv = read_clock ();
- if (cv == NULL_CLOCK)
- { printf ("Error re-reading clock\n");
- exit (1);
- } }
-
- /*
- * Set the system date and time.
- */
- clock_to_time (cv, &da, &ti);
- if (da == NULL_DATE || ti == NULL_TIME)
- { printf ("Garbled date/time from clock\n");
- exit (1);
- }
- settime (ti); setdate (da);
-
- /*
- * Announce the new date and time.
- */
- gettime (ti); getdate (da);
- printf ("New date/time is %02d/%02d/%02d %02d:%02d:%02d\n",
- da->da_mon, da->da_day, da->da_year % 100,
- ti->ti_hour, ti->ti_min, ti->ti_sec);
-
- /*
- * That's all.
- */
- exit (0);
- }