Revision abd0c6bd hw/mc146818rtc.c
b/hw/mc146818rtc.c | ||
---|---|---|
259 | 259 |
} |
260 | 260 |
} |
261 | 261 |
|
262 |
static inline int to_bcd(RTCState *s, int a) |
|
262 |
static inline int rtc_to_bcd(RTCState *s, int a)
|
|
263 | 263 |
{ |
264 | 264 |
if (s->cmos_data[RTC_REG_B] & REG_B_DM) { |
265 | 265 |
return a; |
... | ... | |
268 | 268 |
} |
269 | 269 |
} |
270 | 270 |
|
271 |
static inline int from_bcd(RTCState *s, int a) |
|
271 |
static inline int rtc_from_bcd(RTCState *s, int a)
|
|
272 | 272 |
{ |
273 | 273 |
if (s->cmos_data[RTC_REG_B] & REG_B_DM) { |
274 | 274 |
return a; |
... | ... | |
281 | 281 |
{ |
282 | 282 |
struct tm *tm = &s->current_tm; |
283 | 283 |
|
284 |
tm->tm_sec = from_bcd(s, s->cmos_data[RTC_SECONDS]); |
|
285 |
tm->tm_min = from_bcd(s, s->cmos_data[RTC_MINUTES]); |
|
286 |
tm->tm_hour = from_bcd(s, s->cmos_data[RTC_HOURS] & 0x7f); |
|
284 |
tm->tm_sec = rtc_from_bcd(s, s->cmos_data[RTC_SECONDS]);
|
|
285 |
tm->tm_min = rtc_from_bcd(s, s->cmos_data[RTC_MINUTES]);
|
|
286 |
tm->tm_hour = rtc_from_bcd(s, s->cmos_data[RTC_HOURS] & 0x7f);
|
|
287 | 287 |
if (!(s->cmos_data[RTC_REG_B] & 0x02) && |
288 | 288 |
(s->cmos_data[RTC_HOURS] & 0x80)) { |
289 | 289 |
tm->tm_hour += 12; |
290 | 290 |
} |
291 |
tm->tm_wday = from_bcd(s, s->cmos_data[RTC_DAY_OF_WEEK]) - 1; |
|
292 |
tm->tm_mday = from_bcd(s, s->cmos_data[RTC_DAY_OF_MONTH]); |
|
293 |
tm->tm_mon = from_bcd(s, s->cmos_data[RTC_MONTH]) - 1; |
|
294 |
tm->tm_year = from_bcd(s, s->cmos_data[RTC_YEAR]) + s->base_year - 1900; |
|
291 |
tm->tm_wday = rtc_from_bcd(s, s->cmos_data[RTC_DAY_OF_WEEK]) - 1;
|
|
292 |
tm->tm_mday = rtc_from_bcd(s, s->cmos_data[RTC_DAY_OF_MONTH]);
|
|
293 |
tm->tm_mon = rtc_from_bcd(s, s->cmos_data[RTC_MONTH]) - 1;
|
|
294 |
tm->tm_year = rtc_from_bcd(s, s->cmos_data[RTC_YEAR]) + s->base_year - 1900;
|
|
295 | 295 |
} |
296 | 296 |
|
297 | 297 |
static void rtc_copy_date(RTCState *s) |
... | ... | |
299 | 299 |
const struct tm *tm = &s->current_tm; |
300 | 300 |
int year; |
301 | 301 |
|
302 |
s->cmos_data[RTC_SECONDS] = to_bcd(s, tm->tm_sec); |
|
303 |
s->cmos_data[RTC_MINUTES] = to_bcd(s, tm->tm_min); |
|
302 |
s->cmos_data[RTC_SECONDS] = rtc_to_bcd(s, tm->tm_sec);
|
|
303 |
s->cmos_data[RTC_MINUTES] = rtc_to_bcd(s, tm->tm_min);
|
|
304 | 304 |
if (s->cmos_data[RTC_REG_B] & 0x02) { |
305 | 305 |
/* 24 hour format */ |
306 |
s->cmos_data[RTC_HOURS] = to_bcd(s, tm->tm_hour); |
|
306 |
s->cmos_data[RTC_HOURS] = rtc_to_bcd(s, tm->tm_hour);
|
|
307 | 307 |
} else { |
308 | 308 |
/* 12 hour format */ |
309 |
s->cmos_data[RTC_HOURS] = to_bcd(s, tm->tm_hour % 12); |
|
309 |
s->cmos_data[RTC_HOURS] = rtc_to_bcd(s, tm->tm_hour % 12);
|
|
310 | 310 |
if (tm->tm_hour >= 12) |
311 | 311 |
s->cmos_data[RTC_HOURS] |= 0x80; |
312 | 312 |
} |
313 |
s->cmos_data[RTC_DAY_OF_WEEK] = to_bcd(s, tm->tm_wday + 1); |
|
314 |
s->cmos_data[RTC_DAY_OF_MONTH] = to_bcd(s, tm->tm_mday); |
|
315 |
s->cmos_data[RTC_MONTH] = to_bcd(s, tm->tm_mon + 1); |
|
313 |
s->cmos_data[RTC_DAY_OF_WEEK] = rtc_to_bcd(s, tm->tm_wday + 1);
|
|
314 |
s->cmos_data[RTC_DAY_OF_MONTH] = rtc_to_bcd(s, tm->tm_mday);
|
|
315 |
s->cmos_data[RTC_MONTH] = rtc_to_bcd(s, tm->tm_mon + 1);
|
|
316 | 316 |
year = (tm->tm_year - s->base_year) % 100; |
317 | 317 |
if (year < 0) |
318 | 318 |
year += 100; |
319 |
s->cmos_data[RTC_YEAR] = to_bcd(s, year); |
|
319 |
s->cmos_data[RTC_YEAR] = rtc_to_bcd(s, year);
|
|
320 | 320 |
} |
321 | 321 |
|
322 | 322 |
/* month is between 0 and 11. */ |
... | ... | |
497 | 497 |
qemu_get_timedate(&tm, 0); |
498 | 498 |
rtc_set_date(s, &tm); |
499 | 499 |
|
500 |
val = to_bcd(s, (tm.tm_year / 100) + 19); |
|
500 |
val = rtc_to_bcd(s, (tm.tm_year / 100) + 19);
|
|
501 | 501 |
rtc_set_memory(s, REG_IBM_CENTURY_BYTE, val); |
502 | 502 |
rtc_set_memory(s, REG_IBM_PS2_CENTURY_BYTE, val); |
503 | 503 |
} |
Also available in: Unified diff