/*---------------------------------------------------------------------------* Project: Horizon File: voicesel_demo.cpp Copyright (C)2009-2012 Nintendo Co., Ltd. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Rev:$ *---------------------------------------------------------------------------*/ #include #include "demo.h" #include #include #include //---------------------------------------------------------------- namespace { demo::RenderSystemDrawing df; s32 loopCnt = 0; s32 selectParam = 0; nn::voicesel::Parameter vsel_param; const char* filterTypeStr[] = { "ALL", "100_LT", "75_LT", "50_LT", "25_LT" }; const char* softResetStr[] = { "FALSE", "TRUE", }; const char* homeButtonStr[] = { "FALSE", "TRUE", }; void SetupRenderSystem() { demo::RenderBufferDescription colorBufferDesc; { colorBufferDesc.m_Format = GL_RGBA8_OES; colorBufferDesc.m_Width = nn::gx::DISPLAY0_WIDTH; colorBufferDesc.m_Height = nn::gx::DISPLAY0_HEIGHT; colorBufferDesc.m_Area = NN_GX_MEM_VRAMA; colorBufferDesc.m_Attachment = GL_COLOR_ATTACHMENT0; } demo::RenderBufferDescription depthStencilBufferDesc; { depthStencilBufferDesc.m_Format = GL_DEPTH24_STENCIL8_EXT; depthStencilBufferDesc.m_Width = nn::gx::DISPLAY0_WIDTH; depthStencilBufferDesc.m_Height = nn::gx::DISPLAY0_HEIGHT; depthStencilBufferDesc.m_Area = NN_GX_MEM_VRAMB; depthStencilBufferDesc.m_Attachment = GL_DEPTH_STENCIL_ATTACHMENT; } demo::FrameBufferDescription frameBufferDesc; { frameBufferDesc.m_RenderBufferDescriptionArray[demo::DEMO_COLOR_BUFFER_INDEX] = colorBufferDesc; frameBufferDesc.m_RenderBufferDescriptionArray[demo::DEMO_DEPTH_STENCIL_BUFFER_INDEX] = depthStencilBufferDesc; } demo::DisplayBuffersDescription display0BuffersDesc; { display0BuffersDesc.m_TargetDisplay = NN_GX_DISPLAY0; display0BuffersDesc.m_DisplayBufferNum = demo::DEMO_DISPLAY_BUFFER_NUM; display0BuffersDesc.m_Format = GL_RGB8_OES; display0BuffersDesc.m_Width = nn::gx::DISPLAY0_WIDTH; display0BuffersDesc.m_Height = nn::gx::DISPLAY0_HEIGHT; display0BuffersDesc.m_Area = NN_GX_MEM_FCRAM; // display0BuffersDesc.m_Area = NN_GX_MEM_VRAMA; } demo::DisplayBuffersDescription display1BuffersDesc; { display1BuffersDesc.m_TargetDisplay = NN_GX_DISPLAY1; display1BuffersDesc.m_DisplayBufferNum = demo::DEMO_DISPLAY_BUFFER_NUM; display1BuffersDesc.m_Format = GL_RGB8_OES; display1BuffersDesc.m_Width = nn::gx::DISPLAY1_WIDTH; display1BuffersDesc.m_Height = nn::gx::DISPLAY1_HEIGHT; display1BuffersDesc.m_Area = NN_GX_MEM_FCRAM; // display1BuffersDesc.m_Area = NN_GX_MEM_VRAMB; } df.Initialize(nn::os::GetDeviceMemoryAddress(), nn::os::GetDeviceMemorySize(), 0x40000, 128, true, display0BuffersDesc, display1BuffersDesc, frameBufferDesc ); } void ReleaseRenderSystem() { df.Finalize(); } char SelectMark( s32 select ) { return (select == selectParam) ? '>' : ' '; } template void ChangeValue( T& src, s32 add, const T min, const T max ) { s32 value = static_cast(src) + add; s32 vmin = static_cast(min); s32 vmax = static_cast(max); if (value < vmin) { value += (vmax+1); } if (vmax < value) { value -= (vmax+1); value += vmin; } src = static_cast( value ); } void DrawText() { // display 0 df.SetRenderTarget(NN_GX_DISPLAY0); df.Clear(); { df.SetColor(0.0f, 0.0f, 0.5f); df.FillRectangle( 0, 0, 399, 255 ); df.SetColor(0.5f, 0.4f, 0.0f); df.FillRectangle( 0, 0, 399, 40 ); df.SetColor(0.5f, 0.0f, 0.4f); df.FillRectangle( 0, 180, 399, 40 ); df.SetColor(1.0f, 1.0f, 1.0f); df.DrawText( 100, 50, "** DEMO APPLICATION **" ); df.SetColor(1.0f, 1.0f, 1.0f); df.DrawText( 30, 80, "[A] Launch library applet." ); df.DrawText( 30, 100, "[Up or Down] Select parameter." ); df.DrawText( 30, 110, "[Left or Right] Change parameter." ); // Count df.DrawText( 340, 50, "%d", loopCnt ); } df.SwapBuffers(); // display 1 df.SetRenderTarget(NN_GX_DISPLAY1); df.Clear(); { df.SetColor(0.0f, 0.5f, 0.0f); df.FillRectangle( 0, 0, 399, 255 ); df.SetColor(1.0f, 1.0f, 1.0f); df.DrawText( 80, 50, "** DEMO APPLICATION **" ); df.DrawText( 30, 140, "%c FILTER [%s]", SelectMark(0), filterTypeStr[vsel_param.input.filterFillType] ); df.DrawText( 30, 150, "%c ENABLE SOFT RESET [%s]", SelectMark(1), softResetStr[vsel_param.config.softwareReset ? 1 : 0] ); df.DrawText( 30, 160, "%c ENABLE HOME BUTTON [%s]", SelectMark(2), homeButtonStr[vsel_param.config.homeButton ? 1 : 0] ); df.DrawText( 30, 170, "%c MESSAGE [%ls]", SelectMark(3), vsel_param.input.titleText ); } df.SwapBuffers(); } void DrawDisplay() { DrawText(); } void RestoreGraphics() { // Recover the GPU register settings nngxUpdateState(NN_GX_STATE_ALL); nngxValidateState(NN_GX_STATE_ALL,GL_TRUE); } } //---------------------------------------------------------------- AppletQueryReply myReceiveSleepQueryNotification( uptr arg ) { NN_UNUSED_VAR( arg ); NN_LOG("*** Application-1 sleepQuery \n"); if ( nn::applet::IsActive() ) { return nn::applet::REPLY_LATER; } else { return nn::applet::REPLY_ACCEPT; } } //---------------------------------------------------------------- void myReceiveAwakeNotification( uptr arg ) { NN_UNUSED_VAR( arg ); NN_LOG("*** Application-1 awake \n"); if ( nn::applet::IsActive() ) { nngxStartLcdDisplay(); } } //---------------------------------------------------------------- extern "C" void nnMain() { NN_TLOG_("----Application start\n"); nn::Result result; // applet declarations nn::applet::SetSleepQueryCallback( myReceiveSleepQueryNotification, 0 ); nn::applet::SetAwakeCallback( myReceiveAwakeNotification, 0 ); nn::applet::Enable(); if(nn::applet::IsExpectedToCloseApplication()) { // Quickly end the application nn::applet::PrepareToCloseApplication(); nn::applet::CloseApplication(); // Never reached return; } // hid result = nn::hid::Initialize(); NN_UTIL_PANIC_IF_FAILED(result); // Render class initialization SetupRenderSystem(); nn::hid::PadReader padReader; nn::hid::PadStatus ps; // Call parameter nn::voicesel::InitializeParameter( &vsel_param ); while(1) { loopCnt++; padReader.ReadLatest(&ps); // Render DrawDisplay(); // Start library applet with A Button if ( ps.trigger & nn::hid::BUTTON_A ) { nn::voicesel::StartVoiceSel( &vsel_param ); if(nn::applet::IsExpectedToCloseApplication()) { break; } // Recover the GPU register settings RestoreGraphics(); // Show information for selected file path NN_LOG("file path = [%ls]\n",vsel_param.output.filePath); } // Item selection if ( ps.trigger & nn::hid::BUTTON_UP ) { ChangeValue( selectParam, -1, 0, 3 ); } if ( ps.trigger & nn::hid::BUTTON_DOWN ) { ChangeValue( selectParam, +1, 0, 3 ); } // Item setting if ( ps.trigger & (nn::hid::BUTTON_LEFT | nn::hid::BUTTON_RIGHT) ) { s32 value = (ps.trigger & nn::hid::BUTTON_RIGHT) ? +1 : -1; switch (selectParam) { case 0: ChangeValue( vsel_param.input.filterFillType, value, nn::voicesel::FILTER_FILL_TYPE_ALL, nn::voicesel::FILTER_FILL_TYPE_25_LT ); break; case 1: ChangeValue( vsel_param.config.softwareReset, value, false, true ); break; case 2: ChangeValue( vsel_param.config.homeButton, value, false, true ); break; case 3: ::wcscpy( vsel_param.input.titleText, (value < 0) ? L"" : L"TEST MESSAGE" ); break; } } // Process HOME Button if ( nn::applet::IsExpectedToProcessHomeButton() ) { NN_LOG("HomeBtn.\n"); nn::applet::ProcessHomeButtonAndWait(); if(nn::applet::IsExpectedToCloseApplication()) { break; } RestoreGraphics(); } // POWER button process if ( nn::applet::IsExpectedToProcessPowerButton() ) { NN_LOG("PowerBtn.\n"); nn::applet::ProcessPowerButtonAndWait(); if(nn::applet::IsExpectedToCloseApplication()) { break; } RestoreGraphics(); } } NN_TLOG_("----Application is to be end\n"); // Free the render class ReleaseRenderSystem(); // Finalize hid nn::hid::Finalize(); // Exit application nn::applet::PrepareToCloseApplication(); nn::applet::CloseApplication(); // No need to call Finalize on applet // Execution will probably not reach here. NN_TLOG_("----Application end\n"); }