1 //
2 // Copyright(C) 2005-2014 Simon Howard
3 //
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 //
14 // DESCRIPTION:
15 //      System-specific joystick interface.
16 //
17 
18 
19 #ifndef __I_JOYSTICK__
20 #define __I_JOYSTICK__
21 
22 // Number of "virtual" joystick buttons defined in configuration files.
23 // This needs to be at least as large as the number of different key
24 // bindings supported by the higher-level game code (joyb* variables).
25 #define NUM_VIRTUAL_BUTTONS 11
26 
27 // If this bit is set in a configuration file axis value, the axis is
28 // not actually a joystick axis, but instead is a "button axis". This
29 // means that instead of reading an SDL joystick axis, we read the
30 // state of two buttons to get the axis value. This is needed for eg.
31 // the PS3 SIXAXIS controller, where the D-pad buttons register as
32 // buttons, not as two axes.
33 #define BUTTON_AXIS 0x10000
34 
35 // Query whether a given axis value describes a button axis.
36 #define IS_BUTTON_AXIS(axis) ((axis) >= 0 && ((axis) & BUTTON_AXIS) != 0)
37 
38 // Get the individual buttons from a button axis value.
39 #define BUTTON_AXIS_NEG(axis)  ((axis) & 0xff)
40 #define BUTTON_AXIS_POS(axis)  (((axis) >> 8) & 0xff)
41 
42 // Create a button axis value from two button values.
43 #define CREATE_BUTTON_AXIS(neg, pos) (BUTTON_AXIS | (neg) | ((pos) << 8))
44 
45 // If this bit is set in an axis value, the axis is not actually a
46 // joystick axis, but is a "hat" axis. This means that we read (one of)
47 // the hats on the joystick.
48 #define HAT_AXIS    0x20000
49 
50 #define IS_HAT_AXIS(axis) ((axis) >= 0 && ((axis) & HAT_AXIS) != 0)
51 
52 // Get the hat number from a hat axis value.
53 #define HAT_AXIS_HAT(axis)         ((axis) & 0xff)
54 // Which axis of the hat? (horizonal or vertical)
55 #define HAT_AXIS_DIRECTION(axis)   (((axis) >> 8) & 0xff)
56 
57 #define CREATE_HAT_AXIS(hat, direction) \
58     (HAT_AXIS | (hat) | ((direction) << 8))
59 
60 #define HAT_AXIS_HORIZONTAL 1
61 #define HAT_AXIS_VERTICAL   2
62 
63 void I_InitJoystick(void);
64 void I_ShutdownJoystick(void);
65 void I_UpdateJoystick(void);
66 
67 void I_BindJoystickVariables(void);
68 
69 #endif /* #ifndef __I_JOYSTICK__ */
70 
71