/*---------------------------------------------------------------------------* Project: WPAD demo program File: full_mode.c Copyright (C) 2006 Nintendo. 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. $Log: full_mode.c,v $ Revision 1.6.4.1 2007/12/11 01:15:27 tojo Modified to handle the error code of WPADStatus. Revision 1.6 2007/04/23 08:48:46 tojo (none) Revision 1.5 2007/04/10 10:15:01 tojo (none) Revision 1.4 2007/03/19 11:14:38 tojo (none) Revision 1.3 2006/10/23 01:05:09 tojo Called WPADSetConnectCallback before initialization complete. Revision 1.2 2006/09/08 07:59:30 tojo (none) Revision 1.1 2006/09/05 12:22:31 tojo (none) *---------------------------------------------------------------------------*/ #define DEMO_USE_MEMLIB = 1 #include #include #include #include #define SCREEN_WIDTH 1024 #define SCREEN_HEIGHT 768 /*---------------------------------------------------------------------------* * Private function prototypes *---------------------------------------------------------------------------*/ void *myAlloc( u32 size ); u8 myFree ( void *ptr ); /*---------------------------------------------------------------------------* * Globals *---------------------------------------------------------------------------*/ s32 status; u32 type; const GXColor LIME = { 0, 255, 0, 255 }; const GXColor AQUA = { 0, 255, 255, 255 }; const GXColor MAGENTA = { 255, 0, 255, 255 }; const GXColor GRAY = { 128, 128, 128, 255 }; const GXColor WHITE = { 255, 255, 255, 255 }; const GXColor TEAL = { 0, 128, 128, 255 }; const GXColor ORANGE = { 255, 165, 0, 255 }; const GXColor PINK = { 255, 192, 203, 255 }; const GXColor GREEN = { 0, 128, 0, 255 }; const f32 PI=3.141592f; static GXColor circle[4]; static GXColor box[4]; /*---------------------------------------------------------------------------* * Name : myAlloc() * Description : Callback needed by WPAD to allocate mem from MEM2 heap * Arguments : size of block, in bytes. * Returns : pointer to allocated block. *---------------------------------------------------------------------------*/ void *myAlloc( u32 size ) { void *ptr; ptr = MEMAllocFromAllocator(&DemoAllocator2, size); ASSERTMSG(ptr, "Memory allocation failed\n"); return(ptr); } /*---------------------------------------------------------------------------* * Name : myFree() * Description : Callback needed by WPAD to free mem from MEM2 heap * Arguments : point to the block that should be freed. * Returns : Always 1. *---------------------------------------------------------------------------*/ u8 myFree( void *ptr ) { MEMFreeToAllocator(&DemoAllocator2, ptr); return(1); } /*---------------------------------------------------------------------------* * Name : initialize() * Description : Performs basic system initialization. * Arguments : None. * Returns : None. *---------------------------------------------------------------------------*/ static void initialize( void ) { OSInit(); DEMOInit( &GXNtsc480IntDf ); GXSetCopyClear( GRAY, GX_MAX_Z24 ); GXCopyDisp( DEMOGetCurrentBuffer(), GX_TRUE ); DEMOInitCaption( DM_FT_XLU, SCREEN_WIDTH, SCREEN_HEIGHT ); GXSetZMode( GX_ENABLE, GX_ALWAYS, GX_ENABLE ); // Set pixel processing mode GXSetBlendMode( GX_BM_BLEND, GX_BL_ONE, GX_BL_ONE, GX_LO_CLEAR ); // Translucent mode DEMOPadInit(); circle[0] = WHITE; circle[1] = AQUA; circle[2] = LIME; circle[3] = PINK; box[0] = ORANGE; box[1] = TEAL; box[2] = GREEN; box[3] = MAGENTA; } /* end initialize() */ /*---------------------------------------------------------------------------* * Name : RenderLine() * Description : Draw line * Arguments : x1 and y1 are the coordinate of start point x2 and y2 are the coordinate of end point clr is line color * Returns : None. *---------------------------------------------------------------------------*/ static void RenderLine( s16 x1, s16 y1, s16 x2, s16 y2, GXColor clr ) { Mtx mv; MTXIdentity(mv); GXLoadPosMtxImm(mv, GX_PNMTX0); GXSetCurrentMtx(GX_PNMTX0); GXSetNumChans(1); GXSetNumTevStages(1); GXSetNumTexGens(0); GXSetTevOp(GX_TEVSTAGE0, GX_PASSCLR); GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0); GXClearVtxDesc(); GXSetVtxDesc(GX_VA_POS, GX_DIRECT); GXSetVtxDesc(GX_VA_CLR0, GX_DIRECT); GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XY, GX_S16, 0); GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); GXBegin(GX_LINES, GX_VTXFMT0, 2); GXPosition2s16(x1, y1); GXColor4u8(clr.r, clr.g, clr.b, clr.a); GXPosition2s16(x2, y2); GXColor4u8(clr.r, clr.g, clr.b, clr.a); GXEnd(); } /*---------------------------------------------------------------------------* * Name : RenderCircle() * Description : Draw a circle * Arguments : x and y are the coordinate of center point. div is roundish clr is color * Returns : None. *---------------------------------------------------------------------------*/ static void RenderCircle( s16 x, s16 y, s16 r, s16 div, GXColor clr ) { f32 th; f32 phi; s16 i; for(i=0; ierr == WPAD_ERR_NONE) { for(i=0; iexp[i].pixel * 2))/2); RenderCircle(ep->obj[i].x, ep->obj[i].y, (s16)(sqrt((f32)ep->obj[i].size/PI)*8), 16, circle[chan]); RenderLine(ep->exp[i].range_x1, ep->exp[i].range_y1, ep->exp[i].range_x1, ep->exp[i].range_y2, box[chan]); RenderLine(ep->exp[i].range_x1, ep->exp[i].range_y2, ep->exp[i].range_x2, ep->exp[i].range_y2, box[chan]); RenderLine(ep->exp[i].range_x2, ep->exp[i].range_y2, ep->exp[i].range_x2, ep->exp[i].range_y1, box[chan]); RenderLine(ep->exp[i].range_x2, ep->exp[i].range_y1, ep->exp[i].range_x1, ep->exp[i].range_y1, box[chan]); } } } } } /*---------------------------------------------------------------------------* * Name : dpdCallback() * Description : Callback called when dpd is turned off. Turn on dpd as full mode. * Arguments : chan controller channel result result code * Returns : None. *---------------------------------------------------------------------------*/ static void dpdCallback( s32 chan, s32 result ) { #pragma unused(chan, result) if (result == WPAD_ERR_NONE) { WPADControlDpd(chan, WPAD_DPD_FULL, NULL); WPADSetDataFormat(chan, WPAD_FMT_CORE_ACC_DPD_FULL); } } /*---------------------------------------------------------------------------* * Name : ExtensionCallback() * Description : Callback called when an extension is installed/detached. * Arguments : chan controller channel result result code * Returns : None. *---------------------------------------------------------------------------*/ static void ExtensionCallback( s32 chan, s32 result ) { switch(result) { case WPAD_DEV_CORE: WPADControlDpd(chan, WPAD_DPD_FULL, NULL); WPADSetDataFormat(chan, WPAD_FMT_CORE_ACC_DPD_FULL); break; case WPAD_DEV_FREESTYLE: WPADControlDpd(chan, WPAD_DPD_STD, NULL); WPADSetDataFormat(chan, WPAD_FMT_FREESTYLE_ACC_DPD); break; case WPAD_DEV_CLASSIC: WPADControlDpd(chan, WPAD_DPD_STD, NULL); WPADSetDataFormat(chan, WPAD_FMT_CLASSIC_ACC_DPD); break; default: break; } } /*---------------------------------------------------------------------------* * Name : ConnectCallback() * Description : Callback called when a controller connects/disconnects. * Arguments : chan controller channel result result code * Returns : None. *---------------------------------------------------------------------------*/ static void ConnectCallback( s32 chan, s32 reason ) { if (reason == WPAD_ERR_NONE) { WPADSetExtensionCallback( chan, ExtensionCallback ); WPADControlDpd(chan, WPAD_DPD_FULL, dpdCallback); WPADSetDataFormat(chan, WPAD_FMT_CORE_ACC_DPD_FULL); } } /*---------------------------------------------------------------------------* * Name : PrintIntro() * Description : * Arguments : None. * Returns : None. *---------------------------------------------------------------------------*/ static void PrintIntro( void ) { OSReport("* -------------------------------------------- *\n"); OSReport("* WPAD SAMPLE DEMO: *\n"); OSReport("* *\n"); OSReport("* DPD Full mode and Change DPD sensitivity *\n"); OSReport("* DPD sensitivity range (low) 1 <--> 5 (high) *\n"); OSReport("* -------------------------------------------- *\n"); OSReport("* MENU: Only Controller1 can change *\n"); OSReport("* -------------------------------------------- *\n"); OSReport("* press + button: increase the dpd sensitivity.*\n"); OSReport("* press - button: decrease the dpd sensitivity.*\n"); OSReport("* -------------------------------------------- *\n"); } static void changeSensitivity( u8 level ) { s32 chan; u32 type; WPADSetDpdSensitivity(level); for(chan=0; chan