make time zone work

This commit is contained in:
rumbledethumps
2025-12-02 21:37:14 -08:00
parent dbcfa91089
commit a6a91349bc
5 changed files with 77 additions and 22 deletions

View File

@@ -128,12 +128,15 @@ extern struct _timezone {
char dstname[5]; /* 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 */
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

View File

@@ -5,16 +5,27 @@
;
.export _localtime
.import __time_t_to_tm, __tz
.import __time_t_to_tm, __tz, _tzset_time
.import ldeaxi, tosaddeax, pusheax
.importzp sreg
.importzp sreg, ptr1
_localtime:
cpx #$00 ; Check for null pointer
bne :+
cmp #$00
beq no_pointer
: jsr ldeaxi ; Load value
.if .cap(CPU_HAS_PUSHXY)
pha
phx
jsr _tzset_time
plx
pla
.else
pha
txa
pha
jsr _tzset_time
pla
tax
pla
.endif
jsr ldeaxi ; Load value
jsr pusheax ; Push it
lda __tz+1+3
sta sreg+1
@@ -23,7 +34,12 @@ _localtime:
ldx __tz+1+1
lda __tz+1
jsr tosaddeax ; Add _tz.timezone
jmp __time_t_to_tm ; Convert to struct tm
no_pointer:
jsr __time_t_to_tm ; Convert to struct tm
sta ptr1 ; Save returned tm pointer
stx ptr1+1
ldy #16
lda __tz+0 ; Load _tz.daylight
sta (ptr1),y ; Store to tm.tm_isdst
lda ptr1 ; Restore returned tm pointer
ldx ptr1+1
rts ; A/X already set

View File

@@ -0,0 +1,16 @@
; 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
_tzset_time:
rts

View File

@@ -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);
}

View File

@@ -0,0 +1,29 @@
; 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 pushax
jsr ldax0sp
jsr ldeaxi
jsr pusheax
lda #CLOCK_REALTIME
jsr pusha
lda #<(__tz)
ldx #>(__tz)
jsr _clock_gettimezone
jmp incsp2