Skip to content

Commit

Permalink
apt: Add aptLaunchSystemApplet (#557)
Browse files Browse the repository at this point in the history
Needed for launching system applets like the Miiverse posting applet
"solv3". The screen transfer is expected to be done after launching the
applet.
  • Loading branch information
DaniElectra authored Feb 9, 2025
1 parent 1b1762f commit a88ab66
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions libctru/include/3ds/services/apt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
25 changes: 25 additions & 0 deletions libctru/source/services/apt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit a88ab66

Please sign in to comment.