Moving non-Windows platform-specific code lower in the file again to avoid declaratio...
[freeglut] / src / Common / freeglut_joystick.c
index 17eeb00..962b0f1 100644 (file)
  * interspersed\r
  */\r
 \r
-/* XXX It might be better to poll the operating system for the numbers of buttons and\r
- * XXX axes and then dynamically allocate the arrays.\r
- */\r
-#define _JS_MAX_BUTTONS 32\r
-\r
 #if TARGET_HOST_MACINTOSH\r
-#    define _JS_MAX_AXES  9\r
 #    include <InputSprocket.h>\r
 #endif\r
 \r
 #if TARGET_HOST_MAC_OSX\r
-#    define _JS_MAX_AXES 16\r
 #    include <mach/mach.h>\r
 #    include <IOKit/IOkitLib.h>\r
 #    include <IOKit/hid/IOHIDLib.h>\r
 #endif\r
 \r
 #if TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE)\r
-#    define _JS_MAX_AXES  8\r
 #    include <windows.h>\r
 #    include <mmsystem.h>\r
 #    include <regstr.h>\r
@@ -68,7 +60,6 @@
 #endif\r
 \r
 #if TARGET_HOST_POSIX_X11\r
-#    define _JS_MAX_AXES 16\r
 #    ifdef HAVE_SYS_IOCTL_H\r
 #        include <sys/ioctl.h>\r
 #    endif\r
@@ -376,65 +367,6 @@ static int fghJoystickInitializeHID(struct os_specific_s *os,
 #endif\r
 \r
 /*\r
- * Definition of "SFG_Joystick" structure -- based on JS's "jsJoystick" object class.\r
- * See "js.h" lines 80-178.\r
- */\r
-typedef struct tagSFG_Joystick SFG_Joystick;\r
-struct tagSFG_Joystick\r
-{\r
-#if TARGET_HOST_MACINTOSH\r
-#define  ISP_NUM_AXIS    9\r
-#define  ISP_NUM_NEEDS  41\r
-    ISpElementReference isp_elem  [ ISP_NUM_NEEDS ];\r
-    ISpNeed             isp_needs [ ISP_NUM_NEEDS ];\r
-#endif\r
-\r
-#if TARGET_HOST_MAC_OSX\r
-    IOHIDDeviceInterface ** hidDev;\r
-    IOHIDElementCookie buttonCookies[41];\r
-    IOHIDElementCookie axisCookies[_JS_MAX_AXES];\r
-    long minReport[_JS_MAX_AXES],\r
-         maxReport[_JS_MAX_AXES];\r
-#endif\r
-\r
-#if TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE)\r
-    JOYCAPS     jsCaps;\r
-    JOYINFOEX   js;\r
-    UINT        js_id;\r
-#endif\r
-\r
-\r
-#if TARGET_HOST_POSIX_X11\r
-#   if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)\r
-       struct os_specific_s *os;\r
-#   endif\r
-\r
-#   ifdef JS_NEW\r
-       struct js_event     js;\r
-       int          tmp_buttons;\r
-       float        tmp_axes [ _JS_MAX_AXES ];\r
-#   else\r
-       struct JS_DATA_TYPE js;\r
-#   endif\r
-\r
-    char         fname [ 128 ];\r
-    int          fd;\r
-#endif\r
-\r
-    int          id;\r
-    GLboolean    error;\r
-    char         name [ 128 ];\r
-    int          num_axes;\r
-    int          num_buttons;\r
-\r
-    float dead_band[ _JS_MAX_AXES ];\r
-    float saturate [ _JS_MAX_AXES ];\r
-    float center   [ _JS_MAX_AXES ];\r
-    float max      [ _JS_MAX_AXES ];\r
-    float min      [ _JS_MAX_AXES ];\r
-};\r
-\r
-/*\r
  * Functions associated with the "jsJoystick" class in PLIB\r
  */\r
 #if TARGET_HOST_MAC_OSX\r
@@ -455,13 +387,17 @@ static void fghJoystickAddHatElement ( SFG_Joystick* joy, CFDictionaryRef hat );
 #endif\r
 \r
 \r
+/* External function declarations (mostly platform-specific) */\r
+extern void fgPlatformJoystickOpen( SFG_Joystick* joy );\r
+extern void fgPlatformJoystickInit( SFG_Joystick *fgJoystick[], int ident );\r
+extern void fgPlatformJoystickClose ( int ident );\r
+\r
 /*\r
  * The static joystick structure pointer\r
  */\r
 #define MAX_NUM_JOYSTICKS  2\r
 static SFG_Joystick *fgJoystick [ MAX_NUM_JOYSTICKS ];\r
 \r
-\r
 /*\r
  * Read the raw joystick data\r
  */\r
@@ -993,109 +929,16 @@ static void fghJoystickAddHatElement ( SFG_Joystick *joy, CFDictionaryRef button
 }\r
 #endif\r
 \r
-#if TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE)\r
-/* Inspired by\r
-   http://msdn.microsoft.com/archive/en-us/dnargame/html/msdn_sidewind3d.asp\r
+/*\r
+ *  Platform-Specific Code\r
  */\r
-#    if FREEGLUT_LIB_PRAGMAS\r
-#        pragma comment (lib, "advapi32.lib")\r
-#    endif\r
-\r
-static int fghJoystickGetOEMProductName ( SFG_Joystick* joy, char *buf, int buf_sz )\r
-{\r
-    char buffer [ 256 ];\r
-\r
-    char OEMKey [ 256 ];\r
-\r
-    HKEY  hKey;\r
-    DWORD dwcb;\r
-    LONG  lr;\r
-\r
-    if ( joy->error )\r
-        return 0;\r
-\r
-    /* Open .. MediaResources\CurrentJoystickSettings */\r
-    _snprintf ( buffer, sizeof(buffer), "%s\\%s\\%s",\r
-                REGSTR_PATH_JOYCONFIG, joy->jsCaps.szRegKey,\r
-                REGSTR_KEY_JOYCURR );\r
-\r
-    lr = RegOpenKeyEx ( HKEY_LOCAL_MACHINE, buffer, 0, KEY_QUERY_VALUE, &hKey);\r
-\r
-    if ( lr != ERROR_SUCCESS ) return 0;\r
 \r
-    /* Get OEM Key name */\r
-    dwcb = sizeof(OEMKey);\r
-\r
-    /* JOYSTICKID1-16 is zero-based; registry entries for VJOYD are 1-based. */\r
-    _snprintf ( buffer, sizeof(buffer), "Joystick%d%s", joy->js_id + 1, REGSTR_VAL_JOYOEMNAME );\r
-\r
-    lr = RegQueryValueEx ( hKey, buffer, 0, 0, (LPBYTE) OEMKey, &dwcb);\r
-    RegCloseKey ( hKey );\r
-\r
-    if ( lr != ERROR_SUCCESS ) return 0;\r
-\r
-    /* Open OEM Key from ...MediaProperties */\r
-    _snprintf ( buffer, sizeof(buffer), "%s\\%s", REGSTR_PATH_JOYOEM, OEMKey );\r
-\r
-    lr = RegOpenKeyEx ( HKEY_LOCAL_MACHINE, buffer, 0, KEY_QUERY_VALUE, &hKey );\r
-\r
-    if ( lr != ERROR_SUCCESS ) return 0;\r
-\r
-    /* Get OEM Name */\r
-    dwcb = buf_sz;\r
-\r
-    lr = RegQueryValueEx ( hKey, REGSTR_VAL_JOYOEMNAME, 0, 0, (LPBYTE) buf,\r
-                             &dwcb );\r
-    RegCloseKey ( hKey );\r
-\r
-    if ( lr != ERROR_SUCCESS ) return 0;\r
-\r
-    return 1;\r
-}\r
-#endif\r
-\r
-\r
-static void fghJoystickOpen( SFG_Joystick* joy )\r
-{\r
-    int i = 0;\r
 #if TARGET_HOST_MACINTOSH\r
+void fgPlatformJoystickOpen( SFG_Joystick* joy )\r
+{\r
+       int i = 0;\r
     OSStatus err;\r
-#endif\r
-#if TARGET_HOST_MAC_OSX\r
-        IOReturn rv;\r
-        SInt32 score;\r
-        IOCFPlugInInterface **plugin;\r
-\r
-        HRESULT pluginResult;\r
-\r
-        CFDictionaryRef props;\r
-    CFTypeRef topLevelElement;\r
-#endif\r
-#if TARGET_HOST_POSIX_X11\r
-#    if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ )\r
-       char *cp;\r
-#    endif\r
-#    ifdef JS_NEW\r
-       unsigned char u;\r
-#    else\r
-#      if defined( __linux__ ) || TARGET_HOST_SOLARIS\r
-         int counter = 0;\r
-#      endif\r
-#    endif\r
-#endif\r
-\r
-    /* Silence gcc, the correct #ifdefs would be too fragile... */\r
-    (void)i;\r
-\r
-    /*\r
-     * Default values (for no joystick -- each conditional will reset the\r
-     * error flag)\r
-     */\r
-    joy->error = TRUE;\r
-    joy->num_axes = joy->num_buttons = 0;\r
-    joy->name[ 0 ] = '\0';\r
 \r
-#if TARGET_HOST_MACINTOSH\r
     /* XXX FIXME: get joystick name in Mac */\r
 \r
     err = ISpStartup( );\r
@@ -1193,9 +1036,37 @@ static void fghJoystickOpen( SFG_Joystick* joy )
     }\r
     else\r
         joy->num_buttons = joy->num_axes = 0;\r
+}\r
+\r
+\r
+void fgPlatformJoystickInit( SFG_Joystick *fgJoystick[], int ident )\r
+{\r
+    fgJoystick[ ident ]->id = ident;\r
+    snprintf( fgJoystick[ ident ]->fname, sizeof(fgJoystick[ ident ]->fname), "/dev/js%d", ident ); /* FIXME */\r
+    fgJoystick[ ident ]->error = GL_FALSE;\r
+}\r
+\r
+\r
+void fgPlatformJoystickClose ( int ident )\r
+{\r
+    ISpSuspend( );\r
+    ISpStop( );\r
+    ISpShutdown( );\r
+}\r
 #endif\r
 \r
 #if TARGET_HOST_MAC_OSX\r
+void fgPlatformJoystickOpen( SFG_Joystick* joy )\r
+{\r
+    IOReturn rv;\r
+    SInt32 score;\r
+    IOCFPlugInInterface **plugin;\r
+\r
+    HRESULT pluginResult;\r
+\r
+    CFDictionaryRef props;\r
+    CFTypeRef topLevelElement;\r
+\r
     if( joy->id >= numDevices )\r
     {\r
         fgWarning( "device index out of range in fgJoystickOpen()" );\r
@@ -1243,71 +1114,77 @@ static void fghJoystickOpen( SFG_Joystick* joy )
     enumerateElements( topLevelElement );\r
 \r
     CFRelease( props );\r
-#endif\r
-\r
-#if TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE)\r
-    joy->js.dwFlags = JOY_RETURNALL;\r
-    joy->js.dwSize  = sizeof( joy->js );\r
+}\r
 \r
-    memset( &joy->jsCaps, 0, sizeof( joy->jsCaps ) );\r
 \r
-    joy->error =\r
-        ( joyGetDevCaps( joy->js_id, &joy->jsCaps, sizeof( joy->jsCaps ) ) !=\r
-          JOYERR_NOERROR );\r
+void fgPlatformJoystickInit( SFG_Joystick *fgJoystick[], int ident )\r
+{\r
+    fgJoystick[ ident ]->id = ident;\r
+    fgJoystick[ ident ]->error = GL_FALSE;\r
+    fgJoystick[ ident ]->num_axes = 0;\r
+    fgJoystick[ ident ]->num_buttons = 0;\r
 \r
-    if( joy->jsCaps.wNumAxes == 0 )\r
-    {\r
-        joy->num_axes = 0;\r
-        joy->error = GL_TRUE;\r
-    }\r
-    else\r
+    if( numDevices < 0 )\r
     {\r
-        /* Device name from jsCaps is often "Microsoft PC-joystick driver",\r
-         * at least for USB.  Try to get the real name from the registry.\r
-         */\r
-        if ( ! fghJoystickGetOEMProductName( joy, joy->name,\r
-                                             sizeof( joy->name ) ) )\r
-        {\r
-            fgWarning( "JS: Failed to read joystick name from registry" );\r
-            strncpy( joy->name, joy->jsCaps.szPname, sizeof( joy->name ) );\r
-        }\r
+        /* do first-time init (since we can't over-ride jsInit, hmm */\r
+        numDevices = 0;\r
 \r
-        /* Windows joystick drivers may provide any combination of\r
-         * X,Y,Z,R,U,V,POV - not necessarily the first n of these.\r
-         */\r
-        if( joy->jsCaps.wCaps & JOYCAPS_HASPOV )\r
+        mach_port_t masterPort;\r
+        IOReturn rv = IOMasterPort( bootstrap_port, &masterPort );\r
+        if( rv != kIOReturnSuccess )\r
         {\r
-            joy->num_axes = _JS_MAX_AXES;\r
-            joy->min[ 7 ] = -1.0; joy->max[ 7 ] = 1.0;  /* POV Y */\r
-            joy->min[ 6 ] = -1.0; joy->max[ 6 ] = 1.0;  /* POV X */\r
+            fgWarning( "error getting master Mach port" );\r
+            return;\r
         }\r
-        else\r
-            joy->num_axes = 6;\r
-\r
-        joy->min[ 5 ] = ( float )joy->jsCaps.wVmin;\r
-        joy->max[ 5 ] = ( float )joy->jsCaps.wVmax;\r
-        joy->min[ 4 ] = ( float )joy->jsCaps.wUmin;\r
-        joy->max[ 4 ] = ( float )joy->jsCaps.wUmax;\r
-        joy->min[ 3 ] = ( float )joy->jsCaps.wRmin;\r
-        joy->max[ 3 ] = ( float )joy->jsCaps.wRmax;\r
-        joy->min[ 2 ] = ( float )joy->jsCaps.wZmin;\r
-        joy->max[ 2 ] = ( float )joy->jsCaps.wZmax;\r
-        joy->min[ 1 ] = ( float )joy->jsCaps.wYmin;\r
-        joy->max[ 1 ] = ( float )joy->jsCaps.wYmax;\r
-        joy->min[ 0 ] = ( float )joy->jsCaps.wXmin;\r
-        joy->max[ 0 ] = ( float )joy->jsCaps.wXmax;\r
+        fghJoystickFindDevices( masterPort );\r
     }\r
 \r
-    /* Guess all the rest judging on the axes extremals */\r
-    for( i = 0; i < joy->num_axes; i++ )\r
+    if ( ident >= numDevices )\r
     {\r
-        joy->center   [ i ] = ( joy->max[ i ] + joy->min[ i ] ) * 0.5f;\r
-        joy->dead_band[ i ] = 0.0f;\r
-        joy->saturate [ i ] = 1.0f;\r
+        fgJoystick[ ident ]->error = GL_TRUE;\r
+        return;\r
+    }\r
+\r
+    /* get the name now too */\r
+    CFDictionaryRef properties = getCFProperties( ioDevices[ ident ] );\r
+    CFTypeRef ref = CFDictionaryGetValue( properties,\r
+                                          CFSTR( kIOHIDProductKey ) );\r
+    if (!ref)\r
+        ref = CFDictionaryGetValue(properties, CFSTR( "USB Product Name" ) );\r
+\r
+    if( !ref ||\r
+        !CFStringGetCString( ( CFStringRef )ref, name, 128,\r
+                             CFStringGetSystemEncoding( ) ) )\r
+    {\r
+        fgWarning( "error getting device name" );\r
+        name[ 0 ] = '\0';\r
     }\r
+}\r
+\r
+\r
+void fgPlatformJoystickClose ( int ident )\r
+{\r
+    ( *( fgJoystick[ ident ]->hidDev ) )->\r
+        close( fgJoystick[ ident ]->hidDev );\r
+}\r
 #endif\r
 \r
 #if TARGET_HOST_POSIX_X11\r
+void fgPlatformJoystickOpen( SFG_Joystick* joy )\r
+{\r
+#if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ )\r
+       int i = 0;\r
+       char *cp;\r
+#endif\r
+#ifdef JS_NEW\r
+       unsigned char u;\r
+#else\r
+#  if defined( __linux__ ) || TARGET_HOST_SOLARIS\r
+       int i = 0;\r
+    int counter = 0;\r
+#  endif\r
+#endif\r
+\r
 #if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ )\r
     for( i = 0; i < _JS_MAX_AXES; i++ )\r
         joy->os->cache_axes[ i ] = 0.0f;\r
@@ -1485,96 +1362,12 @@ static void fghJoystickOpen( SFG_Joystick* joy )
         joy->saturate [ i ] = 1.0f;\r
     }\r
 #endif\r
-#endif\r
 }\r
 \r
-/*\r
- * This function replaces the constructor method in the JS library.\r
- */\r
-static void fghJoystickInit( int ident )\r
-{\r
-    if( ident >= MAX_NUM_JOYSTICKS )\r
-      fgError( "Too large a joystick number: %d", ident );\r
-\r
-    if( fgJoystick[ ident ] )\r
-        fgError( "illegal attempt to initialize joystick device again" );\r
-\r
-    fgJoystick[ ident ] =\r
-        ( SFG_Joystick * )calloc( sizeof( SFG_Joystick ), 1 );\r
-\r
-    /* Set defaults */\r
-    fgJoystick[ ident ]->num_axes = fgJoystick[ ident ]->num_buttons = 0;\r
-    fgJoystick[ ident ]->error = GL_TRUE;\r
-\r
-#if TARGET_HOST_MACINTOSH\r
-    fgJoystick[ ident ]->id = ident;\r
-    snprintf( fgJoystick[ ident ]->fname, sizeof(fgJoystick[ ident ]->fname), "/dev/js%d", ident ); /* FIXME */\r
-    fgJoystick[ ident ]->error = GL_FALSE;\r
-#endif\r
-\r
-#if TARGET_HOST_MAC_OSX\r
-    fgJoystick[ ident ]->id = ident;\r
-    fgJoystick[ ident ]->error = GL_FALSE;\r
-    fgJoystick[ ident ]->num_axes = 0;\r
-    fgJoystick[ ident ]->num_buttons = 0;\r
-\r
-    if( numDevices < 0 )\r
-    {\r
-        /* do first-time init (since we can't over-ride jsInit, hmm */\r
-        numDevices = 0;\r
-\r
-        mach_port_t masterPort;\r
-        IOReturn rv = IOMasterPort( bootstrap_port, &masterPort );\r
-        if( rv != kIOReturnSuccess )\r
-        {\r
-            fgWarning( "error getting master Mach port" );\r
-            return;\r
-        }\r
-        fghJoystickFindDevices( masterPort );\r
-    }\r
-\r
-    if ( ident >= numDevices )\r
-    {\r
-        fgJoystick[ ident ]->error = GL_TRUE;\r
-        return;\r
-    }\r
-\r
-    /* get the name now too */\r
-    CFDictionaryRef properties = getCFProperties( ioDevices[ ident ] );\r
-    CFTypeRef ref = CFDictionaryGetValue( properties,\r
-                                          CFSTR( kIOHIDProductKey ) );\r
-    if (!ref)\r
-        ref = CFDictionaryGetValue(properties, CFSTR( "USB Product Name" ) );\r
-\r
-    if( !ref ||\r
-        !CFStringGetCString( ( CFStringRef )ref, name, 128,\r
-                             CFStringGetSystemEncoding( ) ) )\r
-    {\r
-        fgWarning( "error getting device name" );\r
-        name[ 0 ] = '\0';\r
-    }\r
-#endif\r
-\r
-#if TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE)\r
-    switch( ident )\r
-    {\r
-    case 0:\r
-        fgJoystick[ ident ]->js_id = JOYSTICKID1;\r
-        fgJoystick[ ident ]->error = GL_FALSE;\r
-        break;\r
-    case 1:\r
-        fgJoystick[ ident ]->js_id = JOYSTICKID2;\r
-        fgJoystick[ ident ]->error = GL_FALSE;\r
-        break;\r
-    default:\r
-        fgJoystick[ ident ]->num_axes = 0;\r
-        fgJoystick[ ident ]->error = GL_TRUE;\r
-        return;\r
-    }\r
-#endif\r
 \r
-#if TARGET_HOST_POSIX_X11\r
-#    if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ )\r
+void fgPlatformJoystickInit( SFG_Joystick *fgJoystick[], int ident )\r
+{\r
+#if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ )\r
     fgJoystick[ ident ]->id = ident;\r
     fgJoystick[ ident ]->error = GL_FALSE;\r
 \r
@@ -1587,7 +1380,7 @@ static void fghJoystickInit( int ident )
     else\r
         snprintf( fgJoystick[ ident ]->os->fname, sizeof(fgJoystick[ ident ]->os->fname), "%s%d", UHIDDEV,\r
                  ident - USB_IDENT_OFFSET );\r
-#    elif defined( __linux__ )\r
+#elif defined( __linux__ )\r
     fgJoystick[ ident ]->id = ident;\r
     fgJoystick[ ident ]->error = GL_FALSE;\r
 \r
@@ -1595,8 +1388,70 @@ static void fghJoystickInit( int ident )
 \r
     if( access( fgJoystick[ ident ]->fname, F_OK ) != 0 )\r
         snprintf( fgJoystick[ ident ]->fname, sizeof(fgJoystick[ ident ]->fname), "/dev/js%d", ident );\r
-#    endif\r
 #endif\r
+}\r
+\r
+\r
+void fgPlatformJoystickClose ( int ident )\r
+{\r
+#if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ )\r
+    if( fgJoystick[ident]->os )\r
+    {\r
+        if( ! fgJoystick[ ident ]->error )\r
+            close( fgJoystick[ ident ]->os->fd );\r
+#ifdef HAVE_USB_JS\r
+        if( fgJoystick[ ident ]->os->hids )\r
+            free (fgJoystick[ ident ]->os->hids);\r
+        if( fgJoystick[ ident ]->os->hid_data_buf )\r
+            free( fgJoystick[ ident ]->os->hid_data_buf );\r
+#endif\r
+        free( fgJoystick[ident]->os );\r
+       }\r
+#endif\r
+\r
+    if( ! fgJoystick[ident]->error )\r
+         close( fgJoystick[ ident ]->fd );\r
+}\r
+#endif\r
+\r
+\r
+\r
+\r
+\r
+\r
+static void fghJoystickOpen( SFG_Joystick* joy )\r
+{\r
+    /*\r
+     * Default values (for no joystick -- each conditional will reset the\r
+     * error flag)\r
+     */\r
+    joy->error = TRUE;\r
+    joy->num_axes = joy->num_buttons = 0;\r
+    joy->name[ 0 ] = '\0';\r
+\r
+       fgPlatformJoystickOpen ( joy );\r
+\r
+}\r
+\r
+/*\r
+ * This function replaces the constructor method in the JS library.\r
+ */\r
+static void fghJoystickInit( int ident )\r
+{\r
+    if( ident >= MAX_NUM_JOYSTICKS )\r
+      fgError( "Too large a joystick number: %d", ident );\r
+\r
+    if( fgJoystick[ ident ] )\r
+        fgError( "illegal attempt to initialize joystick device again" );\r
+\r
+    fgJoystick[ ident ] =\r
+        ( SFG_Joystick * )calloc( sizeof( SFG_Joystick ), 1 );\r
+\r
+    /* Set defaults */\r
+    fgJoystick[ ident ]->num_axes = fgJoystick[ ident ]->num_buttons = 0;\r
+    fgJoystick[ ident ]->error = GL_TRUE;\r
+\r
+       fgPlatformJoystickInit( fgJoystick, ident );\r
 \r
     fghJoystickOpen( fgJoystick[ ident  ] );\r
 }\r
@@ -1616,9 +1471,7 @@ void fgInitialiseJoysticks ( void )
     }\r
 }\r
 \r
-/*\r
- *\r
- */\r
+\r
 void fgJoystickClose( void )\r
 {\r
     int ident ;\r
@@ -1626,41 +1479,7 @@ void fgJoystickClose( void )
     {\r
         if( fgJoystick[ ident ] )\r
         {\r
-\r
-#if TARGET_HOST_MACINTOSH\r
-            ISpSuspend( );\r
-            ISpStop( );\r
-            ISpShutdown( );\r
-#endif\r
-\r
-#if TARGET_HOST_MAC_OSX\r
-            ( *( fgJoystick[ ident ]->hidDev ) )->\r
-                close( fgJoystick[ ident ]->hidDev );\r
-#endif\r
-\r
-#if TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE)\r
-            /* Do nothing special */\r
-#endif\r
-\r
-#if TARGET_HOST_POSIX_X11\r
-#if defined( __FreeBSD__ ) || defined(__FreeBSD_kernel__) || defined( __NetBSD__ )\r
-            if( fgJoystick[ident]->os )\r
-            {\r
-                if( ! fgJoystick[ ident ]->error )\r
-                    close( fgJoystick[ ident ]->os->fd );\r
-#ifdef HAVE_USB_JS\r
-                if( fgJoystick[ ident ]->os->hids )\r
-                    free (fgJoystick[ ident ]->os->hids);\r
-                if( fgJoystick[ ident ]->os->hid_data_buf )\r
-                    free( fgJoystick[ ident ]->os->hid_data_buf );\r
-#endif\r
-                free( fgJoystick[ident]->os );\r
-            }\r
-#endif\r
-\r
-            if( ! fgJoystick[ident]->error )\r
-                close( fgJoystick[ ident ]->fd );\r
-#endif\r
+                       fgPlatformJoystickClose ( ident );\r
 \r
             free( fgJoystick[ ident ] );\r
             fgJoystick[ ident ] = NULL;\r