Commit 31f22de8 authored by Sam Lantinga's avatar Sam Lantinga

Backing out new changes, at Chris Nelson's request.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40954
parent 11395472
...@@ -69,98 +69,45 @@ static struct { ...@@ -69,98 +69,45 @@ static struct {
#ifndef NO_LOGICAL_JOYSTICKS #ifndef NO_LOGICAL_JOYSTICKS
/* static struct joystick_logical_values {
Some USB HIDs show up as a single joystick even though they actually
control 2 or more joysticks.
*/
/*
This code handles the MP-8800 (Quad) and MP-8866 (Dual), which can
be identified by their transparent blue design. It's quite trivial
to add other joysticks with similar quirky behavior.
-id
*/
struct joystick_logical_mapping {
int njoy; int njoy;
int nthing; int nthing;
}; } joystick_logical_values[] = {
/* /* +0 */
{logical joy, logical axis}, /* MP-8800 axes map - map to {logical joystick #, logical axis #} */
{logical joy, logical hat}, {0,0},{0,1},{0,2},{1,0},{1,1},{0,3},{1,2},{1,3},{2,0},{2,1},{2,2},{2,3},
{logical joy, logical ball}, {3,0},{3,1},{3,2},{3,3},{0,4},{1,4},{2,4},
{logical joy, logical button}
*/
static struct joystick_logical_mapping mp88xx_1_logical_axismap[] = { /* +19 */
{0,0},{0,1},{0,2},{0,3},{0,4},{0,5} /* MP-8800 hat map - map to {logical joystick #, logical hat #} */
}; {0,0},{1,0},{2,0},{3,0},
static struct joystick_logical_mapping mp88xx_1_logical_buttonmap[] = {
{0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},{0,7},{0,8},{0,9},{0,10},{0,11}
};
static struct joystick_logical_mapping mp88xx_2_logical_axismap[] = { /* +23 */
{0,0},{0,1},{0,2},{1,0},{1,1},{0,3}, /* MP-8800 button map - map to {logical joystick #, logical button #} */
{1,2},{1,3},{0,4},{0,5},{1,4},{1,5}
};
static struct joystick_logical_mapping mp88xx_2_logical_buttonmap[] = {
{0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},{0,7},{0,8},{0,9},{0,10},{0,11},
{1,0},{1,1},{1,2},{1,3},{1,4},{1,5},{1,6},{1,7},{1,8},{1,9},{1,10},{1,11}
};
static struct joystick_logical_mapping mp88xx_3_logical_axismap[] = {
{0,0},{0,1},{0,2},{1,0},{1,1},{0,3},
{1,2},{1,3},{2,0},{2,1},{2,2},{2,3},
{0,4},{0,5},{1,4},{1,5},{2,4},{2,5}
};
static struct joystick_logical_mapping mp88xx_3_logical_buttonmap[] = {
{0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},{0,7},{0,8},{0,9},{0,10},{0,11},
{1,0},{1,1},{1,2},{1,3},{1,4},{1,5},{1,6},{1,7},{1,8},{1,9},{1,10},{1,11},
{2,0},{2,1},{2,2},{2,3},{2,4},{2,5},{2,6},{2,7},{2,8},{2,9},{2,10},{2,11}
};
static struct joystick_logical_mapping mp88xx_4_logical_axismap[] = {
{0,0},{0,1},{0,2},{1,0},{1,1},{0,3},
{1,2},{1,3},{2,0},{2,1},{2,2},{2,3},
{3,0},{3,1},{3,2},{3,3},{0,4},{0,5},
{1,4},{1,5},{2,4},{2,5},{3,4},{3,5}
};
static struct joystick_logical_mapping mp88xx_4_logical_buttonmap[] = {
{0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},{0,7},{0,8},{0,9},{0,10},{0,11}, {0,0},{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},{0,7},{0,8},{0,9},{0,10},{0,11},
{1,0},{1,1},{1,2},{1,3},{1,4},{1,5},{1,6},{1,7},{1,8},{1,9},{1,10},{1,11}, {1,0},{1,1},{1,2},{1,3},{1,4},{1,5},{1,6},{1,7},{1,8},{1,9},{1,10},{1,11},
{2,0},{2,1},{2,2},{2,3},{2,4},{2,5},{2,6},{2,7},{2,8},{2,9},{2,10},{2,11}, {2,0},{2,1},{2,2},{2,3},{2,4},{2,5},{2,6},{2,7},{2,8},{2,9},{2,10},{2,11},
{3,0},{3,1},{3,2},{3,3},{3,4},{3,5},{3,6},{3,7},{3,8},{3,9},{3,10},{3,11} {3,0},{3,1},{3,2},{3,3},{3,4},{3,5},{3,6},{3,7},{3,8},{3,9},{3,10},{3,11}
}; };
struct joystick_logical_layout { static struct joystick_logical_layout {
int naxes; int naxes;
int nhats; int nhats;
int nballs; int nballs;
int nbuttons; int nbuttons;
}; } joystick_logical_layout[] = {
/* MP-8800 logical layout */
static struct joystick_logical_layout mp88xx_1_logical_layout[] = { {5, 1, 0, 12},
{6, 0, 0, 12} {5, 1, 0, 12},
}; {5, 1, 0, 12},
static struct joystick_logical_layout mp88xx_2_logical_layout[] = { {4, 1, 0, 12}
{6, 0, 0, 12},
{6, 0, 0, 12}
};
static struct joystick_logical_layout mp88xx_3_logical_layout[] = {
{6, 0, 0, 12},
{6, 0, 0, 12},
{6, 0, 0, 12}
};
static struct joystick_logical_layout mp88xx_4_logical_layout[] = {
{6, 0, 0, 12},
{6, 0, 0, 12},
{6, 0, 0, 12},
{6, 0, 0, 12}
}; };
/* /*
This array sets up a means of mapping a single physical joystick to Some USB HIDs show up as a single joystick even though they actually
multiple logical joysticks. (djm) control 2 or more joysticks. This array sets up a means of mapping
a single physical joystick to multiple logical joysticks. (djm)
njoys njoys
the number of logical joysticks the number of logical joysticks
...@@ -171,78 +118,19 @@ static struct joystick_logical_layout mp88xx_4_logical_layout[] = { ...@@ -171,78 +118,19 @@ static struct joystick_logical_layout mp88xx_4_logical_layout[] = {
axes, hats, balls, buttons axes, hats, balls, buttons
arrays that map a physical thingy to a logical thingy arrays that map a physical thingy to a logical thingy
*/ */
struct joystick_logicalmap { static struct joystick_logicalmap {
const char *name; const char *name;
int nbuttons;
int njoys; int njoys;
struct joystick_logical_layout *layout; struct joystick_logical_layout *layouts;
struct joystick_logical_mapping *axismap; struct joystick_logical_values *axes;
struct joystick_logical_mapping *hatmap; struct joystick_logical_values *hats;
struct joystick_logical_mapping *ballmap; struct joystick_logical_values *balls;
struct joystick_logical_mapping *buttonmap; struct joystick_logical_values *buttons;
};
} joystick_logicalmap[] = {
static struct joystick_logicalmap joystick_logicalmap[] = { {"WiseGroup.,Ltd MP-8800 Quad USB Joypad", 4, joystick_logical_layout,
{ joystick_logical_values, joystick_logical_values+19, NULL,
"WiseGroup.,Ltd MP-8866 Dual USB Joypad", joystick_logical_values+23}
12,
1,
mp88xx_1_logical_layout,
mp88xx_1_logical_axismap,
NULL,
NULL,
mp88xx_1_logical_buttonmap
},
{
"WiseGroup.,Ltd MP-8866 Dual USB Joypad",
24,
2,
mp88xx_2_logical_layout,
mp88xx_2_logical_axismap,
NULL,
NULL,
mp88xx_2_logical_buttonmap
},
{
"WiseGroup.,Ltd MP-8800 Quad USB Joypad",
12,
1,
mp88xx_1_logical_layout,
mp88xx_1_logical_axismap,
NULL,
NULL,
mp88xx_1_logical_buttonmap
},
{
"WiseGroup.,Ltd MP-8800 Quad USB Joypad",
24,
2,
mp88xx_2_logical_layout,
mp88xx_2_logical_axismap,
NULL,
NULL,
mp88xx_2_logical_buttonmap
},
{
"WiseGroup.,Ltd MP-8800 Quad USB Joypad",
36,
3,
mp88xx_3_logical_layout,
mp88xx_3_logical_axismap,
NULL,
NULL,
mp88xx_3_logical_buttonmap
},
{
"WiseGroup.,Ltd MP-8800 Quad USB Joypad",
48,
4,
mp88xx_4_logical_layout,
mp88xx_4_logical_axismap,
NULL,
NULL,
mp88xx_4_logical_buttonmap
}
}; };
/* find the head of a linked list, given a point in it /* find the head of a linked list, given a point in it
...@@ -318,40 +206,28 @@ static int CountLogicalJoysticks(int max) ...@@ -318,40 +206,28 @@ static int CountLogicalJoysticks(int max)
{ {
register int i, j, k, ret, prev; register int i, j, k, ret, prev;
const char* name; const char* name;
int nbuttons, fd;
unsigned char n;
ret = 0; ret = 0;
for(i = 0; i < max; i++) { for(i = 0; i < max; i++) {
name = SDL_SYS_JoystickName(i); name = SDL_SYS_JoystickName(i);
fd = open(SDL_joylist[i].fname, O_RDONLY, 0);
if ( fd >= 0 ) {
if ( ioctl(fd, JSIOCGBUTTONS, &n) < 0 ) {
nbuttons = -1;
} else {
nbuttons = n;
}
close(fd);
}
else {
nbuttons=-1;
}
if (name) { if (name) {
for(j = 0; j < SDL_TABLESIZE(joystick_logicalmap); j++) { for(j = 0; j < SDL_TABLESIZE(joystick_logicalmap); j++) {
if (!strcmp(name, joystick_logicalmap[j].name) && (nbuttons==-1 || nbuttons==joystick_logicalmap[j].nbuttons)) { if (!strcmp(name, joystick_logicalmap[j].name)) {
prev = i; prev = i;
SDL_joylist[prev].map = &(joystick_logicalmap[j]); SDL_joylist[prev].map = joystick_logicalmap+j;
for(k = 1; k < joystick_logicalmap[j].njoys; k++) { for(k = 1; k < joystick_logicalmap[j].njoys; k++) {
SDL_joylist[prev].next = max + ret; SDL_joylist[prev].next = max + ret;
if (prev != i)
SDL_joylist[max+ret].prev = prev; SDL_joylist[max+ret].prev = prev;
prev = max + ret; prev = max + ret;
SDL_joylist[prev].logicalno = k; SDL_joylist[prev].logicalno = k;
SDL_joylist[prev].map = &(joystick_logicalmap[j]); SDL_joylist[prev].map = joystick_logicalmap+j;
ret++; ret++;
} }
...@@ -371,7 +247,9 @@ static void LogicalSuffix(int logicalno, char* namebuf, int len) ...@@ -371,7 +247,9 @@ static void LogicalSuffix(int logicalno, char* namebuf, int len)
"01020304050607080910111213141516171819" "01020304050607080910111213141516171819"
"20212223242526272829303132"; "20212223242526272829303132";
const char* suffix; const char* suffix;
slen = strlen(namebuf); slen = strlen(namebuf);
suffix = NULL; suffix = NULL;
if (logicalno*2<sizeof(suffixs)) if (logicalno*2<sizeof(suffixs))
...@@ -541,12 +419,9 @@ const char *SDL_SYS_JoystickName(int index) ...@@ -541,12 +419,9 @@ const char *SDL_SYS_JoystickName(int index)
} }
close(fd); close(fd);
#ifndef NO_LOGICAL_JOYSTICKS #ifndef NO_LOGICAL_JOYSTICKS
if (SDL_joylist[oindex].prev || SDL_joylist[oindex].next || index!=oindex) if (SDL_joylist[oindex].prev || SDL_joylist[oindex].next)
{
LogicalSuffix(SDL_joylist[oindex].logicalno, namebuf, 128); LogicalSuffix(SDL_joylist[oindex].logicalno, namebuf, 128);
}
#endif #endif
} }
return name; return name;
...@@ -780,7 +655,7 @@ static void ConfigLogicalJoystick(SDL_Joystick *joystick) ...@@ -780,7 +655,7 @@ static void ConfigLogicalJoystick(SDL_Joystick *joystick)
{ {
struct joystick_logical_layout* layout; struct joystick_logical_layout* layout;
layout = SDL_joylist[joystick->index].map->layout + layout = SDL_joylist[joystick->index].map->layouts +
SDL_joylist[joystick->index].logicalno; SDL_joylist[joystick->index].logicalno;
joystick->nbuttons = layout->nbuttons; joystick->nbuttons = layout->nbuttons;
...@@ -856,7 +731,7 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) ...@@ -856,7 +731,7 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
#ifndef NO_LOGICAL_JOYSTICKS #ifndef NO_LOGICAL_JOYSTICKS
static SDL_Joystick* FindLogicalJoystick( static SDL_Joystick* FindLogicalJoystick(
SDL_Joystick *joystick, struct joystick_logical_mapping* v) SDL_Joystick *joystick, struct joystick_logical_values* v)
{ {
SDL_Joystick *logicaljoy; SDL_Joystick *logicaljoy;
register int i; register int i;
...@@ -885,7 +760,7 @@ static SDL_Joystick* FindLogicalJoystick( ...@@ -885,7 +760,7 @@ static SDL_Joystick* FindLogicalJoystick(
static int LogicalJoystickButton( static int LogicalJoystickButton(
SDL_Joystick *joystick, Uint8 button, Uint8 state){ SDL_Joystick *joystick, Uint8 button, Uint8 state){
struct joystick_logical_mapping* buttons; struct joystick_logical_values* buttons;
SDL_Joystick *logicaljoy = NULL; SDL_Joystick *logicaljoy = NULL;
/* if there's no map then this is just a regular joystick /* if there's no map then this is just a regular joystick
...@@ -895,7 +770,7 @@ static int LogicalJoystickButton( ...@@ -895,7 +770,7 @@ static int LogicalJoystickButton(
/* get the logical joystick that will receive the event /* get the logical joystick that will receive the event
*/ */
buttons = SDL_joylist[joystick->index].map->buttonmap+button; buttons = SDL_joylist[joystick->index].map->buttons+button;
logicaljoy = FindLogicalJoystick(joystick, buttons); logicaljoy = FindLogicalJoystick(joystick, buttons);
if (logicaljoy == NULL) if (logicaljoy == NULL)
...@@ -909,7 +784,7 @@ static int LogicalJoystickButton( ...@@ -909,7 +784,7 @@ static int LogicalJoystickButton(
static int LogicalJoystickAxis( static int LogicalJoystickAxis(
SDL_Joystick *joystick, Uint8 axis, Sint16 value) SDL_Joystick *joystick, Uint8 axis, Sint16 value)
{ {
struct joystick_logical_mapping* axes; struct joystick_logical_values* axes;
SDL_Joystick *logicaljoy = NULL; SDL_Joystick *logicaljoy = NULL;
/* if there's no map then this is just a regular joystick /* if there's no map then this is just a regular joystick
...@@ -919,7 +794,7 @@ static int LogicalJoystickAxis( ...@@ -919,7 +794,7 @@ static int LogicalJoystickAxis(
/* get the logical joystick that will receive the event /* get the logical joystick that will receive the event
*/ */
axes = SDL_joylist[joystick->index].map->axismap+axis; axes = SDL_joylist[joystick->index].map->axes+axis;
logicaljoy = FindLogicalJoystick(joystick, axes); logicaljoy = FindLogicalJoystick(joystick, axes);
if (logicaljoy == NULL) if (logicaljoy == NULL)
...@@ -941,7 +816,7 @@ void HandleHat(SDL_Joystick *stick, Uint8 hat, int axis, int value) ...@@ -941,7 +816,7 @@ void HandleHat(SDL_Joystick *stick, Uint8 hat, int axis, int value)
{ SDL_HAT_LEFTDOWN, SDL_HAT_DOWN, SDL_HAT_RIGHTDOWN } { SDL_HAT_LEFTDOWN, SDL_HAT_DOWN, SDL_HAT_RIGHTDOWN }
}; };
SDL_logical_joydecl(SDL_Joystick *logicaljoy = NULL); SDL_logical_joydecl(SDL_Joystick *logicaljoy = NULL);
SDL_logical_joydecl(struct joystick_logical_mapping* hats = NULL); SDL_logical_joydecl(struct joystick_logical_values* hats = NULL);
the_hat = &stick->hwdata->hats[hat]; the_hat = &stick->hwdata->hats[hat];
if ( value < 0 ) { if ( value < 0 ) {
...@@ -963,7 +838,7 @@ void HandleHat(SDL_Joystick *stick, Uint8 hat, int axis, int value) ...@@ -963,7 +838,7 @@ void HandleHat(SDL_Joystick *stick, Uint8 hat, int axis, int value)
/* get the fake joystick that will receive the event /* get the fake joystick that will receive the event
*/ */
hats = SDL_joylist[stick->index].map->hatmap+hat; hats = SDL_joylist[stick->index].map->hats+hat;
logicaljoy = FindLogicalJoystick(stick, hats); logicaljoy = FindLogicalJoystick(stick, hats);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment