comparison src/joystick/mint/SDL_sysjoystick.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents 92947e3a18db
children 8640d90b0406
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
50 or 1 lightpen on joypad port A 50 or 1 lightpen on joypad port A
51 or 2 analog paddles on joypads ports A,B 51 or 2 analog paddles on joypads ports A,B
52 2 joysticks on parallel port 52 2 joysticks on parallel port
53 */ 53 */
54 54
55 enum { 55 enum
56 IKBD_JOY1=0, 56 {
57 XBIOS_JOY1, 57 IKBD_JOY1 = 0,
58 PORTA_PAD, 58 XBIOS_JOY1,
59 PORTB_PAD, 59 PORTA_PAD,
60 PORTA_JOY0, 60 PORTB_PAD,
61 PORTA_JOY1, 61 PORTA_JOY0,
62 PORTB_JOY0, 62 PORTA_JOY1,
63 PORTB_JOY1, 63 PORTB_JOY0,
64 PORTA_LP, 64 PORTB_JOY1,
65 PORTA_ANPAD, 65 PORTA_LP,
66 PORTB_ANPAD, 66 PORTA_ANPAD,
67 PORTB_ANPAD,
67 #if 0 68 #if 0
68 PARA_JOY0, 69 PARA_JOY0,
69 PARA_JOY1, 70 PARA_JOY1,
70 #endif 71 #endif
71 MAX_JOYSTICKS 72 MAX_JOYSTICKS
72 }; 73 };
73 74
74 enum { 75 enum
75 MCH_ST=0, 76 {
76 MCH_STE, 77 MCH_ST = 0,
77 MCH_TT, 78 MCH_STE,
78 MCH_F30, 79 MCH_TT,
79 MCH_CLONE, 80 MCH_F30,
80 MCH_ARANYM 81 MCH_CLONE,
82 MCH_ARANYM
81 }; 83 };
82 84
83 /* Joypad buttons 85 /* Joypad buttons
84 * Procontroller note: 86 * Procontroller note:
85 * L,R are connected to 4,6 87 * L,R are connected to 4,6
86 * X,Y,Z are connected to 7,8,9 88 * X,Y,Z are connected to 7,8,9
87 */ 89 */
88 90
89 enum { 91 enum
90 JP_UP=0, JP_DOWN, JP_LEFT, JP_RIGHT, 92 {
91 JP_KPMULT, JP_KP7, JP_KP4, JP_KP1, 93 JP_UP = 0, JP_DOWN, JP_LEFT, JP_RIGHT,
92 JP_KP0, JP_KP8, JP_KP5, JP_KP2, 94 JP_KPMULT, JP_KP7, JP_KP4, JP_KP1,
93 JP_KPNUM, JP_KP9, JP_KP6, JP_KP3, 95 JP_KP0, JP_KP8, JP_KP5, JP_KP2,
94 JP_PAUSE, JP_FIRE0, JP_UNDEF0, JP_FIRE1, 96 JP_KPNUM, JP_KP9, JP_KP6, JP_KP3,
95 JP_UNDEF1, JP_FIRE2, JP_UNDEF2, JP_OPTION 97 JP_PAUSE, JP_FIRE0, JP_UNDEF0, JP_FIRE1,
98 JP_UNDEF1, JP_FIRE2, JP_UNDEF2, JP_OPTION
96 }; 99 };
97 100
98 #define JP_NUM_BUTTONS 17 101 #define JP_NUM_BUTTONS 17
99 102
100 #define PORT_JS_RIGHT (1<<0) 103 #define PORT_JS_RIGHT (1<<0)
103 #define PORT_JS_UP (1<<3) 106 #define PORT_JS_UP (1<<3)
104 #define PORT_JS_FIRE (1<<4) 107 #define PORT_JS_FIRE (1<<4)
105 108
106 /*--- Types ---*/ 109 /*--- Types ---*/
107 110
108 typedef struct { 111 typedef struct
109 SDL_bool enabled; 112 {
110 unsigned char *name; 113 SDL_bool enabled;
111 Uint32 prevstate; 114 unsigned char *name;
115 Uint32 prevstate;
112 } atarijoy_t; 116 } atarijoy_t;
113 117
114 /*--- Variables ---*/ 118 /*--- Variables ---*/
115 119
116 static atarijoy_t atarijoysticks[MAX_JOYSTICKS]={ 120 static atarijoy_t atarijoysticks[MAX_JOYSTICKS] = {
117 {SDL_FALSE,"IKBD joystick port 1",0}, 121 {SDL_FALSE, "IKBD joystick port 1", 0},
118 {SDL_FALSE,"Xbios joystick port 1",0}, 122 {SDL_FALSE, "Xbios joystick port 1", 0},
119 {SDL_FALSE,"Joypad port A",0}, 123 {SDL_FALSE, "Joypad port A", 0},
120 {SDL_FALSE,"Joypad port B",0}, 124 {SDL_FALSE, "Joypad port B", 0},
121 {SDL_FALSE,"Joystick 0 port A",0}, 125 {SDL_FALSE, "Joystick 0 port A", 0},
122 {SDL_FALSE,"Joystick 1 port A",0}, 126 {SDL_FALSE, "Joystick 1 port A", 0},
123 {SDL_FALSE,"Joystick 0 port B",0}, 127 {SDL_FALSE, "Joystick 0 port B", 0},
124 {SDL_FALSE,"Joystick 1 port B",0}, 128 {SDL_FALSE, "Joystick 1 port B", 0},
125 {SDL_FALSE,"Lightpen port A",0}, 129 {SDL_FALSE, "Lightpen port A", 0},
126 {SDL_FALSE,"Analog paddle port A",0}, 130 {SDL_FALSE, "Analog paddle port A", 0},
127 {SDL_FALSE,"Analog paddle port B",0} 131 {SDL_FALSE, "Analog paddle port B", 0}
128 #if 0 132 #if 0
129 ,{SDL_FALSE,"Joystick 0 parallel port",0}, 133 , {SDL_FALSE, "Joystick 0 parallel port", 0},
130 {SDL_FALSE,"Joystick 1 parallel port",0} 134 {SDL_FALSE, "Joystick 1 parallel port", 0}
131 #endif 135 #endif
132 }; 136 };
133 137
134 static const int jp_buttons[JP_NUM_BUTTONS]={ 138 static const int jp_buttons[JP_NUM_BUTTONS] = {
135 JP_FIRE0, JP_FIRE1, JP_FIRE2, JP_PAUSE, 139 JP_FIRE0, JP_FIRE1, JP_FIRE2, JP_PAUSE,
136 JP_OPTION, JP_KPMULT, JP_KPNUM, JP_KP0, 140 JP_OPTION, JP_KPMULT, JP_KPNUM, JP_KP0,
137 JP_KP1, JP_KP2, JP_KP3, JP_KP4, 141 JP_KP1, JP_KP2, JP_KP3, JP_KP4,
138 JP_KP5, JP_KP6, JP_KP7, JP_KP8, 142 JP_KP5, JP_KP6, JP_KP7, JP_KP8,
139 JP_KP9 143 JP_KP9
140 }; 144 };
141 145
142 static SDL_bool joypad_ports_enabled=SDL_FALSE; 146 static SDL_bool joypad_ports_enabled = SDL_FALSE;
143 147
144 /* Updated joypad ports */ 148 /* Updated joypad ports */
145 static Uint16 jp_paddles[4]; 149 static Uint16 jp_paddles[4];
146 static Uint16 jp_lightpens[2]; 150 static Uint16 jp_lightpens[2];
147 static Uint16 jp_directions; 151 static Uint16 jp_directions;
153 static int GetEnabledAtariJoystick(int index); 157 static int GetEnabledAtariJoystick(int index);
154 static void UpdateJoypads(void); 158 static void UpdateJoypads(void);
155 159
156 /*--- Functions ---*/ 160 /*--- Functions ---*/
157 161
158 int SDL_SYS_JoystickInit(void) 162 int
159 { 163 SDL_SYS_JoystickInit(void)
160 int i; 164 {
161 unsigned long cookie_mch; 165 int i;
162 const char *envr=SDL_getenv("SDL_JOYSTICK_ATARI"); 166 unsigned long cookie_mch;
163 167 const char *envr = SDL_getenv("SDL_JOYSTICK_ATARI");
168
164 #define TEST_JOY_ENABLED(env,idstring,num) \ 169 #define TEST_JOY_ENABLED(env,idstring,num) \
165 if (SDL_strstr(env,idstring"-off")) { \ 170 if (SDL_strstr(env,idstring"-off")) { \
166 atarijoysticks[num].enabled=SDL_FALSE; \ 171 atarijoysticks[num].enabled=SDL_FALSE; \
167 } \ 172 } \
168 if (SDL_strstr(env,idstring"-on")) { \ 173 if (SDL_strstr(env,idstring"-on")) { \
169 atarijoysticks[num].enabled=SDL_TRUE; \ 174 atarijoysticks[num].enabled=SDL_TRUE; \
170 } 175 }
171 176
172 /* Cookie _MCH present ? if not, assume ST machine */ 177 /* Cookie _MCH present ? if not, assume ST machine */
173 if (Getcookie(C__MCH, &cookie_mch) != C_FOUND) { 178 if (Getcookie(C__MCH, &cookie_mch) != C_FOUND) {
174 cookie_mch = MCH_ST << 16; 179 cookie_mch = MCH_ST << 16;
175 } 180 }
176 181
177 /* Enable some default joysticks */ 182 /* Enable some default joysticks */
178 if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) || 183 if ((cookie_mch == MCH_ST << 16) || ((cookie_mch >> 16) == MCH_STE) ||
179 (cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16) || 184 (cookie_mch == MCH_TT << 16) || (cookie_mch == MCH_F30 << 16) ||
180 (cookie_mch == MCH_ARANYM<<16)) { 185 (cookie_mch == MCH_ARANYM << 16)) {
181 atarijoysticks[IKBD_JOY1].enabled=(SDL_AtariIkbd_enabled!=0); 186 atarijoysticks[IKBD_JOY1].enabled = (SDL_AtariIkbd_enabled != 0);
182 } 187 }
183 if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) { 188 if ((cookie_mch == MCH_STE << 16) || (cookie_mch == MCH_F30 << 16)) {
184 atarijoysticks[PORTA_PAD].enabled=SDL_TRUE; 189 atarijoysticks[PORTA_PAD].enabled = SDL_TRUE;
185 atarijoysticks[PORTB_PAD].enabled=SDL_TRUE; 190 atarijoysticks[PORTB_PAD].enabled = SDL_TRUE;
186 } 191 }
187 if (!atarijoysticks[IKBD_JOY1].enabled) { 192 if (!atarijoysticks[IKBD_JOY1].enabled) {
188 atarijoysticks[XBIOS_JOY1].enabled=(SDL_AtariXbios_enabled!=0); 193 atarijoysticks[XBIOS_JOY1].enabled = (SDL_AtariXbios_enabled != 0);
189 } 194 }
190 195
191 /* Read environment for joysticks to enable */ 196 /* Read environment for joysticks to enable */
192 if (envr) { 197 if (envr) {
193 /* IKBD on any Atari, maybe clones */ 198 /* IKBD on any Atari, maybe clones */
194 if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) || 199 if ((cookie_mch == MCH_ST << 16) || ((cookie_mch >> 16) == MCH_STE)
195 (cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16) || 200 || (cookie_mch == MCH_TT << 16) || (cookie_mch == MCH_F30 << 16)
196 (cookie_mch == MCH_ARANYM<<16)) { 201 || (cookie_mch == MCH_ARANYM << 16)) {
197 if (SDL_AtariIkbd_enabled!=0) { 202 if (SDL_AtariIkbd_enabled != 0) {
198 TEST_JOY_ENABLED(envr, "ikbd-joy1", IKBD_JOY1); 203 TEST_JOY_ENABLED(envr, "ikbd-joy1", IKBD_JOY1);
199 } 204 }
200 } 205 }
201 /* Joypads ports only on STE and Falcon */ 206 /* Joypads ports only on STE and Falcon */
202 if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) { 207 if ((cookie_mch == MCH_STE << 16) || (cookie_mch == MCH_F30 << 16)) {
203 TEST_JOY_ENABLED(envr, "porta-pad", PORTA_PAD); 208 TEST_JOY_ENABLED(envr, "porta-pad", PORTA_PAD);
204 if (!atarijoysticks[PORTA_PAD].enabled) { 209 if (!atarijoysticks[PORTA_PAD].enabled) {
205 TEST_JOY_ENABLED(envr, "porta-joy0", PORTA_JOY0); 210 TEST_JOY_ENABLED(envr, "porta-joy0", PORTA_JOY0);
206 TEST_JOY_ENABLED(envr, "porta-joy1", PORTA_JOY1); 211 TEST_JOY_ENABLED(envr, "porta-joy1", PORTA_JOY1);
207 if (!(atarijoysticks[PORTA_JOY0].enabled) && !(atarijoysticks[PORTA_JOY1].enabled)) { 212 if (!(atarijoysticks[PORTA_JOY0].enabled)
208 TEST_JOY_ENABLED(envr, "porta-lp", PORTA_LP); 213 && !(atarijoysticks[PORTA_JOY1].enabled)) {
209 if (!atarijoysticks[PORTA_LP].enabled) { 214 TEST_JOY_ENABLED(envr, "porta-lp", PORTA_LP);
210 TEST_JOY_ENABLED(envr, "porta-anpad", PORTA_ANPAD); 215 if (!atarijoysticks[PORTA_LP].enabled) {
211 } 216 TEST_JOY_ENABLED(envr, "porta-anpad", PORTA_ANPAD);
212 } 217 }
213 } 218 }
214 219 }
215 TEST_JOY_ENABLED(envr, "portb-pad", PORTB_PAD); 220
216 if (!atarijoysticks[PORTB_PAD].enabled) { 221 TEST_JOY_ENABLED(envr, "portb-pad", PORTB_PAD);
217 TEST_JOY_ENABLED(envr, "portb-joy0", PORTB_JOY0); 222 if (!atarijoysticks[PORTB_PAD].enabled) {
218 TEST_JOY_ENABLED(envr, "portb-joy1", PORTB_JOY1); 223 TEST_JOY_ENABLED(envr, "portb-joy0", PORTB_JOY0);
219 if (!(atarijoysticks[PORTB_JOY0].enabled) && !(atarijoysticks[PORTB_JOY1].enabled)) { 224 TEST_JOY_ENABLED(envr, "portb-joy1", PORTB_JOY1);
220 TEST_JOY_ENABLED(envr, "portb-anpad", PORTB_ANPAD); 225 if (!(atarijoysticks[PORTB_JOY0].enabled)
221 } 226 && !(atarijoysticks[PORTB_JOY1].enabled)) {
222 } 227 TEST_JOY_ENABLED(envr, "portb-anpad", PORTB_ANPAD);
223 } 228 }
224 229 }
225 if (!atarijoysticks[IKBD_JOY1].enabled) { 230 }
226 if (SDL_AtariXbios_enabled!=0) { 231
227 TEST_JOY_ENABLED(envr, "xbios-joy1", XBIOS_JOY1); 232 if (!atarijoysticks[IKBD_JOY1].enabled) {
228 } 233 if (SDL_AtariXbios_enabled != 0) {
229 } 234 TEST_JOY_ENABLED(envr, "xbios-joy1", XBIOS_JOY1);
235 }
236 }
230 #if 0 237 #if 0
231 /* Parallel port on any Atari, maybe clones */ 238 /* Parallel port on any Atari, maybe clones */
232 if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) || 239 if ((cookie_mch == MCH_ST << 16) || ((cookie_mch >> 16) == MCH_STE)
233 (cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16)) { 240 || (cookie_mch == MCH_TT << 16)
234 TEST_JOY_ENABLED(envr, "para-joy0", PARA_JOY0); 241 || (cookie_mch == MCH_F30 << 16)) {
235 TEST_JOY_ENABLED(envr, "para-joy1", PARA_JOY1); 242 TEST_JOY_ENABLED(envr, "para-joy0", PARA_JOY0);
236 } 243 TEST_JOY_ENABLED(envr, "para-joy1", PARA_JOY1);
244 }
237 #endif 245 #endif
238 } 246 }
239 247
240 /* Need to update joypad ports ? */ 248 /* Need to update joypad ports ? */
241 joypad_ports_enabled=SDL_FALSE; 249 joypad_ports_enabled = SDL_FALSE;
242 for (i=PORTA_PAD;i<=PORTB_ANPAD;i++) { 250 for (i = PORTA_PAD; i <= PORTB_ANPAD; i++) {
243 if (atarijoysticks[i].enabled) { 251 if (atarijoysticks[i].enabled) {
244 joypad_ports_enabled=SDL_TRUE; 252 joypad_ports_enabled = SDL_TRUE;
245 break; 253 break;
246 } 254 }
247 } 255 }
248 256
249 SDL_numjoysticks = 0; 257 SDL_numjoysticks = 0;
250 for (i=0;i<MAX_JOYSTICKS;i++) { 258 for (i = 0; i < MAX_JOYSTICKS; i++) {
251 if (atarijoysticks[i].enabled) { 259 if (atarijoysticks[i].enabled) {
252 ++SDL_numjoysticks; 260 ++SDL_numjoysticks;
253 } 261 }
254 } 262 }
255 263
256 return(SDL_numjoysticks); 264 return (SDL_numjoysticks);
257 } 265 }
258 266
259 static int GetEnabledAtariJoystick(int index) 267 static int
260 { 268 GetEnabledAtariJoystick(int index)
261 int i,j; 269 {
262 270 int i, j;
263 /* Return the nth'index' enabled atari joystick */ 271
264 j=0; 272 /* Return the nth'index' enabled atari joystick */
265 for (i=0;i<MAX_JOYSTICKS;i++) { 273 j = 0;
266 if (!atarijoysticks[i].enabled) { 274 for (i = 0; i < MAX_JOYSTICKS; i++) {
267 continue; 275 if (!atarijoysticks[i].enabled) {
268 } 276 continue;
269 277 }
270 if (j==index) { 278
271 break; 279 if (j == index) {
272 } 280 break;
273 281 }
274 ++j; 282
275 } 283 ++j;
276 if (i==MAX_JOYSTICKS) 284 }
277 return -1; 285 if (i == MAX_JOYSTICKS)
278 286 return -1;
279 return i; 287
280 } 288 return i;
281 289 }
282 const char *SDL_SYS_JoystickName(int index) 290
283 { 291 const char *
284 int numjoystick; 292 SDL_SYS_JoystickName(int index)
285 293 {
286 numjoystick=GetEnabledAtariJoystick(index); 294 int numjoystick;
287 if (numjoystick==-1) 295
288 return NULL; 296 numjoystick = GetEnabledAtariJoystick(index);
289 297 if (numjoystick == -1)
290 return(atarijoysticks[numjoystick].name); 298 return NULL;
291 } 299
292 300 return (atarijoysticks[numjoystick].name);
293 int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) 301 }
294 { 302
295 int numjoystick; 303 int
296 304 SDL_SYS_JoystickOpen(SDL_Joystick * joystick)
297 numjoystick=GetEnabledAtariJoystick(joystick->index); 305 {
298 if (numjoystick==-1) 306 int numjoystick;
299 return -1; 307
300 308 numjoystick = GetEnabledAtariJoystick(joystick->index);
301 joystick->naxes=0; 309 if (numjoystick == -1)
302 joystick->nhats=0; 310 return -1;
303 joystick->nballs=0; 311
304 312 joystick->naxes = 0;
305 switch(numjoystick) { 313 joystick->nhats = 0;
306 case PORTA_PAD: 314 joystick->nballs = 0;
307 case PORTB_PAD: 315
308 joystick->nhats=1; 316 switch (numjoystick) {
309 joystick->nbuttons=JP_NUM_BUTTONS; 317 case PORTA_PAD:
310 break; 318 case PORTB_PAD:
311 case PORTA_LP: 319 joystick->nhats = 1;
312 case PORTA_ANPAD: 320 joystick->nbuttons = JP_NUM_BUTTONS;
313 case PORTB_ANPAD: 321 break;
314 joystick->naxes=2; 322 case PORTA_LP:
315 joystick->nbuttons=2; 323 case PORTA_ANPAD:
316 break; 324 case PORTB_ANPAD:
317 default: 325 joystick->naxes = 2;
318 joystick->nhats=1; 326 joystick->nbuttons = 2;
319 joystick->nbuttons=1; 327 break;
320 break; 328 default:
321 } 329 joystick->nhats = 1;
322 330 joystick->nbuttons = 1;
323 return(0); 331 break;
324 } 332 }
325 333
326 void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) 334 return (0);
327 { 335 }
328 int numjoystick; 336
329 Uint8 hatstate; 337 void
330 Uint32 curstate,prevstate; 338 SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
331 339 {
332 numjoystick=GetEnabledAtariJoystick(joystick->index); 340 int numjoystick;
333 if (numjoystick==-1) 341 Uint8 hatstate;
334 return; 342 Uint32 curstate, prevstate;
335 343
336 prevstate = atarijoysticks[numjoystick].prevstate; 344 numjoystick = GetEnabledAtariJoystick(joystick->index);
337 345 if (numjoystick == -1)
338 if (joypad_ports_enabled) { 346 return;
339 Supexec(UpdateJoypads); 347
340 } 348 prevstate = atarijoysticks[numjoystick].prevstate;
341 349
342 switch (numjoystick) { 350 if (joypad_ports_enabled) {
343 case IKBD_JOY1: 351 Supexec(UpdateJoypads);
344 case XBIOS_JOY1: 352 }
345 { 353
346 curstate = 0; 354 switch (numjoystick) {
347 355 case IKBD_JOY1:
348 if (numjoystick==IKBD_JOY1) { 356 case XBIOS_JOY1:
349 curstate = SDL_AtariIkbd_joystick & 0xff; 357 {
350 } 358 curstate = 0;
351 if (numjoystick==XBIOS_JOY1) { 359
352 curstate = SDL_AtariXbios_joystick & 0xff; 360 if (numjoystick == IKBD_JOY1) {
353 } 361 curstate = SDL_AtariIkbd_joystick & 0xff;
354 362 }
355 if (curstate != prevstate) { 363 if (numjoystick == XBIOS_JOY1) {
356 hatstate = SDL_HAT_CENTERED; 364 curstate = SDL_AtariXbios_joystick & 0xff;
357 if (curstate & IKBD_JOY_LEFT) { 365 }
358 hatstate |= SDL_HAT_LEFT; 366
359 } 367 if (curstate != prevstate) {
360 if (curstate & IKBD_JOY_RIGHT) { 368 hatstate = SDL_HAT_CENTERED;
361 hatstate |= SDL_HAT_RIGHT; 369 if (curstate & IKBD_JOY_LEFT) {
362 } 370 hatstate |= SDL_HAT_LEFT;
363 if (curstate & IKBD_JOY_UP) { 371 }
364 hatstate |= SDL_HAT_UP; 372 if (curstate & IKBD_JOY_RIGHT) {
365 } 373 hatstate |= SDL_HAT_RIGHT;
366 if (curstate & IKBD_JOY_DOWN) { 374 }
367 hatstate |= SDL_HAT_DOWN; 375 if (curstate & IKBD_JOY_UP) {
368 } 376 hatstate |= SDL_HAT_UP;
369 SDL_PrivateJoystickHat(joystick, 0, hatstate); 377 }
370 378 if (curstate & IKBD_JOY_DOWN) {
371 /* Button */ 379 hatstate |= SDL_HAT_DOWN;
372 if ((curstate & IKBD_JOY_FIRE) && !(prevstate & IKBD_JOY_FIRE)) { 380 }
373 SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED); 381 SDL_PrivateJoystickHat(joystick, 0, hatstate);
374 } 382
375 if (!(curstate & IKBD_JOY_FIRE) && (prevstate & IKBD_JOY_FIRE)) { 383 /* Button */
376 SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED); 384 if ((curstate & IKBD_JOY_FIRE)
377 } 385 && !(prevstate & IKBD_JOY_FIRE)) {
378 } 386 SDL_PrivateJoystickButton(joystick, 0, SDL_PRESSED);
379 atarijoysticks[numjoystick].prevstate = curstate; 387 }
380 } 388 if (!(curstate & IKBD_JOY_FIRE)
381 break; 389 && (prevstate & IKBD_JOY_FIRE)) {
382 case PORTA_PAD: 390 SDL_PrivateJoystickButton(joystick, 0, SDL_RELEASED);
383 case PORTB_PAD: 391 }
384 { 392 }
385 int numjoypad,i; 393 atarijoysticks[numjoystick].prevstate = curstate;
386 394 }
387 numjoypad=0; 395 break;
388 if (numjoystick==PORTB_PAD) numjoypad=1; 396 case PORTA_PAD:
389 397 case PORTB_PAD:
390 curstate=jp_joypads[numjoypad]; 398 {
391 if (curstate!=prevstate) { 399 int numjoypad, i;
392 hatstate = SDL_HAT_CENTERED; 400
393 if (curstate & (1<<JP_LEFT)) { 401 numjoypad = 0;
394 hatstate |= SDL_HAT_LEFT; 402 if (numjoystick == PORTB_PAD)
395 } 403 numjoypad = 1;
396 if (curstate & (1<<JP_RIGHT)) { 404
397 hatstate |= SDL_HAT_RIGHT; 405 curstate = jp_joypads[numjoypad];
398 } 406 if (curstate != prevstate) {
399 if (curstate & (1<<JP_UP)) { 407 hatstate = SDL_HAT_CENTERED;
400 hatstate |= SDL_HAT_UP; 408 if (curstate & (1 << JP_LEFT)) {
401 } 409 hatstate |= SDL_HAT_LEFT;
402 if (curstate & (1<<JP_DOWN)) { 410 }
403 hatstate |= SDL_HAT_DOWN; 411 if (curstate & (1 << JP_RIGHT)) {
404 } 412 hatstate |= SDL_HAT_RIGHT;
405 SDL_PrivateJoystickHat(joystick, 0, hatstate); 413 }
406 414 if (curstate & (1 << JP_UP)) {
407 /* Buttons */ 415 hatstate |= SDL_HAT_UP;
408 for (i=0;i<JP_NUM_BUTTONS;i++) { 416 }
409 int button; 417 if (curstate & (1 << JP_DOWN)) {
410 418 hatstate |= SDL_HAT_DOWN;
411 button=1<<jp_buttons[i]; 419 }
412 420 SDL_PrivateJoystickHat(joystick, 0, hatstate);
413 if ((curstate & button) && !(prevstate & button)) { 421
414 SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED); 422 /* Buttons */
415 } 423 for (i = 0; i < JP_NUM_BUTTONS; i++) {
416 if (!(curstate & button) && (prevstate & button)) { 424 int button;
417 SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED); 425
418 } 426 button = 1 << jp_buttons[i];
419 } 427
420 } 428 if ((curstate & button) && !(prevstate & button)) {
421 atarijoysticks[numjoystick].prevstate = curstate; 429 SDL_PrivateJoystickButton(joystick, i, SDL_PRESSED);
422 } 430 }
423 break; 431 if (!(curstate & button) && (prevstate & button)) {
424 case PORTA_JOY0: 432 SDL_PrivateJoystickButton(joystick, i, SDL_RELEASED);
425 case PORTA_JOY1: 433 }
426 case PORTB_JOY0: 434 }
427 case PORTB_JOY1: 435 }
428 { 436 atarijoysticks[numjoystick].prevstate = curstate;
429 int fire_shift=0,dir_shift=0; 437 }
430 438 break;
431 if (numjoystick==PORTA_JOY0) { fire_shift=0; dir_shift=0; } 439 case PORTA_JOY0:
432 if (numjoystick==PORTA_JOY1) { fire_shift=1; dir_shift=4; } 440 case PORTA_JOY1:
433 if (numjoystick==PORTB_JOY0) { fire_shift=2; dir_shift=8; } 441 case PORTB_JOY0:
434 if (numjoystick==PORTB_JOY1) { fire_shift=3; dir_shift=12; } 442 case PORTB_JOY1:
435 443 {
436 curstate = (jp_directions>>dir_shift) & 15; 444 int fire_shift = 0, dir_shift = 0;
437 curstate |= ((jp_fires>>fire_shift) & 1)<<4; 445
438 446 if (numjoystick == PORTA_JOY0) {
439 if (curstate != prevstate) { 447 fire_shift = 0;
440 hatstate = SDL_HAT_CENTERED; 448 dir_shift = 0;
441 if (curstate & PORT_JS_LEFT) { 449 }
442 hatstate |= SDL_HAT_LEFT; 450 if (numjoystick == PORTA_JOY1) {
443 } 451 fire_shift = 1;
444 if (curstate & PORT_JS_RIGHT) { 452 dir_shift = 4;
445 hatstate |= SDL_HAT_RIGHT; 453 }
446 } 454 if (numjoystick == PORTB_JOY0) {
447 if (curstate & PORT_JS_UP) { 455 fire_shift = 2;
448 hatstate |= SDL_HAT_UP; 456 dir_shift = 8;
449 } 457 }
450 if (curstate & PORT_JS_DOWN) { 458 if (numjoystick == PORTB_JOY1) {
451 hatstate |= SDL_HAT_DOWN; 459 fire_shift = 3;
452 } 460 dir_shift = 12;
453 SDL_PrivateJoystickHat(joystick, 0, hatstate); 461 }
454 462
455 /* Button */ 463 curstate = (jp_directions >> dir_shift) & 15;
456 if ((curstate & PORT_JS_FIRE) && !(prevstate & PORT_JS_FIRE)) { 464 curstate |= ((jp_fires >> fire_shift) & 1) << 4;
457 SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED); 465
458 } 466 if (curstate != prevstate) {
459 if (!(curstate & PORT_JS_FIRE) && (prevstate & PORT_JS_FIRE)) { 467 hatstate = SDL_HAT_CENTERED;
460 SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED); 468 if (curstate & PORT_JS_LEFT) {
461 } 469 hatstate |= SDL_HAT_LEFT;
462 } 470 }
463 atarijoysticks[numjoystick].prevstate = curstate; 471 if (curstate & PORT_JS_RIGHT) {
464 } 472 hatstate |= SDL_HAT_RIGHT;
465 break; 473 }
466 case PORTA_LP: 474 if (curstate & PORT_JS_UP) {
467 { 475 hatstate |= SDL_HAT_UP;
468 int i; 476 }
469 477 if (curstate & PORT_JS_DOWN) {
470 curstate = jp_lightpens[0]>>1; 478 hatstate |= SDL_HAT_DOWN;
471 curstate |= (jp_lightpens[1]>>1)<<15; 479 }
472 curstate |= (jp_fires & 3)<<30; 480 SDL_PrivateJoystickHat(joystick, 0, hatstate);
473 481
474 if (curstate != prevstate) { 482 /* Button */
475 /* X axis */ 483 if ((curstate & PORT_JS_FIRE)
476 SDL_PrivateJoystickAxis(joystick,0,jp_lightpens[0] ^ 0x8000); 484 && !(prevstate & PORT_JS_FIRE)) {
477 /* Y axis */ 485 SDL_PrivateJoystickButton(joystick, 0, SDL_PRESSED);
478 SDL_PrivateJoystickAxis(joystick,1,jp_lightpens[1] ^ 0x8000); 486 }
479 /* Buttons */ 487 if (!(curstate & PORT_JS_FIRE)
480 for (i=0;i<2;i++) { 488 && (prevstate & PORT_JS_FIRE)) {
481 int button; 489 SDL_PrivateJoystickButton(joystick, 0, SDL_RELEASED);
482 490 }
483 button=1<<(30+i); 491 }
484 492 atarijoysticks[numjoystick].prevstate = curstate;
485 if ((curstate & button) && !(prevstate & button)) { 493 }
486 SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED); 494 break;
487 } 495 case PORTA_LP:
488 if (!(curstate & button) && (prevstate & button)) { 496 {
489 SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED); 497 int i;
490 } 498
491 } 499 curstate = jp_lightpens[0] >> 1;
492 } 500 curstate |= (jp_lightpens[1] >> 1) << 15;
493 atarijoysticks[numjoystick].prevstate = curstate; 501 curstate |= (jp_fires & 3) << 30;
494 } 502
495 break; 503 if (curstate != prevstate) {
496 case PORTA_ANPAD: 504 /* X axis */
497 case PORTB_ANPAD: 505 SDL_PrivateJoystickAxis(joystick, 0,
498 { 506 jp_lightpens[0] ^ 0x8000);
499 int numpaddle, i; 507 /* Y axis */
500 508 SDL_PrivateJoystickAxis(joystick, 1,
501 numpaddle=0<<1; 509 jp_lightpens[1] ^ 0x8000);
502 if (numjoystick==PORTB_ANPAD) numpaddle=1<<1; 510 /* Buttons */
503 511 for (i = 0; i < 2; i++) {
504 curstate = jp_paddles[numpaddle]>>1; 512 int button;
505 curstate |= (jp_paddles[numpaddle+1]>>1)<<15; 513
506 curstate |= ((jp_fires>>numpaddle) & 3)<<30; 514 button = 1 << (30 + i);
507 515
508 if (curstate != prevstate) { 516 if ((curstate & button) && !(prevstate & button)) {
509 /* X axis */ 517 SDL_PrivateJoystickButton(joystick, i, SDL_PRESSED);
510 SDL_PrivateJoystickAxis(joystick,0,jp_paddles[numpaddle] ^ 0x8000); 518 }
511 /* Y axis */ 519 if (!(curstate & button) && (prevstate & button)) {
512 SDL_PrivateJoystickAxis(joystick,1,jp_paddles[numpaddle+1] ^ 0x8000); 520 SDL_PrivateJoystickButton(joystick, i, SDL_RELEASED);
513 /* Buttons */ 521 }
514 for (i=0;i<2;i++) { 522 }
515 int button; 523 }
516 524 atarijoysticks[numjoystick].prevstate = curstate;
517 button=1<<(30+i); 525 }
518 526 break;
519 if ((curstate & button) && !(prevstate & button)) { 527 case PORTA_ANPAD:
520 SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED); 528 case PORTB_ANPAD:
521 } 529 {
522 if (!(curstate & button) && (prevstate & button)) { 530 int numpaddle, i;
523 SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED); 531
524 } 532 numpaddle = 0 << 1;
525 } 533 if (numjoystick == PORTB_ANPAD)
526 } 534 numpaddle = 1 << 1;
527 atarijoysticks[numjoystick].prevstate = curstate; 535
528 } 536 curstate = jp_paddles[numpaddle] >> 1;
529 break; 537 curstate |= (jp_paddles[numpaddle + 1] >> 1) << 15;
538 curstate |= ((jp_fires >> numpaddle) & 3) << 30;
539
540 if (curstate != prevstate) {
541 /* X axis */
542 SDL_PrivateJoystickAxis(joystick, 0,
543 jp_paddles[numpaddle] ^ 0x8000);
544 /* Y axis */
545 SDL_PrivateJoystickAxis(joystick, 1,
546 jp_paddles[numpaddle + 1] ^ 0x8000);
547 /* Buttons */
548 for (i = 0; i < 2; i++) {
549 int button;
550
551 button = 1 << (30 + i);
552
553 if ((curstate & button) && !(prevstate & button)) {
554 SDL_PrivateJoystickButton(joystick, i, SDL_PRESSED);
555 }
556 if (!(curstate & button) && (prevstate & button)) {
557 SDL_PrivateJoystickButton(joystick, i, SDL_RELEASED);
558 }
559 }
560 }
561 atarijoysticks[numjoystick].prevstate = curstate;
562 }
563 break;
530 #if 0 564 #if 0
531 case PARA_JOY0: 565 case PARA_JOY0:
532 case PARA_JOY1: 566 case PARA_JOY1:
533 break; 567 break;
534 #endif 568 #endif
535 }; 569 };
536 570
537 return; 571 return;
538 } 572 }
539 573
540 void SDL_SYS_JoystickClose(SDL_Joystick *joystick) 574 void
541 { 575 SDL_SYS_JoystickClose(SDL_Joystick * joystick)
542 return; 576 {
543 } 577 return;
544 578 }
545 void SDL_SYS_JoystickQuit(void) 579
546 { 580 void
547 SDL_numjoysticks=0; 581 SDL_SYS_JoystickQuit(void)
548 return; 582 {
583 SDL_numjoysticks = 0;
584 return;
549 } 585 }
550 586
551 /*--- Joypad I/O read/write interface ---*/ 587 /*--- Joypad I/O read/write interface ---*/
552 588
553 #define JOYPAD_IO_BASE (0xffff9200) 589 #define JOYPAD_IO_BASE (0xffff9200)
554 struct JOYPAD_IO_S { 590 struct JOYPAD_IO_S
555 Uint16 fires; 591 {
556 Uint16 directions; 592 Uint16 fires;
557 Uint16 dummy1[6]; 593 Uint16 directions;
558 Uint16 paddles[4]; 594 Uint16 dummy1[6];
559 Uint16 dummy2[4]; 595 Uint16 paddles[4];
560 Uint16 lightpens[2]; 596 Uint16 dummy2[4];
597 Uint16 lightpens[2];
561 }; 598 };
562 #define JOYPAD_IO ((*(volatile struct JOYPAD_IO_S *)JOYPAD_IO_BASE)) 599 #define JOYPAD_IO ((*(volatile struct JOYPAD_IO_S *)JOYPAD_IO_BASE))
563 600
564 static void UpdateJoypads(void) 601 static void
565 { 602 UpdateJoypads(void)
566 Uint16 tmp; 603 {
567 604 Uint16 tmp;
568 /*--- This function is called in supervisor mode ---*/ 605
569 606 /*--- This function is called in supervisor mode ---*/
570 /* Update joysticks */ 607
571 jp_fires = (~(JOYPAD_IO.fires)) & 15; 608 /* Update joysticks */
572 jp_directions = (~(JOYPAD_IO.directions)); 609 jp_fires = (~(JOYPAD_IO.fires)) & 15;
573 610 jp_directions = (~(JOYPAD_IO.directions));
574 /* Update lightpen */ 611
575 tmp = JOYPAD_IO.lightpens[0] & 1023; 612 /* Update lightpen */
576 jp_lightpens[0] = (tmp<<6) | (tmp>>4); 613 tmp = JOYPAD_IO.lightpens[0] & 1023;
577 tmp = JOYPAD_IO.lightpens[1] & 1023; 614 jp_lightpens[0] = (tmp << 6) | (tmp >> 4);
578 jp_lightpens[1] = (tmp<<6) | (tmp>>4); 615 tmp = JOYPAD_IO.lightpens[1] & 1023;
579 616 jp_lightpens[1] = (tmp << 6) | (tmp >> 4);
580 /* Update paddles */ 617
581 tmp = (JOYPAD_IO.paddles[0] & 255); 618 /* Update paddles */
582 jp_paddles[0] = (tmp<<8) | tmp; 619 tmp = (JOYPAD_IO.paddles[0] & 255);
583 tmp = (JOYPAD_IO.paddles[1] & 255); 620 jp_paddles[0] = (tmp << 8) | tmp;
584 jp_paddles[1] = (tmp<<8) | tmp; 621 tmp = (JOYPAD_IO.paddles[1] & 255);
585 tmp = (JOYPAD_IO.paddles[2] & 255); 622 jp_paddles[1] = (tmp << 8) | tmp;
586 jp_paddles[2] = (tmp<<8) | tmp; 623 tmp = (JOYPAD_IO.paddles[2] & 255);
587 tmp = (JOYPAD_IO.paddles[3] & 255); 624 jp_paddles[2] = (tmp << 8) | tmp;
588 jp_paddles[3] = (tmp<<8) | tmp; 625 tmp = (JOYPAD_IO.paddles[3] & 255);
589 626 jp_paddles[3] = (tmp << 8) | tmp;
590 /* Update joypad 0 */ 627
591 JOYPAD_IO.directions=0xfffe; 628 /* Update joypad 0 */
592 jp_joypads[0]=((~(JOYPAD_IO.fires)) & 3)<<(16); 629 JOYPAD_IO.directions = 0xfffe;
593 JOYPAD_IO.directions=0xfffe; 630 jp_joypads[0] = ((~(JOYPAD_IO.fires)) & 3) << (16);
594 jp_joypads[0] |= ((~(JOYPAD_IO.directions))>>8) & 15; 631 JOYPAD_IO.directions = 0xfffe;
595 632 jp_joypads[0] |= ((~(JOYPAD_IO.directions)) >> 8) & 15;
596 JOYPAD_IO.directions=0xfffd; 633
597 jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3)<<(16+2); 634 JOYPAD_IO.directions = 0xfffd;
598 JOYPAD_IO.directions=0xfffd; 635 jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3) << (16 + 2);
599 jp_joypads[0] |= (((~(JOYPAD_IO.directions))>>8) & 15)<<4; 636 JOYPAD_IO.directions = 0xfffd;
600 637 jp_joypads[0] |= (((~(JOYPAD_IO.directions)) >> 8) & 15) << 4;
601 JOYPAD_IO.directions=0xfffb; 638
602 jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3)<<(16+4); 639 JOYPAD_IO.directions = 0xfffb;
603 JOYPAD_IO.directions=0xfffb; 640 jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3) << (16 + 4);
604 jp_joypads[0] |= (((~(JOYPAD_IO.directions))>>8) & 15)<<8; 641 JOYPAD_IO.directions = 0xfffb;
605 642 jp_joypads[0] |= (((~(JOYPAD_IO.directions)) >> 8) & 15) << 8;
606 JOYPAD_IO.directions=0xfff7; 643
607 jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3)<<(16+6); 644 JOYPAD_IO.directions = 0xfff7;
608 JOYPAD_IO.directions=0xfff7; 645 jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3) << (16 + 6);
609 jp_joypads[0] |= (((~(JOYPAD_IO.directions))>>8) & 15)<<12; 646 JOYPAD_IO.directions = 0xfff7;
610 647 jp_joypads[0] |= (((~(JOYPAD_IO.directions)) >> 8) & 15) << 12;
611 /* Update joypad 1 */ 648
612 JOYPAD_IO.directions=0xffef; 649 /* Update joypad 1 */
613 jp_joypads[1]=((~(JOYPAD_IO.fires)) & (3<<2))<<(16-2); 650 JOYPAD_IO.directions = 0xffef;
614 JOYPAD_IO.directions=0xffef; 651 jp_joypads[1] = ((~(JOYPAD_IO.fires)) & (3 << 2)) << (16 - 2);
615 jp_joypads[1] |= ((~(JOYPAD_IO.directions))>>12) & 15; 652 JOYPAD_IO.directions = 0xffef;
616 653 jp_joypads[1] |= ((~(JOYPAD_IO.directions)) >> 12) & 15;
617 JOYPAD_IO.directions=0xffdf; 654
618 jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3<<2))<<(16); 655 JOYPAD_IO.directions = 0xffdf;
619 JOYPAD_IO.directions=0xffdf; 656 jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3 << 2)) << (16);
620 jp_joypads[1] |= (((~(JOYPAD_IO.directions))>>12) & 15)<<4; 657 JOYPAD_IO.directions = 0xffdf;
621 658 jp_joypads[1] |= (((~(JOYPAD_IO.directions)) >> 12) & 15) << 4;
622 JOYPAD_IO.directions=0xffbf; 659
623 jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3<<2))<<(16+2); 660 JOYPAD_IO.directions = 0xffbf;
624 JOYPAD_IO.directions=0xffbf; 661 jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3 << 2)) << (16 + 2);
625 jp_joypads[1] |= (((~(JOYPAD_IO.directions))>>12) & 15)<<8; 662 JOYPAD_IO.directions = 0xffbf;
626 663 jp_joypads[1] |= (((~(JOYPAD_IO.directions)) >> 12) & 15) << 8;
627 JOYPAD_IO.directions=0xff7f; 664
628 jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3<<2))<<(16+4); 665 JOYPAD_IO.directions = 0xff7f;
629 JOYPAD_IO.directions=0xff7f; 666 jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3 << 2)) << (16 + 4);
630 jp_joypads[1] |= (((~(JOYPAD_IO.directions))>>12) & 15)<<12; 667 JOYPAD_IO.directions = 0xff7f;
668 jp_joypads[1] |= (((~(JOYPAD_IO.directions)) >> 12) & 15) << 12;
631 } 669 }
632 670
633 #endif /* SDL_JOYSTICK_MINT */ 671 #endif /* SDL_JOYSTICK_MINT */
672 /* vi: set ts=4 sw=4 expandtab: */