char ControllerWidget::hatName[4][16] = { "Up", "Rt", "Dn", "Lf" };
+char ControllerWidget::axisName[2][8] = { "+", "-" };
+
// This is hard-coded crap. It's crap-tastic!
// These are the positions to draw the button names at, ordered by the BUTTON_* sequence
// found in joystick.h.
DrawBorderedText(painter, buttonPos[i][0], buttonPos[i][1],
QString("j%1").arg(hatName[keys[i] & JOY_BUTTON_MASK]));
}
+ else if (keys[i] & JOY_AXIS)
+ {
+ DrawBorderedText(painter, buttonPos[i][0], buttonPos[i][1],
+ QString("JA%1%2").arg((keys[i] & JOY_AXISNUM_MASK) >> 1).arg(axisName[keys[i] & JOY_AXISDIR_MASK]));
+ }
#endif
else
DrawBorderedText(painter, buttonPos[i][0], buttonPos[i][1], QString("???"));
static char keyName1[96][16];
static char keyName2[64][16];
static char hatName[4][16];
+ static char axisName[2][8];
static int buttonPos[21][2];
};
/*static*/ SDL_Joystick * Gamepad::pad[8];
/*static*/ int Gamepad::numButtons[8];
/*static*/ int Gamepad::numHats[8];
+/*static*/ int Gamepad::numAxes[8];
/*static*/ bool Gamepad::button[8][256];
/*static*/ uint8_t Gamepad::hat[8][32];
+/*static*/ int32_t Gamepad::axis[8][32];
Gamepad::Gamepad(void)//: numJoysticks(0)
{
numButtons[i] = SDL_JoystickNumButtons(pad[i]);
numHats[i] = SDL_JoystickNumHats(pad[i]);
+ numAxes[i] = SDL_JoystickNumAxes(pad[i]);
}
}
uint8_t hatDirection = hatMask[buttonID & JOY_HATBUT_MASK];
return (hat[joystickID][hatNumber] & hatDirection ? true : false);
}
+ else if (buttonID & JOY_AXIS)
+ {
+ int axisNum = (buttonID & JOY_AXISNUM_MASK) >> 1;
+ int direction = (buttonID & JOY_AXISDIR_MASK);
+
+ if (axis[joystickID][axisNum] != 0)
+ {
+ if (axis[joystickID][axisNum] > 0 && (direction == 0))
+ return true;
+
+ if (axis[joystickID][axisNum] < 0 && (direction == 1))
+ return true;
+ }
+ }
// Default == failure
return false;
if (hat[i][j])
return (JOY_HAT | hatNum[hat[i][j]]);
}
+
+ for(int j=0; j<numAxes[i]; j++)
+ {
+ // We encode these as axis # (in bits 1-15), up or down in bit 0.
+// if (axis[i][j] > 0)
+ if (axis[i][j] > 32000)
+ return (JOY_AXIS | (j << 1) | 0);
+
+// if (axis[i][j] < 0)
+ if (axis[i][j] < -32000)
+ return (JOY_AXIS | (j << 1) | 1);
+ }
}
return -1;
for(int j=0; j<numHats[i]; j++)
hat[i][j] = SDL_JoystickGetHat(pad[i], j);
+
+ for(int j=0; j<numAxes[i]; j++)
+ axis[i][j] = SDL_JoystickGetAxis(pad[i], j);
}
}
#define JOY_KEY 0x000000
#define JOY_BUTTON 0x010000
#define JOY_HAT 0x020000
+#define JOY_AXIS 0x040000
-#define JOY_TYPE_MASK 0xFF0000
-#define JOY_BUTTON_MASK 0x00FFFF
-#define JOY_HATNUM_MASK 0x0000F8
-#define JOY_HATBUT_MASK 0x000007
+#define JOY_TYPE_MASK 0xFF0000
+#define JOY_BUTTON_MASK 0x00FFFF
+#define JOY_HATNUM_MASK 0x0000F8
+#define JOY_HATBUT_MASK 0x000007
+#define JOY_AXISNUM_MASK 0x00FFFE
+#define JOY_AXISDIR_MASK 0x000001
#include <stdint.h>
#include "SDL.h"
static int numJoysticks;
static SDL_Joystick * pad[8];
static int numButtons[8];
+ static int numAxes[8];
static int numHats[8];
static bool button[8][256];
static uint8_t hat[8][32];
+ static int32_t axis[8][32];
};
#endif // __GAMEPAD_H__
{
button = Gamepad::CheckButtonPressed();
- if (button == -1)
+ if (button == -1)
return;
buttonDown = true;
// Prevent the scanner from running...
return;
}
-// else
-// memcpy(jagMemSpace + 0xE00000, jaguarBootROM, 0x20000); // Otherwise, use the stock BIOS
// Run the scanner if nothing passed in and *not* Alpine mode...
// NB: Really need to look into caching the info scanned in here...
for(int i=BUTTON_FIRST; i<=BUTTON_LAST; i++)
{
- if (vjs.p1KeyBindings[i] & (JOY_BUTTON | JOY_HAT))
+ if (vjs.p1KeyBindings[i] & (JOY_BUTTON | JOY_HAT | JOY_AXIS))
joypad_0_buttons[i] = (Gamepad::GetState(0, vjs.p1KeyBindings[i]) ? 0x01 : 0x00);
- if (vjs.p2KeyBindings[i] & (JOY_BUTTON | JOY_HAT))
+ if (vjs.p2KeyBindings[i] & (JOY_BUTTON | JOY_HAT | JOY_AXIS))
joypad_1_buttons[i] = (Gamepad::GetState(1, vjs.p2KeyBindings[i]) ? 0x01 : 0x00);
}
}
enum { BT_K_SERIES, BT_M_SERIES, BT_STUBULATOR_1, BT_STUBULATOR_2 };
-// Exported functions
-
-//void LoadVJSettings(void);
-//void SaveVJSettings(void);
-
// Exported variables
extern VJSettings vjs;