yes!
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_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
|
||||
|
||||
@@ -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__
|
||||
@@ -124,13 +125,10 @@ struct timespec {
|
||||
extern struct _timezone {
|
||||
char daylight; /* True if daylight savings time active */
|
||||
long timezone; /* Number of seconds behind UTC */
|
||||
char tzname[5]; /* Name of timezone, e.g. CET */
|
||||
char dstname[5]; /* Name when daylight true, e.g. CEST */
|
||||
char tzname[6]; /* Name of timezone, e.g. CET */
|
||||
char dstname[6]; /* Name when daylight true, e.g. CEST */
|
||||
} _tz;
|
||||
|
||||
/* Set _tz for a specific time, if supported by target */
|
||||
void __fastcall__ tzset_time (time_t* t);
|
||||
|
||||
#define CLK_TCK CLOCKS_PER_SEC
|
||||
|
||||
/* POSIX function prototypes */
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
;
|
||||
|
||||
.export _localtime
|
||||
.import __time_t_to_tm, __tz, _tzset_time
|
||||
.import __time_t_to_tm, __tz
|
||||
.import ldeaxi, tosaddeax, pusheax
|
||||
.importzp sreg, ptr1
|
||||
.importzp sreg
|
||||
|
||||
_localtime:
|
||||
cpx #$00 ; Check for null pointer
|
||||
@@ -16,7 +16,6 @@ _localtime:
|
||||
beq no_pointer
|
||||
: jsr ldeaxi ; Load value
|
||||
jsr pusheax ; Push it
|
||||
jsr _tzset_time
|
||||
lda __tz+1+3
|
||||
sta sreg+1
|
||||
lda __tz+1+2
|
||||
@@ -24,13 +23,7 @@ _localtime:
|
||||
ldx __tz+1+1
|
||||
lda __tz+1
|
||||
jsr tosaddeax ; Add _tz.timezone
|
||||
jsr __time_t_to_tm ; Convert to struct tm
|
||||
sta ptr1 ; Returned tm pointer
|
||||
stx ptr1+1
|
||||
ldy #16
|
||||
lda __tz+0 ; Load _tz.daylight
|
||||
sta (ptr1),y ; Store to tm.tm_isdst
|
||||
lda ptr1
|
||||
jmp __time_t_to_tm ; Convert to struct tm
|
||||
|
||||
no_pointer:
|
||||
rts ; A/X already set
|
||||
|
||||
@@ -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
|
||||
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)
|
||||
{
|
||||
long time = *timep;
|
||||
struct tm* tm;
|
||||
ria_set_axsreg (*timep);
|
||||
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,26 +0,0 @@
|
||||
; tzset_time.s
|
||||
;
|
||||
; This file is part of
|
||||
; cc65 - a freeware C compiler for 6502 based systems
|
||||
;
|
||||
; https://cc65.github.io
|
||||
;
|
||||
; See "LICENSE" file for legal information.
|
||||
;
|
||||
; void __fastcall__ tzset_time (time_t* time);
|
||||
;
|
||||
|
||||
.export _tzset_time
|
||||
.import _clock_gettimezone, __tz
|
||||
.import pushax, ldax0sp, ldeaxi, pusheax, pusha, incsp2
|
||||
.include "time.inc"
|
||||
|
||||
|
||||
_tzset_time:
|
||||
jsr ldeaxi
|
||||
jsr pusheax
|
||||
lda #CLOCK_REALTIME
|
||||
jsr pusha
|
||||
lda #<(__tz)
|
||||
ldx #>(__tz)
|
||||
jmp _clock_gettimezone
|
||||
Reference in New Issue
Block a user