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