comparison src/joystick/mint/SDL_sysjoystick.c @ 305:9c6613983e85

Atari port cleanups from Patrice
author Sam Lantinga <slouken@libsdl.org>
date Sun, 10 Mar 2002 03:33:59 +0000
parents 8a86bdf34f0f
children 7853b6af5957
comparison
equal deleted inserted replaced
304:ec53caed9fb2 305:9c6613983e85
29 * Atari Joystick/Joypad drivers 29 * Atari Joystick/Joypad drivers
30 * 30 *
31 * Patrice Mandin 31 * Patrice Mandin
32 */ 32 */
33 33
34 #include <stdio.h>
34 #include <stdlib.h> 35 #include <stdlib.h>
35 #include <string.h> 36 #include <string.h>
36 37
37 #include <sys/cookie.h> 38 #include <sys/cookie.h>
38 #include <mint/osbind.h> 39 #include <mint/osbind.h>
41 #include "SDL_error.h" 42 #include "SDL_error.h"
42 #include "SDL_joystick.h" 43 #include "SDL_joystick.h"
43 #include "SDL_sysjoystick.h" 44 #include "SDL_sysjoystick.h"
44 #include "SDL_joystick_c.h" 45 #include "SDL_joystick_c.h"
45 46
46 #include "../video/ataricommon/SDL_ikbdinterrupt_s.h" 47 #include "SDL_ikbdinterrupt_s.h"
48 #include "SDL_xbiosevents_c.h"
49 #include "SDL_xbiosinterrupt_s.h"
47 50
48 /*--- Const ---*/ 51 /*--- Const ---*/
49 52
50 /* We can have: 53 /* We can have:
51 1 joystick on IKBD port 1 (port 0 is used by mouse) 54 1 joystick on IKBD port 1, read via hardware I/O
55 or same joystick on IKBD port 1, read via xbios
52 2 joypads on ports A,B 56 2 joypads on ports A,B
53 or 4 joysticks on joypads ports A,B 57 or 4 joysticks on joypads ports A,B
54 or 1 lightpen on joypad port A 58 or 1 lightpen on joypad port A
55 or 2 analog paddles on joypads ports A,B 59 or 2 analog paddles on joypads ports A,B
56 2 joysticks on parallel port 60 2 joysticks on parallel port
57 */ 61 */
58 62
59 enum { 63 enum {
60 IKBD_JOY1=0, 64 IKBD_JOY1=0,
65 XBIOS_JOY1,
61 PORTA_PAD, 66 PORTA_PAD,
62 PORTB_PAD, 67 PORTB_PAD,
63 PORTA_JOY0, 68 PORTA_JOY0,
64 PORTA_JOY1, 69 PORTA_JOY1,
65 PORTB_JOY0, 70 PORTB_JOY0,
114 119
115 /*--- Variables ---*/ 120 /*--- Variables ---*/
116 121
117 static atarijoy_t atarijoysticks[MAX_JOYSTICKS]={ 122 static atarijoy_t atarijoysticks[MAX_JOYSTICKS]={
118 {SDL_FALSE,"IKBD joystick port 1",0}, 123 {SDL_FALSE,"IKBD joystick port 1",0},
124 {SDL_FALSE,"Xbios joystick port 1",0},
119 {SDL_FALSE,"Joypad port A",0}, 125 {SDL_FALSE,"Joypad port A",0},
120 {SDL_FALSE,"Joypad port B",0}, 126 {SDL_FALSE,"Joypad port B",0},
121 {SDL_FALSE,"Joystick 0 port A",0}, 127 {SDL_FALSE,"Joystick 0 port A",0},
122 {SDL_FALSE,"Joystick 1 port A",0}, 128 {SDL_FALSE,"Joystick 1 port A",0},
123 {SDL_FALSE,"Joystick 0 port B",0}, 129 {SDL_FALSE,"Joystick 0 port B",0},
130 {SDL_FALSE,"Joystick 1 parallel port",0} 136 {SDL_FALSE,"Joystick 1 parallel port",0}
131 #endif 137 #endif
132 }; 138 };
133 139
134 static const int jp_buttons[JP_NUM_BUTTONS]={ 140 static const int jp_buttons[JP_NUM_BUTTONS]={
135 JP_KPMULT, JP_KP7, JP_KP4, JP_KP1, 141 JP_FIRE0, JP_FIRE1, JP_FIRE2, JP_PAUSE,
136 JP_KP0, JP_KP8, JP_KP5, JP_KP2, 142 JP_OPTION, JP_KPMULT, JP_KPNUM, JP_KP0,
137 JP_KPNUM, JP_KP9, JP_KP6, JP_KP3, 143 JP_KP1, JP_KP2, JP_KP3, JP_KP4,
138 JP_PAUSE, JP_FIRE0, JP_FIRE1, JP_FIRE2, 144 JP_KP5, JP_KP6, JP_KP7, JP_KP8,
139 JP_OPTION 145 JP_KP9
140 }; 146 };
141 147
142 static SDL_bool joypad_ports_enabled=SDL_FALSE; 148 static SDL_bool joypad_ports_enabled=SDL_FALSE;
143 149
144 /* Updated joypad ports */ 150 /* Updated joypad ports */
158 int SDL_SYS_JoystickInit(void) 164 int SDL_SYS_JoystickInit(void)
159 { 165 {
160 int i; 166 int i;
161 unsigned long cookie_mch; 167 unsigned long cookie_mch;
162 const char *envr=getenv("SDL_JOYSTICK_ATARI"); 168 const char *envr=getenv("SDL_JOYSTICK_ATARI");
163 const char *env_evt=getenv("SDL_ATARI_EVENTSDRIVER");
164 SDL_bool ikbd_enabled=SDL_FALSE;
165 169
166 #define TEST_JOY_ENABLED(env,idstring,num) \ 170 #define TEST_JOY_ENABLED(env,idstring,num) \
167 if (strstr(env,idstring"-off")) { \ 171 if (strstr(env,idstring"-off")) { \
168 atarijoysticks[num].enabled=SDL_FALSE; \ 172 atarijoysticks[num].enabled=SDL_FALSE; \
169 } \ 173 } \
177 } 181 }
178 182
179 /* Enable some default joysticks */ 183 /* Enable some default joysticks */
180 if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) || 184 if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) ||
181 (cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16)) { 185 (cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16)) {
182 ikbd_enabled=SDL_TRUE; 186 atarijoysticks[IKBD_JOY1].enabled=(SDL_AtariIkbd_enabled!=0);
183 if (env_evt) {
184 if (!strcmp(env_evt,"ikbd")) {
185 ikbd_enabled=SDL_FALSE;
186 }
187 }
188 atarijoysticks[IKBD_JOY1].enabled=ikbd_enabled;
189 } 187 }
190 if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) { 188 if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) {
191 atarijoysticks[PORTA_PAD].enabled=SDL_TRUE; 189 atarijoysticks[PORTA_PAD].enabled=SDL_TRUE;
192 atarijoysticks[PORTB_PAD].enabled=SDL_TRUE; 190 atarijoysticks[PORTB_PAD].enabled=SDL_TRUE;
191 }
192 if (!atarijoysticks[IKBD_JOY1].enabled) {
193 atarijoysticks[XBIOS_JOY1].enabled=(SDL_AtariXbios_enabled!=0);
193 } 194 }
194 195
195 /* Read environment for joysticks to enable */ 196 /* Read environment for joysticks to enable */
196 if (envr) { 197 if (envr) {
197 /* IKBD on any Atari, maybe clones */ 198 /* IKBD on any Atari, maybe clones */
198 if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) || 199 if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) ||
199 (cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16)) { 200 (cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16)) {
200 if (env_evt) { 201 if (SDL_AtariIkbd_enabled!=0) {
201 if (strcmp(env_evt,"ikbd")) { 202 TEST_JOY_ENABLED(envr, "ikbd-joy1", IKBD_JOY1);
202 TEST_JOY_ENABLED(envr, "ikbd-joy1", IKBD_JOY1);
203 }
204 } 203 }
205 } 204 }
206 /* Joypads ports only on STE and Falcon */ 205 /* Joypads ports only on STE and Falcon */
207 if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) { 206 if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) {
208 TEST_JOY_ENABLED(envr, "porta-pad", PORTA_PAD); 207 TEST_JOY_ENABLED(envr, "porta-pad", PORTA_PAD);
224 if (!(atarijoysticks[PORTB_JOY0].enabled) && !(atarijoysticks[PORTB_JOY1].enabled)) { 223 if (!(atarijoysticks[PORTB_JOY0].enabled) && !(atarijoysticks[PORTB_JOY1].enabled)) {
225 TEST_JOY_ENABLED(envr, "portb-anpad", PORTB_ANPAD); 224 TEST_JOY_ENABLED(envr, "portb-anpad", PORTB_ANPAD);
226 } 225 }
227 } 226 }
228 } 227 }
228
229 if (!atarijoysticks[IKBD_JOY1].enabled) {
230 if (SDL_AtariXbios_enabled!=0) {
231 TEST_JOY_ENABLED(envr, "xbios-joy1", XBIOS_JOY1);
232 }
233 }
229 #if 0 234 #if 0
230 /* Parallel port on any Atari, maybe clones */ 235 /* Parallel port on any Atari, maybe clones */
231 if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) || 236 if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) ||
232 (cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16)) { 237 (cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16)) {
233 TEST_JOY_ENABLED(envr, "para-joy0", PARA_JOY0); 238 TEST_JOY_ENABLED(envr, "para-joy0", PARA_JOY0);
260 int i,j; 265 int i,j;
261 266
262 /* Return the nth'index' enabled atari joystick */ 267 /* Return the nth'index' enabled atari joystick */
263 j=0; 268 j=0;
264 for (i=0;i<MAX_JOYSTICKS;i++) { 269 for (i=0;i<MAX_JOYSTICKS;i++) {
265 if (atarijoysticks[i].enabled) { 270 if (!atarijoysticks[i].enabled) {
266 if (j==index) { 271 continue;
267 break; 272 }
268 } else { 273
269 j++; 274 if (j==index) {
270 } 275 break;
271 } 276 }
277
278 ++j;
272 } 279 }
273 if (i==MAX_JOYSTICKS) 280 if (i==MAX_JOYSTICKS)
274 return -1; 281 return -1;
275 282
276 return i; 283 return i;
326 Supexec(UpdateJoypads); 333 Supexec(UpdateJoypads);
327 } 334 }
328 335
329 switch (numjoystick) { 336 switch (numjoystick) {
330 case IKBD_JOY1: 337 case IKBD_JOY1:
338 case XBIOS_JOY1:
331 { 339 {
332 curstate = SDL_AtariIkbd_joystick & 0xff; 340 curstate = 0;
341
342 if (numjoystick==IKBD_JOY1) {
343 curstate = SDL_AtariIkbd_joystick & 0xff;
344 }
345 if (numjoystick==XBIOS_JOY1) {
346 curstate = SDL_AtariXbios_joystick & 0xff;
347 }
348
333 if (curstate != prevstate) { 349 if (curstate != prevstate) {
334 /* X axis */ 350 /* X axis */
335 if ((curstate & (IKBD_JOY_LEFT|IKBD_JOY_RIGHT)) != (prevstate & (IKBD_JOY_LEFT|IKBD_JOY_RIGHT))) { 351 if ((curstate & (IKBD_JOY_LEFT|IKBD_JOY_RIGHT)) != (prevstate & (IKBD_JOY_LEFT|IKBD_JOY_RIGHT))) {
336 curaxis=0; 352 curaxis=0;
337 if (curstate & IKBD_JOY_LEFT) { 353 if (curstate & IKBD_JOY_LEFT) {
357 } 373 }
358 if (!(curstate & IKBD_JOY_FIRE) && (prevstate & IKBD_JOY_FIRE)) { 374 if (!(curstate & IKBD_JOY_FIRE) && (prevstate & IKBD_JOY_FIRE)) {
359 SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED); 375 SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED);
360 } 376 }
361 } 377 }
362 atarijoysticks[IKBD_JOY1].prevstate = curstate; 378 atarijoysticks[numjoystick].prevstate = curstate;
363 } 379 }
364 break; 380 break;
365 case PORTA_PAD: 381 case PORTA_PAD:
366 case PORTB_PAD: 382 case PORTB_PAD:
367 { 383 {