/*---------------------------------------------------------------------------* File: simple.c Copyright (C) 2007 Nintendo. All rights reserved. *---------------------------------------------------------------------------*/ #include // size_t #include #include #include #define DEMO_USE_MEMLIB 1 #include #include static void* AllocFromPadHeap( u32 size ); static u8 FreeToPadHeap ( void* ptr ); /*---------------------------------------------------------------------------* Name: Main Arguments: None. Description: The application's main loop. Returns: None. *---------------------------------------------------------------------------*/ void main ( int argc, char* argv[] ) { #pragma unused( argc , argv ) GXColor Black = {0, 0, 0, 0}; KPADStatus input; // Demo init DEMOInit(NULL); // Font init (void)DEMOInitROMFont(); // Use IPL ROM font GXSetCopyClear(Black, 0x00ffffff); GXCopyDisp(DEMOGetCurrentBuffer(), GX_TRUE); // Initialize KPAD WPADRegisterAllocator( AllocFromPadHeap, FreeToPadHeap ); KPADInit(); memset( &input, 0, sizeof(KPADStatus) ); // Main loop while (1) { GXRenderModeObj* rmp; KPADRead( WPAD_CHAN0, &input, 1 ); DEMOBeforeRender(); // None rmp = DEMOGetRenderModeObj(); DEMOInitCaption(DM_FT_XLU, (s16) rmp->fbWidth, (s16) rmp->efbHeight); DEMOSetFontType(DM_FT_XLU); DEMOSetROMFontSize(32, -1); DEMORFPrintf(32, 128, 0, "Push HOME button" ); DEMORFPrintf(64, 160, 0, "to return to Wii Menu." ); DEMODoneRender(); // If HOME is pressed, return to the Wii Menu if ( input.trig & KPAD_BUTTON_HOME ) { VISetBlack( TRUE ); VIFlush(); VIWaitForRetrace(); OSReturnToMenu(); } } } /*---------------------------------------------------------------------------* Name : AllocFromPadHeap Description : Dynamically allocates memory for the WPAD library. Arguments : size: Size of memory to allocate (in bytes) Returns : void*: Start address of the allocated memory. *---------------------------------------------------------------------------*/ static void* AllocFromPadHeap( u32 size ) { return MEMAllocFromAllocator( &DemoAllocator2, size ); } /*---------------------------------------------------------------------------* Name : FreeToPadHeap Description : Deallocates memory dynamically allocated for the WPAD library. Arguments : ptr: Start address of the memory to deallocate Returns : u8: Returns 0 if the attempt to deallocate memory fails. *---------------------------------------------------------------------------*/ static u8 FreeToPadHeap( void* ptr ) { if ( !ptr ) { return 0; } MEMFreeToAllocator( &DemoAllocator2, ptr ); ptr = NULL; return 1; }