void cmostime(struct rtcdate *r)
{
struct rtcdate t1, t2;
- int sb, bcd;
+ int sb, bcd, tf;
sb = cmosread(CMOS_STATB);
bcd = (sb & CMOS_BINARY_BIT) == 0;
+ tf = (sb & CMOS_24H_BIT) != 0;
// make sure CMOS doesn't modify time while we read it
for(;;){
break;
}
- // convert
+ // backup raw values since BCD conversion removes PM bit from hour
+ t2 = t1;
+
+ // convert t1 from BCD
if(bcd){
#define CONV(x) (t1.x = ((t1.x >> 4) * 10) + (t1.x & 0xf))
CONV(second);
#undef CONV
}
+ // convert 12 hour format to 24 hour format
+ if(!tf){
+ if(t2.hour & CMOS_PM_BIT){
+ t1.hour = (t1.hour + 12) % 24;
+ }
+ }
+
*r = t1;
r->year += 2000;
}