/***********************************************************
-* Rocks'n'Diamonds -- McDuffin Strikes Back! *
+* Rocks'n'Diamonds -- McDuffin Strikes Back! *
*----------------------------------------------------------*
-* (c) 1995-98 Artsoft Entertainment *
-* Holger Schemel *
-* Oststrasse 11a *
-* 33604 Bielefeld *
-* phone: ++49 +521 290471 *
-* email: aeglos@valinor.owl.de *
+* (c) 1995-2001 Artsoft Entertainment *
+* Holger Schemel *
+* Detmolder Strasse 189 *
+* 33604 Bielefeld *
+* Germany *
+* e-mail: info@artsoft.org *
*----------------------------------------------------------*
-* joystick.c *
+* joystick.c *
***********************************************************/
-#ifdef __FreeBSD__
+#if defined(PLATFORM_FREEBSD)
#include <machine/joystick.h>
#endif
+#include "libgame/libgame.h"
+
#include "joystick.h"
-#include "misc.h"
-#ifndef MSDOS
+#define TRANSLATE_JOYSYMBOL_TO_JOYNAME 0
+#define TRANSLATE_JOYNAME_TO_JOYSYMBOL 1
+
+void translate_joyname(int *joysymbol, char **name, int mode)
+{
+ static struct
+ {
+ int joysymbol;
+ char *name;
+ } translate_joy[] =
+ {
+ { JOY_LEFT, "joystick_left" },
+ { JOY_RIGHT, "joystick_right" },
+ { JOY_UP, "joystick_up" },
+ { JOY_DOWN, "joystick_down" },
+ { JOY_BUTTON_1, "joystick_button_1" },
+ { JOY_BUTTON_2, "joystick_button_2" },
+ };
+
+ int i;
+
+ if (mode == TRANSLATE_JOYSYMBOL_TO_JOYNAME)
+ {
+ *name = "[undefined]";
+
+ for (i=0; i<6; i++)
+ {
+ if (*joysymbol == translate_joy[i].joysymbol)
+ {
+ *name = translate_joy[i].name;
+ break;
+ }
+ }
+ }
+ else if (mode == TRANSLATE_JOYNAME_TO_JOYSYMBOL)
+ {
+ *joysymbol = 0;
+
+ for (i=0; i<6; i++)
+ {
+ if (strcmp(*name, translate_joy[i].name) == 0)
+ {
+ *joysymbol = translate_joy[i].joysymbol;
+ break;
+ }
+ }
+ }
+}
+
+char *getJoyNameFromJoySymbol(int joysymbol)
+{
+ char *name;
+
+ translate_joyname(&joysymbol, &name, TRANSLATE_JOYSYMBOL_TO_JOYNAME);
+ return name;
+}
+
+int getJoySymbolFromJoyName(char *name)
+{
+ int joysymbol;
+
+ translate_joyname(&joysymbol, &name, TRANSLATE_JOYNAME_TO_JOYSYMBOL);
+ return joysymbol;
+}
+
+int getJoystickNrFromDeviceName(char *device_name)
+{
+ char c;
+ int joystick_nr = 0;
+
+ if (device_name == NULL || device_name[0] == '\0')
+ return 0;
+
+ c = device_name[strlen(device_name) - 1];
+
+ if (c >= '0' && c <= '9')
+ joystick_nr = (int)(c - '0');
+
+ if (joystick_nr < 0 || joystick_nr >= MAX_PLAYERS)
+ joystick_nr = 0;
+
+ return joystick_nr;
+}
+
+#if !defined(PLATFORM_MSDOS)
static int JoystickPosition(int middle, int margin, int actual)
{
long range, pos;
}
#endif
-#ifdef USE_SDL_LIBRARY
+#if defined(TARGET_SDL)
static SDL_Joystick *sdl_joystick[MAX_PLAYERS] = { NULL, NULL, NULL, NULL };
static int sdl_js_axis[MAX_PLAYERS][2] = { {0, 0}, {0, 0}, {0, 0}, {0, 0} };
return result;
}
-#else /* !USE_SDL_LIBRARY */
+#else /* !TARGET_SDL */
void CheckJoystickData()
{
}
}
-#ifndef MSDOS
+#if defined(PLATFORM_UNIX)
int Joystick(int player_nr)
{
#ifdef __FreeBSD__
return result;
}
-#else /* MSDOS */
+#else /* PLATFORM_MSDOS */
/* allegro global variables for joystick control */
extern int num_joysticks;
return 0;
/* the allegro global variable 'num_joysticks' contains the number
- of joysticks found at initialization under MSDOS / Windows */
+ of joysticks found at initialization under MS-DOS / Windows */
#if 0
if (joystick_nr >= num_joysticks || !setup.input[player_nr].use_joystick)
return result;
}
-#endif /* MSDOS */
+#endif /* PLATFORM_MSDOS */
-#endif /* !USE_SDL_LIBRARY */
+#endif /* !TARGET_SDL */
int JoystickButton(int player_nr)
{