Assorted Joystick fixes
Implemented use of DirectInput sliders. They were previously lumped in with axis and then not read or used at all. Lots of use of joystick_type == 7 or joystick_type != 7 to detect if the joystick_type was none. Changed this to a define. The text to enumerate the types of joysticks was contained in a numbered LPARAM sheet. Switched to using the name listed in the joystick struct. Joysticks with more than 32 buttons would overflow the plat_joystick_state button array. Added overflow checks. Added a 4 axis 4 button joystick type that Win98 can pick up as a generic 4 axis 4 button controller.
This commit is contained in:
@@ -82,37 +82,54 @@ BOOL CALLBACK DIEnumDeviceObjectsCallback(
|
||||
plat_joystick_t *state = (plat_joystick_t *)pvRef;
|
||||
|
||||
if (lpddoi->guidType == GUID_XAxis || lpddoi->guidType == GUID_YAxis || lpddoi->guidType == GUID_ZAxis ||
|
||||
lpddoi->guidType == GUID_RxAxis || lpddoi->guidType == GUID_RyAxis || lpddoi->guidType == GUID_RzAxis ||
|
||||
lpddoi->guidType == GUID_Slider)
|
||||
lpddoi->guidType == GUID_RxAxis || lpddoi->guidType == GUID_RyAxis || lpddoi->guidType == GUID_RzAxis)
|
||||
{
|
||||
memcpy(state->axis[state->nr_axes].name, lpddoi->tszName, strlen(lpddoi->tszName) + 1);
|
||||
joystick_log("Axis %i : %s %x %x\n", state->nr_axes, state->axis[state->nr_axes].name, lpddoi->dwOfs, lpddoi->dwType);
|
||||
if (lpddoi->guidType == GUID_XAxis)
|
||||
state->axis[state->nr_axes].id = 0;
|
||||
else if (lpddoi->guidType == GUID_YAxis)
|
||||
state->axis[state->nr_axes].id = 1;
|
||||
else if (lpddoi->guidType == GUID_ZAxis)
|
||||
state->axis[state->nr_axes].id = 2;
|
||||
else if (lpddoi->guidType == GUID_RxAxis)
|
||||
state->axis[state->nr_axes].id = 3;
|
||||
else if (lpddoi->guidType == GUID_RyAxis)
|
||||
state->axis[state->nr_axes].id = 4;
|
||||
else if (lpddoi->guidType == GUID_RzAxis)
|
||||
state->axis[state->nr_axes].id = 5;
|
||||
state->nr_axes++;
|
||||
if (state->nr_axes < 8)
|
||||
{memcpy(state->axis[state->nr_axes].name, lpddoi->tszName, strlen(lpddoi->tszName) + 1);
|
||||
joystick_log("Axis %i : %s %x %x\n", state->nr_axes, state->axis[state->nr_axes].name, lpddoi->dwOfs, lpddoi->dwType);
|
||||
if (lpddoi->guidType == GUID_XAxis)
|
||||
state->axis[state->nr_axes].id = 0;
|
||||
else if (lpddoi->guidType == GUID_YAxis)
|
||||
state->axis[state->nr_axes].id = 1;
|
||||
else if (lpddoi->guidType == GUID_ZAxis)
|
||||
state->axis[state->nr_axes].id = 2;
|
||||
else if (lpddoi->guidType == GUID_RxAxis)
|
||||
state->axis[state->nr_axes].id = 3;
|
||||
else if (lpddoi->guidType == GUID_RyAxis)
|
||||
state->axis[state->nr_axes].id = 4;
|
||||
else if (lpddoi->guidType == GUID_RzAxis)
|
||||
state->axis[state->nr_axes].id = 5;
|
||||
state->nr_axes++;
|
||||
}
|
||||
}
|
||||
else if (lpddoi->guidType == GUID_Button)
|
||||
{
|
||||
memcpy(state->button[state->nr_buttons].name, lpddoi->tszName, strlen(lpddoi->tszName) + 1);
|
||||
joystick_log("Button %i : %s %x %x\n", state->nr_buttons, state->button[state->nr_buttons].name, lpddoi->dwOfs, lpddoi->dwType);
|
||||
state->nr_buttons++;
|
||||
if (state->nr_buttons < 32)
|
||||
{
|
||||
memcpy(state->button[state->nr_buttons].name, lpddoi->tszName, strlen(lpddoi->tszName) + 1);
|
||||
joystick_log("Button %i : %s %x %x\n", state->nr_buttons, state->button[state->nr_buttons].name, lpddoi->dwOfs, lpddoi->dwType);
|
||||
state->nr_buttons++;
|
||||
}
|
||||
}
|
||||
else if (lpddoi->guidType == GUID_POV)
|
||||
{
|
||||
memcpy(state->pov[state->nr_povs].name, lpddoi->tszName, strlen(lpddoi->tszName) + 1);
|
||||
joystick_log("POV %i : %s %x %x\n", state->nr_povs, state->pov[state->nr_povs].name, lpddoi->dwOfs, lpddoi->dwType);
|
||||
state->nr_povs++;
|
||||
}
|
||||
if (state->nr_povs < 4)
|
||||
{
|
||||
memcpy(state->pov[state->nr_povs].name, lpddoi->tszName, strlen(lpddoi->tszName) + 1);
|
||||
joystick_log("POV %i : %s %x %x\n", state->nr_povs, state->pov[state->nr_povs].name, lpddoi->dwOfs, lpddoi->dwType);
|
||||
state->nr_povs++;
|
||||
}
|
||||
}
|
||||
else if (lpddoi->guidType == GUID_Slider)
|
||||
{
|
||||
if (state->nr_sliders < 2)
|
||||
{
|
||||
memcpy(state->slider[state->nr_sliders].name, lpddoi->tszName, strlen(lpddoi->tszName) + 1);
|
||||
state->slider[state->nr_sliders].id = state->nr_sliders | SLIDER;
|
||||
joystick_log("Slider %i : %s %x %x\n", state->nr_sliders, state->slider[state->nr_sliders].name, lpddoi->dwOfs, lpddoi->dwType);
|
||||
state->nr_sliders++;
|
||||
}
|
||||
}
|
||||
|
||||
return DIENUM_CONTINUE;
|
||||
}
|
||||
@@ -187,7 +204,11 @@ void joystick_init()
|
||||
lpdi_joystick[c]->SetProperty(DIPROP_RANGE, &joy_axis_range.diph);
|
||||
joy_axis_range.diph.dwObj = DIJOFS_RZ;
|
||||
lpdi_joystick[c]->SetProperty(DIPROP_RANGE, &joy_axis_range.diph);
|
||||
|
||||
joy_axis_range.diph.dwObj = DIJOFS_SLIDER(0);
|
||||
lpdi_joystick[c]->SetProperty(DIPROP_RANGE, &joy_axis_range.diph);
|
||||
joy_axis_range.diph.dwObj = DIJOFS_SLIDER(1);
|
||||
lpdi_joystick[c]->SetProperty(DIPROP_RANGE, &joy_axis_range.diph);
|
||||
|
||||
if (FAILED(lpdi_joystick[c]->Acquire()))
|
||||
fatal("joystick_init : Acquire failed\n");
|
||||
}
|
||||
@@ -226,6 +247,10 @@ static int joystick_get_axis(int joystick_nr, int mapping)
|
||||
return 0;
|
||||
else
|
||||
return -cos((2*M_PI * (double)pov) / 36000.0) * 32767;
|
||||
}
|
||||
else if (mapping & SLIDER)
|
||||
{
|
||||
return plat_joystick_state[joystick_nr].s[mapping & 3];
|
||||
}
|
||||
else
|
||||
return plat_joystick_state[joystick_nr].a[plat_joystick_state[joystick_nr].axis[mapping].id];
|
||||
@@ -235,7 +260,7 @@ void joystick_process(void)
|
||||
{
|
||||
int c, d;
|
||||
|
||||
if (joystick_type == 7) return;
|
||||
if (joystick_type == JOYSTICK_TYPE_NONE) return;
|
||||
|
||||
for (c = 0; c < joysticks_present; c++)
|
||||
{
|
||||
@@ -260,6 +285,8 @@ void joystick_process(void)
|
||||
plat_joystick_state[c].a[3] = joystate.lRx;
|
||||
plat_joystick_state[c].a[4] = joystate.lRy;
|
||||
plat_joystick_state[c].a[5] = joystate.lRz;
|
||||
plat_joystick_state[c].s[0] = joystate.rglSlider[0];
|
||||
plat_joystick_state[c].s[1] = joystate.rglSlider[1];
|
||||
|
||||
for (b = 0; b < 16; b++)
|
||||
plat_joystick_state[c].b[b] = joystate.rgbButtons[b] & 0x80;
|
||||
|
||||
@@ -216,7 +216,7 @@ void joystick_process(void)
|
||||
{
|
||||
int c, d;
|
||||
|
||||
if (joystick_type == 7) return;
|
||||
if (joystick_type == JOYSTICK_TYPE_NONE) return;
|
||||
|
||||
joystick_poll();
|
||||
|
||||
|
||||
@@ -58,6 +58,10 @@ static void rebuild_axis_button_selections(HWND hdlg)
|
||||
SendMessage(h, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)s);
|
||||
sprintf(s, "%s (Y axis)", plat_joystick_state[joystick-1].pov[d].name);
|
||||
SendMessage(h, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)s);
|
||||
}
|
||||
for (d = 0; d < plat_joystick_state[joystick - 1].nr_sliders; d++)
|
||||
{
|
||||
SendMessage(h, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)plat_joystick_state[joystick - 1].slider[d].name);
|
||||
}
|
||||
SendMessage(h, CB_SETCURSEL, sel, 0);
|
||||
EnableWindow(h, TRUE);
|
||||
@@ -122,15 +126,23 @@ static int get_axis(HWND hdlg, int id)
|
||||
HWND h = GetDlgItem(hdlg, id);
|
||||
int axis_sel = SendMessage(h, CB_GETCURSEL, 0, 0);
|
||||
int nr_axes = plat_joystick_state[joystick_state[joystick_nr].plat_joystick_nr-1].nr_axes;
|
||||
|
||||
int nr_povs = plat_joystick_state[joystick_state[joystick_nr].plat_joystick_nr - 1].nr_povs;
|
||||
int nr_sliders = plat_joystick_state[joystick_state[joystick_nr].plat_joystick_nr - 1].nr_sliders;
|
||||
|
||||
if (axis_sel < nr_axes)
|
||||
return axis_sel;
|
||||
|
||||
axis_sel -= nr_axes;
|
||||
if (axis_sel & 1)
|
||||
return POV_Y | (axis_sel >> 1);
|
||||
else
|
||||
return POV_X | (axis_sel >> 1);
|
||||
if (axis_sel < nr_povs * 2)
|
||||
{
|
||||
if (axis_sel & 1)
|
||||
return POV_Y | (axis_sel >> 1);
|
||||
else
|
||||
return POV_X | (axis_sel >> 1);
|
||||
}
|
||||
axis_sel -= nr_povs;
|
||||
|
||||
return SLIDER | (axis_sel >> 1);
|
||||
}
|
||||
|
||||
static int get_pov(HWND hdlg, int id)
|
||||
@@ -163,6 +175,7 @@ joystickconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
int joystick;
|
||||
int nr_axes;
|
||||
int nr_povs;
|
||||
int nr_sliders;
|
||||
int mapping;
|
||||
|
||||
switch (message)
|
||||
@@ -186,6 +199,8 @@ joystickconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
nr_axes = plat_joystick_state[joystick-1].nr_axes;
|
||||
nr_povs = plat_joystick_state[joystick-1].nr_povs;
|
||||
nr_sliders = plat_joystick_state[joystick - 1].nr_sliders;
|
||||
|
||||
for (c = 0; c < joystick_get_axis_count(joystick_config_type); c++)
|
||||
{
|
||||
int mapping = joystick_state[joystick_nr].axis_mapping[c];
|
||||
@@ -195,7 +210,9 @@ joystickconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
SendMessage(h, CB_SETCURSEL, nr_axes + (mapping & 3)*2, 0);
|
||||
else if (mapping & POV_Y)
|
||||
SendMessage(h, CB_SETCURSEL, nr_axes + (mapping & 3)*2 + 1, 0);
|
||||
else
|
||||
else if (mapping & SLIDER)
|
||||
SendMessage(h, CB_SETCURSEL, nr_axes + nr_povs * 2 + (mapping & 3), 0);
|
||||
else
|
||||
SendMessage(h, CB_SETCURSEL, mapping, 0);
|
||||
id += 2;
|
||||
}
|
||||
|
||||
@@ -971,6 +971,7 @@ static BOOL CALLBACK
|
||||
win_settings_input_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
wchar_t str[128];
|
||||
char *joy_name;
|
||||
HWND h;
|
||||
int c, d;
|
||||
|
||||
@@ -1000,9 +1001,15 @@ win_settings_input_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
h = GetDlgItem(hdlg, IDC_COMBO_JOYSTICK);
|
||||
c = 0;
|
||||
while (joystick_get_name(c)) {
|
||||
SendMessage(h, CB_ADDSTRING, 0, win_get_string(2105 + c));
|
||||
joy_name = joystick_get_name(c);
|
||||
while (joy_name)
|
||||
{
|
||||
mbstowcs(str, joy_name, strlen(joy_name) + 1);
|
||||
SendMessage(h, CB_ADDSTRING, 0, (LPARAM)str);
|
||||
|
||||
// SendMessage(h, CB_ADDSTRING, 0, win_get_string(2105 + c));
|
||||
c++;
|
||||
joy_name = joystick_get_name(c);
|
||||
}
|
||||
EnableWindow(h, TRUE);
|
||||
SendMessage(h, CB_SETCURSEL, temp_joystick, 0);
|
||||
|
||||
Reference in New Issue
Block a user