2021-06-09 05:17:46 +02:00
|
|
|
#include <sys/ksys.h>
|
2022-04-15 11:00:55 +02:00
|
|
|
#include <time.h>
|
2021-06-09 05:17:46 +02:00
|
|
|
|
2022-04-15 11:00:55 +02:00
|
|
|
time_t time(time_t* timer)
|
|
|
|
{
|
2021-11-07 20:29:12 +01:00
|
|
|
static struct tm __buffertime;
|
2021-06-09 05:17:46 +02:00
|
|
|
int kos_date, kos_time;
|
2021-07-27 01:42:35 +02:00
|
|
|
kos_date = _ksys_get_date().val;
|
2021-07-27 02:20:54 +02:00
|
|
|
kos_time = _ksys_get_time().val;
|
2022-04-15 11:00:55 +02:00
|
|
|
|
2021-06-09 05:17:46 +02:00
|
|
|
int bcd_day = (kos_date >> 16);
|
|
|
|
int bcd_mon = ((kos_date & 0xFF00) >> 8);
|
|
|
|
int bcd_year = (kos_date & 0xFF);
|
2022-04-15 11:00:55 +02:00
|
|
|
__buffertime.tm_mday = ((bcd_day & 0xF0) >> 4) * 10 + (bcd_day & 0x0F);
|
|
|
|
__buffertime.tm_mon = ((bcd_mon & 0xF0) >> 4) * 10 + (bcd_mon & 0x0F) - 1;
|
|
|
|
__buffertime.tm_year = ((bcd_year & 0xF0) >> 4) * 10 + (bcd_year & 0x0F) + 100;
|
|
|
|
|
2021-06-09 05:17:46 +02:00
|
|
|
__buffertime.tm_wday = __buffertime.tm_yday = __buffertime.tm_isdst = -1; /* temporary */
|
2022-04-15 11:00:55 +02:00
|
|
|
|
2021-06-09 05:17:46 +02:00
|
|
|
int bcd_sec = (kos_time >> 16);
|
|
|
|
int bcd_min = ((kos_time & 0xFF00) >> 8);
|
|
|
|
int bcd_hour = (kos_time & 0xFF);
|
2022-04-15 11:00:55 +02:00
|
|
|
|
|
|
|
__buffertime.tm_sec = ((bcd_sec & 0xF0) >> 4) * 10 + (bcd_sec & 0x0F);
|
|
|
|
__buffertime.tm_min = ((bcd_min & 0xF0) >> 4) * 10 + (bcd_min & 0x0F);
|
|
|
|
__buffertime.tm_hour = ((bcd_hour & 0xF0) >> 4) * 10 + (bcd_hour & 0x0F);
|
|
|
|
|
2021-06-09 05:17:46 +02:00
|
|
|
time_t ret = mktime(&__buffertime);
|
2022-04-15 11:00:55 +02:00
|
|
|
if (timer) {
|
|
|
|
*timer = ret;
|
2021-06-09 05:17:46 +02:00
|
|
|
}
|
|
|
|
return ret;
|
2021-07-27 01:42:35 +02:00
|
|
|
}
|