From 7c28d9accecd155b21b67f7d2f3087915a5dca31 Mon Sep 17 00:00:00 2001 From: smea Date: Sat, 1 Feb 2014 19:56:36 +0100 Subject: [PATCH] APT : added ability to specify APPID to aptInit --- arm11u/source/main.c | 2 +- libctru/include/ctr/APT.h | 12 +++++++++--- libctru/include/ctr/SOC.h | 1 - libctru/include/ctr/svc.h | 2 +- libctru/source/APT.c | 29 ++++++++++++++++++----------- sdmc/source/main.c | 2 +- 6 files changed, 30 insertions(+), 18 deletions(-) diff --git a/arm11u/source/main.c b/arm11u/source/main.c index 3f49a56..1cfed16 100644 --- a/arm11u/source/main.c +++ b/arm11u/source/main.c @@ -104,7 +104,7 @@ int main() { initSrv(); - aptInit(); + aptInit(APPID_APPLICATION); gspGpuInit(); diff --git a/libctru/include/ctr/APT.h b/libctru/include/ctr/APT.h index 60e7d75..505d7cd 100644 --- a/libctru/include/ctr/APT.h +++ b/libctru/include/ctr/APT.h @@ -8,15 +8,21 @@ typedef enum{ 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); diff --git a/libctru/include/ctr/SOC.h b/libctru/include/ctr/SOC.h index 4008230..2bb2e7c 100644 --- a/libctru/include/ctr/SOC.h +++ b/libctru/include/ctr/SOC.h @@ -6,4 +6,3 @@ Result SOC_Shutdown(); int SOC_GetErrno(); #endif - diff --git a/libctru/include/ctr/svc.h b/libctru/include/ctr/svc.h index e156616..e66fe78 100644 --- a/libctru/include/ctr/svc.h +++ b/libctru/include/ctr/svc.h @@ -3,13 +3,13 @@ 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); diff --git a/libctru/source/APT.c b/libctru/source/APT.c index 78e097e..e533fce 100644 --- a/libctru/source/APT.c +++ b/libctru/source/APT.c @@ -9,6 +9,8 @@ #define APT_HANDLER_STACKSIZE (0x10000) +NS_APPID currentAppId; + Handle aptLockHandle; Handle aptuHandle; Handle aptEvents[3]; @@ -37,7 +39,7 @@ void aptEventHandler(u32 arg) u8 signalType; aptOpenSession(); - APT_InquireNotification(NULL, APPID_APPLICATION, &signalType); //check signal type + APT_InquireNotification(NULL, currentAppId, &signalType); //check signal type aptCloseSession(); switch(signalType) @@ -46,6 +48,8 @@ void aptEventHandler(u32 arg) aptOpenSession(); APT_PrepareToJumpToHomeMenu(NULL); //prepare for return to menu aptCloseSession(); + + aptSetStatus(APP_SUSPENDED); GSPGPU_ReleaseRight(NULL); //disable GSP module access @@ -56,11 +60,11 @@ void aptEventHandler(u32 arg) } } 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) @@ -69,14 +73,15 @@ void aptEventHandler(u32 arg) 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; } } @@ -89,15 +94,17 @@ void aptEventHandler(u32 arg) 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(); @@ -105,7 +112,7 @@ void aptInit() aptCloseSession(); aptOpenSession(); - APT_NotifyToWait(NULL, APPID_APPLICATION); + APT_NotifyToWait(NULL, currentAppId); aptCloseSession(); } @@ -154,16 +161,16 @@ void aptSetupEventHandler() 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; diff --git a/sdmc/source/main.c b/sdmc/source/main.c index 9039842..f842633 100644 --- a/sdmc/source/main.c +++ b/sdmc/source/main.c @@ -106,7 +106,7 @@ int main() { initSrv(); - aptInit(); + aptInit(APPID_APPLICATION); gspGpuInit();