Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / usr.bin / doscmd / timer.c
1 /*
2  * No copyright?!
3  *
4  * $FreeBSD: src/usr.bin/doscmd/timer.c,v 1.2.2.2 2002/04/25 11:04:51 tg Exp $
5  * $DragonFly: src/usr.bin/doscmd/timer.c,v 1.2 2003/06/17 04:29:26 dillon Exp $
6  */
7 #include "doscmd.h"
8
9 static void
10 int08(regcontext_t *REGS __unused)
11 {
12     *(u_long *)&BIOSDATA[0x6c] += 1;    /* ticks since midnight */
13     while (*(u_long *)&BIOSDATA[0x6c] >= 24*60*6*182) {
14         *(u_long *)&BIOSDATA[0x6c] -= 24*60*6*182;
15         BIOSDATA[0x70]++;               /* # times past mn */
16     }
17     /* What is the real BIOS' sequence? */
18     send_eoi();
19     softint(0x1c);
20 }
21
22 static void
23 int1c(regcontext_t *REGS __unused)
24 {
25 }
26
27 unsigned char timer;
28
29 static u_char
30 inb_timer(int port __unused)
31 {
32     return (--timer);
33 }
34
35 void
36 timer_init(void)
37 {
38     u_long              vec;
39     struct itimerval    itv;
40     struct timeval      tv;
41     time_t              tv_sec;
42     struct timezone     tz;
43     struct tm           tm;
44
45     vec = insert_hardint_trampoline();
46     ivec[0x08] = vec;
47     register_callback(vec, int08, "int 08");
48     
49     vec = insert_softint_trampoline();
50     ivec[0x1c] = vec;
51     register_callback(vec, int1c, "int 1c");
52
53     define_input_port_handler(0x42, inb_timer);
54     define_input_port_handler(0x40, inb_timer);
55     
56     /* Initialize time counter BIOS variable. */
57     gettimeofday(&tv, &tz);
58     tv_sec = tv.tv_sec;
59     tm = *localtime(&tv_sec);
60     *(u_long *)&BIOSDATA[0x6c] =
61         (((tm.tm_hour * 60 + tm.tm_min) * 60) + tm.tm_sec) * 182 / 10;
62
63     itv.it_interval.tv_sec = 0;
64     itv.it_interval.tv_usec = 54925;    /* 1193182/65536 times per second */
65     itv.it_value.tv_sec = 0;
66     itv.it_value.tv_usec = 54925;       /* 1193182/65536 times per second */
67     if (! timer_disable)
68         setitimer(ITIMER_REAL, &itv, 0);
69 }