/* Function to scan the system for joysticks. * Joystick 0 should be the system default joystick. * This function should return the number of available joysticks, or -1 * on an unrecoverable fatal error. */ int SDL_SYS_JoystickInit(void) { static ISpDeviceClass classes[4] = { kISpDeviceClass_Joystick, kISpDeviceClass_Gamepad, kISpDeviceClass_Wheel, 0 }; OSErr err; int i; UInt32 count, numJoysticks; if ( (Ptr)0 == (Ptr)ISpStartup ) { SDL_SetError("InputSprocket not installed"); return -1; // InputSprocket not installed } if( (Ptr)0 == (Ptr)ISpGetVersion ) { SDL_SetError("InputSprocket not version 1.1 or newer"); return -1; // old version of ISp (not at least 1.1) } ISpStartup(); /* Get all the joysticks */ numJoysticks = 0; for ( i=0; classes[i]; ++i ) { count = 0; err = ISpDevices_ExtractByClass( classes[i], MAX_JOYSTICKS-numJoysticks, &count, &SYS_Joysticks[numJoysticks]); numJoysticks += count; } for(i = 0; i < numJoysticks; i++) { ISpDevice_GetDefinition( SYS_Joysticks[i], sizeof(ISpDeviceDefinition), &SYS_DevDef[i]); err = ISpElementList_New( 0, NULL, &SYS_Elements[i], 0); if (err) { SDL_OutOfMemory(); return -1; } ISpDevice_GetElementList( SYS_Joysticks[i], &SYS_Elements[i]); } ISpDevices_Deactivate(numJoysticks, SYS_Joysticks); return numJoysticks; }
/* Function to close a joystick after use */ void SDL_SYS_JoystickClose(SDL_Joystick *joystick) { int index; index = joystick->index; ISpDevices_Deactivate( 1, &SYS_Joysticks[index]); }