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
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "onepad.h"
|
2013-06-28 10:43:50 +00:00
|
|
|
#include "svnrev.h"
|
2009-07-03 11:45:47 +00:00
|
|
|
|
2014-08-03 18:11:22 +00:00
|
|
|
#ifdef __linux__
|
2009-07-03 11:45:47 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2013-06-28 17:11:16 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define snprintf sprintf_s
|
|
|
|
#endif
|
2009-07-03 11:45:47 +00:00
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
PADconf* conf;
|
2015-04-16 21:14:12 +00:00
|
|
|
static char libraryName[256];
|
2009-07-03 11:45:47 +00:00
|
|
|
|
|
|
|
keyEvent event;
|
|
|
|
|
|
|
|
static keyEvent s_event;
|
2010-05-22 02:52:47 +00:00
|
|
|
std::string s_strIniPath("inis/");
|
2010-08-23 18:30:48 +00:00
|
|
|
std::string s_strLogPath("logs/");
|
2015-11-01 09:32:56 +00:00
|
|
|
bool toggleAutoRepeat = false;
|
2009-07-03 11:45:47 +00:00
|
|
|
|
|
|
|
const u32 version = PS2E_PAD_VERSION;
|
2011-06-17 20:44:46 +00:00
|
|
|
const u32 revision = 1;
|
2015-10-17 16:57:28 +00:00
|
|
|
const u32 build = 2; // increase that with each version
|
2009-07-03 11:45:47 +00:00
|
|
|
|
2016-02-27 19:04:06 +00:00
|
|
|
// Useless variable ...
|
|
|
|
//int PadEnum[2][2] = {{0, 2}, {1, 3}};
|
2009-07-03 11:45:47 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
u8 stdpar[2][20] = {
|
2009-07-03 11:45:47 +00:00
|
|
|
{0xff, 0x5a, 0xff, 0xff, 0x80, 0x80, 0x80, 0x80,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0xff, 0x5a, 0xff, 0xff, 0x80, 0x80, 0x80, 0x80,
|
|
|
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00}
|
|
|
|
};
|
|
|
|
u8 cmd40[2][8] = {
|
|
|
|
{0xff, 0x5a, 0x00, 0x00, 0x02, 0x00, 0x00, 0x5a},
|
|
|
|
{0xff, 0x5a, 0x00, 0x00, 0x02, 0x00, 0x00, 0x5a}
|
|
|
|
};
|
|
|
|
u8 cmd41[2][8] = {
|
|
|
|
{0xff, 0x5a, 0xff, 0xff, 0x03, 0x00, 0x00, 0x5a},
|
|
|
|
{0xff, 0x5a, 0xff, 0xff, 0x03, 0x00, 0x00, 0x5a}
|
|
|
|
};
|
|
|
|
u8 unk46[2][8] = {
|
|
|
|
{0xFF, 0x5A, 0x00, 0x00, 0x01, 0x02, 0x00, 0x0A},
|
|
|
|
{0xFF, 0x5A, 0x00, 0x00, 0x01, 0x02, 0x00, 0x0A}
|
|
|
|
};
|
|
|
|
u8 unk47[2][8] = {
|
|
|
|
{0xff, 0x5a, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00},
|
|
|
|
{0xff, 0x5a, 0x00, 0x00, 0x02, 0x00, 0x01, 0x00}
|
|
|
|
};
|
|
|
|
u8 unk4c[2][8] = {
|
|
|
|
{0xff, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0xff, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
|
|
|
|
};
|
2010-04-25 00:31:27 +00:00
|
|
|
u8 unk4d[2][8] = {
|
2009-07-03 11:45:47 +00:00
|
|
|
{0xff, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
|
|
|
|
{0xff, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
|
|
|
|
};
|
2010-04-25 00:31:27 +00:00
|
|
|
u8 cmd4f[2][8] = {
|
2009-07-03 11:45:47 +00:00
|
|
|
{0xff, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5a},
|
|
|
|
{0xff, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5a}
|
|
|
|
};
|
2010-04-25 00:31:27 +00:00
|
|
|
u8 stdcfg[2][8] = {
|
2009-07-03 11:45:47 +00:00
|
|
|
{0xff, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0xff, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
|
|
|
|
}; // 2 & 3 = 0
|
2010-04-25 00:31:27 +00:00
|
|
|
u8 stdmode[2][8] = {
|
2009-07-03 11:45:47 +00:00
|
|
|
{0xff, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
|
|
|
|
{0xff, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
|
|
|
|
};
|
2010-04-25 00:31:27 +00:00
|
|
|
u8 stdmodel[2][8] = {
|
2009-07-03 11:45:47 +00:00
|
|
|
{0xff,
|
|
|
|
0x5a,
|
|
|
|
0x03, // 03 - dualshock2, 01 - dualshock
|
|
|
|
0x02, // number of modes
|
|
|
|
0x01, // current mode: 01 - analog, 00 - digital
|
|
|
|
0x02,
|
|
|
|
0x01,
|
|
|
|
0x00},
|
2010-04-25 00:31:27 +00:00
|
|
|
{0xff,
|
2009-07-03 11:45:47 +00:00
|
|
|
0x5a,
|
|
|
|
0x03, // 03 - dualshock2, 01 - dualshock
|
|
|
|
0x02, // number of modes
|
|
|
|
0x01, // current mode: 01 - analog, 00 - digital
|
|
|
|
0x02,
|
|
|
|
0x01,
|
|
|
|
0x00}
|
|
|
|
};
|
|
|
|
|
|
|
|
u8 *buf;
|
|
|
|
int padID[2];
|
|
|
|
int padMode[2];
|
2009-12-26 00:01:30 +00:00
|
|
|
int curPad, curByte, curCmd, cmdLen;
|
2009-07-03 11:45:47 +00:00
|
|
|
int ds2mode = 0; // DS Mode at start
|
|
|
|
FILE *padLog = NULL;
|
|
|
|
|
2011-06-28 21:30:06 +00:00
|
|
|
pthread_spinlock_t mutex_KeyEvent;
|
2013-06-15 07:20:02 +00:00
|
|
|
bool mutex_WasInit = false;
|
2011-06-28 21:30:06 +00:00
|
|
|
KeyStatus* key_status = NULL;
|
2011-06-12 14:48:36 +00:00
|
|
|
|
|
|
|
queue<keyEvent> ev_fifo;
|
|
|
|
|
|
|
|
static int padVib0[2];
|
|
|
|
static int padVib1[2];
|
2011-10-29 07:57:06 +00:00
|
|
|
//static int padVibC[2];
|
2011-06-12 14:48:36 +00:00
|
|
|
static int padVibF[2][4];
|
2009-07-03 11:45:47 +00:00
|
|
|
|
|
|
|
static void InitLibraryName()
|
|
|
|
{
|
2013-06-28 10:43:50 +00:00
|
|
|
#ifdef PUBLIC
|
2009-07-03 11:45:47 +00:00
|
|
|
|
|
|
|
// Public Release!
|
|
|
|
// Output a simplified string that's just our name:
|
|
|
|
|
|
|
|
strcpy(libraryName, "OnePAD");
|
|
|
|
|
2013-06-28 10:43:50 +00:00
|
|
|
#else
|
2009-07-03 11:45:47 +00:00
|
|
|
|
|
|
|
// Use TortoiseSVN's SubWCRev utility's output
|
|
|
|
// to label the specific revision:
|
|
|
|
|
2014-03-25 16:29:47 +00:00
|
|
|
snprintf(libraryName, 255, "OnePAD %lld%s"
|
2013-06-28 10:43:50 +00:00
|
|
|
# ifdef PCSX2_DEBUG
|
2009-07-03 11:45:47 +00:00
|
|
|
"-Debug"
|
2016-05-18 21:57:34 +00:00
|
|
|
# elif defined(PCSX2_DEVBUILD)
|
2009-07-03 11:45:47 +00:00
|
|
|
"-Dev"
|
2013-06-28 10:43:50 +00:00
|
|
|
# endif
|
2009-07-03 11:45:47 +00:00
|
|
|
, SVN_REV,
|
|
|
|
SVN_MODS ? "m" : ""
|
|
|
|
);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(u32) PS2EgetLibType()
|
|
|
|
{
|
|
|
|
return PS2E_LT_PAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(char*) PS2EgetLibName()
|
|
|
|
{
|
|
|
|
InitLibraryName();
|
|
|
|
return libraryName;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(u32) PS2EgetLibVersion2(u32 type)
|
|
|
|
{
|
|
|
|
return (version << 16) | (revision << 8) | build;
|
|
|
|
}
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
void __Log(const char *fmt, ...)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
|
|
|
|
if (padLog == NULL) return;
|
|
|
|
va_start(list, fmt);
|
|
|
|
vfprintf(padLog, fmt, list);
|
|
|
|
va_end(list);
|
|
|
|
}
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
void __LogToConsole(const char *fmt, ...)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
|
|
|
|
if (padLog != NULL) vfprintf(padLog, fmt, list);
|
|
|
|
|
|
|
|
printf("OnePAD: ");
|
|
|
|
vprintf(fmt, list);
|
|
|
|
va_end(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void initLogging()
|
|
|
|
{
|
|
|
|
#ifdef PAD_LOG
|
2010-08-23 18:30:48 +00:00
|
|
|
if (padLog) return;
|
|
|
|
|
|
|
|
const std::string LogFile(s_strLogPath + "padLog.txt");
|
|
|
|
padLog = fopen(LogFile.c_str(), "w");
|
|
|
|
|
|
|
|
if (padLog)
|
|
|
|
setvbuf(padLog, NULL, _IONBF, 0);
|
|
|
|
|
|
|
|
PAD_LOG("PADinit\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void CloseLogging()
|
|
|
|
{
|
|
|
|
#ifdef PAD_LOG
|
|
|
|
if (padLog)
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
2010-08-23 18:30:48 +00:00
|
|
|
fclose(padLog);
|
|
|
|
padLog = NULL;
|
2009-07-03 11:45:47 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
void clearPAD(int pad)
|
2009-07-10 00:05:05 +00:00
|
|
|
{
|
2011-06-12 14:48:36 +00:00
|
|
|
conf->keysym_map[pad].clear();
|
|
|
|
for (int key= 0; key < MAX_KEYS; ++key)
|
|
|
|
set_key(pad, key, 0);
|
2009-07-10 00:05:05 +00:00
|
|
|
}
|
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
EXPORT_C_(s32) PADinit(u32 flags)
|
|
|
|
{
|
|
|
|
initLogging();
|
|
|
|
|
|
|
|
LoadConfig();
|
|
|
|
|
|
|
|
PADsetMode(0, 0);
|
|
|
|
PADsetMode(1, 0);
|
|
|
|
|
2011-06-28 21:30:06 +00:00
|
|
|
key_status = new KeyStatus();
|
2009-07-03 11:45:47 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(void) PADshutdown()
|
|
|
|
{
|
2015-06-27 21:49:49 +00:00
|
|
|
CloseLogging();
|
|
|
|
delete conf;
|
|
|
|
conf = nullptr;
|
|
|
|
delete key_status;
|
|
|
|
key_status = nullptr;
|
2009-07-03 11:45:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(s32) PADopen(void *pDsp)
|
|
|
|
{
|
|
|
|
memset(&event, 0, sizeof(event));
|
2011-06-28 21:30:06 +00:00
|
|
|
key_status->Init();
|
2009-07-03 11:45:47 +00:00
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
while (!ev_fifo.empty()) ev_fifo.pop();
|
2011-06-28 21:30:06 +00:00
|
|
|
pthread_spin_init(&mutex_KeyEvent, PTHREAD_PROCESS_PRIVATE);
|
2013-06-15 07:20:02 +00:00
|
|
|
mutex_WasInit = true;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2016-05-01 08:54:53 +00:00
|
|
|
#if defined(__unix__)
|
2015-10-14 13:05:02 +00:00
|
|
|
GamePad::EnumerateGamePads(s_vgamePad);
|
2009-07-03 11:45:47 +00:00
|
|
|
#endif
|
|
|
|
return _PADopen(pDsp);
|
|
|
|
}
|
|
|
|
|
2010-08-06 11:43:21 +00:00
|
|
|
EXPORT_C_(void) PADsetSettingsDir(const char* dir)
|
2010-05-22 02:52:47 +00:00
|
|
|
{
|
|
|
|
// Get the path to the ini directory.
|
|
|
|
s_strIniPath = (dir==NULL) ? "inis/" : dir;
|
|
|
|
}
|
|
|
|
|
2010-08-23 18:30:48 +00:00
|
|
|
EXPORT_C_(void) PADsetLogDir(const char* dir)
|
|
|
|
{
|
|
|
|
// Get the path to the log directory.
|
|
|
|
s_strLogPath = (dir==NULL) ? "logs/" : dir;
|
|
|
|
|
|
|
|
// Reload the log file after updated the path
|
|
|
|
CloseLogging();
|
|
|
|
initLogging();
|
|
|
|
}
|
2010-05-22 02:52:47 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
EXPORT_C_(void) PADclose()
|
|
|
|
{
|
2011-06-12 14:48:36 +00:00
|
|
|
while (!ev_fifo.empty()) ev_fifo.pop();
|
2013-06-15 07:20:02 +00:00
|
|
|
mutex_WasInit = false;
|
2011-06-28 21:30:06 +00:00
|
|
|
pthread_spin_destroy(&mutex_KeyEvent);
|
2009-07-03 11:45:47 +00:00
|
|
|
_PADclose();
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(u32) PADquery()
|
|
|
|
{
|
|
|
|
return 3; // both
|
|
|
|
}
|
|
|
|
|
|
|
|
void PADsetMode(int pad, int mode)
|
|
|
|
{
|
|
|
|
padMode[pad] = mode;
|
2011-06-12 14:48:36 +00:00
|
|
|
padVib0[pad] = 0;
|
|
|
|
padVib1[pad] = 0;
|
|
|
|
padVibF[pad][0] = 0;
|
|
|
|
padVibF[pad][1] = 0;
|
2009-07-03 11:45:47 +00:00
|
|
|
switch (ds2mode)
|
|
|
|
{
|
|
|
|
case 0: // dualshock
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case 0: // digital
|
|
|
|
padID[pad] = 0x41;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: // analog
|
|
|
|
padID[pad] = 0x73;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
case 1: // dualshock2
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case 0: // digital
|
|
|
|
padID[pad] = 0x41;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: // analog
|
|
|
|
padID[pad] = 0x79;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(u8) PADstartPoll(int pad)
|
|
|
|
{
|
|
|
|
//PAD_LOG("PADstartPoll: %d\n", pad);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
curPad = pad - 1;
|
|
|
|
curByte = 0;
|
|
|
|
|
|
|
|
return 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 _PADpoll(u8 value)
|
|
|
|
{
|
2009-11-14 09:02:10 +00:00
|
|
|
u8 button_check = 0;
|
2011-06-12 14:48:36 +00:00
|
|
|
int vib_small;
|
|
|
|
int vib_big;
|
2009-07-03 11:45:47 +00:00
|
|
|
|
|
|
|
if (curByte == 0)
|
|
|
|
{
|
|
|
|
curByte++;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
//PAD_LOG("PADpoll: cmd: %x\n", value);
|
|
|
|
|
|
|
|
curCmd = value;
|
|
|
|
switch (value)
|
|
|
|
{
|
|
|
|
case CMD_SET_VREF_PARAM: // DUALSHOCK2 ENABLER
|
|
|
|
cmdLen = 8;
|
|
|
|
buf = cmd40[curPad];
|
|
|
|
return 0xf3;
|
|
|
|
|
|
|
|
case CMD_QUERY_DS2_ANALOG_MODE: // QUERY_DS2_ANALOG_MODE
|
|
|
|
cmdLen = 8;
|
|
|
|
buf = cmd41[curPad];
|
|
|
|
return 0xf3;
|
|
|
|
|
|
|
|
case CMD_READ_DATA_AND_VIBRATE: // READ_DATA
|
|
|
|
|
2011-06-28 21:30:06 +00:00
|
|
|
stdpar[curPad][2] = key_status->get(curPad) >> 8;
|
|
|
|
stdpar[curPad][3] = key_status->get(curPad) & 0xff;
|
2011-06-28 22:16:06 +00:00
|
|
|
stdpar[curPad][4] = key_status->get(curPad, PAD_R_RIGHT);
|
|
|
|
stdpar[curPad][5] = key_status->get(curPad, PAD_R_UP);
|
|
|
|
stdpar[curPad][6] = key_status->get(curPad, PAD_L_RIGHT);
|
|
|
|
stdpar[curPad][7] = key_status->get(curPad, PAD_L_UP);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
|
|
|
if (padMode[curPad] == 1)
|
2009-07-03 11:45:47 +00:00
|
|
|
cmdLen = 20;
|
2010-04-25 00:31:27 +00:00
|
|
|
else
|
2009-07-03 11:45:47 +00:00
|
|
|
cmdLen = 4;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2013-08-25 12:11:32 +00:00
|
|
|
// Square
|
|
|
|
stdpar[curPad][15] = !test_bit(stdpar[curPad][3], 7) ? key_status->get(curPad, PAD_SQUARE) : 0;
|
|
|
|
// X
|
|
|
|
stdpar[curPad][14] = !test_bit(stdpar[curPad][3], 6) ? key_status->get(curPad, PAD_CROSS) : 0;
|
|
|
|
// Circle
|
|
|
|
stdpar[curPad][13] = !test_bit(stdpar[curPad][3], 5) ? key_status->get(curPad, PAD_CIRCLE) : 0;
|
|
|
|
// Triangle
|
|
|
|
stdpar[curPad][12] = !test_bit(stdpar[curPad][3], 4) ? key_status->get(curPad, PAD_TRIANGLE) : 0;
|
|
|
|
// R1
|
|
|
|
stdpar[curPad][17] = !test_bit(stdpar[curPad][3], 3) ? key_status->get(curPad, PAD_R1) : 0;
|
|
|
|
// L1
|
|
|
|
stdpar[curPad][16] = !test_bit(stdpar[curPad][3], 2) ? key_status->get(curPad, PAD_L1) : 0;
|
|
|
|
// R2
|
|
|
|
stdpar[curPad][19] = !test_bit(stdpar[curPad][3], 1) ? key_status->get(curPad, PAD_R2) : 0;
|
|
|
|
// L2
|
|
|
|
stdpar[curPad][18] = !test_bit(stdpar[curPad][3], 0) ? key_status->get(curPad, PAD_L2) : 0;
|
|
|
|
|
2009-11-14 09:02:10 +00:00
|
|
|
button_check = stdpar[curPad][2] >> 4;
|
2013-08-25 12:11:32 +00:00
|
|
|
// LEFT
|
|
|
|
stdpar[curPad][9] = !test_bit(button_check, 3) ? key_status->get(curPad, PAD_LEFT) : 0;
|
|
|
|
// DOWN
|
|
|
|
stdpar[curPad][11] = !test_bit(button_check, 2) ? key_status->get(curPad, PAD_DOWN) : 0;
|
|
|
|
// RIGHT
|
|
|
|
stdpar[curPad][8] = !test_bit(button_check, 1) ? key_status->get(curPad, PAD_RIGHT) : 0;
|
|
|
|
// UP
|
|
|
|
stdpar[curPad][10] = !test_bit(button_check, 0) ? key_status->get(curPad, PAD_UP) : 0;
|
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
buf = stdpar[curPad];
|
2011-06-12 14:48:36 +00:00
|
|
|
|
|
|
|
/* Small Motor */
|
|
|
|
vib_small = padVibF[curPad][0] ? 2000 : 0;
|
|
|
|
// if ((padVibF[curPad][2] != vib_small) && (padVibC[curPad] >= 0))
|
|
|
|
if (padVibF[curPad][2] != vib_small)
|
|
|
|
{
|
|
|
|
padVibF[curPad][2] = vib_small;
|
2015-11-10 07:12:20 +00:00
|
|
|
GamePad::DoRumble(0, curPad);
|
2011-06-12 14:48:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Big Motor */
|
|
|
|
vib_big = padVibF[curPad][1] ? 500 + 37*padVibF[curPad][1] : 0;
|
|
|
|
// if ((padVibF[curPad][3] != vib_big) && (padVibC[curPad] >= 0))
|
|
|
|
if (padVibF[curPad][3] != vib_big)
|
|
|
|
{
|
|
|
|
padVibF[curPad][3] = vib_big;
|
2015-11-10 07:12:20 +00:00
|
|
|
GamePad::DoRumble(1, curPad);
|
2011-06-12 14:48:36 +00:00
|
|
|
}
|
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
return padID[curPad];
|
|
|
|
|
|
|
|
case CMD_CONFIG_MODE: // CONFIG_MODE
|
|
|
|
cmdLen = 8;
|
|
|
|
buf = stdcfg[curPad];
|
|
|
|
if (stdcfg[curPad][3] == 0xff)
|
|
|
|
return 0xf3;
|
2010-04-25 00:31:27 +00:00
|
|
|
else
|
2009-07-03 11:45:47 +00:00
|
|
|
return padID[curPad];
|
|
|
|
|
|
|
|
case CMD_SET_MODE_AND_LOCK: // SET_MODE_AND_LOCK
|
|
|
|
cmdLen = 8;
|
|
|
|
buf = stdmode[curPad];
|
|
|
|
return 0xf3;
|
|
|
|
|
|
|
|
case CMD_QUERY_MODEL_AND_MODE: // QUERY_MODEL_AND_MODE
|
|
|
|
cmdLen = 8;
|
|
|
|
buf = stdmodel[curPad];
|
|
|
|
buf[4] = padMode[curPad];
|
|
|
|
return 0xf3;
|
|
|
|
|
|
|
|
case CMD_QUERY_ACT: // ??
|
|
|
|
cmdLen = 8;
|
|
|
|
buf = unk46[curPad];
|
|
|
|
return 0xf3;
|
|
|
|
|
|
|
|
case CMD_QUERY_COMB: // ??
|
|
|
|
cmdLen = 8;
|
|
|
|
buf = unk47[curPad];
|
|
|
|
return 0xf3;
|
|
|
|
|
|
|
|
case CMD_QUERY_MODE: // QUERY_MODE ??
|
|
|
|
cmdLen = 8;
|
|
|
|
buf = unk4c[curPad];
|
|
|
|
return 0xf3;
|
|
|
|
|
|
|
|
case CMD_VIBRATION_TOGGLE:
|
|
|
|
cmdLen = 8;
|
|
|
|
buf = unk4d[curPad];
|
|
|
|
return 0xf3;
|
|
|
|
|
|
|
|
case CMD_SET_DS2_NATIVE_MODE: // SET_DS2_NATIVE_MODE
|
|
|
|
cmdLen = 8;
|
|
|
|
padID[curPad] = 0x79; // setting ds2 mode
|
|
|
|
ds2mode = 1; // Set DS2 Mode
|
|
|
|
buf = cmd4f[curPad];
|
|
|
|
return 0xf3;
|
|
|
|
|
|
|
|
default:
|
|
|
|
PAD_LOG("*PADpoll*: unknown cmd %x\n", value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (curCmd)
|
|
|
|
{
|
2011-06-12 14:48:36 +00:00
|
|
|
case CMD_READ_DATA_AND_VIBRATE:
|
2015-10-14 14:06:31 +00:00
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
if (curByte == padVib0[curPad])
|
2015-11-22 22:18:02 +00:00
|
|
|
padVibF[curPad][0] = value&1;
|
2011-06-12 14:48:36 +00:00
|
|
|
if (curByte == padVib1[curPad])
|
|
|
|
padVibF[curPad][1] = value;
|
|
|
|
break;
|
2009-07-03 11:45:47 +00:00
|
|
|
case CMD_CONFIG_MODE:
|
|
|
|
if (curByte == 2)
|
|
|
|
{
|
|
|
|
switch (value)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
buf[2] = 0;
|
|
|
|
buf[3] = 0;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
buf[2] = 0xff;
|
|
|
|
buf[3] = 0xff;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CMD_SET_MODE_AND_LOCK:
|
|
|
|
if (curByte == 2)
|
|
|
|
{
|
|
|
|
PADsetMode(curPad, value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CMD_QUERY_ACT:
|
|
|
|
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 CMD_QUERY_MODE:
|
|
|
|
if (curByte == 2)
|
|
|
|
{
|
|
|
|
switch (value)
|
|
|
|
{
|
|
|
|
case 0: // mode 0 - digital mode
|
|
|
|
buf[5] = 0x4;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: // mode 1 - analog mode
|
|
|
|
buf[5] = 0x7;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2011-06-12 14:48:36 +00:00
|
|
|
|
|
|
|
case CMD_VIBRATION_TOGGLE:
|
2015-10-14 14:06:31 +00:00
|
|
|
|
2011-06-12 14:48:36 +00:00
|
|
|
if (curByte >= 2)
|
|
|
|
{
|
|
|
|
if (curByte == padVib0[curPad])
|
|
|
|
buf[curByte] = 0x00;
|
|
|
|
if (curByte == padVib1[curPad])
|
|
|
|
buf[curByte] = 0x01;
|
|
|
|
if (value == 0x00)
|
|
|
|
{
|
|
|
|
padVib0[curPad] = curByte;
|
|
|
|
}
|
|
|
|
else if (value == 0x01)
|
|
|
|
{
|
|
|
|
padVib1[curPad] = curByte;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2009-07-03 11:45:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (curByte >= cmdLen) return 0;
|
|
|
|
return buf[curByte++];
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(u8) PADpoll(u8 value)
|
|
|
|
{
|
|
|
|
u8 ret;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-07-03 11:45:47 +00:00
|
|
|
ret = _PADpoll(value);
|
|
|
|
//PAD_LOG("PADpoll: %x (%d: %x)\n", value, curByte, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
// PADkeyEvent is called every vsync (return NULL if no event)
|
2010-08-06 11:43:21 +00:00
|
|
|
EXPORT_C_(keyEvent*) PADkeyEvent()
|
2009-07-03 11:45:47 +00:00
|
|
|
{
|
|
|
|
s_event = event;
|
|
|
|
event.evt = 0;
|
2010-05-04 09:35:23 +00:00
|
|
|
event.key = 0;
|
2009-07-03 11:45:47 +00:00
|
|
|
return &s_event;
|
|
|
|
}
|
2011-06-12 14:48:36 +00:00
|
|
|
|
2016-05-01 08:54:53 +00:00
|
|
|
#if defined(__unix__)
|
2011-06-12 14:48:36 +00:00
|
|
|
EXPORT_C_(void) PADWriteEvent(keyEvent &evt)
|
|
|
|
{
|
2013-06-15 07:20:02 +00:00
|
|
|
// This function call be called before PADopen. Therefore we cann't
|
|
|
|
// guarantee that the spin lock was initialized
|
|
|
|
if (mutex_WasInit) {
|
|
|
|
pthread_spin_lock(&mutex_KeyEvent);
|
|
|
|
ev_fifo.push(evt);
|
|
|
|
pthread_spin_unlock(&mutex_KeyEvent);
|
|
|
|
}
|
2011-06-12 14:48:36 +00:00
|
|
|
}
|
|
|
|
#endif
|