PANDORA: Added options for Mouse as keys
This commit is contained in:
parent
fa238c399d
commit
3c410e687e
|
@ -22,12 +22,6 @@
|
|||
#include <sys/soundcard.h>
|
||||
#endif
|
||||
|
||||
#define JOYSTICK_SDL
|
||||
|
||||
#ifndef JOYSTICK_SDL
|
||||
#include <linux/joystick.h>
|
||||
#endif
|
||||
|
||||
#include <signal.h>
|
||||
#include <execinfo.h>
|
||||
|
||||
|
@ -104,11 +98,7 @@ enum DCPad {
|
|||
|
||||
void emit_WriteCodeCache();
|
||||
|
||||
#ifdef JOYSTICK_SDL
|
||||
static SDL_Joystick *JoySDL = 0;
|
||||
#else
|
||||
static int JoyFD = -1; // Joystick file descriptor
|
||||
#endif
|
||||
|
||||
#ifdef USE_OSS
|
||||
static int audio_fd = -1;
|
||||
|
@ -142,7 +132,6 @@ void SetupInput()
|
|||
lt[port]=0;
|
||||
}
|
||||
|
||||
#ifdef JOYSTICK_SDL
|
||||
// Open joystick device
|
||||
int numjoys = SDL_NumJoysticks();
|
||||
printf("Number of Joysticks found = %i\n", numjoys);
|
||||
|
@ -171,41 +160,20 @@ void SetupInput()
|
|||
printf("Using Xbox 360 map\n");
|
||||
}
|
||||
} else printf("SDK: No Joystick Found\n");
|
||||
#else
|
||||
// Open joystick device
|
||||
JoyFD = open("/dev/input/js0",O_RDONLY);
|
||||
|
||||
SDL_ShowCursor( 0 );
|
||||
if (SDL_WM_GrabInput( SDL_GRAB_ON ) != SDL_GRAB_ON)
|
||||
printf("SDK: Error while grabbing mouse\n");
|
||||
|
||||
if(JoyFD>=0)
|
||||
{
|
||||
int AxisCount,ButtonCount;
|
||||
char Name[128];
|
||||
|
||||
AxisCount = 0;
|
||||
ButtonCount = 0;
|
||||
Name[0] = '\0';
|
||||
|
||||
fcntl(JoyFD,F_SETFL,O_NONBLOCK);
|
||||
ioctl(JoyFD,JSIOCGAXES,&AxisCount);
|
||||
ioctl(JoyFD,JSIOCGBUTTONS,&ButtonCount);
|
||||
ioctl(JoyFD,JSIOCGNAME(sizeof(Name)),&Name);
|
||||
|
||||
printf("SDK: Found '%s' joystick with %d axis and %d buttons\n",Name,AxisCount,ButtonCount);
|
||||
|
||||
if (strcmp(Name,"Microsoft X-Box 360 pad")==0)
|
||||
{
|
||||
JMapBtn=JMapBtn_360;
|
||||
JMapAxis=JMapAxis_360;
|
||||
printf("Using Xbox 360 map\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool HandleEvents(u32 port) {
|
||||
|
||||
static int keys[13];
|
||||
static int mouse_use = 0;
|
||||
SDL_Event event;
|
||||
int k, value;
|
||||
int xx, yy;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_QUIT:
|
||||
|
@ -232,13 +200,13 @@ bool HandleEvents(u32 port) {
|
|||
case SDLK_RSHIFT: keys[11]=value; break;
|
||||
case SDLK_RCTRL: keys[10]=value; break;
|
||||
case SDLK_LALT: keys[12]=value; break;
|
||||
case SDLK_k: KillTex=true; break;
|
||||
case SDLK_k: if (value) KillTex=true; break;
|
||||
case SDLK_n: if (value) mouse_use=(mouse_use+1)%4; printf("Nub mode %i\n", mouse_use); break; //*TODO* Do some feedback on OSD
|
||||
#else
|
||||
#error *TODO*
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
#ifdef JOYSTICK_SDL
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
case SDL_JOYBUTTONUP:
|
||||
value = (event.type==SDL_JOYBUTTONDOWN)?1:0;
|
||||
|
@ -314,7 +282,35 @@ bool HandleEvents(u32 port) {
|
|||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case SDL_MOUSEMOTION:
|
||||
xx = event.motion.xrel;
|
||||
yy = event.motion.yrel;
|
||||
// some caping and dead zone...
|
||||
if (abs(xx)<4) xx = 0;
|
||||
if (abs(yy)<4) yy = 0;
|
||||
xx = xx*255/20; yy = yy*255/20;
|
||||
if (xx>255) xx = 255; if (xx<-255) xx = -255;
|
||||
if (yy>255) yy = 255; if (yy<-255) yy = -255;
|
||||
//if (abs(xx)>0 || abs(yy)>0) printf("mouse %i, %i\n", xx, yy);
|
||||
switch (mouse_use) {
|
||||
case 0: // nothing
|
||||
break;
|
||||
case 1: // Up=RT, Down=LT
|
||||
if (yy<0) rt[port]=-yy;
|
||||
if (yy>0) lt[port]=yy;
|
||||
break;
|
||||
case 2: // Left=LT, Right=RT
|
||||
if (xx<0) lt[port]=-xx;
|
||||
if (xx>0) rt[port]=xx;
|
||||
break;
|
||||
case 3: // Nub = ABXY
|
||||
if (xx<-127) kcode[port] &= ~Btn_X;
|
||||
if (xx>127) kcode[port] &= ~Btn_B;
|
||||
if (yy<-127) kcode[port] &= ~Btn_Y;
|
||||
if (yy>127) kcode[port] &= ~Btn_A;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -344,98 +340,6 @@ bool HandleEvents(u32 port) {
|
|||
return true;
|
||||
}
|
||||
|
||||
#ifndef JOYSTICK_SDL
|
||||
bool HandleJoystick(u32 port)
|
||||
{
|
||||
|
||||
struct js_event JE;
|
||||
|
||||
// Joystick must be connected
|
||||
if(JoyFD<0) return false;
|
||||
|
||||
while(read(JoyFD,&JE,sizeof(JE))==sizeof(JE))
|
||||
if (JE.number<MAP_SIZE)
|
||||
{
|
||||
switch(JE.type & ~JS_EVENT_INIT)
|
||||
{
|
||||
case JS_EVENT_AXIS:
|
||||
{
|
||||
u32 mt=JMapAxis[JE.number]>>16;
|
||||
u32 mo=JMapAxis[JE.number]&0xFFFF;
|
||||
|
||||
//printf("AXIS %d,%d\n",JE.number,JE.value);
|
||||
s8 v=(s8)(JE.value/256); //-127 ... + 127 range
|
||||
|
||||
if (mt==0)
|
||||
{
|
||||
kcode[port]|=mo;
|
||||
kcode[port]|=mo*2;
|
||||
if (v<-64)
|
||||
{
|
||||
kcode[port]&=~mo;
|
||||
}
|
||||
else if (v>64)
|
||||
{
|
||||
kcode[port]&=~(mo*2);
|
||||
}
|
||||
|
||||
// printf("Mapped to %d %d %d\n",mo,kcode[port]&mo,kcode[port]&(mo*2));
|
||||
}
|
||||
else if (mt==1)
|
||||
{
|
||||
if (v>=0) v++; //up to 255
|
||||
|
||||
// printf("AXIS %d,%d Mapped to %d %d %d\n",JE.number,JE.value,mo,v,v+127);
|
||||
|
||||
if (mo==0)
|
||||
lt[port]=v+127;
|
||||
else if (mo==1)
|
||||
rt[port]=v+127;
|
||||
}
|
||||
else if (mt==2)
|
||||
{
|
||||
// printf("AXIS %d,%d Mapped to %d %d [%d]",JE.number,JE.value,mo,v);
|
||||
if (mo==0)
|
||||
joyx[port]=v;
|
||||
else if (mo==1)
|
||||
joyy[port]=v;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case JS_EVENT_BUTTON:
|
||||
{
|
||||
u32 mt=JMapBtn[JE.number]>>16;
|
||||
u32 mo=JMapBtn[JE.number]&0xFFFF;
|
||||
|
||||
// printf("BUTTON %d,%d\n",JE.number,JE.value);
|
||||
|
||||
if (mt==0)
|
||||
{
|
||||
// printf("Mapped to %d\n",mo);
|
||||
if (JE.value)
|
||||
kcode[port]&=~mo;
|
||||
else
|
||||
kcode[port]|=mo;
|
||||
}
|
||||
else if (mt==1)
|
||||
{
|
||||
// printf("Mapped to %d %d\n",mo,JE.value?255:0);
|
||||
if (mo==0)
|
||||
lt[port]=JE.value?255:0;
|
||||
else if (mo==1)
|
||||
rt[port]=JE.value?255:0;
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
void UpdateInputState(u32 port)
|
||||
{
|
||||
static char key = 0;
|
||||
|
@ -445,9 +349,6 @@ void UpdateInputState(u32 port)
|
|||
lt[port]=0;
|
||||
|
||||
HandleEvents(port);
|
||||
#ifndef JOYSTICK_SDL
|
||||
HandleJoystick(port);
|
||||
#endif
|
||||
}
|
||||
|
||||
void os_DoEvents()
|
||||
|
@ -491,11 +392,7 @@ void clean_exit(int sig_num) {
|
|||
size_t size;
|
||||
|
||||
// close files
|
||||
#ifdef JOYSTICK_SDL
|
||||
if (JoySDL) SDL_JoystickClose(JoySDL);
|
||||
#else
|
||||
if (JoyFD>=0) close(JoyFD);
|
||||
#endif
|
||||
#ifdef USE_OSS
|
||||
if (audio_fd>=0) close(audio_fd);
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue