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>
30 void CheckJoystickData()
37 if (joystick[i].xmiddle <= distance)
38 joystick[i].xmiddle = distance;
39 if (joystick[i].ymiddle <= distance)
40 joystick[i].ymiddle = distance;
42 if (joystick[i].xleft >= joystick[i].xmiddle)
43 joystick[i].xleft = joystick[i].xmiddle-distance;
44 if (joystick[i].xright <= joystick[i].xmiddle)
45 joystick[i].xright = joystick[i].xmiddle+distance;
47 if (joystick[i].yupper >= joystick[i].ymiddle)
48 joystick[i].yupper = joystick[i].ymiddle-distance;
49 if (joystick[i].ylower <= joystick[i].ymiddle)
50 joystick[i].ylower = joystick[i].ymiddle+distance;
54 int JoystickPosition(int middle, int margin, int actual)
59 if (margin<middle && actual>middle)
61 if (margin>middle && actual<middle)
64 range = ABS(margin-middle);
65 pos = ABS(actual-middle);
66 percentage = (int)(pos*100/range);
76 struct joystick joy_ctrl;
78 struct joystick_control
86 int js_x,js_y, js_b1,js_b2;
87 int left, right, up, down;
90 if (joystick_status==JOYSTICK_OFF)
94 if (read(joystick_device, &joy_ctrl, sizeof(joy_ctrl)) != sizeof(joy_ctrl))
96 fprintf(stderr,"%s: cannot read joystick settings - no joystick support\n",
98 joystick_status = JOYSTICK_OFF;
108 js_b1 = joy_ctrl.buttons & 1;
109 js_b2 = joy_ctrl.buttons & 2;
112 left = JoystickPosition(joystick[joystick_nr].xmiddle,
113 joystick[joystick_nr].xleft, js_x);
114 right = JoystickPosition(joystick[joystick_nr].xmiddle,
115 joystick[joystick_nr].xright, js_x);
116 up = JoystickPosition(joystick[joystick_nr].ymiddle,
117 joystick[joystick_nr].yupper, js_y);
118 down = JoystickPosition(joystick[joystick_nr].ymiddle,
119 joystick[joystick_nr].ylower, js_y);
121 if (left>JOYSTICK_PERCENT)
123 else if (right>JOYSTICK_PERCENT)
125 if (up>JOYSTICK_PERCENT)
127 else if (down>JOYSTICK_PERCENT)
130 result |= JOY_BUTTON_1;
132 result |= JOY_BUTTON_2;
142 static int last_joy_button = 0;
143 int joy_button = (Joystick() & JOY_BUTTON);
149 result = JOY_BUTTON_PRESSED;
151 result = JOY_BUTTON_NEW_PRESSED;
156 result = JOY_BUTTON_NEW_RELEASED;
158 result = JOY_BUTTON_NOT_PRESSED;
161 last_joy_button = joy_button;