/*---------------------------------------------------------------------------* Project: WPAD demo program File: dummy_checker.c Copyright (C) 2007 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: dummy_checker.c,v $ Revision 1.5.2.1 2007/12/11 01:14:55 tojo Modified to handle the error code of WPADStatus. Revision 1.5 2007/07/11 12:47:49 tojo (none) Revision 1.4 2007/07/10 12:14:46 tojo (none) Revision 1.3 2007/05/02 07:52:23 tojo (none) Revision 1.2 2007/04/23 08:16:09 tojo (none) Revision 1.1 2007/04/18 01:30:48 tojo Initial check-in. *---------------------------------------------------------------------------*/ #include #include #include #include #include #include #include #include #define DEMO_USE_MEMLIB=1 // This turns on the DEMO library's MEM heaps. #include /*---------------------------------------------------------------------------* * Local Definitions *---------------------------------------------------------------------------*/ #define SCREEN_WIDTH 320 #define SCREEN_HEIGHT 240 #define FONT_HEIGHT 8 /*---------------------------------------------------------------------------* * Local Data *---------------------------------------------------------------------------*/ #define SMPBUF_SIZE 100 static WPADCLStatus cl_ringbuffer[SMPBUF_SIZE]; static WPADFSStatus fs_ringbuffer[SMPBUF_SIZE]; static WPADStatus co_ringbuffer[SMPBUF_SIZE]; /*---------------------------------------------------------------------------* * Function prototypes *---------------------------------------------------------------------------*/ // MEM2 memory allocation routines. The application must provide these to // WPAD, so it can setup the data transfer buffer. This buffer must reside // in MEM2. static void *myAlloc ( u32 size ); static u8 myFree ( void *ptr ); // callbacks void connectCallback ( s32 chan, s32 reason ); void extensionCallback ( s32 chan, s32 result ); void samplingCallback ( s32 chan ); // internal functions static void initialize ( void ); static void renderStatus ( void ); static void renderAimings ( void ); static void printIntro ( void ); static void printBuffer ( char *string, ... ); static u8 *get_dev_name ( u32 type ); static u8 *get_status_name ( s32 status ); /*===========================================================================* * F U N C T I O N D E F I N I T I O N S *===========================================================================*/ /*---------------------------------------------------------------------------* * Name : printIntro() * Description : * Arguments : None. * Returns : None. *---------------------------------------------------------------------------*/ static void printIntro( void ) { #ifdef _DEBUG OSReport("-------------------------------------------------------\n"); OSReport(" Dummy Extension Demo: \n"); OSReport(" Button A: Attach the future device. \n"); OSReport(" Button X: Attach the unsupported device. \n"); OSReport(" Button B: Detach the device. \n"); OSReport("-------------------------------------------------------\n"); #else OSReport("-------------------------------------------------------\n"); OSReport(" \n"); OSReport(" Dummy Extension cannot be used in release build!!! \n"); OSReport(" \n"); OSReport("-------------------------------------------------------\n"); #endif } static u8 buffer[WPAD_MEM_GAMEDATA_LEN]; /*---------------------------------------------------------------------------* * Name : main() * Description : * Arguments : None. * Returns : None. *---------------------------------------------------------------------------*/ int main( void ) { int i; initialize(); // - We must now register memory allocation/free functions // for MEM2. // - WPAD requires some memory in MEM2 for data transfers // between the controller and WPAD driver stack. // - Memory allocation only occurs once, at the initialization. // - Memory usage is on the order of 1KB. // - NOTE: We are using the MEM library allocators defined by // the DEMO library. // WPADRegisterAllocator(myAlloc, myFree); // Initialize WPAD! WPADInit(); for (i=0; ierr)); y+= FONT_HEIGHT; if( wpad_ptr->err != WPAD_ERR_INVALID ) { if( wpad_ptr->button & WPAD_BUTTON_LEFT ) buf[ 0] = '<'; if( wpad_ptr->button & WPAD_BUTTON_UP ) buf[ 1] = '^'; if( wpad_ptr->button & WPAD_BUTTON_DOWN ) buf[ 2] = 'v'; if( wpad_ptr->button & WPAD_BUTTON_RIGHT ) buf[ 3] = '>'; if( wpad_ptr->button & WPAD_BUTTON_A ) buf[ 4] = 'A'; if( wpad_ptr->button & WPAD_BUTTON_B ) buf[ 5] = 'B'; if( wpad_ptr->button & WPAD_BUTTON_1 ) buf[ 6] = '1'; if( wpad_ptr->button & WPAD_BUTTON_2 ) buf[ 7] = '2'; if( wpad_ptr->button & WPAD_BUTTON_MINUS ) buf[ 8] = '-'; if( wpad_ptr->button & WPAD_BUTTON_HOME ) buf[ 9] = 'H'; if( wpad_ptr->button & WPAD_BUTTON_PLUS ) buf[10] = '+'; } DEMOPrintf(x, y, 0, " %s", buf); y+= FONT_HEIGHT; if( wpad_ptr->err == WPAD_ERR_NONE || wpad_ptr->err == WPAD_ERR_CORRUPTED ) { DEMOPrintf(x, y, 0, " %04X %04X", (u16)(wpad_ptr->obj[0].x), (u16)(wpad_ptr->obj[0].y)); y+= FONT_HEIGHT; DEMOPrintf(x, y, 0, " %04X %04X", (u16)(wpad_ptr->obj[1].x), (u16)(wpad_ptr->obj[1].y)); y+= FONT_HEIGHT; DEMOPrintf(x, y, 0, " %04X %04X %04X", (u16)(wpad_ptr->accX), (u16)(wpad_ptr->accY), (u16)(wpad_ptr->accZ)); y+= FONT_HEIGHT; } else { DEMOPrintf(x, y, 0, " ---- ----"); y+= FONT_HEIGHT; DEMOPrintf(x, y, 0, " ---- ----"); y+= FONT_HEIGHT; DEMOPrintf(x, y, 0, " ---- ---- ----"); y+= FONT_HEIGHT; } y+= FONT_HEIGHT; if (WPAD_DEV_FREESTYLE == type) { if( fs_ptr->err == WPAD_ERR_NONE ) { if( fs_ptr->button & WPAD_BUTTON_C) buf2[ 0] = 'C'; if( fs_ptr->button & WPAD_BUTTON_Z) buf2[ 1] = 'Z'; } DEMOPrintf(x, y, 0, " %s", buf2); y+= FONT_HEIGHT; if( fs_ptr->err == WPAD_ERR_NONE ) { DEMOPrintf(x, y, 0, " %04X %04X", (u16)(fs_ptr->fsStickX), (u16)(fs_ptr->fsStickY)); y+= FONT_HEIGHT; DEMOPrintf(x, y, 0, " %04X %04X %04X", (u16)(fs_ptr->fsAccX), (u16)(fs_ptr->fsAccY), (u16)(fs_ptr->fsAccZ)); y+= FONT_HEIGHT; } else { DEMOPrintf(x, y, 0, " ---- ----"); y+= FONT_HEIGHT; DEMOPrintf(x, y, 0, " ---- ---- ----"); y+= FONT_HEIGHT; } } else { y+= FONT_HEIGHT * 3; } y+= FONT_HEIGHT; if (WPAD_DEV_CLASSIC == type) { if( cl_ptr->err == WPAD_ERR_NONE ) { if( cl_ptr->clButton & WPAD_CL_BUTTON_LEFT ) buf3[ 0] = '<'; if( cl_ptr->clButton & WPAD_CL_BUTTON_UP ) buf3[ 1] = '^'; if( cl_ptr->clButton & WPAD_CL_BUTTON_DOWN ) buf3[ 2] = 'v'; if( cl_ptr->clButton & WPAD_CL_BUTTON_RIGHT ) buf3[ 3] = '>'; if( cl_ptr->clButton & WPAD_CL_BUTTON_A ) buf3[ 4] = 'A'; if( cl_ptr->clButton & WPAD_CL_BUTTON_B ) buf3[ 5] = 'B'; if( cl_ptr->clButton & WPAD_CL_BUTTON_X ) buf3[ 6] = 'X'; if( cl_ptr->clButton & WPAD_CL_BUTTON_Y ) buf3[ 7] = 'Y'; if( cl_ptr->clButton & WPAD_CL_TRIGGER_L ) buf3[ 8] = 'L'; if( cl_ptr->clButton & WPAD_CL_TRIGGER_R ) buf3[ 9] = 'R'; if( cl_ptr->clButton & WPAD_CL_TRIGGER_ZL ) buf3[10] = 'z'; if( cl_ptr->clButton & WPAD_CL_TRIGGER_ZR ) buf3[11] = 'Z'; if( cl_ptr->clButton & WPAD_CL_BUTTON_MINUS ) buf3[12] = '-'; if( cl_ptr->clButton & WPAD_CL_BUTTON_HOME ) buf3[13] = 'H'; if( cl_ptr->clButton & WPAD_CL_BUTTON_PLUS ) buf3[14] = '+'; } DEMOPrintf(x, y, 0, " %s", buf3); y+= FONT_HEIGHT; if( cl_ptr->err == WPAD_ERR_NONE ) { DEMOPrintf(x, y, 0, " %04X %04X", (u16)(cl_ptr->clLStickX), (u16)(cl_ptr->clLStickY)); y+= FONT_HEIGHT; DEMOPrintf(x, y, 0, " %04X %04X", (u16)(cl_ptr->clRStickX), (u16)(cl_ptr->clRStickY)); y+= FONT_HEIGHT; DEMOPrintf(x, y, 0, " %04X %04X", (u16)(cl_ptr->clTriggerL), (u16)(cl_ptr->clTriggerR)); y+= FONT_HEIGHT; } else { DEMOPrintf(x, y, 0, " ---- ----"); y+= FONT_HEIGHT; DEMOPrintf(x, y, 0, " ---- ----"); y+= FONT_HEIGHT; DEMOPrintf(x, y, 0, " ---- ----"); y+= FONT_HEIGHT; } } // if classic } // if no error } // end renderStatus() static u8 *get_dev_name( u32 type ) { u8 str_dev_core [] = " Core "; u8 str_dev_extn [] = " Extn "; u8 str_dev_cl [] = " Classic "; u8 str_dev_future [] = " Future "; u8 str_dev_notsup [] = " Not sup "; u8 str_dev_unknown[] = " Unknwon "; u8 *ptr; switch(type) { case WPAD_DEV_CORE: ptr = &str_dev_core[0]; break; case WPAD_DEV_FREESTYLE: ptr = &str_dev_extn[0]; break; case WPAD_DEV_CLASSIC: ptr = &str_dev_cl[0]; break; case WPAD_DEV_FUTURE: ptr = &str_dev_future[0]; break; case WPAD_DEV_NOT_SUPPORTED: ptr = &str_dev_notsup[0]; break; case WPAD_DEV_UNKNOWN: default: ptr = &str_dev_unknown[0]; break; } // end switch return(ptr); } // end static u8 *get_status_name( s32 status ) { u8 str_status_ok [] = " OK "; u8 str_status_none[] = " NONE "; u8 str_status_busy[] = " BUSY "; u8 str_status_xfer[] = " Transfer "; u8 str_status_inv [] = " INVALID "; u8 str_status_crpt[] = " Corrupted"; u8 str_status_unk [] = " UNKNOWN "; u8 *ptr; switch(status) { case WPAD_ERR_NONE: ptr = &str_status_ok[0]; break; case WPAD_ERR_NO_CONTROLLER: ptr = &str_status_none[0]; break; case WPAD_ERR_BUSY: ptr = &str_status_busy[0]; break; case WPAD_ERR_TRANSFER: ptr = &str_status_xfer[0]; break; case WPAD_ERR_INVALID: ptr = &str_status_inv[0]; break; case WPAD_ERR_CORRUPTED: ptr = &str_status_crpt[0]; break; default: ptr = &str_status_unk[0]; break; } // end switch return(ptr); } // end static void initialize( void ) { const GXColor DARKBLUE = { 0, 0, 40, 255 }; OSInit(); DEMOInit( &GXNtsc480IntDf ); GXSetCopyClear( DARKBLUE, 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(); } // end /*---------------------------------------------------------------------------* * Name : renderAimings() * Description : * Arguments : None. * Returns : None. *---------------------------------------------------------------------------*/ static void renderAimings( void ) { u32 latest; u32 index; int i; u32 fmt; WPADStatus *co_ptr; WPADFSStatus *fs_ptr; WPADCLStatus *cl_ptr; fmt = WPADGetDataFormat(WPAD_CHAN0); switch (fmt) { case WPAD_FMT_CORE: case WPAD_FMT_CORE_ACC: case WPAD_FMT_CORE_ACC_DPD: co_ptr = (WPADStatus *)(&co_ringbuffer[0]); latest = WPADGetLatestIndexInBuf(WPAD_CHAN0); index = ((latest - 1) + SMPBUF_SIZE) % SMPBUF_SIZE; for (i=0; i