aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/frontend/qt_sdl/Input.cpp124
-rw-r--r--src/frontend/qt_sdl/Input.h7
-rw-r--r--src/frontend/qt_sdl/main.cpp14
-rw-r--r--src/frontend/qt_sdl/main.h1
4 files changed, 142 insertions, 4 deletions
diff --git a/src/frontend/qt_sdl/Input.cpp b/src/frontend/qt_sdl/Input.cpp
index 7caf24a..d60271c 100644
--- a/src/frontend/qt_sdl/Input.cpp
+++ b/src/frontend/qt_sdl/Input.cpp
@@ -34,6 +34,21 @@ u32 KeyHotkeyMask, JoyHotkeyMask;
u32 HotkeyMask, LastHotkeyMask;
u32 HotkeyPress, HotkeyRelease;
+u32 InputMask;
+
+
+void Init()
+{
+ KeyInputMask = 0xFFF;
+ JoyInputMask = 0xFFF;
+ InputMask = 0xFFF;
+
+ KeyHotkeyMask = 0;
+ JoyHotkeyMask = 0;
+ HotkeyMask = 0;
+ LastHotkeyMask = 0;
+}
+
void OpenJoystick()
{
@@ -62,6 +77,109 @@ void CloseJoystick()
}
+int GetEventKeyVal(QKeyEvent* event)
+{
+ int key = event->key();
+ int mod = event->modifiers();
+ bool ismod = (key == Qt::Key_Control ||
+ key == Qt::Key_Alt ||
+ key == Qt::Key_AltGr ||
+ key == Qt::Key_Shift ||
+ key == Qt::Key_Meta);
+
+ if (!ismod)
+ key |= mod;
+ else if (Input::IsRightModKey(event))
+ key |= (1<<31);
+
+ return key;
+}
+
+void KeyPress(QKeyEvent* event)
+{
+ int keyHK = GetEventKeyVal(event);
+ int keyKP = keyHK & ~event->modifiers();
+
+ for (int i = 0; i < 12; i++)
+ if (keyKP == Config::KeyMapping[i])
+ KeyInputMask &= ~(1<<i);
+
+ for (int i = 0; i < HK_MAX; i++)
+ if (keyHK == Config::HKKeyMapping[i])
+ KeyHotkeyMask |= (1<<i);
+}
+
+void KeyRelease(QKeyEvent* event)
+{
+ int keyHK = GetEventKeyVal(event);
+ int keyKP = keyHK & ~event->modifiers();
+
+ for (int i = 0; i < 12; i++)
+ if (keyKP == Config::KeyMapping[i])
+ KeyInputMask |= (1<<i);
+
+ for (int i = 0; i < HK_MAX; i++)
+ if (keyHK == Config::HKKeyMapping[i])
+ KeyHotkeyMask &= ~(1<<i);
+}
+
+
+bool JoystickButtonDown(int val)
+{
+ if (val == -1) return false;
+
+ bool hasbtn = ((val & 0xFFFF) != 0xFFFF);
+
+ if (hasbtn)
+ {
+ if (val & 0x100)
+ {
+ int hatnum = (val >> 4) & 0xF;
+ int hatdir = val & 0xF;
+ Uint8 hatval = SDL_JoystickGetHat(Joystick, hatnum);
+
+ bool pressed = false;
+ if (hatdir == 0x1) pressed = (hatval & SDL_HAT_UP);
+ else if (hatdir == 0x4) pressed = (hatval & SDL_HAT_DOWN);
+ else if (hatdir == 0x2) pressed = (hatval & SDL_HAT_RIGHT);
+ else if (hatdir == 0x8) pressed = (hatval & SDL_HAT_LEFT);
+
+ if (pressed) return true;
+ }
+ else
+ {
+ int btnnum = val & 0xFFFF;
+ Uint8 btnval = SDL_JoystickGetButton(Joystick, btnnum);
+
+ if (btnval) return true;
+ }
+ }
+
+ if (val & 0x10000)
+ {
+ int axisnum = (val >> 24) & 0xF;
+ int axisdir = (val >> 20) & 0xF;
+ Sint16 axisval = SDL_JoystickGetAxis(Joystick, axisnum);
+
+ switch (axisdir)
+ {
+ case 0: // positive
+ if (axisval > 16384) return true;
+ break;
+
+ case 1: // negative
+ if (axisval < -16384) return true;
+ break;
+
+ case 2: // trigger
+ if (axisval > 0) return true;
+ break;
+ }
+ }
+
+ return false;
+}
+
void Process()
{
SDL_JoystickUpdate();
@@ -80,11 +198,13 @@ void Process()
OpenJoystick();
}
- /*JoyInputMask = 0xFFF;
+ JoyInputMask = 0xFFF;
for (int i = 0; i < 12; i++)
if (JoystickButtonDown(Config::JoyMapping[i]))
JoyInputMask &= ~(1<<i);
+ InputMask = KeyInputMask & JoyInputMask;
+
JoyHotkeyMask = 0;
for (int i = 0; i < HK_MAX; i++)
if (JoystickButtonDown(Config::HKJoyMapping[i]))
@@ -93,7 +213,7 @@ void Process()
HotkeyMask = KeyHotkeyMask | JoyHotkeyMask;
HotkeyPress = HotkeyMask & ~LastHotkeyMask;
HotkeyRelease = LastHotkeyMask & ~HotkeyMask;
- LastHotkeyMask = HotkeyMask;*/
+ LastHotkeyMask = HotkeyMask;
}
diff --git a/src/frontend/qt_sdl/Input.h b/src/frontend/qt_sdl/Input.h
index 24ec3a7..57b5a4a 100644
--- a/src/frontend/qt_sdl/Input.h
+++ b/src/frontend/qt_sdl/Input.h
@@ -27,10 +27,17 @@ namespace Input
extern int JoystickID;
extern SDL_Joystick* Joystick;
+extern u32 InputMask;
+
+void Init();
+
// set joystickID before calling openJoystick()
void OpenJoystick();
void CloseJoystick();
+void KeyPress(QKeyEvent* event);
+void KeyRelease(QKeyEvent* event);
+
void Process();
bool IsRightModKey(QKeyEvent* event);
diff --git a/src/frontend/qt_sdl/main.cpp b/src/frontend/qt_sdl/main.cpp
index a68f933..962fdaf 100644
--- a/src/frontend/qt_sdl/main.cpp
+++ b/src/frontend/qt_sdl/main.cpp
@@ -135,6 +135,7 @@ void EmuThread::run()
GPU3D::InitRenderer(false);
}
+ Input::Init();
/*Touching = false;
LidStatus = false;*/
@@ -184,7 +185,7 @@ void EmuThread::run()
EmuStatus = 1;
// process input and hotkeys
- NDS::SetKeyMask(0xFFF);
+ NDS::SetKeyMask(Input::InputMask);
/*NDS::SetKeyMask(KeyInputMask & JoyInputMask);
if (HotkeyPressed(HK_Lid))
@@ -565,7 +566,16 @@ MainWindow::~MainWindow()
void MainWindow::keyPressEvent(QKeyEvent* event)
{
- printf("key press. %d %d %08X %08X\n", event->key(), event->nativeScanCode(), event->modifiers(), event->nativeModifiers());
+ if (event->isAutoRepeat()) return;
+
+ Input::KeyPress(event);
+}
+
+void MainWindow::keyReleaseEvent(QKeyEvent* event)
+{
+ if (event->isAutoRepeat()) return;
+
+ Input::KeyRelease(event);
}
diff --git a/src/frontend/qt_sdl/main.h b/src/frontend/qt_sdl/main.h
index 4553875..a3125cc 100644
--- a/src/frontend/qt_sdl/main.h
+++ b/src/frontend/qt_sdl/main.h
@@ -87,6 +87,7 @@ public:
protected:
void keyPressEvent(QKeyEvent* event) override;
+ void keyReleaseEvent(QKeyEvent* event) override;
private slots:
void onOpenFile();