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);
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];
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;
}
Result hidInit(u32* sharedMem)
{
+ u8 val=0;
+
if(!sharedMem)sharedMem=(u32*)HID_SHAREDMEM_DEFAULT;
Result ret=0;
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);
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)
Result irrstInit(u32* sharedMem)
{
+ if(irrstUsed)return 0;
+
if(!sharedMem)sharedMem=(u32*)IRRST_SHAREDMEM_DEFAULT;
Result ret=0;
void irrstExit()
{
+ if(!irrstUsed)return;
+
irrstUsed = false;
svcCloseHandle(irrstEvent);
// Unmap ir:rst sharedmem and close handles.