]> icculus.org git repositories - btb/d2x.git/blob - arch/include/joy.h
patch from Steven Mueller for using more than 4 joystick devices in linux (d1x r1...
[btb/d2x.git] / arch / include / joy.h
1 /* $Id: joy.h,v 1.7 2004-05-22 01:32:09 btb Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 /*
16  *
17  * Header for joystick functions
18  *
19  * Old Log:
20  * Revision 1.17  1995/10/07  13:22:30  john
21  * Added new method of reading joystick that allows higher-priority
22  * interrupts to go off.
23  *
24  * Revision 1.16  1995/02/14  11:17:13  john
25  * Added BIOS readings for stick.
26  *
27  * Revision 1.15  1995/02/14  10:09:58  john
28  * Added OS2 switch.
29  *
30  * Revision 1.14  1994/12/28  13:49:20  john
31  * Added function to set joystick for slow reading
32  *
33  * Revision 1.13  1994/10/13  11:36:06  john
34  * Made joy_down_time be kept track of in fixed seconds,
35  * not ticks.
36  *
37  * Revision 1.12  1994/10/12  17:03:16  john
38  * Added prototype for joy_get_scaled_reading.
39  *
40  * Revision 1.11  1994/10/12  16:57:55  john
41  * Added function to set a joystick button's state.
42  *
43  * Revision 1.10  1994/09/22  16:09:00  john
44  * Fixed some virtual memory lockdown problems with timer and
45  * joystick.
46  *
47  * Revision 1.9  1994/08/31  09:54:57  john
48  * *** empty log message ***
49  *
50  * Revision 1.8  1994/08/29  21:02:24  john
51  * Added joy_set_cal_values...
52  *
53  * Revision 1.7  1994/08/29  20:51:52  john
54  * Added better cyberman support; also, joystick calibration
55  * value return funcctiionn,
56  *
57  * Revision 1.6  1994/07/01  10:55:44  john
58  * Fixed some bugs... added support for 4 axis.
59  *
60  * Revision 1.5  1994/06/30  20:36:51  john
61  * Revamped joystick code.
62  *
63  * Revision 1.4  1994/04/22  12:52:10  john
64  * *** empty log message ***
65  *
66  * Revision 1.3  1994/01/18  13:53:39  john
67  * Made all joystick functions return int's instead of
68  * shorts.  Also made the stick reading be CPU speed
69  * independant by using the timer_get_Stamp_64
70  * function.
71  *
72  * Revision 1.2  1994/01/18  10:58:42  john
73  * *** empty log message ***
74  *
75  * Revision 1.1  1993/07/10  13:10:39  matt
76  * Initial revision
77  *
78  *
79  */
80
81 #ifndef _JOY_H
82 #define _JOY_H
83
84 #include "pstypes.h"
85 #include "fix.h"
86
87 // added October 24, 2000 20:40  Steven Mueller: more than 4 joysticks now
88 #define MAX_JOY_DEVS 8
89 #define JOY_1_BUTTON_A  1
90 #define JOY_1_BUTTON_B  2
91 #define JOY_2_BUTTON_A  4
92 #define JOY_2_BUTTON_B  8
93 #define JOY_ALL_BUTTONS (1+2+4+8)
94
95 #define JOY_1_X_AXIS        1
96 #define JOY_1_Y_AXIS        2
97 #define JOY_1_Z_AXIS        4
98 #define JOY_1_R_AXIS        16
99 #define JOY_1_U_AXIS        32
100 #define JOY_1_V_AXIS        64
101
102 #if defined WINDOWS
103 #define JOY_NUM_AXES        7
104 #elif defined USE_LINUX_JOY
105 #define JOY_NUM_AXES        5
106 #else
107 #define JOY_NUM_AXES        4
108 #endif
109
110 #ifdef WINDOWS
111 #define JOY_1_POV           8
112 #define JOY_ALL_AXIS        (1+2+4+8)
113 #define JOY_EXT_AXIS        (16+32+64)
114 #else
115 #define JOY_2_X_AXIS        4
116 #define JOY_2_Y_AXIS        8
117 #define JOY_ALL_AXIS        (1+2+4+8)
118 #endif
119
120 #define JOY_SLOW_READINGS       1
121 #define JOY_POLLED_READINGS     2
122 #define JOY_BIOS_READINGS       4
123 /* not present in d2src, maybe we don't really need it? */
124 #define JOY_FRIENDLY_READINGS   8
125
126 #ifdef USE_LINUX_JOY
127 #define MAX_BUTTONS 64
128 #else
129 #define MAX_BUTTONS 20
130 #endif
131
132 //==========================================================================
133 // This initializes the joy and does a "quick" calibration which
134 // assumes the stick is centered and sets the minimum value to 0 and
135 // the maximum value to 2 times the centered reading. Returns 0 if no
136 // joystick was detected, 1 if everything is ok.
137 // joy_init() is called.
138
139 #ifdef WINDOWS
140 # ifdef __NT__
141 extern int joy_init(int joy, int spjoy);
142 # endif
143 extern int joy95_init_stick(int joy, int spjoy);
144 #else
145 extern int joy_init();
146 #endif
147 extern void joy_close();
148
149 extern char joy_installed;
150 extern char joy_present;
151
152 //==========================================================================
153 // The following 3 routines can be used to zero in on better joy
154 // calibration factors. To use them, ask the user to hold the stick
155 // in either the upper left, lower right, or center and then have them
156 // press a key or button and then call the appropriate one of these
157 // routines, and it will read the stick and update the calibration factors.
158 // Usually, assuming that the stick was centered when joy_init was
159 // called, you really only need to call joy_set_lr, since the upper
160 // left position is usually always 0,0 on most joys.  But, the safest
161 // bet is to do all three, or let the user choose which ones to set.
162
163 extern void joy_set_ul();
164 extern void joy_set_lr();
165 extern void joy_set_cen();
166
167
168 //==========================================================================
169 // This reads the joystick. X and Y will be between -128 and 127.
170 // Takes about 1 millisecond in the worst case when the stick
171 // is in the lower right hand corner. Always returns 0,0 if no stick
172 // is present.
173
174 extern void joy_get_pos(int *x, int *y);
175
176 //==========================================================================
177 // This just reads the buttons and returns their status.  When bit 0
178 // is 1, button 1 is pressed, when bit 1 is 1, button 2 is pressed.
179 extern int joy_get_btns();
180
181 //==========================================================================
182 // This returns the number of times a button went either down or up since
183 // the last call to this function.
184 extern int joy_get_button_up_cnt(int btn);
185 extern int joy_get_button_down_cnt(int btn);
186
187 //==========================================================================
188 // This returns how long (in approximate milliseconds) that each of the
189 // buttons has been held down since the last call to this function.
190 // It is the total time... say you pressed it down for 3 ticks, released
191 // it, and held it down for 6 more ticks. The time returned would be 9.
192 extern fix joy_get_button_down_time(int btn);
193
194 extern ubyte joy_read_raw_buttons();
195 extern ubyte joystick_read_raw_axis(ubyte mask, int *axis);
196 extern void joy_flush();
197 extern ubyte joy_get_present_mask();
198 extern void joy_set_timer_rate(int max_value);
199 extern int joy_get_timer_rate();
200
201 extern int joy_get_button_state(int btn);
202 extern void joy_set_cen_fake(int channel);
203 extern ubyte joy_read_stick(ubyte masks, int *axis);
204 extern void joy_get_cal_vals(int *axis_min, int *axis_center, int *axis_max);
205 extern void joy_set_cal_vals(int *axis_min, int *axis_center, int *axis_max);
206 extern void joy_set_btn_values(int btn, int state, fix timedown, int downcount, int upcount);
207 extern int joy_get_scaled_reading(int raw, int axn);
208 extern void joy_set_slow_reading(int flag);
209
210 #endif // _JOY_H