mirror of
https://github.com/mupen64plus/mupen64plus-input-sdl.git
synced 2025-04-02 10:52:40 -04:00
Compare commits
No commits in common. "master" and "2.6.0" have entirely different histories.
5 changed files with 257 additions and 14 deletions
24
projects/unix/Makefile
Normal file → Executable file
24
projects/unix/Makefile
Normal file → Executable file
|
@ -96,7 +96,7 @@ OBJDIR = _obj$(POSTFIX)
|
||||||
# base CFLAGS, LDLIBS, and LDFLAGS
|
# base CFLAGS, LDLIBS, and LDFLAGS
|
||||||
OPTFLAGS ?= -O3 -flto
|
OPTFLAGS ?= -O3 -flto
|
||||||
WARNFLAGS ?= -Wall
|
WARNFLAGS ?= -Wall
|
||||||
CFLAGS += $(OPTFLAGS) $(WARNFLAGS) -ffast-math -fvisibility=hidden -I$(SRCDIR) -D_GNU_SOURCE=1
|
CFLAGS += $(OPTFLAGS) $(WARNFLAGS) -ffast-math -fno-strict-aliasing -fvisibility=hidden -I$(SRCDIR) -D_GNU_SOURCE=1
|
||||||
LDFLAGS += $(SHARED)
|
LDFLAGS += $(SHARED)
|
||||||
LDLIBS += -lm
|
LDLIBS += -lm
|
||||||
|
|
||||||
|
@ -147,21 +147,19 @@ ifeq ($(OS), OSX)
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# test for essential build dependencies
|
|
||||||
ifeq ($(origin PKG_CONFIG), undefined)
|
|
||||||
PKG_CONFIG = $(CROSS_COMPILE)pkg-config
|
|
||||||
ifeq ($(shell which $(PKG_CONFIG) 2>/dev/null),)
|
|
||||||
$(error $(PKG_CONFIG) not found)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
# test for presence of SDL
|
# test for presence of SDL
|
||||||
ifeq ($(origin SDL_CFLAGS) $(origin SDL_LDLIBS), undefined undefined)
|
ifeq ($(origin SDL_CFLAGS) $(origin SDL_LDLIBS), undefined undefined)
|
||||||
ifeq ($(shell $(PKG_CONFIG) --modversion sdl2 2>/dev/null),)
|
SDL_CONFIG = $(CROSS_COMPILE)sdl2-config
|
||||||
$(error No SDL2 development libraries found!)
|
ifeq ($(shell which $(SDL_CONFIG) 2>/dev/null),)
|
||||||
|
SDL_CONFIG = $(CROSS_COMPILE)sdl-config
|
||||||
|
ifeq ($(shell which $(SDL_CONFIG) 2>/dev/null),)
|
||||||
|
$(error No SDL development libraries found!)
|
||||||
|
else
|
||||||
|
$(warning Using SDL 1.2 libraries)
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
SDL_CFLAGS += $(shell $(PKG_CONFIG) --cflags sdl2)
|
SDL_CFLAGS += $(shell $(SDL_CONFIG) --cflags)
|
||||||
SDL_LDLIBS += $(shell $(PKG_CONFIG) --libs sdl2)
|
SDL_LDLIBS += $(shell $(SDL_CONFIG) --libs)
|
||||||
endif
|
endif
|
||||||
CFLAGS += $(SDL_CFLAGS)
|
CFLAGS += $(SDL_CFLAGS)
|
||||||
LDLIBS += $(SDL_LDLIBS)
|
LDLIBS += $(SDL_LDLIBS)
|
||||||
|
|
|
@ -148,10 +148,12 @@ static int auto_compare_name(const char *joySDLName, char *line)
|
||||||
wordPtr = StripSpace(wordPtr + 6);
|
wordPtr = StripSpace(wordPtr + 6);
|
||||||
joyFoundScore = 1;
|
joyFoundScore = 1;
|
||||||
}
|
}
|
||||||
|
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||||
else if (strncmp(wordPtr, "XInput:", 7) == 0) {
|
else if (strncmp(wordPtr, "XInput:", 7) == 0) {
|
||||||
wordPtr = StripSpace(wordPtr + 7);
|
wordPtr = StripSpace(wordPtr + 7);
|
||||||
joyFoundScore = 2;
|
joyFoundScore = 2;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
/* extra points if the section name is a perfect match */
|
/* extra points if the section name is a perfect match */
|
||||||
if (strcmp(wordPtr, joySDLName) == 0)
|
if (strcmp(wordPtr, joySDLName) == 0)
|
||||||
|
|
208
src/plugin.c
208
src/plugin.c
|
@ -111,6 +111,12 @@ static int romopen = 0; // is a rom opened
|
||||||
|
|
||||||
static unsigned char myKeyState[SDL_NUM_SCANCODES];
|
static unsigned char myKeyState[SDL_NUM_SCANCODES];
|
||||||
|
|
||||||
|
#if __linux__ && !SDL_VERSION_ATLEAST(2,0,0)
|
||||||
|
static struct ff_effect ffeffect[4];
|
||||||
|
static struct ff_effect ffstrong[4];
|
||||||
|
static struct ff_effect ffweak[4];
|
||||||
|
#endif //__linux__
|
||||||
|
|
||||||
/* Global functions */
|
/* Global functions */
|
||||||
void DebugMessage(int level, const char *message, ...)
|
void DebugMessage(int level, const char *message, ...)
|
||||||
{
|
{
|
||||||
|
@ -316,7 +322,11 @@ doSdlKeys(const unsigned char* keystate)
|
||||||
grabtoggled = 1;
|
grabtoggled = 1;
|
||||||
grabmouse = !grabmouse;
|
grabmouse = !grabmouse;
|
||||||
// grab/ungrab mouse
|
// grab/ungrab mouse
|
||||||
|
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||||
SDL_SetRelativeMouseMode(grabmouse ? SDL_TRUE : SDL_FALSE);
|
SDL_SetRelativeMouseMode(grabmouse ? SDL_TRUE : SDL_FALSE);
|
||||||
|
#else
|
||||||
|
SDL_WM_GrabInput( grabmouse ? SDL_GRAB_ON : SDL_GRAB_OFF );
|
||||||
|
#endif
|
||||||
SDL_ShowCursor( grabmouse ? 0 : 1 );
|
SDL_ShowCursor( grabmouse ? 0 : 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -409,6 +419,7 @@ EXPORT void CALL ControllerCommand(int Control, unsigned char *Command)
|
||||||
unsigned int dwAddress = (Command[3] << 8) + (Command[4] & 0xE0);
|
unsigned int dwAddress = (Command[3] << 8) + (Command[4] & 0xE0);
|
||||||
if (dwAddress == PAK_IO_RUMBLE && *Data)
|
if (dwAddress == PAK_IO_RUMBLE && *Data)
|
||||||
DebugMessage(M64MSG_VERBOSE, "Triggering rumble pack.");
|
DebugMessage(M64MSG_VERBOSE, "Triggering rumble pack.");
|
||||||
|
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||||
if(dwAddress == PAK_IO_RUMBLE && controller[Control].event_joystick) {
|
if(dwAddress == PAK_IO_RUMBLE && controller[Control].event_joystick) {
|
||||||
#if SDL_VERSION_ATLEAST(2,0,18)
|
#if SDL_VERSION_ATLEAST(2,0,18)
|
||||||
if (*Data) {
|
if (*Data) {
|
||||||
|
@ -424,6 +435,31 @@ EXPORT void CALL ControllerCommand(int Control, unsigned char *Command)
|
||||||
}
|
}
|
||||||
#endif /* SDL_VERSION_ATLEAST(2,0,18) */
|
#endif /* SDL_VERSION_ATLEAST(2,0,18) */
|
||||||
}
|
}
|
||||||
|
#elif __linux__
|
||||||
|
struct input_event play;
|
||||||
|
if( dwAddress == PAK_IO_RUMBLE && controller[Control].event_joystick != 0)
|
||||||
|
{
|
||||||
|
if( *Data )
|
||||||
|
{
|
||||||
|
play.type = EV_FF;
|
||||||
|
play.code = ffeffect[Control].id;
|
||||||
|
play.value = 1;
|
||||||
|
|
||||||
|
if (write(controller[Control].event_joystick, (const void*) &play, sizeof(play)) == -1)
|
||||||
|
perror("Error starting rumble effect");
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
play.type = EV_FF;
|
||||||
|
play.code = ffeffect[Control].id;
|
||||||
|
play.value = 0;
|
||||||
|
|
||||||
|
if (write(controller[Control].event_joystick, (const void*) &play, sizeof(play)) == -1)
|
||||||
|
perror("Error stopping rumble effect");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif //__linux__
|
||||||
Data[32] = DataCRC( Data, 32 );
|
Data[32] = DataCRC( Data, 32 );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -478,7 +514,11 @@ EXPORT void CALL GetKeys( int Control, BUTTONS *Keys )
|
||||||
{
|
{
|
||||||
if (controller[b].device >= 0)
|
if (controller[b].device >= 0)
|
||||||
{
|
{
|
||||||
|
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||||
if (!SDL_JoystickGetAttached(controller[b].joystick))
|
if (!SDL_JoystickGetAttached(controller[b].joystick))
|
||||||
|
#else
|
||||||
|
if (!SDL_JoystickOpened(controller[b].device))
|
||||||
|
#endif
|
||||||
controller[b].joystick = SDL_JoystickOpen(controller[b].device);
|
controller[b].joystick = SDL_JoystickOpen(controller[b].device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -586,12 +626,22 @@ EXPORT void CALL GetKeys( int Control, BUTTONS *Keys )
|
||||||
|
|
||||||
if (controller[Control].mouse)
|
if (controller[Control].mouse)
|
||||||
{
|
{
|
||||||
|
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||||
if (SDL_GetRelativeMouseMode())
|
if (SDL_GetRelativeMouseMode())
|
||||||
|
#else
|
||||||
|
if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
|
#if SDL_VERSION_ATLEAST(1,3,0)
|
||||||
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_MOUSEMOTION, SDL_MOUSEMOTION) == 1)
|
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_MOUSEMOTION, SDL_MOUSEMOTION) == 1)
|
||||||
|
#else
|
||||||
|
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_EVENTMASK(SDL_MOUSEMOTION)) == 1)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
|
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||||
int w, h;
|
int w, h;
|
||||||
SDL_Window *focus;
|
SDL_Window *focus;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (event.motion.xrel)
|
if (event.motion.xrel)
|
||||||
{
|
{
|
||||||
|
@ -602,6 +652,7 @@ EXPORT void CALL GetKeys( int Control, BUTTONS *Keys )
|
||||||
mousey_residual += (int) (event.motion.yrel * controller[Control].mouse_sens[1]);
|
mousey_residual += (int) (event.motion.yrel * controller[Control].mouse_sens[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||||
focus = SDL_GetKeyboardFocus();
|
focus = SDL_GetKeyboardFocus();
|
||||||
if (focus) {
|
if (focus) {
|
||||||
SDL_GetWindowSize(focus, &w, &h);
|
SDL_GetWindowSize(focus, &w, &h);
|
||||||
|
@ -610,6 +661,7 @@ EXPORT void CALL GetKeys( int Control, BUTTONS *Keys )
|
||||||
mousex_residual = 0;
|
mousex_residual = 0;
|
||||||
mousey_residual = 0;
|
mousey_residual = 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* store the result */
|
/* store the result */
|
||||||
|
@ -642,6 +694,7 @@ EXPORT void CALL GetKeys( int Control, BUTTONS *Keys )
|
||||||
*Keys = controller[Control].buttons;
|
*Keys = controller[Control].buttons;
|
||||||
|
|
||||||
/* handle mempack / rumblepak switching (only if rumble is active on joystick) */
|
/* handle mempack / rumblepak switching (only if rumble is active on joystick) */
|
||||||
|
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||||
#if !SDL_VERSION_ATLEAST(2,0,18)
|
#if !SDL_VERSION_ATLEAST(2,0,18)
|
||||||
if (controller[Control].event_joystick) {
|
if (controller[Control].event_joystick) {
|
||||||
static unsigned int SwitchPackTime[4] = {0, 0, 0, 0}, SwitchPackType[4] = {0, 0, 0, 0};
|
static unsigned int SwitchPackTime[4] = {0, 0, 0, 0}, SwitchPackType[4] = {0, 0, 0, 0};
|
||||||
|
@ -666,6 +719,42 @@ EXPORT void CALL GetKeys( int Control, BUTTONS *Keys )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* SDL_VERSION_ATLEAST(2,0,18) */
|
#endif /* SDL_VERSION_ATLEAST(2,0,18) */
|
||||||
|
#elif __linux__
|
||||||
|
if (controller[Control].event_joystick != 0)
|
||||||
|
{
|
||||||
|
struct input_event play;
|
||||||
|
static unsigned int SwitchPackTime[4] = {0, 0, 0, 0}, SwitchPackType[4] = {0, 0, 0, 0};
|
||||||
|
// when the user switches packs, we should mimick the act of removing 1 pack, and then inserting another 1 second later
|
||||||
|
if (controller[Control].buttons.Value & button_bits[14])
|
||||||
|
{
|
||||||
|
SwitchPackTime[Control] = SDL_GetTicks(); // time at which the 'switch pack' command was given
|
||||||
|
SwitchPackType[Control] = PLUGIN_MEMPAK; // type of new pack to insert
|
||||||
|
controller[Control].control->Plugin = PLUGIN_NONE;// remove old pack
|
||||||
|
play.type = EV_FF;
|
||||||
|
play.code = ffweak[Control].id;
|
||||||
|
play.value = 1;
|
||||||
|
if (write(controller[Control].event_joystick, (const void*) &play, sizeof(play)) == -1)
|
||||||
|
perror("Error starting rumble effect");
|
||||||
|
}
|
||||||
|
if (controller[Control].buttons.Value & button_bits[15])
|
||||||
|
{
|
||||||
|
SwitchPackTime[Control] = SDL_GetTicks(); // time at which the 'switch pack' command was given
|
||||||
|
SwitchPackType[Control] = PLUGIN_RAW; // type of new pack to insert
|
||||||
|
controller[Control].control->Plugin = PLUGIN_NONE;// remove old pack
|
||||||
|
play.type = EV_FF;
|
||||||
|
play.code = ffstrong[Control].id;
|
||||||
|
play.value = 1;
|
||||||
|
if (write(controller[Control].event_joystick, (const void*) &play, sizeof(play)) == -1)
|
||||||
|
perror("Error starting rumble effect");
|
||||||
|
}
|
||||||
|
// handle inserting new pack if the time has arrived
|
||||||
|
if (SwitchPackTime[Control] != 0 && (SDL_GetTicks() - SwitchPackTime[Control]) >= 1000)
|
||||||
|
{
|
||||||
|
controller[Control].control->Plugin = SwitchPackType[Control];
|
||||||
|
SwitchPackTime[Control] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* __linux__ */
|
||||||
|
|
||||||
controller[Control].buttons.Value = 0;
|
controller[Control].buttons.Value = 0;
|
||||||
}
|
}
|
||||||
|
@ -683,14 +772,17 @@ static void InitiateJoysticks(int cntrl)
|
||||||
|
|
||||||
static void DeinitJoystick(int cntrl)
|
static void DeinitJoystick(int cntrl)
|
||||||
{
|
{
|
||||||
|
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||||
if (controller[cntrl].joystick) {
|
if (controller[cntrl].joystick) {
|
||||||
SDL_JoystickClose(controller[cntrl].joystick);
|
SDL_JoystickClose(controller[cntrl].joystick);
|
||||||
controller[cntrl].joystick = NULL;
|
controller[cntrl].joystick = NULL;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void InitiateRumble(int cntrl)
|
static void InitiateRumble(int cntrl)
|
||||||
{
|
{
|
||||||
|
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||||
l_hapticWasInit = SDL_WasInit(SDL_INIT_HAPTIC);
|
l_hapticWasInit = SDL_WasInit(SDL_INIT_HAPTIC);
|
||||||
if (!l_hapticWasInit) {
|
if (!l_hapticWasInit) {
|
||||||
if (SDL_InitSubSystem(SDL_INIT_HAPTIC) == -1) {
|
if (SDL_InitSubSystem(SDL_INIT_HAPTIC) == -1) {
|
||||||
|
@ -730,10 +822,113 @@ static void InitiateRumble(int cntrl)
|
||||||
#endif /* SDL_VERSION_ATLEAST(2,0,18) */
|
#endif /* SDL_VERSION_ATLEAST(2,0,18) */
|
||||||
|
|
||||||
DebugMessage(M64MSG_INFO, "Rumble activated on N64 joystick #%i", cntrl + 1);
|
DebugMessage(M64MSG_INFO, "Rumble activated on N64 joystick #%i", cntrl + 1);
|
||||||
|
#elif __linux__
|
||||||
|
DIR* dp;
|
||||||
|
struct dirent* ep;
|
||||||
|
unsigned long features[4];
|
||||||
|
char temp[128];
|
||||||
|
char temp2[128];
|
||||||
|
int iFound = 0;
|
||||||
|
|
||||||
|
controller[cntrl].event_joystick = 0;
|
||||||
|
|
||||||
|
sprintf(temp,"/sys/class/input/js%d/device", controller[cntrl].device);
|
||||||
|
dp = opendir(temp);
|
||||||
|
|
||||||
|
if(dp==NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
while ((ep=readdir(dp)))
|
||||||
|
{
|
||||||
|
if (strncmp(ep->d_name, "event",5)==0)
|
||||||
|
{
|
||||||
|
sprintf(temp, "/dev/input/%s", ep->d_name);
|
||||||
|
iFound = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if(strncmp(ep->d_name,"input:event", 11)==0)
|
||||||
|
{
|
||||||
|
sscanf(ep->d_name, "input:%s", temp2);
|
||||||
|
sprintf(temp, "/dev/input/%s", temp2);
|
||||||
|
iFound = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if(strncmp(ep->d_name,"input:input", 11)==0)
|
||||||
|
{
|
||||||
|
strcat(temp, "/");
|
||||||
|
strcat(temp, ep->d_name);
|
||||||
|
closedir (dp);
|
||||||
|
dp = opendir(temp);
|
||||||
|
if(dp==NULL)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(dp);
|
||||||
|
|
||||||
|
if (!iFound)
|
||||||
|
{
|
||||||
|
DebugMessage(M64MSG_WARNING, "Couldn't find input event for rumble support.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
controller[cntrl].event_joystick = open(temp, O_RDWR);
|
||||||
|
if(controller[cntrl].event_joystick==-1)
|
||||||
|
{
|
||||||
|
DebugMessage(M64MSG_WARNING, "Couldn't open device file '%s' for rumble support.", temp);
|
||||||
|
controller[cntrl].event_joystick = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ioctl(controller[cntrl].event_joystick, EVIOCGBIT(EV_FF, sizeof(unsigned long) * 4), features)==-1)
|
||||||
|
{
|
||||||
|
DebugMessage(M64MSG_WARNING, "Linux kernel communication failed for force feedback (rumble).\n");
|
||||||
|
controller[cntrl].event_joystick = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!test_bit(FF_RUMBLE, features))
|
||||||
|
{
|
||||||
|
DebugMessage(M64MSG_WARNING, "No rumble supported on N64 joystick #%i", cntrl + 1);
|
||||||
|
controller[cntrl].event_joystick = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ffeffect[cntrl].type = FF_RUMBLE;
|
||||||
|
ffeffect[cntrl].id = -1;
|
||||||
|
ffeffect[cntrl].u.rumble.strong_magnitude = 0xFFFF;
|
||||||
|
ffeffect[cntrl].u.rumble.weak_magnitude = 0xFFFF;
|
||||||
|
ffeffect[cntrl].replay.length = 0x7fff; // hack: xboxdrv is buggy and doesn't support infinite replay.
|
||||||
|
// when xboxdrv is fixed (https://github.com/Grumbel/xboxdrv/issues/47),
|
||||||
|
// please remove this
|
||||||
|
|
||||||
|
ioctl(controller[cntrl].event_joystick, EVIOCSFF, &ffeffect[cntrl]);
|
||||||
|
|
||||||
|
ffstrong[cntrl].type = FF_RUMBLE;
|
||||||
|
ffstrong[cntrl].id = -1;
|
||||||
|
ffstrong[cntrl].u.rumble.strong_magnitude = 0xFFFF;
|
||||||
|
ffstrong[cntrl].u.rumble.weak_magnitude = 0x0000;
|
||||||
|
ffstrong[cntrl].replay.length = 500;
|
||||||
|
ffstrong[cntrl].replay.delay = 0;
|
||||||
|
|
||||||
|
ioctl(controller[cntrl].event_joystick, EVIOCSFF, &ffstrong[cntrl]);
|
||||||
|
|
||||||
|
ffweak[cntrl].type = FF_RUMBLE;
|
||||||
|
ffweak[cntrl].id = -1;
|
||||||
|
ffweak[cntrl].u.rumble.strong_magnitude = 0x0000;
|
||||||
|
ffweak[cntrl].u.rumble.weak_magnitude = 0xFFFF;
|
||||||
|
ffweak[cntrl].replay.length = 500;
|
||||||
|
ffweak[cntrl].replay.delay = 0;
|
||||||
|
|
||||||
|
ioctl(controller[cntrl].event_joystick, EVIOCSFF, &ffweak[cntrl]);
|
||||||
|
|
||||||
|
DebugMessage(M64MSG_INFO, "Rumble activated on N64 joystick #%i", cntrl + 1);
|
||||||
|
#endif /* __linux__ */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DeinitRumble(int cntrl)
|
static void DeinitRumble(int cntrl)
|
||||||
{
|
{
|
||||||
|
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||||
/* quit the haptic subsystem if necessary */
|
/* quit the haptic subsystem if necessary */
|
||||||
if (!l_hapticWasInit)
|
if (!l_hapticWasInit)
|
||||||
SDL_QuitSubSystem(SDL_INIT_HAPTIC);
|
SDL_QuitSubSystem(SDL_INIT_HAPTIC);
|
||||||
|
@ -744,6 +939,8 @@ static void DeinitRumble(int cntrl)
|
||||||
controller[cntrl].event_joystick = NULL;
|
controller[cntrl].event_joystick = NULL;
|
||||||
}
|
}
|
||||||
#endif /* !SDL_VERSION_ATLEAST(2,0,18) */
|
#endif /* !SDL_VERSION_ATLEAST(2,0,18) */
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************
|
/******************************************************************
|
||||||
|
@ -825,7 +1022,11 @@ EXPORT void CALL RomClosed(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// release/ungrab mouse
|
// release/ungrab mouse
|
||||||
|
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||||
SDL_SetRelativeMouseMode(SDL_FALSE);
|
SDL_SetRelativeMouseMode(SDL_FALSE);
|
||||||
|
#else
|
||||||
|
SDL_WM_GrabInput( SDL_GRAB_OFF );
|
||||||
|
#endif
|
||||||
SDL_ShowCursor( 1 );
|
SDL_ShowCursor( 1 );
|
||||||
|
|
||||||
romopen = 0;
|
romopen = 0;
|
||||||
|
@ -852,9 +1053,16 @@ EXPORT int CALL RomOpen(void)
|
||||||
if (controller[0].mouse || controller[1].mouse || controller[2].mouse || controller[3].mouse)
|
if (controller[0].mouse || controller[1].mouse || controller[2].mouse || controller[3].mouse)
|
||||||
{
|
{
|
||||||
SDL_ShowCursor( 0 );
|
SDL_ShowCursor( 0 );
|
||||||
|
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||||
if (SDL_SetRelativeMouseMode(SDL_TRUE) < 0) {
|
if (SDL_SetRelativeMouseMode(SDL_TRUE) < 0) {
|
||||||
DebugMessage(M64MSG_WARNING, "Couldn't grab input! Mouse support won't work!");
|
DebugMessage(M64MSG_WARNING, "Couldn't grab input! Mouse support won't work!");
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
if (SDL_WM_GrabInput( SDL_GRAB_ON ) != SDL_GRAB_ON)
|
||||||
|
{
|
||||||
|
DebugMessage(M64MSG_WARNING, "Couldn't grab input! Mouse support won't work!");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
romopen = 1;
|
romopen = 1;
|
||||||
|
|
21
src/plugin.h
21
src/plugin.h
|
@ -32,6 +32,21 @@
|
||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#if ! SDL_VERSION_ATLEAST(1,3,0)
|
||||||
|
|
||||||
|
#define SDL_GetKeyboardState SDL_GetKeyState
|
||||||
|
#define SDL_SCANCODE_UNKNOWN SDLK_UNKNOWN
|
||||||
|
#define SDL_NUM_SCANCODES SDLK_LAST
|
||||||
|
#define SDL_SCANCODE_RCTRL SDLK_RCTRL
|
||||||
|
#define SDL_SCANCODE_RSHIFT SDLK_RSHIFT
|
||||||
|
#define SDL_SCANCODE_LCTRL SDLK_LCTRL
|
||||||
|
#define SDL_SCANCODE_LALT SDLK_LALT
|
||||||
|
#define SDL_SCANCODE_LGUI SDLK_LSUPER
|
||||||
|
#define SDL_Scancode SDLKey
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if SDL_VERSION_ATLEAST(2,0,0)
|
||||||
|
|
||||||
static inline const char* _SDL_JoystickName(int device_index)
|
static inline const char* _SDL_JoystickName(int device_index)
|
||||||
{
|
{
|
||||||
|
@ -56,6 +71,8 @@ static inline const char* _SDL_JoystickName(int device_index)
|
||||||
|
|
||||||
#define SDL_JoystickName(device_index) _SDL_JoystickName(device_index)
|
#define SDL_JoystickName(device_index) _SDL_JoystickName(device_index)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#define M64P_PLUGIN_PROTOTYPES 1
|
#define M64P_PLUGIN_PROTOTYPES 1
|
||||||
#include "m64p_config.h"
|
#include "m64p_config.h"
|
||||||
#include "m64p_plugin.h"
|
#include "m64p_plugin.h"
|
||||||
|
@ -128,8 +145,10 @@ typedef struct
|
||||||
SDL_Joystick *joystick; // SDL joystick device
|
SDL_Joystick *joystick; // SDL joystick device
|
||||||
#if SDL_VERSION_ATLEAST(2,0,18)
|
#if SDL_VERSION_ATLEAST(2,0,18)
|
||||||
int event_joystick; // if sdl device has rumble support
|
int event_joystick; // if sdl device has rumble support
|
||||||
#else /* SDL_VERSION_ATLEAST(2,0,0) */
|
#elif SDL_VERSION_ATLEAST(2,0,0)
|
||||||
SDL_Haptic *event_joystick; // the sdl device for force feeback
|
SDL_Haptic *event_joystick; // the sdl device for force feeback
|
||||||
|
#else
|
||||||
|
int event_joystick; // the /dev/input/eventX device for force feeback
|
||||||
#endif
|
#endif
|
||||||
int axis_deadzone[2]; // minimum absolute value before analog movement is recognized
|
int axis_deadzone[2]; // minimum absolute value before analog movement is recognized
|
||||||
int axis_peak[2]; // highest analog value returned by SDL, used for scaling
|
int axis_peak[2]; // highest analog value returned by SDL, used for scaling
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
uint16_t sdl_keysym2scancode(uint16_t keysym);
|
uint16_t sdl_keysym2scancode(uint16_t keysym);
|
||||||
uint16_t sdl_scancode2keysym(uint16_t scancode);
|
uint16_t sdl_scancode2keysym(uint16_t scancode);
|
||||||
|
|
||||||
|
#if SDL_VERSION_ATLEAST(1,3,0)
|
||||||
|
|
||||||
static osal_inline uint16_t sdl_keysym2native(uint16_t keysym)
|
static osal_inline uint16_t sdl_keysym2native(uint16_t keysym)
|
||||||
{
|
{
|
||||||
return sdl_keysym2scancode(keysym);
|
return sdl_keysym2scancode(keysym);
|
||||||
|
@ -36,3 +38,17 @@ static osal_inline uint16_t sdl_native2keysym(uint16_t native)
|
||||||
{
|
{
|
||||||
return sdl_scancode2keysym(native);
|
return sdl_scancode2keysym(native);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
static osal_inline uint16_t sdl_keysym2native(uint16_t keysym)
|
||||||
|
{
|
||||||
|
return keysym;
|
||||||
|
}
|
||||||
|
|
||||||
|
static osal_inline uint16_t sdl_native2keysym(uint16_t native)
|
||||||
|
{
|
||||||
|
return native;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue