diff --git a/INSTALL b/INSTALL index 289cefa..61a151b 100644 --- a/INSTALL +++ b/INSTALL @@ -14,6 +14,7 @@ x11proto-xf86vidmode automake and autoconf (verion >= 1.9) Nvidia Cg-Toolkit (http://developer.nvidia.com/object/cg_toolkit.html) libasound-dev +joystick When first building, the Pcsx2 programs need to configure the Makefiles for your specific OS. type: diff --git a/plugins/pad/zeropad/Linux/callbacks.h b/plugins/pad/zeropad/Linux/callbacks.h new file mode 100644 index 0000000..cb64e16 --- /dev/null +++ b/plugins/pad/zeropad/Linux/callbacks.h @@ -0,0 +1,46 @@ +#include + + +void +OnConf_Pad1 (GtkButton *button, + gpointer user_data); + +void +OnConf_Pad2 (GtkButton *button, + gpointer user_data); + +void +OnConf_Key (GtkButton *button, + gpointer user_data); + +void +OnConf_Cancel (GtkButton *button, + gpointer user_data); + +void +OnConf_Ok (GtkButton *button, + gpointer user_data); + +void +on_joydevicescombo_changed (GtkComboBox *combobox, + gpointer user_data); + +void +on_checkbutton_reverselx_toggled (GtkToggleButton *togglebutton, + gpointer user_data); + +void +on_checkbutton_reversely_toggled (GtkToggleButton *togglebutton, + gpointer user_data); + +void +on_checkbutton_reverserx_toggled (GtkToggleButton *togglebutton, + gpointer user_data); + +void +on_checkbutton_reversery_toggled (GtkToggleButton *togglebutton, + gpointer user_data); + +void +on_forcefeedback_toggled (GtkToggleButton *togglebutton, + gpointer user_data); diff --git a/plugins/pad/zeropad/interface.c b/plugins/pad/zeropad/Linux/interface.c similarity index 83% rename from plugins/pad/zeropad/interface.c rename to plugins/pad/zeropad/Linux/interface.c index 0c832ab..ffd4261 100644 --- a/plugins/pad/zeropad/interface.c +++ b/plugins/pad/zeropad/Linux/interface.c @@ -66,6 +66,9 @@ create_Conf (void) GSList *PAD1_group = NULL; GtkWidget *PAD2; GtkWidget *label2; + GtkWidget *vbox2; + GtkWidget *label5; + GtkWidget *joydevicescombo; GtkWidget *fixed1; GtkWidget *eL2; GtkWidget *eL1; @@ -99,17 +102,22 @@ create_Conf (void) GtkWidget *Cross; GtkWidget *Triangle; GtkWidget *Circle; - GtkWidget *Right; GtkWidget *Square; - GtkWidget *R3; - GtkWidget *Lx; - GtkWidget *Rx; - GtkWidget *Ly; - GtkWidget *Ry; - GtkWidget *label3; GtkWidget *L3; GtkWidget *Up; GtkWidget *L2; + GtkWidget *Lx; + GtkWidget *Ly; + GtkWidget *Rx; + GtkWidget *Ry; + GtkWidget *Right; + GtkWidget *label3; + GtkWidget *R3; + GtkWidget *checkbutton_reverselx; + GtkWidget *checkbutton_reversely; + GtkWidget *checkbutton_reverserx; + GtkWidget *checkbutton_reversery; + GtkWidget *forcefeedback; GtkWidget *dialog_action_area1; GtkWidget *cancelbutton1; GtkWidget *okbutton1; @@ -128,7 +136,6 @@ create_Conf (void) frame1 = gtk_frame_new (NULL); gtk_widget_show (frame1); gtk_box_pack_start (GTK_BOX (vbox1), frame1, FALSE, FALSE, 0); - gtk_frame_set_shadow_type (GTK_FRAME (frame1), GTK_SHADOW_NONE); alignment1 = gtk_alignment_new (0.5, 0.5, 1, 1); gtk_widget_show (alignment1); @@ -157,6 +164,18 @@ create_Conf (void) gtk_frame_set_label_widget (GTK_FRAME (frame1), label2); gtk_label_set_use_markup (GTK_LABEL (label2), TRUE); + vbox2 = gtk_vbox_new (FALSE, 0); + gtk_widget_show (vbox2); + gtk_box_pack_start (GTK_BOX (vbox1), vbox2, TRUE, TRUE, 0); + + label5 = gtk_label_new (_("Joystick to use for this PAD")); + gtk_widget_show (label5); + gtk_box_pack_start (GTK_BOX (vbox2), label5, FALSE, FALSE, 0); + + joydevicescombo = gtk_combo_box_entry_new_text (); + gtk_widget_show (joydevicescombo); + gtk_box_pack_start (GTK_BOX (vbox2), joydevicescombo, TRUE, TRUE, 0); + fixed1 = gtk_fixed_new (); gtk_widget_show (fixed1); gtk_box_pack_start (GTK_BOX (vbox1), fixed1, TRUE, TRUE, 0); @@ -281,28 +300,28 @@ create_Conf (void) eRx = gtk_entry_new (); gtk_widget_show (eRx); gtk_fixed_put (GTK_FIXED (fixed1), eRx, 272, 352); - gtk_widget_set_size_request (eRx, 64, 24); + gtk_widget_set_size_request (eRx, 80, 24); gtk_editable_set_editable (GTK_EDITABLE (eRx), FALSE); gtk_entry_set_invisible_char (GTK_ENTRY (eRx), 8226); eLx = gtk_entry_new (); gtk_widget_show (eLx); - gtk_fixed_put (GTK_FIXED (fixed1), eLx, 176, 352); - gtk_widget_set_size_request (eLx, 64, 24); + gtk_fixed_put (GTK_FIXED (fixed1), eLx, 160, 352); + gtk_widget_set_size_request (eLx, 80, 24); gtk_editable_set_editable (GTK_EDITABLE (eLx), FALSE); gtk_entry_set_invisible_char (GTK_ENTRY (eLx), 8226); eRy = gtk_entry_new (); gtk_widget_show (eRy); gtk_fixed_put (GTK_FIXED (fixed1), eRy, 272, 416); - gtk_widget_set_size_request (eRy, 64, 24); + gtk_widget_set_size_request (eRy, 80, 24); gtk_editable_set_editable (GTK_EDITABLE (eRy), FALSE); gtk_entry_set_invisible_char (GTK_ENTRY (eRy), 8226); eLy = gtk_entry_new (); gtk_widget_show (eLy); - gtk_fixed_put (GTK_FIXED (fixed1), eLy, 176, 416); - gtk_widget_set_size_request (eLy, 64, 24); + gtk_fixed_put (GTK_FIXED (fixed1), eLy, 160, 416); + gtk_widget_set_size_request (eLy, 80, 24); gtk_editable_set_editable (GTK_EDITABLE (eLy), FALSE); gtk_entry_set_invisible_char (GTK_ENTRY (eLy), 8226); @@ -361,47 +380,11 @@ create_Conf (void) gtk_fixed_put (GTK_FIXED (fixed1), Circle, 432, 176); gtk_widget_set_size_request (Circle, 64, 32); - Right = gtk_button_new_with_mnemonic (_("Right")); - gtk_widget_show (Right); - gtk_fixed_put (GTK_FIXED (fixed1), Right, 128, 176); - gtk_widget_set_size_request (Right, 64, 32); - Square = gtk_button_new_with_mnemonic (_("Square")); gtk_widget_show (Square); gtk_fixed_put (GTK_FIXED (fixed1), Square, 304, 176); gtk_widget_set_size_request (Square, 64, 32); - R3 = gtk_button_new_with_mnemonic (_("R3")); - gtk_widget_show (R3); - gtk_fixed_put (GTK_FIXED (fixed1), R3, 272, 240); - gtk_widget_set_size_request (R3, 64, 32); - - Lx = gtk_button_new_with_mnemonic (_("Lx")); - gtk_widget_show (Lx); - gtk_fixed_put (GTK_FIXED (fixed1), Lx, 176, 320); - gtk_widget_set_size_request (Lx, 64, 32); - - Rx = gtk_button_new_with_mnemonic (_("Rx")); - gtk_widget_show (Rx); - gtk_fixed_put (GTK_FIXED (fixed1), Rx, 272, 320); - gtk_widget_set_size_request (Rx, 64, 32); - - Ly = gtk_button_new_with_mnemonic (_("Ly")); - gtk_widget_show (Ly); - gtk_fixed_put (GTK_FIXED (fixed1), Ly, 176, 384); - gtk_widget_set_size_request (Ly, 64, 32); - - Ry = gtk_button_new_with_mnemonic (_("Ry")); - gtk_widget_show (Ry); - gtk_fixed_put (GTK_FIXED (fixed1), Ry, 272, 384); - gtk_widget_set_size_request (Ry, 64, 32); - - label3 = gtk_label_new (_("Analog Controls (move mouse or analog joystick to select)")); - gtk_widget_show (label3); - gtk_fixed_put (GTK_FIXED (fixed1), label3, 56, 296); - gtk_widget_set_size_request (label3, 408, 16); - gtk_label_set_single_line_mode (GTK_LABEL (label3), TRUE); - L3 = gtk_button_new_with_mnemonic (_("L3")); gtk_widget_show (L3); gtk_fixed_put (GTK_FIXED (fixed1), L3, 176, 240); @@ -417,6 +400,67 @@ create_Conf (void) gtk_fixed_put (GTK_FIXED (fixed1), L2, 64, 8); gtk_widget_set_size_request (L2, 64, 32); + Lx = gtk_button_new_with_mnemonic (_("Lx")); + gtk_widget_show (Lx); + gtk_fixed_put (GTK_FIXED (fixed1), Lx, 160, 320); + gtk_widget_set_size_request (Lx, 80, 32); + + Ly = gtk_button_new_with_mnemonic (_("Ly")); + gtk_widget_show (Ly); + gtk_fixed_put (GTK_FIXED (fixed1), Ly, 160, 384); + gtk_widget_set_size_request (Ly, 80, 32); + + Rx = gtk_button_new_with_mnemonic (_("Rx")); + gtk_widget_show (Rx); + gtk_fixed_put (GTK_FIXED (fixed1), Rx, 272, 320); + gtk_widget_set_size_request (Rx, 80, 32); + + Ry = gtk_button_new_with_mnemonic (_("Ry")); + gtk_widget_show (Ry); + gtk_fixed_put (GTK_FIXED (fixed1), Ry, 272, 384); + gtk_widget_set_size_request (Ry, 80, 32); + + Right = gtk_button_new_with_mnemonic (_("Right")); + gtk_widget_show (Right); + gtk_fixed_put (GTK_FIXED (fixed1), Right, 128, 176); + gtk_widget_set_size_request (Right, 64, 32); + + label3 = gtk_label_new (_("Analog Controls (move mouse or analog joystick to select)")); + gtk_widget_show (label3); + gtk_fixed_put (GTK_FIXED (fixed1), label3, 48, 296); + gtk_widget_set_size_request (label3, 408, 16); + gtk_label_set_single_line_mode (GTK_LABEL (label3), TRUE); + + R3 = gtk_button_new_with_mnemonic (_("R3")); + gtk_widget_show (R3); + gtk_fixed_put (GTK_FIXED (fixed1), R3, 272, 240); + gtk_widget_set_size_request (R3, 64, 32); + + checkbutton_reverselx = gtk_check_button_new_with_mnemonic (_("Reverse LX")); + gtk_widget_show (checkbutton_reverselx); + gtk_fixed_put (GTK_FIXED (fixed1), checkbutton_reverselx, 16, 328); + gtk_widget_set_size_request (checkbutton_reverselx, 111, 22); + + checkbutton_reversely = gtk_check_button_new_with_mnemonic (_("Reverse LY")); + gtk_widget_show (checkbutton_reversely); + gtk_fixed_put (GTK_FIXED (fixed1), checkbutton_reversely, 16, 352); + gtk_widget_set_size_request (checkbutton_reversely, 111, 22); + + checkbutton_reverserx = gtk_check_button_new_with_mnemonic (_("Reverse RX")); + gtk_widget_show (checkbutton_reverserx); + gtk_fixed_put (GTK_FIXED (fixed1), checkbutton_reverserx, 16, 376); + gtk_widget_set_size_request (checkbutton_reverserx, 111, 22); + + checkbutton_reversery = gtk_check_button_new_with_mnemonic (_("Reverse RY")); + gtk_widget_show (checkbutton_reversery); + gtk_fixed_put (GTK_FIXED (fixed1), checkbutton_reversery, 16, 400); + gtk_widget_set_size_request (checkbutton_reversery, 111, 22); + + forcefeedback = gtk_check_button_new_with_mnemonic (_("Enable Force\nFeedback")); + gtk_widget_show (forcefeedback); + gtk_fixed_put (GTK_FIXED (fixed1), forcefeedback, 384, 320); + gtk_widget_set_size_request (forcefeedback, 112, 48); + dialog_action_area1 = GTK_DIALOG (Conf)->action_area; gtk_widget_show (dialog_action_area1); gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area1), GTK_BUTTONBOX_END); @@ -437,6 +481,9 @@ create_Conf (void) g_signal_connect ((gpointer) PAD2, "clicked", G_CALLBACK (OnConf_Pad2), NULL); + g_signal_connect ((gpointer) joydevicescombo, "changed", + G_CALLBACK (on_joydevicescombo_changed), + NULL); g_signal_connect ((gpointer) Select, "clicked", G_CALLBACK (OnConf_Key), NULL); @@ -470,27 +517,9 @@ create_Conf (void) g_signal_connect ((gpointer) Circle, "clicked", G_CALLBACK (OnConf_Key), NULL); - g_signal_connect ((gpointer) Right, "clicked", - G_CALLBACK (OnConf_Key), - NULL); g_signal_connect ((gpointer) Square, "clicked", G_CALLBACK (OnConf_Key), NULL); - g_signal_connect ((gpointer) R3, "clicked", - G_CALLBACK (OnConf_Key), - NULL); - g_signal_connect ((gpointer) Lx, "clicked", - G_CALLBACK (OnConf_Key), - NULL); - g_signal_connect ((gpointer) Rx, "clicked", - G_CALLBACK (OnConf_Key), - NULL); - g_signal_connect ((gpointer) Ly, "clicked", - G_CALLBACK (OnConf_Key), - NULL); - g_signal_connect ((gpointer) Ry, "clicked", - G_CALLBACK (OnConf_Key), - NULL); g_signal_connect ((gpointer) L3, "clicked", G_CALLBACK (OnConf_Key), NULL); @@ -500,6 +529,39 @@ create_Conf (void) g_signal_connect ((gpointer) L2, "clicked", G_CALLBACK (OnConf_Key), NULL); + g_signal_connect ((gpointer) Lx, "clicked", + G_CALLBACK (OnConf_Key), + NULL); + g_signal_connect ((gpointer) Ly, "clicked", + G_CALLBACK (OnConf_Key), + NULL); + g_signal_connect ((gpointer) Rx, "clicked", + G_CALLBACK (OnConf_Key), + NULL); + g_signal_connect ((gpointer) Ry, "clicked", + G_CALLBACK (OnConf_Key), + NULL); + g_signal_connect ((gpointer) Right, "clicked", + G_CALLBACK (OnConf_Key), + NULL); + g_signal_connect ((gpointer) R3, "clicked", + G_CALLBACK (OnConf_Key), + NULL); + g_signal_connect ((gpointer) checkbutton_reverselx, "toggled", + G_CALLBACK (on_checkbutton_reverselx_toggled), + NULL); + g_signal_connect ((gpointer) checkbutton_reversely, "toggled", + G_CALLBACK (on_checkbutton_reversely_toggled), + NULL); + g_signal_connect ((gpointer) checkbutton_reverserx, "toggled", + G_CALLBACK (on_checkbutton_reverserx_toggled), + NULL); + g_signal_connect ((gpointer) checkbutton_reversery, "toggled", + G_CALLBACK (on_checkbutton_reversery_toggled), + NULL); + g_signal_connect ((gpointer) forcefeedback, "toggled", + G_CALLBACK (on_forcefeedback_toggled), + NULL); g_signal_connect ((gpointer) cancelbutton1, "clicked", G_CALLBACK (OnConf_Cancel), NULL); @@ -517,6 +579,9 @@ create_Conf (void) GLADE_HOOKUP_OBJECT (Conf, PAD1, "PAD1"); GLADE_HOOKUP_OBJECT (Conf, PAD2, "PAD2"); GLADE_HOOKUP_OBJECT (Conf, label2, "label2"); + GLADE_HOOKUP_OBJECT (Conf, vbox2, "vbox2"); + GLADE_HOOKUP_OBJECT (Conf, label5, "label5"); + GLADE_HOOKUP_OBJECT (Conf, joydevicescombo, "joydevicescombo"); GLADE_HOOKUP_OBJECT (Conf, fixed1, "fixed1"); GLADE_HOOKUP_OBJECT (Conf, eL2, "eL2"); GLADE_HOOKUP_OBJECT (Conf, eL1, "eL1"); @@ -550,17 +615,22 @@ create_Conf (void) GLADE_HOOKUP_OBJECT (Conf, Cross, "Cross"); GLADE_HOOKUP_OBJECT (Conf, Triangle, "Triangle"); GLADE_HOOKUP_OBJECT (Conf, Circle, "Circle"); - GLADE_HOOKUP_OBJECT (Conf, Right, "Right"); GLADE_HOOKUP_OBJECT (Conf, Square, "Square"); - GLADE_HOOKUP_OBJECT (Conf, R3, "R3"); - GLADE_HOOKUP_OBJECT (Conf, Lx, "Lx"); - GLADE_HOOKUP_OBJECT (Conf, Rx, "Rx"); - GLADE_HOOKUP_OBJECT (Conf, Ly, "Ly"); - GLADE_HOOKUP_OBJECT (Conf, Ry, "Ry"); - GLADE_HOOKUP_OBJECT (Conf, label3, "label3"); GLADE_HOOKUP_OBJECT (Conf, L3, "L3"); GLADE_HOOKUP_OBJECT (Conf, Up, "Up"); GLADE_HOOKUP_OBJECT (Conf, L2, "L2"); + GLADE_HOOKUP_OBJECT (Conf, Lx, "Lx"); + GLADE_HOOKUP_OBJECT (Conf, Ly, "Ly"); + GLADE_HOOKUP_OBJECT (Conf, Rx, "Rx"); + GLADE_HOOKUP_OBJECT (Conf, Ry, "Ry"); + GLADE_HOOKUP_OBJECT (Conf, Right, "Right"); + GLADE_HOOKUP_OBJECT (Conf, label3, "label3"); + GLADE_HOOKUP_OBJECT (Conf, R3, "R3"); + GLADE_HOOKUP_OBJECT (Conf, checkbutton_reverselx, "checkbutton_reverselx"); + GLADE_HOOKUP_OBJECT (Conf, checkbutton_reversely, "checkbutton_reversely"); + GLADE_HOOKUP_OBJECT (Conf, checkbutton_reverserx, "checkbutton_reverserx"); + GLADE_HOOKUP_OBJECT (Conf, checkbutton_reversery, "checkbutton_reversery"); + GLADE_HOOKUP_OBJECT (Conf, forcefeedback, "forcefeedback"); GLADE_HOOKUP_OBJECT_NO_REF (Conf, dialog_action_area1, "dialog_action_area1"); GLADE_HOOKUP_OBJECT (Conf, cancelbutton1, "cancelbutton1"); GLADE_HOOKUP_OBJECT (Conf, okbutton1, "okbutton1"); diff --git a/plugins/pad/zeropad/interface.h b/plugins/pad/zeropad/Linux/interface.h similarity index 100% rename from plugins/pad/zeropad/interface.h rename to plugins/pad/zeropad/Linux/interface.h diff --git a/plugins/pad/zeropad/Linux/linux.cpp b/plugins/pad/zeropad/Linux/linux.cpp new file mode 100644 index 0000000..4f18144 --- /dev/null +++ b/plugins/pad/zeropad/Linux/linux.cpp @@ -0,0 +1,844 @@ +/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include + +#ifdef JOYSTICK_SUPPORT +#include +#include +#include +#include +#include +#include +#endif + +#include "zeropad.h" + +extern "C" { +#include "interface.h" +#include "support.h" +#include "callbacks.h" +} + +Display *GSdsp; +static pthread_spinlock_t s_mutexStatus; +static u32 s_keyPress[2], s_keyRelease[2]; // thread safe + +// holds all joystick info +class JoystickInfo +{ +public: + JoystickInfo(); + ~JoystickInfo() { Destroy(); } + + void Destroy(); + // opens handles to all possible joysticks + static void EnumerateJoysticks(vector& vjoysticks); + + bool Init(const char* pdev, int id, bool bStartThread=true); // opens a handle and gets information + void Assign(int pad); // assigns a joystick to a pad + void ProcessData(); // reads data from the joystick + + void TestForce(); + + const string& GetName() { return devname; } + int GetNumButtons() { return vbuttonstate.size(); } + int GetButtonState(int ibut) { return vbuttonstate[ibut]; } + int GetNumAxes() { return vaxes.size(); } + int GetAxisState(int iaxis) { return vaxes[iaxis]; } + int GetVersion() { return version; } + int GetId() { return _id; } + int GetPAD() { return pad; } + +private: + +#ifdef JOYSTICK_SUPPORT + static void* pollthread(void* p); + void* _pollthread(); +#endif + + string devid; // device id + string devname; // pretty device name + int _id, js_fd; + vector vbuttonstate; + vector vaxes; // values of the axes + int axisrange; + int pad; + int version; + + bool bTerminateThread; + pthread_t pthreadpoll; +}; + +static vector s_vjoysticks; + +extern string s_strIniPath; + +void SaveConfig() +{ + int i, j; + FILE *f; + char cfg[255]; + + strcpy(cfg, s_strIniPath.c_str()); + f = fopen(cfg,"w"); + if (f == NULL) { + printf("ZeroPAD: failed to save ini %s\n", s_strIniPath.c_str()); + return; + } + + for (j=0; j<2; j++) { + for (i=0; i::iterator it; + FORIT(it, s_vjoysticks) delete *it; + s_vjoysticks.clear(); +} + +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); +} + +int _GetJoystickIdFromPAD(int pad) +{ + // select the right joystick id + int joyid = -1; + for(int i = 0; i < PADKEYS; ++i) { + if( IS_JOYSTICK(conf.keys[pad][i]) || IS_JOYBUTTONS(conf.keys[pad][i]) ) { + joyid = PAD_GETJOYID(conf.keys[pad][i]); + break; + } + } + + return joyid; +} + +void CALLBACK PADupdate(int pad) +{ + int i; + XEvent E; + int keyPress=0,keyRelease=0; + KeySym key; + + // keyboard input + while (XPending(GSdsp) > 0) { + XNextEvent(GSdsp, &E); + switch (E.type) { + case KeyPress: + //_KeyPress(pad, XLookupKeysym((XKeyEvent *)&E, 0)); break; + key = XLookupKeysym((XKeyEvent *)&E, 0); + for (i=0; iProcessData(); + + 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); +} + +static GtkWidget *Conf=NULL, *s_devicecombo=NULL; +static int s_selectedpad = 0; + +void UpdateConf(int pad) +{ + s_selectedpad = pad; + + int i; + GtkWidget *Btn; + for (i=0; i 0) { + gtk_entry_set_text(GTK_ENTRY(Btn), tmp.c_str()); + } + else + gtk_entry_set_text(GTK_ENTRY(Btn), "Unknown"); + + gtk_object_set_user_data(GTK_OBJECT(Btn), (void*)(PADKEYS*pad+i)); + } + + // check bounds + int joyid = _GetJoystickIdFromPAD(pad); + if( joyid < 0 || joyid >= (int)s_vjoysticks.size() ) { + // get first unused joystick + for(joyid = 0; joyid < s_vjoysticks.size(); ++joyid) { + if( s_vjoysticks[joyid]->GetPAD() < 0 ) + break; + } + } + + if( joyid >= 0 && joyid < (int)s_vjoysticks.size() ) { + // select the combo + gtk_combo_box_set_active(GTK_COMBO_BOX(s_devicecombo), joyid); + } + else gtk_combo_box_set_active(GTK_COMBO_BOX(s_devicecombo), s_vjoysticks.size()); // no gamepad + + int padopts = conf.options>>(16*pad); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(lookup_widget(Conf, "checkbutton_reverselx")), padopts&PADOPTION_REVERTLX); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(lookup_widget(Conf, "checkbutton_reversely")), padopts&PADOPTION_REVERTLY); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(lookup_widget(Conf, "checkbutton_reverserx")), padopts&PADOPTION_REVERTRX); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(lookup_widget(Conf, "checkbutton_reversery")), padopts&PADOPTION_REVERTRY); + gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(lookup_widget(Conf, "forcefeedback")), padopts&PADOPTION_FORCEFEEDBACK); +} + +void OnConf_Key(GtkButton *button, gpointer user_data) +{ + GdkEvent *ev; + GtkWidget* label = lookup_widget(Conf, GetLabelFromButton(gtk_button_get_label(button)).c_str()); + if( label == NULL ) { + printf("couldn't find correct label\n"); + return; + } + + int id = (int)gtk_object_get_user_data(GTK_OBJECT(label)); + int pad = id/PADKEYS; + int key = id%PADKEYS; + unsigned long *pkey = &conf.keys[pad][key]; + + vector::iterator it; + + for (;;) { + ev = gdk_event_get(); + if (ev != NULL) { + if (ev->type == GDK_KEY_PRESS) { + *pkey = ev->key.keyval; + + char* tmp = XKeysymToString(*pkey); + if (tmp != NULL) + gtk_entry_set_text(GTK_ENTRY(label), tmp); + else + gtk_entry_set_text(GTK_ENTRY(label), "Unknown"); + return; + } + } + +#ifdef JOYSTICK_SUPPORT + FORIT(it, s_vjoysticks) { + if( (*it)->GetPAD() == s_selectedpad ) { + for(int i = 0; i < (*it)->GetNumButtons(); ++i) { + if( (*it)->GetButtonState(i) ) { + *pkey = PAD_JOYBUTTON((*it)->GetId(), i); + char str[32]; + sprintf(str, "JBut %d", i); + gtk_entry_set_text(GTK_ENTRY(label), str); + return; + } + } + + for(int i = 0; i < (*it)->GetNumAxes(); ++i) { + + if( abs((*it)->GetAxisState(i)) > 0x3fff ) { + if( key < 16 ) { // POV + *pkey = PAD_POV((*it)->GetId(), (*it)->GetAxisState(i)<0, i); + char str[32]; + sprintf(str, "JPOV %d%s", i, (*it)->GetAxisState(i)<0?"-":"+"); + gtk_entry_set_text(GTK_ENTRY(label), str); + return; + } + else { // axis + *pkey = PAD_JOYSTICK((*it)->GetId(), i); + char str[32]; + sprintf(str, "JAxis %d", i); + gtk_entry_set_text(GTK_ENTRY(label), str); + return; + } + } + } + } + } +#endif + } +} + +void OnConf_Pad1(GtkButton *button, gpointer user_data) +{ + if( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)) ) + UpdateConf(0); +} + +void OnConf_Pad2(GtkButton *button, gpointer user_data) +{ + if( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)) ) + UpdateConf(1); +} + +void OnConf_Ok(GtkButton *button, gpointer user_data) +{ +// conf.analog = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Analog)); + SaveConfig(); + + gtk_widget_destroy(Conf); + gtk_main_quit(); +} + +void OnConf_Cancel(GtkButton *button, gpointer user_data) +{ + gtk_widget_destroy(Conf); + gtk_main_quit(); + LoadConfig(); // load previous config +} + +void CALLBACK PADconfigure() +{ + LoadConfig(); + + Conf = create_Conf(); + + // recreate + JoystickInfo::EnumerateJoysticks(s_vjoysticks); + + s_devicecombo = lookup_widget(Conf, "joydevicescombo"); + + // fill the combo + char str[255]; + vector::iterator it; + FORIT(it, s_vjoysticks) { + sprintf(str, "%d: %s - but: %d, axes: %d, ver: 0x%x", (*it)->GetId(), (*it)->GetName().c_str(), + (*it)->GetNumButtons(), (*it)->GetNumAxes(), (*it)->GetVersion()); + gtk_combo_box_append_text (GTK_COMBO_BOX (s_devicecombo), str); + } + gtk_combo_box_append_text (GTK_COMBO_BOX (s_devicecombo), "No Gamepad"); + + UpdateConf(0); + + gtk_widget_show_all(Conf); + gtk_main(); +} + +// GUI event handlers +void on_joydevicescombo_changed(GtkComboBox *combobox, gpointer user_data) +{ + int joyid = gtk_combo_box_get_active(combobox); + + // unassign every joystick with this pad + for(int i = 0; i < (int)s_vjoysticks.size(); ++i) { + if( s_vjoysticks[i]->GetPAD() == s_selectedpad ) + s_vjoysticks[i]->Assign(-1); + } + + if( joyid >= 0 && joyid < (int)s_vjoysticks.size() ) + s_vjoysticks[joyid]->Assign(s_selectedpad); +} + +void on_checkbutton_reverselx_toggled(GtkToggleButton *togglebutton, gpointer user_data) +{ + int mask = PADOPTION_REVERTLX<<(16*s_selectedpad); + if( gtk_toggle_button_get_active(togglebutton) ) conf.options |= mask; + else conf.options &= ~mask; +} + +void on_checkbutton_reversely_toggled(GtkToggleButton *togglebutton, gpointer user_data) +{ + int mask = PADOPTION_REVERTLY<<(16*s_selectedpad); + if( gtk_toggle_button_get_active(togglebutton) ) conf.options |= mask; + else conf.options &= ~mask; +} + +void on_checkbutton_reverserx_toggled(GtkToggleButton *togglebutton, gpointer user_data) +{ + int mask = PADOPTION_REVERTRX<<(16*s_selectedpad); + if( gtk_toggle_button_get_active(togglebutton) ) conf.options |= mask; + else conf.options &= ~mask; +} + +void on_checkbutton_reversery_toggled(GtkToggleButton *togglebutton, gpointer user_data) +{ + int mask = PADOPTION_REVERTRY<<(16*s_selectedpad); + if( gtk_toggle_button_get_active(togglebutton) ) conf.options |= mask; + else conf.options &= ~mask; +} + +void on_forcefeedback_toggled(GtkToggleButton *togglebutton, gpointer user_data) +{ + int mask = PADOPTION_REVERTLX<<(16*s_selectedpad); + if( gtk_toggle_button_get_active(togglebutton) ) { + conf.options |= mask; + + int joyid = gtk_combo_box_get_active(GTK_COMBO_BOX(s_devicecombo)); + if( joyid >= 0 && joyid < (int)s_vjoysticks.size() ) + s_vjoysticks[joyid]->TestForce(); + } + else conf.options &= ~mask; +} + +GtkWidget *About = NULL; + +void OnAbout_Ok(GtkButton *button, gpointer user_data) +{ + gtk_widget_destroy(About); + gtk_main_quit(); +} + +void CALLBACK PADabout() { + + About = create_About(); + + gtk_widget_show_all(About); + gtk_main(); +} + +s32 CALLBACK PADtest() { + return 0; +} + +////////////////////////// +// Joystick definitions // +////////////////////////// + +// opens handles to all possible joysticks +void JoystickInfo::EnumerateJoysticks(vector& vjoysticks) +{ +#ifdef JOYSTICK_SUPPORT + vector::iterator it; + FORIT(it, vjoysticks) delete *it; + vjoysticks.clear(); + + char devid[10]; + JoystickInfo* pjoy = new JoystickInfo(); + for(int i = 0; i < 6; ++i) { + sprintf(devid, "/dev/js%d", i); + if( pjoy->Init(devid, i) ) { + vjoysticks.push_back(pjoy); + pjoy = new JoystickInfo(); + } + } + + delete pjoy; + + // set the pads + for(int pad = 0; pad < 2; ++pad) { + // select the right joystick id + int joyid = -1; + for(int i = 0; i < PADKEYS; ++i) { + if( IS_JOYSTICK(conf.keys[pad][i]) || IS_JOYBUTTONS(conf.keys[pad][i]) ) { + joyid = PAD_GETJOYID(conf.keys[pad][i]); + break; + } + } + + if( joyid >= 0 && joyid < (int)s_vjoysticks.size() ) + s_vjoysticks[joyid]->Assign(pad); + } + +#endif +} + +JoystickInfo::JoystickInfo() +{ + bTerminateThread = false; + js_fd = -1; + _id = -1; + pad = -1; + axisrange = 0x7fff; +} + +void JoystickInfo::Destroy() +{ +#ifdef JOYSTICK_SUPPORT + if( js_fd >= 0 ) { + bTerminateThread = true; + void* ret; + pthread_join(pthreadpoll, &ret); + close(js_fd); + js_fd = -1; + } +#endif +} + +bool JoystickInfo::Init(const char* pdevid, int id, bool bStartThread) +{ +#ifdef JOYSTICK_SUPPORT + assert(pdevid != NULL ); + Destroy(); + + if ((js_fd = open(pdevid, O_RDONLY)) < 0) { + return false; + } + + char name[256]; + ioctl(js_fd, JSIOCGVERSION, &version); + + if (version < 0x010000) { + printf("joystick driver version is too old (%d)\n",version); + return false; + } + + char numaxes, numbuttons; + ioctl(js_fd, JSIOCGAXES, &numaxes); + ioctl(js_fd, JSIOCGBUTTONS, &numbuttons); + ioctl(js_fd, JSIOCGNAME(256), name); + + // set to non-blocking + int flags; + if (-1 == (flags = fcntl(js_fd, F_GETFL, 0))) + flags = 0; + if( fcntl(js_fd, F_SETFL, flags | O_NONBLOCK) < 0 ) + return false; + + if( numaxes >= 0 ) vaxes.resize(numaxes); + if( numbuttons >= 0 ) vbuttonstate.resize(numbuttons); + + devid = pdevid; + devname = name; + _id = id; + + if( bStartThread ) { + // create thread + if( pthread_create(&pthreadpoll, NULL, pollthread, this) ) { + printf("failed to create thread\n"); + close(js_fd); js_fd = -1; + return false; + } + } + return true; +#else + return false; +#endif +} + +void JoystickInfo::ProcessData() +{ + if( pad < 0 ) + return; + + for (int i=0; i2048) ) + status[pad] &= ~(1<= 0 ) { + for(int i = 0; i < PADKEYS; ++i) { + if( IS_JOYBUTTONS(conf.keys[pad][i]) ) { + conf.keys[pad][i] = PAD_JOYBUTTON(_id, PAD_GETJOYBUTTON(conf.keys[pad][i])); + } + else if( IS_JOYSTICK(conf.keys[pad][i]) ) { + conf.keys[pad][i] = PAD_JOYSTICK(_id, PAD_GETJOYBUTTON(conf.keys[pad][i])); + } + } + } +} + +void JoystickInfo::TestForce() +{ +#ifdef JOYSTICK_SUPPORT + // send a small force command + +#endif +} + +#ifdef JOYSTICK_SUPPORT + +void* JoystickInfo::pollthread(void* p) +{ + return ((JoystickInfo*)p)->_pollthread(); +} + +void* JoystickInfo::_pollthread() +{ + int ret; + js_event js; + while(!bTerminateThread) { + usleep(5000); // 10ms + + if( js_fd < 0 ) { + // try to recreate + if( Init(devid.c_str(), _id, false) ) { + printf("ZeroPAD: recreating joystick \"%s\"\n", devname.c_str()); + } + else continue; + } + + if ( (ret=read(js_fd, &js, sizeof(struct js_event))) != sizeof(struct js_event)) { + + if( errno == EBADF || errno == ENODEV ) { + // close and recreate + close(js_fd); js_fd = -1; + } + else if( errno != EINTR && errno != EAGAIN ) { + printf("error in reading joystick data: %d\n", errno); + } + continue; + } + + // ignore the startup events? + if( js.type & JS_EVENT_INIT ) { + continue; + } + + if ((js.type & ~JS_EVENT_INIT) == JS_EVENT_BUTTON) + vbuttonstate[js.number] = js.value; + + if( js.type == JS_EVENT_AXIS ) + vaxes[js.number] = js.value; + } + + return NULL; +} + +#endif diff --git a/plugins/pad/zeropad/support.c b/plugins/pad/zeropad/Linux/support.c similarity index 100% rename from plugins/pad/zeropad/support.c rename to plugins/pad/zeropad/Linux/support.c diff --git a/plugins/pad/zeropad/support.h b/plugins/pad/zeropad/Linux/support.h similarity index 100% rename from plugins/pad/zeropad/support.h rename to plugins/pad/zeropad/Linux/support.h diff --git a/plugins/pad/zeropad/zeropad.glade b/plugins/pad/zeropad/Linux/zeropad.glade similarity index 84% rename from plugins/pad/zeropad/zeropad.glade rename to plugins/pad/zeropad/Linux/zeropad.glade index d4426a0..08c54d6 100644 --- a/plugins/pad/zeropad/zeropad.glade +++ b/plugins/pad/zeropad/Linux/zeropad.glade @@ -91,7 +91,7 @@ and SSSPSXPad, TwinPad authors True 0 0.5 - GTK_SHADOW_NONE + GTK_SHADOW_ETCHED_IN @@ -186,6 +186,60 @@ and SSSPSXPad, TwinPad authors + + + True + False + 0 + + + + True + Joystick to use for this PAD + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + True + + False + True + True + + + + 0 + True + True + + + + + 0 + True + True + + + True @@ -532,7 +586,7 @@ and SSSPSXPad, TwinPad authors - 64 + 80 24 True True @@ -552,7 +606,7 @@ and SSSPSXPad, TwinPad authors - 64 + 80 24 True True @@ -565,14 +619,14 @@ and SSSPSXPad, TwinPad authors False - 176 + 160 352 - 64 + 80 24 True True @@ -592,7 +646,7 @@ and SSSPSXPad, TwinPad authors - 64 + 80 24 True True @@ -605,7 +659,7 @@ and SSSPSXPad, TwinPad authors False - 176 + 160 416 @@ -808,24 +862,6 @@ and SSSPSXPad, TwinPad authors - - - 64 - 32 - True - True - Right - True - GTK_RELIEF_NORMAL - True - - - - 128 - 176 - - - 64 @@ -844,122 +880,6 @@ and SSSPSXPad, TwinPad authors - - - 64 - 32 - True - True - R3 - True - GTK_RELIEF_NORMAL - True - - - - 272 - 240 - - - - - - 64 - 32 - True - True - Lx - True - GTK_RELIEF_NORMAL - True - - - - 176 - 320 - - - - - - 64 - 32 - True - True - Rx - True - GTK_RELIEF_NORMAL - True - - - - 272 - 320 - - - - - - 64 - 32 - True - True - Ly - True - GTK_RELIEF_NORMAL - True - - - - 176 - 384 - - - - - - 64 - 32 - True - True - Ry - True - GTK_RELIEF_NORMAL - True - - - - 272 - 384 - - - - - - 408 - 16 - True - Analog Controls (move mouse or analog joystick to select) - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - True - 0 - - - 56 - 296 - - - 64 @@ -1013,6 +933,246 @@ and SSSPSXPad, TwinPad authors 8 + + + + 80 + 32 + True + True + Lx + True + GTK_RELIEF_NORMAL + True + + + + 160 + 320 + + + + + + 80 + 32 + True + True + Ly + True + GTK_RELIEF_NORMAL + True + + + + 160 + 384 + + + + + + 80 + 32 + True + True + Rx + True + GTK_RELIEF_NORMAL + True + + + + 272 + 320 + + + + + + 80 + 32 + True + True + Ry + True + GTK_RELIEF_NORMAL + True + + + + 272 + 384 + + + + + + 64 + 32 + True + True + Right + True + GTK_RELIEF_NORMAL + True + + + + 128 + 176 + + + + + + 408 + 16 + True + Analog Controls (move mouse or analog joystick to select) + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + True + 0 + + + 48 + 296 + + + + + + 64 + 32 + True + True + R3 + True + GTK_RELIEF_NORMAL + True + + + + 272 + 240 + + + + + + 111 + 22 + True + True + Reverse LX + True + GTK_RELIEF_NORMAL + True + False + False + True + + + + 16 + 328 + + + + + + 111 + 22 + True + True + Reverse LY + True + GTK_RELIEF_NORMAL + True + False + False + True + + + + 16 + 352 + + + + + + 111 + 22 + True + True + Reverse RX + True + GTK_RELIEF_NORMAL + True + False + False + True + + + + 16 + 376 + + + + + + 111 + 22 + True + True + Reverse RY + True + GTK_RELIEF_NORMAL + True + False + False + True + + + + 16 + 400 + + + + + + 112 + 48 + True + True + Enable Force +Feedback + True + GTK_RELIEF_NORMAL + True + False + False + True + + + + 384 + 320 + + 0 diff --git a/plugins/pad/zeropad/Makefile.am b/plugins/pad/zeropad/Makefile.am index 1c89d46..3ee4bd5 100644 --- a/plugins/pad/zeropad/Makefile.am +++ b/plugins/pad/zeropad/Makefile.am @@ -26,4 +26,4 @@ libZeroPAD_LDFLAGS= @SHARED_LDFLAGS@ libZeroPAD_LDFLAGS+=-Wl,-soname,@ZEROPAD_SONAME@ libZeroPAD_LDADD=$(libZeroPAD_a_OBJECTS) -libZeroPAD_a_SOURCES = zeropad.cpp linux.cpp support.c interface.c \ No newline at end of file +libZeroPAD_a_SOURCES = zeropad.cpp Linux/linux.cpp Linux/support.c Linux/interface.c diff --git a/plugins/pad/zeropad/Windows/win.cpp b/plugins/pad/zeropad/Windows/win.cpp index 198c8c2..e7a7d48 100644 --- a/plugins/pad/zeropad/Windows/win.cpp +++ b/plugins/pad/zeropad/Windows/win.cpp @@ -1,4 +1,4 @@ -/* ZeroPAD +/* ZeroPAD - author: zerofrog(@gmail.com) * Copyright (C) 2006-2007 * * This program is free software; you can redistribute it and/or modify diff --git a/plugins/pad/zeropad/callbacks.h b/plugins/pad/zeropad/callbacks.h deleted file mode 100644 index 88121ff..0000000 --- a/plugins/pad/zeropad/callbacks.h +++ /dev/null @@ -1,22 +0,0 @@ -#include - - -void -OnConf_Key (GtkButton *button, - gpointer user_data); - -void -OnConf_Pad1 (GtkButton *button, - gpointer user_data); - -void -OnConf_Pad2 (GtkButton *button, - gpointer user_data); - -void -OnConf_Cancel (GtkButton *button, - gpointer user_data); - -void -OnConf_Ok (GtkButton *button, - gpointer user_data); diff --git a/plugins/pad/zeropad/configure.ac b/plugins/pad/zeropad/configure.ac index 7a452c4..cbcd79d 100644 --- a/plugins/pad/zeropad/configure.ac +++ b/plugins/pad/zeropad/configure.ac @@ -1,4 +1,4 @@ -AC_INIT(ZeroPAD,0.1,zerofrog@gmail.com) +AC_INIT(ZeroPAD,0.2,zerofrog@gmail.com) AM_INIT_AUTOMAKE(ZeroPAD,0.1) @@ -25,7 +25,6 @@ AC_SUBST(ZEROPAD_RELEASE) AC_SUBST(ZEROPAD_SONAME) CFLAGS= -CPPFLAGS= CXXFLAGS= dnl Check for debug build @@ -36,12 +35,10 @@ if test "x$debug" == xyes then AC_DEFINE(_DEBUG,1,[_DEBUG]) CFLAGS+="-g " - CPPFLAGS+="-g " CXXFLAGS+="-g " else AC_DEFINE(NDEBUG,1,[NDEBUG]) CFLAGS+="-O2 -fomit-frame-pointer " - CPPFLAGS+="-O2 -fomit-frame-pointer " CXXFLAGS+="-O2 -fomit-frame-pointer " fi AM_CONDITIONAL(DEBUGBUILD, test x$debug = xyes) @@ -81,7 +78,7 @@ AC_MSG_CHECKING(gtk2+) AC_CHECK_PROG(GTK_CONFIG, pkg-config, pkg-config) LIBS+=$(pkg-config --libs gtk+-2.0) -dnl bindir = pcsx2exe +AC_CHECK_HEADER([linux/joystick.h], [AC_DEFINE(JOYSTICK_SUPPORT,1)]) dnl assuming linux environment so_ext=".so.$ZEROPAD_RELEASE" diff --git a/plugins/pad/zeropad/linux.cpp b/plugins/pad/zeropad/linux.cpp deleted file mode 100644 index e402479..0000000 --- a/plugins/pad/zeropad/linux.cpp +++ /dev/null @@ -1,370 +0,0 @@ -/* ZeroPAD - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include -#include -#include - -#include "zeropad.h" - -extern "C" { -#include "interface.h" -#include "support.h" -#include "callbacks.h" -} - -Display *GSdsp; -static pthread_spinlock_t s_mutexStatus; -static u32 s_keyPress[2], s_keyRelease[2]; -extern u16 status[2]; - -extern string s_strIniPath; - -void SaveConfig() -{ - int i, j; - FILE *f; - char cfg[255]; - - strcpy(cfg, s_strIniPath.c_str()); - f = fopen(cfg,"w"); - if (f == NULL) { - printf("ZeroPAD: failed to save ini %s\n", s_strIniPath.c_str()); - return; - } - - for (j=0; j<2; j++) { - for (i=0; i<16; i++) { - fprintf(f, "[%d][%d] = 0x%lx\n", j, i, conf.keys[j][i]); - } - } - fprintf(f, "log = %d\n", conf.log); - fclose(f); -} - -static char* s_pGuiKeyMap[] = { "L2", "R2", "L1", "R1", - "Triangle", "Circle", "Cross", "Square", - "Select", "L3", "R3", "Start", - "Up", "Right", "Down", "Left", - "Lx", "Rx", "Ly", "Ry" }; - -string GetLabelFromButton(const char* buttonname) -{ - string label = "e"; - label += buttonname; - return label; -} - -void LoadConfig() { - FILE *f; - char str[256]; - char cfg[255]; - int i, j; - - memset(&conf, 0, sizeof(conf)); - conf.keys[0][0] = XK_a; // L2 - conf.keys[0][1] = XK_semicolon; // R2 - conf.keys[0][2] = XK_w; // L1 - conf.keys[0][3] = XK_p; // R1 - conf.keys[0][4] = XK_i; // TRIANGLE - conf.keys[0][5] = XK_l; // CIRCLE - conf.keys[0][6] = XK_k; // CROSS - conf.keys[0][7] = XK_j; // SQUARE - conf.keys[0][8] = XK_v; // SELECT - conf.keys[0][11] = XK_n;// START - conf.keys[0][12] = XK_e; // UP - conf.keys[0][13] = XK_f; // RIGHT - conf.keys[0][14] = XK_d; // DOWN - conf.keys[0][15] = XK_s; // LEFT - conf.log = 0; - - strcpy(cfg, s_strIniPath.c_str()); - f = fopen(cfg, "r"); - if (f == NULL) { - printf("ZeroPAD: failed to load ini %s\n", s_strIniPath.c_str()); - SaveConfig();//save and return - return; - } - - for (j=0; j<2; j++) { - for (i=0; i<16; i++) { - sprintf(str, "[%d][%d] = 0x%%x\n", j, i); - fscanf(f, str, &conf.keys[j][i]); - } - } - fscanf(f, "log = %d\n", &conf.log); - fclose(f); -} - -GtkWidget *MsgDlg; - -void OnMsg_Ok() { - gtk_widget_destroy(MsgDlg); - gtk_main_quit(); -} - -void SysMessage(char *fmt, ...) { - GtkWidget *Ok,*Txt; - GtkWidget *Box,*Box1; - va_list list; - char msg[512]; - - va_start(list, fmt); - vsprintf(msg, fmt, list); - va_end(list); - - if (msg[strlen(msg)-1] == '\n') msg[strlen(msg)-1] = 0; - - MsgDlg = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_position(GTK_WINDOW(MsgDlg), GTK_WIN_POS_CENTER); - gtk_window_set_title(GTK_WINDOW(MsgDlg), "GSsoft Msg"); - gtk_container_set_border_width(GTK_CONTAINER(MsgDlg), 5); - - Box = gtk_vbox_new(5, 0); - gtk_container_add(GTK_CONTAINER(MsgDlg), Box); - gtk_widget_show(Box); - - Txt = gtk_label_new(msg); - - gtk_box_pack_start(GTK_BOX(Box), Txt, FALSE, FALSE, 5); - gtk_widget_show(Txt); - - Box1 = gtk_hbutton_box_new(); - gtk_box_pack_start(GTK_BOX(Box), Box1, FALSE, FALSE, 0); - gtk_widget_show(Box1); - - Ok = gtk_button_new_with_label("Ok"); - gtk_signal_connect (GTK_OBJECT(Ok), "clicked", GTK_SIGNAL_FUNC(OnMsg_Ok), NULL); - gtk_container_add(GTK_CONTAINER(Box1), Ok); - GTK_WIDGET_SET_FLAGS(Ok, GTK_CAN_DEFAULT); - gtk_widget_show(Ok); - - gtk_widget_show(MsgDlg); - - gtk_main(); -} - -s32 _PADopen(void *pDsp) -{ - GSdsp = *(Display**)pDsp; - pthread_spin_init(&s_mutexStatus, PTHREAD_PROCESS_PRIVATE); - s_keyPress[0] = s_keyPress[1] = 0; - s_keyRelease[0] = s_keyRelease[1] = 0; - XAutoRepeatOff(GSdsp); - return 0; -} - -void _PADclose() -{ - pthread_spin_destroy(&s_mutexStatus); - XAutoRepeatOn(GSdsp); -} - -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 CALLBACK PADupdate(int pad) -{ - int i; - XEvent E; - int keyPress=0,keyRelease=0; - KeySym key; - - while (XPending(GSdsp) > 0) { - XNextEvent(GSdsp, &E); - switch (E.type) { - case KeyPress: - //_KeyPress(pad, XLookupKeysym((XKeyEvent *)&E, 0)); break; - key = XLookupKeysym((XKeyEvent *)&E, 0); - for (i=0; itype == GDK_KEY_PRESS) { - *key = ev->key.keyval; - - char* tmp = XKeysymToString(*key); - if (tmp != NULL) - gtk_entry_set_text(GTK_ENTRY(label), tmp); - else - gtk_entry_set_text(GTK_ENTRY(label), "Unknown"); - return; - } - } - } -} - -void OnConf_Pad1(GtkButton *button, gpointer user_data) -{ - if( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)) ) - UpdateConf(0); -} - -void OnConf_Pad2(GtkButton *button, gpointer user_data) -{ - if( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)) ) - UpdateConf(1); -} - -void OnConf_Ok(GtkButton *button, gpointer user_data) -{ -// conf.analog = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(Analog)); - SaveConfig(); - - gtk_widget_destroy(Conf); - gtk_main_quit(); -} - -void OnConf_Cancel(GtkButton *button, gpointer user_data) -{ - gtk_widget_destroy(Conf); - gtk_main_quit(); -} - -void CALLBACK PADconfigure() { - LoadConfig(); - - Conf = create_Conf(); - -// Analog = lookup_widget(Conf, "GtkCheckButton_Analog"); -// gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(Analog), conf.analog); - - UpdateConf(0); - - gtk_widget_show_all(Conf); - gtk_main(); -} - -GtkWidget *About; - -void OnAbout_Ok(GtkButton *button, gpointer user_data) -{ - gtk_widget_destroy(About); - gtk_main_quit(); -} - -void CALLBACK PADabout() { - - About = create_About(); - - gtk_widget_show_all(About); - gtk_main(); -} - -s32 CALLBACK PADtest() { - return 0; -} diff --git a/plugins/pad/zeropad/zeropad.cpp b/plugins/pad/zeropad/zeropad.cpp index 1b5a338..36a85cf 100644 --- a/plugins/pad/zeropad/zeropad.cpp +++ b/plugins/pad/zeropad/zeropad.cpp @@ -1,4 +1,4 @@ -/* ZeroPAD +/* ZeroPAD - author: zerofrog(@gmail.com) * Copyright (C) 2006-2007 * * This program is free software; you can redistribute it and/or modify @@ -34,7 +34,7 @@ char *libraryName = "ZeroPAD (Debug) "; char *libraryName = "ZeroPAD "; #endif -Analog lanalog[2], ranalog[2]; +PADAnalog g_lanalog[2], g_ranalog[2]; PADconf conf; keyEvent event; @@ -45,7 +45,7 @@ string s_strIniPath="inis/zeropad.ini"; const unsigned char version = PS2E_PAD_VERSION; const unsigned char revision = 0; -const unsigned char build = 1; // increase that with each version +const unsigned char build = 2; // increase that with each version u32 pads=0; @@ -186,12 +186,10 @@ s32 CALLBACK PADinit(u32 flags) { pressure = 100; for(int i = 0; i < 2; ++i) { - ranalog[i].x = 0x80; - ranalog[i].y = 0x80; - ranalog[i].button = 0; - lanalog[i].x = 0x80; - lanalog[i].y = 0x80; - lanalog[i].button = 0; + g_ranalog[i].x = 0x80; + g_ranalog[i].y = 0x80; + g_lanalog[i].x = 0x80; + g_lanalog[i].y = 0x80; } return 0; @@ -282,21 +280,13 @@ u8 _PADpoll(u8 value) { case 0x42: // READ_DATA _PADupdate(curPad); - - if(lanalog[curPad].button) status[curPad] &= ~(1<<9); - else status[curPad] |= (1<<9); - if(ranalog[curPad].button) status[curPad] &= ~(1<<10); - else status[curPad] |= (1<<10); - - lanalog[curPad].button = 0; // reset them :p (l3) - ranalog[curPad].button = 0; // reset them :P (r3) - + stdpar[curPad][2] = status[curPad] >> 8; stdpar[curPad][3] = status[curPad] & 0xff; - stdpar[curPad][4] = ranalog[curPad].x; - stdpar[curPad][5] = ranalog[curPad].y; - stdpar[curPad][6] = lanalog[curPad].x; - stdpar[curPad][7] = lanalog[curPad].y; + stdpar[curPad][4] = g_ranalog[curPad].x+128; + stdpar[curPad][5] = g_ranalog[curPad].y+128; + stdpar[curPad][6] = g_lanalog[curPad].x+128; + stdpar[curPad][7] = g_lanalog[curPad].y+128; if (padMode[curPad] == 1) cmdLen = 20; else cmdLen = 4; button_check2 = stdpar[curPad][2] >> 4; diff --git a/plugins/pad/zeropad/zeropad.h b/plugins/pad/zeropad/zeropad.h index 588fbdf..d749ba2 100644 --- a/plugins/pad/zeropad/zeropad.h +++ b/plugins/pad/zeropad/zeropad.h @@ -1,4 +1,4 @@ -/* ZeroPAD +/* ZeroPAD - author: zerofrog(@gmail.com) * Copyright (C) 2006-2007 * * This program is free software; you can redistribute it and/or modify @@ -47,47 +47,67 @@ extern "C" { extern char *libraryName; -#define PAD_GETKEY(key) (key&0xffff) +#define FORIT(it, v) for(it = (v).begin(); it != (v).end(); (it)++) + #define IS_KEYBOARD(key) (key<0x10000) -#define IS_JOYBUTTONS(key) (key>=0x10000 && key<0x20000) -#define IS_JOYSTICK(key) (key>=0x20000&&key<0x30000) -#define IS_POV(key) (key>=0x30000&&key<0x40000) -#define IS_MOUSE(key) (key>=0x40000&&key<0x50000) +#define IS_JOYBUTTONS(key) (key>=0x10000 && key<0x20000) // buttons +#define IS_JOYSTICK(key) (key>=0x20000&&key<0x30000) // analog +#define IS_POV(key) (key>=0x30000&&key<0x40000) // uses analog as buttons (cares about sign) +#define IS_MOUSE(key) (key>=0x40000&&key<0x50000) // mouse + +#define PAD_GETKEY(key) ((key)&0xffff) +#define PAD_GETJOYID(key) (((key)&0xf000)>>12) +#define PAD_GETJOYBUTTON(key) ((key)&0xff) +#define PAD_GETJOYSTICK_AXIS(key) ((key)&0xff) +#define PAD_JOYBUTTON(joyid, buttonid) (0x10000|((joyid)<<12)|(buttonid)) +#define PAD_JOYSTICK(joyid, axisid) (0x20000|((joyid)<<12)|(axisid)) +#define PAD_POV(joyid, sign, axisid) (0x30000|((joyid)<<12)|((sign)<<8)|(axisid)) +#define PAD_GETPOVSIGN(key) (((key)&0x100)>>8) #define PADKEYS 20 +#define PADOPTION_FORCEFEEDBACK 1 +#define PADOPTION_REVERTLX 0x2 +#define PADOPTION_REVERTLY 0x4 +#define PADOPTION_REVERTRX 0x8 +#define PADOPTION_REVERTRY 0x10 + typedef struct { unsigned long keys[2][PADKEYS]; int log; + int options; // upper 16 bits are for pad2 } PADconf; typedef struct { u8 x,y; - u8 button; -} Analog; +} PADAnalog; extern PADconf conf; -extern Analog lanalog[2], ranalog[2]; +extern PADAnalog g_lanalog[2], g_ranalog[2]; extern FILE *padLog; #define PAD_LOG __Log -#define PAD_LEFT 0x8000 -#define PAD_DOWN 0x4000 -#define PAD_RIGHT 0x2000 -#define PAD_UP 0x1000 -#define PAD_START 0x0800 -#define PAD_R3 0x0400 -#define PAD_L3 0x0200 -#define PAD_SELECT 0x0100 -#define PAD_SQUARE 0x0080 -#define PAD_CROSS 0x0040 -#define PAD_CIRCLE 0x0020 -#define PAD_TRIANGLE 0x0010 -#define PAD_R1 0x0008 -#define PAD_L1 0x0004 -#define PAD_R2 0x0002 -#define PAD_L2 0x0001 +#define PAD_RY 19 +#define PAD_LY 18 +#define PAD_RX 17 +#define PAD_LX 16 +#define PAD_LEFT 15 +#define PAD_DOWN 14 +#define PAD_RIGHT 13 +#define PAD_UP 12 +#define PAD_START 11 +#define PAD_R3 10 +#define PAD_L3 9 +#define PAD_SELECT 8 +#define PAD_SQUARE 7 +#define PAD_CROSS 6 +#define PAD_CIRCLE 5 +#define PAD_TRIANGLE 4 +#define PAD_R1 3 +#define PAD_L1 2 +#define PAD_R2 1 +#define PAD_L2 0 /* end of pad.h */ diff --git a/plugins/spu2/PeopsSPU2/build.sh b/plugins/spu2/PeopsSPU2/build.sh index 68f23fd..c228930 100644 --- a/plugins/spu2/PeopsSPU2/build.sh +++ b/plugins/spu2/PeopsSPU2/build.sh @@ -13,4 +13,8 @@ then exit 1 fi -cp libspu2Peops*.so* ${PCSX2PLUGINS} +if [ -s libspu2Peops*.so* ] +then +cp libspu2Peops*.so* ${PCSX2PLUGINS} +fi + diff --git a/plugins/spu2/SPU2null/Src/Makefile b/plugins/spu2/SPU2null/Src/Makefile index ee703e9..fc6bebe 100644 --- a/plugins/spu2/SPU2null/Src/Makefile +++ b/plugins/spu2/SPU2null/Src/Makefile @@ -22,4 +22,4 @@ clean: %.o: %.cpp ${CC} ${CFLAGS} -c -o $@ $< -MD -MF $(patsubst %.o,%.d,$@) --include ${DEPS} +#-include ${DEPS} diff --git a/plugins/usb/USBnull/Linux/Makefile b/plugins/usb/USBnull/Linux/Makefile index 24d378a..bcf7a48 100644 --- a/plugins/usb/USBnull/Linux/Makefile +++ b/plugins/usb/USBnull/Linux/Makefile @@ -32,4 +32,4 @@ clean: %.o: %.c ${CC} ${CFLAGS} -c -o $@ $< -MD -MF $(patsubst %.o,%.d,$@) --include ${DEPS} +#-include ${DEPS}