]> Shamusworld >> Repos - virtualjaguar/commitdiff
Initial gamepad support.
authorShamus Hammons <jlhamm@acm.org>
Wed, 9 Jan 2013 03:56:06 +0000 (21:56 -0600)
committerShamus Hammons <jlhamm@acm.org>
Thu, 10 Jan 2013 18:18:52 +0000 (12:18 -0600)
src/gui/gamepad.cpp [new file with mode: 0644]
src/gui/gamepad.h [new file with mode: 0644]
src/jaguar.cpp
virtualjaguar.pro

diff --git a/src/gui/gamepad.cpp b/src/gui/gamepad.cpp
new file mode 100644 (file)
index 0000000..ba8a551
--- /dev/null
@@ -0,0 +1,45 @@
+//
+// gamepad.cpp - Host joystick handling (using SDL)
+//
+// by James Hammons
+// (C) 2013 Underground Software
+//
+// JLH = James Hammons <jlhamm@acm.org>
+//
+// 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 (file)
index 0000000..350a913
--- /dev/null
@@ -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 <stdint.h>
+
+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__
index 191630423107e7ac26c74d5adc975c0dadb65842..f930c9a31e5b2a6965457b7dacc3d4956dd10758 100644 (file)
@@ -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... \0s in NTSC and 64 \0s 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)
 {
index 0c42810a1fa81e82f96f0f97b31a8dd5f55d059d..9a66477109fa6f1805e908eab265ba323f074e16 100644 (file)
@@ -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 \