2009-07-03 11:45:47 +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
|
2010-07-04 22:49:00 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
2009-07-03 11:45:47 +00:00
|
|
|
*/
|
|
|
|
|
2015-10-14 13:05:02 +00:00
|
|
|
#include "GamePad.h"
|
2010-06-05 11:03:12 +00:00
|
|
|
#include "onepad.h"
|
2011-06-12 14:48:36 +00:00
|
|
|
#include "keyboard.h"
|
2010-06-05 11:03:12 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <gtk/gtk.h>
|
2009-07-03 11:45:47 +00:00
|
|
|
#include "linux.h"
|
|
|
|
|
|
|
|
Display *GSdsp;
|
2011-06-12 14:48:36 +00:00
|
|
|
Window GSwin;
|
2010-06-05 08:22:14 +00:00
|
|
|
|
2010-07-05 15:43:21 +00:00
|
|
|
void SysMessage(const char *fmt, ...)
|
2010-04-25 00:31:27 +00:00
|
|
|
{
|
2010-06-05 08:22:14 +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;
|
|
|
|
|
|
|
|
GtkWidget *dialog;
|
|
|
|
dialog = gtk_message_dialog_new (NULL,
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_MESSAGE_INFO,
|
|
|
|
GTK_BUTTONS_OK,
|
|
|
|
"%s", msg);
|
|
|
|
gtk_dialog_run (GTK_DIALOG (dialog));
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
}
|
2009-07-03 11:45:47 +00:00
|
|
|
|
2010-06-05 08:22:14 +00:00
|
|
|
EXPORT_C_(void) PADabout()
|
|
|
|
{
|
|
|
|
SysMessage("OnePad is a rewrite of Zerofrog's ZeroPad, done by arcum42.");
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(s32) PADtest()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2009-07-10 06:07:32 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
s32 _PADopen(void *pDsp)
|
|
|
|
{
|
2011-06-12 14:48:36 +00:00
|
|
|
GSdsp = *(Display**)pDsp;
|
|
|
|
GSwin = (Window)*(((u32*)pDsp)+1);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-12-26 00:01:30 +00:00
|
|
|
SetAutoRepeat(false);
|
2009-07-03 11:45:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void _PADclose()
|
|
|
|
{
|
|
|
|
SetAutoRepeat(true);
|
|
|
|
|
2015-10-14 13:05:02 +00:00
|
|
|
vector<GamePad*>::iterator it = s_vgamePad.begin();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
// Delete everything in the vector vjoysticks.
|
2015-10-14 13:05:02 +00:00
|
|
|
while (it != s_vgamePad.end())
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
|
|
|
delete *it;
|
|
|
|
it ++;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2015-10-14 13:05:02 +00:00
|
|
|
s_vgamePad.clear();
|
2009-07-03 11:45:47 +00:00
|
|
|
}
|
|
|
|
|
2011-06-28 21:30:06 +00:00
|
|
|
void PollForJoystickInput(int cpad)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
2011-06-28 21:30:06 +00:00
|
|
|
int joyid = conf->get_joyid(cpad);
|
2015-10-14 13:05:02 +00:00
|
|
|
if (!GamePadIdWithinBounds(joyid)) return;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2015-10-14 13:05:02 +00:00
|
|
|
GamePad::UpdateGamePadState();
|
2011-06-28 21:30:06 +00:00
|
|
|
for (int i = 0; i < MAX_KEYS; i++)
|
|
|
|
{
|
2015-10-14 13:05:02 +00:00
|
|
|
GamePad* gamePad = s_vgamePad[joyid];
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2011-06-28 21:30:06 +00:00
|
|
|
switch (type_of_joykey(cpad, i))
|
|
|
|
{
|
|
|
|
case PAD_JOYBUTTONS:
|
|
|
|
{
|
2011-06-12 14:48:36 +00:00
|
|
|
|
2015-10-14 13:05:02 +00:00
|
|
|
int value = gamePad->GetButton(key_to_button(cpad, i));
|
2011-06-28 21:30:06 +00:00
|
|
|
if (value)
|
|
|
|
key_status->press(cpad, i);
|
|
|
|
else
|
|
|
|
key_status->release(cpad, i);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2011-06-28 21:30:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PAD_HAT:
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
2015-10-14 13:05:02 +00:00
|
|
|
int value = gamePad->GetHat(key_to_axis(cpad, i));
|
2011-06-12 14:48:36 +00:00
|
|
|
|
2011-06-28 21:30:06 +00:00
|
|
|
// 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);
|
2011-06-12 14:48:36 +00:00
|
|
|
|
2011-06-28 21:30:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PAD_AXIS:
|
|
|
|
{
|
2015-10-14 13:05:02 +00:00
|
|
|
int value = gamePad->GetAxisFromKey(cpad, i);
|
2011-06-28 21:30:06 +00:00
|
|
|
bool sign = key_to_axis_sign(cpad, i);
|
|
|
|
bool full_axis = key_to_axis_type(cpad, i);
|
|
|
|
|
|
|
|
if (IsAnalogKey(i)) {
|
2015-10-14 13:05:02 +00:00
|
|
|
if (abs(value) > gamePad->GetDeadzone())
|
2011-06-28 21:30:06 +00:00
|
|
|
key_status->press(cpad, i, value);
|
|
|
|
else
|
|
|
|
key_status->release(cpad, i);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (full_axis) {
|
|
|
|
value += 0x8000;
|
2015-10-14 13:05:02 +00:00
|
|
|
if (value > gamePad->GetDeadzone())
|
2011-06-28 22:16:06 +00:00
|
|
|
key_status->press(cpad, i, min(value/256 , 0xFF));
|
|
|
|
else
|
2011-06-28 21:30:06 +00:00
|
|
|
key_status->release(cpad, i);
|
2011-06-12 14:48:36 +00:00
|
|
|
|
2011-06-28 21:30:06 +00:00
|
|
|
} else {
|
2015-10-14 13:05:02 +00:00
|
|
|
if (sign && (-value > gamePad->GetDeadzone()))
|
2011-06-28 22:16:06 +00:00
|
|
|
key_status->press(cpad, i, min(-value /128, 0xFF));
|
2015-10-14 13:05:02 +00:00
|
|
|
else if (!sign && (value > gamePad->GetDeadzone()))
|
2011-06-28 22:16:06 +00:00
|
|
|
key_status->press(cpad, i, min(value /128, 0xFF));
|
|
|
|
else
|
2011-06-28 21:30:06 +00:00
|
|
|
key_status->release(cpad, i);
|
2011-06-12 14:48:36 +00:00
|
|
|
}
|
2011-06-28 21:30:06 +00:00
|
|
|
}
|
2009-07-03 11:45:47 +00:00
|
|
|
}
|
2011-06-28 21:30:06 +00:00
|
|
|
default: break;
|
2009-07-03 11:45:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-28 21:30:06 +00:00
|
|
|
EXPORT_C_(void) PADupdate(int pad)
|
|
|
|
{
|
2015-11-07 10:03:39 +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;
|
2015-11-07 12:19:46 +00:00
|
|
|
count++;
|
2015-11-07 10:03:39 +00:00
|
|
|
if ((count & 0xFFF) == 0) {
|
|
|
|
// 1 call every 4096 Vsync is enough
|
|
|
|
XResetScreenSaver(GSdsp);
|
|
|
|
}
|
|
|
|
|
2011-06-28 21:30:06 +00:00
|
|
|
// Actually PADupdate is always call with pad == 0. So you need to update both
|
|
|
|
// pads -- Gregory
|
2016-02-27 19:04:06 +00:00
|
|
|
for (int cpad = 0; cpad < GAMEPAD_NUMBER; cpad++) {
|
2011-06-28 21:30:06 +00:00
|
|
|
// Poll keyboard/mouse event
|
|
|
|
key_status->keyboard_state_acces(cpad);
|
|
|
|
PollForX11KeyboardInput(cpad);
|
|
|
|
|
|
|
|
// Get joystick state
|
|
|
|
key_status->joystick_state_acces(cpad);
|
|
|
|
PollForJoystickInput(cpad);
|
|
|
|
|
|
|
|
key_status->commit_status(cpad);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-04 22:12:37 +00:00
|
|
|
EXPORT_C_(void) PADconfigure()
|
|
|
|
{
|
|
|
|
LoadConfig();
|
|
|
|
|
2010-06-05 08:22:14 +00:00
|
|
|
DisplayDialog();
|
|
|
|
return;
|
2009-07-03 11:45:47 +00:00
|
|
|
}
|