LilyPad: Fixed some binding stuff that some incompetant person broke in his last release. PADfreeze fixed so should work when called twice (Once for pad 1, once for pad 2).

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@790 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
mattmenke 2009-03-15 09:20:53 +00:00
parent 85a1c605fa
commit 493ecaa206
6 changed files with 100 additions and 148 deletions

View File

@ -1253,12 +1253,7 @@ INT_PTR CALLBACK DialogProc(HWND hWnd, unsigned int msg, WPARAM wParam, LPARAM l
unsigned int uid;
int value;
InitInfo info = {selected==0x7F, hWndProp, hWnd, GetDlgItem(hWnd, selected)};
int hint = 0;
if (selected < 0x7F) {
// 2 will accept relative axes, absolute axes, and POV controls.
hint = 2;
}
Device *dev = dm->GetActiveDevice(&info, hint, &uid, &index, &value);
Device *dev = dm->GetActiveDevice(&info, &uid, &index, &value);
if (dev) {
int command = selected;
// Good idea to do this first, as BindCommand modifies the ListView, which will
@ -1276,75 +1271,6 @@ INT_PTR CALLBACK DialogProc(HWND hWnd, unsigned int msg, WPARAM wParam, LPARAM l
index = BindCommand(dev, uid, pad, command, BASE_SENSITIVITY, 0);
}
}
else {
int v[4];
int base = 0;
if (command == 0x30 || command == 0x31) {
base = 0x14;
}
else if (command == 0x32 || command == 0x33) {
base = 0x20;
}
else if (command == 0x34 || command == 0x35) {
base = 0x24;
}
else if (command == 0x36) {
base = 0x1B;
}
else if (command == 0x37) {
base = 0x19;
}
else if (command == 0x38) {
base = 0x12;
}
if (base) {
// Lx/Rx
if (base & 3) {
v[0] = base;
v[2] = base-1;
v[1]=v[3] = 0;
}
else {
if (command & 1) {
v[0] = base;
v[1] = base+1;
v[2] = base+2;
v[3] = base+3;
}
else {
v[0] = base+1;
v[1] = base+2;
v[2] = base+3;
v[3] = base;
}
}
if (uid & UID_POV) {
int rotate = 0;
while (value > 4500) {
rotate++;
value -= 9000;
}
index = BindCommand(dev, (uid&~UID_POV)|UID_POV_N, pad, v[(4-rotate)%4], BASE_SENSITIVITY, 0);
ListView_SetItemState(hWndList, index, LVIS_SELECTED, LVIS_SELECTED);
index = BindCommand(dev, (uid&~UID_POV)|UID_POV_E, pad, v[(5-rotate)%4], BASE_SENSITIVITY, 0);
ListView_SetItemState(hWndList, index, LVIS_SELECTED, LVIS_SELECTED);
index = BindCommand(dev, (uid&~UID_POV)|UID_POV_S, pad, v[(6-rotate)%4], BASE_SENSITIVITY, 0);
ListView_SetItemState(hWndList, index, LVIS_SELECTED, LVIS_SELECTED);
index = BindCommand(dev, (uid&~UID_POV)|UID_POV_W, pad, v[(7-rotate)%4], BASE_SENSITIVITY, 0);
}
else if (uid & UID_AXIS) {
int b1 = v[0];
int b2 = v[2];
if (value < 0) {
b1 = v[2];
b2 = v[0];
}
index = BindCommand(dev, (uid&~UID_AXIS)|UID_AXIS_POS, pad, b1, BASE_SENSITIVITY, 0);
ListView_SetItemState(hWndList, index, LVIS_SELECTED, LVIS_SELECTED);
index = BindCommand(dev, (uid&~UID_AXIS)|UID_AXIS_NEG, pad, b2, BASE_SENSITIVITY, 0);
}
}
}
if (index >= 0) {
PropSheet_Changed(hWndProp, hWnds[pad]);
if (index >= 0)
@ -1504,7 +1430,7 @@ INT_PTR CALLBACK DialogProc(HWND hWnd, unsigned int msg, WPARAM wParam, LPARAM l
}
}
}
else if ((cmd >= ID_GUITAR_HERO && cmd <= ID_L3R3) || cmd == ID_IGNORE) {// || cmd == ID_FORCE_FEEDBACK) {
else if ((cmd >= ID_GUITAR_HERO && cmd <= ID_ANALOG) || cmd == ID_IGNORE) {// || cmd == ID_FORCE_FEEDBACK) {
// Messes up things, unfortunately.
// End binding on a bunch of notification messages, and
// this will send a bunch.
@ -1527,13 +1453,18 @@ INT_PTR CALLBACK DialogProc(HWND hWnd, unsigned int msg, WPARAM wParam, LPARAM l
InitInfo info = {selected==0x7F, hWndProp, hWnd, GetDlgItem(hWnd, cmd)};
EatWndProc(info.hWndButton, DoNothingWndProc);
int w = timeGetTime();
dm->Update(&info);
dm->PostRead();
// Workaround for things that return 0 on first poll and something else ever after.
Sleep(200);
Sleep(40);
dm->Update(&info);
dm->PostRead();
SetTimer(hWnd, 1, 100, 0);
int w2 = timeGetTime();
if (dm->devices[0xe]->oldVirtualControlState[6] != 0x8000) {
dm->devices[0xe]->oldVirtualControlState[6]=dm->devices[0xe]->oldVirtualControlState[6];
}
SetTimer(hWnd, 1, 30, 0);
}
if (cmd == IDC_TURBO) {
// Don't allow setting it back to indeterminate.

View File

@ -350,7 +350,7 @@ void InputDeviceManager::PostRead() {
}
}
Device *InputDeviceManager::GetActiveDevice(void *info, int axisHint, unsigned int *uid, int *index, int *value) {
Device *InputDeviceManager::GetActiveDevice(void *info, unsigned int *uid, int *index, int *value) {
int i, j;
Update(info);
int bestDiff = FULLY_DOWN/2;
@ -359,34 +359,30 @@ Device *InputDeviceManager::GetActiveDevice(void *info, int axisHint, unsigned i
if (devices[i]->active) {
for (j=0; j<devices[i]->numVirtualControls; j++) {
if (devices[i]->virtualControlState[j] == devices[i]->oldVirtualControlState[j]) continue;
if (devices[i]->virtualControls[j].uid & UID_POV) continue;
// Fix for two things:
// Releasing button used to click on bind button, and
// DirectInput not updating control state.
//Note: Handling latter not great for pressure sensitive button handling, but should still work...
// with some effort.
if (!((devices[i]->virtualControls[j].uid >> 16) & (POV|RELAXIS))) {
if (!(devices[i]->virtualControls[j].uid & (POV|RELAXIS))) {
if (abs(devices[i]->oldVirtualControlState[j]) > abs(devices[i]->virtualControlState[j])) {
devices[i]->oldVirtualControlState[j] = 0;
}
}
int diff = abs(devices[i]->virtualControlState[j] - devices[i]->oldVirtualControlState[j]);
if ((devices[i]->virtualControls[j].uid & UID_POV) && diff) {
if (devices[i]->virtualControlState[j] == -1) diff = 0;
else diff = 2*FULLY_DOWN;
}
// Make it require a bit more work to bind relative axes.
else if (((devices[i]->virtualControls[j].uid>>16) & 0xFF) == RELAXIS) {
if (((devices[i]->virtualControls[j].uid>>16) & 0xFF) == RELAXIS) {
diff = diff/4+1;
}
if (diff > bestDiff) {
if (axisHint != 2) {
if (devices[i]->virtualControls[j].uid & UID_POV) continue;
if (devices[i]->virtualControls[j].uid & UID_AXIS) {
if ((((devices[i]->virtualControls[j].uid>>16)&0xFF) != ABSAXIS)) continue;
// Very picky when binding entire axes. Prefer binding half-axes.
if (devices[i]->oldVirtualControlState[j] >= FULLY_DOWN/8 &&
devices[i]->oldVirtualControlState[j] <= FULLY_DOWN*7/8) continue;
}
if (devices[i]->virtualControls[j].uid & UID_AXIS) {
if ((((devices[i]->virtualControls[j].uid>>16)&0xFF) != ABSAXIS)) continue;
// Very picky when binding entire axes. Prefer binding half-axes.
if (!((devices[i]->oldVirtualControlState[j] < FULLY_DOWN/16 && devices[i]->virtualControlState[j] > FULLY_DOWN/8) ||
(devices[i]->oldVirtualControlState[j] > 15*FULLY_DOWN/16 && devices[i]->virtualControlState[j] < 7*FULLY_DOWN/8)))
continue;
devices[i]->virtualControls[j].uid = devices[i]->virtualControls[j].uid;
}
bestDiff = diff;
*uid = devices[i]->virtualControls[j].uid;

View File

@ -298,8 +298,7 @@ public:
~InputDeviceManager();
void AddDevice(Device *d);
// If axisHint is 1, prefer axes.
Device *GetActiveDevice(void *info, int axisHint, unsigned int *uid, int *index, int *value);
Device *GetActiveDevice(void *info, unsigned int *uid, int *index, int *value);
void Update(void *attachInfo);
// Called after reading state, after Update().
void PostRead();

View File

@ -15,6 +15,10 @@
#include "svnrev.h"
#include "resource.h"
#ifdef _DEBUG
#include "crtdbg.h"
#endif
// Used to prevent reading input and cleaning up input devices at the same time.
// Only an issue when not reading input in GS thread and disabling devices due to
// lost focus.
@ -32,8 +36,8 @@ int openCount = 0;
int activeWindow = 0;
int bufSize = 0;
static unsigned char outBuf[50];
static unsigned char inBuf[50];
unsigned char outBuf[50];
unsigned char inBuf[50];
#define MODE_DIGITAL 0x41
#define MODE_ANALOG 0x73
@ -79,10 +83,10 @@ void DEBUG_NEW_SET() {
end++[0] = '\n';
DWORD junk;
WriteFile(hFile, temp, end-temp, &junk, 0);
bufSize = 0;
CloseHandle(hFile);;
}
}
bufSize = 0;
}
inline void DEBUG_IN(unsigned char c) {
@ -298,7 +302,6 @@ int lockStateChanged[2] = {0,0};
#define LOCK_BUTTONS 4
#define LOCK_BOTH 1
extern HWND hWndStealing;
void Update(int pad) {
if ((unsigned int)pad > 2) return;
@ -529,11 +532,6 @@ void CALLBACK PADshutdown() {
UnloadConfigs();
}
#ifdef _DEBUG
#include "crtdbg.h"
#endif
inline void StopVibrate() {
for (int i=0; i<4; i++) {
SetVibrate(&pads[i/2], i&1, 0);
@ -626,7 +624,7 @@ struct QueryInfo {
u8 currentCommand;
u8 numBytes;
u8 queryDone;
u8 response[22];
u8 response[42];
} query = {0,0,0,0, 0,0xFF, 0xF3};
int saveStateIndex = 0;
@ -823,6 +821,19 @@ u8 CALLBACK PADpoll(u8 value) {
DEBUG_OUT(query.response[1+query.lastByte]);
return query.response[++query.lastByte];
}
/*
{
query.numBytes = 35;
u8 test[35] = {0xFF, 0x80, 0x5A,
0x73, 0x5A, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0x80,
0x73, 0x5A, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0x80,
0x73, 0x5A, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0x80,
0x73, 0x5A, 0xFF, 0xFF, 0x80, 0x80, 0x80, 0x80
};
memcpy(query.response, test, sizeof(test));
DEBUG_OUT(query.response[1+query.lastByte]);
return query.response[++query.lastByte];
}//*/
int i;
Pad *pad = &pads[query.pad];
if (query.lastByte == 0) {
@ -1190,7 +1201,11 @@ struct PadPluginFreezeData {
// Currently all different versions are incompatible.
// May split into major/minor with some compatibility rules.
u32 version;
PadFreezeData padData[2];
// So when loading, know which plugin's settings I'm loading.
// Not a big deal. Use a static variable when saving to figure it out.
u8 port;
// Currently only use padData[0]. Save room for all 4 slots for simplicity.
PadFreezeData padData[4];
};
s32 CALLBACK PADfreeze(int mode, freezeData *data) {
@ -1200,58 +1215,68 @@ s32 CALLBACK PADfreeze(int mode, freezeData *data) {
else if (mode == FREEZE_LOAD) {
if (data->size < sizeof(PadPluginFreezeData)) return 0;
PadPluginFreezeData &pdata = *(PadPluginFreezeData*)(data->data);
strcpy(pdata.format, "PadMode");
pdata.version = PAD_SAVE_STATE_VERSION;
for (int i=0; i<2; i++) {
pdata.padData[i].mode = pads[i].mode;
pdata.padData[i].locked = pads[i].modeLock;
memcpy(pdata.padData[i].umask, pads[i].umask, sizeof(pads[i].umask));
memcpy(pdata.padData[i].vibrate, pads[i].vibrate, sizeof(pads[i].vibrate));
if (pdata.version != PAD_SAVE_STATE_VERSION || strcmp(pdata.format, "PadMode")) return 0;
StopVibrate();
int port = pdata.port;
for (int i=0; i<1; i++) {
u8 mode = pads[port].mode = pdata.padData[i].mode;
if (mode != MODE_DIGITAL && mode != MODE_ANALOG && mode != MODE_DS2_NATIVE) {
ResetPad(i);
continue;
}
pads[port].config = pdata.padData[i].config;
pads[port].modeLock = pdata.padData[i].locked;
memcpy(pads[port].umask, pdata.padData[i].umask, sizeof(pads[port].umask));
// Means I only have to have one chunk of code to parse vibrate info.
// Other plugins don't store it exactly, but think it's technically correct
// to do so, though I could be wrong.
pads[i].config = 1;
PADstartPoll(i+1);
PADpoll(0x4D);
PADpoll(0x00);
for (int j=0; j<7; j++) {
PADpoll(pdata.padData[i].vibrate[j]);
}
pdata.padData[i].config = pads[i].config;
}
}
else if (mode == FREEZE_SAVE) {
if (data->size != sizeof(PadPluginFreezeData)) return 0;
PadPluginFreezeData &pdata = *(PadPluginFreezeData*)(data->data);
if (pdata.version != PAD_SAVE_STATE_VERSION || !stricmp(pdata.format, "PadMode")) return 0;
StopVibrate();
for (int i=0; i<2; i++) {
u8 mode = pads[i].mode = pdata.padData[i].mode;
if (mode != MODE_DIGITAL && mode != MODE_ANALOG && mode != MODE_DS2_NATIVE) {
ResetPad(i);
continue;
}
pads[i].config = pdata.padData[i].config;
pads[i].modeLock = pdata.padData[i].locked;
memcpy(pads[i].umask, pdata.padData[i].umask, sizeof(pads[i].umask));
static int nextPort = 0;
if (!pads[nextPort].initialized) nextPort ^= 1;
int port = nextPort;
if (!pads[nextPort^1].initialized) nextPort = 0;
else nextPort ^= 1;
memset(&pdata, 0, sizeof(pdata));
strcpy(pdata.format, "PadMode");
pdata.version = PAD_SAVE_STATE_VERSION;
pdata.port = port;
for (int i=0; i<1; i++) {
pdata.padData[i].mode = pads[port].mode;
pdata.padData[i].locked = pads[port].modeLock;
memcpy(pdata.padData[i].umask, pads[port].umask, sizeof(pads[port].umask));
memcpy(pdata.padData[i].vibrate, pads[port].vibrate, sizeof(pads[port].vibrate));
// Means I only have to have one chunk of code to parse vibrate info.
// Other plugins don't store it exactly, but think it's technically correct
// to do so, though I could be wrong.
PADstartPoll(i+1);
pads[port].config = 1;
PADstartPoll(port+1);
PADpoll(0x4D);
PADpoll(0x00);
for (int j=0; j<7; j++) {
PADpoll(pdata.padData[i].vibrate[j]);
PADpoll(pdata.padData[port].vibrate[j]);
}
pdata.padData[port].config = pads[port].config;
}
}
else return -1;
return 0;
}
}
u32 CALLBACK PADreadPort1 (PadDataS* pads) {
PADstartPoll(1);

View File

@ -27,18 +27,18 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
// TEXTINCLUDE
//
1 TEXTINCLUDE
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
2 TEXTINCLUDE
BEGIN
"#include <winres.h>\r\n"
"\0"
END
3 TEXTINCLUDE
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
@ -74,17 +74,17 @@ BEGIN
PUSHBUTTON "R2",ID_R2,372,73,45,15
PUSHBUTTON "L3",ID_L3,195,93,45,15
PUSHBUTTON "R3",ID_R3,371,93,46,15
GROUPBOX "D-Pad",IDC_STATIC,251,44,110,68
GROUPBOX "D-Pad",IDC_DPAD,251,44,110,68
PUSHBUTTON "Up",ID_DPAD_UP,285,54,35,15
PUSHBUTTON "Left",ID_DPAD_LEFT,267,73,35,15
PUSHBUTTON "Right",ID_DPAD_RIGHT,307,73,35,15
PUSHBUTTON "Down",ID_DPAD_DOWN,285,92,35,15
GROUPBOX "Left Analog Stick",IDC_STATIC,195,115,108,70
GROUPBOX "Left Analog Stick",IDC_LSTICK,195,115,108,70
PUSHBUTTON "Up",ID_LSTICK_UP,228,125,35,15
PUSHBUTTON "Left",ID_LSTICK_LEFT,210,144,35,15
PUSHBUTTON "Right",ID_LSTICK_RIGHT,250,144,35,15
PUSHBUTTON "Down",ID_LSTICK_DOWN,228,164,35,15
GROUPBOX "Right Analog Stick",IDC_STATIC,309,115,108,70
GROUPBOX "Right Analog Stick",IDC_RSTICK,309,115,108,70
PUSHBUTTON "Up",ID_RSTICK_UP,342,125,35,15
PUSHBUTTON "Left",ID_RSTICK_LEFT,324,144,35,15
PUSHBUTTON "Right",ID_RSTICK_RIGHT,364,144,35,15
@ -279,7 +279,7 @@ END
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
GUIDELINES DESIGNINFO
BEGIN
IDD_CONFIG, DIALOG
BEGIN

View File

@ -34,11 +34,18 @@
#define IDC_DISABLE_SCREENSAVER 1119
#define IDC_MOUSE_UNFOCUS 1120
#define IDC_MOUSE_UNFOCUS2 1121
#define IDC_AXIS_BUTTONS 1121
#define IDC_BACKGROUND 1122
#define IDC_MULTIPLE_BINDING 1123
#define IDC_DISABLE_SCREENSAVER2 1124
#define IDC_FORCE_HIDE 1124
#define IDC_FORCE_HIDE2 1125
#define IDC_GH2_HACK 1125
#define IDC_FORCEFEEDBACK_HACK1 1126
#define IDC_GH2_HACK2 1126
#define IDC_VISTA_VOLUME 1126
#define IDC_DISABLE_SCREENSAVER4 1127
#define IDC_FORCEFEEDBACK_HACK2 1127
#define IDC_FORCE_HIDE3 1127
#define IDC_GS_THREAD_INPUT 1128
#define IDC_SAVE_STATE_TITLE 1129
@ -50,6 +57,9 @@
#define IDC_TURBO 0x1005
#define IDC_AXIS_DEVICE1 0x1006
#define ID_SENSITIVITY 0x1007
#define IDC_DPAD 0x1008
#define IDC_LSTICK 0x1009
#define IDC_RSTICK 0x100A
#define ID_GUITAR_HERO 0x10FB
#define ID_LOCK_BUTTONS 0x10FC
#define ID_LOCK 0x10FD
@ -80,15 +90,6 @@
#define ID_RSTICK_DOWN 0x1116
#define ID_RSTICK_LEFT 0x1117
#define ID_ANALOG 0x1118
#define ID_DPAD_LRAXIS 0x1120
#define ID_DPAD_UDAXIS 0x1121
#define ID_LSTICK_LRAXIS 0x1122
#define ID_LSTICK_UDAXIS 0x1123
#define ID_RSTICK_LRAXIS 0x1124
#define ID_RSTICK_UDAXIS 0x1125
#define ID_L1R1 0x1126
#define ID_L2R2 0x1127
#define ID_L3R3 0x1128
#define ID_DELETE 0x11FF
#define ID_DEBUG 0x1200
#define ID_IGNORE 0x1201
@ -147,7 +148,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 112
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1127
#define _APS_NEXT_CONTROL_VALUE 1130
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif