Make use of clock_settime().

clock_gettime(), clock_settime() and clock_getres() were added to the cc65 C libaries the other day.
This commit is contained in:
Oliver Schmidt
2018-08-18 23:28:59 +02:00
parent d79db04aa1
commit 300ca8626a

View File

@@ -52,8 +52,7 @@ void main(void)
{ {
uint8_t drv_init = DRV_INIT_DEFAULT; uint8_t drv_init = DRV_INIT_DEFAULT;
uint32_t server; uint32_t server;
time_t rawtime; struct timespec time;
struct tm* timeinfo;
strncpy(_tz.tzname, TIMEZONE_CODE, strncpy(_tz.tzname, TIMEZONE_CODE,
sizeof(_tz.tzname) - 1); sizeof(_tz.tzname) - 1);
@@ -100,42 +99,18 @@ void main(void)
} }
printf("- Ok\n\nGetting %s ", _tz.tzname); printf("- Ok\n\nGetting %s ", _tz.tzname);
rawtime = sntp_get_time(server); time.tv_sec = sntp_get_time(server);
if (!rawtime) if (!time.tv_sec)
{ {
error_exit(); error_exit();
} }
// Convert time from seconds since 1900 to // Convert time from seconds since 1900 to
// seconds since 1970 according to RFC 868 // seconds since 1970 according to RFC 868
rawtime -= 2208988800UL; time.tv_sec -= 2208988800UL;
timeinfo = localtime(&rawtime); printf("- %s", ctime(&time.tv_sec));
printf("- %s", asctime(timeinfo));
#ifdef __APPLE2__ time.tv_nsec = 0;
{ clock_settime(CLOCK_REALTIME, &time);
// See ProDOS 8 Technical Reference Manual
// Chapter 6.1 - Clock/Calendar Routines
typedef struct
{
unsigned mday :5;
unsigned mon :4;
unsigned year :7;
uint8_t min;
uint8_t hour;
}
dostime_t;
dostime_t* dostime = (dostime_t*)0xBF90;
// If DOS time is 0:00 assume no RTC active
if (!(dostime->hour || dostime->min))
{
// Set only DOS date to today
dostime->year = timeinfo->tm_year % 100;
dostime->mon = timeinfo->tm_mon + 1;
dostime->mday = timeinfo->tm_mday;
}
}
#endif
} }