From: Peter H. Froehlich Date: Thu, 5 Nov 2015 22:52:05 +0000 (-0500) Subject: Convert 12-hour clock to 24-hour time. X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=0cabc5d959e5c9cb556805430a8e31dee4a46930;p=xv6-public Convert 12-hour clock to 24-hour time. --- diff --git a/cmos.c b/cmos.c index 68fcb90..4b295b0 100644 --- a/cmos.c +++ b/cmos.c @@ -40,11 +40,12 @@ static void fill_rtcdate(struct rtcdate *r) 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(;;){ @@ -56,7 +57,10 @@ void cmostime(struct rtcdate *r) 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); @@ -68,6 +72,13 @@ void cmostime(struct rtcdate *r) #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; } diff --git a/cmos.h b/cmos.h index 378f152..43cd068 100644 --- a/cmos.h +++ b/cmos.h @@ -14,6 +14,7 @@ #define CMOS_SECS 0x00 #define CMOS_MINS 0x02 #define CMOS_HOURS 0x04 + #define CMOS_PM_BIT (1 << 7) // RTC PM #define CMOS_DAY 0x07 #define CMOS_MONTH 0x08 #define CMOS_YEAR 0x09