⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdl_sysjoystick.c

📁 SDL库 在进行视频显示程序spcaview安装时必须的库文件
💻 C
📖 第 1 页 / 共 2 页
字号:
/*    SDL - Simple DirectMedia Layer    Copyright (C) 1997-2006 Sam Lantinga    This library is free software; you can redistribute it and/or    modify it under the terms of the GNU Lesser General Public    License as published by the Free Software Foundation; either    version 2.1 of the License, or (at your option) any later version.    This library is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    Lesser General Public License for more details.    You should have received a copy of the GNU Lesser General Public    License along with this library; if not, write to the Free Software    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA    Sam Lantinga    slouken@libsdl.org*/#include "SDL_config.h"#ifdef SDL_JOYSTICK_MINT/* *	Atari Joystick/Joypad drivers * *	Patrice Mandin */#include <mint/cookie.h>#include <mint/osbind.h>#include "SDL_events.h"#include "../SDL_sysjoystick.h"#include "../SDL_joystick_c.h"#include "../../video/ataricommon/SDL_ikbdinterrupt_s.h"#include "../../video/ataricommon/SDL_xbiosevents_c.h"#include "../../video/ataricommon/SDL_xbiosinterrupt_s.h"/*--- Const ---*//* We can have:	1 joystick on IKBD port 1, read via hardware I/O	  or same joystick on IKBD port 1, read via xbios	1 joypad on port A (up to 4 with teamtap)	  or 2 joysticks on joypad port A	  or 1 analog paddle on joypad port A	  or 1 lightpen on joypad port A	1 joypad on port B (up to 4 with teamtap)	  or 2 joysticks on joypad port B	  or 1 analog paddle on joypad port B	2 joysticks on parallel port*/enum {	IKBD_JOY1=0,	XBIOS_JOY1,	PORTA_PAD0,	PORTA_PAD1,	PORTA_PAD2,	PORTA_PAD3,	PORTB_PAD0,	PORTB_PAD1,	PORTB_PAD2,	PORTB_PAD3,	PORTA_JOY0,	PORTA_JOY1,	PORTB_JOY0,	PORTB_JOY1,	PORTA_LP,	PORTA_ANPAD,	PORTB_ANPAD,#if 0	PARA_JOY0,	PARA_JOY1,#endif	MAX_JOYSTICKS};enum {	MCH_ST=0,	MCH_STE,	MCH_TT,	MCH_F30,	MCH_CLONE,	MCH_ARANYM};/*	Joypad buttons *		Procontroller note: *			L,R are connected to 4,6 *			X,Y,Z are connected to 7,8,9 */enum {	JP_UP=0,	JP_DOWN,	JP_LEFT,	JP_RIGHT,	JP_KPMULT,	JP_KP7,		JP_KP4,		JP_KP1,	JP_KP0,		JP_KP8,		JP_KP5,		JP_KP2,	JP_KPNUM,	JP_KP9,		JP_KP6,		JP_KP3,	JP_PAUSE,	JP_FIRE0,	JP_UNDEF0,	JP_FIRE1,	JP_UNDEF1,	JP_FIRE2,	JP_UNDEF2,	JP_OPTION};#define JP_NUM_BUTTONS 17#define PORT_JS_RIGHT	(1<<0)#define PORT_JS_LEFT	(1<<1)#define PORT_JS_DOWN	(1<<2)#define PORT_JS_UP		(1<<3)#define PORT_JS_FIRE	(1<<4)/*--- Types ---*/typedef struct {	SDL_bool enabled;	unsigned char *name;	Uint32 prevstate;} atarijoy_t;/*--- Variables ---*/static atarijoy_t atarijoysticks[MAX_JOYSTICKS]={	{SDL_FALSE,"IKBD joystick port 1",0},	{SDL_FALSE,"Xbios joystick port 1",0},	{SDL_FALSE,"Joypad 0 port A",0},	{SDL_FALSE,"Joypad 1 port A",0},	{SDL_FALSE,"Joypad 2 port A",0},	{SDL_FALSE,"Joypad 3 port A",0},	{SDL_FALSE,"Joypad 0 port B",0},	{SDL_FALSE,"Joypad 1 port B",0},	{SDL_FALSE,"Joypad 2 port B",0},	{SDL_FALSE,"Joypad 3 port B",0},	{SDL_FALSE,"Joystick 0 port A",0},	{SDL_FALSE,"Joystick 1 port A",0},	{SDL_FALSE,"Joystick 0 port B",0},	{SDL_FALSE,"Joystick 1 port B",0},	{SDL_FALSE,"Lightpen port A",0},	{SDL_FALSE,"Analog paddle port A",0},	{SDL_FALSE,"Analog paddle port B",0}#if 0	,{SDL_FALSE,"Joystick 0 parallel port",0},	{SDL_FALSE,"Joystick 1 parallel port",0}#endif};static const int jp_buttons[JP_NUM_BUTTONS]={	JP_FIRE0,	JP_FIRE1,	JP_FIRE2,	JP_PAUSE,	JP_OPTION,	JP_KPMULT,	JP_KPNUM,	JP_KP0,	JP_KP1,		JP_KP2,		JP_KP3,		JP_KP4,	JP_KP5,		JP_KP6,		JP_KP7,		JP_KP8,	JP_KP9};static SDL_bool joypad_ports_enabled=SDL_FALSE;/* Updated joypad ports */static Uint16 jp_paddles[4];static Uint16 jp_lightpens[2];static Uint16 jp_directions;static Uint16 jp_fires;static Uint32 jp_joypads[8];/*--- Functions prototypes ---*/static int GetEnabledAtariJoystick(int index);static void UpdateJoypads(void);/*--- Functions ---*/int SDL_SYS_JoystickInit(void){	int i;	unsigned long cookie_mch;	const char *envr=SDL_getenv("SDL_JOYSTICK_ATARI");	#define TEST_JOY_ENABLED(env,idstring,num) \	if (SDL_strstr(env,idstring"-off")) { \		atarijoysticks[num].enabled=SDL_FALSE; \	} \	if (SDL_strstr(env,idstring"-on")) { \		atarijoysticks[num].enabled=SDL_TRUE; \	}	/* Cookie _MCH present ? if not, assume ST machine */	if (Getcookie(C__MCH, &cookie_mch) != C_FOUND) {		cookie_mch = MCH_ST << 16;	}	/* Enable some default joysticks */	if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) ||		(cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16) ||		(cookie_mch == MCH_ARANYM<<16)) {		atarijoysticks[IKBD_JOY1].enabled=(SDL_AtariIkbd_enabled!=0);	}	if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) {		atarijoysticks[PORTA_PAD0].enabled = 			atarijoysticks[PORTA_PAD1].enabled =			atarijoysticks[PORTA_PAD2].enabled =			atarijoysticks[PORTA_PAD3].enabled =			atarijoysticks[PORTB_PAD0].enabled =			atarijoysticks[PORTB_PAD1].enabled =			atarijoysticks[PORTB_PAD2].enabled =			atarijoysticks[PORTB_PAD3].enabled = SDL_TRUE;	}	if (!atarijoysticks[IKBD_JOY1].enabled) {		atarijoysticks[XBIOS_JOY1].enabled=(SDL_AtariXbios_enabled!=0);	}	/* Read environment for joysticks to enable */	if (envr) {		/* IKBD on any Atari, maybe clones */		if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) ||			(cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16) ||			(cookie_mch == MCH_ARANYM<<16)) {			if (SDL_AtariIkbd_enabled!=0) {				TEST_JOY_ENABLED(envr, "ikbd-joy1", IKBD_JOY1);			}		}		/* Joypads ports only on STE and Falcon */		if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) {			TEST_JOY_ENABLED(envr, "porta-pad", PORTA_PAD0);			if (!atarijoysticks[PORTA_PAD0].enabled) {				TEST_JOY_ENABLED(envr, "porta-joy0", PORTA_JOY0);				TEST_JOY_ENABLED(envr, "porta-joy1", PORTA_JOY1);				if (!(atarijoysticks[PORTA_JOY0].enabled) && !(atarijoysticks[PORTA_JOY1].enabled)) {					TEST_JOY_ENABLED(envr, "porta-lp", PORTA_LP);					if (!atarijoysticks[PORTA_LP].enabled) {						TEST_JOY_ENABLED(envr, "porta-anpad", PORTA_ANPAD);					}				}			}			TEST_JOY_ENABLED(envr, "portb-pad", PORTB_PAD0);			if (!atarijoysticks[PORTB_PAD0].enabled) {				TEST_JOY_ENABLED(envr, "portb-joy0", PORTB_JOY0);				TEST_JOY_ENABLED(envr, "portb-joy1", PORTB_JOY1);				if (!(atarijoysticks[PORTB_JOY0].enabled) && !(atarijoysticks[PORTB_JOY1].enabled)) {					TEST_JOY_ENABLED(envr, "portb-anpad", PORTB_ANPAD);				}			}		}		if (!atarijoysticks[IKBD_JOY1].enabled) {			if (SDL_AtariXbios_enabled!=0) {				TEST_JOY_ENABLED(envr, "xbios-joy1", XBIOS_JOY1);			}		}#if 0		/* Parallel port on any Atari, maybe clones */		if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) ||			(cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16)) {			TEST_JOY_ENABLED(envr, "para-joy0", PARA_JOY0);			TEST_JOY_ENABLED(envr, "para-joy1", PARA_JOY1);		}#endif	}	/* Need to update joypad ports ? */	joypad_ports_enabled=SDL_FALSE;	for (i=PORTA_PAD0;i<=PORTB_ANPAD;i++) {		if (atarijoysticks[i].enabled) {			joypad_ports_enabled=SDL_TRUE;			break;		}	}	SDL_numjoysticks = 0;	for (i=0;i<MAX_JOYSTICKS;i++) {		if (atarijoysticks[i].enabled) {			++SDL_numjoysticks;		}	}	return(SDL_numjoysticks);}static int GetEnabledAtariJoystick(int index){	int i,j;	/* Return the nth'index' enabled atari joystick */	j=0;	for (i=0;i<MAX_JOYSTICKS;i++) {		if (!atarijoysticks[i].enabled) {			continue;		}		if (j==index) {			break;		}		++j;	}	if (i==MAX_JOYSTICKS)		return -1;	return i;}const char *SDL_SYS_JoystickName(int index){	int numjoystick;	numjoystick=GetEnabledAtariJoystick(index);	if (numjoystick==-1)		return NULL;	return(atarijoysticks[numjoystick].name);}int SDL_SYS_JoystickOpen(SDL_Joystick *joystick){	int numjoystick;		numjoystick=GetEnabledAtariJoystick(joystick->index);	if (numjoystick==-1)		return -1;		joystick->naxes=0;	joystick->nhats=0;	joystick->nballs=0;	switch(numjoystick) {		case PORTA_PAD0:		case PORTA_PAD1:		case PORTA_PAD2:		case PORTA_PAD3:		case PORTB_PAD0:		case PORTB_PAD1:		case PORTB_PAD2:		case PORTB_PAD3:			joystick->nhats=1;			joystick->nbuttons=JP_NUM_BUTTONS;			break;		case PORTA_LP:		case PORTA_ANPAD:		case PORTB_ANPAD:			joystick->naxes=2;			joystick->nbuttons=2;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -