Add aptMainLoop() for handling APT events in main()

This commit is contained in:
fincs 2014-11-02 18:58:37 +01:00
parent 3135d1c344
commit 7f10ad4097
4 changed files with 61 additions and 57 deletions

View File

@ -177,10 +177,7 @@ int main()
gspWaitForPSC0();
gfxSwapBuffersGpu();
APP_STATUS status;
while((status=aptGetStatus())!=APP_EXITING)
{
if(status==APP_RUNNING)
while(aptMainLoop())
{
demoControls();
@ -196,7 +193,6 @@ int main()
gfxSwapBuffersGpu();
GX_SetDisplayTransfer(gxCmdBuf, (u32*)gpuOut, 0x019001E0, (u32*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), 0x019001E0, 0x01001000);
gspWaitForPPF();
}
gspWaitForVBlank();
}

View File

@ -24,10 +24,7 @@ int main()
MIC_Initialize(sharedmem, sharedmem_size, control, 0, 3, 1, 1);//See mic.h.
APP_STATUS status;
while((status=aptGetStatus())!=APP_EXITING)
{
if(status==APP_RUNNING)
while(aptMainLoop())
{
framebuf = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
hidScanInput();
@ -69,15 +66,6 @@ int main()
gfxFlushBuffers();
gfxSwapBuffers();
}
else if(status == APP_SUSPENDING)
{
aptReturnToMenu();
}
else if(status == APP_SLEEPMODE)
{
aptWaitStatusEvent();
}
gspWaitForVBlank();
}

View File

@ -49,6 +49,7 @@ void aptReturnToMenu();//This should be called by the user application when aptG
void aptWaitStatusEvent();
void aptSignalReadyForSleep();
NS_APPID aptGetMenuAppID();
bool aptMainLoop(); // Use like this in your main(): while (aptMainLoop()) { your code here... }
Result APT_GetLockHandle(Handle* handle, u16 flags, Handle* lockHandle);
Result APT_Initialize(Handle* handle, NS_APPID appId, Handle* eventHandle1, Handle* eventHandle2);

View File

@ -394,6 +394,25 @@ void aptExit()
svcCloseHandle(aptStatusEvent);
}
bool aptMainLoop()
{
for (;;) switch (aptGetStatus())
{
case APP_RUNNING:
return true;
case APP_SUSPENDING:
aptReturnToMenu();
break;
case APP_SLEEPMODE:
aptWaitStatusEvent();
break;
case APP_EXITING:
return false;
default:
break;
}
}
void aptAppStarted()
{
u8 buf1[4], buf2[4];