Пример #1
0
void DreamcastFile::timeToDec(vmu_timestamp_t *tbcd) {
	tbcd->cent=bcd_to_dec(tbcd->cent);
	tbcd->year=bcd_to_dec(tbcd->year);
	tbcd->month=bcd_to_dec(tbcd->month);
	tbcd->day=bcd_to_dec(tbcd->day);
	tbcd->hour=bcd_to_dec(tbcd->hour);
	tbcd->min=bcd_to_dec(tbcd->min);
	tbcd->sec=bcd_to_dec(tbcd->sec);
	tbcd->dow=bcd_to_dec(tbcd->dow);
}
Пример #2
0
void get_time(struct tm *t)
{
  int osec, n;
  unsigned long i;
  struct sigaction sa;

  /* Start a timer to keep us from getting stuck on a dead clock. */
  sigemptyset(&sa.sa_mask);
  sa.sa_flags = 0;
  sa.sa_handler = timeout;
  sigaction(SIGALRM, &sa, NULL);
  dead = 0;
  alarm(5);

  do {
	osec = -1;
	n = 0;
	do {
		if (dead) {
			fprintf(stderr, "readclock: CMOS clock appears dead\n");
			exit(1);
		}

		/* Clock update in progress? */
		if (read_register(RTC_REG_A) & RTC_A_UIP) continue;

		t->tm_sec = read_register(RTC_SEC);
		if (t->tm_sec != osec) {
			/* Seconds changed.  First from -1, then because the
			 * clock ticked, which is what we're waiting for to
			 * get a precise reading.
			 */
			osec = t->tm_sec;
			n++;
		}
	} while (n < 2);

	/* Read the other registers. */
	t->tm_min = read_register(RTC_MIN);
	t->tm_hour = read_register(RTC_HOUR);
	t->tm_mday = read_register(RTC_MDAY);
	t->tm_mon = read_register(RTC_MONTH);
	t->tm_year = read_register(RTC_YEAR);

	/* Time stable? */
  } while (read_register(RTC_SEC) != t->tm_sec
	|| read_register(RTC_MIN) != t->tm_min
	|| read_register(RTC_HOUR) != t->tm_hour
	|| read_register(RTC_MDAY) != t->tm_mday
	|| read_register(RTC_MONTH) != t->tm_mon
	|| read_register(RTC_YEAR) != t->tm_year);

  if ((read_register(RTC_REG_B) & RTC_B_DM_BCD) == 0) {
	/* Convert BCD to binary (default RTC mode). */
	t->tm_year = bcd_to_dec(t->tm_year);
	t->tm_mon = bcd_to_dec(t->tm_mon);
	t->tm_mday = bcd_to_dec(t->tm_mday);
	t->tm_hour = bcd_to_dec(t->tm_hour);
	t->tm_min = bcd_to_dec(t->tm_min);
	t->tm_sec = bcd_to_dec(t->tm_sec);
  }
  t->tm_mon--;	/* Counts from 0. */

  /* Correct the year, good until 2080. */
  if (t->tm_year < 80) t->tm_year += 100;

  if (y2kflag) {
	/* Clock with Y2K bug, interpret 1980 as 2000, good until 2020. */
	if (t->tm_year < 100) t->tm_year += 20;
  }
}