[freeldr] Move custom.c, drivemap.c/h, miscboot.c/h to i386 directories
[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 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 RTC_REGISTER_A 0x0A
23 #define RTC_REG_A_UIP 0x80 /* Update In Progress bit */
24
25 #define BCD_INT(bcd) (((bcd & 0xf0) >> 4) * 10 + (bcd &0x0f))
26
27 static UCHAR
28 HalpQueryCMOS(UCHAR Reg)
29 {
30 UCHAR Val;
31 Reg |= 0x80;
32
33 WRITE_PORT_UCHAR((PUCHAR)0x70, Reg);
34 Val = READ_PORT_UCHAR((PUCHAR)0x71);
35 WRITE_PORT_UCHAR((PUCHAR)0x70, 0);
36
37 return(Val);
38 }
39
40 TIMEINFO*
41 XboxGetTime(VOID)
42 {
43 static TIMEINFO TimeInfo;
44
45 while (HalpQueryCMOS (RTC_REGISTER_A) & RTC_REG_A_UIP)
46 {
47 ;
48 }
49
50 TimeInfo.Second = BCD_INT(HalpQueryCMOS(0));
51 TimeInfo.Minute = BCD_INT(HalpQueryCMOS(2));
52 TimeInfo.Hour = BCD_INT(HalpQueryCMOS(4));
53 TimeInfo.Day = BCD_INT(HalpQueryCMOS(7));
54 TimeInfo.Month = BCD_INT(HalpQueryCMOS(8));
55 TimeInfo.Year = BCD_INT(HalpQueryCMOS(9));
56 if (TimeInfo.Year > 80)
57 TimeInfo.Year += 1900;
58 else
59 TimeInfo.Year += 2000;
60
61 return &TimeInfo;
62 }
63
64 /* EOF */