datetime_t GetTimeDate() { datetime_t t; datepack_t tp; CdvdClock_t clock; if (!cdReadClock(&clock)) return INVALID_DATETIME_T; tp.Year = Bcd2Dec(clock.year)+2000; tp.Month = Bcd2Dec(clock.month); tp.Day = Bcd2Dec(clock.day); tp.Hour = Bcd2Dec(clock.hour); tp.Minute = Bcd2Dec(clock.minute); tp.Second = Bcd2Dec(clock.second); tp.WeekDay = 0; t = TimePackToRel(&tp,0); if (t != INVALID_DATETIME_T) { t -= 9*60*60; //adjust JST to GMC if (t == INVALID_DATETIME_T) ++t; } return t; }
int ps2time_init( void ) { CdvdClock_t clock; struct tm tm_time; static unsigned int monthdays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; // query the RTC cdInit(CDVD_INIT_NOCHECK); if( !cdReadClock(&clock) ) return -1; tm_time.tm_sec = BCD2DEC(clock.second); tm_time.tm_min = BCD2DEC(clock.minute); tm_time.tm_hour = BCD2DEC(clock.hour); // hour in Japan (GMT + 9) tm_time.tm_mday = BCD2DEC(clock.day); tm_time.tm_mon = BCD2DEC(clock.month) - 1; // RTC months range from 1 - 12 tm_time.tm_year = BCD2DEC(clock.year) + 100; // RTC returns year less 2000 if( tm_time.tm_hour < 9 ) { // go back to last month if( tm_time.tm_mday == 1 ) { // go back to last year if month is january if( tm_time.tm_mon == 0 ) { tm_time.tm_mon = 11; tm_time.tm_year = tm_time.tm_year - 1; } else { tm_time.tm_mon = tm_time.tm_mon - 1; } // if going back to february and year is a leapyear if( tm_time.tm_mon == 1 && IS_LEAP_YEAR(tm_time.tm_year + 1900)) { tm_time.tm_mday = 29; } else { tm_time.tm_mday = monthdays[ tm_time.tm_mon ]; } } else { tm_time.tm_mday = tm_time.tm_mday - 1; } tm_time.tm_hour = (24 - (9 - tm_time.tm_hour)) % 24; } else { tm_time.tm_hour -= 9; } g_ps2time_start = ps2time_mktime(&tm_time); // setup EE timer1 *T1_MODE = 0x0000; // enable the overflow interrupt handler g_interruptID = AddIntcHandler(T1_INTC, ps2time_intr_handler, 0); EnableIntc(T1_INTC); g_interruptCount = 0; *T1_COUNT = 0; *T1_MODE = Tn_MODE(0x02, 0, 0, 0, 0, 0x01, 0, 0x01, 0, 0); // set the timezone as offset in minutes from GMT ps2time_setTimezone( configGetTimezone() ); return 0; }