From afd2140cb79b6bdb29efe125dc0b8a3524ed5e2e Mon Sep 17 00:00:00 2001 From: StapleButter Date: Mon, 27 Oct 2014 15:37:30 +0100 Subject: [PATCH] Create APT event handler thread as soon as possible, and complete initialization automatically when needed. No more 'call aptSetupEventHandler() as late as possible' shit. Adapt examples to the changes (not tested). --- examples/arm11u/source/main.c | 2 -- examples/gpu/source/main.c | 11 +++++----- examples/mic/source/main.c | 1 - examples/sdmc/source/main.c | 2 -- libctru/include/3ds/services/apt.h | 1 - libctru/source/services/apt.c | 33 ++++++------------------------ 6 files changed, 12 insertions(+), 38 deletions(-) diff --git a/examples/arm11u/source/main.c b/examples/arm11u/source/main.c index 0c0f677..8862f17 100644 --- a/examples/arm11u/source/main.c +++ b/examples/arm11u/source/main.c @@ -121,8 +121,6 @@ int main() hidInit(NULL); - aptSetupEventHandler(); - APP_STATUS status; while((status=aptGetStatus())!=APP_EXITING) { diff --git a/examples/gpu/source/main.c b/examples/gpu/source/main.c index 1bd9832..1c06bd5 100644 --- a/examples/gpu/source/main.c +++ b/examples/gpu/source/main.c @@ -56,7 +56,7 @@ void doFrame1() GPU_SetFaceCulling(GPU_CULL_BACK_CCW); GPU_SetStencilTest(false, GPU_ALWAYS, 0x00); - GPU_SetDepthTest(true, GPU_GREATER, 0x1F); + GPU_SetDepthTestAndWriteMask(true, GPU_GREATER, GPU_WRITE_ALL); // ? GPUCMD_AddSingleParam(0x00010062, 0x00000000); //param always 0x0 according to code @@ -122,9 +122,7 @@ void doFrame1() GPU_DrawArray(GPU_TRIANGLES, mdlFaces*3); //finalize stuff ? - GPUCMD_AddSingleParam(0x000F0111, 0x00000001); - GPUCMD_AddSingleParam(0x000F0110, 0x00000001); - GPUCMD_AddSingleParam(0x0008025E, 0x00000000); + GPU_FinishDrawing(); } void demoControls(void) @@ -156,7 +154,6 @@ int main() aptInit(); gfxInit(); hidInit(NULL); - aptSetupEventHandler(); GPU_Init(NULL); @@ -177,6 +174,7 @@ int main() shader=SHDR_ParseSHBIN((u32*)test_vsh_shbin,test_vsh_shbin_size); GX_SetMemoryFill(gxCmdBuf, (u32*)gpuOut, 0x404040FF, (u32*)&gpuOut[0x2EE00], 0x201, (u32*)gpuDOut, 0x00000000, (u32*)&gpuDOut[0x2EE00], 0x201); + gspWaitForPSC0(); gfxSwapBuffersGpu(); APP_STATUS status; @@ -187,14 +185,17 @@ int main() demoControls(); 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(); gfxSwapBuffersGpu(); GX_SetDisplayTransfer(gxCmdBuf, (u32*)gpuOut, 0x019001E0, (u32*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL), 0x019001E0, 0x01001000); + gspWaitForPPF(); } gspWaitForVBlank(); } diff --git a/examples/mic/source/main.c b/examples/mic/source/main.c index 022902a..90205b5 100644 --- a/examples/mic/source/main.c +++ b/examples/mic/source/main.c @@ -16,7 +16,6 @@ int main() aptInit(); gfxInit(); hidInit(NULL); - aptSetupEventHandler(); CSND_initialize(NULL); diff --git a/examples/sdmc/source/main.c b/examples/sdmc/source/main.c index 68f9b5c..53d4404 100644 --- a/examples/sdmc/source/main.c +++ b/examples/sdmc/source/main.c @@ -131,8 +131,6 @@ int main() FSUSER_OpenFileDirectly(fsuHandle, &fileHandle, sdmcArchive, filePath, FS_OPEN_READ, FS_ATTRIBUTE_NONE); FSFILE_Read(fileHandle, &bytesRead, 0x0, (u32*)gspHeap, 0x46500); FSFILE_Close(fileHandle); - - aptSetupEventHandler(); APP_STATUS status; while((status=aptGetStatus())!=APP_EXITING) diff --git a/libctru/include/3ds/services/apt.h b/libctru/include/3ds/services/apt.h index b8c05d9..cf2fb31 100644 --- a/libctru/include/3ds/services/apt.h +++ b/libctru/include/3ds/services/apt.h @@ -41,7 +41,6 @@ Result aptInit(); void aptExit(); void aptOpenSession(); void aptCloseSession(); -void aptSetupEventHandler(); void aptSetStatus(APP_STATUS status); APP_STATUS aptGetStatus(); 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. diff --git a/libctru/source/services/apt.c b/libctru/source/services/apt.c index 3c8de84..4d4759a 100644 --- a/libctru/source/services/apt.c +++ b/libctru/source/services/apt.c @@ -249,6 +249,7 @@ static bool __handle_incoming_parameter() { switch(type) { case 0x1: // Application just started. + aptAppStarted(); return true; case 0xB: // Just returned from menu. @@ -320,6 +321,10 @@ Result aptInit(void) aptOpenSession(); if((ret=APT_NotifyToWait(NULL, currentAppId)))return ret; aptCloseSession(); + + // create APT event handler thread + svcCreateThread(&aptEventHandlerThread, aptEventHandler, 0x0, + (u32*)(&aptEventHandlerStack[APT_HANDLER_STACKSIZE/8]), 0x31, 0xfffffffe); } svcCreateEvent(&aptStatusEvent, 0); @@ -357,32 +362,10 @@ void aptExit() svcCloseHandle(aptStatusEvent); } -void aptSetupEventHandler() +void aptAppStarted() { u8 buf1[4], buf2[4]; - /*buf1[0]=0x02; buf1[1]=0x00; buf1[2]=0x00; buf1[3]=0x04; - aptOpenSession(); - APT_AppletUtility(NULL, NULL, 0x7, 0x4, buf1, 0x1, buf2); - aptCloseSession(); - - aptOpenSession(); - APT_AppletUtility(NULL, NULL, 0x4, 0x1, buf1, 0x1, buf2); - aptCloseSession(); - - aptOpenSession(); - APT_AppletUtility(NULL, NULL, 0x4, 0x1, buf1, 0x1, buf2); - aptCloseSession(); - - buf1[0]=0x13; buf1[1]=0x00; buf1[2]=0x10; buf1[3]=0x00; - aptOpenSession(); - APT_AppletUtility(NULL, NULL, 0x7, 0x4, buf1, 0x1, buf2); - aptCloseSession(); - - aptOpenSession(); - APT_AppletUtility(NULL, NULL, 0x4, 0x1, buf1, 0x1, buf2); - aptCloseSession();*/ - svcCreateMutex(&aptStatusMutex, true); aptStatus=0; svcReleaseMutex(aptStatusMutex); @@ -406,10 +389,6 @@ void aptSetupEventHandler() aptOpenSession(); APT_AppletUtility(NULL, NULL, 0x4, 0x1, buf1, 0x1, buf2); aptCloseSession(); - - // Create thread for stuff handling APT events. - svcCreateThread(&aptEventHandlerThread, aptEventHandler, 0x0, - (u32*)(&aptEventHandlerStack[APT_HANDLER_STACKSIZE/8]), 0x31, 0xfffffffe); } }