]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/doscmd/int1a.c
This commit was generated by cvs2svn to compensate for changes in r77422,
[FreeBSD/FreeBSD.git] / usr.bin / doscmd / int1a.c
1 /*
2  * Copyright (c) 1992, 1993, 1996
3  *      Berkeley Software Design, Inc.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by Berkeley Software
16  *      Design, Inc.
17  *
18  * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  *      BSDI int1a.c,v 2.2 1996/04/08 19:32:49 bostic Exp
31  *
32  * $FreeBSD$
33  */
34
35 #include "doscmd.h"
36
37 static inline int
38 to_BCD (int n)
39 {
40     n &= 0xFF;
41     return n%10 + ((n/10)<<4);
42 }
43
44 void
45 int1a(regcontext_t *REGS)
46 {
47     struct      timeval tod;
48     struct      timezone zone;
49     struct      tm *tm;
50     time_t      tv_sec;
51     long        value;
52     static long midnight = 0;
53
54     R_FLAGS &= ~PSL_C;
55
56     switch (R_AH) {
57     case 0x00:
58         gettimeofday(&tod, &zone);
59
60         if (midnight == 0) {
61             tv_sec = boot_time.tv_sec;
62             tm = localtime(&tv_sec);
63             midnight = boot_time.tv_sec - (((tm->tm_hour * 60)
64                                             + tm->tm_min) * 60
65                                            + tm->tm_sec);
66         }
67
68         R_AL = (tod.tv_sec - midnight) / (24 * 60 * 60);
69
70         if (R_AL) {
71             tv_sec = boot_time.tv_sec;
72             tm = localtime(&tv_sec);
73             midnight = boot_time.tv_sec - (((tm->tm_hour * 60)
74                                             + tm->tm_min) * 60
75                                            + tm->tm_sec);
76         }
77
78         tod.tv_sec -= midnight;
79         tod.tv_usec -= boot_time.tv_usec;
80
81         value = (tod.tv_sec * 182 + tod.tv_usec / (1000000L/182)) / 10;
82         R_CX = value >> 16;
83         R_DX = value & 0xffff;
84         break;
85
86     case 0x01:                          /* set current clock count */
87         tv_sec = boot_time.tv_sec;
88         tm = localtime(&tv_sec);
89         midnight = boot_time.tv_sec - (((tm->tm_hour * 60)
90             + tm->tm_min) * 60 + tm->tm_sec);
91         break;
92
93     case 0x02:
94         gettimeofday(&tod, &zone);
95         tv_sec = tod.tv_sec;
96         tm = localtime(&tv_sec);
97         R_CH = to_BCD(tm->tm_hour);
98         R_CL = to_BCD(tm->tm_min);
99         R_DH = to_BCD(tm->tm_sec);
100         break;
101
102     case 0x04:
103         gettimeofday(&tod, &zone);
104         tv_sec = tod.tv_sec;
105         tm = localtime(&tv_sec);
106         R_CH = to_BCD((tm->tm_year + 1900) / 100);
107         R_CL = to_BCD((tm->tm_year + 1900) % 100);
108         R_DH = to_BCD(tm->tm_mon + 1);
109         R_DL = to_BCD(tm->tm_mday);
110         break;
111
112     default:
113         unknown_int2(0x1a, R_AH, REGS);
114         break;
115     }
116 }