1141753aa92aac7d2541c47000934e465d32ba34
[reactos.git] / reactos / boot / freeldr / freeldr / arch / i386 / pcrtc.c
1 /* $Id$
2 *
3 * FreeLoader
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include <freeldr.h>
21
22 #define BCD_INT(bcd) (((bcd & 0xf0) >> 4) * 10 + (bcd &0x0f))
23
24 TIMEINFO*
25 PcGetTime(VOID)
26 {
27 static TIMEINFO TimeInfo;
28 REGS Regs;
29
30 /* Some BIOSes, such as the 1998/07/25 system ROM
31 * in the Compaq Deskpro EP/SB, leave CF unchanged
32 * if successful, so CF should be cleared before
33 * calling this function. */
34 __writeeflags(__readeflags() & ~EFLAGS_CF);
35
36 /* Int 1Ah AH=04h
37 * TIME - GET REAL-TIME CLOCK DATE (AT,XT286,PS)
38 *
39 * AH = 04h
40 * CF clear to avoid bug
41 * Return:
42 * CF clear if successful
43 * CH = century (BCD)
44 * CL = year (BCD)
45 * DH = month (BCD)
46 * DL = day (BCD)
47 * CF set on error
48 */
49 Regs.b.ah = 0x04;
50 Int386(0x1A, &Regs, &Regs);
51
52 TimeInfo.Year = 100 * BCD_INT(Regs.b.ch) + BCD_INT(Regs.b.cl);
53 TimeInfo.Month = BCD_INT(Regs.b.dh);
54 TimeInfo.Day = BCD_INT(Regs.b.dl);
55
56 /* Some BIOSes leave CF unchanged if successful,
57 * so CF should be cleared before calling this function. */
58 __writeeflags(__readeflags() & ~EFLAGS_CF);
59
60 /* Int 1Ah AH=02h
61 * TIME - GET REAL-TIME CLOCK TIME (AT,XT286,PS)
62 *
63 * AH = 02h
64 * CF clear to avoid bug
65 * Return:
66 * CF clear if successful
67 * CH = hour (BCD)
68 * CL = minutes (BCD)
69 * DH = seconds (BCD)
70 * DL = daylight savings flag (00h standard time, 01h daylight time)
71 * CF set on error (i.e. clock not running or in middle of update)
72 */
73 Regs.b.ah = 0x02;
74 Int386(0x1A, &Regs, &Regs);
75
76 TimeInfo.Hour = BCD_INT(Regs.b.ch);
77 TimeInfo.Minute = BCD_INT(Regs.b.cl);
78 TimeInfo.Second = BCD_INT(Regs.b.dh);
79
80 return &TimeInfo;
81 }
82
83 /* EOF */