Patch for gamepads (e,g, 360) that use hat events for dpad

Gamepad acting up? Keyboard not responding properly? Can't get that other user to work? Read and post about it here.

Moderator: ZSNES Mods

Post Reply
hakonrk
Rookie
Posts: 20
Joined: Sun Jun 19, 2005 9:17 pm

Patch for gamepads (e,g, 360) that use hat events for dpad

Post by hakonrk »

I recently built a custom made controller based on the Xbox 360 controller electronics, and while testing it, I noticed and fixed a bug in ZSNES. The dpad on the 360 controller sends "hat" events, and when assigning these to Up/Down/Left/Right, one has to center the stick after hitting a diagonal to reset the appropriate directions. Ridiculously annoying, but trivial to fix (the below patch is for the latest SVN snapshot):

Code: Select all

--- zsnes/src/linux/sdllink.c.orig	2008-07-27 22:13:02.000000000 +0200
+++ zsnes/src/linux/sdllink.c	2009-02-10 00:50:17.000000000 +0100
@@ -344,6 +344,8 @@
           case SDL_HAT_UP:
             pressed[offset + 3] = 1;
             pressed[offset + 2] = 0;
+            pressed[offset + 1] = 0;
+            pressed[offset + 0] = 0;
             break;
           case SDL_HAT_RIGHTUP:
             pressed[offset] = 1;
@@ -354,6 +356,8 @@
           case SDL_HAT_RIGHT:
             pressed[offset] = 1;
             pressed[offset + 1] = 0;
+            pressed[offset + 2] = 0;
+            pressed[offset + 3] = 0;
             break;
           case SDL_HAT_RIGHTDOWN:
             pressed[offset] = 1;
@@ -363,6 +367,8 @@
             break;
           case SDL_HAT_DOWN:
             pressed[offset + 2] = 1;
+            pressed[offset + 0] = 0;
+            pressed[offset + 1] = 0;
             pressed[offset + 3] = 0;
             break;
           case SDL_HAT_LEFTDOWN:
@@ -374,6 +380,8 @@
           case SDL_HAT_LEFT:
             pressed[offset + 1] = 1;
             pressed[offset] = 0;
+            pressed[offset + 2] = 0;
+            pressed[offset + 3] = 0;
             break;
           case SDL_HAT_LEFTUP:
             pressed[offset + 1] = 1;
Post Reply