2009-10-30 22:34:27 +00:00
|
|
|
/* GSnull
|
2010-05-03 14:08:02 +00:00
|
|
|
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-11-01 06:47:32 +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-10-30 22:34:27 +00:00
|
|
|
*
|
2009-11-01 06:47:32 +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-10-30 22:34:27 +00:00
|
|
|
*
|
2009-11-01 06:47:32 +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-10-30 22:34:27 +00:00
|
|
|
*/
|
|
|
|
|
2009-11-01 06:47:32 +00:00
|
|
|
|
2009-10-30 22:34:27 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#include "GS.h"
|
2010-08-06 09:30:36 +00:00
|
|
|
#include "GifTransfer.h"
|
2009-10-30 22:34:27 +00:00
|
|
|
#include "null/GSnull.h"
|
|
|
|
|
|
|
|
const unsigned char version = PS2E_GS_VERSION;
|
|
|
|
const unsigned char revision = 0;
|
|
|
|
const unsigned char build = 1; // increase that with each version
|
|
|
|
|
|
|
|
static char *libraryName = "GSnull Driver";
|
|
|
|
FILE *gsLog;
|
|
|
|
Config conf;
|
|
|
|
u32 GSKeyEvent = 0;
|
|
|
|
bool GSShift = false, GSAlt = false;
|
|
|
|
|
2009-12-19 18:30:56 +00:00
|
|
|
string s_strIniPath="inis";
|
2010-06-11 17:31:45 +00:00
|
|
|
std::string s_strLogPath("logs/");
|
2009-12-19 18:30:56 +00:00
|
|
|
const char* s_iniFilename = "GSnull.ini";
|
2010-08-06 09:30:36 +00:00
|
|
|
GSVars gs;
|
2009-12-19 18:30:56 +00:00
|
|
|
|
2009-12-26 00:01:30 +00:00
|
|
|
// Because I haven't bothered to get GSOpen2 working in Windows yet in GSNull.
|
|
|
|
#ifdef __LINUX__
|
|
|
|
#define USE_GSOPEN2
|
|
|
|
#endif
|
|
|
|
|
2009-10-30 22:34:27 +00:00
|
|
|
void (*GSirq)();
|
2010-08-06 22:58:30 +00:00
|
|
|
extern void ResetRegs();
|
|
|
|
extern void SetMultithreaded();
|
|
|
|
extern void SetFrameSkip(bool skip);
|
|
|
|
extern void InitPath();
|
2009-10-30 22:34:27 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
EXPORT_C_(u32) PS2EgetLibType()
|
2009-10-30 22:34:27 +00:00
|
|
|
{
|
|
|
|
return PS2E_LT_GS;
|
|
|
|
}
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
EXPORT_C_(char*) PS2EgetLibName()
|
2009-10-30 22:34:27 +00:00
|
|
|
{
|
|
|
|
return libraryName;
|
|
|
|
}
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
EXPORT_C_(u32) PS2EgetLibVersion2(u32 type)
|
2009-10-30 22:34:27 +00:00
|
|
|
{
|
|
|
|
return (version<<16) | (revision<<8) | build;
|
|
|
|
}
|
|
|
|
|
2010-06-11 17:31:45 +00:00
|
|
|
bool OpenLog() {
|
|
|
|
bool result = true;
|
|
|
|
#ifdef GS_LOG
|
|
|
|
const std::string LogFile(s_strLogPath + "GSnull.log");
|
|
|
|
|
|
|
|
gsLog = fopen(LogFile.c_str(), "w");
|
|
|
|
if (gsLog != NULL)
|
|
|
|
setvbuf(gsLog, NULL, _IONBF, 0);
|
|
|
|
else {
|
|
|
|
SysMessage("Can't create log file %s\n", LogFile.c_str());
|
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
GS_LOG("GSnull plugin version %d,%d\n",revision,build);
|
|
|
|
GS_LOG("GS init\n");
|
|
|
|
#endif
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
void __Log(char *fmt, ...)
|
2009-10-30 22:34:27 +00:00
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
|
|
|
|
if (!conf.Log || gsLog == NULL) return;
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
vfprintf(gsLog, fmt, list);
|
|
|
|
va_end(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(void) GSprintf(int timeout, char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
char msg[512];
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
vsprintf(msg, fmt, list);
|
|
|
|
va_end(list);
|
|
|
|
|
|
|
|
GS_LOG("GSprintf:%s", msg);
|
|
|
|
printf("GSprintf:%s", msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SysPrintf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
char msg[512];
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
vsprintf(msg, fmt, list);
|
|
|
|
va_end(list);
|
|
|
|
|
|
|
|
GS_LOG(msg);
|
|
|
|
printf("GSnull:%s", msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
// basic funcs
|
2010-06-10 16:30:08 +00:00
|
|
|
EXPORT_C_(void) GSsetSettingsDir(const char* dir)
|
|
|
|
{
|
|
|
|
s_strIniPath = (dir == NULL) ? "inis/" : dir;
|
|
|
|
}
|
2009-10-30 22:34:27 +00:00
|
|
|
|
2010-06-11 17:31:45 +00:00
|
|
|
EXPORT_C_(void) GSsetLogDir(const char* dir)
|
|
|
|
{
|
|
|
|
// Get the path to the log directory.
|
|
|
|
s_strLogPath = (dir==NULL) ? "logs/" : dir;
|
|
|
|
|
|
|
|
// Reload the log file after updated the path
|
|
|
|
if (gsLog != NULL) fclose(gsLog);
|
|
|
|
OpenLog();
|
|
|
|
}
|
|
|
|
|
2009-10-30 22:34:27 +00:00
|
|
|
EXPORT_C_(s32) GSinit()
|
|
|
|
{
|
|
|
|
LoadConfig();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-06-11 17:31:45 +00:00
|
|
|
OpenLog();
|
2009-10-30 22:34:27 +00:00
|
|
|
|
|
|
|
SysPrintf("Initializing GSnull\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(void) GSshutdown()
|
|
|
|
{
|
2009-12-19 18:30:56 +00:00
|
|
|
SysPrintf("Shutting down GSnull\n");
|
|
|
|
GSCloseWindow();
|
|
|
|
|
2009-10-30 22:34:27 +00:00
|
|
|
#ifdef GS_LOG
|
|
|
|
if (gsLog) fclose(gsLog);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(s32) GSopen(void *pDsp, char *Title, int multithread)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
GS_LOG("GS open\n");
|
|
|
|
//assert( GSirq != NULL );
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-10-30 22:34:27 +00:00
|
|
|
err = GSOpenWindow(pDsp, Title);
|
2010-08-06 22:58:30 +00:00
|
|
|
gs.MultiThreaded = multithread;
|
2009-10-30 22:34:27 +00:00
|
|
|
|
2010-08-06 22:58:30 +00:00
|
|
|
ResetRegs();
|
|
|
|
SetMultithreaded();
|
|
|
|
InitPath();
|
2009-10-30 22:34:27 +00:00
|
|
|
SysPrintf("Opening GSnull\n");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
#ifdef USE_GSOPEN2
|
2009-12-26 00:01:30 +00:00
|
|
|
EXPORT_C_(s32) GSopen2( void *pDsp, u32 flags )
|
|
|
|
{
|
|
|
|
GS_LOG("GS open2\n");
|
|
|
|
|
|
|
|
GSOpenWindow2(pDsp, flags);
|
|
|
|
|
2010-08-06 22:58:30 +00:00
|
|
|
gs.MultiThreaded = true;
|
|
|
|
|
|
|
|
ResetRegs();
|
|
|
|
SetMultithreaded();
|
|
|
|
InitPath();
|
2009-12-26 00:01:30 +00:00
|
|
|
SysPrintf("Opening GSnull (2)\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-10-30 22:34:27 +00:00
|
|
|
EXPORT_C_(void) GSclose()
|
|
|
|
{
|
|
|
|
SysPrintf("Closing GSnull\n");
|
2009-12-19 18:30:56 +00:00
|
|
|
|
|
|
|
// Better to only close the window on Shutdown. All the other plugins
|
|
|
|
// pretty much worked that way, and all old PCSX2 versions expect it as well.
|
|
|
|
//GSCloseWindow();
|
2009-10-30 22:34:27 +00:00
|
|
|
}
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
EXPORT_C_(void) GSirqCallback(void (*callback)())
|
2009-10-30 22:34:27 +00:00
|
|
|
{
|
|
|
|
GSirq = callback;
|
|
|
|
}
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
EXPORT_C_(s32) GSfreeze(int mode, freezeData *data)
|
2009-10-30 22:34:27 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
EXPORT_C_(s32) GStest()
|
2009-10-30 22:34:27 +00:00
|
|
|
{
|
|
|
|
SysPrintf("Testing GSnull\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(void) GSvsync(int field)
|
|
|
|
{
|
|
|
|
GSProcessMessages();
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns the last tag processed (64 bits)
|
|
|
|
EXPORT_C_(void) GSgetLastTag(u64* ptag)
|
|
|
|
{
|
2010-08-06 09:30:36 +00:00
|
|
|
*(u32*)ptag = gs.nPath3Hack;
|
|
|
|
gs.nPath3Hack = 0;
|
2009-10-30 22:34:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(void) GSgifSoftReset(u32 mask)
|
|
|
|
{
|
|
|
|
SysPrintf("Doing a soft reset of the GS plugin.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(void) GSreadFIFO(u64 *mem)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(void) GSreadFIFO2(u64 *mem, int qwc)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// extended funcs
|
|
|
|
|
|
|
|
// GSkeyEvent gets called when there is a keyEvent from the PAD plugin
|
|
|
|
EXPORT_C_(void) GSkeyEvent(keyEvent *ev)
|
|
|
|
{
|
|
|
|
HandleKeyEvent(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(void) GSchangeSaveState(int, const char* filename)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(void) GSmakeSnapshot(char *path)
|
|
|
|
{
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-10-30 22:34:27 +00:00
|
|
|
SysPrintf("Taking a snapshot.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(void) GSmakeSnapshot2(char *pathname, int* snapdone, int savejpg)
|
|
|
|
{
|
|
|
|
SysPrintf("Taking a snapshot to %s.\n", pathname);
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(void) GSsetBaseMem(void*)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(void) GSsetGameCRC(int crc, int gameoptions)
|
|
|
|
{
|
|
|
|
SysPrintf("Setting the crc to '%x' with 0x%x for options.\n", crc, gameoptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
// controls frame skipping in the GS, if this routine isn't present, frame skipping won't be done
|
|
|
|
EXPORT_C_(void) GSsetFrameSkip(int frameskip)
|
|
|
|
{
|
2010-08-06 22:58:30 +00:00
|
|
|
SetFrameSkip(frameskip != 0);
|
2009-10-30 22:34:27 +00:00
|
|
|
SysPrintf("Frameskip set to %d.\n", frameskip);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if start is 1, starts recording spu2 data, else stops
|
|
|
|
// returns a non zero value if successful
|
|
|
|
// for now, pData is not used
|
|
|
|
EXPORT_C_(int) GSsetupRecording(int start, void* pData)
|
|
|
|
{
|
|
|
|
if (start)
|
|
|
|
SysPrintf("Pretending to record.\n");
|
2010-04-25 00:31:27 +00:00
|
|
|
else
|
2009-10-30 22:34:27 +00:00
|
|
|
SysPrintf("Pretending to stop recording.\n");
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-10-30 22:34:27 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(void) GSreset()
|
|
|
|
{
|
|
|
|
SysPrintf("Doing a reset of the GS plugin.");
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(void) GSwriteCSR(u32 value)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(void) GSgetDriverInfo(GSdriverInfo *info)
|
|
|
|
{
|
|
|
|
}
|