diff --git a/SDL/src/joystick/wii/SDL_sysjoystick.c b/SDL/src/joystick/wii/SDL_sysjoystick.c index da57251..aaffabd 100644 --- a/SDL/src/joystick/wii/SDL_sysjoystick.c +++ b/SDL/src/joystick/wii/SDL_sysjoystick.c @@ -87,6 +87,8 @@ static int __jspad_enabled = 1; static int __numwiijoysticks = 4; static int __numgcjoysticks = 4; +static int __scan_pads_callback_set = 0; + /* Function to scan the system for joysticks. * This function should set SDL_numjoysticks to the number of available * joysticks. Joystick 0 should be the system default joystick. @@ -110,6 +112,14 @@ const char *SDL_SYS_JoystickName(int index) return (const char *)joy_name; } + +static void +UpdatePadsCB() +{ + WPAD_ScanPads(); + PAD_ScanPads(); +} + /* Function to open a joystick for use. The joystick to open is specified by the index field of the joystick. This should fill the nbuttons and naxes fields of the joystick structure. @@ -147,6 +157,11 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) joystick->nhats = MAX_GC_HATS; } } + + /* Update pads at vertical retrace */ + VIDEO_SetPostRetraceCallback ((VIRetraceCallback)UpdatePadsCB); + __scan_pads_callback_set++; + return(0); } @@ -381,6 +396,11 @@ void SDL_SYS_JoystickClose(SDL_Joystick *joystick) { if (joystick->hwdata != NULL) SDL_free(joystick->hwdata); + + /* Clear callback again */ + __scan_pads_callback_set--; + if ( __scan_pads_callback_set == 0 ) + VIDEO_SetPostRetraceCallback (NULL); } /* Function to perform any system-specific joystick related cleanup */ diff --git a/SDL/src/video/wii/SDL_wiivideo.c b/SDL/src/video/wii/SDL_wiivideo.c index 9c0d197..0375d5a 100644 --- a/SDL/src/video/wii/SDL_wiivideo.c +++ b/SDL/src/video/wii/SDL_wiivideo.c @@ -164,13 +164,6 @@ draw_square (Mtx v) GX_End (); } -static void -UpdatePadsCB() -{ - WPAD_ScanPads(); - PAD_ScanPads(); -} - void WII_InitVideoSystem() { @@ -194,9 +187,6 @@ WII_InitVideoSystem() VIDEO_ClearFrameBuffer(display_mode, xfb[1], COLOR_BLACK); VIDEO_SetNextFramebuffer (xfb[0]); - // video callbacks - VIDEO_SetPostRetraceCallback ((VIRetraceCallback)UpdatePadsCB); - // Show the screen. VIDEO_SetBlack(FALSE); VIDEO_Flush();