2017-04-15 12:57:00 +00:00
|
|
|
/* OnePAD - author: arcum42(@gmail.com)
|
|
|
|
* Copyright (C) 2009
|
|
|
|
*
|
|
|
|
* Based on ZeroPAD, author zerofrog@gmail.com
|
|
|
|
* Copyright (C) 2006-2007
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "GamePad.h"
|
|
|
|
#include "onepad.h"
|
|
|
|
#include "keyboard.h"
|
|
|
|
#include "state_management.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include "linux.h"
|
2020-07-20 02:11:42 +00:00
|
|
|
#include <wx/wx.h>
|
2017-04-15 12:57:00 +00:00
|
|
|
|
|
|
|
Display *GSdsp;
|
|
|
|
Window GSwin;
|
|
|
|
|
2020-07-20 02:11:42 +00:00
|
|
|
static void SysMessage(const char *fmt, ...)
|
2017-04-15 12:57:00 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2020-07-20 02:11:42 +00:00
|
|
|
wxMessageDialog dialog(nullptr, msg, "Info", wxOK);
|
|
|
|
dialog.ShowModal();
|
2017-04-15 12:57:00 +00:00
|
|
|
}
|
|
|
|
|
2020-07-20 02:11:42 +00:00
|
|
|
|
2018-10-07 05:54:47 +00:00
|
|
|
EXPORT_C_(void) PADabout()
|
2017-04-15 12:57:00 +00:00
|
|
|
{
|
|
|
|
SysMessage("OnePad is a rewrite of Zerofrog's ZeroPad, done by arcum42.");
|
|
|
|
}
|
|
|
|
|
2018-10-07 05:54:47 +00:00
|
|
|
EXPORT_C_(s32) PADtest()
|
2017-04-15 12:57:00 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 _PADopen(void *pDsp)
|
|
|
|
{
|
|
|
|
GSdsp = *(Display **)pDsp;
|
|
|
|
GSwin = (Window) * (((u32 *)pDsp) + 1);
|
|
|
|
|
|
|
|
SetAutoRepeat(false);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _PADclose()
|
|
|
|
{
|
|
|
|
SetAutoRepeat(true);
|
|
|
|
|
2018-10-07 03:01:23 +00:00
|
|
|
std::vector<GamePad *>::iterator it = s_vgamePad.begin();
|
2017-04-15 12:57:00 +00:00
|
|
|
|
|
|
|
// Delete everything in the vector vjoysticks.
|
2018-10-07 05:54:47 +00:00
|
|
|
while (it != s_vgamePad.end())
|
|
|
|
{
|
2017-04-15 12:57:00 +00:00
|
|
|
delete *it;
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
|
|
|
s_vgamePad.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PollForJoystickInput(int cpad)
|
|
|
|
{
|
|
|
|
int joyid = conf->get_joyid(cpad);
|
|
|
|
if (!GamePadIdWithinBounds(joyid))
|
|
|
|
return;
|
|
|
|
|
|
|
|
GamePad::UpdateGamePadState();
|
2018-10-07 05:54:47 +00:00
|
|
|
for (int i = 0; i < MAX_KEYS; i++)
|
|
|
|
{
|
2017-04-15 12:57:00 +00:00
|
|
|
GamePad *gamePad = s_vgamePad[joyid];
|
|
|
|
|
2018-10-07 05:54:47 +00:00
|
|
|
switch (type_of_joykey(cpad, i))
|
|
|
|
{
|
|
|
|
case PAD_JOYBUTTONS:
|
|
|
|
{
|
2017-04-15 12:57:00 +00:00
|
|
|
|
|
|
|
int value = gamePad->GetButton(key_to_button(cpad, i));
|
|
|
|
if (value)
|
|
|
|
key_status->press(cpad, i);
|
|
|
|
else
|
|
|
|
key_status->release(cpad, i);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2018-10-07 05:54:47 +00:00
|
|
|
case PAD_HAT:
|
|
|
|
{
|
2017-04-15 12:57:00 +00:00
|
|
|
int value = gamePad->GetHat(key_to_axis(cpad, i));
|
|
|
|
|
|
|
|
// key_to_hat_dir and SDL_JoystickGetHat are a 4 bits bitmap, one for each directions. Only 1 bit can be high for
|
|
|
|
// key_to_hat_dir. SDL_JoystickGetHat handles diagonal too (2 bits) so you must check the intersection
|
|
|
|
// '&' not only equality '=='. -- Gregory
|
|
|
|
if (key_to_hat_dir(cpad, i) & value)
|
|
|
|
key_status->press(cpad, i);
|
|
|
|
else
|
|
|
|
key_status->release(cpad, i);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2018-10-07 05:54:47 +00:00
|
|
|
case PAD_AXIS:
|
|
|
|
{
|
2017-04-15 12:57:00 +00:00
|
|
|
int value = gamePad->GetAxisFromKey(cpad, i);
|
|
|
|
bool sign = key_to_axis_sign(cpad, i);
|
|
|
|
bool full_axis = key_to_axis_type(cpad, i);
|
2019-04-28 01:35:35 +00:00
|
|
|
float k=conf->get_sensibility()/100.0; // convert sensibility to float
|
2018-10-07 05:54:47 +00:00
|
|
|
if (IsAnalogKey(i))
|
|
|
|
{
|
2017-04-15 12:57:00 +00:00
|
|
|
if (abs(value) > gamePad->GetDeadzone())
|
2019-04-28 01:35:35 +00:00
|
|
|
key_status->press(cpad, i, (int)(value*k));
|
2017-04-15 12:57:00 +00:00
|
|
|
else
|
|
|
|
key_status->release(cpad, i);
|
2018-10-07 05:54:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (full_axis)
|
|
|
|
{
|
2017-04-15 12:57:00 +00:00
|
|
|
value += 0x8000;
|
|
|
|
if (value > gamePad->GetDeadzone())
|
2018-10-07 03:01:23 +00:00
|
|
|
key_status->press(cpad, i, std::min(value / 256, 0xFF));
|
2017-04-15 12:57:00 +00:00
|
|
|
else
|
|
|
|
key_status->release(cpad, i);
|
2018-10-07 05:54:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-04-15 12:57:00 +00:00
|
|
|
if (sign && (-value > gamePad->GetDeadzone()))
|
2019-04-28 01:35:35 +00:00
|
|
|
key_status->press(cpad, i, std::min((int)(-value*k) / 128, 0xFF));
|
2017-04-15 12:57:00 +00:00
|
|
|
else if (!sign && (value > gamePad->GetDeadzone()))
|
2019-04-28 01:35:35 +00:00
|
|
|
key_status->press(cpad, i, std::min((int)(value*k) / 128, 0xFF));
|
2017-04-15 12:57:00 +00:00
|
|
|
else
|
|
|
|
key_status->release(cpad, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-07 05:54:47 +00:00
|
|
|
EXPORT_C_(void) PADupdate(int pad)
|
2017-04-15 12:57:00 +00:00
|
|
|
{
|
|
|
|
// Gamepad inputs don't count as an activity. Therefore screensaver will
|
|
|
|
// be fired after a couple of minute.
|
|
|
|
// Emulate an user activity
|
|
|
|
static int count = 0;
|
|
|
|
count++;
|
2018-10-07 05:54:47 +00:00
|
|
|
if ((count & 0xFFF) == 0)
|
|
|
|
{
|
2017-04-15 12:57:00 +00:00
|
|
|
// 1 call every 4096 Vsync is enough
|
|
|
|
XResetScreenSaver(GSdsp);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Actually PADupdate is always call with pad == 0. So you need to update both
|
|
|
|
// pads -- Gregory
|
|
|
|
|
|
|
|
// Poll keyboard/mouse event. There is currently no way to separate pad0 from pad1 event.
|
|
|
|
// So we will populate both pad in the same time
|
2018-10-07 05:54:47 +00:00
|
|
|
for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++)
|
|
|
|
{
|
2017-04-15 12:57:00 +00:00
|
|
|
key_status->keyboard_state_acces(cpad);
|
|
|
|
}
|
|
|
|
PollForX11KeyboardInput();
|
|
|
|
|
|
|
|
// Get joystick state + Commit
|
2018-10-07 05:54:47 +00:00
|
|
|
for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++)
|
|
|
|
{
|
2017-04-15 12:57:00 +00:00
|
|
|
key_status->joystick_state_acces(cpad);
|
|
|
|
|
|
|
|
PollForJoystickInput(cpad);
|
|
|
|
|
|
|
|
key_status->commit_status(cpad);
|
|
|
|
}
|
|
|
|
|
|
|
|
Pad::rumble_all();
|
|
|
|
}
|
|
|
|
|
2018-10-07 05:54:47 +00:00
|
|
|
EXPORT_C_(void) PADconfigure()
|
2017-04-15 12:57:00 +00:00
|
|
|
{
|
|
|
|
LoadConfig();
|
|
|
|
|
|
|
|
DisplayDialog();
|
|
|
|
return;
|
|
|
|
}
|