Skip to content

Commit

Permalink
Expose functions for updating timezone properly
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtrujy committed Dec 7, 2023
1 parent b3596ef commit 4a5d65f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
9 changes: 7 additions & 2 deletions ee/libcglue/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 $@

Expand Down
8 changes: 6 additions & 2 deletions ee/libcglue/include/ps2sdkapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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__ */
34 changes: 27 additions & 7 deletions ee/libcglue/src/timezone.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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

0 comments on commit 4a5d65f

Please sign in to comment.