1 /*---------------------------------------------------------------------------*
2 File: simple.c
3
4 Copyright (C) 2007 Nintendo. All rights reserved.
5
6 *---------------------------------------------------------------------------*/
7 #include <stdio.h> // size_t
8 #include <string.h>
9 #include <wstring.h>
10
11 #include <revolution.h>
12 #define DEMO_USE_MEMLIB 1
13 #include <demo.h>
14 #include <revolution/kpad.h>
15
16 static void* AllocFromPadHeap( u32 size );
17 static u8 FreeToPadHeap ( void* ptr );
18
19 /*---------------------------------------------------------------------------*
20 Name: Main
21
22 Arguments: None.
23
24 Description: The application's main loop.
25
26 Returns: None.
27 *---------------------------------------------------------------------------*/
main(int argc,char * argv[])28 void main ( int argc, char* argv[] )
29 {
30 #pragma unused( argc , argv )
31 GXColor Black = {0, 0, 0, 0};
32 KPADStatus input;
33
34 // Demo init
35 DEMOInit(NULL);
36 // Font init
37 (void)DEMOInitROMFont(); // Use IPL ROM font
38 GXSetCopyClear(Black, 0x00ffffff);
39 GXCopyDisp(DEMOGetCurrentBuffer(), GX_TRUE);
40
41 // Initialize KPAD
42 WPADRegisterAllocator( AllocFromPadHeap, FreeToPadHeap );
43 KPADInit();
44
45 memset( &input, 0, sizeof(KPADStatus) );
46
47 // Main loop
48 while (1) {
49 GXRenderModeObj* rmp;
50
51 KPADRead( WPAD_CHAN0, &input, 1 );
52
53 DEMOBeforeRender();
54
55 // None
56
57 rmp = DEMOGetRenderModeObj();
58 DEMOInitCaption(DM_FT_XLU, (s16) rmp->fbWidth, (s16) rmp->efbHeight);
59 DEMOSetFontType(DM_FT_XLU);
60 DEMOSetROMFontSize(32, -1);
61
62 DEMORFPrintf(32, 128, 0, "Push HOME button" );
63 DEMORFPrintf(64, 160, 0, "to return to Wii Menu." );
64
65 DEMODoneRender();
66
67 // If HOME is pressed, return to the Wii Menu
68 if ( input.trig & KPAD_BUTTON_HOME )
69 {
70 VISetBlack( TRUE );
71 VIFlush();
72 VIWaitForRetrace();
73 OSReturnToMenu();
74 }
75 }
76 }
77
78
79 /*---------------------------------------------------------------------------*
80 Name : AllocFromPadHeap
81 Description : Dynamically allocates memory for the WPAD library.
82 Arguments : size: Size of memory to allocate (in bytes)
83 Returns : void*: Start address of the allocated memory.
84 *---------------------------------------------------------------------------*/
AllocFromPadHeap(u32 size)85 static void* AllocFromPadHeap( u32 size )
86 {
87 return MEMAllocFromAllocator( &DemoAllocator2, size );
88 }
89
90
91 /*---------------------------------------------------------------------------*
92 Name : FreeToPadHeap
93 Description : Deallocates memory dynamically allocated for the WPAD library.
94 Arguments : ptr: Start address of the memory to deallocate
95 Returns : u8: Returns 0 if the attempt to deallocate memory fails.
96 *---------------------------------------------------------------------------*/
FreeToPadHeap(void * ptr)97 static u8 FreeToPadHeap( void* ptr )
98 {
99 if ( !ptr )
100 {
101 return 0;
102 }
103
104 MEMFreeToAllocator( &DemoAllocator2, ptr );
105 ptr = NULL;
106
107 return 1;
108 }
109