From 82f0143d23f5b87655b923cb7dfb3ba8ef07e5de Mon Sep 17 00:00:00 2001 From: arcum42 Date: Fri, 22 May 2009 02:29:01 +0000 Subject: [PATCH] GSnull: Modularise things a bit more, so we don't have a bunch of platform-specific code in the main code. (Note: the Linux side hasn't been tested yet. I'll be doing that a bit later.) git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1238 96395faa-99c1-11dd-bbfe-3dabce05a288 --- plugins/GSnull/GS.cpp | 132 +------------------- plugins/GSnull/GS.h | 11 +- plugins/GSnull/Linux/GSLinux.cpp | 104 +++++++++++++++ plugins/GSnull/Linux/GSLinux.h | 27 ++++ plugins/GSnull/Makefile.am | 12 +- plugins/GSnull/Windows/GSnull_vc2008.vcproj | 58 ++++++++- plugins/GSnull/Windows/GSwin.cpp | 77 ++++++++++++ plugins/GSnull/Windows/GSwin.h | 36 ++++++ 8 files changed, 312 insertions(+), 145 deletions(-) create mode 100644 plugins/GSnull/Linux/GSLinux.cpp create mode 100644 plugins/GSnull/Linux/GSLinux.h create mode 100644 plugins/GSnull/Windows/GSwin.cpp create mode 100644 plugins/GSnull/Windows/GSwin.h diff --git a/plugins/GSnull/GS.cpp b/plugins/GSnull/GS.cpp index d23c07cdf1..b524ce8349 100644 --- a/plugins/GSnull/GS.cpp +++ b/plugins/GSnull/GS.cpp @@ -29,15 +29,6 @@ using namespace std; #include "GS.h" #include "null/GSnull.h" -#ifdef __LINUX__ -Display *display; -int screen; -#endif -#ifdef _WIN32 -HINSTANCE HInst; -HWND GShwnd; -#endif - const unsigned char version = PS2E_GS_VERSION; const unsigned char revision = 0; const unsigned char build = 1; // increase that with each version @@ -129,64 +120,24 @@ EXPORT_C_(void) GSshutdown() SysPrintf("Shutting down GSnull\n"); } -#ifndef __LINUX__ -LRESULT CALLBACK MsgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - switch(msg) - { - case WM_CLOSE: - DestroyWindow(hwnd); - break; - case WM_DESTROY: - PostQuitMessage(0); - break; - default: - return DefWindowProc(hwnd, msg, wParam, lParam); - } - return 0; -} - -#endif - EXPORT_C_(s32) GSopen(void *pDsp, char *Title, int multithread) { + int err = 0; #ifdef GS_LOG GS_LOG("GS open\n"); #endif //assert( GSirq != NULL ); -#ifdef __LINUX__ - display = XOpenDisplay(0); - screen = DefaultScreen(display); + err = GSOpenWindow(pDsp, Title); - if( pDsp != NULL ) *(Display**)pDsp = display; -#else - WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, - GetModuleHandle(NULL), NULL, NULL, NULL, NULL, - "PS2EMU_GSNULL", NULL }; - RegisterClassEx( &wc ); - - 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); - - if(GShwnd == NULL) - { - GS_LOG("Failed to create window. Exiting..."); - return -1; - } - - if( pDsp != NULL ) *(int*)pDsp = (int)GShwnd; -#endif SysPrintf("Opening GSnull\n"); - return 0; + return err; } EXPORT_C_(void) GSclose() { SysPrintf("Closing GSnull\n"); -#ifdef __LINUX__ - XCloseDisplay(display); -#endif + GSCloseWindow(); } EXPORT_C_(void) GSirqCallback(void (*callback)()) @@ -205,37 +156,9 @@ EXPORT_C_(s32) GStest() return 0; } -void ProcessMessages() -{ -#ifdef __LINUX__ - if ( GSKeyEvent ) - { - int myKeyEvent = GSKeyEvent; - bool myShift = GSShift; - GSKeyEvent = 0; - - switch ( myKeyEvent ) - { - case XK_F5: - OnKeyboardF5(myShift); - break; - case XK_F6: - OnKeyboardF6(myShift); - break; - case XK_F7: - OnKeyboardF7(myShift); - break; - case XK_F9: - OnKeyboardF9(myShift); - break; - } - } -#endif -} - EXPORT_C_(void) GSvsync(int field) { - ProcessMessages(); + GSProcessMessages(); } EXPORT_C_(void) GSgifTransfer1(u32 *pMem, u32 addr) @@ -276,43 +199,7 @@ EXPORT_C_(void) GSreadFIFO2(u64 *mem, int qwc) // GSkeyEvent gets called when there is a keyEvent from the PAD plugin EXPORT_C_(void) GSkeyEvent(keyEvent *ev) { -#ifdef __LINUX__ - switch(ev->evt) { - case KEYPRESS: - switch(ev->key) { - case XK_F5: - case XK_F6: - case XK_F7: - case XK_F9: - GSKeyEvent = ev->key ; - break; - case XK_Escape: - break; - case XK_Shift_L: - case XK_Shift_R: - //bShift = true; - GSShift = true; - break; - case XK_Alt_L: - case XK_Alt_R: - GSAlt = true; - break; - } - break; - case KEYRELEASE: - switch(ev->key) { - case XK_Shift_L: - case XK_Shift_R: - //bShift = false; - GSShift = false; - break; - case XK_Alt_L: - case XK_Alt_R: - GSAlt = false; - break; - } - } -#endif + HandleKeyEvent(ev); } EXPORT_C_(void) GSchangeSaveState(int, const char* filename) @@ -370,10 +257,3 @@ EXPORT_C_(void) GSwriteCSR(u32 value) EXPORT_C_(void) GSgetDriverInfo(GSdriverInfo *info) { } - -#ifdef _WIN32 -EXPORT_C_(s32) GSsetWindowInfo(winInfo *info) -{ - return 0; -} -#endif \ No newline at end of file diff --git a/plugins/GSnull/GS.h b/plugins/GSnull/GS.h index a322279618..58877bac70 100644 --- a/plugins/GSnull/GS.h +++ b/plugins/GSnull/GS.h @@ -22,16 +22,9 @@ #include #ifdef _WIN32 - -#include -#include - +#include "Windows/GSwin.h" #else - -#include -#include -#include - +#include "Linux/GSLinux.h" #endif #ifdef __cplusplus diff --git a/plugins/GSnull/Linux/GSLinux.cpp b/plugins/GSnull/Linux/GSLinux.cpp new file mode 100644 index 0000000000..34c7d5149c --- /dev/null +++ b/plugins/GSnull/Linux/GSLinux.cpp @@ -0,0 +1,104 @@ +/* GSnull + * Copyright (C) 2004-2009 PCSX2 Team + * + * 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 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "GSLinux.h" + +Display *display; +int screen; + +int GSOpenWindow(void *pDsp, char *Title) +{ + display = XOpenDisplay(0); + screen = DefaultScreen(display); + + if( pDsp != NULL ) + *(Display**)pDsp = display; + else + return -1; + + return 0; +} + +void GSCloseWindow() +{ + XCloseDisplay(display); +} + +void GSProcessMessages() +{ + if ( GSKeyEvent ) + { + int myKeyEvent = GSKeyEvent; + bool myShift = GSShift; + GSKeyEvent = 0; + + switch ( myKeyEvent ) + { + case XK_F5: + OnKeyboardF5(myShift); + break; + case XK_F6: + OnKeyboardF6(myShift); + break; + case XK_F7: + OnKeyboardF7(myShift); + break; + case XK_F9: + OnKeyboardF9(myShift); + break; + } + } +} + + +void HandleKeyEvent(keyEvent *ev) +{ + switch(ev->evt) { + case KEYPRESS: + switch(ev->key) { + case XK_F5: + case XK_F6: + case XK_F7: + case XK_F9: + GSKeyEvent = ev->key ; + break; + case XK_Escape: + break; + case XK_Shift_L: + case XK_Shift_R: + GSShift = true; + break; + case XK_Alt_L: + case XK_Alt_R: + GSAlt = true; + break; + } + break; + case KEYRELEASE: + switch(ev->key) { + case XK_Shift_L: + case XK_Shift_R: + GSShift = false; + break; + case XK_Alt_L: + case XK_Alt_R: + GSAlt = false; + break; + } + } +} diff --git a/plugins/GSnull/Linux/GSLinux.h b/plugins/GSnull/Linux/GSLinux.h new file mode 100644 index 0000000000..99a686efd6 --- /dev/null +++ b/plugins/GSnull/Linux/GSLinux.h @@ -0,0 +1,27 @@ +/* GSnull + * Copyright (C) 2004-2009 PCSX2 Team + * + * 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 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include +#include "../GS.h" + +int GSOpenWindow(void *pDsp, char *Title); +void GSCloseWindow(); +void GSProcessMessages(); +void HandleKeyEvent(keyEvent *ev); \ No newline at end of file diff --git a/plugins/GSnull/Makefile.am b/plugins/GSnull/Makefile.am index 21f39566fa..da1ecce6a1 100644 --- a/plugins/GSnull/Makefile.am +++ b/plugins/GSnull/Makefile.am @@ -22,12 +22,14 @@ libGSnull_LDFLAGS= @SHARED_LDFLAGS@ libGSnull_LDFLAGS+=-Wl,-soname,@libGSnull_SONAME@ libGSnull_LDADD=$(libGSnull_a_OBJECTS) -libGSnull_a_SOURCES = GS.cpp Linux/Config.cpp Linux/Linux.cpp \ -FW.h Linux/Config.h Linux/Linux.h +libGSnull_a_SOURCES = \ +GS.cpp \ +Linux/Config.cpp Linux/Linux.cpp Linux/GSLinux.cpp +Linux/GSLinux.h Linux/Config.h Linux/Linux.h \ +GifTransfer.cpp GifTransfer.h \ +null/GSnull.cpp null/GSnull.h libGSnull_a_SOURCES += \ Linux/interface.h Linux/support.c \ Linux/interface.c Linux/support.h \ -Linux/callbacks.h \ -GifTransfer.cpp GifTransfer.h \ -null/GSnull.cpp null/GSnull.h \ No newline at end of file +Linux/callbacks.h \ No newline at end of file diff --git a/plugins/GSnull/Windows/GSnull_vc2008.vcproj b/plugins/GSnull/Windows/GSnull_vc2008.vcproj index 5772e553be..95b476419f 100644 --- a/plugins/GSnull/Windows/GSnull_vc2008.vcproj +++ b/plugins/GSnull/Windows/GSnull_vc2008.vcproj @@ -160,16 +160,40 @@ RelativePath=".\Config.cpp" > + + + + + + + + + + - - + + + + + + + + + + + + diff --git a/plugins/GSnull/Windows/GSwin.cpp b/plugins/GSnull/Windows/GSwin.cpp new file mode 100644 index 0000000000..fa3c66a335 --- /dev/null +++ b/plugins/GSnull/Windows/GSwin.cpp @@ -0,0 +1,77 @@ +/* GSnull + * Copyright (C) 2004-2009 PCSX2 Team + * + * 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 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "GSwin.h" + +HINSTANCE HInst; +HWND GShwnd; + +LRESULT CALLBACK MsgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch(msg) + { + case WM_CLOSE: + DestroyWindow(hwnd); + break; + case WM_DESTROY: + PostQuitMessage(0); + break; + default: + return DefWindowProc(hwnd, msg, wParam, lParam); + } + return 0; +} + +int GSOpenWindow(void *pDsp, char *Title) +{ + WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, + GetModuleHandle(NULL), NULL, NULL, NULL, NULL, + "PS2EMU_GSNULL", NULL }; + RegisterClassEx( &wc ); + + GShwnd = CreateWindowEx( WS_EX_CLIENTEDGE, "PS2EMU_GSNULL", Title, + WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, NULL, NULL, wc.hInstance, NULL); + + if(GShwnd == NULL) + { + GS_LOG("Failed to create window. Exiting..."); + return -1; + } + + if( pDsp != NULL ) *(int*)pDsp = (int)GShwnd; + + return 0; +} + +void GSCloseWindow() +{ +} + +void GSProcessMessages() +{ +} + +// GSkeyEvent gets called when there is a keyEvent from the PAD plugin +void HandleKeyEvent(keyEvent *ev) +{ +} + +EXPORT_C_(s32) GSsetWindowInfo(winInfo *info) +{ + return 0; +} \ No newline at end of file diff --git a/plugins/GSnull/Windows/GSwin.h b/plugins/GSnull/Windows/GSwin.h new file mode 100644 index 0000000000..8e7777fe87 --- /dev/null +++ b/plugins/GSnull/Windows/GSwin.h @@ -0,0 +1,36 @@ +/* GSnull + * Copyright (C) 2004-2009 PCSX2 Team + * + * 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 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include "../GS.h" + +#ifdef __cplusplus +extern "C" +{ +#endif +#define GSdefs +#include "PS2Edefs.h" +#ifdef __cplusplus +} +#endif + +int GSOpenWindow(void *pDsp, char *Title); +void GSCloseWindow(); +void GSProcessMessages(); +void HandleKeyEvent(keyEvent *ev); \ No newline at end of file