GSnull: Make it work better with Windows and LilyPad.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1237 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
arcum42 2009-05-22 01:49:39 +00:00
parent 3b22adc4b3
commit f9cf905155
2 changed files with 379 additions and 344 deletions

View File

@ -1,344 +1,379 @@
/* GSnull /* GSnull
* Copyright (C) 2004-2009 PCSX2 Team * Copyright (C) 2004-2009 PCSX2 Team
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <string> #include <string>
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
using namespace std; using namespace std;
#include "GS.h" #include "GS.h"
#include "null/GSnull.h" #include "null/GSnull.h"
#ifdef __LINUX__ #ifdef __LINUX__
Display *display; Display *display;
int screen; int screen;
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
HINSTANCE HInst; HINSTANCE HInst;
#endif HWND GShwnd;
#endif
const unsigned char version = PS2E_GS_VERSION;
const unsigned char revision = 0; const unsigned char version = PS2E_GS_VERSION;
const unsigned char build = 1; // increase that with each version const unsigned char revision = 0;
const unsigned char build = 1; // increase that with each version
static char *libraryName = "GSnull Driver";
FILE *gsLog; static char *libraryName = "GSnull Driver";
Config conf; FILE *gsLog;
u32 GSKeyEvent = 0; Config conf;
bool GSShift = false, GSAlt = false; u32 GSKeyEvent = 0;
bool GSShift = false, GSAlt = false;
string s_strIniPath="inis/GSnull.ini";
void (*GSirq)(); string s_strIniPath="inis/GSnull.ini";
void (*GSirq)();
EXPORT_C_(u32) PS2EgetLibType()
{ EXPORT_C_(u32) PS2EgetLibType()
return PS2E_LT_GS; {
} return PS2E_LT_GS;
}
EXPORT_C_(char*) PS2EgetLibName()
{ EXPORT_C_(char*) PS2EgetLibName()
return libraryName; {
} return libraryName;
}
EXPORT_C_(u32) PS2EgetLibVersion2(u32 type)
{ EXPORT_C_(u32) PS2EgetLibVersion2(u32 type)
return (version<<16) | (revision<<8) | build; {
} return (version<<16) | (revision<<8) | build;
}
void __Log(char *fmt, ...)
{ void __Log(char *fmt, ...)
va_list list; {
va_list list;
if (!conf.Log || gsLog == NULL) return;
if (!conf.Log || gsLog == NULL) return;
va_start(list, fmt);
vfprintf(gsLog, fmt, list); va_start(list, fmt);
va_end(list); vfprintf(gsLog, fmt, list);
} va_end(list);
}
EXPORT_C_(void) GSprintf(int timeout, char *fmt, ...)
{ EXPORT_C_(void) GSprintf(int timeout, char *fmt, ...)
va_list list; {
char msg[512]; va_list list;
char msg[512];
va_start(list, fmt);
vsprintf(msg, fmt, list); va_start(list, fmt);
va_end(list); vsprintf(msg, fmt, list);
va_end(list);
GS_LOG("GSprintf:%s", msg);
printf("GSprintf:%s", msg); GS_LOG("GSprintf:%s", msg);
} printf("GSprintf:%s", msg);
}
void SysPrintf(const char *fmt, ...)
{ void SysPrintf(const char *fmt, ...)
va_list list; {
char msg[512]; va_list list;
char msg[512];
va_start(list, fmt);
vsprintf(msg, fmt, list); va_start(list, fmt);
va_end(list); vsprintf(msg, fmt, list);
va_end(list);
GS_LOG(msg);
printf("GSnull:%s", msg); GS_LOG(msg);
} printf("GSnull:%s", msg);
}
// basic funcs
// basic funcs
EXPORT_C_(s32) GSinit()
{ EXPORT_C_(s32) GSinit()
LoadConfig(); {
LoadConfig();
#ifdef GS_LOG
gsLog = fopen("logs/gsLog.txt", "w"); #ifdef GS_LOG
if (gsLog) setvbuf(gsLog, NULL, _IONBF, 0); gsLog = fopen("logs/gsLog.txt", "w");
GS_LOG("GSnull plugin version %d,%d\n",revision,build); if (gsLog) setvbuf(gsLog, NULL, _IONBF, 0);
GS_LOG("GS init\n"); GS_LOG("GSnull plugin version %d,%d\n",revision,build);
#endif GS_LOG("GS init\n");
#endif
SysPrintf("Initializing GSnull\n");
return 0; SysPrintf("Initializing GSnull\n");
} return 0;
}
EXPORT_C_(void) GSshutdown()
{ EXPORT_C_(void) GSshutdown()
#ifdef GS_LOG {
if (gsLog) fclose(gsLog); #ifdef GS_LOG
#endif if (gsLog) fclose(gsLog);
#endif
SysPrintf("Shutting down GSnull\n");
} SysPrintf("Shutting down GSnull\n");
}
EXPORT_C_(s32) GSopen(void *pDsp, char *Title, int multithread)
{ #ifndef __LINUX__
#ifdef GS_LOG LRESULT CALLBACK MsgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
GS_LOG("GS open\n"); {
#endif switch(msg)
//assert( GSirq != NULL ); {
case WM_CLOSE:
#ifdef __LINUX__ DestroyWindow(hwnd);
display = XOpenDisplay(0); break;
screen = DefaultScreen(display); case WM_DESTROY:
PostQuitMessage(0);
if( pDsp != NULL ) *(Display**)pDsp = display; break;
#else default:
if( pDsp != NULL ) *(int*)pDsp = (int)GetNextWindow(GetForegroundWindow(),GW_HWNDNEXT); return DefWindowProc(hwnd, msg, wParam, lParam);
(NULL); }
#endif return 0;
SysPrintf("Opening GSnull\n"); }
return 0;
} #endif
EXPORT_C_(void) GSclose() EXPORT_C_(s32) GSopen(void *pDsp, char *Title, int multithread)
{ {
SysPrintf("Closing GSnull\n"); #ifdef GS_LOG
#ifdef __LINUX__ GS_LOG("GS open\n");
XCloseDisplay(display); #endif
#endif //assert( GSirq != NULL );
}
#ifdef __LINUX__
EXPORT_C_(void) GSirqCallback(void (*callback)()) display = XOpenDisplay(0);
{ screen = DefaultScreen(display);
GSirq = callback;
} if( pDsp != NULL ) *(Display**)pDsp = display;
#else
EXPORT_C_(s32) GSfreeze(int mode, freezeData *data) WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
{ GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
return 0; "PS2EMU_GSNULL", NULL };
} RegisterClassEx( &wc );
EXPORT_C_(s32) GStest() GShwnd = CreateWindowEx( WS_EX_CLIENTEDGE, "PS2EMU_GSNULL", "The title of my window",
{ WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, NULL, NULL, wc.hInstance, NULL);
SysPrintf("Testing GSnull\n");
return 0; if(GShwnd == NULL)
} {
GS_LOG("Failed to create window. Exiting...");
void ProcessMessages() return -1;
{ }
#ifdef __LINUX__
if ( GSKeyEvent ) if( pDsp != NULL ) *(int*)pDsp = (int)GShwnd;
{ #endif
int myKeyEvent = GSKeyEvent; SysPrintf("Opening GSnull\n");
bool myShift = GSShift; return 0;
GSKeyEvent = 0; }
switch ( myKeyEvent ) EXPORT_C_(void) GSclose()
{ {
case XK_F5: SysPrintf("Closing GSnull\n");
OnKeyboardF5(myShift); #ifdef __LINUX__
break; XCloseDisplay(display);
case XK_F6: #endif
OnKeyboardF6(myShift); }
break;
case XK_F7: EXPORT_C_(void) GSirqCallback(void (*callback)())
OnKeyboardF7(myShift); {
break; GSirq = callback;
case XK_F9: }
OnKeyboardF9(myShift);
break; EXPORT_C_(s32) GSfreeze(int mode, freezeData *data)
} {
} return 0;
#endif }
}
EXPORT_C_(s32) GStest()
EXPORT_C_(void) GSvsync(int field) {
{ SysPrintf("Testing GSnull\n");
ProcessMessages(); return 0;
} }
EXPORT_C_(void) GSgifTransfer1(u32 *pMem, u32 addr) void ProcessMessages()
{ {
_GSgifTransfer1(pMem, addr); #ifdef __LINUX__
} if ( GSKeyEvent )
{
EXPORT_C_(void) GSgifTransfer2(u32 *pMem, u32 size) int myKeyEvent = GSKeyEvent;
{ bool myShift = GSShift;
_GSgifTransfer2(pMem, size); GSKeyEvent = 0;
}
switch ( myKeyEvent )
EXPORT_C_(void) GSgifTransfer3(u32 *pMem, u32 size) {
{ case XK_F5:
_GSgifTransfer3(pMem, size); OnKeyboardF5(myShift);
} break;
case XK_F6:
// returns the last tag processed (64 bits) OnKeyboardF6(myShift);
EXPORT_C_(void) GSgetLastTag(u64* ptag) break;
{ case XK_F7:
} OnKeyboardF7(myShift);
break;
EXPORT_C_(void) GSgifSoftReset(u32 mask) case XK_F9:
{ OnKeyboardF9(myShift);
SysPrintf("Doing a soft reset of the GS plugin.\n"); break;
} }
}
EXPORT_C_(void) GSreadFIFO(u64 *mem) #endif
{ }
}
EXPORT_C_(void) GSvsync(int field)
EXPORT_C_(void) GSreadFIFO2(u64 *mem, int qwc) {
{ ProcessMessages();
} }
// extended funcs EXPORT_C_(void) GSgifTransfer1(u32 *pMem, u32 addr)
{
// GSkeyEvent gets called when there is a keyEvent from the PAD plugin _GSgifTransfer1(pMem, addr);
EXPORT_C_(void) GSkeyEvent(keyEvent *ev) }
{
switch(ev->evt) { EXPORT_C_(void) GSgifTransfer2(u32 *pMem, u32 size)
case KEYPRESS: {
switch(ev->key) { _GSgifTransfer2(pMem, size);
case XK_F5: }
case XK_F6:
case XK_F7: EXPORT_C_(void) GSgifTransfer3(u32 *pMem, u32 size)
case XK_F9: {
GSKeyEvent = ev->key ; _GSgifTransfer3(pMem, size);
break; }
case XK_Escape:
break; // returns the last tag processed (64 bits)
case XK_Shift_L: EXPORT_C_(void) GSgetLastTag(u64* ptag)
case XK_Shift_R: {
//bShift = true; }
GSShift = true;
break; EXPORT_C_(void) GSgifSoftReset(u32 mask)
case XK_Alt_L: {
case XK_Alt_R: SysPrintf("Doing a soft reset of the GS plugin.\n");
GSAlt = true; }
break;
} EXPORT_C_(void) GSreadFIFO(u64 *mem)
break; {
case KEYRELEASE: }
switch(ev->key) {
case XK_Shift_L: EXPORT_C_(void) GSreadFIFO2(u64 *mem, int qwc)
case XK_Shift_R: {
//bShift = false; }
GSShift = false;
break; // extended funcs
case XK_Alt_L:
case XK_Alt_R: // GSkeyEvent gets called when there is a keyEvent from the PAD plugin
GSAlt = false; EXPORT_C_(void) GSkeyEvent(keyEvent *ev)
break; {
} #ifdef __LINUX__
} switch(ev->evt) {
} case KEYPRESS:
switch(ev->key) {
EXPORT_C_(void) GSchangeSaveState(int, const char* filename) case XK_F5:
{ case XK_F6:
} case XK_F7:
case XK_F9:
EXPORT_C_(void) GSmakeSnapshot(char *path) GSKeyEvent = ev->key ;
{ break;
case XK_Escape:
SysPrintf("Taking a snapshot.\n"); break;
} case XK_Shift_L:
case XK_Shift_R:
EXPORT_C_(void) GSmakeSnapshot2(char *pathname, int* snapdone, int savejpg) //bShift = true;
{ GSShift = true;
SysPrintf("Taking a snapshot to %s.\n", pathname); break;
} case XK_Alt_L:
case XK_Alt_R:
EXPORT_C_(void) GSsetBaseMem(void*) GSAlt = true;
{ break;
} }
break;
EXPORT_C_(void) GSsetGameCRC(int crc, int gameoptions) case KEYRELEASE:
{ switch(ev->key) {
SysPrintf("Setting the crc to '%x' with 0x%x for options.\n", crc, gameoptions); case XK_Shift_L:
} case XK_Shift_R:
//bShift = false;
// controls frame skipping in the GS, if this routine isn't present, frame skipping won't be done GSShift = false;
EXPORT_C_(void) GSsetFrameSkip(int frameskip) break;
{ case XK_Alt_L:
SysPrintf("Frameskip set to %d.\n", frameskip); case XK_Alt_R:
} GSAlt = false;
break;
// if start is 1, starts recording spu2 data, else stops }
// returns a non zero value if successful }
// for now, pData is not used #endif
EXPORT_C_(int) GSsetupRecording(int start, void* pData) }
{
if (start) EXPORT_C_(void) GSchangeSaveState(int, const char* filename)
SysPrintf("Pretending to record.\n"); {
else }
SysPrintf("Pretending to stop recording.\n");
EXPORT_C_(void) GSmakeSnapshot(char *path)
return 1; {
}
SysPrintf("Taking a snapshot.\n");
EXPORT_C_(void) GSreset() }
{
SysPrintf("Doing a reset of the GS plugin."); EXPORT_C_(void) GSmakeSnapshot2(char *pathname, int* snapdone, int savejpg)
} {
SysPrintf("Taking a snapshot to %s.\n", pathname);
EXPORT_C_(void) GSwriteCSR(u32 value) }
{
} EXPORT_C_(void) GSsetBaseMem(void*)
{
EXPORT_C_(void) GSgetDriverInfo(GSdriverInfo *info) }
{
} EXPORT_C_(void) GSsetGameCRC(int crc, int gameoptions)
{
#ifdef _WIN32 SysPrintf("Setting the crc to '%x' with 0x%x for options.\n", crc, gameoptions);
EXPORT_C_(s32) GSsetWindowInfo(winInfo *info) }
{
return 0; // controls frame skipping in the GS, if this routine isn't present, frame skipping won't be done
} EXPORT_C_(void) GSsetFrameSkip(int frameskip)
{
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");
else
SysPrintf("Pretending to stop recording.\n");
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)
{
}
#ifdef _WIN32
EXPORT_C_(s32) GSsetWindowInfo(winInfo *info)
{
return 0;
}
#endif #endif

View File

@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "GS.h" #include "../GS.h"
void OnKeyboardF5(int myShift) void OnKeyboardF5(int myShift)
{ {