示例#1
0
int
bbc_to_gmt(u_long *timbuf)
{
	int i;
	u_long tmp;
	int year, month, day, hour, min, sec;

	read_bbc();

	sec = bbc_to_decimal(1, 0);
	min = bbc_to_decimal(3, 2);

	/*
	 * Hours are different for some reason. Makes no sense really.
	 */
	hour  = ((bbc_registers[5] & 0x03) * 10) + bbc_registers[4];
	day   = bbc_to_decimal(8, 7);
	month = bbc_to_decimal(10, 9);
	year  = bbc_to_decimal(12, 11) + 1900;

	range_test(hour, 0, 23);
	range_test(day, 1, 31);
	range_test(month, 1, 12);
	range_test(year, STARTOFTIME, 2038);	/* 2038 is the end of time. */

	tmp = 0;

	for (i = STARTOFTIME; i < year; i++)
		tmp += days_in_year(i);
	if (leapyear(year) && month > FEBRUARY)
		tmp++;

	for (i = 1; i < month; i++)
	  	tmp += days_in_month(i);

	tmp += (day - 1);
	tmp = ((tmp * 24 + hour) * 60 + min) * 60 + sec;

	*timbuf = tmp;
	return(1);
}
static bool
clock_to_gmt(satime_t *timbuf)
{
	int i;
	satime_t tmp;
	int year, month, day, hour, min, sec;

	if (machineid == HP_425 && mmuid == MMUID_425_E) {
		/* 425e uses mcclock on the frodo utility chip */
		while ((mc_read(MC_REGA) & MC_REGA_UIP) != 0)
			continue;
		sec   = mc_read(MC_SEC);
		min   = mc_read(MC_MIN);
		hour  = mc_read(MC_HOUR);
		day   = mc_read(MC_DOM);
		month = mc_read(MC_MONTH);
		year  = mc_read(MC_YEAR) + 1900;
	} else {
		/* Use the traditional HIL bbc for all other models */
		read_bbc();

		sec = bbc_to_decimal(1, 0);
		min = bbc_to_decimal(3, 2);

		/*
		 * Hours are different for some reason. Makes no sense really.
		 */
		hour  = ((bbc_registers[5] & 0x03) * 10) + bbc_registers[4];
		day   = bbc_to_decimal(8, 7);
		month = bbc_to_decimal(10, 9);
		year  = bbc_to_decimal(12, 11) + 1900;
	}

	if (year < POSIX_BASE_YEAR)
		year += 100;

#ifdef CLOCK_DEBUG
	printf("clock todr: %u/%u/%u %u:%u:%u\n",
	    year, month, day, hour, min, sec);
#endif

	range_test(hour, 0, 23);
	range_test(day, 1, 31);
	range_test(month, 1, 12);

	tmp = 0;

	for (i = POSIX_BASE_YEAR; i < year; i++)
		tmp += days_per_year(i);
	if (is_leap_year(year) && month > FEBRUARY)
		tmp++;

	for (i = 1; i < month; i++)
	  	tmp += days_in_month(i);
	
	tmp += (day - 1);
	tmp = ((tmp * 24 + hour) * 60 + min) * 60 + sec;

	*timbuf = tmp;
	return true;
}