actually hook up input to the core
also unbotch CMakeLists.txt
This commit is contained in:
parent
9df8d91bdc
commit
b262313816
|
@ -14,6 +14,14 @@ if(NOT CMAKE_BUILD_TYPE)
|
|||
set(CMAKE_BUILD_TYPE Release)
|
||||
endif()
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL Debug)
|
||||
add_compile_options(-Og)
|
||||
endif()
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL Release)
|
||||
add_compile_options(-O3)
|
||||
endif()
|
||||
|
||||
add_compile_options(-fno-pic)
|
||||
add_link_options(-no-pie)
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -87,6 +87,7 @@ public:
|
|||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent* event) override;
|
||||
void keyReleaseEvent(QKeyEvent* event) override;
|
||||
|
||||
private slots:
|
||||
void onOpenFile();
|
||||
|
|
Loading…
Reference in New Issue