diff --git a/plugins/zeropad/Linux/linux.cpp b/plugins/zeropad/Linux/linux.cpp index d14aebbe60..67afc24340 100644 --- a/plugins/zeropad/Linux/linux.cpp +++ b/plugins/zeropad/Linux/linux.cpp @@ -1,5 +1,5 @@ /* ZeroPAD - author: zerofrog(@gmail.com) - * Copyright (C) 2006-2007 + * 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 @@ -27,7 +27,8 @@ #include "zeropad.h" -extern "C" { +extern "C" +{ #include "interface.h" #include "support.h" #include "callbacks.h" @@ -41,48 +42,87 @@ static u32 s_bSDLInit = false; // 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(int id, bool bStartThread=true); // opens a handle and gets information - void Assign(int pad); // assigns a joystick to a pad + public: + JoystickInfo(); + ~JoystickInfo() + { + Destroy(); + } - void TestForce(); + void Destroy(); + // opens handles to all possible joysticks + static void EnumerateJoysticks(vector& vjoysticks); - const string& GetName() { return devname; } - int GetNumButtons() { return numbuttons; } - int GetNumAxes() { return numaxes; } - int GetNumPOV() { return numpov; } - int GetId() { return _id; } - int GetPAD() { return pad; } - int GetDeadzone(int axis) { return deadzone; } + bool Init(int id, bool bStartThread = true); // opens a handle and gets information + void Assign(int pad); // assigns a joystick to a pad - void SaveState(); - int GetButtonState(int i) { return vbutstate[i]; } - int GetAxisState(int i) { return vaxisstate[i]; } - void SetButtonState(int i, int state) { vbutstate[i] = state; } - void SetAxisState(int i, int value) { vaxisstate[i] = value; } + void TestForce(); + + const string& GetName() + { + return devname; + } + int GetNumButtons() + { + return numbuttons; + } + int GetNumAxes() + { + return numaxes; + } + int GetNumPOV() + { + return numpov; + } + int GetId() + { + return _id; + } + int GetPAD() + { + return pad; + } + int GetDeadzone(int axis) + { + return deadzone; + } + + void SaveState(); + int GetButtonState(int i) + { + return vbutstate[i]; + } + int GetAxisState(int i) + { + return vaxisstate[i]; + } + void SetButtonState(int i, int state) + { + vbutstate[i] = state; + } + void SetAxisState(int i, int value) + { + vaxisstate[i] = value; + } #ifdef JOYSTICK_SUPPORT - SDL_Joystick* GetJoy() { return joy; } + SDL_Joystick* GetJoy() + { + return joy; + } #endif -private: + private: + + string devname; // pretty device name + int _id; + int numbuttons, numaxes, numpov; + int axisrange, deadzone; + int pad; + + vector vbutstate, vaxisstate; - string devname; // pretty device name - int _id; - int numbuttons, numaxes, numpov; - int axisrange, deadzone; - int pad; - - vector vbutstate, vaxisstate; - #ifdef JOYSTICK_SUPPORT - SDL_Joystick* joy; + SDL_Joystick* joy; #endif }; @@ -92,41 +132,48 @@ extern string s_strIniPath; void SaveConfig() { - int i, j; - FILE *f; - char cfg[255]; + 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 * PADSUBKEYS; j++) { - for (i=0; i::iterator it; - FORIT(it, s_vjoysticks) delete *it; - s_vjoysticks.clear(); + vector::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); + 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 p = 0; p < PADSUBKEYS; p++) { - for(int i = 0; i < PADKEYS; ++i) { - if (IS_JOYSTICK(conf.keys[(PadEnum[pad][p])][i]) || IS_JOYBUTTONS(conf.keys[(PadEnum[pad][p])][i])) { - joyid = PAD_GETJOYID(conf.keys[(PadEnum[pad][p])][i]); + + for (int p = 0; p < PADSUBKEYS; p++) + { + for (int i = 0; i < PADKEYS; ++i) + { + if (IS_JOYSTICK(conf.keys[(PadEnum[pad][p])][i]) || IS_JOYBUTTONS(conf.keys[(PadEnum[pad][p])][i])) + { + joyid = PAD_GETJOYID(conf.keys[(PadEnum[pad][p])][i]); return joyid; - } + } } } } void CALLBACK PADupdate(int pad) { - int i; - XEvent E; - int keyPress=0,keyRelease=0; - KeySym key; + int i; + XEvent E; + int keyPress = 0, keyRelease = 0; + KeySym key; - // keyboard input - while (XPending(GSdsp) > 0) { + // keyboard input + while (XPending(GSdsp) > 0) + { XNextEvent(GSdsp, &E); - switch (E.type) { - case KeyPress: - key = XLookupKeysym((XKeyEvent *)&E, 0); + switch (E.type) + { + case KeyPress: + key = XLookupKeysym((XKeyEvent *) & E, 0); -#ifdef ANALOG_CONTROLS_HACK - switch(key) { - case KEY_PAD_LX_LEFT: - g_lanalog[pad].x = DEF_VALUE/256; - if( conf.options&PADOPTION_REVERTLX ) - g_lanalog[pad].x = -g_lanalog[pad].x; - g_lanalog[pad].x += 0x80; - break; - case KEY_PAD_LX_RIGHT: - g_lanalog[pad].x = -DEF_VALUE/256; - if( conf.options&PADOPTION_REVERTLX ) - g_lanalog[pad].x = -g_lanalog[pad].x; - g_lanalog[pad].x += 0x80; - break; - case KEY_PAD_LY_UP: - g_lanalog[pad].y = DEF_VALUE/256; - if( conf.options&PADOPTION_REVERTLY ) - g_lanalog[pad].y = -g_lanalog[pad].y; - g_lanalog[pad].y += 0x80; - break; - case KEY_PAD_LY_DOWN: - g_lanalog[pad].y = -DEF_VALUE/256; - if( conf.options&PADOPTION_REVERTLY ) - g_lanalog[pad].y = -g_lanalog[pad].y; - g_lanalog[pad].y += 0x80; - break; - case KEY_PAD_RX_LEFT: - g_ranalog[pad].x = DEF_VALUE/256; - if( conf.options&PADOPTION_REVERTRX ) - g_ranalog[pad].x = -g_ranalog[pad].x; - g_ranalog[pad].x += 0x80; - break; - case KEY_PAD_RX_RIGHT: - g_ranalog[pad].x = -DEF_VALUE/256; - if( conf.options&PADOPTION_REVERTRX ) - g_ranalog[pad].x = -g_ranalog[pad].x; - g_ranalog[pad].x += 0x80; - break; - case KEY_PAD_RY_UP: - g_ranalog[pad].y = DEF_VALUE/256; - if( conf.options&PADOPTION_REVERTRY ) - g_ranalog[pad].y = -g_ranalog[pad].y; - g_ranalog[pad].y += 0x80; - break; - case KEY_PAD_RY_DOWN: - g_ranalog[pad].y = -DEF_VALUE/256; - if( conf.options&PADOPTION_REVERTRY ) - g_ranalog[pad].y = -g_ranalog[pad].y; - g_ranalog[pad].y += 0x80; - break; - } -#endif - - i = FindKey(key, pad); - keyPress |= (1 << i); - keyRelease &= ~(1 << i); - - event.evt = KEYPRESS; - event.key = key; - break; - case KeyRelease: - key = XLookupKeysym((XKeyEvent *)&E, 0); - #ifdef ANALOG_CONTROLS_HACK - switch(key) { - case KEY_PAD_LX_LEFT: - g_lanalog[pad].x = 0x80; - break; - case KEY_PAD_LY_UP: - g_lanalog[pad].y = 0x80; - break; - case KEY_PAD_RX_LEFT: - g_ranalog[pad].x = 0x80; - break; - case KEY_PAD_RY_UP: - g_ranalog[pad].y = 0x80; - break; - case KEY_PAD_LX_RIGHT: - g_lanalog[pad].x = 0x80; - break; - case KEY_PAD_LY_DOWN: - g_lanalog[pad].y = 0x80; - break; - case KEY_PAD_RX_RIGHT: - g_ranalog[pad].x = 0x80; - break; - case KEY_PAD_RY_DOWN: - g_ranalog[pad].y = 0x80; - break; - } + switch (key) + { + case KEY_PAD_LX_LEFT: + g_lanalog[pad].x = DEF_VALUE / 256; + if (conf.options&PADOPTION_REVERTLX) g_lanalog[pad].x = -g_lanalog[pad].x; + g_lanalog[pad].x += 0x80; + break; + case KEY_PAD_LX_RIGHT: + g_lanalog[pad].x = -DEF_VALUE / 256; + if (conf.options&PADOPTION_REVERTLX) g_lanalog[pad].x = -g_lanalog[pad].x; + g_lanalog[pad].x += 0x80; + break; + case KEY_PAD_LY_UP: + g_lanalog[pad].y = DEF_VALUE / 256; + if (conf.options&PADOPTION_REVERTLY) g_lanalog[pad].y = -g_lanalog[pad].y; + g_lanalog[pad].y += 0x80; + break; + case KEY_PAD_LY_DOWN: + g_lanalog[pad].y = -DEF_VALUE / 256; + if (conf.options&PADOPTION_REVERTLY) g_lanalog[pad].y = -g_lanalog[pad].y; + g_lanalog[pad].y += 0x80; + break; + case KEY_PAD_RX_LEFT: + g_ranalog[pad].x = DEF_VALUE / 256; + if (conf.options&PADOPTION_REVERTRX) g_ranalog[pad].x = -g_ranalog[pad].x; + g_ranalog[pad].x += 0x80; + break; + case KEY_PAD_RX_RIGHT: + g_ranalog[pad].x = -DEF_VALUE / 256; + if (conf.options&PADOPTION_REVERTRX) g_ranalog[pad].x = -g_ranalog[pad].x; + g_ranalog[pad].x += 0x80; + break; + case KEY_PAD_RY_UP: + g_ranalog[pad].y = DEF_VALUE / 256; + if (conf.options&PADOPTION_REVERTRY) g_ranalog[pad].y = -g_ranalog[pad].y; + g_ranalog[pad].y += 0x80; + break; + case KEY_PAD_RY_DOWN: + g_ranalog[pad].y = -DEF_VALUE / 256; + if (conf.options&PADOPTION_REVERTRY) g_ranalog[pad].y = -g_ranalog[pad].y; + g_ranalog[pad].y += 0x80; + break; + } #endif - - i = FindKey(key, pad); - keyPress &= ~(1<= 0 && joyid < (int)s_vjoysticks.size()) { - pjoy = s_vjoysticks[joyid]; - if( SDL_JoystickGetButton((pjoy)->GetJoy(), PAD_GETJOYBUTTON(key)) ) { - status[(pjoy)->GetPAD()] &= ~(1<GetPAD()] |= (1<= 0 && joyid < (int)s_vjoysticks.size()) + { + pjoy = s_vjoysticks[joyid]; + + if (SDL_JoystickGetButton((pjoy)->GetJoy(), PAD_GETJOYBUTTON(key))) + status[(pjoy)->GetPAD()] &= ~(1 << i); // pressed + else + status[(pjoy)->GetPAD()] |= (1 << i); // pressed } - } - else if( IS_JOYSTICK(key) ) { - int joyid = PAD_GETJOYID(key); - if( joyid >= 0 && joyid < (int)s_vjoysticks.size()) { + } + else if (IS_JOYSTICK(key)) + { + int joyid = PAD_GETJOYID(key); + if (joyid >= 0 && joyid < (int)s_vjoysticks.size()) + { - pjoy = s_vjoysticks[joyid]; - int value = SDL_JoystickGetAxis((pjoy)->GetJoy(), PAD_GETJOYSTICK_AXIS(key)); - int pad = (pjoy)->GetPAD(); - switch(i) { - case PAD_LX: - if( abs(value) > (pjoy)->GetDeadzone(value) ) { - g_lanalog[pad].x = value/256; - if( conf.options&PADOPTION_REVERTLX ) - g_lanalog[pad].x = -g_lanalog[pad].x; - g_lanalog[pad].x += 0x80; - } - else g_lanalog[pad].x = 0x80; - break; - case PAD_LY: - if( abs(value) > (pjoy)->GetDeadzone(value) ) { - g_lanalog[pad].y = value/256; - if( conf.options&PADOPTION_REVERTLX ) - g_lanalog[pad].y = -g_lanalog[pad].y; - g_lanalog[pad].y += 0x80; - } - else g_lanalog[pad].y = 0x80; - break; - case PAD_RX: - if( abs(value) > (pjoy)->GetDeadzone(value) ) { - g_ranalog[pad].x = value/256; - if( conf.options&PADOPTION_REVERTLX ) - g_ranalog[pad].x = -g_ranalog[pad].x; - g_ranalog[pad].x += 0x80; - } - else g_ranalog[pad].x = 0x80; - break; - case PAD_RY: - if( abs(value) > (pjoy)->GetDeadzone(value) ) { - g_ranalog[pad].y = value/256; - if( conf.options&PADOPTION_REVERTLX ) - g_ranalog[pad].y = -g_ranalog[pad].y; - g_ranalog[pad].y += 0x80; - } - else g_ranalog[pad].y = 0x80; - break; - } - } - } - else if( IS_POV(key) ) { - int joyid = PAD_GETJOYID(key); - if( joyid >= 0 && joyid < (int)s_vjoysticks.size()) { + pjoy = s_vjoysticks[joyid]; + int value = SDL_JoystickGetAxis((pjoy)->GetJoy(), PAD_GETJOYSTICK_AXIS(key)); + int pad = (pjoy)->GetPAD(); + switch (i) + { + case PAD_LX: + if (abs(value) > (pjoy)->GetDeadzone(value)) + { + g_lanalog[pad].x = value / 256; + if (conf.options&PADOPTION_REVERTLX) + g_lanalog[pad].x = -g_lanalog[pad].x; + g_lanalog[pad].x += 0x80; + } + else + { + g_lanalog[pad].x = 0x80; + } + break; + case PAD_LY: + if (abs(value) > (pjoy)->GetDeadzone(value)) + { + g_lanalog[pad].y = value / 256; + if (conf.options&PADOPTION_REVERTLX) + g_lanalog[pad].y = -g_lanalog[pad].y; + g_lanalog[pad].y += 0x80; + } + else + { + g_lanalog[pad].y = 0x80; + } + break; + case PAD_RX: + if (abs(value) > (pjoy)->GetDeadzone(value)) + { + g_ranalog[pad].x = value / 256; + if (conf.options&PADOPTION_REVERTLX) + g_ranalog[pad].x = -g_ranalog[pad].x; + g_ranalog[pad].x += 0x80; + } + else + { + g_ranalog[pad].x = 0x80; + } + break; + case PAD_RY: + if (abs(value) > (pjoy)->GetDeadzone(value)) + { + g_ranalog[pad].y = value / 256; + if (conf.options&PADOPTION_REVERTLX) g_ranalog[pad].y = -g_ranalog[pad].y; + g_ranalog[pad].y += 0x80; + } + else + { + g_ranalog[pad].y = 0x80; + } + break; + } + } + } + else if (IS_POV(key)) + { + int joyid = PAD_GETJOYID(key); + if (joyid >= 0 && joyid < (int)s_vjoysticks.size()) + { + pjoy = s_vjoysticks[joyid]; - pjoy = s_vjoysticks[joyid]; - - int value = SDL_JoystickGetAxis((pjoy)->GetJoy(), PAD_GETJOYSTICK_AXIS(key)); - int pad = (pjoy)->GetPAD(); - if( PAD_GETPOVSIGN(key) && (value<-2048) ) - status[pad] &= ~(1<2048) ) - status[pad] &= ~(1<GetJoy(), PAD_GETJOYSTICK_AXIS(key)); + int pad = (pjoy)->GetPAD(); + if (PAD_GETPOVSIGN(key) && (value < -2048)) + status[pad] &= ~(1 << i); + else if (!PAD_GETPOVSIGN(key) && (value > 2048)) + status[pad] &= ~(1 << i); + else + status[pad] |= (1 << i); + } + } + } #endif - - 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); + + 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 GtkWidget *Conf = NULL, *s_devicecombo = NULL; static int s_selectedpad = 0; void UpdateConf(int pad) @@ -489,186 +565,204 @@ void UpdateConf(int pad) int i; GtkWidget *Btn; - for (i=0; i 0) { - gtk_entry_set_text(GTK_ENTRY(Btn), tmp.c_str()); - } + if (tmp.size() > 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)); + 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 + // 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; + } + } - 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); + if (joyid >= 0 && joyid < (int)s_vjoysticks.size()) + gtk_combo_box_set_active(GTK_COMBO_BOX(s_devicecombo), joyid); // select the combo + 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)(uptr)gtk_object_get_user_data(GTK_OBJECT(label)); - int pad = id/PADKEYS; - int key = id%PADKEYS; - unsigned long *pkey = &conf.keys[pad][key]; + 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; + } - vector::iterator itjoy; + int id = (int)(uptr)gtk_object_get_user_data(GTK_OBJECT(label)); + int pad = id / PADKEYS; + int key = id % PADKEYS; + unsigned long *pkey = &conf.keys[pad][key]; - // save the states + vector::iterator itjoy; + + // save the states #ifdef JOYSTICK_SUPPORT - SDL_JoystickUpdate(); - FORIT(itjoy, s_vjoysticks) (*itjoy)->SaveState(); + SDL_JoystickUpdate(); + FORIT(itjoy, s_vjoysticks)(*itjoy)->SaveState(); #endif - - 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) + 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 + else gtk_entry_set_text(GTK_ENTRY(label), "Unknown"); return; } - } + } #ifdef JOYSTICK_SUPPORT - SDL_JoystickUpdate(); - FORIT(itjoy, s_vjoysticks) { + SDL_JoystickUpdate(); + FORIT(itjoy, s_vjoysticks) + { + // MAKE sure to look for changes in the state!! + for (int i = 0; i < (*itjoy)->GetNumButtons(); ++i) + { + int but = SDL_JoystickGetButton((*itjoy)->GetJoy(), i); + if (but != (*itjoy)->GetButtonState(i)) + { + if (!but) // released, we don't really want this + { + (*itjoy)->SetButtonState(i, 0); + break; + } - // MAKE sure to look for changes in the state!! - - for(int i = 0; i < (*itjoy)->GetNumButtons(); ++i) { - int but = SDL_JoystickGetButton((*itjoy)->GetJoy(), i); - if( but != (*itjoy)->GetButtonState(i) ) { + *pkey = PAD_JOYBUTTON((*itjoy)->GetId(), i); + char str[32]; + sprintf(str, "JBut %d", i); + gtk_entry_set_text(GTK_ENTRY(label), str); + return; + } + } - if( !but ) { // released, we don't really want this - (*itjoy)->SetButtonState(i, 0); - break; - } + for (int i = 0; i < (*itjoy)->GetNumAxes(); ++i) + { + int value = SDL_JoystickGetAxis((*itjoy)->GetJoy(), i); - *pkey = PAD_JOYBUTTON((*itjoy)->GetId(), i); - char str[32]; - sprintf(str, "JBut %d", i); - gtk_entry_set_text(GTK_ENTRY(label), str); - return; - } - } + if (value != (*itjoy)->GetAxisState(i)) + { - for(int i = 0; i < (*itjoy)->GetNumAxes(); ++i) { - int value = SDL_JoystickGetAxis((*itjoy)->GetJoy(), i); + if (abs(value) <= (*itjoy)->GetAxisState(i)) // we don't want this + { + // released, we don't really want this + (*itjoy)->SetButtonState(i, value); + break; + } - if( value != (*itjoy)->GetAxisState(i) ) { - if( abs(value) <= (*itjoy)->GetAxisState(i)) {// we don't want this - // released, we don't really want this - (*itjoy)->SetButtonState(i, value); - break; - } - - - if( abs(value) > 0x3fff ) { - if( key < 16 ) { // POV - *pkey = PAD_POV((*itjoy)->GetId(), value<0, i); - char str[32]; - sprintf(str, "JPOV %d%s", i, value<0?"-":"+"); - gtk_entry_set_text(GTK_ENTRY(label), str); - return; - } - else { // axis - *pkey = PAD_JOYSTICK((*itjoy)->GetId(), i); - char str[32]; - sprintf(str, "JAxis %d", i); - gtk_entry_set_text(GTK_ENTRY(label), str); - return; - } - } - } - } - } + if (abs(value) > 0x3fff) + { + if (key < 16) // POV + { + *pkey = PAD_POV((*itjoy)->GetId(), value < 0, i); + char str[32]; + sprintf(str, "JPOV %d%s", i, value < 0 ? "-" : "+"); + gtk_entry_set_text(GTK_ENTRY(label), str); + return; + } + else // axis + { + *pkey = PAD_JOYSTICK((*itjoy)->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); + 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); + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) + UpdateConf(1); } void OnConf_Pad3(GtkButton *button, gpointer user_data) { - if( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)) ) - UpdateConf(2); + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) + UpdateConf(2); } void OnConf_Pad4(GtkButton *button, gpointer user_data) { - if( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)) ) - UpdateConf(3); + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) + UpdateConf(3); } void OnConf_Ok(GtkButton *button, gpointer user_data) @@ -684,7 +778,7 @@ void OnConf_Cancel(GtkButton *button, gpointer user_data) { gtk_widget_destroy(Conf); gtk_main_quit(); - LoadConfig(); // load previous config + LoadConfig(); // load previous config } void CALLBACK PADconfigure() @@ -693,86 +787,99 @@ void CALLBACK PADconfigure() getcwd(strcurdir, 256); s_strIniPath = strcurdir; s_strIniPath += "/inis/zeropad.ini"; - + LoadConfig(); Conf = create_Conf(); - // recreate - JoystickInfo::EnumerateJoysticks(s_vjoysticks); + // recreate + JoystickInfo::EnumerateJoysticks(s_vjoysticks); - s_devicecombo = lookup_widget(Conf, "joydevicescombo"); + 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, pov: %d", (*it)->GetId(), (*it)->GetName().c_str(), - (*it)->GetNumButtons(), (*it)->GetNumAxes(), (*it)->GetNumPOV()); - gtk_combo_box_append_text (GTK_COMBO_BOX (s_devicecombo), str); - } - gtk_combo_box_append_text (GTK_COMBO_BOX (s_devicecombo), "No Gamepad"); + // fill the combo + char str[255]; + vector::iterator it; + + FORIT(it, s_vjoysticks) + { + sprintf(str, "%d: %s - but: %d, axes: %d, pov: %d", (*it)->GetId(), (*it)->GetName().c_str(), + (*it)->GetNumButtons(), (*it)->GetNumAxes(), (*it)->GetNumPOV()); + 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_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); + 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); + // 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; + 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; + 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; + 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; + 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 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; + 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; @@ -783,7 +890,8 @@ void OnAbout_Ok(GtkButton *button, gpointer user_data) gtk_main_quit(); } -void CALLBACK PADabout() { +void CALLBACK PADabout() +{ About = create_About(); @@ -791,7 +899,8 @@ void CALLBACK PADabout() { gtk_main(); } -s32 CALLBACK PADtest() { +s32 CALLBACK PADtest() +{ return 0; } @@ -804,36 +913,40 @@ void JoystickInfo::EnumerateJoysticks(vector& vjoysticks) { #ifdef JOYSTICK_SUPPORT - if( !s_bSDLInit ) { - if( SDL_Init(SDL_INIT_JOYSTICK) < 0 ) - return; - SDL_JoystickEventState(SDL_QUERY); - s_bSDLInit = true; - } + if (!s_bSDLInit) + { + if (SDL_Init(SDL_INIT_JOYSTICK) < 0) return; + SDL_JoystickEventState(SDL_QUERY); + s_bSDLInit = true; + } - vector::iterator it; - FORIT(it, vjoysticks) delete *it; + vector::iterator it; + FORIT(it, vjoysticks) delete *it; - vjoysticks.resize(SDL_NumJoysticks()); - for(int i = 0; i < (int)vjoysticks.size(); ++i) { - vjoysticks[i] = new JoystickInfo(); - vjoysticks[i]->Init(i, true); - } + vjoysticks.resize(SDL_NumJoysticks()); + for (int i = 0; i < (int)vjoysticks.size(); ++i) + { + vjoysticks[i] = new JoystickInfo(); + vjoysticks[i]->Init(i, true); + } - // 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; - } - } + // 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); - } + if (joyid >= 0 && joyid < (int)s_vjoysticks.size()) + s_vjoysticks[joyid]->Assign(pad); + } #endif } @@ -841,77 +954,80 @@ void JoystickInfo::EnumerateJoysticks(vector& vjoysticks) JoystickInfo::JoystickInfo() { #ifdef JOYSTICK_SUPPORT - joy = NULL; + joy = NULL; #endif - _id = -1; - pad = -1; - axisrange = 0x7fff; - deadzone = 2000; + _id = -1; + pad = -1; + axisrange = 0x7fff; + deadzone = 2000; } void JoystickInfo::Destroy() { #ifdef JOYSTICK_SUPPORT - if( joy != NULL ) { - if( SDL_JoystickOpened(_id) ) - SDL_JoystickClose(joy); - joy = NULL; - } + if (joy != NULL) + { + if (SDL_JoystickOpened(_id)) SDL_JoystickClose(joy); + joy = NULL; + } #endif } bool JoystickInfo::Init(int id, bool bStartThread) { #ifdef JOYSTICK_SUPPORT - Destroy(); - _id = id; + Destroy(); + _id = id; - joy = SDL_JoystickOpen(id); - if( joy == NULL ) { - printf("failed to open joystick %d\n", id); - return false; - } + joy = SDL_JoystickOpen(id); + if (joy == NULL) + { + printf("failed to open joystick %d\n", id); + return false; + } - numaxes = SDL_JoystickNumAxes(joy); - numbuttons = SDL_JoystickNumButtons(joy); - numpov = SDL_JoystickNumHats(joy); - devname = SDL_JoystickName(id); - vbutstate.resize(numbuttons); - vaxisstate.resize(numbuttons); - - return true; + numaxes = SDL_JoystickNumAxes(joy); + numbuttons = SDL_JoystickNumButtons(joy); + numpov = SDL_JoystickNumHats(joy); + devname = SDL_JoystickName(id); + vbutstate.resize(numbuttons); + vaxisstate.resize(numbuttons); + + return true; #else - return false; + return false; #endif } // assigns a joystick to a pad void JoystickInfo::Assign(int newpad) { - if( pad == newpad ) - return; + if (pad == newpad) return; + pad = newpad; - pad = newpad; - - if( pad >= 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])); - } - } - } + if (pad >= 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::SaveState() { #ifdef JOYSTICK_SUPPORT - for(int i = 0; i < numbuttons; ++i) - vbutstate[i] = SDL_JoystickGetButton(joy, i); - for(int i = 0; i < numaxes; ++i) - vaxisstate[i] = SDL_JoystickGetAxis(joy, i); + for (int i = 0; i < numbuttons; ++i) + vbutstate[i] = SDL_JoystickGetButton(joy, i); + for (int i = 0; i < numaxes; ++i) + vaxisstate[i] = SDL_JoystickGetAxis(joy, i); #endif } diff --git a/plugins/zeropad/Windows/resource.h b/plugins/zeropad/Windows/resource.h index 5490aad8ee..029b8d33c1 100644 --- a/plugins/zeropad/Windows/resource.h +++ b/plugins/zeropad/Windows/resource.h @@ -59,7 +59,7 @@ #define IDC_SR2 1063 // Next default values for new objects -// +// #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 114 diff --git a/plugins/zeropad/Windows/win.cpp b/plugins/zeropad/Windows/win.cpp index d89aadce3b..132ac8abb8 100644 --- a/plugins/zeropad/Windows/win.cpp +++ b/plugins/zeropad/Windows/win.cpp @@ -1,5 +1,5 @@ /* ZeroPAD - author: zerofrog(@gmail.com) - * Copyright (C) 2006-2007 + * 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 @@ -29,100 +29,106 @@ using namespace std; -HINSTANCE hInst=NULL; +HINSTANCE hInst = NULL; static pthread_spinlock_t s_mutexStatus; static u32 s_keyPress[2], s_keyRelease[2]; extern u16 status[2]; extern string s_strIniPath; LRESULT WINAPI PADwndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); -WNDPROC GSwndProc=NULL; -HWND GShwnd=NULL; +WNDPROC GSwndProc = NULL; +HWND GShwnd = NULL; extern keyEvent event; void SaveConfig() { - char *szTemp; - char szIniFile[256], szValue[256], szProf[256]; - int i, j; - - GetModuleFileName(GetModuleHandle((LPCSTR)hInst), szIniFile, 256); - szTemp = strrchr(szIniFile, '\\'); - - if(!szTemp) return; - strcpy(szTemp, "\\inis\\zeropad.ini"); - - for (j=0; j<2 * PADSUBKEYS; j++) { - for (i=0; i=0x60 && key<=0x69) { + strcpy(buff, "NONE"); + else + { + if (key >= 0x60 && key <= 0x69) sprintf(buff, "NumPad %c", '0' + key - 0x60); - } - else sprintf(buff, "%c", key); - } - } + else + sprintf(buff, "%c", key); + } + } else if (key >= 0x1000 && key < 0x2000) { - sprintf (buff, "J%d_%d", (key & 0xfff) / 0x100, (key & 0xff) + 1); + sprintf(buff, "J%d_%d", (key & 0xfff) / 0x100, (key & 0xff) + 1); } else if (key >= 0x2000 && key < 0x3000) { static const char name[][4] = { "MIN", "MAX" }; const int axis = (key & 0xff); - sprintf (buff, "J%d_AXIS%d_%s", (key & 0xfff) / 0x100, axis / 2, name[axis % 2]); - if (index >= 17 && index <= 20) - buff[strlen (buff) -4] = '\0'; + + sprintf(buff, "J%d_AXIS%d_%s", (key & 0xfff) / 0x100, axis / 2, name[axis % 2]); + if (index >= 17 && index <= 20) buff[strlen(buff) -4] = '\0'; } else if (key >= 0x3000 && key < 0x4000) { static const char name[][7] = { "FOWARD", "RIGHT", "BACK", "LEFT" }; const int pov = (key & 0xff); - sprintf (buff, "J%d_POV%d_%s", (key & 0xfff) / 0x100, pov /4, name[pov % 4]); + sprintf(buff, "J%d_POV%d_%s", (key & 0xfff) / 0x100, pov / 4, name[pov % 4]); } - return buff; + return buff; } -BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) { +BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ HWND hWC; - TCITEM tcI; - int i,key, numkeys; - u8* pkeyboard; - static int disabled=0; - static int padn=0; + TCITEM tcI; + int i, key, numkeys; + u8* pkeyboard; + static int disabled = 0; + static int padn = 0; - switch(uMsg) { + switch (uMsg) + { case WM_INITDIALOG: LoadConfig(); - padn = 0; - if (conf.log) CheckDlgButton(hW, IDC_LOG, TRUE); + padn = 0; + if (conf.log) CheckDlgButton(hW, IDC_LOG, TRUE); - for (i=0; i= 0) && (angle< 4500)) return 1;//forward - if ((direction==2) && (angle>= 4500) && (angle<13500)) return 1;//right - if ((direction==1) && (angle>=13500) && (angle<22500)) return 1;//backward - if ((direction==3) && (angle>=22500) && (angle<31500)) return 1;//left - if ((direction==0) && (angle>=31500) && (angle<36000)) return 1;//forward +int POV(u32 direction, u32 angle) +{ + if ((direction == 0) && (angle >= 0) && (angle < 4500)) return 1;//forward + if ((direction == 2) && (angle >= 4500) && (angle < 13500)) return 1;//right + if ((direction == 1) && (angle >= 13500) && (angle < 22500)) return 1;//backward + if ((direction == 3) && (angle >= 22500) && (angle < 31500)) return 1;//left + if ((direction == 0) && (angle >= 31500) && (angle < 36000)) return 1;//forward return 0; } @@ -111,12 +136,15 @@ void _KeyPress(int pad, u32 key) { int i; - for (int p=0; p > 8; stdpar[curPad][3] = status[curPad] & 0xff; stdpar[curPad][4] = g_ranalog[curPad].x; stdpar[curPad][5] = g_ranalog[curPad].y; stdpar[curPad][6] = g_lanalog[curPad].x; stdpar[curPad][7] = g_lanalog[curPad].y; - if (padMode[curPad] == 1) cmdLen = 20; - else cmdLen = 4; + + if (padMode[curPad] == 1) + cmdLen = 20; + else + cmdLen = 4; + button_check2 = stdpar[curPad][2] >> 4; - switch(stdpar[curPad][3]) + switch (stdpar[curPad][3]) { - case 0xBF: // X - stdpar[curPad][14] = (pressure*255)/100; //0xff/(100/(100-conf.keys[curPad][16])); - break; - case 0xDF: // Circle - stdpar[curPad][13] = (pressure*255)/100; //0xff/(100/(100-conf.keys[curPad][17])); - break; - case 0xEF: // Triangle - stdpar[curPad][12] = (pressure*255)/100; //0xff/(100/(100-conf.keys[curPad][19])); - break; - case 0x7F: // Square - stdpar[curPad][15] = (pressure*255)/100; //0xff/(100/(100-conf.keys[curPad][18])); - break; - case 0xFB: // L1 - stdpar[curPad][16] = (pressure*255)/100; //0xff/(100/(100-conf.keys[curPad][26])); - break; - case 0xF7: // R1 - stdpar[curPad][17] = (pressure*255)/100; //0xff/(100/(100-conf.keys[curPad][28])); - break; - case 0xFE: // L2 - stdpar[curPad][18] = (pressure*255)/100; //0xff/(100/(100-conf.keys[curPad][27])); - break; - case 0xFD: // R2 - stdpar[curPad][19] = (pressure*255)/100; //0xff/(100/(100-conf.keys[curPad][29])); - break; - default: - stdpar[curPad][14] = 0x00; // Not pressed - stdpar[curPad][13] = 0x00; // Not pressed - stdpar[curPad][12] = 0x00; // Not pressed - stdpar[curPad][15] = 0x00; // Not pressed - stdpar[curPad][16] = 0x00; // Not pressed - stdpar[curPad][17] = 0x00; // Not pressed - stdpar[curPad][18] = 0x00; // Not pressed - stdpar[curPad][19] = 0x00; // Not pressed - break; + case 0xBF: // X + stdpar[curPad][14] = (pressure * 255) / 100; //0xff/(100/(100-conf.keys[curPad][16])); + break; + case 0xDF: // Circle + stdpar[curPad][13] = (pressure * 255) / 100; //0xff/(100/(100-conf.keys[curPad][17])); + break; + case 0xEF: // Triangle + stdpar[curPad][12] = (pressure * 255) / 100; //0xff/(100/(100-conf.keys[curPad][19])); + break; + case 0x7F: // Square + stdpar[curPad][15] = (pressure * 255) / 100; //0xff/(100/(100-conf.keys[curPad][18])); + break; + case 0xFB: // L1 + stdpar[curPad][16] = (pressure * 255) / 100; //0xff/(100/(100-conf.keys[curPad][26])); + break; + case 0xF7: // R1 + stdpar[curPad][17] = (pressure * 255) / 100; //0xff/(100/(100-conf.keys[curPad][28])); + break; + case 0xFE: // L2 + stdpar[curPad][18] = (pressure * 255) / 100; //0xff/(100/(100-conf.keys[curPad][27])); + break; + case 0xFD: // R2 + stdpar[curPad][19] = (pressure * 255) / 100; //0xff/(100/(100-conf.keys[curPad][29])); + break; + default: + stdpar[curPad][14] = 0x00; // Not pressed + stdpar[curPad][13] = 0x00; // Not pressed + stdpar[curPad][12] = 0x00; // Not pressed + stdpar[curPad][15] = 0x00; // Not pressed + stdpar[curPad][16] = 0x00; // Not pressed + stdpar[curPad][17] = 0x00; // Not pressed + stdpar[curPad][18] = 0x00; // Not pressed + stdpar[curPad][19] = 0x00; // Not pressed + break; } - switch(button_check2) + switch (button_check2) { - case 0xE: // UP - stdpar[curPad][10] = (pressure*255)/100; //0xff/(100/(100-conf.keys[curPad][21])); - break; - case 0xB: // DOWN - stdpar[curPad][11] = (pressure*255)/100; //0xff/(100/(100-conf.keys[curPad][22])); - break; - case 0x7: // LEFT - stdpar[curPad][9] = (pressure*255)/100; //0xff/(100/(100-conf.keys[curPad][23])); - break; - case 0xD: // RIGHT - stdpar[curPad][8] = (pressure*255)/100; //0xff/(100/(100-conf.keys[curPad][24])); - break; - default: - stdpar[curPad][8] = 0x00; // Not pressed - stdpar[curPad][9] = 0x00; // Not pressed - stdpar[curPad][10] = 0x00; // Not pressed - stdpar[curPad][11] = 0x00; // Not pressed - break; + case 0xE: // UP + stdpar[curPad][10] = (pressure * 255) / 100; //0xff/(100/(100-conf.keys[curPad][21])); + break; + case 0xB: // DOWN + stdpar[curPad][11] = (pressure * 255) / 100; //0xff/(100/(100-conf.keys[curPad][22])); + break; + case 0x7: // LEFT + stdpar[curPad][9] = (pressure * 255) / 100; //0xff/(100/(100-conf.keys[curPad][23])); + break; + case 0xD: // RIGHT + stdpar[curPad][8] = (pressure * 255) / 100; //0xff/(100/(100-conf.keys[curPad][24])); + break; + default: + stdpar[curPad][8] = 0x00; // Not pressed + stdpar[curPad][9] = 0x00; // Not pressed + stdpar[curPad][10] = 0x00; // Not pressed + stdpar[curPad][11] = 0x00; // Not pressed + break; } buf = stdpar[curPad]; return padID[curPad]; @@ -435,7 +488,7 @@ u8 _PADpoll(u8 value) { buf = unk4c[curPad]; return 0xf3; - case 0x4d: + case 0x4d: cmdLen = 8; buf = unk4d[curPad]; return 0xf3; @@ -455,49 +508,56 @@ u8 _PADpoll(u8 value) { } } - switch (curCmd) { - case 0x43: - if(curByte == 2) + switch (curCmd) + { + case 0x43: + if (curByte == 2) { - switch(value){ - case 0: - buf[2] = 0; - buf[3] = 0; - break; - case 1: - buf[2] = 0xff; - buf[3] = 0xff; - break; + switch (value) + { + case 0: + buf[2] = 0; + buf[3] = 0; + break; + case 1: + buf[2] = 0xff; + buf[3] = 0xff; + break; } } break; case 0x44: - if (curByte == 2) { + if (curByte == 2) + { PADsetMode(curPad, value); } break; case 0x46: - if(curByte == 2) { - switch(value) { - case 0: // default - buf[5] = 0x2; - buf[6] = 0x0; - buf[7] = 0xA; - break; - case 1: // Param std conf change - buf[5] = 0x1; - buf[6] = 0x1; - buf[7] = 0x14; - break; + if (curByte == 2) + { + switch (value) + { + case 0: // default + buf[5] = 0x2; + buf[6] = 0x0; + buf[7] = 0xA; + break; + case 1: // Param std conf change + buf[5] = 0x1; + buf[6] = 0x1; + buf[7] = 0x14; + break; } } break; case 0x4c: - if (curByte == 2) { - switch (value) { + if (curByte == 2) + { + switch (value) + { case 0: // mode 0 - digital mode buf[5] = 0x4; break; @@ -517,10 +577,9 @@ u8 _PADpoll(u8 value) { u8 CALLBACK PADpoll(u8 value) { u8 ret; + ret = _PADpoll(value); -#ifdef PAD_LOG PAD_LOG("PADpoll: %x (%d: %x)\n", value, curByte, ret); -#endif return ret; } @@ -528,7 +587,7 @@ u8 CALLBACK PADpoll(u8 value) static keyEvent s_event; keyEvent* CALLBACK PADkeyEvent() { - s_event = event; - event.evt = 0; - return &s_event; + s_event = event; + event.evt = 0; + return &s_event; } diff --git a/plugins/zeropad/zeropad.h b/plugins/zeropad/zeropad.h index c43efb1794..eb7ac4e9ba 100644 --- a/plugins/zeropad/zeropad.h +++ b/plugins/zeropad/zeropad.h @@ -40,7 +40,8 @@ using namespace std; #define PADdefs -extern "C" { +extern "C" +{ #include "PS2Edefs.h" } @@ -48,20 +49,20 @@ extern char libraryName[256]; #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) // 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 IS_KEYBOARD(key) (key < 0x10000) +#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 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 @@ -74,14 +75,16 @@ extern char libraryName[256]; #define PADSUBKEYS 2 extern int PadEnum[2][2]; -typedef struct { +typedef struct +{ unsigned long keys[2 * PADSUBKEYS][PADKEYS]; int log; - int options; // upper 16 bits are for pad2 + int options; // upper 16 bits are for pad2 } PADconf; -typedef struct { - u8 x,y; +typedef struct +{ + u8 x, y; } PADAnalog; extern PADconf conf; @@ -90,28 +93,31 @@ extern PADAnalog g_lanalog[2], g_ranalog[2]; extern FILE *padLog; #define PAD_LOG __Log -#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 +enum gamePadValues +{ + PAD_RY = 19, + PAD_LY = 18, + PAD_RX = 17, + PAD_LX = 16, + PAD_LEFT = 15, + PAD_DOWN = 14, + PAD_RIGHT = 13, + PAD_UP = 12, + PAD_START = 11, + PAD_R3 = 10, + PAD_L3 = 9, + PAD_SELECT = 8, + PAD_SQUARE = 7, + PAD_CROSS = 6, + PAD_CIRCLE = 5, + PAD_TRIANGLE = 4, + PAD_R1 = 3, + PAD_L1 = 2, + PAD_R2 = 1, + PAD_L2 = 0 +}; -// Put in the code for bolche's analog contols hack, ifdeffed out, so I don't forget to +// Put in the code for bolche's analog contols hack, ifdeffed out, so I don't forget to // add a gui some day and activate it. //#define ANALOG_CONTROLS_HACK // The various KEY_PAD_xxx definitions are defined as the value of whatever key is pressed. @@ -151,11 +157,11 @@ void SaveConfig(); void SysMessage(char *fmt, ...); -inline int FindKey(int key, int pad) { - for (int p=0; p < PADSUBKEYS; p++) - for (int i=0; i