From: Shamus Hammons Date: Wed, 9 Jan 2013 03:56:06 +0000 (-0600) Subject: Initial gamepad support. X-Git-Tag: 2.1.0~8 X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=virtualjaguar;a=commitdiff_plain;h=f63cd569374c4fbcd872bb8a67c94788da29c3a8 Initial gamepad support. --- diff --git a/src/gui/gamepad.cpp b/src/gui/gamepad.cpp new file mode 100644 index 0000000..ba8a551 --- /dev/null +++ b/src/gui/gamepad.cpp @@ -0,0 +1,45 @@ +// +// gamepad.cpp - Host joystick handling (using SDL) +// +// by James Hammons +// (C) 2013 Underground Software +// +// JLH = James Hammons +// +// Who When What +// --- ---------- ------------------------------------------------------------- +// JLH 01/05/2013 Created this file +// + +#include "gamepad.h" + + +bool Gamepad::GetState(int joystickID, int buttonID) +{ + if (buttonID & JOY_BUTTON) + { + // Handle SDL button + } + else if (buttonID & JOY_HAT) + { + // Handle SDL hats + int hatNumber = (buttonID & JOY_HATNUM_MASK) >> 3; + int hatDirection = hatMask[buttonID & JOY_HATBUT_MASK]; + } + + // Default == failure + return false; +} + + +int Gamepad::GetButtonID(void) +{ + // Return single button ID being pressed (if any) +} + + +int Gamepad::GetJoystickID(void) +{ + // Return joystick ID of button being pressed (if any) +} + diff --git a/src/gui/gamepad.h b/src/gui/gamepad.h new file mode 100644 index 0000000..350a913 --- /dev/null +++ b/src/gui/gamepad.h @@ -0,0 +1,39 @@ +// +// gamepad.h: Header file +// +// by James Hammons +// (C) 2013 Underground Software +// + +#ifndef __GAMEPAD_H__ +#define __GAMEPAD_H__ + +#define JOY_BUTTON 0x0100 +#define JOY_HAT 0x0200 + +#define JOY_TYPE_MASK 0xFF00 +#define JOY_HATNUM_MASK 0x00F8 +#define JOY_HATBUT_MASK 0x0007 + +#include + +uint8_t hatMask[8] = { 1, 2, 4, 8, 16, 32, 64, 128 }; + +// buttonID is the combination of the type (BUTTON, HAT) and the button # +// (0-255 for buttons, 0-31 for hats). Hats also have 0-7 for a button # +// that corresponds to a direction. + +class Gamepad +{ +// really should make all methods and members be static so that we can +// call this stuff without instantiating one. :-) + public: + Gamepad(); + ~Gamepad(); + + bool GetState(int joystickID, int buttonID); + int GetButtonID(void); + int GetJoystickID(void); +}; + +#endif // __GAMEPAD_H__ diff --git a/src/jaguar.cpp b/src/jaguar.cpp index 1916304..f930c9a 100644 --- a/src/jaguar.cpp +++ b/src/jaguar.cpp @@ -2007,7 +2007,7 @@ void JaguarExecuteNew(void) // it will be half this number for a half frame. BUT, since we're counting // HALF lines, we double this number and we're back at 525 for NTSC, 625 for PAL. // -// Scanline times are 63.5555... s in NTSC and 64 s in PAL +// Scanline times are 63.5555... μs in NTSC and 64 μs in PAL // Half line times are, naturally, half of this. :-P void HalflineCallback(void) { diff --git a/virtualjaguar.pro b/virtualjaguar.pro index 0c42810..9a66477 100644 --- a/virtualjaguar.pro +++ b/virtualjaguar.pro @@ -67,6 +67,7 @@ HEADERS = \ src/gui/filelistmodel.h \ src/gui/filepicker.h \ src/gui/filethread.h \ + src/gui/gamepad.h \ src/gui/generaltab.h \ src/gui/glwidget.h \ src/gui/help.h \ @@ -89,6 +90,7 @@ SOURCES = \ src/gui/filelistmodel.cpp \ src/gui/filepicker.cpp \ src/gui/filethread.cpp \ + src/gui/gamepad.cpp \ src/gui/generaltab.cpp \ src/gui/glwidget.cpp \ src/gui/help.cpp \