#102980 - Lick - Mon Sep 18, 2006 12:27 pm
As the current standard ctime functions don't work, I've wrote a very unclean hack that does the same as time(), at least that's what it should do.
Is there anything wrong with it? Can it be optimized?
ndsx_time.h
BTW, you're free to use this code in your project!
_________________
http://licklick.wordpress.com
Is there anything wrong with it? Can it be optimized?
ndsx_time.h
Code: |
#ifndef _NDSX_TIME_
#define _NDSX_TIME_ #define ISLEAP(y) (!((y) % 4) && (((y) % 100) || !((y) % 400))) #define DAY2S(dys) u32((dys) * 86400) #define HOURS2S(hrs) u32((hrs) * 3600) #define MINUTES2S(min) u32((min) * 60) u16 mdays[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }; u16 mdays_leap[] = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }; #define rtc24hours ((IPC->rtc_hours > 51) ? IPC->rtc_hours-40 : IPC->rtc_hours) u32 NDSX_time() { static u32 year_shit1 = (IPC->rtc_year+30) / 4; // get number of 4-years static u32 year_shit2 = (IPC->rtc_year+30) % 4; // rest of 4-years (1, 2, 3 are important) u32 years_in_sec = year_shit1 * (31536000*3 + 31622400); if(year_shit2 == 1) years_in_sec += 31536000; // normal year else if(year_shit2 == 2) years_in_sec += 31536000 + 31622400; // normal year + leap year else if(year_shit2 == 3) years_in_sec += 31536000*2 + 31622400; // normal year * 2 + leap year return years_in_sec + ISLEAP(IPC->rtc_year+2000) ? DAY2S(mdays_leap[IPC->rtc_month-1]) : DAY2S(mdays[IPC->rtc_month-1]) + DAY2S(IPC->rtc_day-1) + HOURS2S(rtc24hours) + MINUTES2S(IPC->rtc_minutes) + IPC->rtc_seconds ; } #endif |
BTW, you're free to use this code in your project!
_________________
http://licklick.wordpress.com