TOBCD
t = TOBCD(dt->dt_ ## y) & 0xff; \
t = TOBCD(t);
chiptime[MK_SEC] = TOBCD(dt->dt_sec) << 24;
chiptime[MK_MIN] = TOBCD(dt->dt_min) << 24;
chiptime[MK_HOUR] = TOBCD(dt->dt_hour) << 24;
chiptime[MK_DOW] = TOBCD(dt->dt_wday) << 24;
chiptime[MK_DOM] = TOBCD(dt->dt_day) << 24;
chiptime[MK_MONTH] = TOBCD(dt->dt_mon) << 24;
chiptime[MK_YEAR] = TOBCD(dt->dt_year - MK_YEAR0) << 24;
*chipdata = TOBCD((u_int8_t)(data)); \
cmd->data[1] = TOBCD(dt.dt_sec);
cmd->data[2] = TOBCD(dt.dt_min);
cmd->data[3] = TOBCD(dt.dt_hour);
cmd->data[4] = TOBCD(dt.dt_wday);
cmd->data[5] = TOBCD(dt.dt_day);
cmd->data[6] = TOBCD(dt.dt_mon);
cmd->data[7] = TOBCD(dt.dt_year - 2000);
tod[0] = TOBCD(dt.dt_sec);
tod[1] = TOBCD(dt.dt_min);
tod[2] = TOBCD(dt.dt_hour);
tod[3] = TOBCD(dt.dt_wday + 1);
tod[4] = TOBCD(dt.dt_day);
tod[5] = TOBCD(dt.dt_mon);
tod[6] = TOBCD(dt.dt_year % 100);
time |= (uint64_t)TOBCD(dt.dt_sec) << 40;
time |= (uint64_t)TOBCD(dt.dt_min) << 48;
time |= (uint64_t)TOBCD(dt.dt_hour) << 56;
date |= (uint32_t)TOBCD(dt.dt_day);
date |= (uint32_t)TOBCD(dt.dt_mon) << 8;
date |= (uint32_t)TOBCD(dt.dt_year) << 16;
date |= (uint32_t)TOBCD(dt.dt_year / 100) << 24;
_reg_write_1(SH3_RYRCNT, TOBCD(dt->dt_year % 100));
_reg_write_2(SH4_RYRCNT, TOBCD(dt->dt_year % 100));
#define RTCSET(x, y) _reg_write_1(SH_(R ## x ## CNT), TOBCD(dt->dt_ ## y))
bus_space_write_1(iot, ioh, BQ4802_SEC, TOBCD(dt.dt_sec));
bus_space_write_1(iot, ioh, BQ4802_MIN, TOBCD(dt.dt_min));
bus_space_write_1(iot, ioh, BQ4802_HOUR, TOBCD(dt.dt_hour));
bus_space_write_1(iot, ioh, BQ4802_DOW, TOBCD(dt.dt_wday));
bus_space_write_1(iot, ioh, BQ4802_DAY, TOBCD(dt.dt_day));
bus_space_write_1(iot, ioh, BQ4802_MONTH, TOBCD(dt.dt_mon));
bus_space_write_1(iot, ioh, BQ4802_YEAR, TOBCD(dt.dt_year % 100));
bus_space_write_1(iot, ioh, BQ4802_CENTURY, TOBCD(dt.dt_year / 100));
acrtc_write_reg(sc, RTC_SEC, TOBCD(dt->dt_sec));
acrtc_write_reg(sc, RTC_MIN, TOBCD(dt->dt_min));
acrtc_write_reg(sc, RTC_HOU, TOBCD(dt->dt_hour));
acrtc_write_reg(sc, RTC_WEE, TOBCD(dt->dt_wday));
acrtc_write_reg(sc, RTC_DAY, TOBCD(dt->dt_day));
acrtc_write_reg(sc, RTC_MON, TOBCD(dt->dt_mon));
acrtc_write_reg(sc, RTC_YEA, TOBCD(dt->dt_year - 2000) | leap);
HWRITE4(sc, RTCSEC, TOBCD(dt.dt_sec));
HWRITE4(sc, RTCMIN, TOBCD(dt.dt_min));
HWRITE4(sc, RTCHOUR, TOBCD(dt.dt_hour));
HWRITE4(sc, RTCDAY, TOBCD(dt.dt_day));
HWRITE4(sc, RTCMON, TOBCD(dt.dt_mon));
HWRITE4(sc, RTCYEAR, TOBCD(dt.dt_year - 1900));
regs[0] = TOBCD(dt->dt_sec);
regs[1] = TOBCD(dt->dt_min);
regs[2] = TOBCD(dt->dt_hour);
regs[3] = TOBCD(dt->dt_day);
regs[4] = TOBCD(dt->dt_mon);
regs[5] = TOBCD(dt->dt_year - 2000);
regs[6] = TOBCD(dt->dt_wday);
regs[1] = TOBCD(dt->dt_sec);
regs[2] = TOBCD(dt->dt_min);
regs[3] = TOBCD(dt->dt_hour);
regs[4] = TOBCD(dt->dt_day);
regs[5] = TOBCD(dt->dt_mon);
regs[6] = TOBCD(dt->dt_year - 2000);
data[1] = TOBCD(dt.dt_sec); /* this will also enable the osc */
data[2] = TOBCD(dt.dt_min);
data[3] = TOBCD(dt.dt_hour); /* this will also set 24h mode */
data[4] = TOBCD(dt.dt_wday);
data[5] = TOBCD(dt.dt_day);
data[6] = TOBCD(dt.dt_mon);
data[7] = TOBCD(dt.dt_year - 2000);
regs[0] = TOBCD(dt->dt_sec);
regs[1] = TOBCD(dt->dt_min);
regs[2] = TOBCD(dt->dt_hour);
regs[3] = TOBCD(dt->dt_wday + 1);
regs[4] = TOBCD(dt->dt_day);
regs[5] = TOBCD(dt->dt_mon);
regs[6] = TOBCD(dt->dt_year - 2000);
regs[0] = TOBCD(dt->dt_sec);
regs[1] = TOBCD(dt->dt_min);
regs[2] = TOBCD(dt->dt_hour) | ISL1208_HR_MIL;
regs[3] = TOBCD(dt->dt_day);
regs[4] = TOBCD(dt->dt_mon);
regs[5] = TOBCD(dt->dt_year - 2000);
regs[6] = TOBCD(dt->dt_wday);
data[M41T8X_SEC] = TOBCD(dt.dt_sec);
data[M41T8X_MIN] = TOBCD(dt.dt_min);
data[M41T8X_HR] |= TOBCD(dt.dt_hour);
data[M41T8X_DOW] |= TOBCD(dt.dt_wday + 1);
data[M41T8X_DAY] = TOBCD(dt.dt_day);
data[M41T8X_MON] = TOBCD(dt.dt_mon);
data[M41T8X_YEAR] = TOBCD(dt.dt_year % 100);
regs[0] = TOBCD(dt->dt_sec);
regs[1] = TOBCD(dt->dt_min);
regs[2] = TOBCD(dt->dt_hour);
regs[3] = TOBCD(dt->dt_wday) | MCP794XX_DW_VBATEN;
regs[4] = TOBCD(dt->dt_day);
regs[5] = TOBCD(dt->dt_mon);
regs[6] = TOBCD(dt->dt_year - 2000);
regs[0] = TOBCD(dt->dt_sec);
regs[1] = TOBCD(dt->dt_min);
regs[2] = TOBCD(dt->dt_hour);
regs[3] = TOBCD(dt->dt_day);
regs[4] = TOBCD(dt->dt_wday);
regs[5] = TOBCD(dt->dt_mon);
regs[6] = TOBCD(dt->dt_year - 2000);
regs[0] = TOBCD(dt->dt_sec);
regs[1] = TOBCD(dt->dt_min);
regs[2] = TOBCD(dt->dt_hour);
regs[3] = TOBCD(dt->dt_day);
regs[4] = TOBCD(dt->dt_wday);
regs[5] = TOBCD(dt->dt_mon);
regs[6] = TOBCD(dt->dt_year - 2000);
regs[0] = TOBCD(dt->dt_sec);
regs[1] = TOBCD(dt->dt_min);
regs[2] = TOBCD(dt->dt_hour);
regs[3] = TOBCD(dt->dt_day);
regs[4] = TOBCD(dt->dt_wday);
regs[5] = TOBCD(dt->dt_mon);
regs[6] = TOBCD(dt->dt_year - 2000);
bcd[RICOHRTC_SECONDS] = TOBCD(dt->dt_sec);
bcd[RICOHRTC_MINUTES] = TOBCD(dt->dt_min);
bcd[RICOHRTC_HOURS] = TOBCD(dt->dt_hour);
bcd[RICOHRTC_DATE] = TOBCD(dt->dt_day);
bcd[RICOHRTC_DAY] = TOBCD(dt->dt_wday);
bcd[RICOHRTC_MONTH] = TOBCD(dt->dt_mon);
bcd[RICOHRTC_YEAR] = TOBCD(dt->dt_year - POSIX_BASE_YEAR);
bus_space_write_1(bt, bh, clkoff + MK48TXX_ISEC, TOBCD(dt.dt_sec));
bus_space_write_1(bt, bh, clkoff + MK48TXX_IMIN, TOBCD(dt.dt_min));
bus_space_write_1(bt, bh, clkoff + MK48TXX_IHOUR, TOBCD(dt.dt_hour));
bus_space_write_1(bt, bh, clkoff + MK48TXX_IWDAY, TOBCD(dt.dt_wday));
bus_space_write_1(bt, bh, clkoff + MK48TXX_IDAY, TOBCD(dt.dt_day));
bus_space_write_1(bt, bh, clkoff + MK48TXX_IMON, TOBCD(dt.dt_mon));
bus_space_write_1(bt, bh, clkoff + MK48TXX_IYEAR, TOBCD(year));
rtc.regs[MC_HOUR] = TOBCD(gnow->tm_hour);
rtc.regs[MC_DOW] = TOBCD(gnow->tm_wday + 1);
rtc.regs[MC_DOM] = TOBCD(gnow->tm_mday);
rtc.regs[MC_MONTH] = TOBCD(gnow->tm_mon + 1);
rtc.regs[MC_YEAR] = TOBCD((gnow->tm_year + 1900) % 100);
rtc.regs[NVRAM_CENTURY] = TOBCD((gnow->tm_year + 1900) / 100);
rtc.regs[MC_SEC] = TOBCD(gnow->tm_sec);
rtc.regs[MC_MIN] = TOBCD(gnow->tm_min);