rnd-20020323-2-src
[rocksndiamonds.git] / src / libgame / joystick.h
1 /***********************************************************
2 * Artsoft Retro-Game Library                               *
3 *----------------------------------------------------------*
4 * (c) 1995-2002 Artsoft Entertainment                      *
5 *               Holger Schemel                             *
6 *               Detmolder Strasse 189                      *
7 *               33604 Bielefeld                            *
8 *               Germany                                    *
9 *               e-mail: info@artsoft.org                   *
10 *----------------------------------------------------------*
11 * joystick.h                                               *
12 ***********************************************************/
13
14 #ifndef JOYSTICK_H
15 #define JOYSTICK_H
16
17 #include "system.h"
18
19 /* values for the joystick */
20 #define JOYSTICK_NOT_AVAILABLE  0
21 #define JOYSTICK_AVAILABLE      (1 << 0)
22 #define JOYSTICK_ACTIVE         (1 << 1)
23
24 #define JOYSTICK_ACTIVATED      (JOYSTICK_AVAILABLE | JOYSTICK_ACTIVE)
25
26 #if defined(PLATFORM_FREEBSD)
27 #define DEV_JOYSTICK_0          "/dev/joy0"
28 #define DEV_JOYSTICK_1          "/dev/joy1"
29 #define DEV_JOYSTICK_2          "/dev/joy2"
30 #define DEV_JOYSTICK_3          "/dev/joy3"
31 #else
32 #define DEV_JOYSTICK_0          "/dev/js0"
33 #define DEV_JOYSTICK_1          "/dev/js1"
34 #define DEV_JOYSTICK_2          "/dev/js2"
35 #define DEV_JOYSTICK_3          "/dev/js3"
36 #endif
37
38 /* get these values from the program 'js' from the joystick package, */
39 /* set JOYSTICK_PERCENT to a threshold appropriate for your joystick */
40
41 #ifdef TARGET_SDL
42 #define JOYSTICK_XLEFT          -32767
43 #define JOYSTICK_XMIDDLE        0
44 #define JOYSTICK_XRIGHT         32767
45 #define JOYSTICK_YUPPER         -32767
46 #define JOYSTICK_YMIDDLE        0
47 #define JOYSTICK_YLOWER         32767
48 #else
49 #define JOYSTICK_XLEFT          30
50 #define JOYSTICK_XMIDDLE        530
51 #define JOYSTICK_XRIGHT         1250
52 #define JOYSTICK_YUPPER         40
53 #define JOYSTICK_YMIDDLE        680
54 #define JOYSTICK_YLOWER         1440
55 #endif
56
57 #define JOYSTICK_PERCENT        25
58
59 #define JOY_LEFT                MV_LEFT
60 #define JOY_RIGHT               MV_RIGHT
61 #define JOY_UP                  MV_UP
62 #define JOY_DOWN                MV_DOWN
63 #define JOY_BUTTON_1            (1 << 4)
64 #define JOY_BUTTON_2            (1 << 5)
65 #define JOY_BUTTON              (JOY_BUTTON_1 | JOY_BUTTON_2)
66
67 #define JOY_BUTTON_NOT_PRESSED  0
68 #define JOY_BUTTON_PRESSED      1
69 #define JOY_BUTTON_NEW_PRESSED  2
70 #define JOY_BUTTON_NEW_RELEASED 3
71
72 #ifdef NO_JOYSTICK
73 #define JOYSTICK_STATUS         JOYSTICK_NOT_AVAILABLE
74 #else
75 #define JOYSTICK_STATUS         JOYSTICK_AVAILABLE
76 #endif
77
78
79 char *getJoyNameFromJoySymbol(int);
80 int getJoySymbolFromJoyName(char *);
81 int getJoystickNrFromDeviceName(char *);
82 char *getDeviceNameFromJoystickNr(int);
83
84 #if defined(TARGET_SDL)
85 SDL_Joystick *Get_SDL_Joystick(int);
86 boolean Open_SDL_Joystick(int);
87 void Close_SDL_Joystick(int);
88 boolean Check_SDL_JoystickOpened(int);
89 void HandleJoystickEvent(Event *);
90 int Get_SDL_Joystick_Axis(int, int);
91 #endif
92
93 void CheckJoystickData(void);
94 int Joystick(int);
95 int JoystickButton(int);
96 int AnyJoystick(void);
97 int AnyJoystickButton(void);
98
99 void DeactivateJoystickForCalibration();
100 void ActivateJoystickIfAvailable();
101
102 #endif  /* JOYSTICK_H */