From 47e6268e236e0f133c1e36b363abee05895824ff Mon Sep 17 00:00:00 2001 From: TuxSH <1922548+TuxSH@users.noreply.github.com> Date: Sun, 17 May 2020 18:17:38 +0100 Subject: [PATCH] Add ptm rtc time commands --- libctru/include/3ds/services/ptmsysm.h | 15 ++++++++++++ libctru/source/services/ptmsysm.c | 33 ++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/libctru/include/3ds/services/ptmsysm.h b/libctru/include/3ds/services/ptmsysm.h index f39af46..a1b7053 100644 --- a/libctru/include/3ds/services/ptmsysm.h +++ b/libctru/include/3ds/services/ptmsysm.h @@ -81,6 +81,21 @@ Result PTMSYSM_GetWakeReason(PtmSleepConfig *outSleepConfig); /// Cancels the "half-awake" state and fully wakes up the 3DS after some delay. Result PTMSYSM_Awaken(void); +/// Invalidates the "system time" (cfg block 0x30002) +Result PTMSYSM_InvalidateSystemTime(void); + +/** + * @brief Reads the time and date coming from the RTC and converts the result. + * @returns The number of milliseconds since 01/01/2000. + */ +Result PTMSYSM_GetRtcTime(s64 *outMsY2k); + +/** + * @brief Writes the time and date coming to the RTC, after conversion. + * @param msY2k The number of milliseconds since 01/01/2000. + */ +Result PTMSYSM_SetRtcTime(s64 msY2k); + /** * @brief Returns 1 if it's a New 3DS, otherwise 0. */ diff --git a/libctru/source/services/ptmsysm.c b/libctru/source/services/ptmsysm.c index de9d2ad..b9b1b85 100644 --- a/libctru/source/services/ptmsysm.c +++ b/libctru/source/services/ptmsysm.c @@ -143,3 +143,36 @@ Result PTMSYSM_RebootAsync(u64 timeout) return (Result)cmdbuf[1]; } + +Result PTMSYSM_InvalidateSystemTime(void) +{ + Result ret; + u32 *cmdbuf = getThreadCommandBuffer(); + cmdbuf[0] = IPC_MakeHeader(0x080D,0,0); // 0x080D0000 + + if(R_FAILED(ret = svcSendSyncRequest(ptmSysmHandle)))return ret; + + return (Result)cmdbuf[1]; +} + +Result PTMSYSM_GetRtcTime(s64 *outMsY2k) +{ + Result ret; + u32 *cmdbuf = getThreadCommandBuffer(); + cmdbuf[0] = IPC_MakeHeader(0x0816,0,0); // 0x08160000 + if(R_FAILED(ret = svcSendSyncRequest(ptmSysmHandle)))return ret; + memcpy(outMsY2k, &cmdbuf[2], 8); + + return (Result)cmdbuf[1]; +} + +Result PTMSYSM_SetRtcTime(s64 msY2k) +{ + Result ret; + u32 *cmdbuf = getThreadCommandBuffer(); + cmdbuf[0] = IPC_MakeHeader(0x0817,2,0); // 0x08170080 + memcpy(&cmdbuf[1], &msY2k, 8); + if(R_FAILED(ret = svcSendSyncRequest(ptmSysmHandle)))return ret; + + return (Result)cmdbuf[1]; +}