onepad: create a key_status object to handle key activities with a single press/release interface

GSdx: remove some linux dialog options which were already controlled by PCSX2


git-svn-id: http://pcsx2.googlecode.com/svn/trunk@4780 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
gregory.hainaut@gmail.com 2011-06-28 21:30:06 +00:00
parent 73b46c4b7d
commit 9cb19121e0
14 changed files with 410 additions and 451 deletions

View File

@ -44,10 +44,8 @@ bool RunLinuxDialog()
{
GtkWidget *dialog;
GtkWidget *main_frame, *main_box;
GtkWidget *res_label, *res_combo_box;
GtkWidget *render_label, *render_combo_box;
GtkWidget *interlace_label, *interlace_combo_box;
GtkWidget *aspect_label, *aspect_combo_box;
GtkWidget *swthreads_label, *swthreads_text;
GtkWidget *filter_check, *logz_check, *paltex_check, *fba_check, *aa_check, *win_check;
int return_value;
@ -67,30 +65,6 @@ bool RunLinuxDialog()
main_frame = gtk_frame_new ("GSdx Config");
gtk_container_add (GTK_CONTAINER(main_frame), main_box);
res_label = gtk_label_new ("Interpolation:");
res_combo_box = gtk_combo_box_new_text ();
gtk_combo_box_append_text(GTK_COMBO_BOX(res_combo_box), "640x480@60");
gtk_combo_box_append_text(GTK_COMBO_BOX(res_combo_box), "800x600@60");
gtk_combo_box_append_text(GTK_COMBO_BOX(res_combo_box), "1024x768@60");
gtk_combo_box_append_text(GTK_COMBO_BOX(res_combo_box), "1280x960@60");
gtk_combo_box_append_text(GTK_COMBO_BOX(res_combo_box), "And a few other values like that.");
// A little hackish but enough for the moment.
// Better drop this setting and lets the user resize the windows like any applications
// You need only to constrain it with the aspect ratio -- greg
int width = theApp.GetConfig("ModeWidth", 640);
switch(width) {
case 1280: gtk_combo_box_set_active(GTK_COMBO_BOX(res_combo_box), 3); break;
case 1024: gtk_combo_box_set_active(GTK_COMBO_BOX(res_combo_box), 2); break;
case 800: gtk_combo_box_set_active(GTK_COMBO_BOX(res_combo_box), 1); break;
case 640: gtk_combo_box_set_active(GTK_COMBO_BOX(res_combo_box), 0); break;
default: gtk_combo_box_set_active(GTK_COMBO_BOX(res_combo_box), 0); break;
}
gtk_container_add(GTK_CONTAINER(main_box), res_label);
gtk_container_add(GTK_CONTAINER(main_box), res_combo_box);
render_label = gtk_label_new ("Renderer:");
render_combo_box = gtk_combo_box_new_text ();
@ -128,25 +102,6 @@ bool RunLinuxDialog()
gtk_container_add(GTK_CONTAINER(main_box), interlace_label);
gtk_container_add(GTK_CONTAINER(main_box), interlace_combo_box);
aspect_label = gtk_label_new ("Aspect Ratio:");
aspect_combo_box = gtk_combo_box_new_text ();
for(size_t i = 0; i < theApp.m_gs_aspectratio.size(); i++)
{
const GSSetting& s = theApp.m_gs_aspectratio[i];
string label = s.name;
if(!s.note.empty()) label += format(" (%s)", s.note.c_str());
gtk_combo_box_append_text(GTK_COMBO_BOX(aspect_combo_box), label.c_str());
}
gtk_combo_box_set_active(GTK_COMBO_BOX(aspect_combo_box), 0);
gtk_container_add(GTK_CONTAINER(main_box), aspect_label);
gtk_container_add(GTK_CONTAINER(main_box), aspect_combo_box);
swthreads_label = gtk_label_new("Software renderer threads:");
swthreads_text = gtk_entry_new();
char buf[5];
@ -157,7 +112,6 @@ bool RunLinuxDialog()
gtk_container_add(GTK_CONTAINER(main_box), swthreads_text);
filter_check = gtk_check_button_new_with_label("Texture Filtering");
logz_check = gtk_check_button_new_with_label("Logarithmic Z");
paltex_check = gtk_check_button_new_with_label("Allow 8 bit textures");
@ -190,9 +144,6 @@ bool RunLinuxDialog()
// Get all the settings from the dialog box.
#if 0 // I'll put the right variable names in later.
if (gtk_combo_box_get_active(GTK_COMBO_BOX(res_combo_box)) != -1)
resolution = gtk_combo_box_get_active(GTK_COMBO_BOX(res_combo_box));
if (gtk_combo_box_get_active(GTK_COMBO_BOX(render_combo_box)) != -1)
renderer = gtk_combo_box_get_active(GTK_COMBO_BOX(render_combo_box));
@ -202,17 +153,6 @@ bool RunLinuxDialog()
if (gtk_combo_box_get_active(GTK_COMBO_BOX(aspect_combo_box)) != -1)
aspect = gtk_combo_box_get_active(GTK_COMBO_BOX(aspect_combo_box));
#endif
if (gtk_combo_box_get_active(GTK_COMBO_BOX(res_combo_box)) != -1) {
int resolution = gtk_combo_box_get_active(GTK_COMBO_BOX(res_combo_box));
switch (resolution) {
case 0: theApp.SetConfig("ModeWidth", 640); theApp.SetConfig("ModeHeight", 480); break;
case 1: theApp.SetConfig("ModeWidth", 800); theApp.SetConfig("ModeHeight", 600); break;
case 2: theApp.SetConfig("ModeWidth", 1024); theApp.SetConfig("ModeHeight", 768); break;
case 3: theApp.SetConfig("ModeWidth", 1280); theApp.SetConfig("ModeHeight", 960); break;
default: theApp.SetConfig("ModeWidth", 640); theApp.SetConfig("ModeHeight", 480);
}
}
theApp.SetConfig("swthreads", atoi((char*)gtk_entry_get_text(GTK_ENTRY(swthreads_text))) );

View File

@ -39,19 +39,19 @@ endif(CMAKE_BUILD_TYPE STREQUAL Release)
# onepad sources
set(onepadSources
analog.cpp
controller.cpp
joystick.cpp
keyboard.cpp
KeyStatus.cpp
onepad.cpp)
# onepad headers
set(onepadHeaders
analog.h
bitwise.h
controller.h
joystick.h
keyboard.h
KeyStatus.h
onepad.h)
# onepad Linux sources

View File

@ -0,0 +1,192 @@
/* OnePAD - author: arcum42(@gmail.com)
* Copyright (C) 2011
*
* Based on ZeroPAD, author zerofrog@gmail.com
* Copyright (C) 2006-2007
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "KeyStatus.h"
void KeyStatus::Init()
{
for (int pad = 0; pad < 2; pad++) {
m_button[pad] = 0xFFFF;
m_internal_button_kbd[pad] = 0xFFFF;
m_internal_button_joy[pad] = 0xFFFF;
for (int index = 0; index < MAX_KEYS; index++) {
m_button_pressure[pad][index] = 0xFF;
m_internal_button_pressure[pad][index] = 0xFF;
}
analog[pad].lx = 0x80;
analog[pad].ly = 0x80;
analog[pad].rx = 0x80;
analog[pad].ry = 0x80;
m_internal_analog_kbd[pad].lx = 0x80;
m_internal_analog_kbd[pad].ly = 0x80;
m_internal_analog_kbd[pad].rx = 0x80;
m_internal_analog_kbd[pad].ry = 0x80;
m_internal_analog_joy[pad].lx = 0x80;
m_internal_analog_joy[pad].ly = 0x80;
m_internal_analog_joy[pad].rx = 0x80;
m_internal_analog_joy[pad].ry = 0x80;
}
}
void KeyStatus::press(u32 pad, u32 index, s32 value)
{
if (!IsAnalogKey(index)) {
if (m_state_acces[pad])
clear_bit(m_internal_button_kbd[pad], index);
else
clear_bit(m_internal_button_joy[pad], index);
} else {
// clamp value
if (value > MAX_ANALOG_VALUE)
value = MAX_ANALOG_VALUE;
else if (value < -MAX_ANALOG_VALUE)
value = -MAX_ANALOG_VALUE;
// Left -> -- -> Right
// Value range : FFFF8002 -> 0 -> 7FFE
// Force range : 80 -> 0 -> 7F
// Normal mode : expect value 0 -> 80 -> FF
// Reverse mode: expect value FF -> 7F -> 0
u8 force = (value / 256);
if (analog_is_reversed(index)) analog_set(pad, index, 0x7F - force);
else analog_set(pad, index, 0x80 + force);
}
}
void KeyStatus::release(u32 pad, u32 index)
{
if (!IsAnalogKey(index)) {
if (m_state_acces[pad])
set_bit(m_internal_button_kbd[pad], index);
else
set_bit(m_internal_button_joy[pad], index);
} else {
analog_set(pad, index, 0x80);
}
}
u16 KeyStatus::get(u32 pad)
{
return m_button[pad];
}
void KeyStatus::set_pressure(u32 pad, u32 index, u32 value)
{
m_internal_button_pressure[pad][index] = value;
}
u8 KeyStatus::get_pressure(u32 pad, u32 index)
{
return m_button_pressure[pad][index];
}
void KeyStatus::analog_set(u32 pad, u32 index, u8 value)
{
PADAnalog* m_internal_analog_ref;
if (m_state_acces[pad])
m_internal_analog_ref = &m_internal_analog_kbd[pad];
else
m_internal_analog_ref = &m_internal_analog_joy[pad];
switch (index)
{
case PAD_R_LEFT:
case PAD_R_RIGHT: m_internal_analog_ref->rx = value; break;
case PAD_R_DOWN:
case PAD_R_UP: m_internal_analog_ref->ry = value; break;
case PAD_L_LEFT:
case PAD_L_RIGHT: m_internal_analog_ref->lx = value; break;
case PAD_L_DOWN:
case PAD_L_UP: m_internal_analog_ref->ly = value; break;
default: break;
}
}
bool KeyStatus::analog_is_reversed(u32 index)
{
switch (index)
{
case PAD_L_RIGHT:
case PAD_L_LEFT:
return ((conf->options & PADOPTION_REVERSELX) != 0);
case PAD_R_LEFT:
case PAD_R_RIGHT:
return ((conf->options & PADOPTION_REVERSERX) != 0);
case PAD_L_UP:
case PAD_L_DOWN:
return ((conf->options & PADOPTION_REVERSELY) != 0);
case PAD_R_DOWN:
case PAD_R_UP:
return ((conf->options & PADOPTION_REVERSERY) != 0);
default: return false;
}
}
u8 KeyStatus::analog_get(u32 pad, u32 index)
{
switch (index)
{
case PAD_R_LEFT:
case PAD_R_RIGHT: return analog[pad].rx;
case PAD_R_DOWN:
case PAD_R_UP: return analog[pad].ry;
case PAD_L_LEFT:
case PAD_L_RIGHT: return analog[pad].lx;
case PAD_L_DOWN:
case PAD_L_UP: return analog[pad].ly;
default: return 0;
}
}
u8 KeyStatus::analog_merge(u8 kbd, u8 joy)
{
if (kbd != 0x80)
return kbd;
else
return joy;
}
void KeyStatus::commit_status(u32 pad)
{
m_button[pad] = m_internal_button_kbd[pad] & m_internal_button_joy[pad];
for (int index = 0; index < MAX_KEYS; index++)
m_button_pressure[pad][index] = m_internal_button_pressure[pad][index];
analog[pad].lx = analog_merge(m_internal_analog_kbd[pad].lx, m_internal_analog_joy[pad].lx);
analog[pad].ly = analog_merge(m_internal_analog_kbd[pad].ly, m_internal_analog_joy[pad].ly);
analog[pad].rx = analog_merge(m_internal_analog_kbd[pad].rx, m_internal_analog_joy[pad].rx);
analog[pad].ry = analog_merge(m_internal_analog_kbd[pad].ry, m_internal_analog_joy[pad].ry);
}

View File

@ -0,0 +1,76 @@
/* OnePAD - author: arcum42(@gmail.com)
* Copyright (C) 2011
*
* Based on ZeroPAD, author zerofrog@gmail.com
* Copyright (C) 2006-2007
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __KEYSTATUS_H__
#define __KEYSTATUS_H__
#include "onepad.h"
typedef struct
{
u8 lx, ly;
u8 rx, ry;
} PADAnalog;
#define MAX_ANALOG_VALUE 32766
class KeyStatus
{
private:
u16 m_button[2];
u16 m_internal_button_kbd[2];
u16 m_internal_button_joy[2];
u8 m_button_pressure[2][MAX_KEYS];
u8 m_internal_button_pressure[2][MAX_KEYS];
bool m_state_acces[2];
PADAnalog analog[2];
PADAnalog m_internal_analog_kbd[2];
PADAnalog m_internal_analog_joy[2];
void analog_set(u32 pad, u32 index, u8 value);
bool analog_is_reversed(u32 index);
u8 analog_merge(u8 kbd, u8 joy);
public:
KeyStatus() { Init(); }
void Init();
void keyboard_state_acces(u32 pad) { m_state_acces[pad] = true; }
void joystick_state_acces(u32 pad) { m_state_acces[pad] = false; }
void press(u32 pad, u32 index, s32 value = 0);
void release(u32 pad, u32 index);
u16 get(u32 pad);
void set_pressure(u32 pad, u32 index, u32 value);
u8 get_pressure(u32 pad, u32 index);
u8 analog_get(u32 pad, u32 index);
void commit_status(u32 pad);
};
extern KeyStatus* key_status;
#endif

View File

@ -57,8 +57,8 @@
<Unit filename="ini.cpp" />
<Unit filename="linux.cpp" />
<Unit filename="linux.h" />
<Unit filename="../analog.cpp" />
<Unit filename="../analog.h" />
<Unit filename="../KeyStatus.cpp" />
<Unit filename="../KeyStatus.h" />
<Unit filename="../bitwise.h" />
<Unit filename="../controller.cpp" />
<Unit filename="../controller.h" />

View File

@ -87,30 +87,12 @@ void _PADclose()
s_vjoysticks.clear();
}
static bool used_by_keyboard = false;
EXPORT_C_(void) PADupdate(int pad)
void PollForJoystickInput(int cpad)
{
// FIXME joystick directly update the status variable
// Keyboard does a nice roadtrip (with semaphore in the middle)
// s_keyRelease (by UpdateKeys) -> status (by _PADupdate -> by _PADpoll)
// If we need semaphore, joy part must be updated
// Actually PADupdate is always call with pad == 0. So you need to update both
// pads -- Gregory
for (int cpad = 0; cpad < 2; cpad++) {
int keyPress = 0, keyRelease = 0;
// Poll keyboard.
PollForX11KeyboardInput(cpad, keyPress, keyRelease, used_by_keyboard);
UpdateKeys(pad, keyPress, keyRelease);
// joystick info
SDL_JoystickUpdate();
int joyid = conf->get_joyid(cpad);
if (!JoystickIdWithinBounds(joyid)) return;
if (JoystickIdWithinBounds(joyid)) {
SDL_JoystickUpdate();
for (int i = 0; i < MAX_KEYS; i++)
{
JoystickInfo* pjoy = s_vjoysticks[joyid];
@ -122,9 +104,9 @@ EXPORT_C_(void) PADupdate(int pad)
int value = SDL_JoystickGetButton((pjoy)->GetJoy(), key_to_button(cpad, i));
if (value)
clear_bit(status[cpad], i); // released
key_status->press(cpad, i);
else
set_bit(status[cpad], i); // pressed
key_status->release(cpad, i);
break;
}
@ -132,13 +114,13 @@ EXPORT_C_(void) PADupdate(int pad)
{
int value = SDL_JoystickGetHat((pjoy)->GetJoy(), key_to_axis(cpad, i));
// key_to_hat_dir and value are a 4 bits bitmap, one for each directions. Only 1 bit can be high for
// key_to_hat_dir. Value handles diagonal too (2 bits) so you must check the intersection
// key_to_hat_dir and SDL_JoystickGetHat are a 4 bits bitmap, one for each directions. Only 1 bit can be high for
// key_to_hat_dir. SDL_JoystickGetHat handles diagonal too (2 bits) so you must check the intersection
// '&' not only equality '=='. -- Gregory
if (key_to_hat_dir(cpad, i) & value)
clear_bit(status[cpad], i);
key_status->press(cpad, i);
else
set_bit(status[cpad], i);
key_status->release(cpad, i);
break;
}
@ -149,35 +131,30 @@ EXPORT_C_(void) PADupdate(int pad)
bool full_axis = key_to_axis_type(cpad, i);
if (IsAnalogKey(i)) {
if (abs(value) > (pjoy)->GetDeadzone())
Analog::ConfigurePad(cpad, i, value);
else if (! (conf->options & ((PADOPTION_MOUSE_R|PADOPTION_MOUSE_L) << 16 * cpad ))
&& !(used_by_keyboard) )
// There is a conflict between keyboard/mouse and joystick configuration.
// Do nothing when either the mouse or the keyboad is pressed/enabled.
// It avoid to be stuck in reset mode --Gregory
Analog::ResetPad(cpad, i);
if (abs(value) > pjoy->GetDeadzone())
key_status->press(cpad, i, value);
else
key_status->release(cpad, i);
} else {
if (full_axis) {
value += 0x8000;
if (value > 2048) {
clear_bit(status[cpad], i);
status_pressure[cpad][i] = min(value/256 , 0xFF); // Max pressure is 255
if (value > pjoy->GetDeadzone()) {
key_status->press(cpad, i);
key_status->set_pressure(cpad, i, min(value/256 , 0xFF));
} else {
set_bit(status[cpad], i);
status_pressure[cpad][i] = 0; // no pressure
key_status->release(cpad, i);
}
} else {
if (sign && (value < -2048)) {
clear_bit(status[cpad], i);
status_pressure[cpad][i] = min(-value /128, 0xFF); // Max pressure is 255
} else if (!sign && (value > 2048)) {
clear_bit(status[cpad], i);
status_pressure[cpad][i] = min(value /128, 0xFF); // Max pressure is 255
if (sign && (-value > pjoy->GetDeadzone())) {
key_status->press(cpad, i);
key_status->set_pressure(cpad, i, min(-value /128, 0xFF));
} else if (!sign && (value > pjoy->GetDeadzone())) {
key_status->press(cpad, i);
key_status->set_pressure(cpad, i, min(value /128, 0xFF));
} else {
set_bit(status[cpad], i);
status_pressure[cpad][i] = 0; // no pressure
key_status->release(cpad, i);
}
}
}
@ -186,6 +163,21 @@ EXPORT_C_(void) PADupdate(int pad)
}
}
}
EXPORT_C_(void) PADupdate(int pad)
{
// Actually PADupdate is always call with pad == 0. So you need to update both
// pads -- Gregory
for (int cpad = 0; cpad < 2; cpad++) {
// Poll keyboard/mouse event
key_status->keyboard_state_acces(cpad);
PollForX11KeyboardInput(cpad);
// Get joystick state
key_status->joystick_state_acces(cpad);
PollForJoystickInput(cpad);
key_status->commit_status(cpad);
}
}

View File

@ -1,119 +0,0 @@
/* OnePAD - author: arcum42(@gmail.com)
* Copyright (C) 2009
*
* Based on ZeroPAD, author zerofrog@gmail.com
* Copyright (C) 2006-2007
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "analog.h"
static PADAnalog g_lanalog[NUM_OF_PADS], g_ranalog[NUM_OF_PADS];
namespace Analog
{
u8 Pad(int pad, u8 index)
{
switch (index)
{
case PAD_R_LEFT:
case PAD_R_RIGHT: return g_ranalog[pad].x;
case PAD_R_DOWN:
case PAD_R_UP: return g_ranalog[pad].y;
case PAD_L_LEFT:
case PAD_L_RIGHT: return g_lanalog[pad].x;
case PAD_L_DOWN:
case PAD_L_UP: return g_lanalog[pad].y;
default: return 0;
}
}
static void SetPad(u8 pad, int index, u8 value)
{
switch (index)
{
case PAD_R_LEFT:
case PAD_R_RIGHT: g_ranalog[pad].x = value; break;
case PAD_R_DOWN:
case PAD_R_UP: g_ranalog[pad].y = value; break;
case PAD_L_LEFT:
case PAD_L_RIGHT: g_lanalog[pad].x = value; break;
case PAD_L_DOWN:
case PAD_L_UP: g_lanalog[pad].y = value; break;
default: break;
}
}
void ResetPad( u8 pad, int key)
{
SetPad(pad, key, 0x80);
}
void Init()
{
for (u8 pad = 0; pad < 2; ++pad)
{
// no need to put the 2 part of the axis
ResetPad(pad, PAD_R_LEFT);
ResetPad(pad, PAD_R_DOWN);
ResetPad(pad, PAD_L_LEFT);
ResetPad(pad, PAD_L_DOWN);
}
}
static bool ReversePad(u8 index)
{
switch (index)
{
case PAD_L_RIGHT:
case PAD_L_LEFT:
return ((conf->options & PADOPTION_REVERSELX) != 0);
case PAD_R_LEFT:
case PAD_R_RIGHT:
return ((conf->options & PADOPTION_REVERSERX) != 0);
case PAD_L_UP:
case PAD_L_DOWN:
return ((conf->options & PADOPTION_REVERSELY) != 0);
case PAD_R_DOWN:
case PAD_R_UP:
return ((conf->options & PADOPTION_REVERSERY) != 0);
default: return false;
}
}
void ConfigurePad( u8 pad, int index, int value)
{
// Left -> -- -> Right
// Value range : FFFF8002 -> 0 -> 7FFE
// Force range : 80 -> 0 -> 7F
// Normal mode : expect value 0 -> 80 -> FF
// Reverse mode: expect value FF -> 7F -> 0
u8 force = (value / 256);
if (ReversePad(index)) SetPad(pad, index, 0x7F - force);
else SetPad(pad, index, 0x80 + force);
}
}

View File

@ -1,32 +0,0 @@
/* OnePAD - author: arcum42(@gmail.com)
* Copyright (C) 2009
*
* Based on ZeroPAD, author zerofrog@gmail.com
* Copyright (C) 2006-2007
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#define NUM_OF_PADS 2
#include "onepad.h"
namespace Analog
{
extern void Init();
extern u8 Pad(int pad, u8 index);
extern void ResetPad( u8 pad, int key);
extern void ConfigurePad( u8 pad, int index, int value);
}

View File

@ -136,9 +136,4 @@ struct PADconf
}
};
extern PADconf *conf;
typedef struct
{
u8 x, y;
} PADAnalog;
#endif

View File

@ -56,10 +56,10 @@ static bool s_grab_input = false;
static bool s_Shift = false;
static unsigned int s_previous_mouse_x = 0;
static unsigned int s_previous_mouse_y = 0;
void AnalyzeKeyEvent(int pad, keyEvent &evt, int& keyPress, int& keyRelease, bool& used_by_keyboard)
void AnalyzeKeyEvent(int pad, keyEvent &evt)
{
int i;
KeySym key = (KeySym)evt.key;
int index = get_keyboard_key(pad, key);
switch (evt.evt)
{
@ -82,36 +82,28 @@ void AnalyzeKeyEvent(int pad, keyEvent &evt, int& keyPress, int& keyRelease, boo
}
}
i = get_keyboard_key(pad, key);
// Analog controls.
if (IsAnalogKey(i))
if (IsAnalogKey(index))
{
used_by_keyboard = true; // avoid the joystick to reset the analog pad...
switch (i)
switch (index)
{
case PAD_R_LEFT:
case PAD_R_UP:
case PAD_L_LEFT:
case PAD_L_UP:
Analog::ConfigurePad(pad, i, -DEF_VALUE);
key_status->press(pad, index, -MAX_ANALOG_VALUE);
break;
case PAD_R_RIGHT:
case PAD_R_DOWN:
case PAD_L_RIGHT:
case PAD_L_DOWN:
Analog::ConfigurePad(pad, i, DEF_VALUE);
key_status->press(pad, index, MAX_ANALOG_VALUE);
break;
}
i += 0xff00;
}
} else if (index != -1)
key_status->press(pad, index);
if (i != -1)
{
clear_bit(keyRelease, i);
set_bit(keyPress, i);
}
//PAD_LOG("Key pressed:%d\n", i);
//PAD_LOG("Key pressed:%d\n", index);
event.evt = KEYPRESS;
event.key = key;
@ -120,21 +112,8 @@ void AnalyzeKeyEvent(int pad, keyEvent &evt, int& keyPress, int& keyRelease, boo
case KeyRelease:
if (key == XK_Shift_R || key == XK_Shift_L) s_Shift = false;
i = get_keyboard_key(pad, key);
// Analog Controls.
if (IsAnalogKey(i))
{
used_by_keyboard = false; // allow the joystick to reset the analog pad...
Analog::ResetPad(pad, i);
i += 0xff00;
}
if (i != -1)
{
clear_bit(keyPress, i);
set_bit(keyRelease, i);
}
if (index != -1)
key_status->release(pad, index);
event.evt = KEYRELEASE;
event.key = key;
@ -149,21 +128,13 @@ void AnalyzeKeyEvent(int pad, keyEvent &evt, int& keyPress, int& keyRelease, boo
break;
case ButtonPress:
i = get_keyboard_key(pad, evt.key);
if (i != -1)
{
clear_bit(keyRelease, i);
set_bit(keyPress, i);
}
if (index != -1)
key_status->press(pad, index);
break;
case ButtonRelease:
i = get_keyboard_key(pad, evt.key);
if (i != -1)
{
clear_bit(keyPress, i);
set_bit(keyRelease, i);
}
if (index != -1)
key_status->release(pad, index);
break;
case MotionNotify:
@ -185,34 +156,32 @@ void AnalyzeKeyEvent(int pad, keyEvent &evt, int& keyPress, int& keyRelease, boo
unsigned x = evt.key & 0xFFFF;
unsigned int value = abs(s_previous_mouse_x - x) * conf->sensibility;
value = max(value, (unsigned int)DEF_VALUE);
if (x == 0)
Analog::ConfigurePad(pad, pad_x, -DEF_VALUE);
key_status->press(pad, pad_x, -MAX_ANALOG_VALUE);
else if (x == 0xFFFF)
Analog::ConfigurePad(pad, pad_x, DEF_VALUE);
key_status->press(pad, pad_x, MAX_ANALOG_VALUE);
else if (x < (s_previous_mouse_x -2))
Analog::ConfigurePad(pad, pad_x, -value);
key_status->press(pad, pad_x, -value);
else if (x > (s_previous_mouse_x +2))
Analog::ConfigurePad(pad, pad_x, value);
key_status->press(pad, pad_x, value);
else
Analog::ResetPad(pad, pad_x);
key_status->release(pad, pad_x);
unsigned y = evt.key >> 16;
value = abs(s_previous_mouse_y - y) * conf->sensibility;
value = max(value, (unsigned int)DEF_VALUE);
if (y == 0)
Analog::ConfigurePad(pad, pad_y, -DEF_VALUE);
key_status->press(pad, pad_y, -MAX_ANALOG_VALUE);
else if (y == 0xFFFF)
Analog::ConfigurePad(pad, pad_y, DEF_VALUE);
key_status->press(pad, pad_y, MAX_ANALOG_VALUE);
else if (y < (s_previous_mouse_y -2))
Analog::ConfigurePad(pad, pad_y, -value);
key_status->press(pad, pad_y, -value);
else if (y > (s_previous_mouse_y +2))
Analog::ConfigurePad(pad, pad_y, value);
key_status->press(pad, pad_y, value);
else
Analog::ResetPad(pad, pad_y);
key_status->release(pad, pad_y);
s_previous_mouse_x = x;
s_previous_mouse_y = y;
@ -222,7 +191,7 @@ void AnalyzeKeyEvent(int pad, keyEvent &evt, int& keyPress, int& keyRelease, boo
}
}
void PollForX11KeyboardInput(int pad, int& keyPress, int& keyRelease, bool& used_by_keyboard)
void PollForX11KeyboardInput(int pad)
{
keyEvent evt;
XEvent E;
@ -230,10 +199,10 @@ void PollForX11KeyboardInput(int pad, int& keyPress, int& keyRelease, bool& used
// Keyboard input send by PCSX2
while (!ev_fifo.empty()) {
AnalyzeKeyEvent(pad, ev_fifo.front(), keyPress, keyRelease, used_by_keyboard);
pthread_mutex_lock(&mutex_KeyEvent);
AnalyzeKeyEvent(pad, ev_fifo.front());
pthread_spin_lock(&mutex_KeyEvent);
ev_fifo.pop();
pthread_mutex_unlock(&mutex_KeyEvent);
pthread_spin_unlock(&mutex_KeyEvent);
}
// keyboard input
@ -251,7 +220,7 @@ void PollForX11KeyboardInput(int pad, int& keyPress, int& keyRelease, bool& used
case ButtonPress: evt.key = BE->button; break;
default: break;
}
AnalyzeKeyEvent(pad, evt, keyPress, keyRelease, used_by_keyboard);
AnalyzeKeyEvent(pad, evt);
}
}

View File

@ -29,7 +29,7 @@
#include "Linux/linux.h"
extern Display *GSdsp;
extern void PollForX11KeyboardInput(int pad, int& keyPress, int& keyRelease, bool& used_by_keyboard);
extern void PollForX11KeyboardInput(int pad);
extern bool PollX11KeyboardMouseEvent(u32 &pkey);
extern Window GSwin;

View File

@ -39,8 +39,6 @@ char libraryName[256];
keyEvent event;
u16 status[2];
int status_pressure[2][MAX_KEYS];
static keyEvent s_event;
std::string s_strIniPath("inis/");
std::string s_strLogPath("logs/");
@ -52,7 +50,6 @@ const u32 build = 1; // increase that with each version
int PadEnum[2][2] = {{0, 2}, {1, 3}};
u32 pads = 0;
u8 stdpar[2][20] = {
{0xff, 0x5a, 0xff, 0xff, 0x80, 0x80, 0x80, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -123,9 +120,8 @@ int curPad, curByte, curCmd, cmdLen;
int ds2mode = 0; // DS Mode at start
FILE *padLog = NULL;
pthread_spinlock_t s_mutexStatus;
pthread_mutex_t mutex_KeyEvent;
static u32 s_keyPress[2], s_keyRelease[2];
pthread_spinlock_t mutex_KeyEvent;
KeyStatus* key_status = NULL;
queue<keyEvent> ev_fifo;
@ -257,19 +253,12 @@ EXPORT_C_(s32) PADinit(u32 flags)
{
initLogging();
pads |= flags;
for (int i = 0 ; i < 2 ; i++) {
status[i] = 0xffff;
for (int j = 0 ; j < MAX_KEYS ; j++)
status_pressure[i][j] = 255;
}
LoadConfig();
PADsetMode(0, 0);
PADsetMode(1, 0);
Analog::Init();
key_status = new KeyStatus();
return 0;
}
@ -278,17 +267,16 @@ EXPORT_C_(void) PADshutdown()
{
CloseLogging();
if (conf) delete conf;
if (key_status) delete key_status;
}
EXPORT_C_(s32) PADopen(void *pDsp)
{
memset(&event, 0, sizeof(event));
key_status->Init();
while (!ev_fifo.empty()) ev_fifo.pop();
pthread_spin_init(&s_mutexStatus, PTHREAD_PROCESS_PRIVATE);
pthread_mutex_init(&mutex_KeyEvent, NULL);
s_keyPress[0] = s_keyPress[1] = 0;
s_keyRelease[0] = s_keyRelease[1] = 0;
pthread_spin_init(&mutex_KeyEvent, PTHREAD_PROCESS_PRIVATE);
#ifdef __LINUX__
JoystickInfo::EnumerateJoysticks(s_vjoysticks);
@ -315,31 +303,10 @@ EXPORT_C_(void) PADsetLogDir(const char* dir)
EXPORT_C_(void) PADclose()
{
while (!ev_fifo.empty()) ev_fifo.pop();
pthread_spin_destroy(&s_mutexStatus);
pthread_mutex_destroy(&mutex_KeyEvent);
pthread_spin_destroy(&mutex_KeyEvent);
_PADclose();
}
void _PADupdate(int pad)
{
pthread_spin_lock(&s_mutexStatus);
status[pad] |= s_keyRelease[pad];
status[pad] &= ~s_keyPress[pad];
s_keyRelease[pad] = 0;
s_keyPress[pad] = 0;
pthread_spin_unlock(&s_mutexStatus);
}
void UpdateKeys(int pad, int keyPress, int keyRelease)
{
pthread_spin_lock(&s_mutexStatus);
s_keyPress[pad] |= keyPress;
s_keyPress[pad] &= ~keyRelease;
s_keyRelease[pad] |= keyRelease;
s_keyRelease[pad] &= ~keyPress;
pthread_spin_unlock(&s_mutexStatus);
}
EXPORT_C_(u32) PADquery()
{
return 3; // both
@ -420,14 +387,12 @@ u8 _PADpoll(u8 value)
case CMD_READ_DATA_AND_VIBRATE: // READ_DATA
_PADupdate(curPad);
stdpar[curPad][2] = status[curPad] >> 8;
stdpar[curPad][3] = status[curPad] & 0xff;
stdpar[curPad][4] = Analog::Pad(curPad, PAD_R_RIGHT);
stdpar[curPad][5] = Analog::Pad(curPad, PAD_R_UP);
stdpar[curPad][6] = Analog::Pad(curPad, PAD_L_RIGHT);
stdpar[curPad][7] = Analog::Pad(curPad, PAD_L_UP);
stdpar[curPad][2] = key_status->get(curPad) >> 8;
stdpar[curPad][3] = key_status->get(curPad) & 0xff;
stdpar[curPad][4] = key_status->analog_get(curPad, PAD_R_RIGHT);
stdpar[curPad][5] = key_status->analog_get(curPad, PAD_R_UP);
stdpar[curPad][6] = key_status->analog_get(curPad, PAD_L_RIGHT);
stdpar[curPad][7] = key_status->analog_get(curPad, PAD_L_UP);
if (padMode[curPad] == 1)
cmdLen = 20;
@ -438,35 +403,35 @@ u8 _PADpoll(u8 value)
switch (stdpar[curPad][3])
{
case 0xBF: // X
stdpar[curPad][14] = status_pressure[curPad][PAD_CROSS];
stdpar[curPad][14] = key_status->get_pressure(curPad, PAD_CROSS);
break;
case 0xDF: // Circle
stdpar[curPad][13] = status_pressure[curPad][PAD_CIRCLE];
stdpar[curPad][13] = key_status->get_pressure(curPad, PAD_CIRCLE);
break;
case 0xEF: // Triangle
stdpar[curPad][12] = status_pressure[curPad][PAD_TRIANGLE];
stdpar[curPad][12] = key_status->get_pressure(curPad, PAD_TRIANGLE);
break;
case 0x7F: // Square
stdpar[curPad][15] = status_pressure[curPad][PAD_SQUARE];
stdpar[curPad][15] = key_status->get_pressure(curPad, PAD_SQUARE);
break;
case 0xFB: // L1
stdpar[curPad][16] = status_pressure[curPad][PAD_L1];
stdpar[curPad][16] = key_status->get_pressure(curPad, PAD_L1);
break;
case 0xF7: // R1
stdpar[curPad][17] = status_pressure[curPad][PAD_R1];
stdpar[curPad][17] = key_status->get_pressure(curPad, PAD_R1);
break;
case 0xFE: // L2
stdpar[curPad][18] = status_pressure[curPad][PAD_L2];
stdpar[curPad][18] = key_status->get_pressure(curPad, PAD_L2);
break;
case 0xFD: // R2
stdpar[curPad][19] = status_pressure[curPad][PAD_R2];
stdpar[curPad][19] = key_status->get_pressure(curPad, PAD_R2);
break;
default:
@ -483,19 +448,19 @@ u8 _PADpoll(u8 value)
switch (button_check)
{
case 0xE: // UP
stdpar[curPad][10] = status_pressure[curPad][PAD_UP];
stdpar[curPad][10] = key_status->get_pressure(curPad, PAD_UP);
break;
case 0xB: // DOWN
stdpar[curPad][11] =status_pressure[curPad][PAD_DOWN];
stdpar[curPad][11] =key_status->get_pressure(curPad, PAD_DOWN);
break;
case 0x7: // LEFT
stdpar[curPad][9] = status_pressure[curPad][PAD_LEFT];
stdpar[curPad][9] = key_status->get_pressure(curPad, PAD_LEFT);
break;
case 0xD: // RIGHT
stdpar[curPad][8] = status_pressure[curPad][PAD_RIGHT];
stdpar[curPad][8] = key_status->get_pressure(curPad, PAD_RIGHT);
break;
default:
@ -701,8 +666,8 @@ EXPORT_C_(keyEvent*) PADkeyEvent()
#ifdef __LINUX__
EXPORT_C_(void) PADWriteEvent(keyEvent &evt)
{
pthread_mutex_lock(&mutex_KeyEvent);
pthread_spin_lock(&mutex_KeyEvent);
ev_fifo.push(evt);
pthread_mutex_unlock(&mutex_KeyEvent);
pthread_spin_unlock(&mutex_KeyEvent);
}
#endif

View File

@ -50,9 +50,9 @@ using namespace std;
#ifdef __LINUX__
#include "joystick.h"
#endif
#include "analog.h"
#include "bitwise.h"
#include "controller.h"
#include "KeyStatus.h"
#ifdef _MSC_VER
#define EXPORT_C_(type) extern "C" __declspec(dllexport) type CALLBACK
@ -124,31 +124,14 @@ enum gamePadValues
PAD_R_LEFT
};
// Activate bolche's analog controls hack
// DEF_VALUE is the strength you press the control.
// Code taken from http://forums.pcsx2.net/thread-4699.html
#define DEF_VALUE 32766
/* end of pad.h */
extern keyEvent event;
extern queue<keyEvent> ev_fifo;
extern pthread_mutex_t mutex_KeyEvent;
extern u16 status[2];
extern int status_pressure[2][MAX_KEYS];
extern u32 pads;
extern pthread_spinlock_t mutex_KeyEvent;
void clearPAD(int pad);
int POV(u32 direction, u32 angle);
s32 _PADopen(void *pDsp);
void _PADclose();
void _KeyPress(int pad, u32 key);
void _KeyRelease(int pad, u32 key);
void PADsetMode(int pad, int mode);
void _PADupdate(int pad);
void __Log(const char *fmt, ...);
void __LogToConsole(const char *fmt, ...);
@ -156,7 +139,5 @@ void LoadConfig();
void SaveConfig();
void SysMessage(char *fmt, ...);
void UpdateKeys(int pad, int keyPress, int keyRelease);
#endif

View File

@ -7,7 +7,7 @@ endif(NOT TOP_CMAKE_WAS_SOURCED)
# plugin name
set(Output spu2x-1.5.0)
set(Output spu2x-2.0.0)
set(CommonFlags
-fvisibility=hidden
@ -113,7 +113,7 @@ set_target_properties(${Output} PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin/plugins)
# link target with project internal libraries
target_link_libraries(${Output} Utilities x86emitter Utilities)
target_link_libraries(${Output} Utilities Utilities)
# link target with ALSA
target_link_libraries(${Output} ${ALSA_LIBRARIES})