1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-98 Artsoft Entertainment *
8 * phone: ++49 +521 290471 *
9 * email: aeglos@valinor.owl.de *
10 *----------------------------------------------------------*
12 ***********************************************************/
15 #include <machine/joystick.h>
21 void CheckJoystickData()
26 for(i=0; i<MAX_PLAYERS; i++)
28 if (setup.input[i].joy.xmiddle <= distance)
29 setup.input[i].joy.xmiddle = distance;
30 if (setup.input[i].joy.ymiddle <= distance)
31 setup.input[i].joy.ymiddle = distance;
33 if (setup.input[i].joy.xleft >= setup.input[i].joy.xmiddle)
34 setup.input[i].joy.xleft = setup.input[i].joy.xmiddle - distance;
35 if (setup.input[i].joy.xright <= setup.input[i].joy.xmiddle)
36 setup.input[i].joy.xright = setup.input[i].joy.xmiddle + distance;
38 if (setup.input[i].joy.yupper >= setup.input[i].joy.ymiddle)
39 setup.input[i].joy.yupper = setup.input[i].joy.ymiddle - distance;
40 if (setup.input[i].joy.ylower <= setup.input[i].joy.ymiddle)
41 setup.input[i].joy.ylower = setup.input[i].joy.ymiddle + distance;
45 static int JoystickPosition(int middle, int margin, int actual)
50 if (margin < middle && actual > middle)
52 if (margin > middle && actual < middle)
55 range = ABS(margin - middle);
56 pos = ABS(actual - middle);
57 percentage = (int)(pos * 100 / range);
65 int Joystick(int player_nr)
68 struct joystick joy_ctrl;
70 struct joystick_control
78 int joystick_fd = stored_player[player_nr].joystick_fd;
79 int js_x,js_y, js_b1,js_b2;
80 int left, right, up, down;
83 if (joystick_status == JOYSTICK_OFF)
86 if (!setup.input[player_nr].use_joystick || joystick_fd < 0)
90 if (read(joystick_fd, &joy_ctrl, sizeof(joy_ctrl)) != sizeof(joy_ctrl))
92 Error(ERR_WARN, "cannot read joystick device '%s'",
93 setup.input[player_nr].joy.device_name);
94 joystick_status = JOYSTICK_OFF;
105 js_b1 = joy_ctrl.buttons & 1;
106 js_b2 = joy_ctrl.buttons & 2;
109 left = JoystickPosition(setup.input[player_nr].joy.xmiddle,
110 setup.input[player_nr].joy.xleft, js_x);
111 right = JoystickPosition(setup.input[player_nr].joy.xmiddle,
112 setup.input[player_nr].joy.xright, js_x);
113 up = JoystickPosition(setup.input[player_nr].joy.ymiddle,
114 setup.input[player_nr].joy.yupper, js_y);
115 down = JoystickPosition(setup.input[player_nr].joy.ymiddle,
116 setup.input[player_nr].joy.ylower, js_y);
118 if (left > JOYSTICK_PERCENT)
120 else if (right > JOYSTICK_PERCENT)
122 if (up > JOYSTICK_PERCENT)
124 else if (down > JOYSTICK_PERCENT)
128 result |= JOY_BUTTON_1;
130 result |= JOY_BUTTON_2;
138 int JoystickButton(int player_nr)
140 static int last_joy_button = 0;
141 int joy_button = (Joystick(player_nr) & JOY_BUTTON);
147 result = JOY_BUTTON_PRESSED;
149 result = JOY_BUTTON_NEW_PRESSED;
154 result = JOY_BUTTON_NEW_RELEASED;
156 result = JOY_BUTTON_NOT_PRESSED;
159 last_joy_button = joy_button;
168 for (i=0; i<MAX_PLAYERS; i++)
170 if (!setup.input[i].use_joystick)
173 result |= Joystick(i);
179 int AnyJoystickButton()
184 for (i=0; i<MAX_PLAYERS; i++)
186 if (!setup.input[i].use_joystick)
189 result |= JoystickButton(i);