]> Chaos Git - corbenik/ctrulib.git/commitdiff
Updated APT_CheckNew3DS to only use the APT cmds once(which also now calls aptOpenSes...
authoryellows8 <yellows8@users.noreply.github.com>
Sun, 2 Nov 2014 03:48:35 +0000 (23:48 -0400)
committeryellows8 <yellows8@users.noreply.github.com>
Sun, 2 Nov 2014 03:48:35 +0000 (23:48 -0400)
libctru/include/3ds/services/apt.h
libctru/source/services/apt.c
libctru/source/services/hid.c
libctru/source/services/irrst.c

index 3092f99ed667b0bc5593826fb183f083a9d327f9..bec85f733cdf84ce8698e0e7312ed3d2635c828f 100644 (file)
@@ -69,7 +69,7 @@ Result APT_PrepareToCloseApplication(Handle* handle, u8 a);
 Result APT_CloseApplication(Handle* handle, u32 a, u32 b, u32 c);
 Result APT_SetAppCpuTimeLimit(Handle* handle, u32 percent);
 Result APT_GetAppCpuTimeLimit(Handle* handle, u32 *percent);
-Result APT_CheckNew3DS_Application(Handle* handle, u8 *out);//*Application and *System use APT commands 0x01010000 and 0x01020000. Using APT_CheckNew3DS() is recommended, this determines which of those two funcs to use automatically.
+Result APT_CheckNew3DS_Application(Handle* handle, u8 *out);//*Application and *System use APT commands 0x01010000 and 0x01020000. Using APT_CheckNew3DS() is recommended, this determines which of those two funcs to use automatically. When this is first called(this calls aptOpenSession/aptCloseSession internally), this initializes an internal flag, which is then used for the out val for all future calls.
 Result APT_CheckNew3DS_System(Handle* handle, u8 *out);
 Result APT_CheckNew3DS(Handle* handle, u8 *out);
 
index 91e1c175376c0812867556d640a5f7f5c38662a4..9294f1a1ffd4f7a15f10155275e8128e3863d303 100644 (file)
@@ -17,6 +17,9 @@ NS_APPID currentAppId;
 static char *__apt_servicestr = NULL;
 static char *__apt_servicenames[3] = {"APT:U", "APT:S", "APT:A"};
 
+static u32 __apt_new3dsflag_initialized = 0;
+static u8 __apt_new3dsflag = 0;
+
 Handle aptLockHandle;
 Handle aptuHandle;
 Handle aptEvents[3];
@@ -838,7 +841,22 @@ Result APT_CheckNew3DS_System(Handle* handle, u8 *out)
 
 Result APT_CheckNew3DS(Handle* handle, u8 *out)
 {
-       if(currentAppId==APPID_APPLICATION)return APT_CheckNew3DS_Application(NULL, out);
-       return APT_CheckNew3DS_System(NULL, out);
+       Result ret=0;
+
+       if(__apt_new3dsflag_initialized)
+       {
+               *out = __apt_new3dsflag;
+               return 0;
+       }
+
+       aptOpenSession();
+       if(currentAppId==APPID_APPLICATION)ret = APT_CheckNew3DS_Application(NULL, out);
+       ret = APT_CheckNew3DS_System(NULL, out);
+       aptCloseSession();
+
+       __apt_new3dsflag_initialized = 1;
+       __apt_new3dsflag = *out;
+
+       return ret;
 }
 
index cc17b688414ea76f9b5794422ab3a955768f303e..d48f30c91f3401e8e0fa4116fe39785589c9288d 100644 (file)
@@ -21,6 +21,8 @@ static angularRate gRate;
 
 Result hidInit(u32* sharedMem)
 {
+       u8 val=0;
+
        if(!sharedMem)sharedMem=(u32*)HID_SHAREDMEM_DEFAULT;
        Result ret=0;
 
@@ -34,9 +36,16 @@ Result hidInit(u32* sharedMem)
        hidSharedMem=sharedMem;
        if((ret=svcMapMemoryBlock(hidMemHandle, (u32)hidSharedMem, MEMPERM_READ, 0x10000000)))goto cleanup2;
 
+       APT_CheckNew3DS(NULL, &val);
+
+       if(val)
+       {
+               ret = irrstInit(NULL);
+       }
+
        // Reset internal state.
        kOld = kHeld = kDown = kUp = 0;
-       return 0;
+       return ret;
 
 cleanup2:
        svcCloseHandle(hidMemHandle);
@@ -48,10 +57,18 @@ cleanup1:
 void hidExit()
 {
        // Unmap HID sharedmem and close handles.
+       u8 val=0;
        int i; for(i=0; i<5; i++)svcCloseHandle(hidEvents[i]);
        svcUnmapMemoryBlock(hidMemHandle, (u32)hidSharedMem);
        svcCloseHandle(hidMemHandle);
        svcCloseHandle(hidHandle);
+
+       APT_CheckNew3DS(NULL, &val);
+
+       if(val)
+       {
+               irrstExit();
+       }
 }
 
 void hidWaitForEvent(HID_Event id, bool nextEvent)
index 87121ac277a567ef121a8916c7d0245b8e697881..c7a54ff3eacc86cc2638a4e6007c219990b9ca1d 100644 (file)
@@ -17,6 +17,8 @@ static bool irrstUsed = false;
 
 Result irrstInit(u32* sharedMem)
 {
+       if(irrstUsed)return 0;
+
        if(!sharedMem)sharedMem=(u32*)IRRST_SHAREDMEM_DEFAULT;
        Result ret=0;
 
@@ -44,6 +46,8 @@ cleanup1:
 
 void irrstExit()
 {
+       if(!irrstUsed)return;
+
        irrstUsed = false;
        svcCloseHandle(irrstEvent);
        // Unmap ir:rst sharedmem and close handles.