Merge pull request #2911 from picocomputer/tz2
Time zone support for target RP6502
This commit is contained in:
@@ -96,11 +96,12 @@ long __fastcall__ ria_call_long (unsigned char op);
|
|||||||
#define RIA_OP_LRAND 0x04
|
#define RIA_OP_LRAND 0x04
|
||||||
#define RIA_OP_STDIN_OPT 0x05
|
#define RIA_OP_STDIN_OPT 0x05
|
||||||
#define RIA_OP_ERRNO_OPT 0x06
|
#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 0x0F
|
||||||
#define RIA_OP_CLOCK_GETRES 0x10
|
#define RIA_OP_CLOCK_GETRES 0x10
|
||||||
#define RIA_OP_CLOCK_GETTIME 0x11
|
#define RIA_OP_CLOCK_GETTIME 0x11
|
||||||
#define RIA_OP_CLOCK_SETTIME 0x12
|
#define RIA_OP_CLOCK_SETTIME 0x12
|
||||||
#define RIA_OP_CLOCK_GETTIMEZONE 0x13
|
|
||||||
#define RIA_OP_OPEN 0x14
|
#define RIA_OP_OPEN 0x14
|
||||||
#define RIA_OP_CLOSE 0x15
|
#define RIA_OP_CLOSE 0x15
|
||||||
#define RIA_OP_READ_XSTACK 0x16
|
#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_getlabel (const char* path, char* label);
|
||||||
int __fastcall__ f_getfree (const char* name, unsigned long* free, unsigned long* total);
|
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 */
|
/* XREG location helpers */
|
||||||
|
|
||||||
#define xreg_ria_keyboard(...) xreg(0, 0, 0, __VA_ARGS__)
|
#define xreg_ria_keyboard(...) xreg(0, 0, 0, __VA_ARGS__)
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ struct tm* __fastcall__ localtime (const time_t* timep);
|
|||||||
time_t __fastcall__ mktime (struct tm* timep);
|
time_t __fastcall__ mktime (struct tm* timep);
|
||||||
size_t __fastcall__ strftime (char* buf, size_t bufsize, const char* format, const struct tm* tm);
|
size_t __fastcall__ strftime (char* buf, size_t bufsize, const char* format, const struct tm* tm);
|
||||||
time_t __fastcall__ time (time_t* t);
|
time_t __fastcall__ time (time_t* t);
|
||||||
|
void tzset (void);
|
||||||
|
|
||||||
|
|
||||||
#if __CC65_STD__ >= __CC65_STD_CC65__
|
#if __CC65_STD__ >= __CC65_STD_CC65__
|
||||||
@@ -131,9 +132,9 @@ extern struct _timezone {
|
|||||||
#define CLK_TCK CLOCKS_PER_SEC
|
#define CLK_TCK CLOCKS_PER_SEC
|
||||||
|
|
||||||
/* POSIX function prototypes */
|
/* POSIX function prototypes */
|
||||||
int __fastcall__ clock_getres (clockid_t clock_id, struct timespec *res);
|
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_gettime (clockid_t clock_id, struct timespec* tp);
|
||||||
int __fastcall__ clock_settime (clockid_t clock_id, const struct timespec *tp);
|
int __fastcall__ clock_settime (clockid_t clock_id, const struct timespec* tp);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
31
libsrc/rp6502/_localtime.c
Normal file
31
libsrc/rp6502/_localtime.c
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#include <rp6502.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
#include <rp6502.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
12
libsrc/rp6502/localtime.s
Normal file
12
libsrc/rp6502/localtime.s
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
;
|
||||||
|
; struct tm* __fastcall__ localtime (const time_t* timep);
|
||||||
|
;
|
||||||
|
|
||||||
|
.export _localtime
|
||||||
|
|
||||||
|
.import __localtime
|
||||||
|
|
||||||
|
|
||||||
|
;--------------------------------------------------------------------------
|
||||||
|
|
||||||
|
_localtime = __localtime
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#include <rp6502.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user