From 1442b1d6122abe59091391df1d32ba5cfcac9c38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B3pez=20Guimaraes?= Date: Sun, 9 Feb 2025 12:02:04 +0000 Subject: [PATCH 1/2] apt: Add aptLaunchSystemApplet Needed for launching system applets like the Miiverse posting applet "solv3". The screen transfer is expected to be done after launching the applet. --- libctru/include/3ds/services/apt.h | 9 +++++++++ libctru/source/services/apt.c | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/libctru/include/3ds/services/apt.h b/libctru/include/3ds/services/apt.h index 4e9de7e97..7dc2fc672 100644 --- a/libctru/include/3ds/services/apt.h +++ b/libctru/include/3ds/services/apt.h @@ -227,6 +227,15 @@ void aptSetMessageCallback(aptMessageCb callback, void* user); */ void aptLaunchLibraryApplet(NS_APPID appId, void* buf, size_t bufsize, Handle handle); +/** + * @brief Launches a system applet. + * @param appId ID of the applet to launch. + * @param buf Input/output buffer that contains launch parameters on entry and result data on exit. + * @param bufsize Size of the buffer. + * @param handle Handle to pass to the system applet. + */ +void aptLaunchSystemApplet(NS_APPID appId, void* buf, size_t bufsize, Handle handle); + /// Clears the chainloader state. void aptClearChainloader(void); diff --git a/libctru/source/services/apt.c b/libctru/source/services/apt.c index 93743de1d..2b254981f 100644 --- a/libctru/source/services/apt.c +++ b/libctru/source/services/apt.c @@ -909,6 +909,30 @@ void aptLaunchLibraryApplet(NS_APPID appId, void* buf, size_t bufsize, Handle ha aptSetSleepAllowed(sleep); } +void aptLaunchSystemApplet(NS_APPID appId, void* buf, size_t bufsize, Handle handle) +{ + bool sleep = aptIsSleepAllowed(); + + aptSetSleepAllowed(false); + aptFlags &= ~FLAG_SPURIOUS; // If we haven't received a spurious wakeup by now, we probably never will (see aptInit) + APT_PrepareToStartSystemApplet(appId); + aptSetSleepAllowed(sleep); + + aptCallHook(APTHOOK_ONSUSPEND); + + aptSetSleepAllowed(false); + APT_StartSystemApplet(appId, buf, bufsize, handle); + aptFlags &= ~FLAG_ACTIVE; + + GSPGPU_SaveVramSysArea(); + aptScreenTransfer(appId, true); + GSPGPU_ReleaseRight(); + + aptWaitForWakeUp(TR_SYSAPPLET); + memcpy(buf, aptParameters, bufsize); + aptSetSleepAllowed(sleep); +} + Result APT_GetLockHandle(u16 flags, Handle* lockHandle) { u32 cmdbuf[16]; From 6fc8e527420bb396c78165e794a87fa8cf3ee1de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B3pez=20Guimaraes?= Date: Sun, 9 Feb 2025 18:16:52 +0000 Subject: [PATCH 2/2] apt: Save and release screen before launching system applet --- libctru/source/services/apt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libctru/source/services/apt.c b/libctru/source/services/apt.c index 2b254981f..552d8fc95 100644 --- a/libctru/source/services/apt.c +++ b/libctru/source/services/apt.c @@ -920,13 +920,14 @@ void aptLaunchSystemApplet(NS_APPID appId, void* buf, size_t bufsize, Handle han aptCallHook(APTHOOK_ONSUSPEND); + GSPGPU_SaveVramSysArea(); + GSPGPU_ReleaseRight(); + aptSetSleepAllowed(false); APT_StartSystemApplet(appId, buf, bufsize, handle); aptFlags &= ~FLAG_ACTIVE; - GSPGPU_SaveVramSysArea(); aptScreenTransfer(appId, true); - GSPGPU_ReleaseRight(); aptWaitForWakeUp(TR_SYSAPPLET); memcpy(buf, aptParameters, bufsize);