From 08ed73f47cf90a042decd381919111710796c8a6 Mon Sep 17 00:00:00 2001 From: Martin Baliet Date: Fri, 8 Mar 2024 10:39:37 +0100 Subject: [PATCH] + libsceRtc --- modules/libSceRtc/CMakeLists.txt | 18 +++ modules/libSceRtc/codes.h | 19 +++ modules/libSceRtc/entry.cpp | 253 +++++++++++++++++++++++++++++++ modules/libSceRtc/types.h | 22 +++ modules/libSceSaveData/codes.h | 46 +++--- 5 files changed, 335 insertions(+), 23 deletions(-) create mode 100644 modules/libSceRtc/CMakeLists.txt create mode 100644 modules/libSceRtc/codes.h create mode 100644 modules/libSceRtc/entry.cpp create mode 100644 modules/libSceRtc/types.h diff --git a/modules/libSceRtc/CMakeLists.txt b/modules/libSceRtc/CMakeLists.txt new file mode 100644 index 0000000..80adb3d --- /dev/null +++ b/modules/libSceRtc/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.24) +include(../setupModule.cmake) + +set(libName libSceRtc) +project(${libName}) + +add_library(${libName} SHARED entry.cpp) + +add_dependencies(${libName} third_party) +target_link_libraries(${libName} PRIVATE + libboost_chrono +) + +target_compile_definitions(${libName} PRIVATE + BOOST_ALL_NO_LIB +) + +setupModule(${libName}) \ No newline at end of file diff --git a/modules/libSceRtc/codes.h b/modules/libSceRtc/codes.h new file mode 100644 index 0000000..db8438c --- /dev/null +++ b/modules/libSceRtc/codes.h @@ -0,0 +1,19 @@ +#pragma once +#include + +namespace Err { +constexpr int32_t SCE_RTC_ERROR_NOT_INITIALIZED = -2135621631; +constexpr int32_t SCE_RTC_ERROR_INVALID_POINTER = -2135621630; +constexpr int32_t SCE_RTC_ERROR_INVALID_VALUE = -2135621629; +constexpr int32_t SCE_RTC_ERROR_INVALID_ARG = -2135621628; +constexpr int32_t SCE_RTC_ERROR_NOT_SUPPORTED = -2135621627; +constexpr int32_t SCE_RTC_ERROR_NO_CLOCK = -2135621626; +constexpr int32_t SCE_RTC_ERROR_BAD_PARSE = -2135621625; +constexpr int32_t SCE_RTC_ERROR_INVALID_YEAR = -2135621624; +constexpr int32_t SCE_RTC_ERROR_INVALID_MONTH = -2135621623; +constexpr int32_t SCE_RTC_ERROR_INVALID_DAY = -2135621622; +constexpr int32_t SCE_RTC_ERROR_INVALID_HOUR = -2135621621; +constexpr int32_t SCE_RTC_ERROR_INVALID_MINUTE = -2135621620; +constexpr int32_t SCE_RTC_ERROR_INVALID_SECOND = -2135621619; +constexpr int32_t SCE_RTC_ERROR_INVALID_MICROSECOND = -2135621618; +} // namespace Err \ No newline at end of file diff --git a/modules/libSceRtc/entry.cpp b/modules/libSceRtc/entry.cpp new file mode 100644 index 0000000..e9835d5 --- /dev/null +++ b/modules/libSceRtc/entry.cpp @@ -0,0 +1,253 @@ +#include "common.h" +#include "logging.h" +#include "types.h" + +#include +#include +#include +#include +#include + +LOG_DEFINE_MODULE(libSceRtc); + +namespace {} // namespace + +extern "C" { + +EXPORT const char* MODULE_NAME = "libSceRtc"; + +EXPORT SYSV_ABI int sceRtcGetCurrentTick(SceRtcTick* pTick) { + pTick->tick = boost::chrono::duration_cast(boost::chrono::high_resolution_clock::now().time_since_epoch()).count(); + return Ok; +} + +EXPORT SYSV_ABI int sceRtcGetCurrentClock(SceRtcDateTime* pTime, int iTimeZone) { + boost::posix_time::ptime const now = boost::posix_time::microsec_clock::universal_time(); + + boost::posix_time::time_duration const duration = now.time_of_day() + boost::posix_time::minutes(iTimeZone); + + pTime->year = now.date().year(); + pTime->month = now.date().month(); + pTime->day = now.date().day(); + pTime->hour = duration.hours(); + pTime->minute = duration.minutes(); + pTime->second = duration.seconds(); + pTime->microsecond = duration.fractional_seconds() * 1000; + return Ok; +} + +EXPORT SYSV_ABI int sceRtcGetCurrentClockLocalTime(SceRtcDateTime* pTime) { + boost::posix_time::ptime const now = boost::posix_time::microsec_clock::local_time(); + + boost::posix_time::time_duration const duration = now.time_of_day(); + + pTime->year = now.date().year(); + pTime->month = now.date().month(); + pTime->day = now.date().day(); + pTime->hour = duration.hours(); + pTime->minute = duration.minutes(); + pTime->second = duration.seconds(); + pTime->microsecond = duration.fractional_seconds() * 1000; + return Ok; +} + +EXPORT SYSV_ABI int sceRtcGetCurrentNetworkTick(SceRtcTick* pTick) { + pTick->tick = boost::chrono::system_clock::now().time_since_epoch().count(); + return Ok; +} + +EXPORT SYSV_ABI int sceRtcConvertUtcToLocalTime(const SceRtcTick* pUtc, SceRtcTick* pLocalTime) { + *pLocalTime = *pUtc; + + LOG_USE_MODULE(libSceRtc); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int sceRtcConvertLocalTimeToUtc(const SceRtcTick* pLocalTime, SceRtcTick* pUtc) { + *pUtc = *pLocalTime; + + LOG_USE_MODULE(libSceRtc); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int sceRtcIsLeapYear(int year) { + return boost::gregorian::gregorian_calendar::is_leap_year(2020); +} + +EXPORT SYSV_ABI int sceRtcGetDaysInMonth(int year, int month) { + return boost::gregorian::gregorian_calendar::end_of_month_day(year, month); +} + +EXPORT SYSV_ABI SceRTCDay sceRtcGetDayOfWeek(int year, int month, int day) { + boost::gregorian::date const date(year, month, day); + + return (SceRTCDay)date.day_of_week().as_number(); +} + +EXPORT SYSV_ABI int sceRtcCheckValid(const SceRtcDateTime* pTime) { + LOG_USE_MODULE(libSceRtc); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int sceRtcSetTime_t(SceRtcDateTime* pTime, time_t llTime) { + boost::posix_time::ptime const ptime = boost::posix_time::from_time_t(llTime); + + auto const date = ptime.date(); + auto const time = ptime.time_of_day(); + + pTime->year = date.year(); + pTime->month = date.month(); + pTime->day = date.day(); + pTime->hour = time.hours(); + pTime->minute = time.minutes(); + pTime->second = time.seconds(); + return Ok; +} + +EXPORT SYSV_ABI int sceRtcGetTime_t(const SceRtcDateTime* pTime, time_t* pllTime) { + boost::posix_time::ptime ptime(boost::gregorian::date(pTime->year, pTime->month, pTime->day), + boost::posix_time::seconds(pTime->hour * 3600 + pTime->minute * 60 + pTime->second)); + + *pllTime = boost::posix_time::to_time_t(ptime); + return Ok; +} + +EXPORT SYSV_ABI int sceRtcSetDosTime(SceRtcDateTime* pTime, unsigned int uiDosTime) { + LOG_USE_MODULE(libSceRtc); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int sceRtcGetDosTime(const SceRtcDateTime* pTime, unsigned int* puiDosTime) { + LOG_USE_MODULE(libSceRtc); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int sceRtcSetWin32FileTime(SceRtcDateTime* pTime, uint64_t ulWin32Time) { + LOG_USE_MODULE(libSceRtc); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int sceRtcGetWin32FileTime(const SceRtcDateTime* pTime, uint64_t* ulWin32Time) { + LOG_USE_MODULE(libSceRtc); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int sceRtcSetTick(SceRtcDateTime* pTime, const SceRtcTick* pTick) { + boost::posix_time::ptime const ptime = boost::posix_time::from_time_t(pTick->tick); + + auto const date = ptime.date(); + auto const time = ptime.time_of_day(); + + pTime->year = date.year(); + pTime->month = date.month(); + pTime->day = date.day(); + pTime->hour = time.hours(); + pTime->minute = time.minutes(); + pTime->second = time.seconds(); + return Ok; +} + +EXPORT SYSV_ABI int sceRtcGetTick(const SceRtcDateTime* pTime, SceRtcTick* pTick) { + boost::posix_time::ptime ptime(boost::gregorian::date(pTime->year, pTime->month, pTime->day), + boost::posix_time::seconds(pTime->hour * 3600 + pTime->minute * 60 + pTime->second)); + + pTick->tick = boost::posix_time::to_time_t(ptime); + return Ok; +} + +EXPORT SYSV_ABI unsigned int sceRtcGetTickResolution(void) { + LOG_USE_MODULE(libSceRtc); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int sceRtcTickAddTicks(SceRtcTick* pTick0, const SceRtcTick* pTick1, int64_t lAdd) { + pTick0->tick = pTick1->tick + lAdd; + return Ok; +} + +EXPORT SYSV_ABI int sceRtcTickAddMicroseconds(SceRtcTick* pTick0, const SceRtcTick* pTick1, int64_t lAdd) { + pTick0->tick = pTick1->tick + lAdd; + return Ok; +} + +EXPORT SYSV_ABI int sceRtcTickAddSeconds(SceRtcTick* pTick0, const SceRtcTick* pTick1, int64_t lAdd) { + pTick0->tick = uint64_t(1e6) * pTick1->tick + lAdd; + return Ok; +} + +EXPORT SYSV_ABI int sceRtcTickAddMinutes(SceRtcTick* pTick0, const SceRtcTick* pTick1, int64_t lAdd) { + pTick0->tick = uint64_t(60 * 1e6) * pTick1->tick + lAdd; + return Ok; +} + +EXPORT SYSV_ABI int sceRtcTickAddHours(SceRtcTick* pTick0, const SceRtcTick* pTick1, int iAdd) { + pTick0->tick = uint64_t(60 * 60 * 1e6) * pTick1->tick + iAdd; + return Ok; +} + +EXPORT SYSV_ABI int sceRtcTickAddDays(SceRtcTick* pTick0, const SceRtcTick* pTick1, int iAdd) { + pTick0->tick = uint64_t(24 * 60 * 60 * 1e6) * pTick1->tick + iAdd; + return Ok; +} + +EXPORT SYSV_ABI int sceRtcTickAddWeeks(SceRtcTick* pTick0, const SceRtcTick* pTick1, int iAdd) { + pTick0->tick = uint64_t(7 * 60 * 60 * 1e6) * pTick1->tick + iAdd; + return Ok; +} + +EXPORT SYSV_ABI int sceRtcTickAddMonths(SceRtcTick* pTick0, const SceRtcTick* pTick1, int iAdd) { + LOG_USE_MODULE(libSceRtc); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int sceRtcTickAddYears(SceRtcTick* pTick0, const SceRtcTick* pTick1, int iAdd) { + LOG_USE_MODULE(libSceRtc); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int sceRtcFormatRFC2822(char* pszDateTime, const SceRtcTick* pUtc, int iTimeZoneMinutes) { + LOG_USE_MODULE(libSceRtc); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int sceRtcFormatRFC2822LocalTime(char* pszDateTime, const SceRtcTick* pUtc) { + LOG_USE_MODULE(libSceRtc); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int sceRtcFormatRFC3339(char* pszDateTime, const SceRtcTick* pUtc, int iTimeZoneMinutes) { + LOG_USE_MODULE(libSceRtc); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int sceRtcFormatRFC3339LocalTime(char* pszDateTime, const SceRtcTick* pUtc) { + LOG_USE_MODULE(libSceRtc); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int sceRtcParseDateTime(SceRtcTick* pUtc, const char* pszDateTime) { + LOG_USE_MODULE(libSceRtc); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} + +EXPORT SYSV_ABI int sceRtcParseRFC3339(SceRtcTick* pUtc, const char* pszDateTime) { + LOG_USE_MODULE(libSceRtc); + LOG_ERR(L"todo %S", __FUNCTION__); + return Ok; +} +} \ No newline at end of file diff --git a/modules/libSceRtc/types.h b/modules/libSceRtc/types.h new file mode 100644 index 0000000..ebe7b6b --- /dev/null +++ b/modules/libSceRtc/types.h @@ -0,0 +1,22 @@ +#pragma once +#include "codes.h" + +enum class SceRTCDay { + SUNDAY = 0, + MONDAY = 1, + TUESDAY = 2, + WEDNESDAY = 3, + THURSDAY = 4, + FRIDAY = 5, + SATURDAY = 6, +}; + +struct SceRtcDateTime { + uint16_t year; + uint16_t month; + uint16_t day; + uint16_t hour; + uint16_t minute; + uint16_t second; + uint32_t microsecond; +}; \ No newline at end of file diff --git a/modules/libSceSaveData/codes.h b/modules/libSceSaveData/codes.h index ef656cd..d4b3d06 100644 --- a/modules/libSceSaveData/codes.h +++ b/modules/libSceSaveData/codes.h @@ -4,29 +4,29 @@ namespace Err { -constexpr int SAVE_DATA_ERROR_PARAMETER = -2137063424; /* 0x809F0000 */ -constexpr int SAVE_DATA_ERROR_NOT_INITIALIZED = -2137063423; /* 0x809F0001 */ -constexpr int SAVE_DATA_ERROR_OUT_OF_MEMORY = -2137063422; /* 0x809F0002 */ -constexpr int SAVE_DATA_ERROR_BUSY = -2137063421; /* 0x809F0003 */ -constexpr int SAVE_DATA_ERROR_NOT_MOUNTED = -2137063420; /* 0x809F0004 */ -constexpr int SAVE_DATA_ERROR_NO_PERMISSION = -2137063419; /* 0x809F0005 */ -constexpr int SAVE_DATA_ERROR_FINGERPRINT_MISMATCH = -2137063418; /* 0x809F0006 */ -constexpr int SAVE_DATA_ERROR_EXISTS = -2137063417; /* 0x809F0007 */ -constexpr int SAVE_DATA_ERROR_NOT_FOUND = -2137063416; /* 0x809F0008 */ -constexpr int SAVE_DATA_ERROR_NO_SPACE_FS = -2137063414; /* 0x809F000A */ -constexpr int SAVE_DATA_ERROR_INTERNAL = -2137063413; /* 0x809F000B */ -constexpr int SAVE_DATA_ERROR_MOUNT_FULL = -2137063412; /* 0x809F000C */ -constexpr int SAVE_DATA_ERROR_BAD_MOUNTED = -2137063411; /* 0x809F000D */ -constexpr int SAVE_DATA_ERROR_FILE_NOT_FOUND = -2137063410; /* 0x809F000E */ -constexpr int SAVE_DATA_ERROR_BROKEN = -2137063409; /* 0x809F000F */ -constexpr int SAVE_DATA_ERROR_INVALID_LOGIN_USER = -2137063407; /* 0x809F0011 */ -constexpr int SAVE_DATA_ERROR_MEMORY_NOT_READY = -2137063406; /* 0x809F0012 */ -constexpr int SAVE_DATA_ERROR_BACKUP_BUSY = -2137063405; /* 0x809F0013 */ -constexpr int SAVE_DATA_ERROR_NOT_REGIST_CALLBACK = -2137063403; /* 0x809F0015 */ -constexpr int SAVE_DATA_ERROR_BUSY_FOR_SAVING = -2137063402; /* 0x809F0016 */ -constexpr int SAVE_DATA_ERROR_LIMITATION_OVER = -2137063401; /* 0x809F0017 */ -constexpr int SAVE_DATA_ERROR_EVENT_BUSY = -2137063400; /* 0x809F0018 */ -constexpr int SAVE_DATA_ERROR_PARAMSFO_TRANSFER_TITLE_ID_NOT_FOUND = -2137063399; /* 0x809F0019 */ +constexpr int SAVE_DATA_ERROR_PARAMETER = -2137063424; +constexpr int SAVE_DATA_ERROR_NOT_INITIALIZED = -2137063423; +constexpr int SAVE_DATA_ERROR_OUT_OF_MEMORY = -2137063422; +constexpr int SAVE_DATA_ERROR_BUSY = -2137063421; +constexpr int SAVE_DATA_ERROR_NOT_MOUNTED = -2137063420; +constexpr int SAVE_DATA_ERROR_NO_PERMISSION = -2137063419; +constexpr int SAVE_DATA_ERROR_FINGERPRINT_MISMATCH = -2137063418; +constexpr int SAVE_DATA_ERROR_EXISTS = -2137063417; +constexpr int SAVE_DATA_ERROR_NOT_FOUND = -2137063416; +constexpr int SAVE_DATA_ERROR_NO_SPACE_FS = -2137063414; +constexpr int SAVE_DATA_ERROR_INTERNAL = -2137063413; +constexpr int SAVE_DATA_ERROR_MOUNT_FULL = -2137063412; +constexpr int SAVE_DATA_ERROR_BAD_MOUNTED = -2137063411; +constexpr int SAVE_DATA_ERROR_FILE_NOT_FOUND = -2137063410; +constexpr int SAVE_DATA_ERROR_BROKEN = -2137063409; +constexpr int SAVE_DATA_ERROR_INVALID_LOGIN_USER = -2137063407; +constexpr int SAVE_DATA_ERROR_MEMORY_NOT_READY = -2137063406; +constexpr int SAVE_DATA_ERROR_BACKUP_BUSY = -2137063405; +constexpr int SAVE_DATA_ERROR_NOT_REGIST_CALLBACK = -2137063403; +constexpr int SAVE_DATA_ERROR_BUSY_FOR_SAVING = -2137063402; +constexpr int SAVE_DATA_ERROR_LIMITATION_OVER = -2137063401; +constexpr int SAVE_DATA_ERROR_EVENT_BUSY = -2137063400; +constexpr int SAVE_DATA_ERROR_PARAMSFO_TRANSFER_TITLE_ID_NOT_FOUND = -2137063399; } // namespace Err