2010-05-03 14:08:02 +00:00
|
|
|
/* PadNull
|
|
|
|
* Copyright (C) 2004-2010 PCSX2 Dev Team
|
2009-05-23 05:15:03 +00:00
|
|
|
*
|
2010-05-03 14:08:02 +00:00
|
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
2009-05-23 05:15:03 +00:00
|
|
|
*
|
2010-05-03 14:08:02 +00:00
|
|
|
* PCSX2 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.
|
2009-05-23 05:15:03 +00:00
|
|
|
*
|
2010-05-03 14:08:02 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
2009-05-23 05:15:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string>
|
|
|
|
using namespace std;
|
2013-06-28 10:43:50 +00:00
|
|
|
#include "svnrev.h"
|
2009-05-23 05:15:03 +00:00
|
|
|
#include "Pad.h"
|
|
|
|
|
2016-08-24 21:18:58 +00:00
|
|
|
const u8 version = PS2E_PAD_VERSION;
|
2009-05-23 05:15:03 +00:00
|
|
|
const u8 revision = 0;
|
2017-01-29 09:27:43 +00:00
|
|
|
const u8 build = 1; // increase that with each version
|
2009-05-23 05:15:03 +00:00
|
|
|
|
2013-06-28 17:11:16 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define snprintf sprintf_s
|
|
|
|
#endif
|
2012-06-18 21:16:25 +00:00
|
|
|
static char libraryName[256];
|
2016-08-24 21:18:58 +00:00
|
|
|
string s_strIniPath = "inis";
|
|
|
|
string s_strLogPath = "logs";
|
2009-05-23 05:15:03 +00:00
|
|
|
|
2016-08-28 16:14:07 +00:00
|
|
|
FILE *padLog;
|
2009-05-23 05:15:03 +00:00
|
|
|
Config conf;
|
|
|
|
keyEvent event;
|
|
|
|
static keyEvent s_event;
|
|
|
|
|
2016-08-24 21:18:58 +00:00
|
|
|
EXPORT_C_(u32)
|
|
|
|
PS2EgetLibType()
|
2009-05-23 05:15:03 +00:00
|
|
|
{
|
2016-08-24 21:18:58 +00:00
|
|
|
return PS2E_LT_PAD;
|
2009-05-23 05:15:03 +00:00
|
|
|
}
|
|
|
|
|
2017-01-29 09:27:43 +00:00
|
|
|
EXPORT_C_(const char *)
|
2016-08-24 21:18:58 +00:00
|
|
|
PS2EgetLibName()
|
2009-05-23 05:15:03 +00:00
|
|
|
{
|
2016-08-24 21:18:58 +00:00
|
|
|
snprintf(libraryName, 255, "Padnull Driver %lld%s", SVN_REV, SVN_MODS ? "m" : "");
|
|
|
|
return libraryName;
|
2009-05-23 05:15:03 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:18:58 +00:00
|
|
|
EXPORT_C_(u32)
|
|
|
|
PS2EgetLibVersion2(u32 type)
|
2009-05-23 05:15:03 +00:00
|
|
|
{
|
2016-08-24 21:18:58 +00:00
|
|
|
return (version << 16) | (revision << 8) | build;
|
2009-05-23 05:15:03 +00:00
|
|
|
}
|
|
|
|
|
2016-08-28 16:14:07 +00:00
|
|
|
void __Log(const char *fmt, ...)
|
2009-05-23 05:15:03 +00:00
|
|
|
{
|
2016-08-24 21:18:58 +00:00
|
|
|
va_list list;
|
2009-05-23 05:15:03 +00:00
|
|
|
|
2016-08-24 21:18:58 +00:00
|
|
|
if (padLog == NULL)
|
|
|
|
return;
|
|
|
|
va_start(list, fmt);
|
|
|
|
vfprintf(padLog, fmt, list);
|
|
|
|
va_end(list);
|
2009-05-23 05:15:03 +00:00
|
|
|
}
|
|
|
|
|
2016-08-28 16:14:07 +00:00
|
|
|
void __LogToConsole(const char *fmt, ...)
|
2009-05-23 05:15:03 +00:00
|
|
|
{
|
2016-08-24 21:18:58 +00:00
|
|
|
va_list list;
|
2009-05-23 05:15:03 +00:00
|
|
|
|
2016-08-24 21:18:58 +00:00
|
|
|
va_start(list, fmt);
|
2009-05-23 05:15:03 +00:00
|
|
|
|
2016-08-24 21:18:58 +00:00
|
|
|
if (padLog != NULL)
|
|
|
|
vfprintf(padLog, fmt, list);
|
2009-05-23 05:15:03 +00:00
|
|
|
|
2016-08-24 21:18:58 +00:00
|
|
|
printf("PadNull: ");
|
|
|
|
vprintf(fmt, list);
|
|
|
|
va_end(list);
|
2009-05-23 05:15:03 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:18:58 +00:00
|
|
|
EXPORT_C_(void)
|
2016-08-28 16:14:07 +00:00
|
|
|
PADsetSettingsDir(const char *dir)
|
2010-06-10 16:30:08 +00:00
|
|
|
{
|
2016-08-24 21:18:58 +00:00
|
|
|
s_strIniPath = (dir == NULL) ? "inis" : dir;
|
2010-06-10 16:30:08 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:18:58 +00:00
|
|
|
bool OpenLog()
|
|
|
|
{
|
2010-06-11 17:31:45 +00:00
|
|
|
bool result = true;
|
|
|
|
#ifdef PAD_LOG
|
2016-08-24 21:18:58 +00:00
|
|
|
if (padLog)
|
|
|
|
return result;
|
2010-06-11 17:31:45 +00:00
|
|
|
|
|
|
|
const std::string LogFile(s_strLogPath + "/padnull.log");
|
|
|
|
|
|
|
|
padLog = fopen(LogFile.c_str(), "w");
|
|
|
|
if (padLog != NULL)
|
2016-08-24 21:18:58 +00:00
|
|
|
setvbuf(padLog, NULL, _IONBF, 0);
|
2010-06-11 17:31:45 +00:00
|
|
|
else {
|
2015-11-25 19:04:19 +00:00
|
|
|
fprintf(stderr, "Can't create log file %s\n", LogFile.c_str());
|
2010-06-11 17:31:45 +00:00
|
|
|
result = false;
|
|
|
|
}
|
2016-08-24 21:18:58 +00:00
|
|
|
PAD_LOG("PADinit\n");
|
2010-06-11 17:31:45 +00:00
|
|
|
#endif
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-08-24 21:18:58 +00:00
|
|
|
EXPORT_C_(void)
|
2016-08-28 16:14:07 +00:00
|
|
|
PADsetLogDir(const char *dir)
|
2010-06-11 17:31:45 +00:00
|
|
|
{
|
2016-08-24 21:18:58 +00:00
|
|
|
// Get the path to the log directory.
|
|
|
|
s_strLogPath = (dir == NULL) ? "logs" : dir;
|
2010-06-11 17:31:45 +00:00
|
|
|
|
2016-08-24 21:18:58 +00:00
|
|
|
// Reload the log file after updated the path
|
|
|
|
if (padLog) {
|
2010-08-25 20:18:45 +00:00
|
|
|
fclose(padLog);
|
|
|
|
padLog = NULL;
|
|
|
|
}
|
2010-06-11 17:31:45 +00:00
|
|
|
OpenLog();
|
|
|
|
}
|
|
|
|
|
2016-08-24 21:18:58 +00:00
|
|
|
EXPORT_C_(s32)
|
|
|
|
PADinit(u32 flags)
|
2009-05-23 05:15:03 +00:00
|
|
|
{
|
2016-08-24 21:18:58 +00:00
|
|
|
LoadConfig();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-06-11 17:31:45 +00:00
|
|
|
OpenLog();
|
2009-05-23 05:15:03 +00:00
|
|
|
|
2016-08-24 21:18:58 +00:00
|
|
|
return 0;
|
2009-05-23 05:15:03 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:18:58 +00:00
|
|
|
EXPORT_C_(void)
|
|
|
|
PADshutdown()
|
2009-05-23 05:15:03 +00:00
|
|
|
{
|
|
|
|
#ifdef PAD_LOG
|
2016-08-24 21:18:58 +00:00
|
|
|
if (padLog) {
|
|
|
|
fclose(padLog);
|
|
|
|
padLog = NULL;
|
|
|
|
}
|
2009-05-23 05:15:03 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-08-24 21:18:58 +00:00
|
|
|
EXPORT_C_(s32)
|
2016-08-28 16:14:07 +00:00
|
|
|
PADopen(void *pDsp)
|
2009-05-23 05:15:03 +00:00
|
|
|
{
|
2016-08-24 21:18:58 +00:00
|
|
|
memset(&event, 0, sizeof(event));
|
2009-05-23 05:15:03 +00:00
|
|
|
|
2016-08-24 21:18:58 +00:00
|
|
|
return _PADOpen(pDsp);
|
2009-05-23 05:15:03 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:18:58 +00:00
|
|
|
EXPORT_C_(void)
|
|
|
|
PADclose()
|
2009-05-23 05:15:03 +00:00
|
|
|
{
|
2016-08-24 21:18:58 +00:00
|
|
|
_PADClose();
|
2009-05-23 05:15:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// PADkeyEvent is called every vsync (return NULL if no event)
|
2016-08-28 16:14:07 +00:00
|
|
|
EXPORT_C_(keyEvent *)
|
2016-08-24 21:18:58 +00:00
|
|
|
PADkeyEvent()
|
2009-05-23 05:15:03 +00:00
|
|
|
{
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2016-08-24 21:18:58 +00:00
|
|
|
s_event = event;
|
|
|
|
event.evt = 0;
|
|
|
|
event.key = 0;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2016-08-24 21:18:58 +00:00
|
|
|
return &s_event;
|
2009-05-23 05:15:03 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:18:58 +00:00
|
|
|
EXPORT_C_(u8)
|
|
|
|
PADstartPoll(int pad)
|
2009-05-23 05:15:03 +00:00
|
|
|
{
|
2016-08-24 21:18:58 +00:00
|
|
|
return 0;
|
2009-05-23 05:15:03 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:18:58 +00:00
|
|
|
EXPORT_C_(u8)
|
|
|
|
PADpoll(u8 value)
|
2009-05-23 05:15:03 +00:00
|
|
|
{
|
2016-08-24 21:18:58 +00:00
|
|
|
return 0;
|
2009-05-23 05:15:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// call to give a hint to the PAD plugin to query for the keyboard state. A
|
|
|
|
// good plugin will query the OS for keyboard state ONLY in this function.
|
|
|
|
// This function is necessary when multithreading because otherwise
|
|
|
|
// the PAD plugin can get into deadlocks with the thread that really owns
|
|
|
|
// the window (and input). Note that PADupdate can be called from a different
|
|
|
|
// thread than the other functions, so mutex or other multithreading primitives
|
|
|
|
// have to be added to maintain data integrity.
|
2016-08-24 21:18:58 +00:00
|
|
|
EXPORT_C_(u32)
|
|
|
|
PADquery()
|
2009-05-23 05:15:03 +00:00
|
|
|
// returns: 1 if supported pad1
|
|
|
|
// 2 if supported pad2
|
|
|
|
// 3 if both are supported
|
|
|
|
{
|
2016-08-24 21:18:58 +00:00
|
|
|
return 3;
|
2009-05-23 05:15:03 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:18:58 +00:00
|
|
|
EXPORT_C_(void)
|
|
|
|
PADupdate(int pad)
|
2009-05-23 05:15:03 +00:00
|
|
|
{
|
2016-08-24 21:18:58 +00:00
|
|
|
_PadUpdate(pad);
|
2009-05-23 05:15:03 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:18:58 +00:00
|
|
|
EXPORT_C_(void)
|
2016-08-28 16:14:07 +00:00
|
|
|
PADgsDriverInfo(GSdriverInfo *info)
|
2009-05-23 05:15:03 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-08-24 21:18:58 +00:00
|
|
|
EXPORT_C_(s32)
|
2016-08-28 16:14:07 +00:00
|
|
|
PADfreeze(int mode, freezeData *data)
|
2009-05-23 05:15:03 +00:00
|
|
|
{
|
2016-08-24 21:18:58 +00:00
|
|
|
return 0;
|
2009-05-23 05:15:03 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:18:58 +00:00
|
|
|
EXPORT_C_(s32)
|
|
|
|
PADtest()
|
2009-05-23 05:15:03 +00:00
|
|
|
{
|
2016-08-24 21:18:58 +00:00
|
|
|
return 0;
|
2009-05-23 05:15:03 +00:00
|
|
|
}
|