ps2 system time

Discuss the development of software, tools, libraries and anything else that helps make ps2dev happen.

Moderators: cheriff, Herben

Post Reply
JorDy
Posts: 121
Joined: Sun Dec 11, 2005 8:45 am

ps2 system time

Post by JorDy »

There seems to be an error with the Hours returned from cdReadClock, my ps2 system clock was around 23:37 when i ran this but cdReadClock returned that my hours was 08 yet everything else was correct. I also got a friend to run this and his time was 18:?? and his returned 20:?? can someone tell me what the problem is?
Polo35
Posts: 25
Joined: Sun Apr 09, 2006 7:22 am

Post by Polo35 »

Time return by cdreadclock is time in Japan GTM+9.

Take a look in myps2 1.2 source code, there is a libps2time which deal with ps2 clock.

Best regards

Polo
JorDy
Posts: 121
Joined: Sun Dec 11, 2005 8:45 am

Post by JorDy »

thanks a lot! i thought there was something strange with the time difference!

*edit* im now getting a funny date, its the 6th of may and its telling me its the 29th
Polo35
Posts: 25
Joined: Sun Apr 09, 2006 7:22 am

Post by Polo35 »

Hey.

Here a simple code i wrote some time ago:

Code: Select all

#define BCD2DEC(bcd)	   (((((bcd)>>4) & 0x0F) * 10) + ((bcd) & 0x0F)) 
#define IS_LEAP_YEAR(Y)  ( ((Y)>0) && !((Y)%4) && ( ((Y)%100) || !((Y)%400) ) )

static char CurClock[ 256 ];

void GetClock ( void ) {

	CdvdClock_t clock;
	int			   nMinute;
	int			   nHour;
	int			   nDay;
	int			   nMonth;
	int			   nYear;
	s32			   nGMTOffset;

	int			   nMonthsDays[] =
 			{	31, 28, 31,	30,	31,	30,	31,	31,	30,	31,	30,	31	};

	cdReadClock( &clock );
	s32 TimeZone = configGetTimezone();
	int DayLightSaving = configIsDaylightSavingEnabled();


	nGMTOffset = TimeZone / 60;
	nMinute		 = BCD2DEC(clock.minute);
	nHour		   = BCD2DEC(clock.hour);		// Hour in Japan (GMT + 9)
	nDay		   = BCD2DEC(clock.day);
	nMonth	   = BCD2DEC(clock.month);
	nYear		   = BCD2DEC(clock.year);
	nYear		   = nYear + 2000;
	nMonth		 = nMonth;
	nDay		   = nDay;
	nHour		   = nHour - 9 + nGMTOffset + DayLightSaving;

	if&#40; nHour < 0 &#41; &#123;
		nHour += 24;
		if&#40; --nDay == 0 &#41; &#123;
			if&#40; --nMonth == 0 &#41; &#123;
				nMonth = 11;
				nYear--;
			&#125; /* end if */
			nDay = nMonthsDays&#91;nMonth&#93;;
			if&#40; nMonth == 2 && IS_LEAP_YEAR&#40;nYear&#41; &#41;
				nDay++;
		&#125; /* end if */
	&#125; /* end if */

	snprintf&#40; CurClock, sizeof&#40; CurClock &#41;, "%02i/%02i/%i  %02i&#58;%02i", nDay, nMonth, nYear, nHour, nMinute &#41;;

&#125; /* end GetClock */
Best regards

Polo
JorDy
Posts: 121
Joined: Sun Dec 11, 2005 8:45 am

Post by JorDy »

absolutely perfect!! thank you so much
Post Reply