merge ROS Shell without integrated explorer part into trunk
[reactos.git] / reactos / boot / freeldr / freeldr / arch / i386 / xboxrtc.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
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include "freeldr.h"
21 #include "machine.h"
22 #include "machxbox.h"
23 #include "portio.h"
24
25 #define RTC_REGISTER_A 0x0A
26 #define RTC_REG_A_UIP 0x80 /* Update In Progress bit */
27
28 #define BCD_INT(bcd) (((bcd & 0xf0) >> 4) * 10 + (bcd &0x0f))
29
30 static UCHAR
31 HalpQueryCMOS(UCHAR Reg)
32 {
33 UCHAR Val;
34 Reg |= 0x80;
35
36 WRITE_PORT_UCHAR((PUCHAR)0x70, Reg);
37 Val = READ_PORT_UCHAR((PUCHAR)0x71);
38 WRITE_PORT_UCHAR((PUCHAR)0x70, 0);
39
40 return(Val);
41 }
42
43 VOID
44 XboxRTCGetCurrentDateTime(PULONG Year, PULONG Month, PULONG Day, PULONG Hour, PULONG Minute, PULONG Second)
45 {
46 while (HalpQueryCMOS (RTC_REGISTER_A) & RTC_REG_A_UIP)
47 {
48 ;
49 }
50
51 if (NULL != Second)
52 {
53 *Second = BCD_INT(HalpQueryCMOS(0));
54 }
55 if (NULL != Minute)
56 {
57 *Minute = BCD_INT(HalpQueryCMOS(2));
58 }
59 if (NULL != Hour)
60 {
61 *Hour = BCD_INT(HalpQueryCMOS(4));
62 }
63 if (NULL != Day)
64 {
65 *Day = BCD_INT(HalpQueryCMOS(7));
66 }
67 if (NULL != Month)
68 {
69 *Month = BCD_INT(HalpQueryCMOS(8));
70 }
71 if (NULL != Year)
72 {
73 *Year = BCD_INT(HalpQueryCMOS(9));
74 if (*Year > 80)
75 {
76 *Year += 1900;
77 }
78 else
79 {
80 *Year += 2000;
81 }
82 }
83 }
84
85 /* EOF */