]> icculus.org git repositories - btb/d2x.git/blob - arch/include/joy.h
move old per-file change logs into new file ChangeLog-old
[btb/d2x.git] / arch / include / joy.h
1 /* $Id: joy.h,v 1.8 2004-08-28 23:17:45 schaffner 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  */
20
21 #ifndef _JOY_H
22 #define _JOY_H
23
24 #include "pstypes.h"
25 #include "fix.h"
26
27 // added October 24, 2000 20:40  Steven Mueller: more than 4 joysticks now
28 #define MAX_JOY_DEVS 8
29 #define JOY_1_BUTTON_A  1
30 #define JOY_1_BUTTON_B  2
31 #define JOY_2_BUTTON_A  4
32 #define JOY_2_BUTTON_B  8
33 #define JOY_ALL_BUTTONS (1+2+4+8)
34
35 #define JOY_1_X_AXIS        1
36 #define JOY_1_Y_AXIS        2
37 #define JOY_1_Z_AXIS        4
38 #define JOY_1_R_AXIS        16
39 #define JOY_1_U_AXIS        32
40 #define JOY_1_V_AXIS        64
41
42 #if defined WINDOWS
43 #define JOY_NUM_AXES        7
44 #elif defined USE_LINUX_JOY
45 #define JOY_NUM_AXES        5
46 #else
47 #define JOY_NUM_AXES        4
48 #endif
49
50 #ifdef WINDOWS
51 #define JOY_1_POV           8
52 #define JOY_ALL_AXIS        (1+2+4+8)
53 #define JOY_EXT_AXIS        (16+32+64)
54 #else
55 #define JOY_2_X_AXIS        4
56 #define JOY_2_Y_AXIS        8
57 #define JOY_ALL_AXIS        (1+2+4+8)
58 #endif
59
60 #define JOY_SLOW_READINGS       1
61 #define JOY_POLLED_READINGS     2
62 #define JOY_BIOS_READINGS       4
63 /* not present in d2src, maybe we don't really need it? */
64 #define JOY_FRIENDLY_READINGS   8
65
66 #ifdef USE_LINUX_JOY
67 #define MAX_BUTTONS 64
68 #else
69 #define MAX_BUTTONS 20
70 #endif
71
72 //==========================================================================
73 // This initializes the joy and does a "quick" calibration which
74 // assumes the stick is centered and sets the minimum value to 0 and
75 // the maximum value to 2 times the centered reading. Returns 0 if no
76 // joystick was detected, 1 if everything is ok.
77 // joy_init() is called.
78
79 #ifdef WINDOWS
80 # ifdef __NT__
81 extern int joy_init(int joy, int spjoy);
82 # endif
83 extern int joy95_init_stick(int joy, int spjoy);
84 #else
85 extern int joy_init();
86 #endif
87 extern void joy_close();
88
89 extern char joy_installed;
90 extern char joy_present;
91
92 //==========================================================================
93 // The following 3 routines can be used to zero in on better joy
94 // calibration factors. To use them, ask the user to hold the stick
95 // in either the upper left, lower right, or center and then have them
96 // press a key or button and then call the appropriate one of these
97 // routines, and it will read the stick and update the calibration factors.
98 // Usually, assuming that the stick was centered when joy_init was
99 // called, you really only need to call joy_set_lr, since the upper
100 // left position is usually always 0,0 on most joys.  But, the safest
101 // bet is to do all three, or let the user choose which ones to set.
102
103 extern void joy_set_ul();
104 extern void joy_set_lr();
105 extern void joy_set_cen();
106
107
108 //==========================================================================
109 // This reads the joystick. X and Y will be between -128 and 127.
110 // Takes about 1 millisecond in the worst case when the stick
111 // is in the lower right hand corner. Always returns 0,0 if no stick
112 // is present.
113
114 extern void joy_get_pos(int *x, int *y);
115
116 //==========================================================================
117 // This just reads the buttons and returns their status.  When bit 0
118 // is 1, button 1 is pressed, when bit 1 is 1, button 2 is pressed.
119 extern int joy_get_btns();
120
121 //==========================================================================
122 // This returns the number of times a button went either down or up since
123 // the last call to this function.
124 extern int joy_get_button_up_cnt(int btn);
125 extern int joy_get_button_down_cnt(int btn);
126
127 //==========================================================================
128 // This returns how long (in approximate milliseconds) that each of the
129 // buttons has been held down since the last call to this function.
130 // It is the total time... say you pressed it down for 3 ticks, released
131 // it, and held it down for 6 more ticks. The time returned would be 9.
132 extern fix joy_get_button_down_time(int btn);
133
134 extern ubyte joy_read_raw_buttons();
135 extern ubyte joystick_read_raw_axis(ubyte mask, int *axis);
136 extern void joy_flush();
137 extern ubyte joy_get_present_mask();
138 extern void joy_set_timer_rate(int max_value);
139 extern int joy_get_timer_rate();
140
141 extern int joy_get_button_state(int btn);
142 extern void joy_set_cen_fake(int channel);
143 extern ubyte joy_read_stick(ubyte masks, int *axis);
144 extern void joy_get_cal_vals(int *axis_min, int *axis_center, int *axis_max);
145 extern void joy_set_cal_vals(int *axis_min, int *axis_center, int *axis_max);
146 extern void joy_set_btn_values(int btn, int state, fix timedown, int downcount, int upcount);
147 extern int joy_get_scaled_reading(int raw, int axn);
148 extern void joy_set_slow_reading(int flag);
149
150 #endif // _JOY_H