void upd1990a_rtc_device::rtc_clock_updated(int year, int month, int day, int day_of_week, int hour, int minute, int second) { m_time_counter[0] = convert_to_bcd(second); m_time_counter[1] = convert_to_bcd(minute); m_time_counter[2] = convert_to_bcd(hour); m_time_counter[3] = convert_to_bcd(day); m_time_counter[4] = (month << 4) | day_of_week; }
inline void upd1990a_device::advance_seconds() { static const int days_per_month[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int seconds = bcd_to_integer(m_time_counter[0]); int minutes = bcd_to_integer(m_time_counter[1]); int hours = bcd_to_integer(m_time_counter[2]); int days = bcd_to_integer(m_time_counter[3]); int day_of_week = m_time_counter[4] & 0x0f; int month = (m_time_counter[4] & 0xf0) >> 4; seconds++; if (seconds > 59) { seconds = 0; minutes++; } if (minutes > 59) { minutes = 0; hours++; } if (hours > 23) { hours = 0; days++; day_of_week++; } if (day_of_week > 6) { day_of_week++; } if (days > days_per_month[month - 1]) { days = 1; month++; } if (month > 12) { month = 1; } m_time_counter[0] = convert_to_bcd(seconds); m_time_counter[1] = convert_to_bcd(minutes); m_time_counter[2] = convert_to_bcd(hours); m_time_counter[3] = convert_to_bcd(days); m_time_counter[4] = (month << 4) | day_of_week; }
void upd1990a_device::device_reset() { system_time curtime, *systime = &curtime; machine().current_datetime(curtime); // HACK: load time counter from system time m_time_counter[0] = convert_to_bcd(systime->local_time.second); m_time_counter[1] = convert_to_bcd(systime->local_time.minute); m_time_counter[2] = convert_to_bcd(systime->local_time.hour); m_time_counter[3] = convert_to_bcd(systime->local_time.mday); m_time_counter[4] = systime->local_time.weekday; m_time_counter[4] |= (systime->local_time.month + 1) << 4; }
void gba_s3511_device::update_time(int len) { system_time curtime; m_machine.current_datetime(curtime); if (len == 7) { m_data[0] = convert_to_bcd(curtime.local_time.year); m_data[1] = convert_to_bcd(curtime.local_time.month + 1); m_data[2] = convert_to_bcd(curtime.local_time.mday); m_data[3] = convert_to_bcd(curtime.local_time.weekday); m_data[4] = convert_to_bcd(curtime.local_time.hour); m_data[5] = convert_to_bcd(curtime.local_time.minute); m_data[6] = convert_to_bcd(curtime.local_time.second); } else if (len == 3) { m_data[0] = convert_to_bcd(curtime.local_time.hour); m_data[1] = convert_to_bcd(curtime.local_time.minute); m_data[2] = convert_to_bcd(curtime.local_time.second); } }
static int final_form(int isbcd, int number) { return isbcd ? convert_to_bcd(number) : number; }
WRITE8_DEVICE_HANDLER_TRAMPOLINE(ds1302, ds1302_clk_w) { if (data != m_last_clk) { if (data) //Rising, shift in command { m_icount++; if(m_icount == 8) //Command start { system_time systime; m_machine.base_datetime(systime); switch(m_shift_in) { case 0x81: //Sec m_shift_out = convert_to_bcd(systime.local_time.second); break; case 0x83: //Min m_shift_out = convert_to_bcd(systime.local_time.minute); break; case 0x85: //Hour m_shift_out = convert_to_bcd(systime.local_time.hour); break; case 0x87: //Day m_shift_out = convert_to_bcd(systime.local_time.mday); break; case 0x89: //Month m_shift_out = convert_to_bcd(systime.local_time.month + 1); break; case 0x8b: //weekday m_shift_out = convert_to_bcd(systime.local_time.weekday); break; case 0x8d: //Year m_shift_out = convert_to_bcd(systime.local_time.year % 100); break; default: m_shift_out = 0x0; } if(m_shift_in > 0xc0) { m_shift_out = m_sram[(m_shift_in >> 1) & 0x1f]; } m_last_cmd = m_shift_in & 0xff; m_icount++; } if(m_icount == 17 && !(m_last_cmd & 1)) { UINT8 val = (m_shift_in >> 9) & 0xff; switch(m_last_cmd) { case 0x80: //Sec break; case 0x82: //Min break; case 0x84: //Hour break; case 0x86: //Day break; case 0x88: //Month break; case 0x8a: //weekday break; case 0x8c: //Year break; default: m_shift_out = 0x0; } if(m_last_cmd > 0xc0) { m_sram[(m_last_cmd >> 1) & 0x1f] = val; }