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..552d8fc95 100644 --- a/libctru/source/services/apt.c +++ b/libctru/source/services/apt.c @@ -909,6 +909,31 @@ 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); + + GSPGPU_SaveVramSysArea(); + GSPGPU_ReleaseRight(); + + aptSetSleepAllowed(false); + APT_StartSystemApplet(appId, buf, bufsize, handle); + aptFlags &= ~FLAG_ACTIVE; + + aptScreenTransfer(appId, true); + + aptWaitForWakeUp(TR_SYSAPPLET); + memcpy(buf, aptParameters, bufsize); + aptSetSleepAllowed(sleep); +} + Result APT_GetLockHandle(u16 flags, Handle* lockHandle) { u32 cmdbuf[16];