]> icculus.org git repositories - btb/d2x.git/blob - arch/include/joy.h
do away with Joystick.buttons
[btb/d2x.git] / arch / include / joy.h
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14 /*
15  *
16  * Header for joystick functions
17  *
18  */
19
20 #ifndef _JOY_H
21 #define _JOY_H
22
23 #include "pstypes.h"
24 #include "fix.h"
25
26 // added October 24, 2000 20:40  Steven Mueller: more than 4 joysticks now
27 #define MAX_JOY_DEVS 8
28 #define JOY_1_BUTTON_A  1
29 #define JOY_1_BUTTON_B  2
30 #define JOY_2_BUTTON_A  4
31 #define JOY_2_BUTTON_B  8
32 #define JOY_ALL_BUTTONS (1+2+4+8)
33
34 #define JOY_1_X_AXIS        1
35 #define JOY_1_Y_AXIS        2
36 #define JOY_1_Z_AXIS        4
37 #define JOY_1_R_AXIS        16
38 #define JOY_1_U_AXIS        32
39 #define JOY_1_V_AXIS        64
40
41 #define JOY_MAX_AXES        32
42
43 #if defined USE_LINUX_JOY
44 #define JOY_NUM_AXES        5
45 #else
46 #define JOY_NUM_AXES        4
47 #endif
48
49 #define JOY_2_X_AXIS        4
50 #define JOY_2_Y_AXIS        8
51 #define JOY_ALL_AXIS        (1+2+4+8)
52
53 #define JOY_SLOW_READINGS       1
54 #define JOY_POLLED_READINGS     2
55 #define JOY_BIOS_READINGS       4
56 /* not present in d2src, maybe we don't really need it? */
57 #define JOY_FRIENDLY_READINGS   8
58
59 #ifdef USE_LINUX_JOY
60 #define JOY_MAX_BUTTONS 64
61 #else
62 #define JOY_MAX_BUTTONS 32
63 #endif
64
65 //==========================================================================
66 // This initializes the joy and does a "quick" calibration which
67 // assumes the stick is centered and sets the minimum value to 0 and
68 // the maximum value to 2 times the centered reading. Returns 0 if no
69 // joystick was detected, 1 if everything is ok.
70 // joy_init() is called.
71
72 extern int joy_init();
73 extern void joy_close();
74
75 extern char joy_installed;
76 extern char joy_present;
77
78
79 //==========================================================================
80 // The actual number of available axes.  If the arch can't set this
81 // properly, it should set joy_num_axes=JOY_NUM_AXES;
82 extern int joy_num_axes;
83
84
85 //==========================================================================
86 // The following 3 routines can be used to zero in on better joy
87 // calibration factors. To use them, ask the user to hold the stick
88 // in either the upper left, lower right, or center and then have them
89 // press a key or button and then call the appropriate one of these
90 // routines, and it will read the stick and update the calibration factors.
91 // Usually, assuming that the stick was centered when joy_init was
92 // called, you really only need to call joy_set_lr, since the upper
93 // left position is usually always 0,0 on most joys.  But, the safest
94 // bet is to do all three, or let the user choose which ones to set.
95
96 extern void joy_set_ul();
97 extern void joy_set_lr();
98 extern void joy_set_cen();
99
100
101 //==========================================================================
102 // This reads the joystick. X and Y will be between -128 and 127.
103 // Takes about 1 millisecond in the worst case when the stick
104 // is in the lower right hand corner. Always returns 0,0 if no stick
105 // is present.
106
107 extern void joy_get_pos(int *x, int *y);
108
109 //==========================================================================
110 // This just reads the buttons and returns their status.  When bit 0
111 // is 1, button 1 is pressed, when bit 1 is 1, button 2 is pressed.
112 extern int joy_get_btns();
113
114 //==========================================================================
115 // This returns the number of times a button went either down or up since
116 // the last call to this function.
117 #define joy_get_button_up_cnt(btn) key_up_count(KEY_JB1 + (btn))
118 #define joy_get_button_down_cnt(btn) key_down_count(KEY_JB1 + (btn))
119
120 //==========================================================================
121 // This returns how long (in approximate milliseconds) that each of the
122 // buttons has been held down since the last call to this function.
123 // It is the total time... say you pressed it down for 3 ticks, released
124 // it, and held it down for 6 more ticks. The time returned would be 9.
125 #define joy_get_button_down_time(btn) key_down_time(KEY_JB1 + (btn))
126
127 extern ubyte joy_read_raw_buttons();
128 extern ubyte joystick_read_raw_axis(ubyte mask, int *axis);
129 extern void joy_flush();
130 extern ubyte joy_get_present_mask();
131 extern void joy_set_timer_rate(int max_value);
132 extern int joy_get_timer_rate();
133
134 extern int joy_get_button_state(int btn);
135 extern void joy_set_cen_fake(int channel);
136 extern ubyte joy_read_stick(ubyte masks, int *axis);
137 extern void joy_get_cal_vals(int *axis_min, int *axis_center, int *axis_max);
138 extern void joy_set_cal_vals(int *axis_min, int *axis_center, int *axis_max);
139 extern void joy_set_btn_values(int btn, int state, fix timedown, int downcount, int upcount);
140 extern int joy_get_scaled_reading(int raw, int axn);
141 extern void joy_set_slow_reading(int flag);
142
143 #endif // _JOY_H