From 4a5d65f972708f79d3b7ce6a5317b21de8536dc5 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Wed, 6 Dec 2023 23:06:32 +0100 Subject: [PATCH] Expose functions for updating timezone properly --- ee/libcglue/Makefile | 9 +++++++-- ee/libcglue/include/ps2sdkapi.h | 8 ++++++-- ee/libcglue/src/timezone.c | 34 ++++++++++++++++++++++++++------- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/ee/libcglue/Makefile b/ee/libcglue/Makefile index a7d3ba1ef666..cb1ff65dbc0e 100644 --- a/ee/libcglue/Makefile +++ b/ee/libcglue/Makefile @@ -8,7 +8,9 @@ EE_LIB = libcglue.a -CORE_OBJS = timezone.o rtc.o +CORE_OBJS = rtc.o + +TIMEZONE_OBJS = _libcglue_timezone_update.o ps2sdk_setTimezone.o ps2sdk_setDaylightSaving.o FDMAN_OBJS = __fdman_sema.o __descriptor_data_pool.o __descriptormap.o __fdman_init.o __fdman_deinit.o __fdman_get_new_descriptor.o \ __fdman_get_dup_descriptor.o __fdman_release_descriptor.o @@ -37,13 +39,16 @@ GLUE_OBJS = __dummy_passwd.o __transform_errno.o __transform64_errno.o compile_t LOCK_OBJS = __retarget_lock_init.o __retarget_lock_acquire.o __retarget_lock_release.o __retarget_lock_try_acquire.o __retarget_lock_close.o \ __retarget_lock_init_recursive.o __retarget_lock_acquire_recursive.o __retarget_lock_release_recursive.o __retarget_lock_try_acquire_recursive.o __retarget_lock_close_recursive.o -EE_OBJS = $(CORE_OBJS) $(SJIS_OBJS) $(TIME_OBJS) $(FDMAN_OBJS) $(INIT_OBJS) $(SLEEP_OBJS) $(TERMINATE_OBJS) $(CWD_OBJS) $(PS2SDKAPI_OBJS) $(GLUE_OBJS) $(LOCK_OBJS) +EE_OBJS = $(CORE_OBJS) $(TIMEZONE_OBJS) $(SJIS_OBJS) $(TIME_OBJS) $(FDMAN_OBJS) $(INIT_OBJS) $(SLEEP_OBJS) $(TERMINATE_OBJS) $(CWD_OBJS) $(PS2SDKAPI_OBJS) $(GLUE_OBJS) $(LOCK_OBJS) include $(PS2SDKSRC)/Defs.make include $(PS2SDKSRC)/ee/Rules.lib.make include $(PS2SDKSRC)/ee/Rules.make include $(PS2SDKSRC)/ee/Rules.release +$(TIMEZONE_OBJS:%=$(EE_OBJS_DIR)%): $(EE_SRC_DIR)timezone.c + $(EE_C_COMPILE) -DF_$(*:$(EE_OBJS_DIR)%=%) $< -c -o $@ + $(SJIS_OBJS:%=$(EE_OBJS_DIR)%): $(EE_SRC_DIR)sjis.c $(EE_C_COMPILE) -DF_$(*:$(EE_OBJS_DIR)%=%) $< -c -o $@ diff --git a/ee/libcglue/include/ps2sdkapi.h b/ee/libcglue/include/ps2sdkapi.h index 46e8c249dd72..398218da92aa 100644 --- a/ee/libcglue/include/ps2sdkapi.h +++ b/ee/libcglue/include/ps2sdkapi.h @@ -70,8 +70,6 @@ static inline ps2_clock_t ps2_clock(void) { return (ps2_clock_t)(GetTimerSystemTime() >> 8); } -extern void _libcglue_timezone_update(); - extern s64 _ps2sdk_rtc_offset_from_busclk; extern void _libcglue_rtc_update(); @@ -80,4 +78,10 @@ extern void _libcglue_rtc_update(); typedef int64_t off64_t; off64_t lseek64(int fd, off64_t offset, int whence); +// Functions to be used related to timezone +extern void _libcglue_timezone_update(); + +void ps2sdk_setTimezone(int timezone); +void ps2sdk_setDaylightSaving(int daylightSaving); + #endif /* __PS2SDKAPI_H__ */ diff --git a/ee/libcglue/src/timezone.c b/ee/libcglue/src/timezone.c index 39645a4e2e3e..00cdb7dc0e12 100644 --- a/ee/libcglue/src/timezone.c +++ b/ee/libcglue/src/timezone.c @@ -21,19 +21,22 @@ #define OSD_CONFIG_NO_LIBCDVD #include "osd_config.h" -__attribute__((weak)) -void _libcglue_timezone_update() -{ - /* Initialize timezone from PS2 OSD configuration */ - int tzOffset = 0; - +static inline void setPS2SDKFunctions() { // Set ps2sdk functions if (_ps2sdk_open == NULL) _set_ps2sdk_open(); if (_ps2sdk_close == NULL) _set_ps2sdk_close(); if (_ps2sdk_read == NULL) _set_ps2sdk_read(); +} + +#ifdef F__libcglue_timezone_update +__attribute__((weak)) +void _libcglue_timezone_update() +{ + /* Initialize timezone from PS2 OSD configuration */ + setPS2SDKFunctions(); _io_driver driver = { _ps2sdk_open, _ps2sdk_close, _ps2sdk_read }; - configGetTimezoneWithIODriver(&driver); + int tzOffset = configGetTimezoneWithIODriver(&driver); int tzOffsetAbs = tzOffset < 0 ? -tzOffset : tzOffset; int hours = tzOffsetAbs / 60; int minutes = tzOffsetAbs - hours * 60; @@ -42,3 +45,20 @@ void _libcglue_timezone_update() sprintf(tz, "GMT%s%02i:%02i%s", tzOffset < 0 ? "+" : "-", hours, minutes, daylight ? "DST" : ""); setenv("TZ", tz, 1); } +#endif + +#ifdef F_ps2sdk_setTimezone +void ps2sdk_setTimezone(int timezone) { + setPS2SDKFunctions(); + _io_driver driver = { _ps2sdk_open, _ps2sdk_close, _ps2sdk_read }; + configSetTimezoneWithIODriver(timezone, &driver, _libcglue_timezone_update); +} +#endif + +#ifdef F_ps2sdk_setDaylightSaving +void ps2sdk_setDaylightSaving(int daylightSaving) { + setPS2SDKFunctions(); + _io_driver driver = { _ps2sdk_open, _ps2sdk_close, _ps2sdk_read }; + configSetDaylightSavingEnabledWithIODriver(daylightSaving, &driver, _libcglue_timezone_update); +} +#endif \ No newline at end of file