Remove service handle parameter from APT IPC wrappers

This commit is contained in:
fincs 2015-09-06 17:41:47 +02:00
parent 15af3eff30
commit 9b1e6bfc39
4 changed files with 180 additions and 223 deletions

View File

@ -71,55 +71,55 @@ typedef struct tag_aptHookCookie
extern Handle aptEvents[3]; extern Handle aptEvents[3];
Result aptInit(); Result aptInit(void);
void aptExit(); void aptExit(void);
void aptOpenSession(); void aptOpenSession(void);
void aptCloseSession(); void aptCloseSession(void);
void aptSetStatus(APP_STATUS status); void aptSetStatus(APP_STATUS status);
APP_STATUS aptGetStatus(); APP_STATUS aptGetStatus(void);
u32 aptGetStatusPower();//This can be used when the status is APP_SUSPEND* to check how the return-to-menu was triggered: 0 = home-button, 1 = power-button. u32 aptGetStatusPower(void);//This can be used when the status is APP_SUSPEND* to check how the return-to-menu was triggered: 0 = home-button, 1 = power-button.
void aptSetStatusPower(u32 status); void aptSetStatusPower(u32 status);
void aptReturnToMenu();//This should be called by the user application when aptGetStatus() returns APP_SUSPENDING, not calling this will result in return-to-menu being disabled with the status left at APP_SUSPENDING. This function will not return until the system returns to the application, or when the status was changed to APP_EXITING. void aptReturnToMenu(void);//This should be called by the user application when aptGetStatus() returns APP_SUSPENDING, not calling this will result in return-to-menu being disabled with the status left at APP_SUSPENDING. This function will not return until the system returns to the application, or when the status was changed to APP_EXITING.
void aptWaitStatusEvent(); void aptWaitStatusEvent(void);
void aptSignalReadyForSleep(); void aptSignalReadyForSleep(void);
NS_APPID aptGetMenuAppID(); NS_APPID aptGetMenuAppID(void);
bool aptMainLoop(); // Use like this in your main(): while (aptMainLoop()) { your code here... } bool aptMainLoop(void); // Use like this in your main(): while (aptMainLoop()) { your code here... }
void aptHook(aptHookCookie* cookie, aptHookFn callback, void* param); void aptHook(aptHookCookie* cookie, aptHookFn callback, void* param);
void aptUnhook(aptHookCookie* cookie); void aptUnhook(aptHookCookie* cookie);
Result APT_GetLockHandle(Handle* handle, u16 flags, Handle* lockHandle); Result APT_GetLockHandle(u16 flags, Handle* lockHandle);
Result APT_Initialize(Handle* handle, NS_APPID appId, Handle* eventHandle1, Handle* eventHandle2); Result APT_Initialize(NS_APPID appId, Handle* eventHandle1, Handle* eventHandle2);
Result APT_Finalize(Handle* handle, NS_APPID appId); Result APT_Finalize(NS_APPID appId);
Result APT_HardwareResetAsync(Handle* handle); Result APT_HardwareResetAsync(void);
Result APT_Enable(Handle* handle, u32 a); Result APT_Enable(u32 a);
Result APT_GetAppletManInfo(Handle* handle, u8 inval, u8 *outval8, u32 *outval32, NS_APPID *menu_appid, NS_APPID *active_appid); Result APT_GetAppletManInfo(u8 inval, u8 *outval8, u32 *outval32, NS_APPID *menu_appid, NS_APPID *active_appid);
Result APT_PrepareToJumpToHomeMenu(Handle* handle); Result APT_PrepareToJumpToHomeMenu(void);
Result APT_JumpToHomeMenu(Handle* handle, u32 a, u32 b, u32 c); Result APT_JumpToHomeMenu(u32 a, u32 b, u32 c);
Result APT_PrepareToJumpToApplication(Handle* handle, u32 a); Result APT_PrepareToJumpToApplication(u32 a);
Result APT_JumpToApplication(Handle* handle, u32 a, u32 b, u32 c); Result APT_JumpToApplication(u32 a, u32 b, u32 c);
Result APT_IsRegistered(Handle* handle, NS_APPID appID, u8* out); Result APT_IsRegistered(NS_APPID appID, u8* out);
Result APT_InquireNotification(Handle* handle, u32 appID, u8* signalType); Result APT_InquireNotification(u32 appID, u8* signalType);
Result APT_NotifyToWait(Handle* handle, NS_APPID appID); Result APT_NotifyToWait(NS_APPID appID);
Result APT_AppletUtility(Handle* handle, u32* out, u32 a, u32 size1, u8* buf1, u32 size2, u8* buf2); Result APT_AppletUtility(u32* out, u32 a, u32 size1, u8* buf1, u32 size2, u8* buf2);
Result APT_GlanceParameter(Handle* handle, NS_APPID appID, u32 bufferSize, u32* buffer, u32* actualSize, u8* signalType); Result APT_GlanceParameter(NS_APPID appID, u32 bufferSize, u32* buffer, u32* actualSize, u8* signalType);
Result APT_ReceiveParameter(Handle* handle, NS_APPID appID, u32 bufferSize, u32* buffer, u32* actualSize, u8* signalType); Result APT_ReceiveParameter(NS_APPID appID, u32 bufferSize, u32* buffer, u32* actualSize, u8* signalType);
Result APT_SendParameter(Handle* handle, NS_APPID src_appID, NS_APPID dst_appID, u32 bufferSize, u32* buffer, Handle paramhandle, u8 signalType); Result APT_SendParameter(NS_APPID src_appID, NS_APPID dst_appID, u32 bufferSize, u32* buffer, Handle paramhandle, u8 signalType);
Result APT_SendCaptureBufferInfo(Handle* handle, u32 bufferSize, u32* buffer); Result APT_SendCaptureBufferInfo(u32 bufferSize, u32* buffer);
Result APT_ReplySleepQuery(Handle* handle, NS_APPID appID, u32 a); Result APT_ReplySleepQuery(NS_APPID appID, u32 a);
Result APT_ReplySleepNotificationComplete(Handle* handle, NS_APPID appID); Result APT_ReplySleepNotificationComplete(NS_APPID appID);
Result APT_PrepareToCloseApplication(Handle* handle, u8 a); Result APT_PrepareToCloseApplication(u8 a);
Result APT_CloseApplication(Handle* handle, u32 a, u32 b, u32 c); Result APT_CloseApplication(u32 a, u32 b, u32 c);
Result APT_SetAppCpuTimeLimit(Handle* handle, u32 percent); Result APT_SetAppCpuTimeLimit(u32 percent);
Result APT_GetAppCpuTimeLimit(Handle* handle, u32 *percent); Result APT_GetAppCpuTimeLimit(u32 *percent);
Result APT_CheckNew3DS_Application(Handle* handle, u8 *out);// Note: this function is unreliable, see: http://3dbrew.org/wiki/APT:PrepareToStartApplication Result APT_CheckNew3DS_Application(u8 *out);// Note: this function is unreliable, see: http://3dbrew.org/wiki/APT:PrepareToStartApplication
Result APT_CheckNew3DS_System(Handle* handle, u8 *out); Result APT_CheckNew3DS_System(u8 *out);
Result APT_CheckNew3DS(Handle* handle, u8 *out); Result APT_CheckNew3DS(u8 *out);
Result APT_PrepareToDoAppJump(Handle* handle, u8 flags, u64 programID, u8 mediatype); Result APT_PrepareToDoAppJump(u8 flags, u64 programID, u8 mediatype);
Result APT_DoAppJump(Handle* handle, u32 NSbuf0Size, u32 NSbuf1Size, u8 *NSbuf0Ptr, u8 *NSbuf1Ptr); Result APT_DoAppJump(u32 NSbuf0Size, u32 NSbuf1Size, u8 *NSbuf0Ptr, u8 *NSbuf1Ptr);
Result APT_PrepareToStartLibraryApplet(Handle* handle, NS_APPID appID); Result APT_PrepareToStartLibraryApplet(NS_APPID appID);
Result APT_StartLibraryApplet(Handle* handle, NS_APPID appID, Handle inhandle, u32 *parambuf, u32 parambufsize); Result APT_StartLibraryApplet(NS_APPID appID, Handle inhandle, u32 *parambuf, u32 parambufsize);
Result APT_LaunchLibraryApplet(NS_APPID appID, Handle inhandle, u32 *parambuf, u32 parambufsize);//This should be used for launching library applets, this uses the above APT_StartLibraryApplet/APT_PrepareToStartLibraryApplet funcs + apt*Session(). parambuf is used for APT params input, when the applet closes the output param block is copied here. This is not usable from the homebrew launcher. This is broken: when the applet does get launched at all, the applet process doesn't actually get terminated when the applet gets closed. Result APT_LaunchLibraryApplet(NS_APPID appID, Handle inhandle, u32 *parambuf, u32 parambufsize);//This should be used for launching library applets, this uses the above APT_StartLibraryApplet/APT_PrepareToStartLibraryApplet funcs + apt*Session(). parambuf is used for APT params input, when the applet closes the output param block is copied here. This is not usable from the homebrew launcher. This is broken: when the applet does get launched at all, the applet process doesn't actually get terminated when the applet gets closed.
Result APT_PrepareToStartSystemApplet(Handle* handle, NS_APPID appID); Result APT_PrepareToStartSystemApplet(NS_APPID appID);
Result APT_StartSystemApplet(Handle* handle, NS_APPID appID, u32 bufSize, Handle applHandle, u8 *buf); Result APT_StartSystemApplet(NS_APPID appID, u32 bufSize, Handle applHandle, u8 *buf);

View File

@ -90,14 +90,20 @@ void GPUCMD_Finalize(void)
GPUCMD_AddWrite(GPUREG_FINALIZE, 0x12345678); //not the cleanest way of guaranteeing 0x10-byte size but whatever good enough for now GPUCMD_AddWrite(GPUREG_FINALIZE, 0x12345678); //not the cleanest way of guaranteeing 0x10-byte size but whatever good enough for now
} }
static inline u32 floatrawbits(float f)
{
union { float f; u32 i; } s;
s.f = f;
return s.i;
}
// f24 has: // f24 has:
// - 1 sign bit // - 1 sign bit
// - 7 exponent bits // - 7 exponent bits
// - 16 mantissa bits // - 16 mantissa bits
u32 f32tof24(float f) u32 f32tof24(float f)
{ {
u32 i; u32 i = floatrawbits(f);
memcpy(&i, &f, 4);
u32 mantissa = (i << 9) >> 9; u32 mantissa = (i << 9) >> 9;
s32 exponent = (i << 1) >> 24; s32 exponent = (i << 1) >> 24;
@ -128,8 +134,7 @@ u32 f32tof24(float f)
// - 23 mantissa bits // - 23 mantissa bits
u32 f32tof31(float f) u32 f32tof31(float f)
{ {
u32 i; u32 i = floatrawbits(f);
memcpy(&i, &f, 4);
u32 mantissa = (i << 9) >> 9; u32 mantissa = (i << 9) >> 9;
s32 exponent = (i << 1) >> 24; s32 exponent = (i << 1) >> 24;

View File

@ -74,7 +74,7 @@ static bool aptIsCrippled(void)
return (__system_runflags & RUNFLAG_APTWORKAROUND) != 0 && !aptIsReinit(); return (__system_runflags & RUNFLAG_APTWORKAROUND) != 0 && !aptIsReinit();
} }
static Result __apt_initservicehandle() static Result __apt_initservicehandle(void)
{ {
Result ret=0; Result ret=0;
u32 i; u32 i;
@ -126,7 +126,7 @@ void aptInitCaptureInfo(u32 *ns_capinfo)
ns_capinfo[0] = main_pixsz * 0x7000 + tmp; ns_capinfo[0] = main_pixsz * 0x7000 + tmp;
} }
void aptWaitStatusEvent() void aptWaitStatusEvent(void)
{ {
svcWaitSynchronization(aptStatusEvent, U64_MAX); svcWaitSynchronization(aptStatusEvent, U64_MAX);
svcClearEvent(aptStatusEvent); svcClearEvent(aptStatusEvent);
@ -140,48 +140,48 @@ void aptAppletUtility_Exit_RetToApp(u32 type)
buf1[0]=0x10; buf1[0]=0x10;
aptOpenSession(); aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x7, 0x4, buf1, 0x1, buf2); APT_AppletUtility(NULL, 0x7, 0x4, buf1, 0x1, buf2);
aptCloseSession(); aptCloseSession();
buf1[0]=0x00; buf1[0]=0x00;
aptOpenSession(); aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x4, 0x1, buf1, 0x1, buf2); APT_AppletUtility(NULL, 0x4, 0x1, buf1, 0x1, buf2);
aptCloseSession(); aptCloseSession();
buf1[0]=0x01; buf1[0]=0x01;
aptOpenSession(); aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x7, 0x4, buf1, 0x1, buf2); APT_AppletUtility(NULL, 0x7, 0x4, buf1, 0x1, buf2);
aptCloseSession(); aptCloseSession();
buf1[0]=0x00; buf1[0]=0x00;
aptOpenSession(); aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x4, 0x1, buf1, 0x1, buf2); APT_AppletUtility(NULL, 0x4, 0x1, buf1, 0x1, buf2);
aptCloseSession(); aptCloseSession();
aptOpenSession(); aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x4, 0x1, buf1, 0x1, buf2); APT_AppletUtility(NULL, 0x4, 0x1, buf1, 0x1, buf2);
aptCloseSession(); aptCloseSession();
if(type) if(type)
{ {
aptOpenSession(); aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x4, 0x1, buf1, 0x1, buf2); APT_AppletUtility(NULL, 0x4, 0x1, buf1, 0x1, buf2);
aptCloseSession(); aptCloseSession();
} }
} }
NS_APPID aptGetMenuAppID() NS_APPID aptGetMenuAppID(void)
{ {
NS_APPID menu_appid; NS_APPID menu_appid;
aptOpenSession(); aptOpenSession();
APT_GetAppletManInfo(NULL, 0xff, NULL, NULL, &menu_appid, NULL); APT_GetAppletManInfo(0xff, NULL, NULL, &menu_appid, NULL);
aptCloseSession(); aptCloseSession();
return menu_appid; return menu_appid;
} }
void aptReturnToMenu() void aptReturnToMenu(void)
{ {
NS_APPID menu_appid; NS_APPID menu_appid;
u32 tmp0 = 1, tmp1 = 0; u32 tmp0 = 1, tmp1 = 0;
@ -197,7 +197,7 @@ void aptReturnToMenu()
if(aptGetStatusPower() == 0) if(aptGetStatusPower() == 0)
{ {
aptOpenSession(); aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x6, 0x4, (u8*)&tmp0, 0x1, (u8*)&tmp1); APT_AppletUtility(NULL, 0x6, 0x4, (u8*)&tmp0, 0x1, (u8*)&tmp1);
aptCloseSession(); aptCloseSession();
} }
@ -208,7 +208,7 @@ void aptReturnToMenu()
// Prepare for return to menu // Prepare for return to menu
aptOpenSession(); aptOpenSession();
APT_PrepareToJumpToHomeMenu(NULL); APT_PrepareToJumpToHomeMenu();
aptCloseSession(); aptCloseSession();
// Save Vram // Save Vram
@ -223,11 +223,11 @@ void aptReturnToMenu()
// Send capture-screen info to menu. // Send capture-screen info to menu.
aptOpenSession(); aptOpenSession();
APT_SendParameter(NULL, currentAppId, menu_appid, 0x20, __ns_capinfo, 0x0, 0x10); APT_SendParameter(currentAppId, menu_appid, 0x20, __ns_capinfo, 0x0, 0x10);
aptCloseSession(); aptCloseSession();
aptOpenSession(); aptOpenSession();
APT_SendCaptureBufferInfo(NULL, 0x20, __ns_capinfo); APT_SendCaptureBufferInfo(0x20, __ns_capinfo);
aptCloseSession(); aptCloseSession();
// Release GSP module. // Release GSP module.
@ -235,12 +235,12 @@ void aptReturnToMenu()
// Jump to menu! // Jump to menu!
aptOpenSession(); aptOpenSession();
APT_JumpToHomeMenu(NULL, 0x0, 0x0, 0x0); APT_JumpToHomeMenu(0x0, 0x0, 0x0);
aptCloseSession(); aptCloseSession();
// Wait for return to application. // Wait for return to application.
aptOpenSession(); aptOpenSession();
APT_NotifyToWait(NULL, currentAppId); APT_NotifyToWait(currentAppId);
aptCloseSession(); aptCloseSession();
// This is only executed when ret-to-menu was triggered via the home-button, not the power-button. // This is only executed when ret-to-menu was triggered via the home-button, not the power-button.
@ -248,14 +248,14 @@ void aptReturnToMenu()
{ {
tmp0 = 0; tmp0 = 0;
aptOpenSession(); aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x4, 0x1, (u8*)&tmp0, 0x1, (u8*)&tmp1); APT_AppletUtility(NULL, 0x4, 0x1, (u8*)&tmp0, 0x1, (u8*)&tmp1);
aptCloseSession(); aptCloseSession();
} }
aptWaitStatusEvent(); aptWaitStatusEvent();
} }
void aptAppletStarted() void aptAppletStarted(void)
{ {
u8 buf1[4], buf2[4]; u8 buf1[4], buf2[4];
@ -266,33 +266,33 @@ void aptAppletStarted()
aptSetStatus(APP_SUSPENDED); aptSetStatus(APP_SUSPENDED);
aptOpenSession(); aptOpenSession();
APT_SendCaptureBufferInfo(NULL, 0x20, __ns_capinfo); APT_SendCaptureBufferInfo(0x20, __ns_capinfo);
aptCloseSession(); aptCloseSession();
aptOpenSession(); aptOpenSession();
APT_ReplySleepQuery(NULL, currentAppId, 0x0); APT_ReplySleepQuery(currentAppId, 0x0);
aptCloseSession(); aptCloseSession();
aptOpenSession(); aptOpenSession();
APT_StartLibraryApplet(NULL, __apt_launchapplet_appID, __apt_launchapplet_inhandle, __apt_launchapplet_parambuf, __apt_launchapplet_parambufsize); APT_StartLibraryApplet(__apt_launchapplet_appID, __apt_launchapplet_inhandle, __apt_launchapplet_parambuf, __apt_launchapplet_parambufsize);
aptCloseSession(); aptCloseSession();
buf1[0]=0x00; buf1[0]=0x00;
aptOpenSession(); aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x4, 0x1, buf1, 0x1, buf2); APT_AppletUtility(NULL, 0x4, 0x1, buf1, 0x1, buf2);
aptCloseSession(); aptCloseSession();
aptOpenSession(); aptOpenSession();
APT_NotifyToWait(NULL, currentAppId); APT_NotifyToWait(currentAppId);
aptCloseSession(); aptCloseSession();
buf1[0]=0x00; buf1[0]=0x00;
aptOpenSession(); aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x4, 0x1, buf1, 0x1, buf2); APT_AppletUtility(NULL, 0x4, 0x1, buf1, 0x1, buf2);
aptCloseSession(); aptCloseSession();
} }
void aptAppletClosed() void aptAppletClosed(void)
{ {
aptAppletUtility_Exit_RetToApp(1); aptAppletUtility_Exit_RetToApp(1);
@ -304,13 +304,13 @@ void aptAppletClosed()
svcClearEvent(aptStatusEvent); svcClearEvent(aptStatusEvent);
} }
static void __handle_notification() { static void __handle_notification(void) {
u8 type; u8 type;
Result ret=0; Result ret=0;
// Get notification type. // Get notification type.
aptOpenSession(); aptOpenSession();
ret = APT_InquireNotification(NULL, currentAppId, &type); ret = APT_InquireNotification(currentAppId, &type);
aptCloseSession(); aptCloseSession();
if(ret!=0) return; if(ret!=0) return;
@ -324,7 +324,7 @@ static void __handle_notification() {
if(aptGetStatus() == APP_RUNNING) if(aptGetStatus() == APP_RUNNING)
{ {
aptOpenSession(); aptOpenSession();
APT_ReplySleepQuery(NULL, currentAppId, 0x0); APT_ReplySleepQuery(currentAppId, 0x0);
aptCloseSession(); aptCloseSession();
if(type == APTSIGNAL_HOMEBUTTON) aptSetStatusPower(0); if(type == APTSIGNAL_HOMEBUTTON) aptSetStatusPower(0);
@ -341,7 +341,7 @@ static void __handle_notification() {
svcClearEvent(aptSleepSync); svcClearEvent(aptSleepSync);
aptOpenSession(); aptOpenSession();
APT_ReplySleepQuery(NULL, currentAppId, 0x1); APT_ReplySleepQuery(currentAppId, 0x1);
aptCloseSession(); aptCloseSession();
break; break;
@ -352,7 +352,7 @@ static void __handle_notification() {
aptSetStatus(APP_SLEEPMODE); aptSetStatus(APP_SLEEPMODE);
aptOpenSession(); aptOpenSession();
APT_ReplySleepNotificationComplete(NULL, currentAppId); APT_ReplySleepNotificationComplete(currentAppId);
aptCloseSession(); aptCloseSession();
} }
break; break;
@ -370,11 +370,11 @@ static void __handle_notification() {
} }
} }
static bool __handle_incoming_parameter() { static bool __handle_incoming_parameter(void) {
u8 type; u8 type;
aptOpenSession(); aptOpenSession();
APT_ReceiveParameter(NULL, currentAppId, 0x1000, aptParameters, NULL, &type); APT_ReceiveParameter(currentAppId, 0x1000, aptParameters, NULL, &type);
aptCloseSession(); aptCloseSession();
_aptDebug(2, type); _aptDebug(2, type);
@ -455,7 +455,7 @@ Result aptInit(void)
// Initialize APT stuff, escape load screen. // Initialize APT stuff, escape load screen.
ret = __apt_initservicehandle(); ret = __apt_initservicehandle();
if(ret!=0)return ret; if(ret!=0)return ret;
if((ret=APT_GetLockHandle(&aptuHandle, 0x0, &aptLockHandle)))return ret; if((ret=APT_GetLockHandle(0x0, &aptLockHandle)))return ret;
svcCloseHandle(aptuHandle); svcCloseHandle(aptuHandle);
currentAppId = __apt_appid; currentAppId = __apt_appid;
@ -466,11 +466,11 @@ Result aptInit(void)
if(!aptIsCrippled()) if(!aptIsCrippled())
{ {
aptOpenSession(); aptOpenSession();
if((ret=APT_Initialize(NULL, currentAppId, &aptEvents[0], &aptEvents[1])))return ret; if((ret=APT_Initialize(currentAppId, &aptEvents[0], &aptEvents[1])))return ret;
aptCloseSession(); aptCloseSession();
aptOpenSession(); aptOpenSession();
if((ret=APT_Enable(NULL, 0x0)))return ret; if((ret=APT_Enable(0x0)))return ret;
aptCloseSession(); aptCloseSession();
// create APT close event // create APT close event
@ -481,16 +481,16 @@ Result aptInit(void)
if (aptIsReinit()) if (aptIsReinit())
{ {
aptOpenSession(); aptOpenSession();
APT_PrepareToJumpToApplication(NULL, 0x0); APT_PrepareToJumpToApplication(0x0);
aptCloseSession(); aptCloseSession();
aptOpenSession(); aptOpenSession();
APT_JumpToApplication(NULL, 0x0, 0x0, 0x0); APT_JumpToApplication(0x0, 0x0, 0x0);
aptCloseSession(); aptCloseSession();
} }
aptOpenSession(); aptOpenSession();
if((ret=APT_NotifyToWait(NULL, currentAppId)))return ret; if((ret=APT_NotifyToWait(currentAppId)))return ret;
aptCloseSession(); aptCloseSession();
// create APT event handler thread // create APT event handler thread
@ -504,7 +504,7 @@ Result aptInit(void)
return 0; return 0;
} }
void aptExit() void aptExit(void)
{ {
if (!aptInitialised) return; if (!aptInitialised) return;
@ -514,7 +514,7 @@ void aptExit()
if(aptGetStatusPower() == 1) if(aptGetStatusPower() == 1)
{ {
aptOpenSession(); aptOpenSession();
APT_ReplySleepQuery(NULL, currentAppId, 0x0); APT_ReplySleepQuery(currentAppId, 0x0);
aptCloseSession(); aptCloseSession();
} }
@ -524,11 +524,11 @@ void aptExit()
if (aptGetStatus() == APP_EXITING || !isReinit) if (aptGetStatus() == APP_EXITING || !isReinit)
{ {
aptOpenSession(); aptOpenSession();
APT_PrepareToCloseApplication(NULL, 0x1); APT_PrepareToCloseApplication(0x1);
aptCloseSession(); aptCloseSession();
aptOpenSession(); aptOpenSession();
APT_CloseApplication(NULL, 0x0, 0x0, 0x0); APT_CloseApplication(0x0, 0x0, 0x0);
aptCloseSession(); aptCloseSession();
if (isReinit) if (isReinit)
@ -539,7 +539,7 @@ void aptExit()
} else if (isReinit) } else if (isReinit)
{ {
aptOpenSession(); aptOpenSession();
APT_Finalize(NULL, currentAppId); APT_Finalize(currentAppId);
aptCloseSession(); aptCloseSession();
} }
} }
@ -558,7 +558,7 @@ void aptExit()
aptInitialised = false; aptInitialised = false;
} }
bool aptMainLoop() bool aptMainLoop(void)
{ {
while(1) while(1)
{ {
@ -622,7 +622,7 @@ void aptUnhook(aptHookCookie* cookie)
} }
} }
void aptAppStarted() void aptAppStarted(void)
{ {
u8 buf1[4], buf2[4]; u8 buf1[4], buf2[4];
@ -638,21 +638,21 @@ void aptAppStarted()
buf1[0] = 0x10; buf1[0] = 0x10;
aptOpenSession(); aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x7, 0x4, buf1, 0x1, buf2); APT_AppletUtility(NULL, 0x7, 0x4, buf1, 0x1, buf2);
aptCloseSession(); aptCloseSession();
buf1[0] = 0x00; buf1[0] = 0x00;
aptOpenSession(); aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x4, 0x1, buf1, 0x1, buf2); APT_AppletUtility(NULL, 0x4, 0x1, buf1, 0x1, buf2);
aptCloseSession(); aptCloseSession();
aptOpenSession(); aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x4, 0x1, buf1, 0x1, buf2); APT_AppletUtility(NULL, 0x4, 0x1, buf1, 0x1, buf2);
aptCloseSession(); aptCloseSession();
} }
} }
APP_STATUS aptGetStatus() APP_STATUS aptGetStatus(void)
{ {
APP_STATUS ret; APP_STATUS ret;
svcWaitSynchronization(aptStatusMutex, U64_MAX); svcWaitSynchronization(aptStatusMutex, U64_MAX);
@ -676,7 +676,7 @@ void aptSetStatus(APP_STATUS status)
svcReleaseMutex(aptStatusMutex); svcReleaseMutex(aptStatusMutex);
} }
u32 aptGetStatusPower() u32 aptGetStatusPower(void)
{ {
u32 ret; u32 ret;
svcWaitSynchronization(aptStatusMutex, U64_MAX); svcWaitSynchronization(aptStatusMutex, U64_MAX);
@ -692,7 +692,7 @@ void aptSetStatusPower(u32 status)
svcReleaseMutex(aptStatusMutex); svcReleaseMutex(aptStatusMutex);
} }
void aptOpenSession() void aptOpenSession(void)
{ {
//Result ret; //Result ret;
@ -700,42 +700,40 @@ void aptOpenSession()
__apt_initservicehandle(); __apt_initservicehandle();
} }
void aptCloseSession() void aptCloseSession(void)
{ {
svcCloseHandle(aptuHandle); svcCloseHandle(aptuHandle);
svcReleaseMutex(aptLockHandle); svcReleaseMutex(aptLockHandle);
} }
void aptSignalReadyForSleep() void aptSignalReadyForSleep(void)
{ {
svcSignalEvent(aptSleepSync); svcSignalEvent(aptSleepSync);
} }
Result APT_GetLockHandle(Handle* handle, u16 flags, Handle* lockHandle) Result APT_GetLockHandle(u16 flags, Handle* lockHandle)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x10040; //request header code cmdbuf[0]=0x10040; //request header code
cmdbuf[1]=flags; cmdbuf[1]=flags;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
if(lockHandle)*lockHandle=cmdbuf[5]; if(lockHandle)*lockHandle=cmdbuf[5];
return cmdbuf[1]; return cmdbuf[1];
} }
Result APT_Initialize(Handle* handle, NS_APPID appId, Handle* eventHandle1, Handle* eventHandle2) Result APT_Initialize(NS_APPID appId, Handle* eventHandle1, Handle* eventHandle2)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x20080; //request header code cmdbuf[0]=0x20080; //request header code
cmdbuf[1]=appId; cmdbuf[1]=appId;
cmdbuf[2]=0x0; cmdbuf[2]=0x0;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
if(eventHandle1)*eventHandle1=cmdbuf[3]; //return to menu event ? if(eventHandle1)*eventHandle1=cmdbuf[3]; //return to menu event ?
if(eventHandle2)*eventHandle2=cmdbuf[4]; if(eventHandle2)*eventHandle2=cmdbuf[4];
@ -743,52 +741,48 @@ Result APT_Initialize(Handle* handle, NS_APPID appId, Handle* eventHandle1, Hand
return cmdbuf[1]; return cmdbuf[1];
} }
Result APT_Finalize(Handle* handle, NS_APPID appId) Result APT_Finalize(NS_APPID appId)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x40040; //request header code cmdbuf[0]=0x40040; //request header code
cmdbuf[1]=appId; cmdbuf[1]=appId;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result APT_HardwareResetAsync(Handle* handle) Result APT_HardwareResetAsync()
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x4E0000; //request header code cmdbuf[0]=0x4E0000; //request header code
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result APT_Enable(Handle* handle, u32 a) Result APT_Enable(u32 a)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x30040; //request header code cmdbuf[0]=0x30040; //request header code
cmdbuf[1]=a; cmdbuf[1]=a;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result APT_GetAppletManInfo(Handle* handle, u8 inval, u8 *outval8, u32 *outval32, NS_APPID *menu_appid, NS_APPID *active_appid) Result APT_GetAppletManInfo(u8 inval, u8 *outval8, u32 *outval32, NS_APPID *menu_appid, NS_APPID *active_appid)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x00050040; //request header code cmdbuf[0]=0x00050040; //request header code
cmdbuf[1]=inval; cmdbuf[1]=inval;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
if(outval8)*outval8=cmdbuf[2]; if(outval8)*outval8=cmdbuf[2];
if(outval32)*outval32=cmdbuf[3]; if(outval32)*outval32=cmdbuf[3];
@ -798,51 +792,47 @@ Result APT_GetAppletManInfo(Handle* handle, u8 inval, u8 *outval8, u32 *outval32
return cmdbuf[1]; return cmdbuf[1];
} }
Result APT_IsRegistered(Handle* handle, NS_APPID appID, u8* out) Result APT_IsRegistered(NS_APPID appID, u8* out)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x90040; //request header code cmdbuf[0]=0x90040; //request header code
cmdbuf[1]=appID; cmdbuf[1]=appID;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
if(out)*out=cmdbuf[2]; if(out)*out=cmdbuf[2];
return cmdbuf[1]; return cmdbuf[1];
} }
Result APT_InquireNotification(Handle* handle, u32 appID, u8* signalType) Result APT_InquireNotification(u32 appID, u8* signalType)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0xB0040; //request header code cmdbuf[0]=0xB0040; //request header code
cmdbuf[1]=appID; cmdbuf[1]=appID;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
if(signalType)*signalType=cmdbuf[2]; if(signalType)*signalType=cmdbuf[2];
return cmdbuf[1]; return cmdbuf[1];
} }
Result APT_PrepareToJumpToHomeMenu(Handle* handle) Result APT_PrepareToJumpToHomeMenu()
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x2b0000; //request header code cmdbuf[0]=0x2b0000; //request header code
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result APT_JumpToHomeMenu(Handle* handle, u32 a, u32 b, u32 c) Result APT_JumpToHomeMenu(u32 a, u32 b, u32 c)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x2C0044; //request header code cmdbuf[0]=0x2C0044; //request header code
cmdbuf[1]=a; cmdbuf[1]=a;
@ -851,27 +841,25 @@ Result APT_JumpToHomeMenu(Handle* handle, u32 a, u32 b, u32 c)
cmdbuf[4]=(b<<14)|2; cmdbuf[4]=(b<<14)|2;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result APT_PrepareToJumpToApplication(Handle* handle, u32 a) Result APT_PrepareToJumpToApplication(u32 a)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x230040; //request header code cmdbuf[0]=0x230040; //request header code
cmdbuf[1]=a; cmdbuf[1]=a;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result APT_JumpToApplication(Handle* handle, u32 a, u32 b, u32 c) Result APT_JumpToApplication(u32 a, u32 b, u32 c)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x240044; //request header code cmdbuf[0]=0x240044; //request header code
cmdbuf[1]=a; cmdbuf[1]=a;
@ -880,27 +868,25 @@ Result APT_JumpToApplication(Handle* handle, u32 a, u32 b, u32 c)
cmdbuf[4]=(b<<14)|2; cmdbuf[4]=(b<<14)|2;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result APT_NotifyToWait(Handle* handle, NS_APPID appID) Result APT_NotifyToWait(NS_APPID appID)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x430040; //request header code cmdbuf[0]=0x430040; //request header code
cmdbuf[1]=appID; cmdbuf[1]=appID;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result APT_AppletUtility(Handle* handle, u32* out, u32 a, u32 size1, u8* buf1, u32 size2, u8* buf2) Result APT_AppletUtility(u32* out, u32 a, u32 size1, u8* buf1, u32 size2, u8* buf2)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x4B00C2; //request header code cmdbuf[0]=0x4B00C2; //request header code
cmdbuf[1]=a; cmdbuf[1]=a;
@ -913,16 +899,15 @@ Result APT_AppletUtility(Handle* handle, u32* out, u32 a, u32 size1, u8* buf1, u
cmdbuf[1+0x100/4]=(u32)buf2; cmdbuf[1+0x100/4]=(u32)buf2;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
if(out)*out=cmdbuf[2]; if(out)*out=cmdbuf[2];
return cmdbuf[1]; return cmdbuf[1];
} }
Result APT_GlanceParameter(Handle* handle, NS_APPID appID, u32 bufferSize, u32* buffer, u32* actualSize, u8* signalType) Result APT_GlanceParameter(NS_APPID appID, u32 bufferSize, u32* buffer, u32* actualSize, u8* signalType)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0xE0080; //request header code cmdbuf[0]=0xE0080; //request header code
cmdbuf[1]=appID; cmdbuf[1]=appID;
@ -932,7 +917,7 @@ Result APT_GlanceParameter(Handle* handle, NS_APPID appID, u32 bufferSize, u32*
cmdbuf[1+0x100/4]=(u32)buffer; cmdbuf[1+0x100/4]=(u32)buffer;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
if(signalType)*signalType=cmdbuf[3]; if(signalType)*signalType=cmdbuf[3];
if(actualSize)*actualSize=cmdbuf[4]; if(actualSize)*actualSize=cmdbuf[4];
@ -940,9 +925,8 @@ Result APT_GlanceParameter(Handle* handle, NS_APPID appID, u32 bufferSize, u32*
return cmdbuf[1]; return cmdbuf[1];
} }
Result APT_ReceiveParameter(Handle* handle, NS_APPID appID, u32 bufferSize, u32* buffer, u32* actualSize, u8* signalType) Result APT_ReceiveParameter(NS_APPID appID, u32 bufferSize, u32* buffer, u32* actualSize, u8* signalType)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0xD0080; //request header code cmdbuf[0]=0xD0080; //request header code
cmdbuf[1]=appID; cmdbuf[1]=appID;
@ -952,7 +936,7 @@ Result APT_ReceiveParameter(Handle* handle, NS_APPID appID, u32 bufferSize, u32*
cmdbuf[1+0x100/4]=(u32)buffer; cmdbuf[1+0x100/4]=(u32)buffer;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
if(signalType)*signalType=cmdbuf[3]; if(signalType)*signalType=cmdbuf[3];
if(actualSize)*actualSize=cmdbuf[4]; if(actualSize)*actualSize=cmdbuf[4];
@ -960,12 +944,10 @@ Result APT_ReceiveParameter(Handle* handle, NS_APPID appID, u32 bufferSize, u32*
return cmdbuf[1]; return cmdbuf[1];
} }
Result APT_SendParameter(Handle* handle, NS_APPID src_appID, NS_APPID dst_appID, u32 bufferSize, u32* buffer, Handle paramhandle, u8 signalType) Result APT_SendParameter(NS_APPID src_appID, NS_APPID dst_appID, u32 bufferSize, u32* buffer, Handle paramhandle, u8 signalType)
{ {
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
if(!handle)handle=&aptuHandle;
cmdbuf[0] = 0x000C0104; //request header code cmdbuf[0] = 0x000C0104; //request header code
cmdbuf[1] = src_appID; cmdbuf[1] = src_appID;
cmdbuf[2] = dst_appID; cmdbuf[2] = dst_appID;
@ -979,75 +961,65 @@ Result APT_SendParameter(Handle* handle, NS_APPID src_appID, NS_APPID dst_appID,
cmdbuf[8] = (u32)buffer; cmdbuf[8] = (u32)buffer;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result APT_SendCaptureBufferInfo(Handle* handle, u32 bufferSize, u32* buffer) Result APT_SendCaptureBufferInfo(u32 bufferSize, u32* buffer)
{ {
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
if(!handle)handle=&aptuHandle;
cmdbuf[0] = 0x00400042; //request header code cmdbuf[0] = 0x00400042; //request header code
cmdbuf[1] = bufferSize; cmdbuf[1] = bufferSize;
cmdbuf[2] = (bufferSize<<14) | 2; cmdbuf[2] = (bufferSize<<14) | 2;
cmdbuf[3] = (u32)buffer; cmdbuf[3] = (u32)buffer;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result APT_ReplySleepQuery(Handle* handle, NS_APPID appID, u32 a) Result APT_ReplySleepQuery(NS_APPID appID, u32 a)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x3E0080; //request header code cmdbuf[0]=0x3E0080; //request header code
cmdbuf[1]=appID; cmdbuf[1]=appID;
cmdbuf[2]=a; cmdbuf[2]=a;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result APT_ReplySleepNotificationComplete(Handle* handle, NS_APPID appID) Result APT_ReplySleepNotificationComplete(NS_APPID appID)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x3F0040; //request header code cmdbuf[0]=0x3F0040; //request header code
cmdbuf[1]=appID; cmdbuf[1]=appID;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result APT_PrepareToCloseApplication(Handle* handle, u8 a) Result APT_PrepareToCloseApplication(u8 a)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x220040; //request header code cmdbuf[0]=0x220040; //request header code
cmdbuf[1]=a; cmdbuf[1]=a;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result APT_CloseApplication(Handle* handle, u32 a, u32 b, u32 c) Result APT_CloseApplication(u32 a, u32 b, u32 c)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x270044; //request header code cmdbuf[0]=0x270044; //request header code
cmdbuf[1]=a; cmdbuf[1]=a;
@ -1057,37 +1029,33 @@ Result APT_CloseApplication(Handle* handle, u32 a, u32 b, u32 c)
cmdbuf[5]=c; cmdbuf[5]=c;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
//See http://3dbrew.org/APT:SetApplicationCpuTimeLimit //See http://3dbrew.org/APT:SetApplicationCpuTimeLimit
Result APT_SetAppCpuTimeLimit(Handle* handle, u32 percent) Result APT_SetAppCpuTimeLimit(u32 percent)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x4F0080; cmdbuf[0]=0x4F0080;
cmdbuf[1]=1; cmdbuf[1]=1;
cmdbuf[2]=percent; cmdbuf[2]=percent;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result APT_GetAppCpuTimeLimit(Handle* handle, u32 *percent) Result APT_GetAppCpuTimeLimit(u32 *percent)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x500040; cmdbuf[0]=0x500040;
cmdbuf[1]=1; cmdbuf[1]=1;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
if(percent)*percent=cmdbuf[2]; if(percent)*percent=cmdbuf[2];
@ -1095,15 +1063,13 @@ Result APT_GetAppCpuTimeLimit(Handle* handle, u32 *percent)
} }
// Note: this function is unreliable, see: http://3dbrew.org/wiki/APT:PrepareToStartApplication // Note: this function is unreliable, see: http://3dbrew.org/wiki/APT:PrepareToStartApplication
Result APT_CheckNew3DS_Application(Handle* handle, u8 *out) Result APT_CheckNew3DS_Application(u8 *out)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x01010000; cmdbuf[0]=0x01010000;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
if(ret==0)ret = cmdbuf[1]; if(ret==0)ret = cmdbuf[1];
@ -1116,15 +1082,13 @@ Result APT_CheckNew3DS_Application(Handle* handle, u8 *out)
return ret; return ret;
} }
Result APT_CheckNew3DS_System(Handle* handle, u8 *out) Result APT_CheckNew3DS_System(u8 *out)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x01020000; cmdbuf[0]=0x01020000;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
if(ret==0)ret = cmdbuf[1]; if(ret==0)ret = cmdbuf[1];
@ -1137,7 +1101,7 @@ Result APT_CheckNew3DS_System(Handle* handle, u8 *out)
return ret; return ret;
} }
Result APT_CheckNew3DS(Handle* handle, u8 *out) Result APT_CheckNew3DS(u8 *out)
{ {
Result ret=0; Result ret=0;
@ -1152,7 +1116,7 @@ Result APT_CheckNew3DS(Handle* handle, u8 *out)
} }
aptOpenSession(); aptOpenSession();
ret = APT_CheckNew3DS_System(NULL, out); ret = APT_CheckNew3DS_System(out);
aptCloseSession(); aptCloseSession();
__apt_new3dsflag_initialized = 1; __apt_new3dsflag_initialized = 1;
@ -1161,10 +1125,8 @@ Result APT_CheckNew3DS(Handle* handle, u8 *out)
return ret; return ret;
} }
Result APT_PrepareToDoAppJump(Handle* handle, u8 flags, u64 programID, u8 mediatype) Result APT_PrepareToDoAppJump(u8 flags, u64 programID, u8 mediatype)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x310100; //request header code cmdbuf[0]=0x310100; //request header code
cmdbuf[1]=flags; cmdbuf[1]=flags;
@ -1173,15 +1135,13 @@ Result APT_PrepareToDoAppJump(Handle* handle, u8 flags, u64 programID, u8 mediat
cmdbuf[4]=mediatype; cmdbuf[4]=mediatype;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result APT_DoAppJump(Handle* handle, u32 NSbuf0Size, u32 NSbuf1Size, u8 *NSbuf0Ptr, u8 *NSbuf1Ptr) Result APT_DoAppJump(u32 NSbuf0Size, u32 NSbuf1Size, u8 *NSbuf0Ptr, u8 *NSbuf1Ptr)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x320084; //request header code cmdbuf[0]=0x320084; //request header code
cmdbuf[1]=NSbuf0Size; cmdbuf[1]=NSbuf0Size;
@ -1192,29 +1152,25 @@ Result APT_DoAppJump(Handle* handle, u32 NSbuf0Size, u32 NSbuf1Size, u8 *NSbuf0P
cmdbuf[6]=(u32)NSbuf1Ptr; cmdbuf[6]=(u32)NSbuf1Ptr;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result APT_PrepareToStartLibraryApplet(Handle* handle, NS_APPID appID) Result APT_PrepareToStartLibraryApplet(NS_APPID appID)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x180040; //request header code cmdbuf[0]=0x180040; //request header code
cmdbuf[1]=appID; cmdbuf[1]=appID;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result APT_StartLibraryApplet(Handle* handle, NS_APPID appID, Handle inhandle, u32 *parambuf, u32 parambufsize) Result APT_StartLibraryApplet(NS_APPID appID, Handle inhandle, u32 *parambuf, u32 parambufsize)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x1E0084; //request header code cmdbuf[0]=0x1E0084; //request header code
cmdbuf[1]=appID; cmdbuf[1]=appID;
@ -1225,7 +1181,7 @@ Result APT_StartLibraryApplet(Handle* handle, NS_APPID appID, Handle inhandle, u
cmdbuf[6]=(u32)parambuf; cmdbuf[6]=(u32)parambuf;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
@ -1239,23 +1195,23 @@ Result APT_LaunchLibraryApplet(NS_APPID appID, Handle inhandle, u32 *parambuf, u
u8 buf2[4]; u8 buf2[4];
aptOpenSession(); aptOpenSession();
APT_ReplySleepQuery(NULL, currentAppId, 0); APT_ReplySleepQuery(currentAppId, 0);
aptCloseSession(); aptCloseSession();
aptOpenSession(); aptOpenSession();
ret=APT_PrepareToStartLibraryApplet(NULL, appID); ret=APT_PrepareToStartLibraryApplet(appID);
aptCloseSession(); aptCloseSession();
if(ret!=0)return ret; if(ret!=0)return ret;
memset(buf1, 0, 4); memset(buf1, 0, 4);
aptOpenSession(); aptOpenSession();
APT_AppletUtility(NULL, NULL, 0x4, 0x1, buf1, 0x1, buf2); APT_AppletUtility(NULL, 0x4, 0x1, buf1, 0x1, buf2);
aptCloseSession(); aptCloseSession();
while(1) while(1)
{ {
aptOpenSession(); aptOpenSession();
ret=APT_IsRegistered(NULL, appID, &tmp); ret=APT_IsRegistered(appID, &tmp);
aptCloseSession(); aptCloseSession();
if(ret!=0)return ret; if(ret!=0)return ret;
@ -1283,7 +1239,7 @@ Result APT_LaunchLibraryApplet(NS_APPID appID, Handle inhandle, u32 *parambuf, u
// Send capture-screen info to the library applet. // Send capture-screen info to the library applet.
aptOpenSession(); aptOpenSession();
APT_SendParameter(NULL, currentAppId, appID, 0x20, __ns_capinfo, 0x0, 0x2); APT_SendParameter(currentAppId, appID, 0x20, __ns_capinfo, 0x0, 0x2);
aptCloseSession(); aptCloseSession();
// Release GSP module. // Release GSP module.
@ -1292,24 +1248,20 @@ Result APT_LaunchLibraryApplet(NS_APPID appID, Handle inhandle, u32 *parambuf, u
return 0; return 0;
} }
Result APT_PrepareToStartSystemApplet(Handle* handle, NS_APPID appID) Result APT_PrepareToStartSystemApplet(NS_APPID appID)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0]=0x00190040; //request header code cmdbuf[0]=0x00190040; //request header code
cmdbuf[1]=appID; cmdbuf[1]=appID;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }
Result APT_StartSystemApplet(Handle* handle, NS_APPID appID, u32 bufSize, Handle applHandle, u8 *buf) Result APT_StartSystemApplet(NS_APPID appID, u32 bufSize, Handle applHandle, u8 *buf)
{ {
if(!handle)handle=&aptuHandle;
u32* cmdbuf=getThreadCommandBuffer(); u32* cmdbuf=getThreadCommandBuffer();
cmdbuf[0] = 0x001F0084; //request header code cmdbuf[0] = 0x001F0084; //request header code
cmdbuf[1] = appID; cmdbuf[1] = appID;
@ -1320,7 +1272,7 @@ Result APT_StartSystemApplet(Handle* handle, NS_APPID appID, u32 bufSize, Handle
cmdbuf[6] = (u32)buf; cmdbuf[6] = (u32)buf;
Result ret=0; Result ret=0;
if((ret=svcSendSyncRequest(*handle)))return ret; if((ret=svcSendSyncRequest(aptuHandle)))return ret;
return cmdbuf[1]; return cmdbuf[1];
} }

View File

@ -44,7 +44,7 @@ Result hidInit(u32* sharedMem)
hidSharedMem=sharedMem; hidSharedMem=sharedMem;
if((ret=svcMapMemoryBlock(hidMemHandle, (u32)hidSharedMem, MEMPERM_READ, 0x10000000)))goto cleanup2; if((ret=svcMapMemoryBlock(hidMemHandle, (u32)hidSharedMem, MEMPERM_READ, 0x10000000)))goto cleanup2;
APT_CheckNew3DS(NULL, &val); APT_CheckNew3DS(&val);
if(val) if(val)
{ {
@ -74,7 +74,7 @@ void hidExit()
svcCloseHandle(hidMemHandle); svcCloseHandle(hidMemHandle);
svcCloseHandle(hidHandle); svcCloseHandle(hidHandle);
APT_CheckNew3DS(NULL, &val); APT_CheckNew3DS(&val);
if(val) if(val)
{ {