From a6a91349bcf7225995a56fb3e84865277f1abebd Mon Sep 17 00:00:00 2001 From: rumbledethumps <16963588+rumbledethumps@users.noreply.github.com> Date: Tue, 2 Dec 2025 21:37:14 -0800 Subject: [PATCH] make time zone work --- include/time.h | 9 ++++++--- libsrc/common/localtime.s | 36 ++++++++++++++++++++++++++---------- libsrc/common/tzset_time.s | 16 ++++++++++++++++ libsrc/rp6502/ria_tzset.c | 9 --------- libsrc/rp6502/tzset_time.s | 29 +++++++++++++++++++++++++++++ 5 files changed, 77 insertions(+), 22 deletions(-) create mode 100644 libsrc/common/tzset_time.s delete mode 100644 libsrc/rp6502/ria_tzset.c create mode 100644 libsrc/rp6502/tzset_time.s diff --git a/include/time.h b/include/time.h index 5eb6f144a..3fab28454 100644 --- a/include/time.h +++ b/include/time.h @@ -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 diff --git a/libsrc/common/localtime.s b/libsrc/common/localtime.s index 279442c9d..bc64a19cd 100644 --- a/libsrc/common/localtime.s +++ b/libsrc/common/localtime.s @@ -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 diff --git a/libsrc/common/tzset_time.s b/libsrc/common/tzset_time.s new file mode 100644 index 000000000..5c0160404 --- /dev/null +++ b/libsrc/common/tzset_time.s @@ -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 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); -} diff --git a/libsrc/rp6502/tzset_time.s b/libsrc/rp6502/tzset_time.s new file mode 100644 index 000000000..60c1177d7 --- /dev/null +++ b/libsrc/rp6502/tzset_time.s @@ -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