APPID_APPLICATION = 0x300, // Application
}NS_APPID; // cf http://3dbrew.org/wiki/NS#AppIDs
+typedef enum{
+ APP_RUNNING,
+ APP_SUSPENDED,
+ APP_EXITING
+}APP_STATUS;
+
extern Handle aptEvents[3];
-void aptInit();
+void aptInit(NS_APPID appID);
void aptExit();
void aptOpenSession();
void aptCloseSession();
void aptSetupEventHandler();
-u32 aptGetStatus();
-void aptSetStatus(u32 status);
+void aptSetStatus(APP_STATUS status);
+APP_STATUS aptGetStatus();
Result APT_GetLockHandle(Handle* handle, u16 flags, Handle* lockHandle);
Result APT_Initialize(Handle* handle, NS_APPID appId, Handle* eventHandle1, Handle* eventHandle2);
u32* getThreadCommandBuffer(void);
+ Result svc_controlMemory(u32* outaddr, u32 addr0, u32 addr1, u32 size, u32 operation, u32 permissions); //(outaddr is usually the same as the input addr0)
void svc_exitProcess(void);
Result svc_createThread(Handle* thread, ThreadFunc entrypoint, u32 arg, u32* stacktop, s32 threadpriority, s32 processorid);
void svc_exitThread();
void svc_sleepThread(s64 ns);
Result svc_createMutex(Handle* mutex, bool initialLocked);
Result svc_releaseMutex(Handle handle);
- Result svc_controlMemory(u32* outaddr, u32 addr0, u32 addr1, u32 size, u32 operation, u32 permissions); //(outaddr is usually the same as the input addr0)
Result svc_createEvent(Handle* event, u8 resettype);
Result svc_clearEvent(Handle handle);
Result svc_createMemoryBlock(Handle* memblock, u32 addr, u32 size, u32 mypermission, u32 otherpermission);
#define APT_HANDLER_STACKSIZE (0x10000)
+NS_APPID currentAppId;
+
Handle aptLockHandle;
Handle aptuHandle;
Handle aptEvents[3];
u8 signalType;
aptOpenSession();
- APT_InquireNotification(NULL, APPID_APPLICATION, &signalType); //check signal type
+ APT_InquireNotification(NULL, currentAppId, &signalType); //check signal type
aptCloseSession();
switch(signalType)
aptOpenSession();
APT_PrepareToJumpToHomeMenu(NULL); //prepare for return to menu
aptCloseSession();
+
+ aptSetStatus(APP_SUSPENDED);
GSPGPU_ReleaseRight(NULL); //disable GSP module access
}
}
break;
- case 0x1: //event 1 means app just started or we're returning to app
+ case 0x1: //event 1 means app just started, we're returning to app, exiting app etc.
{
u8 signalType;
aptOpenSession();
- APT_ReceiveParameter(NULL, APPID_APPLICATION, 0x1000, aptParameters, NULL, &signalType);
+ APT_ReceiveParameter(NULL, currentAppId, 0x1000, aptParameters, NULL, &signalType);
aptCloseSession();
switch(signalType)
break;
case 0xB: //just returned from menu
GSPGPU_AcquireRight(NULL, 0x0);
+ aptSetStatus(APP_RUNNING);
break;
case 0xC: //exiting application
aptOpenSession();
- APT_ReplySleepQuery(NULL, APPID_APPLICATION, 0x0);
+ APT_ReplySleepQuery(NULL, currentAppId, 0x0);
aptCloseSession();
runThread=false;
- aptSetStatus(1); //app exit signal
+ aptSetStatus(APP_EXITING); //app exit signal
break;
}
}
svc_exitThread();
}
-void aptInit()
+void aptInit(NS_APPID appID)
{
//initialize APT stuff, escape load screen
srv_getServiceHandle(NULL, &aptuHandle, "APT:U");
APT_GetLockHandle(&aptuHandle, 0x0, &aptLockHandle);
svc_closeHandle(aptuHandle);
+ currentAppId=appID;
+
aptOpenSession();
- APT_Initialize(NULL, APPID_APPLICATION, &aptEvents[0], &aptEvents[1]);
+ APT_Initialize(NULL, currentAppId, &aptEvents[0], &aptEvents[1]);
aptCloseSession();
aptOpenSession();
aptCloseSession();
aptOpenSession();
- APT_NotifyToWait(NULL, APPID_APPLICATION);
+ APT_NotifyToWait(NULL, currentAppId);
aptCloseSession();
}
svc_createThread(&aptEventHandlerThread, aptEventHandler, 0x0, (u32*)(&aptEventHandlerStack[APT_HANDLER_STACKSIZE/8]), 0x31, 0xfffffffe);
}
-u32 aptGetStatus()
+APP_STATUS aptGetStatus()
{
- u32 ret;
+ APP_STATUS ret;
svc_waitSynchronization1(aptStatusMutex, U64_MAX);
ret=aptStatus;
svc_releaseMutex(aptStatusMutex);
return ret;
}
-void aptSetStatus(u32 status)
+void aptSetStatus(APP_STATUS status)
{
svc_waitSynchronization1(aptStatusMutex, U64_MAX);
aptStatus=status;