src/joystick/mint/SDL_sysjoystick.c
author Sam Lantinga
Sat, 25 Feb 2006 15:01:44 +0000
changeset 1429 aff0170f9f1b
parent 1412 a8181c4040b8
child 1635 92947e3a18db
permissions -rw-r--r--
Date: Sat, 25 Feb 2006 14:26:19 +0100 (CET)
From: "Torsten Giebl"
Subject: [SDL] testpalette.diff

To get rid of Mousecursor Fullscreen problems on Mac OSX.
slouken@302
     1
/*
slouken@302
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@302
     4
slouken@302
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@302
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@302
     9
slouken@302
    10
    This library is distributed in the hope that it will be useful,
slouken@302
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@302
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@302
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@302
    18
slouken@302
    19
    Sam Lantinga
slouken@302
    20
    slouken@libsdl.org
slouken@302
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@302
    23
slouken@302
    24
/*
slouken@302
    25
 *	Atari Joystick/Joypad drivers
slouken@302
    26
 *
slouken@302
    27
 *	Patrice Mandin
slouken@302
    28
 */
slouken@302
    29
slouken@557
    30
#include <mint/cookie.h>
slouken@302
    31
#include <mint/osbind.h>
slouken@302
    32
patmandin@1350
    33
#include "SDL_events.h"
slouken@1361
    34
#include "../SDL_sysjoystick.h"
slouken@1361
    35
#include "../SDL_joystick_c.h"
slouken@302
    36
patmandin@1412
    37
#include "../../video/ataricommon/SDL_ikbdinterrupt_s.h"
patmandin@1412
    38
#include "../../video/ataricommon/SDL_xbiosevents_c.h"
patmandin@1412
    39
#include "../../video/ataricommon/SDL_xbiosinterrupt_s.h"
slouken@302
    40
slouken@302
    41
/*--- Const ---*/
slouken@302
    42
slouken@302
    43
/* We can have:
slouken@305
    44
	1 joystick on IKBD port 1, read via hardware I/O
slouken@305
    45
      or same joystick on IKBD port 1, read via xbios
slouken@302
    46
	2 joypads on ports A,B
slouken@302
    47
	  or 4 joysticks on joypads ports A,B
slouken@302
    48
	  or 1 lightpen on joypad port A
slouken@302
    49
	  or 2 analog paddles on joypads ports A,B
slouken@302
    50
	2 joysticks on parallel port
slouken@302
    51
*/
slouken@302
    52
slouken@302
    53
enum {
slouken@302
    54
	IKBD_JOY1=0,
slouken@305
    55
	XBIOS_JOY1,
slouken@302
    56
	PORTA_PAD,
slouken@302
    57
	PORTB_PAD,
slouken@302
    58
	PORTA_JOY0,
slouken@302
    59
	PORTA_JOY1,
slouken@302
    60
	PORTB_JOY0,
slouken@302
    61
	PORTB_JOY1,
slouken@302
    62
	PORTA_LP,
slouken@302
    63
	PORTA_ANPAD,
slouken@302
    64
	PORTB_ANPAD,
slouken@302
    65
#if 0
slouken@302
    66
	PARA_JOY0,
slouken@302
    67
	PARA_JOY1,
slouken@302
    68
#endif
slouken@302
    69
	MAX_JOYSTICKS
slouken@302
    70
};
slouken@302
    71
slouken@302
    72
enum {
slouken@302
    73
	MCH_ST=0,
slouken@302
    74
	MCH_STE,
slouken@302
    75
	MCH_TT,
patmandin@1054
    76
	MCH_F30,
patmandin@1079
    77
	MCH_CLONE,
patmandin@1054
    78
	MCH_ARANYM
slouken@302
    79
};
slouken@302
    80
slouken@302
    81
/*	Joypad buttons
slouken@302
    82
 *		Procontroller note:
slouken@302
    83
 *			L,R are connected to 4,6
slouken@302
    84
 *			X,Y,Z are connected to 7,8,9
slouken@302
    85
 */
slouken@302
    86
slouken@302
    87
enum {
slouken@302
    88
	JP_UP=0,	JP_DOWN,	JP_LEFT,	JP_RIGHT,
slouken@302
    89
	JP_KPMULT,	JP_KP7,		JP_KP4,		JP_KP1,
slouken@302
    90
	JP_KP0,		JP_KP8,		JP_KP5,		JP_KP2,
slouken@302
    91
	JP_KPNUM,	JP_KP9,		JP_KP6,		JP_KP3,
slouken@302
    92
	JP_PAUSE,	JP_FIRE0,	JP_UNDEF0,	JP_FIRE1,
slouken@302
    93
	JP_UNDEF1,	JP_FIRE2,	JP_UNDEF2,	JP_OPTION
slouken@302
    94
};
slouken@302
    95
slouken@302
    96
#define JP_NUM_BUTTONS 17
slouken@302
    97
slouken@302
    98
#define PORT_JS_RIGHT	(1<<0)
slouken@302
    99
#define PORT_JS_LEFT	(1<<1)
slouken@302
   100
#define PORT_JS_DOWN	(1<<2)
slouken@302
   101
#define PORT_JS_UP		(1<<3)
slouken@302
   102
#define PORT_JS_FIRE	(1<<4)
slouken@302
   103
slouken@302
   104
/*--- Types ---*/
slouken@302
   105
slouken@302
   106
typedef struct {
slouken@302
   107
	SDL_bool enabled;
slouken@302
   108
	unsigned char *name;
slouken@302
   109
	Uint32 prevstate;
slouken@302
   110
} atarijoy_t;
slouken@302
   111
slouken@302
   112
/*--- Variables ---*/
slouken@302
   113
slouken@302
   114
static atarijoy_t atarijoysticks[MAX_JOYSTICKS]={
slouken@302
   115
	{SDL_FALSE,"IKBD joystick port 1",0},
slouken@305
   116
	{SDL_FALSE,"Xbios joystick port 1",0},
slouken@302
   117
	{SDL_FALSE,"Joypad port A",0},
slouken@302
   118
	{SDL_FALSE,"Joypad port B",0},
slouken@302
   119
	{SDL_FALSE,"Joystick 0 port A",0},
slouken@302
   120
	{SDL_FALSE,"Joystick 1 port A",0},
slouken@302
   121
	{SDL_FALSE,"Joystick 0 port B",0},
slouken@302
   122
	{SDL_FALSE,"Joystick 1 port B",0},
slouken@302
   123
	{SDL_FALSE,"Lightpen port A",0},
slouken@302
   124
	{SDL_FALSE,"Analog paddle port A",0},
slouken@302
   125
	{SDL_FALSE,"Analog paddle port B",0}
slouken@302
   126
#if 0
slouken@302
   127
	,{SDL_FALSE,"Joystick 0 parallel port",0},
slouken@302
   128
	{SDL_FALSE,"Joystick 1 parallel port",0}
slouken@302
   129
#endif
slouken@302
   130
};
slouken@302
   131
slouken@302
   132
static const int jp_buttons[JP_NUM_BUTTONS]={
slouken@305
   133
	JP_FIRE0,	JP_FIRE1,	JP_FIRE2,	JP_PAUSE,
slouken@305
   134
	JP_OPTION,	JP_KPMULT,	JP_KPNUM,	JP_KP0,
slouken@305
   135
	JP_KP1,		JP_KP2,		JP_KP3,		JP_KP4,
slouken@305
   136
	JP_KP5,		JP_KP6,		JP_KP7,		JP_KP8,
slouken@305
   137
	JP_KP9
slouken@302
   138
};
slouken@302
   139
slouken@302
   140
static SDL_bool joypad_ports_enabled=SDL_FALSE;
slouken@302
   141
slouken@302
   142
/* Updated joypad ports */
slouken@302
   143
static Uint16 jp_paddles[4];
slouken@302
   144
static Uint16 jp_lightpens[2];
slouken@302
   145
static Uint16 jp_directions;
slouken@302
   146
static Uint16 jp_fires;
slouken@302
   147
static Uint32 jp_joypads[2];
slouken@302
   148
slouken@302
   149
/*--- Functions prototypes ---*/
slouken@302
   150
slouken@302
   151
static int GetEnabledAtariJoystick(int index);
slouken@302
   152
static void UpdateJoypads(void);
slouken@302
   153
slouken@302
   154
/*--- Functions ---*/
slouken@302
   155
slouken@302
   156
int SDL_SYS_JoystickInit(void)
slouken@302
   157
{
slouken@302
   158
	int i;
slouken@302
   159
	unsigned long cookie_mch;
slouken@1336
   160
	const char *envr=SDL_getenv("SDL_JOYSTICK_ATARI");
slouken@302
   161
	
slouken@302
   162
#define TEST_JOY_ENABLED(env,idstring,num) \
slouken@1336
   163
	if (SDL_strstr(env,idstring"-off")) { \
slouken@302
   164
		atarijoysticks[num].enabled=SDL_FALSE; \
slouken@302
   165
	} \
slouken@1336
   166
	if (SDL_strstr(env,idstring"-on")) { \
slouken@302
   167
		atarijoysticks[num].enabled=SDL_TRUE; \
slouken@302
   168
	}
slouken@302
   169
slouken@302
   170
	/* Cookie _MCH present ? if not, assume ST machine */
slouken@302
   171
	if (Getcookie(C__MCH, &cookie_mch) != C_FOUND) {
slouken@302
   172
		cookie_mch = MCH_ST << 16;
slouken@302
   173
	}
slouken@302
   174
slouken@302
   175
	/* Enable some default joysticks */
slouken@302
   176
	if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) ||
patmandin@1054
   177
		(cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16) ||
patmandin@1054
   178
		(cookie_mch == MCH_ARANYM<<16)) {
slouken@305
   179
		atarijoysticks[IKBD_JOY1].enabled=(SDL_AtariIkbd_enabled!=0);
slouken@302
   180
	}
slouken@302
   181
	if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) {
slouken@302
   182
		atarijoysticks[PORTA_PAD].enabled=SDL_TRUE;
slouken@302
   183
		atarijoysticks[PORTB_PAD].enabled=SDL_TRUE;
slouken@302
   184
	}
slouken@305
   185
	if (!atarijoysticks[IKBD_JOY1].enabled) {
slouken@305
   186
		atarijoysticks[XBIOS_JOY1].enabled=(SDL_AtariXbios_enabled!=0);
slouken@305
   187
	}
slouken@302
   188
slouken@302
   189
	/* Read environment for joysticks to enable */
slouken@302
   190
	if (envr) {
slouken@302
   191
		/* IKBD on any Atari, maybe clones */
slouken@302
   192
		if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) ||
patmandin@1054
   193
			(cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16) ||
patmandin@1054
   194
			(cookie_mch == MCH_ARANYM<<16)) {
slouken@305
   195
			if (SDL_AtariIkbd_enabled!=0) {
slouken@305
   196
				TEST_JOY_ENABLED(envr, "ikbd-joy1", IKBD_JOY1);
slouken@302
   197
			}
slouken@302
   198
		}
slouken@302
   199
		/* Joypads ports only on STE and Falcon */
slouken@302
   200
		if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) {
slouken@302
   201
			TEST_JOY_ENABLED(envr, "porta-pad", PORTA_PAD);
slouken@302
   202
			if (!atarijoysticks[PORTA_PAD].enabled) {
slouken@302
   203
				TEST_JOY_ENABLED(envr, "porta-joy0", PORTA_JOY0);
slouken@302
   204
				TEST_JOY_ENABLED(envr, "porta-joy1", PORTA_JOY1);
slouken@302
   205
				if (!(atarijoysticks[PORTA_JOY0].enabled) && !(atarijoysticks[PORTA_JOY1].enabled)) {
slouken@302
   206
					TEST_JOY_ENABLED(envr, "porta-lp", PORTA_LP);
slouken@302
   207
					if (!atarijoysticks[PORTA_LP].enabled) {
slouken@302
   208
						TEST_JOY_ENABLED(envr, "porta-anpad", PORTA_ANPAD);
slouken@302
   209
					}
slouken@302
   210
				}
slouken@302
   211
			}
slouken@302
   212
slouken@302
   213
			TEST_JOY_ENABLED(envr, "portb-pad", PORTB_PAD);
slouken@302
   214
			if (!atarijoysticks[PORTB_PAD].enabled) {
slouken@302
   215
				TEST_JOY_ENABLED(envr, "portb-joy0", PORTB_JOY0);
slouken@302
   216
				TEST_JOY_ENABLED(envr, "portb-joy1", PORTB_JOY1);
slouken@302
   217
				if (!(atarijoysticks[PORTB_JOY0].enabled) && !(atarijoysticks[PORTB_JOY1].enabled)) {
slouken@302
   218
					TEST_JOY_ENABLED(envr, "portb-anpad", PORTB_ANPAD);
slouken@302
   219
				}
slouken@302
   220
			}
slouken@302
   221
		}
slouken@305
   222
slouken@305
   223
		if (!atarijoysticks[IKBD_JOY1].enabled) {
slouken@305
   224
			if (SDL_AtariXbios_enabled!=0) {
slouken@305
   225
				TEST_JOY_ENABLED(envr, "xbios-joy1", XBIOS_JOY1);
slouken@305
   226
			}
slouken@305
   227
		}
slouken@302
   228
#if 0
slouken@302
   229
		/* Parallel port on any Atari, maybe clones */
slouken@302
   230
		if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) ||
slouken@302
   231
			(cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16)) {
slouken@302
   232
			TEST_JOY_ENABLED(envr, "para-joy0", PARA_JOY0);
slouken@302
   233
			TEST_JOY_ENABLED(envr, "para-joy1", PARA_JOY1);
slouken@302
   234
		}
slouken@302
   235
#endif
slouken@302
   236
	}
slouken@302
   237
slouken@302
   238
	/* Need to update joypad ports ? */
slouken@302
   239
	joypad_ports_enabled=SDL_FALSE;
slouken@302
   240
	for (i=PORTA_PAD;i<=PORTB_ANPAD;i++) {
slouken@302
   241
		if (atarijoysticks[i].enabled) {
slouken@302
   242
			joypad_ports_enabled=SDL_TRUE;
slouken@302
   243
			break;
slouken@302
   244
		}
slouken@302
   245
	}
slouken@302
   246
slouken@302
   247
	SDL_numjoysticks = 0;
slouken@302
   248
	for (i=0;i<MAX_JOYSTICKS;i++) {
slouken@302
   249
		if (atarijoysticks[i].enabled) {
slouken@302
   250
			++SDL_numjoysticks;
slouken@302
   251
		}
slouken@302
   252
	}
slouken@302
   253
slouken@302
   254
	return(SDL_numjoysticks);
slouken@302
   255
}
slouken@302
   256
slouken@302
   257
static int GetEnabledAtariJoystick(int index)
slouken@302
   258
{
slouken@302
   259
	int i,j;
slouken@302
   260
slouken@302
   261
	/* Return the nth'index' enabled atari joystick */
slouken@302
   262
	j=0;
slouken@302
   263
	for (i=0;i<MAX_JOYSTICKS;i++) {
slouken@305
   264
		if (!atarijoysticks[i].enabled) {
slouken@305
   265
			continue;
slouken@302
   266
		}
slouken@305
   267
slouken@305
   268
		if (j==index) {
slouken@305
   269
			break;
slouken@305
   270
		}
slouken@305
   271
slouken@305
   272
		++j;
slouken@302
   273
	}
slouken@302
   274
	if (i==MAX_JOYSTICKS)
slouken@302
   275
		return -1;
slouken@302
   276
slouken@302
   277
	return i;
slouken@302
   278
}
slouken@302
   279
slouken@302
   280
const char *SDL_SYS_JoystickName(int index)
slouken@302
   281
{
slouken@302
   282
	int numjoystick;
slouken@302
   283
slouken@302
   284
	numjoystick=GetEnabledAtariJoystick(index);
slouken@302
   285
	if (numjoystick==-1)
slouken@302
   286
		return NULL;
slouken@302
   287
slouken@302
   288
	return(atarijoysticks[numjoystick].name);
slouken@302
   289
}
slouken@302
   290
slouken@302
   291
int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
slouken@302
   292
{
slouken@302
   293
	int numjoystick;
slouken@302
   294
	
slouken@302
   295
	numjoystick=GetEnabledAtariJoystick(joystick->index);
slouken@302
   296
	if (numjoystick==-1)
slouken@302
   297
		return -1;
slouken@302
   298
	
patmandin@963
   299
	joystick->naxes=0;
patmandin@963
   300
	joystick->nhats=0;
patmandin@963
   301
	joystick->nballs=0;
patmandin@963
   302
patmandin@963
   303
	switch(numjoystick) {
patmandin@963
   304
		case PORTA_PAD:
patmandin@963
   305
		case PORTB_PAD:
patmandin@963
   306
			joystick->nhats=1;
patmandin@963
   307
			joystick->nbuttons=JP_NUM_BUTTONS;
patmandin@963
   308
			break;
patmandin@963
   309
		case PORTA_LP:
patmandin@963
   310
		case PORTA_ANPAD:
patmandin@963
   311
		case PORTB_ANPAD:
patmandin@963
   312
			joystick->naxes=2;
patmandin@963
   313
			joystick->nbuttons=2;
patmandin@963
   314
			break;
patmandin@963
   315
		default:
patmandin@963
   316
			joystick->nhats=1;
patmandin@963
   317
			joystick->nbuttons=1;
patmandin@963
   318
			break;
slouken@302
   319
	}
slouken@302
   320
slouken@302
   321
	return(0);
slouken@302
   322
}
slouken@302
   323
slouken@302
   324
void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
slouken@302
   325
{
slouken@302
   326
	int numjoystick;
patmandin@963
   327
	Uint8 hatstate;
slouken@302
   328
	Uint32 curstate,prevstate;
slouken@302
   329
	
slouken@302
   330
	numjoystick=GetEnabledAtariJoystick(joystick->index);
slouken@302
   331
	if (numjoystick==-1)
slouken@302
   332
		return;
slouken@302
   333
slouken@302
   334
	prevstate = atarijoysticks[numjoystick].prevstate;
slouken@302
   335
slouken@302
   336
	if (joypad_ports_enabled) {
slouken@302
   337
		Supexec(UpdateJoypads);
slouken@302
   338
	}
slouken@302
   339
slouken@302
   340
	switch (numjoystick) {
slouken@302
   341
		case IKBD_JOY1:
slouken@305
   342
		case XBIOS_JOY1:
slouken@302
   343
			{
slouken@305
   344
				curstate = 0;
slouken@305
   345
slouken@305
   346
				if (numjoystick==IKBD_JOY1) {
slouken@305
   347
					curstate = SDL_AtariIkbd_joystick & 0xff;
slouken@305
   348
				}
slouken@305
   349
				if (numjoystick==XBIOS_JOY1) {
slouken@305
   350
					curstate = SDL_AtariXbios_joystick & 0xff;
slouken@305
   351
				}
slouken@305
   352
slouken@302
   353
				if (curstate != prevstate) {
patmandin@963
   354
					hatstate = SDL_HAT_CENTERED;
patmandin@963
   355
					if (curstate & IKBD_JOY_LEFT) {
patmandin@963
   356
						hatstate |= SDL_HAT_LEFT;
patmandin@963
   357
					}
patmandin@963
   358
					if (curstate & IKBD_JOY_RIGHT) {
patmandin@963
   359
						hatstate |= SDL_HAT_RIGHT;
slouken@302
   360
					}
patmandin@963
   361
					if (curstate & IKBD_JOY_UP) {
patmandin@963
   362
						hatstate |= SDL_HAT_UP;
slouken@302
   363
					}
patmandin@963
   364
					if (curstate & IKBD_JOY_DOWN) {
patmandin@963
   365
						hatstate |= SDL_HAT_DOWN;
patmandin@963
   366
					}
patmandin@963
   367
					SDL_PrivateJoystickHat(joystick, 0, hatstate);
patmandin@963
   368
slouken@302
   369
					/* Button */
slouken@302
   370
					if ((curstate & IKBD_JOY_FIRE) && !(prevstate & IKBD_JOY_FIRE)) {
slouken@302
   371
						SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED);
slouken@302
   372
					}
slouken@302
   373
					if (!(curstate & IKBD_JOY_FIRE) && (prevstate & IKBD_JOY_FIRE)) {
slouken@302
   374
						SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED);
slouken@302
   375
					}
slouken@302
   376
				}
slouken@305
   377
				atarijoysticks[numjoystick].prevstate = curstate;
slouken@302
   378
			}
slouken@302
   379
			break;
slouken@302
   380
		case PORTA_PAD:
slouken@302
   381
		case PORTB_PAD:
slouken@302
   382
			{
slouken@302
   383
				int numjoypad,i;
slouken@302
   384
				
slouken@302
   385
				numjoypad=0;
slouken@302
   386
				if (numjoystick==PORTB_PAD) numjoypad=1;
slouken@302
   387
				
slouken@302
   388
				curstate=jp_joypads[numjoypad];
slouken@302
   389
				if (curstate!=prevstate) {
patmandin@963
   390
					hatstate = SDL_HAT_CENTERED;
patmandin@963
   391
					if (curstate & (1<<JP_LEFT)) {
patmandin@963
   392
						hatstate |= SDL_HAT_LEFT;
patmandin@963
   393
					}
patmandin@963
   394
					if (curstate & (1<<JP_RIGHT)) {
patmandin@963
   395
						hatstate |= SDL_HAT_RIGHT;
slouken@302
   396
					}
patmandin@963
   397
					if (curstate & (1<<JP_UP)) {
patmandin@963
   398
						hatstate |= SDL_HAT_UP;
slouken@302
   399
					}
patmandin@963
   400
					if (curstate & (1<<JP_DOWN)) {
patmandin@963
   401
						hatstate |= SDL_HAT_DOWN;
patmandin@963
   402
					}
patmandin@963
   403
					SDL_PrivateJoystickHat(joystick, 0, hatstate);
patmandin@963
   404
slouken@302
   405
					/* Buttons */
slouken@302
   406
					for (i=0;i<JP_NUM_BUTTONS;i++) {
slouken@302
   407
						int button;
slouken@302
   408
						
slouken@302
   409
						button=1<<jp_buttons[i];
slouken@302
   410
slouken@302
   411
						if ((curstate & button) && !(prevstate & button)) {
slouken@302
   412
							SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED);
slouken@302
   413
						}
slouken@302
   414
						if (!(curstate & button) && (prevstate & button)) {
slouken@302
   415
							SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED);
slouken@302
   416
						}
slouken@302
   417
					}
slouken@302
   418
				}
slouken@302
   419
				atarijoysticks[numjoystick].prevstate = curstate;
slouken@302
   420
			}
slouken@302
   421
			break;
slouken@302
   422
		case PORTA_JOY0:
slouken@302
   423
		case PORTA_JOY1:
slouken@302
   424
		case PORTB_JOY0:
slouken@302
   425
		case PORTB_JOY1:
slouken@302
   426
			{
slouken@302
   427
				int fire_shift=0,dir_shift=0;
slouken@302
   428
				
slouken@302
   429
				if (numjoystick==PORTA_JOY0) {	fire_shift=0; dir_shift=0; }
slouken@302
   430
				if (numjoystick==PORTA_JOY1) {	fire_shift=1; dir_shift=4; }
slouken@302
   431
				if (numjoystick==PORTB_JOY0) {	fire_shift=2; dir_shift=8; }
slouken@302
   432
				if (numjoystick==PORTB_JOY1) {	fire_shift=3; dir_shift=12; }
slouken@302
   433
slouken@302
   434
				curstate = (jp_directions>>dir_shift) & 15;
slouken@302
   435
				curstate |= ((jp_fires>>fire_shift) & 1)<<4;
slouken@302
   436
slouken@302
   437
				if (curstate != prevstate) {
patmandin@963
   438
					hatstate = SDL_HAT_CENTERED;
patmandin@963
   439
					if (curstate & PORT_JS_LEFT) {
patmandin@963
   440
						hatstate |= SDL_HAT_LEFT;
patmandin@963
   441
					}
patmandin@963
   442
					if (curstate & PORT_JS_RIGHT) {
patmandin@963
   443
						hatstate |= SDL_HAT_RIGHT;
slouken@302
   444
					}
patmandin@963
   445
					if (curstate & PORT_JS_UP) {
patmandin@963
   446
						hatstate |= SDL_HAT_UP;
slouken@302
   447
					}
patmandin@963
   448
					if (curstate & PORT_JS_DOWN) {
patmandin@963
   449
						hatstate |= SDL_HAT_DOWN;
patmandin@963
   450
					}
patmandin@963
   451
					SDL_PrivateJoystickHat(joystick, 0, hatstate);
patmandin@963
   452
slouken@302
   453
					/* Button */
slouken@302
   454
					if ((curstate & PORT_JS_FIRE) && !(prevstate & PORT_JS_FIRE)) {
slouken@302
   455
						SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED);
slouken@302
   456
					}
slouken@302
   457
					if (!(curstate & PORT_JS_FIRE) && (prevstate & PORT_JS_FIRE)) {
slouken@302
   458
						SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED);
slouken@302
   459
					}
slouken@302
   460
				}
slouken@302
   461
				atarijoysticks[numjoystick].prevstate = curstate;
slouken@302
   462
			}
slouken@302
   463
			break;
slouken@302
   464
		case PORTA_LP:
slouken@302
   465
			{
slouken@302
   466
				int i;
slouken@302
   467
slouken@302
   468
				curstate = jp_lightpens[0]>>1;
slouken@302
   469
				curstate |= (jp_lightpens[1]>>1)<<15;
slouken@302
   470
				curstate |= (jp_fires & 3)<<30;
slouken@302
   471
slouken@302
   472
				if (curstate != prevstate) {
slouken@302
   473
					/* X axis */
slouken@507
   474
					SDL_PrivateJoystickAxis(joystick,0,jp_lightpens[0] ^ 0x8000);
slouken@302
   475
					/* Y axis */
slouken@507
   476
					SDL_PrivateJoystickAxis(joystick,1,jp_lightpens[1] ^ 0x8000);
slouken@302
   477
					/* Buttons */
slouken@302
   478
					for (i=0;i<2;i++) {
slouken@302
   479
						int button;
slouken@302
   480
						
slouken@302
   481
						button=1<<(30+i);
slouken@302
   482
slouken@302
   483
						if ((curstate & button) && !(prevstate & button)) {
slouken@302
   484
							SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED);
slouken@302
   485
						}
slouken@302
   486
						if (!(curstate & button) && (prevstate & button)) {
slouken@302
   487
							SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED);
slouken@302
   488
						}
slouken@302
   489
					}
slouken@302
   490
				}
slouken@302
   491
				atarijoysticks[numjoystick].prevstate = curstate;
slouken@302
   492
			}
slouken@302
   493
			break;
slouken@302
   494
		case PORTA_ANPAD:
slouken@302
   495
		case PORTB_ANPAD:
slouken@302
   496
			{
slouken@302
   497
				int numpaddle, i;
slouken@302
   498
				
slouken@302
   499
				numpaddle=0<<1;
slouken@302
   500
				if (numjoystick==PORTB_ANPAD) numpaddle=1<<1;
slouken@302
   501
slouken@302
   502
				curstate = jp_paddles[numpaddle]>>1;
slouken@302
   503
				curstate |= (jp_paddles[numpaddle+1]>>1)<<15;
slouken@302
   504
				curstate |= ((jp_fires>>numpaddle) & 3)<<30;
slouken@302
   505
slouken@302
   506
				if (curstate != prevstate) {
slouken@302
   507
					/* X axis */
slouken@507
   508
					SDL_PrivateJoystickAxis(joystick,0,jp_paddles[numpaddle] ^ 0x8000);
slouken@302
   509
					/* Y axis */
slouken@507
   510
					SDL_PrivateJoystickAxis(joystick,1,jp_paddles[numpaddle+1] ^ 0x8000);
slouken@302
   511
					/* Buttons */
slouken@302
   512
					for (i=0;i<2;i++) {
slouken@302
   513
						int button;
slouken@302
   514
						
slouken@302
   515
						button=1<<(30+i);
slouken@302
   516
slouken@302
   517
						if ((curstate & button) && !(prevstate & button)) {
slouken@302
   518
							SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED);
slouken@302
   519
						}
slouken@302
   520
						if (!(curstate & button) && (prevstate & button)) {
slouken@302
   521
							SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED);
slouken@302
   522
						}
slouken@302
   523
					}
slouken@302
   524
				}
slouken@302
   525
				atarijoysticks[numjoystick].prevstate = curstate;
slouken@302
   526
			}
slouken@302
   527
			break;
slouken@302
   528
#if 0
slouken@302
   529
		case PARA_JOY0:
slouken@302
   530
		case PARA_JOY1:
slouken@302
   531
			break;
slouken@302
   532
#endif
slouken@302
   533
	};
slouken@302
   534
slouken@302
   535
	return;
slouken@302
   536
}
slouken@302
   537
slouken@302
   538
void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
slouken@302
   539
{
slouken@302
   540
	return;
slouken@302
   541
}
slouken@302
   542
slouken@302
   543
void SDL_SYS_JoystickQuit(void)
slouken@302
   544
{
slouken@302
   545
	SDL_numjoysticks=0;
slouken@302
   546
	return;
slouken@302
   547
}
slouken@302
   548
slouken@302
   549
/*--- Joypad I/O read/write interface ---*/
slouken@302
   550
slouken@302
   551
#define JOYPAD_IO_BASE (0xffff9200)
slouken@302
   552
struct JOYPAD_IO_S {
slouken@302
   553
	Uint16 fires;
slouken@302
   554
	Uint16 directions;
slouken@302
   555
	Uint16 dummy1[6];
slouken@302
   556
	Uint16 paddles[4];
slouken@302
   557
	Uint16 dummy2[4];
slouken@302
   558
	Uint16 lightpens[2];
slouken@302
   559
};
slouken@302
   560
#define JOYPAD_IO ((*(volatile struct JOYPAD_IO_S *)JOYPAD_IO_BASE))
slouken@302
   561
slouken@302
   562
static void UpdateJoypads(void)
slouken@302
   563
{
slouken@302
   564
	Uint16 tmp;
slouken@302
   565
slouken@302
   566
	/*--- This function is called in supervisor mode ---*/
slouken@302
   567
slouken@302
   568
	/* Update joysticks */
slouken@302
   569
	jp_fires = (~(JOYPAD_IO.fires)) & 15;
slouken@302
   570
	jp_directions = (~(JOYPAD_IO.directions));
slouken@302
   571
	
slouken@302
   572
	/* Update lightpen */
slouken@302
   573
	tmp = JOYPAD_IO.lightpens[0] & 1023;
slouken@302
   574
	jp_lightpens[0] = (tmp<<6) | (tmp>>4);
slouken@302
   575
	tmp = JOYPAD_IO.lightpens[1] & 1023;
slouken@302
   576
	jp_lightpens[1] = (tmp<<6) | (tmp>>4);
slouken@302
   577
	
slouken@302
   578
	/* Update paddles */
slouken@302
   579
	tmp = (JOYPAD_IO.paddles[0] & 255);
slouken@302
   580
	jp_paddles[0] = (tmp<<8) | tmp;
slouken@302
   581
	tmp = (JOYPAD_IO.paddles[1] & 255);
slouken@302
   582
	jp_paddles[1] = (tmp<<8) | tmp;
slouken@302
   583
	tmp = (JOYPAD_IO.paddles[2] & 255);
slouken@302
   584
	jp_paddles[2] = (tmp<<8) | tmp;
slouken@302
   585
	tmp = (JOYPAD_IO.paddles[3] & 255);
slouken@302
   586
	jp_paddles[3] = (tmp<<8) | tmp;
slouken@302
   587
slouken@302
   588
	/* Update joypad 0 */	
slouken@302
   589
	JOYPAD_IO.directions=0xfffe;
slouken@302
   590
	jp_joypads[0]=((~(JOYPAD_IO.fires)) & 3)<<(16);
slouken@302
   591
	JOYPAD_IO.directions=0xfffe;
slouken@302
   592
	jp_joypads[0] |= ((~(JOYPAD_IO.directions))>>8) & 15;
slouken@302
   593
slouken@302
   594
	JOYPAD_IO.directions=0xfffd;
slouken@302
   595
	jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3)<<(16+2);
slouken@302
   596
	JOYPAD_IO.directions=0xfffd;
slouken@302
   597
	jp_joypads[0] |= (((~(JOYPAD_IO.directions))>>8) & 15)<<4;
slouken@302
   598
slouken@302
   599
	JOYPAD_IO.directions=0xfffb;
slouken@302
   600
	jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3)<<(16+4);
slouken@302
   601
	JOYPAD_IO.directions=0xfffb;
slouken@302
   602
	jp_joypads[0] |= (((~(JOYPAD_IO.directions))>>8) & 15)<<8;
slouken@302
   603
slouken@302
   604
	JOYPAD_IO.directions=0xfff7;
slouken@302
   605
	jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3)<<(16+6);
slouken@302
   606
	JOYPAD_IO.directions=0xfff7;
slouken@302
   607
	jp_joypads[0] |= (((~(JOYPAD_IO.directions))>>8) & 15)<<12;
slouken@302
   608
slouken@302
   609
	/* Update joypad 1 */	
slouken@302
   610
	JOYPAD_IO.directions=0xffef;
slouken@302
   611
	jp_joypads[1]=((~(JOYPAD_IO.fires)) & (3<<2))<<(16-2);
slouken@302
   612
	JOYPAD_IO.directions=0xffef;
slouken@302
   613
	jp_joypads[1] |= ((~(JOYPAD_IO.directions))>>12) & 15;
slouken@302
   614
slouken@302
   615
	JOYPAD_IO.directions=0xffdf;
slouken@302
   616
	jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3<<2))<<(16);
slouken@302
   617
	JOYPAD_IO.directions=0xffdf;
slouken@302
   618
	jp_joypads[1] |= (((~(JOYPAD_IO.directions))>>12) & 15)<<4;
slouken@302
   619
slouken@302
   620
	JOYPAD_IO.directions=0xffbf;
slouken@302
   621
	jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3<<2))<<(16+2);
slouken@302
   622
	JOYPAD_IO.directions=0xffbf;
slouken@302
   623
	jp_joypads[1] |= (((~(JOYPAD_IO.directions))>>12) & 15)<<8;
slouken@302
   624
slouken@302
   625
	JOYPAD_IO.directions=0xff7f;
slouken@302
   626
	jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3<<2))<<(16+4);
slouken@302
   627
	JOYPAD_IO.directions=0xff7f;
slouken@302
   628
	jp_joypads[1] |= (((~(JOYPAD_IO.directions))>>12) & 15)<<12;
slouken@302
   629
}