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,26 +177,22 @@ int main()
gspWaitForPSC0();
gfxSwapBuffersGpu();
APP_STATUS status;
while((status=aptGetStatus())!=APP_EXITING)
while(aptMainLoop())
{
if(status==APP_RUNNING)
{
demoControls();
demoControls();
GX_SetMemoryFill(gxCmdBuf, (u32*)gpuOut, 0x404040FF, (u32*)&gpuOut[0x2EE00], 0x201, (u32*)gpuDOut, 0x00000000, (u32*)&gpuDOut[0x2EE00], 0x201);
gspWaitForPSC0();
GX_SetMemoryFill(gxCmdBuf, (u32*)gpuOut, 0x404040FF, (u32*)&gpuOut[0x2EE00], 0x201, (u32*)gpuDOut, 0x00000000, (u32*)&gpuDOut[0x2EE00], 0x201);
gspWaitForPSC0();
GPUCMD_SetBuffer(gpuCmd, gpuCmdSize, 0);
doFrame1();
GPUCMD_Finalize();
GPUCMD_Run(gxCmdBuf);
gspWaitForP3D();
GPUCMD_SetBuffer(gpuCmd, gpuCmdSize, 0);
doFrame1();
GPUCMD_Finalize();
GPUCMD_Run(gxCmdBuf);
gspWaitForP3D();
gfxSwapBuffersGpu();
GX_SetDisplayTransfer(gxCmdBuf, (u32*)gpuOut, 0x019001E0, (u32*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), 0x019001E0, 0x01001000);
gspWaitForPPF();
}
gfxSwapBuffersGpu();
GX_SetDisplayTransfer(gxCmdBuf, (u32*)gpuOut, 0x019001E0, (u32*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), 0x019001E0, 0x01001000);
gspWaitForPPF();
gspWaitForVBlank();
}

View File

@ -24,60 +24,48 @@ int main()
MIC_Initialize(sharedmem, sharedmem_size, control, 0, 3, 1, 1);//See mic.h.
APP_STATUS status;
while((status=aptGetStatus())!=APP_EXITING)
while(aptMainLoop())
{
if(status==APP_RUNNING)
framebuf = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
hidScanInput();
if(hidKeysDown() & KEY_A)
{
framebuf = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
hidScanInput();
audiobuf_pos = 0;
if(hidKeysDown() & KEY_A)
{
audiobuf_pos = 0;
CSND_setchannel_playbackstate(0x8, 0);//Stop audio playback.
CSND_sharedmemtype0_cmdupdatestate(0);
CSND_setchannel_playbackstate(0x8, 0);//Stop audio playback.
CSND_sharedmemtype0_cmdupdatestate(0);
MIC_SetRecording(1);
MIC_SetRecording(1);
memset(framebuf, 0x20, 0x46500);
}
memset(framebuf, 0x20, 0x46500);
}
if((hidKeysHeld() & KEY_A) && audiobuf_pos < audiobuf_size)
{
audiobuf_pos+= MIC_ReadAudioData(&audiobuf[audiobuf_pos], audiobuf_size-audiobuf_pos, 1);
if(audiobuf_pos > audiobuf_size)audiobuf_pos = audiobuf_size;
if((hidKeysHeld() & KEY_A) && audiobuf_pos < audiobuf_size)
{
audiobuf_pos+= MIC_ReadAudioData(&audiobuf[audiobuf_pos], audiobuf_size-audiobuf_pos, 1);
if(audiobuf_pos > audiobuf_size)audiobuf_pos = audiobuf_size;
memset(framebuf, 0x60, 0x46500);
}
memset(framebuf, 0x60, 0x46500);
}
if(hidKeysUp() & KEY_A)
{
MIC_SetRecording(0);
GSPGPU_FlushDataCache(NULL, audiobuf, audiobuf_pos);
CSND_playsound(0x8, CSND_LOOP_DISABLE, CSND_ENCODING_PCM16, 16000, (u32*)audiobuf, NULL, audiobuf_pos, 2, 0);
if(hidKeysUp() & KEY_A)
{
MIC_SetRecording(0);
GSPGPU_FlushDataCache(NULL, audiobuf, audiobuf_pos);
CSND_playsound(0x8, CSND_LOOP_DISABLE, CSND_ENCODING_PCM16, 16000, (u32*)audiobuf, NULL, audiobuf_pos, 2, 0);
memset(framebuf, 0xe0, 0x46500);
gfxFlushBuffers();
gfxSwapBuffers();
framebuf = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
memset(framebuf, 0xe0, 0x46500);
}
memset(framebuf, 0xe0, 0x46500);
gfxFlushBuffers();
gfxSwapBuffers();
framebuf = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
memset(framebuf, 0xe0, 0x46500);
}
else if(status == APP_SUSPENDING)
{
aptReturnToMenu();
}
else if(status == APP_SLEEPMODE)
{
aptWaitStatusEvent();
}
gfxFlushBuffers();
gfxSwapBuffers();
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];