Re: [AD] Unknown joystick axis problem under Windows

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Hello again,

Enclosed is a patch to fix the problem that I first reported in this
thread on 2003/12/30. The problem is that joystick Slider 0 data was
incorrect using the DirectInput driver.

I discussed with Eric Botcazou about it and made various attempts.
It turned out that the bug is due to a little known particularly
about the DirectInput API on versions earlier than 8.00 (0x0800).

I added detailed comments in the modified source file (wjoydx.c),
and made sure that the fix won't cause any problem if upgrading
to DirectInput API 8.00+.

Omar Cornut 
--- wjoydx.c.old	2003-11-09 19:43:12.000000000 +0000
+++ wjoydx.c	2004-02-10 17:51:04.000000000 +0000
@@ -177,13 +177,58 @@
             n_axis++;
          }
 
+         /* 
+          * (note from Omar Cornut)
+          * Below we are dealing with a particularly of the DirectInput API.
+          * In version earlier than 8.00, slider data is to be found in the z-axis 
+          * data member, although the object was reported as a slider during 
+          * enumeration. 
+          *
+          * Very few location seems to describe this bug. Here is one:
+          * http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dx81_vb/directx_vb/Input/VB_Ref/Types/dijoystate2.asp
+          * The interesting part is the note at the bottom of the page.
+          * I pasted it below because I am uncertain that old MSDN archives will be kept:
+          *
+          * " Note  Under Microsoft DirectX 7, sliders on some joysticks could be assigned
+          *   to the Z axis, with subsequent code retrieving data from that member. 
+          *   Using DirectX 8, those same sliders will be assigned to the slider array. 
+          *   This should be taken into account when porting applications to DirectX 8. 
+          *   Make any necessary alterations to ensure that slider data is retrieved from 
+          *   the slider array. "
+          *
+          * When using DirectInput API < 8.00, this particularity is emulated.
+          * Currently Allegro use DirectInput API 5.00, but I added definitions
+          * so that this part of code won't have to be changed if switching to
+          * a newer version in the future.
+          */
+
+         /* for U axis (slider 0), get data from Z axis member if API < 0x0800
+          * and if a real Z axis is not present. else get from slider 0 member. */
 	 if (dinput_joystick[n_joy].caps & JOYCAPS_HASU) {
+#if DIRECTINPUT_VERSION < 0x0800
+	    if (dinput_joystick[n_joy].caps & JOYCAPS_HASZ)
+               dinput_joystick[n_joy].axis[n_axis] = js.rglSlider[0];
+            else
+               dinput_joystick[n_joy].axis[n_axis] = js.lZ;
+#else
             dinput_joystick[n_joy].axis[n_axis] = js.rglSlider[0];
+#endif
             n_axis++;
          }
 
-	 if (dinput_joystick[n_joy].caps & JOYCAPS_HASV) {
+         /* for V axis (slider 1), get data from slider 0 member if API < 0x0800
+          * and if a real Z axis is not present. else get from slider 1 member.
+          * Note: the HASU case is untested, as I could not find any joystick
+          * with both sliders and no Z axis. */
+         if (dinput_joystick[n_joy].caps & JOYCAPS_HASV) {
+#if DIRECTINPUT_VERSION < 0x0800
+	    if (dinput_joystick[n_joy].caps & JOYCAPS_HASZ)
+               dinput_joystick[n_joy].axis[n_axis] = js.rglSlider[1];
+            else
+               dinput_joystick[n_joy].axis[n_axis] = js.rglSlider[0];
+#else
             dinput_joystick[n_joy].axis[n_axis] = js.rglSlider[1];
+#endif
             n_axis++;
          }
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/