diff --git a/include/rp6502.h b/include/rp6502.h index 2c0e78b87..434f2d130 100644 --- a/include/rp6502.h +++ b/include/rp6502.h @@ -96,11 +96,12 @@ long __fastcall__ ria_call_long (unsigned char op); #define RIA_OP_LRAND 0x04 #define RIA_OP_STDIN_OPT 0x05 #define RIA_OP_ERRNO_OPT 0x06 +#define RIA_OP_TZSET 0x0D +#define RIA_OP_TZQUERY 0x0E #define RIA_OP_CLOCK 0x0F #define RIA_OP_CLOCK_GETRES 0x10 #define RIA_OP_CLOCK_GETTIME 0x11 #define RIA_OP_CLOCK_SETTIME 0x12 -#define RIA_OP_CLOCK_GETTIMEZONE 0x13 #define RIA_OP_OPEN 0x14 #define RIA_OP_CLOSE 0x15 #define RIA_OP_READ_XSTACK 0x16 @@ -171,10 +172,6 @@ int __fastcall__ f_setlabel (const char* name); int __fastcall__ f_getlabel (const char* path, char* label); int __fastcall__ f_getfree (const char* name, unsigned long* free, unsigned long* total); -/* Time zone hack */ - -void ria_tzset (unsigned long time); - /* XREG location helpers */ #define xreg_ria_keyboard(...) xreg(0, 0, 0, __VA_ARGS__) diff --git a/include/time.h b/include/time.h index 5eb6f144a..210e49fb1 100644 --- a/include/time.h +++ b/include/time.h @@ -108,6 +108,7 @@ struct tm* __fastcall__ localtime (const time_t* timep); time_t __fastcall__ mktime (struct tm* timep); size_t __fastcall__ strftime (char* buf, size_t bufsize, const char* format, const struct tm* tm); time_t __fastcall__ time (time_t* t); +void tzset (void); #if __CC65_STD__ >= __CC65_STD_CC65__ @@ -131,9 +132,9 @@ extern struct _timezone { #define CLK_TCK CLOCKS_PER_SEC /* POSIX function prototypes */ -int __fastcall__ clock_getres (clockid_t clock_id, struct timespec *res); -int __fastcall__ clock_gettime (clockid_t clock_id, struct timespec *tp); -int __fastcall__ clock_settime (clockid_t clock_id, const struct timespec *tp); +int __fastcall__ clock_getres (clockid_t clock_id, struct timespec* res); +int __fastcall__ clock_gettime (clockid_t clock_id, struct timespec* tp); +int __fastcall__ clock_settime (clockid_t clock_id, const struct timespec* tp); #endif diff --git a/libsrc/rp6502/_localtime.c b/libsrc/rp6502/_localtime.c new file mode 100644 index 000000000..8c76e3a26 --- /dev/null +++ b/libsrc/rp6502/_localtime.c @@ -0,0 +1,31 @@ +#include +#include +#include + +static bool tzset_set = false; + +struct tm* __fastcall__ _time_t_to_tm (const time_t t); + +struct tm* __fastcall__ _localtime (const time_t* timep) +{ + struct tm* tm; + time_t time = *timep; + ria_set_axsreg (time); + time += ria_call_long (RIA_OP_TZQUERY); + tm = _time_t_to_tm (time); + tm->tm_isdst = ria_pop_char (); + if (!tzset_set) { tzset (); } + return tm; +} + +void tzset (void) +{ + int ax = ria_call_int (RIA_OP_TZSET); + if (ax >= 0) { + char i; + for (i = 0; i < sizeof (struct _timezone); i++) { + ((char*)&_tz)[i] = ria_pop_char (); + } + tzset_set = true; + } +} diff --git a/libsrc/rp6502/gettimezone.c b/libsrc/rp6502/gettimezone.c deleted file mode 100644 index 4c4584c07..000000000 --- a/libsrc/rp6502/gettimezone.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -int clock_gettimezone (time_t time, clockid_t clock_id, struct _timezone* tz) -{ - int ax; - ria_set_ax (clock_id); - ria_push_long (time); - ax = ria_call_int (RIA_OP_CLOCK_GETTIMEZONE); - if (ax >= 0) { - char i; - for (i = 0; i < sizeof (struct _timezone); i++) { - ((char*)tz)[i] = ria_pop_char (); - } - } - return ax; -} diff --git a/libsrc/rp6502/localtime.s b/libsrc/rp6502/localtime.s new file mode 100644 index 000000000..89984770d --- /dev/null +++ b/libsrc/rp6502/localtime.s @@ -0,0 +1,12 @@ +; +; struct tm* __fastcall__ localtime (const time_t* timep); +; + + .export _localtime + + .import __localtime + + +;-------------------------------------------------------------------------- + +_localtime = __localtime diff --git a/libsrc/rp6502/ria_tzset.c b/libsrc/rp6502/ria_tzset.c deleted file mode 100644 index 3f39e44f2..000000000 --- a/libsrc/rp6502/ria_tzset.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -int clock_gettimezone (time_t time, clockid_t clock_id, struct _timezone* tz); - -void ria_tzset (unsigned long time) -{ - clock_gettimezone (time, CLOCK_REALTIME, &_tz); -}