1 /* FCE Ultra - NES/Famicom Emulator
3 * Copyright notice for this file:
4 * Copyright (C) 2002 Ben Parnell
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <linux/joystick.h>
27 #include "lnx-joystick.h"
32 static int32 joybuttons[4]={0,0,0,0};
33 static int32 joyx[4]={0,0,0,0};
34 static int32 joyy[4]={0,0,0,0};
36 static void ConfigJoystick(int z);
46 #define JOY_RIGHT 0x80
48 static void UpdateJoyData(int x)
52 while(read(fd[x],&e,sizeof(struct js_event))==sizeof(struct js_event))
54 e.type&=~JS_EVENT_INIT;
55 if(e.type==JS_EVENT_BUTTON)
58 joybuttons[x]|=(1<<e.number);
60 joybuttons[x]&=~(1<<e.number);
62 else if(e.type==JS_EVENT_AXIS)
85 if(joybuttons[x]&joym[y]) ret|=(1<<y)<<(x<<3);
86 if(joyx[x]<=-16383) ret|=JOY_LEFT<<(x<<3);
87 else if(joyx[x]>=16383) ret|=JOY_RIGHT<<(x<<3);
88 if(joyy[x]<=-16383) ret|=JOY_UP<<(x<<3);
89 else if(joyy[x]>=16383) ret|=JOY_DOWN<<(x<<3);
94 void KillJoysticks(void)
102 int InitJoysticks(void)
110 if(!joy[z]) continue;
111 sprintf(dbuf,"/dev/js%d",joy[z]-1);
112 if((fd[z]=open(dbuf,O_RDONLY|O_NONBLOCK))<0)
114 printf("Could not open %s.\n",dbuf);
119 if(ioctl(fd[z], JSIOCGVERSION, &version)==-1)
121 printf("Error using ioctl JSIOCGVERSION on %s.\n",dbuf);
127 if(!(joyBMap[z][0]|joyBMap[z][1]|joyBMap[z][2]|joyBMap[z][3]))
131 return(joy[0]|joy[1]|joy[2]|joy[3]);
134 #define WNOINPUT(); for(;;){uint8 t; if(read(fileno(stdin),&t,1)==-1) \
137 static void BConfig(int z,int b)
143 if(read(fileno(stdin),&t,1)==-1)
145 if(errno!=EAGAIN) break;
153 while(read(fd[z],&e,sizeof(struct js_event))==sizeof(struct js_event))
155 if(e.type==JS_EVENT_BUTTON)
159 joyBMap[z][b]=1<<e.number;
171 void ConfigJoystick(int z)
174 static char *genb="** Press button for ";
176 printf("\n\n Joystick button configuration:\n\n");
177 printf(" Push the button to map to the virtual joystick.\n");
178 printf(" If you do not wish to assign a button, press Enter to skip\n");
179 printf(" that button.\n\n");
180 printf(" Press enter to continue...\n");
182 printf("**** Configuring joystick %d ****\n\n",z+1);
184 sa=fcntl(fileno(stdin),F_GETFL);
185 fcntl(fileno(stdin),F_SETFL,O_NONBLOCK);
187 printf("%s\"Select\".\n",genb);
190 printf("%s\"Start\".\n",genb);
193 printf("%s\"B\".\n",genb);
196 printf("%s\"A\".\n",genb);
199 fcntl(fileno(stdin),F_SETFL,sa);