2 * $Source: /cvs/cvsroot/d2x/arch/sdl/joy.c,v $
5 * $Date: 2001-12-03 02:43:02 $
9 * $Log: not supported by cvs2svn $
10 * Revision 1.1 2001/10/24 09:25:05 bradleyb
11 * Moved input stuff to arch subdirs, as in d1x.
13 * Revision 1.1 2001/10/10 03:01:29 bradleyb
14 * Replacing win32 joystick (broken) with SDL joystick (stubs)
30 #define MAX_JOYSTICKS 16
33 #define MAX_AXES_PER_JOYSTICK 8
34 #define MAX_BUTTONS_PER_JOYSTICK 16
37 int num_joysticks = 0;
47 static struct joyinfo {
51 struct joybutton buttons[MAX_BUTTONS];
58 int axis_map[MAX_AXES_PER_JOYSTICK];
59 int button_map[MAX_BUTTONS_PER_JOYSTICK];
60 } SDL_Joysticks[MAX_JOYSTICKS];
62 void joy_button_handler(SDL_JoyButtonEvent *jbe)
66 button = SDL_Joysticks[jbe->which].button_map[jbe->button];
68 Joystick.buttons[button].state = jbe->state;
71 case SDL_JOYBUTTONDOWN:
72 Joystick.buttons[button].time_went_down
73 = timer_get_fixed_seconds();
74 Joystick.buttons[button].num_downs++;
77 Joystick.buttons[button].time_held_down
78 += timer_get_fixed_seconds()
79 - Joystick.buttons[button].time_went_down;
80 Joystick.buttons[button].num_ups++;
85 void joy_axis_handler(SDL_JoyAxisEvent *jae)
89 axis = SDL_Joysticks[jae->which].axis_map[jae->axis];
91 Joystick.axes[axis] = jae->value;
95 /* ----------------------------------------------- */
101 memset(&Joystick,0,sizeof(Joystick));
103 n = SDL_NumJoysticks();
105 con_printf(CON_VERBOSE, "Joystick: found %d joysticks\n", n);
106 for (i = 0; i < n; i++) {
107 con_printf(CON_VERBOSE, "Joystick %d: %s\n", i, SDL_JoystickName(i));
108 SDL_Joysticks[num_joysticks].handle = SDL_JoystickOpen(i);
109 if (SDL_Joysticks[num_joysticks].handle) {
111 SDL_Joysticks[num_joysticks].n_axes
112 = SDL_JoystickNumAxes(SDL_Joysticks[num_joysticks].handle);
113 SDL_Joysticks[num_joysticks].n_buttons
114 = SDL_JoystickNumButtons(SDL_Joysticks[num_joysticks].handle);
115 con_printf(CON_VERBOSE, "Joystick: %d axes\n", SDL_Joysticks[num_joysticks].n_axes);
116 con_printf(CON_VERBOSE, "Joystick: %d buttons\n", SDL_Joysticks[num_joysticks].n_buttons);
117 for (j=0; j < SDL_Joysticks[num_joysticks].n_axes; j++)
118 SDL_Joysticks[num_joysticks].axis_map[j] = Joystick.n_axes++;
119 for (j=0; j < SDL_Joysticks[num_joysticks].n_buttons; j++)
120 SDL_Joysticks[num_joysticks].button_map[j] = Joystick.n_buttons++;
123 con_printf(CON_VERBOSE, "Joystick: initialization failed!\n");
131 while (num_joysticks)
132 SDL_JoystickClose(SDL_Joysticks[--num_joysticks].handle);
135 void joy_get_pos(int *x, int *y)
137 *x = Joystick.axes[0] << 8;
138 *y = Joystick.axes[1] << 8;
146 int joy_get_button_down_cnt( int btn )
151 fix joy_get_button_down_time(int btn)
155 time = Joystick.buttons[btn].time_held_down;
156 Joystick.buttons[btn].time_held_down = 0;
161 ubyte joystick_read_raw_axis( ubyte mask, int * axis )
170 int joy_get_button_state( int btn )
175 void joy_get_cal_vals(int *axis_min, int *axis_center, int *axis_max)
179 void joy_set_cal_vals(int *axis_min, int *axis_center, int *axis_max)
183 int joy_get_scaled_reading( int raw, int axn )
188 void joy_set_slow_reading( int flag )