2010-04-25 00:31:27 +00:00
|
|
|
/*
|
2009-02-09 21:15:56 +00:00
|
|
|
* Copyright (C) 2007-2009 Gabest
|
|
|
|
* http://www.gabest.org
|
|
|
|
*
|
|
|
|
* 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, or (at your option)
|
|
|
|
* any later version.
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-02-09 21:15:56 +00:00
|
|
|
* 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.
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-02-09 21:15:56 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Make; see the file COPYING. If not, write to
|
2012-09-09 18:16:11 +00:00
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA USA.
|
2009-02-09 21:15:56 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
2011-02-19 03:36:30 +00:00
|
|
|
#include "GSdx.h"
|
2009-02-09 21:15:56 +00:00
|
|
|
#include "GSUtil.h"
|
|
|
|
#include "GSRendererSW.h"
|
|
|
|
#include "GSRendererNull.h"
|
2011-02-19 03:36:30 +00:00
|
|
|
#include "GSDeviceNull.h"
|
2013-01-10 13:13:59 +00:00
|
|
|
#include "GSDeviceOGL.h"
|
|
|
|
#include "GSRendererOGL.h"
|
2011-02-19 03:36:30 +00:00
|
|
|
|
|
|
|
#ifdef _WINDOWS
|
|
|
|
|
|
|
|
#include "GSRendererDX9.h"
|
|
|
|
#include "GSRendererDX11.h"
|
|
|
|
#include "GSDevice9.h"
|
|
|
|
#include "GSDevice11.h"
|
2013-01-04 11:41:51 +00:00
|
|
|
#include "GSWndDX.h"
|
2013-01-04 21:33:24 +00:00
|
|
|
#include "GSWndWGL.h"
|
2012-01-13 18:10:05 +00:00
|
|
|
#include "GSRendererCS.h"
|
2009-02-09 21:15:56 +00:00
|
|
|
#include "GSSettingsDlg.h"
|
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
static HRESULT s_hr = E_FAIL;
|
|
|
|
|
2011-02-20 01:57:43 +00:00
|
|
|
#else
|
2011-02-20 16:09:46 +00:00
|
|
|
|
2013-01-04 11:41:51 +00:00
|
|
|
#include "GSWndOGL.h"
|
2013-01-17 16:58:48 +00:00
|
|
|
#include "GSWndEGL.h"
|
2011-11-16 22:17:37 +00:00
|
|
|
|
2011-02-23 09:16:00 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <gdk/gdkx.h>
|
|
|
|
|
2011-02-20 01:57:43 +00:00
|
|
|
extern bool RunLinuxDialog();
|
2011-02-20 16:09:46 +00:00
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
#endif
|
2010-12-03 03:04:55 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
#define PS2E_LT_GS 0x01
|
|
|
|
#define PS2E_GS_VERSION 0x0006
|
|
|
|
#define PS2E_X86 0x01 // 32 bit
|
|
|
|
#define PS2E_X86_64 0x02 // 64 bit
|
|
|
|
|
2013-01-14 09:25:16 +00:00
|
|
|
#ifdef ENABLE_OGL_MT_HACK
|
2012-06-12 18:14:01 +00:00
|
|
|
GSRenderer* s_gs = NULL;
|
|
|
|
#else
|
2009-05-22 01:22:52 +00:00
|
|
|
static GSRenderer* s_gs = NULL;
|
2012-06-12 18:14:01 +00:00
|
|
|
#endif
|
2009-02-09 21:15:56 +00:00
|
|
|
static void (*s_irq)() = NULL;
|
2009-05-14 16:41:52 +00:00
|
|
|
static uint8* s_basemem = NULL;
|
2009-09-18 23:48:12 +00:00
|
|
|
static int s_renderer = -1;
|
2009-10-31 01:06:23 +00:00
|
|
|
static bool s_framelimit = true;
|
2009-12-03 15:49:12 +00:00
|
|
|
static bool s_vsync = false;
|
2009-12-04 03:24:59 +00:00
|
|
|
static bool s_exclusive = true;
|
2013-06-28 10:43:50 +00:00
|
|
|
#ifdef _WINDOWS
|
2011-02-19 03:36:30 +00:00
|
|
|
static bool s_isgsopen2 = false; // boolean to remove some stuff from the config panel in new PCSX2's/
|
2013-06-28 10:43:50 +00:00
|
|
|
#endif
|
2014-01-25 19:36:45 +00:00
|
|
|
bool gsopen_done = false; // crash guard for GSgetTitleInfo2
|
2010-01-28 02:53:10 +00:00
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C_(uint32) PS2EgetLibType()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
return PS2E_LT_GS;
|
|
|
|
}
|
|
|
|
|
2011-02-19 23:41:52 +00:00
|
|
|
EXPORT_C_(const char*) PS2EgetLibName()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
return GSUtil::GetLibName();
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C_(uint32) PS2EgetLibVersion2(uint32 type)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
const uint32 revision = 0;
|
|
|
|
const uint32 build = 1;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
return (build << 0) | (revision << 8) | (PS2E_GS_VERSION << 16) | (PLUGIN_VERSION << 24);
|
|
|
|
}
|
|
|
|
|
2011-02-23 09:16:00 +00:00
|
|
|
#ifdef _WINDOWS
|
|
|
|
|
2010-01-28 02:53:10 +00:00
|
|
|
EXPORT_C_(void) PS2EsetEmuVersion(const char* emuId, uint32 version)
|
|
|
|
{
|
2011-02-19 03:36:30 +00:00
|
|
|
s_isgsopen2 = true;
|
2010-01-28 02:53:10 +00:00
|
|
|
}
|
|
|
|
|
2011-02-23 09:16:00 +00:00
|
|
|
#endif
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C_(uint32) PS2EgetCpuPlatform()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
#if _M_AMD64
|
2011-02-19 03:36:30 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
return PS2E_X86_64;
|
2011-02-19 03:36:30 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
#else
|
2011-02-19 03:36:30 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
return PS2E_X86;
|
2011-02-19 03:36:30 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C GSsetBaseMem(uint8* mem)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-09-18 18:45:37 +00:00
|
|
|
s_basemem = mem;
|
2011-02-19 03:36:30 +00:00
|
|
|
|
|
|
|
if(s_gs)
|
2009-09-18 18:45:37 +00:00
|
|
|
{
|
2011-02-19 03:36:30 +00:00
|
|
|
s_gs->SetRegsMem(s_basemem);
|
2009-09-18 18:45:37 +00:00
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-12-19 18:30:56 +00:00
|
|
|
EXPORT_C GSsetSettingsDir(const char* dir)
|
|
|
|
{
|
|
|
|
theApp.SetConfigDir(dir);
|
|
|
|
}
|
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
EXPORT_C_(int) GSinit()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-06-23 04:12:32 +00:00
|
|
|
if(!GSUtil::CheckSSE())
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-09-17 07:40:38 +00:00
|
|
|
#ifdef _WINDOWS
|
|
|
|
|
|
|
|
s_hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
|
|
|
|
|
|
|
if(!GSUtil::CheckDirectX())
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-02-25 01:01:00 +00:00
|
|
|
#endif
|
2011-02-24 23:46:26 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C GSshutdown()
|
|
|
|
{
|
2010-04-25 00:31:27 +00:00
|
|
|
delete s_gs;
|
2009-09-17 07:40:38 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
s_gs = NULL;
|
2011-02-19 03:36:30 +00:00
|
|
|
|
2009-09-18 23:48:12 +00:00
|
|
|
s_renderer = -1;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-18 11:08:04 +00:00
|
|
|
#ifdef _WINDOWS
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
if(SUCCEEDED(s_hr))
|
|
|
|
{
|
|
|
|
::CoUninitialize();
|
|
|
|
|
|
|
|
s_hr = E_FAIL;
|
|
|
|
}
|
2009-05-18 11:08:04 +00:00
|
|
|
|
|
|
|
#endif
|
2014-01-25 19:53:12 +00:00
|
|
|
|
|
|
|
gsopen_done = false;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-09-17 07:40:38 +00:00
|
|
|
EXPORT_C GSclose()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-02-19 03:36:30 +00:00
|
|
|
if(s_gs == NULL) return;
|
2009-05-18 11:08:04 +00:00
|
|
|
|
2010-05-23 17:26:37 +00:00
|
|
|
s_gs->ResetDevice();
|
|
|
|
|
2013-06-16 07:05:57 +00:00
|
|
|
// Opengl requirement: It must be done before the Detach() of
|
|
|
|
// the context
|
2010-05-23 17:26:37 +00:00
|
|
|
delete s_gs->m_dev;
|
2011-02-19 03:36:30 +00:00
|
|
|
|
2010-05-23 17:26:37 +00:00
|
|
|
s_gs->m_dev = NULL;
|
|
|
|
|
2013-06-16 09:55:37 +00:00
|
|
|
if (s_gs->m_wnd)
|
2013-06-16 09:43:34 +00:00
|
|
|
{
|
|
|
|
s_gs->m_wnd->Detach();
|
|
|
|
}
|
2014-01-25 19:36:45 +00:00
|
|
|
|
|
|
|
gsopen_done = false;
|
2009-09-17 07:40:38 +00:00
|
|
|
}
|
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
static int _GSopen(void** dsp, char* title, int renderer, int threads = -1)
|
2009-09-17 07:40:38 +00:00
|
|
|
{
|
|
|
|
GSDevice* dev = NULL;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-02-07 01:59:05 +00:00
|
|
|
if(renderer == -1)
|
2009-09-19 11:20:31 +00:00
|
|
|
{
|
|
|
|
renderer = theApp.GetConfig("renderer", 0);
|
|
|
|
}
|
|
|
|
|
2011-02-17 03:24:37 +00:00
|
|
|
if(threads == -1)
|
|
|
|
{
|
2011-12-20 14:33:28 +00:00
|
|
|
threads = theApp.GetConfig("extrathreads", 0);
|
2011-02-17 03:24:37 +00:00
|
|
|
}
|
|
|
|
|
2013-06-16 09:40:38 +00:00
|
|
|
GSWnd* wnd[2];
|
2009-09-18 18:45:37 +00:00
|
|
|
try
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-02-19 03:36:30 +00:00
|
|
|
if(s_renderer != renderer)
|
2010-05-23 17:26:37 +00:00
|
|
|
{
|
|
|
|
// Emulator has made a render change request, which requires a completely
|
|
|
|
// new s_gs -- if the emu doesn't save/restore the GS state across this
|
|
|
|
// GSopen call then they'll get corrupted graphics, but that's not my problem.
|
|
|
|
|
|
|
|
delete s_gs;
|
2011-02-07 01:59:05 +00:00
|
|
|
|
2010-05-23 17:26:37 +00:00
|
|
|
s_gs = NULL;
|
|
|
|
}
|
|
|
|
|
2012-01-18 11:47:31 +00:00
|
|
|
if(renderer == 15)
|
2009-09-17 07:40:38 +00:00
|
|
|
{
|
2012-01-13 18:10:05 +00:00
|
|
|
#ifdef _WINDOWS
|
|
|
|
|
|
|
|
dev = new GSDevice11();
|
2009-09-18 18:45:37 +00:00
|
|
|
|
2012-01-13 18:10:05 +00:00
|
|
|
if(dev == NULL)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-01-27 11:56:49 +00:00
|
|
|
delete s_gs;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2012-01-27 11:56:49 +00:00
|
|
|
s_gs = new GSRendererCS();
|
|
|
|
|
|
|
|
s_renderer = renderer;
|
2012-01-13 18:10:05 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
2009-09-18 18:45:37 +00:00
|
|
|
{
|
2012-01-13 18:10:05 +00:00
|
|
|
switch(renderer / 3)
|
2009-09-18 18:45:37 +00:00
|
|
|
{
|
2010-04-25 00:31:27 +00:00
|
|
|
default:
|
2012-01-15 14:51:49 +00:00
|
|
|
#ifdef _WINDOWS
|
|
|
|
case 0: dev = new GSDevice9(); break;
|
|
|
|
case 1: dev = new GSDevice11(); break;
|
|
|
|
#endif
|
2012-05-17 14:18:37 +00:00
|
|
|
case 3: dev = new GSDeviceNull(); break;
|
2013-01-10 13:13:59 +00:00
|
|
|
case 4: dev = new GSDeviceOGL(); break;
|
2009-09-18 18:45:37 +00:00
|
|
|
}
|
2009-09-18 23:48:12 +00:00
|
|
|
|
2012-01-13 18:10:05 +00:00
|
|
|
if(dev == NULL)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(s_gs == NULL)
|
|
|
|
{
|
|
|
|
switch(renderer % 3)
|
|
|
|
{
|
2013-01-10 13:13:59 +00:00
|
|
|
default:
|
|
|
|
case 0:
|
|
|
|
switch(renderer)
|
|
|
|
{
|
|
|
|
default:
|
2013-01-14 09:15:39 +00:00
|
|
|
#ifdef _WINDOWS
|
2013-01-10 13:13:59 +00:00
|
|
|
case 0: s_gs = (GSRenderer*)new GSRendererDX9(); break;
|
|
|
|
case 3: s_gs = (GSRenderer*)new GSRendererDX11(); break;
|
2013-01-14 09:15:39 +00:00
|
|
|
#endif
|
2013-01-10 13:13:59 +00:00
|
|
|
case 12: s_gs = (GSRenderer*)new GSRendererOGL(); break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
s_gs = new GSRendererSW(threads);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
s_gs = new GSRendererNull();
|
|
|
|
break;
|
2012-01-13 18:10:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
s_renderer = renderer;
|
|
|
|
}
|
2009-09-18 23:48:12 +00:00
|
|
|
}
|
2013-01-04 11:41:51 +00:00
|
|
|
|
|
|
|
if (s_gs->m_wnd == NULL)
|
|
|
|
{
|
2013-01-04 21:33:24 +00:00
|
|
|
#ifdef _WINDOWS
|
|
|
|
if (renderer / 3 == 4)
|
|
|
|
s_gs->m_wnd = new GSWndWGL();
|
|
|
|
else
|
|
|
|
s_gs->m_wnd = new GSWndDX();
|
2013-07-13 11:39:45 +00:00
|
|
|
#else
|
|
|
|
#ifdef ENABLE_GLES
|
|
|
|
wnd[0] = NULL;
|
2013-01-04 21:33:24 +00:00
|
|
|
#else
|
2013-06-16 09:40:38 +00:00
|
|
|
wnd[0] = new GSWndOGL();
|
2013-07-13 11:39:45 +00:00
|
|
|
#endif
|
2013-06-16 09:40:38 +00:00
|
|
|
wnd[1] = new GSWndEGL();
|
2013-01-04 21:33:24 +00:00
|
|
|
#endif
|
2013-01-04 11:41:51 +00:00
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
2011-02-17 03:24:37 +00:00
|
|
|
catch(std::exception& ex)
|
2009-09-18 18:45:37 +00:00
|
|
|
{
|
|
|
|
// Allowing std exceptions to escape the scope of the plugin callstack could
|
|
|
|
// be problematic, because of differing typeids between DLL and EXE compilations.
|
2009-09-18 22:13:40 +00:00
|
|
|
// ('new' could throw std::alloc)
|
2009-09-18 18:45:37 +00:00
|
|
|
|
2011-02-17 03:24:37 +00:00
|
|
|
printf("GSdx error: Exception caught in GSopen: %s", ex.what());
|
|
|
|
|
2009-09-18 18:45:37 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-09-18 19:54:56 +00:00
|
|
|
s_gs->SetRegsMem(s_basemem);
|
|
|
|
s_gs->SetIrqCallback(s_irq);
|
2011-02-19 03:36:30 +00:00
|
|
|
s_gs->SetVSync(s_vsync);
|
2009-12-03 15:49:12 +00:00
|
|
|
s_gs->SetFrameLimit(s_framelimit);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
if(*dsp == NULL)
|
2009-09-17 07:40:38 +00:00
|
|
|
{
|
|
|
|
// old-style API expects us to create and manage our own window:
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-09-17 07:40:38 +00:00
|
|
|
int w = theApp.GetConfig("ModeWidth", 0);
|
|
|
|
int h = theApp.GetConfig("ModeHeight", 0);
|
|
|
|
|
2013-06-16 09:40:38 +00:00
|
|
|
#ifdef _LINUX
|
|
|
|
for(uint32 i = 0; i < 2; i++) {
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (wnd[i] == NULL) continue;
|
|
|
|
|
|
|
|
wnd[i]->Create(title, w, h);
|
|
|
|
s_gs->m_wnd = wnd[i];
|
|
|
|
|
|
|
|
if (i == 0) delete wnd[1];
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
catch (GSDXRecoverableError)
|
|
|
|
{
|
2013-06-16 16:33:08 +00:00
|
|
|
wnd[i]->Detach();
|
2013-06-16 09:40:38 +00:00
|
|
|
delete wnd[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (s_gs->m_wnd == NULL)
|
|
|
|
{
|
|
|
|
GSclose();
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef _WINDOWS
|
2009-09-17 07:40:38 +00:00
|
|
|
if(!s_gs->CreateWnd(title, w, h))
|
|
|
|
{
|
|
|
|
GSclose();
|
2011-02-19 03:36:30 +00:00
|
|
|
|
2009-09-17 07:40:38 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2013-06-16 09:40:38 +00:00
|
|
|
#endif
|
2009-09-17 07:40:38 +00:00
|
|
|
|
2013-01-04 11:41:51 +00:00
|
|
|
s_gs->m_wnd->Show();
|
2011-02-17 03:24:37 +00:00
|
|
|
|
2013-01-04 11:41:51 +00:00
|
|
|
*dsp = s_gs->m_wnd->GetDisplay();
|
2009-09-17 07:40:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-02-17 03:24:37 +00:00
|
|
|
s_gs->SetMultithreaded(true);
|
2011-02-19 03:36:30 +00:00
|
|
|
|
2012-01-04 23:19:17 +00:00
|
|
|
#ifdef _LINUX
|
2013-06-30 15:27:50 +00:00
|
|
|
if (s_gs->m_wnd) {
|
|
|
|
// A window was already attached to s_gs so we also
|
|
|
|
// need to restore the window state (Attach)
|
|
|
|
s_gs->m_wnd->Attach((void*)((uint32*)(dsp)+1), false);
|
|
|
|
} else {
|
|
|
|
// No window found, try to attach a GLX win and retry
|
|
|
|
// with EGL win if failed.
|
|
|
|
for(uint32 i = 0; i < 2; i++) {
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (wnd[i] == NULL) continue;
|
2013-06-16 09:40:38 +00:00
|
|
|
|
2013-06-30 15:27:50 +00:00
|
|
|
wnd[i]->Attach((void*)((uint32*)(dsp)+1), false);
|
|
|
|
s_gs->m_wnd = wnd[i];
|
2013-06-16 09:40:38 +00:00
|
|
|
|
2013-06-30 15:27:50 +00:00
|
|
|
if (i == 0) delete wnd[1];
|
2013-06-16 09:40:38 +00:00
|
|
|
|
2013-06-30 15:27:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
catch (GSDXRecoverableError)
|
|
|
|
{
|
|
|
|
wnd[i]->Detach();
|
|
|
|
delete wnd[i];
|
|
|
|
}
|
2013-06-16 09:40:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (s_gs->m_wnd == NULL)
|
|
|
|
{
|
2011-12-08 16:39:14 +00:00
|
|
|
return -1;
|
2013-06-16 09:40:38 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef _WINDOWS
|
2013-01-04 11:41:51 +00:00
|
|
|
s_gs->m_wnd->Attach(*dsp, false);
|
2011-06-12 14:48:36 +00:00
|
|
|
#endif
|
2009-09-17 07:40:38 +00:00
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-02-17 03:24:37 +00:00
|
|
|
if(!s_gs->CreateDevice(dev))
|
2009-09-17 07:40:38 +00:00
|
|
|
{
|
2010-06-05 04:06:24 +00:00
|
|
|
// This probably means the user has DX11 configured with a video card that is only DX9
|
|
|
|
// compliant. Cound mean drivr issues of some sort also, but to be sure, that's the most
|
|
|
|
// common cause of device creation errors. :) --air
|
|
|
|
|
2009-09-17 07:40:38 +00:00
|
|
|
GSclose();
|
2011-02-17 03:24:37 +00:00
|
|
|
|
2009-09-17 07:40:38 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2014-01-25 19:36:45 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
EXPORT_C_(int) GSopen2(void** dsp, uint32 flags)
|
2009-09-17 07:40:38 +00:00
|
|
|
{
|
2014-01-10 21:04:04 +00:00
|
|
|
#ifdef _LINUX
|
|
|
|
// Use ogl renderer as default otherwise it crash at startup
|
|
|
|
// GSRenderOGL only GSDeviceOGL (not GSDeviceNULL)
|
|
|
|
int renderer = theApp.GetConfig("renderer", 12);
|
|
|
|
#else
|
2009-09-17 07:40:38 +00:00
|
|
|
int renderer = theApp.GetConfig("renderer", 0);
|
2014-01-10 21:04:04 +00:00
|
|
|
#endif
|
2011-02-17 03:24:37 +00:00
|
|
|
|
|
|
|
if(flags & 4)
|
2009-09-17 07:40:38 +00:00
|
|
|
{
|
2011-02-24 23:46:26 +00:00
|
|
|
#ifdef _WINDOWS
|
2012-08-06 01:56:25 +00:00
|
|
|
int best_sw_renderer = GSUtil::CheckDirect3D11Level() >= D3D_FEATURE_LEVEL_10_0 ? 4 : 1; // dx11 / dx9 sw
|
2012-04-19 19:10:24 +00:00
|
|
|
|
|
|
|
switch(renderer){
|
|
|
|
// Use alternative renderer (SW if currently using HW renderer, and vice versa, keeping the same DX level)
|
|
|
|
case 1: renderer = 0; break; // DX9: SW to HW
|
|
|
|
case 0: renderer = 1; break; // DX9: HW to SW
|
|
|
|
case 4: renderer = 3; break; // DX11: SW to HW
|
|
|
|
case 3: renderer = 4; break; // DX11: HW to SW
|
2013-07-19 19:25:50 +00:00
|
|
|
case 13: renderer = 12; break; // OGL: SW to HW
|
|
|
|
case 12: renderer = 13; break; // OGL: HW to SW
|
2012-04-19 19:10:24 +00:00
|
|
|
default: renderer = best_sw_renderer; // If wasn't using DX (e.g. SDL), use best SW renderer.
|
|
|
|
}
|
2011-02-20 16:09:46 +00:00
|
|
|
|
2013-07-19 19:25:50 +00:00
|
|
|
#endif
|
|
|
|
#ifdef _LINUX
|
|
|
|
switch(renderer) {
|
|
|
|
case 13: renderer = 12; break; // OGL: SW to HW
|
|
|
|
case 12: renderer = 13; break; // OGL: HW to SW
|
|
|
|
}
|
2011-02-24 23:46:26 +00:00
|
|
|
#endif
|
2009-09-17 07:40:38 +00:00
|
|
|
}
|
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
int retval = _GSopen(dsp, NULL, renderer);
|
2011-02-17 03:24:37 +00:00
|
|
|
|
2012-01-04 23:19:17 +00:00
|
|
|
if (s_gs != NULL)
|
|
|
|
s_gs->SetAspectRatio(0); // PCSX2 manages the aspect ratios
|
2009-12-04 03:24:59 +00:00
|
|
|
|
2014-01-25 19:53:12 +00:00
|
|
|
gsopen_done = true;
|
|
|
|
|
2009-12-01 05:59:43 +00:00
|
|
|
return retval;
|
2009-09-17 07:40:38 +00:00
|
|
|
}
|
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
EXPORT_C_(int) GSopen(void** dsp, char* title, int mt)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2011-02-23 09:16:00 +00:00
|
|
|
/*
|
|
|
|
if(!XInitThreads()) return -1;
|
|
|
|
|
|
|
|
Display* display = XOpenDisplay(0);
|
|
|
|
|
|
|
|
XCloseDisplay(display);
|
|
|
|
*/
|
|
|
|
|
2013-06-28 10:43:50 +00:00
|
|
|
int renderer = 0;
|
2009-12-04 03:24:59 +00:00
|
|
|
|
2009-12-04 04:50:49 +00:00
|
|
|
// Legacy GUI expects to acquire vsync from the configuration files.
|
2011-02-17 03:24:37 +00:00
|
|
|
|
2009-12-04 03:24:59 +00:00
|
|
|
s_vsync = !!theApp.GetConfig("vsync", 0);
|
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
if(mt == 2)
|
|
|
|
{
|
|
|
|
// pcsx2 sent a switch renderer request
|
2011-02-17 03:24:37 +00:00
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
#ifdef _WINDOWS
|
2011-02-20 16:09:46 +00:00
|
|
|
|
2012-08-06 01:56:25 +00:00
|
|
|
renderer = GSUtil::CheckDirect3D11Level() >= D3D_FEATURE_LEVEL_10_0 ? 4 : 1; // dx11 / dx9 sw
|
2011-02-20 16:09:46 +00:00
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
#endif
|
2011-02-17 03:24:37 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
mt = 1;
|
2009-03-05 20:00:41 +00:00
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
else
|
2009-05-11 08:18:00 +00:00
|
|
|
{
|
|
|
|
// normal init
|
2011-02-17 03:24:37 +00:00
|
|
|
|
2009-05-18 11:08:04 +00:00
|
|
|
renderer = theApp.GetConfig("renderer", 0);
|
2009-03-05 20:00:41 +00:00
|
|
|
}
|
2009-05-11 08:18:00 +00:00
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
*dsp = NULL;
|
2009-09-18 19:54:56 +00:00
|
|
|
|
|
|
|
int retval = _GSopen(dsp, title, renderer);
|
|
|
|
|
2011-02-17 03:24:37 +00:00
|
|
|
if(retval == 0 && s_gs)
|
2009-09-18 19:54:56 +00:00
|
|
|
{
|
2011-02-17 03:24:37 +00:00
|
|
|
s_gs->SetMultithreaded(!!mt);
|
2009-09-18 19:54:56 +00:00
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2014-01-25 19:36:45 +00:00
|
|
|
gsopen_done = true;
|
|
|
|
|
2009-09-18 19:54:56 +00:00
|
|
|
return retval;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C GSreset()
|
|
|
|
{
|
2012-06-11 02:31:44 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
s_gs->Reset();
|
|
|
|
}
|
|
|
|
catch (GSDXRecoverableError)
|
|
|
|
{
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C GSgifSoftReset(uint32 mask)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2012-06-11 02:31:44 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
s_gs->SoftReset(mask);
|
|
|
|
}
|
|
|
|
catch (GSDXRecoverableError)
|
|
|
|
{
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C GSwriteCSR(uint32 csr)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2012-06-11 02:31:44 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
s_gs->WriteCSR(csr);
|
|
|
|
}
|
|
|
|
catch (GSDXRecoverableError)
|
|
|
|
{
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C GSreadFIFO(uint8* mem)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2012-06-11 02:31:44 +00:00
|
|
|
try
|
|
|
|
{
|
2013-01-14 09:25:16 +00:00
|
|
|
#ifdef ENABLE_OGL_MT_HACK
|
2012-06-11 02:31:44 +00:00
|
|
|
// FIXME: double check which thread call this function
|
|
|
|
// See fifo2 issue below
|
2013-01-16 18:25:53 +00:00
|
|
|
#ifdef ENABLE_OGL_DEBUG
|
2012-06-12 18:14:01 +00:00
|
|
|
if (theApp.GetConfig("renderer", 0) / 3 == 4) fprintf(stderr, "Disable FIFO1 on opengl\n");
|
|
|
|
#endif
|
2013-10-24 20:54:27 +00:00
|
|
|
s_gs->m_dev->AttachContext();
|
2012-04-28 09:39:23 +00:00
|
|
|
#endif
|
2012-02-11 10:22:02 +00:00
|
|
|
|
2012-06-11 02:31:44 +00:00
|
|
|
s_gs->ReadFIFO(mem, 1);
|
2012-02-11 10:22:02 +00:00
|
|
|
|
2013-01-14 09:25:16 +00:00
|
|
|
#ifdef ENABLE_OGL_MT_HACK
|
2013-10-24 20:54:27 +00:00
|
|
|
s_gs->m_dev->DetachContext();
|
2012-04-28 09:39:23 +00:00
|
|
|
#endif
|
2012-06-11 02:31:44 +00:00
|
|
|
}
|
|
|
|
catch (GSDXRecoverableError)
|
|
|
|
{
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C GSreadFIFO2(uint8* mem, uint32 size)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2012-06-11 02:31:44 +00:00
|
|
|
try
|
|
|
|
{
|
2013-01-14 09:25:16 +00:00
|
|
|
#ifdef ENABLE_OGL_MT_HACK
|
2012-06-11 02:31:44 +00:00
|
|
|
// FIXME called from EE core thread not MTGS which cause
|
|
|
|
// invalidate data for opengl
|
2013-10-24 20:54:27 +00:00
|
|
|
s_gs->m_dev->AttachContext();
|
2012-04-28 09:39:23 +00:00
|
|
|
#endif
|
2012-02-11 10:22:02 +00:00
|
|
|
|
2012-06-11 02:31:44 +00:00
|
|
|
s_gs->ReadFIFO(mem, size);
|
2012-02-11 10:22:02 +00:00
|
|
|
|
2013-01-14 09:25:16 +00:00
|
|
|
#ifdef ENABLE_OGL_MT_HACK
|
2013-10-24 20:54:27 +00:00
|
|
|
s_gs->m_dev->DetachContext();
|
2012-04-28 09:39:23 +00:00
|
|
|
#endif
|
2012-06-11 02:31:44 +00:00
|
|
|
}
|
|
|
|
catch (GSDXRecoverableError)
|
|
|
|
{
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2010-07-19 15:49:30 +00:00
|
|
|
EXPORT_C GSgifTransfer(const uint8* mem, uint32 size)
|
2010-07-11 04:38:33 +00:00
|
|
|
{
|
2012-06-11 02:31:44 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
s_gs->Transfer<3>(mem, size);
|
|
|
|
}
|
|
|
|
catch (GSDXRecoverableError)
|
|
|
|
{
|
|
|
|
}
|
2010-07-11 04:38:33 +00:00
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C GSgifTransfer1(uint8* mem, uint32 addr)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2012-06-11 02:31:44 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
s_gs->Transfer<0>(const_cast<uint8*>(mem) + addr, (0x4000 - addr) / 16);
|
|
|
|
}
|
|
|
|
catch (GSDXRecoverableError)
|
|
|
|
{
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C GSgifTransfer2(uint8* mem, uint32 size)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2012-06-11 02:31:44 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
s_gs->Transfer<1>(const_cast<uint8*>(mem), size);
|
|
|
|
}
|
|
|
|
catch (GSDXRecoverableError)
|
|
|
|
{
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C GSgifTransfer3(uint8* mem, uint32 size)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2012-06-11 02:31:44 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
s_gs->Transfer<2>(const_cast<uint8*>(mem), size);
|
|
|
|
}
|
|
|
|
catch (GSDXRecoverableError)
|
|
|
|
{
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C GSvsync(int field)
|
|
|
|
{
|
2012-06-11 02:31:44 +00:00
|
|
|
try
|
|
|
|
{
|
2009-05-18 11:08:04 +00:00
|
|
|
#ifdef _WINDOWS
|
|
|
|
|
2013-01-04 11:41:51 +00:00
|
|
|
if(s_gs->m_wnd->IsManaged())
|
2012-06-11 02:31:44 +00:00
|
|
|
{
|
|
|
|
MSG msg;
|
2009-05-18 11:08:04 +00:00
|
|
|
|
2012-06-11 02:31:44 +00:00
|
|
|
memset(&msg, 0, sizeof(msg));
|
2009-05-18 11:08:04 +00:00
|
|
|
|
2012-06-11 02:31:44 +00:00
|
|
|
while(msg.message != WM_QUIT && PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
2009-12-01 05:59:43 +00:00
|
|
|
}
|
2011-02-17 18:22:47 +00:00
|
|
|
|
2009-05-18 11:08:04 +00:00
|
|
|
#endif
|
|
|
|
|
2013-01-14 09:25:16 +00:00
|
|
|
#ifdef ENABLE_OGL_MT_HACK
|
2013-10-24 20:54:27 +00:00
|
|
|
s_gs->m_dev->AttachContext();
|
2012-08-19 13:06:40 +00:00
|
|
|
#endif
|
2012-06-11 02:31:44 +00:00
|
|
|
s_gs->VSync(field);
|
|
|
|
}
|
|
|
|
catch (GSDXRecoverableError)
|
|
|
|
{
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C_(uint32) GSmakeSnapshot(char* path)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2012-06-11 02:31:44 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
string s(path);
|
|
|
|
|
|
|
|
if(!s.empty() && s[s.length() - 1] != DIRECTORY_SEPARATOR)
|
|
|
|
{
|
|
|
|
s = s + DIRECTORY_SEPARATOR;
|
|
|
|
}
|
2011-02-17 03:24:37 +00:00
|
|
|
|
2012-06-11 02:31:44 +00:00
|
|
|
return s_gs->MakeSnapshot(s + "gsdx");
|
|
|
|
}
|
|
|
|
catch (GSDXRecoverableError)
|
2011-02-17 03:24:37 +00:00
|
|
|
{
|
2012-06-11 02:31:44 +00:00
|
|
|
return false;
|
2011-02-17 03:24:37 +00:00
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-18 11:08:04 +00:00
|
|
|
EXPORT_C GSkeyEvent(GSKeyEventData* e)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2012-06-11 02:31:44 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
s_gs->KeyEvent(e);
|
|
|
|
}
|
|
|
|
catch (GSDXRecoverableError)
|
|
|
|
{
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C_(int) GSfreeze(int mode, GSFreezeData* data)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2012-06-11 02:31:44 +00:00
|
|
|
try
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2012-06-11 02:31:44 +00:00
|
|
|
if(mode == FREEZE_SAVE)
|
|
|
|
{
|
|
|
|
return s_gs->Freeze(data, false);
|
|
|
|
}
|
|
|
|
else if(mode == FREEZE_SIZE)
|
|
|
|
{
|
|
|
|
return s_gs->Freeze(data, true);
|
|
|
|
}
|
|
|
|
else if(mode == FREEZE_LOAD)
|
|
|
|
{
|
|
|
|
return s_gs->Defrost(data);
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
2012-06-11 02:31:44 +00:00
|
|
|
catch (GSDXRecoverableError)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C GSconfigure()
|
|
|
|
{
|
2012-06-11 02:31:44 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if(!GSUtil::CheckSSE()) return;
|
2009-11-18 08:13:28 +00:00
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
#ifdef _WINDOWS
|
|
|
|
|
2012-06-11 02:31:44 +00:00
|
|
|
if(GSSettingsDlg(s_isgsopen2).DoModal() == IDOK)
|
2009-09-18 23:48:12 +00:00
|
|
|
{
|
2013-01-04 11:41:51 +00:00
|
|
|
if(s_gs != NULL && s_gs->m_wnd->IsManaged())
|
2012-06-11 02:31:44 +00:00
|
|
|
{
|
|
|
|
// Legacy apps like gsdxgui expect this...
|
2011-02-17 03:24:37 +00:00
|
|
|
|
2012-06-11 02:31:44 +00:00
|
|
|
GSshutdown();
|
|
|
|
}
|
2009-09-18 23:48:12 +00:00
|
|
|
}
|
2011-02-19 03:36:30 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2013-06-15 15:03:44 +00:00
|
|
|
if (RunLinuxDialog()) {
|
|
|
|
theApp.ReloadConfig();
|
2011-02-20 01:57:43 +00:00
|
|
|
}
|
2013-06-15 15:03:44 +00:00
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
#endif
|
2012-06-11 02:31:44 +00:00
|
|
|
} catch (GSDXRecoverableError)
|
|
|
|
{
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
EXPORT_C_(int) GStest()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-11-16 00:40:09 +00:00
|
|
|
if(!GSUtil::CheckSSE())
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _WINDOWS
|
|
|
|
|
|
|
|
s_hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
|
|
|
|
|
|
|
if(!GSUtil::CheckDirectX())
|
|
|
|
{
|
|
|
|
if(SUCCEEDED(s_hr))
|
2011-02-17 03:24:37 +00:00
|
|
|
{
|
2009-11-16 00:40:09 +00:00
|
|
|
::CoUninitialize();
|
2011-02-17 03:24:37 +00:00
|
|
|
}
|
2009-11-16 00:40:09 +00:00
|
|
|
|
|
|
|
s_hr = E_FAIL;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(SUCCEEDED(s_hr))
|
2011-02-17 03:24:37 +00:00
|
|
|
{
|
2009-11-16 00:40:09 +00:00
|
|
|
::CoUninitialize();
|
2011-02-17 03:24:37 +00:00
|
|
|
}
|
2009-11-16 00:40:09 +00:00
|
|
|
|
|
|
|
s_hr = E_FAIL;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C GSabout()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C GSirqCallback(void (*irq)())
|
|
|
|
{
|
|
|
|
s_irq = irq;
|
2011-02-17 03:24:37 +00:00
|
|
|
|
|
|
|
if(s_gs)
|
2009-09-18 19:54:56 +00:00
|
|
|
{
|
|
|
|
s_gs->SetIrqCallback(s_irq);
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2011-11-08 13:22:54 +00:00
|
|
|
void pt(const char* str){
|
2011-08-30 07:11:36 +00:00
|
|
|
struct tm *current;
|
|
|
|
time_t now;
|
|
|
|
|
|
|
|
time(&now);
|
|
|
|
current = localtime(&now);
|
|
|
|
|
|
|
|
printf("%02i:%02i:%02i%s", current->tm_hour, current->tm_min, current->tm_sec, str);
|
|
|
|
}
|
|
|
|
|
2009-08-16 16:45:26 +00:00
|
|
|
EXPORT_C_(int) GSsetupRecording(int start, void* data)
|
2009-08-16 11:35:30 +00:00
|
|
|
{
|
2014-02-11 21:47:43 +00:00
|
|
|
if (s_gs == NULL) {
|
|
|
|
printf("GSdx: no s_gs for recording\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2009-08-16 16:45:26 +00:00
|
|
|
|
2010-06-24 20:25:33 +00:00
|
|
|
if(start & 1)
|
2011-02-17 03:24:37 +00:00
|
|
|
{
|
2014-02-12 12:52:03 +00:00
|
|
|
printf("GSdx: Recording start command\n");
|
2011-08-30 07:11:36 +00:00
|
|
|
if( s_gs->BeginCapture() )
|
|
|
|
pt(" - Capture started\n");
|
2011-02-17 03:24:37 +00:00
|
|
|
}
|
2010-06-24 20:25:33 +00:00
|
|
|
else
|
2011-02-17 03:24:37 +00:00
|
|
|
{
|
2014-02-12 12:52:03 +00:00
|
|
|
printf("GSdx: Recording end command\n");
|
2010-06-24 20:25:33 +00:00
|
|
|
s_gs->EndCapture();
|
2011-08-30 07:11:36 +00:00
|
|
|
pt(" - Capture ended\n");
|
2011-02-17 03:24:37 +00:00
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-08-16 11:35:30 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C GSsetGameCRC(uint32 crc, int options)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2012-06-20 18:51:30 +00:00
|
|
|
s_gs->SetGameCRC(crc, options);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-07-15 19:44:06 +00:00
|
|
|
EXPORT_C GSgetLastTag(uint32* tag)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
s_gs->GetLastTag(tag);
|
|
|
|
}
|
|
|
|
|
2010-12-03 21:18:29 +00:00
|
|
|
EXPORT_C GSgetTitleInfo2(char* dest, size_t length)
|
2010-01-28 02:53:10 +00:00
|
|
|
{
|
2014-01-25 19:36:45 +00:00
|
|
|
if (gsopen_done == false) {
|
2014-01-25 19:53:12 +00:00
|
|
|
//printf("GSdx: GSgetTitleInfo but GSOpen not yet done. Ignoring\n");
|
2014-01-25 19:36:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
string s = "GSdx";
|
|
|
|
|
2013-08-28 08:44:16 +00:00
|
|
|
// TODO: this gets called from a different thread concurrently with GSOpen (on linux)
|
|
|
|
if(s_gs == NULL) return;
|
2011-02-19 23:41:52 +00:00
|
|
|
|
2011-02-19 03:36:30 +00:00
|
|
|
if(s_gs->m_GStitleInfoBuffer[0])
|
2010-12-03 03:04:55 +00:00
|
|
|
{
|
2011-02-19 03:36:30 +00:00
|
|
|
GSAutoLock lock(&s_gs->m_pGSsetTitle_Crit);
|
|
|
|
|
2011-02-21 22:36:10 +00:00
|
|
|
s = format("GSdx | %s", s_gs->m_GStitleInfoBuffer);
|
2011-02-19 03:36:30 +00:00
|
|
|
|
|
|
|
if(s.size() > length - 1)
|
|
|
|
{
|
|
|
|
s = s.substr(0, length - 1);
|
|
|
|
}
|
2010-12-03 03:04:55 +00:00
|
|
|
}
|
2011-02-19 03:36:30 +00:00
|
|
|
|
|
|
|
strcpy(dest, s.c_str());
|
2010-01-28 02:53:10 +00:00
|
|
|
}
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
EXPORT_C GSsetFrameSkip(int frameskip)
|
|
|
|
{
|
|
|
|
s_gs->SetFrameSkip(frameskip);
|
|
|
|
}
|
|
|
|
|
2009-12-03 15:49:12 +00:00
|
|
|
EXPORT_C GSsetVsync(int enabled)
|
|
|
|
{
|
|
|
|
s_vsync = !!enabled;
|
2011-02-17 03:24:37 +00:00
|
|
|
|
|
|
|
if(s_gs)
|
|
|
|
{
|
2011-02-19 03:36:30 +00:00
|
|
|
s_gs->SetVSync(s_vsync);
|
2011-02-17 03:24:37 +00:00
|
|
|
}
|
2009-12-03 15:49:12 +00:00
|
|
|
}
|
2009-10-31 01:06:23 +00:00
|
|
|
|
2009-12-04 03:24:59 +00:00
|
|
|
EXPORT_C GSsetExclusive(int enabled)
|
|
|
|
{
|
|
|
|
s_exclusive = !!enabled;
|
2011-02-17 03:24:37 +00:00
|
|
|
|
|
|
|
if(s_gs)
|
|
|
|
{
|
2011-02-19 03:36:30 +00:00
|
|
|
s_gs->SetVSync(s_vsync);
|
2011-02-17 03:24:37 +00:00
|
|
|
}
|
2009-12-04 03:24:59 +00:00
|
|
|
}
|
|
|
|
|
2009-07-16 12:38:42 +00:00
|
|
|
EXPORT_C GSsetFrameLimit(int limit)
|
2009-07-15 19:44:06 +00:00
|
|
|
{
|
2009-12-03 15:49:12 +00:00
|
|
|
s_framelimit = !!limit;
|
2011-02-17 03:24:37 +00:00
|
|
|
|
|
|
|
if(s_gs)
|
|
|
|
{
|
2009-10-31 01:06:23 +00:00
|
|
|
s_gs->SetFrameLimit(s_framelimit);
|
2011-02-17 03:24:37 +00:00
|
|
|
}
|
2009-07-15 19:44:06 +00:00
|
|
|
}
|
|
|
|
|
2009-05-18 11:08:04 +00:00
|
|
|
#ifdef _WINDOWS
|
|
|
|
|
2011-02-16 03:19:36 +00:00
|
|
|
#include <io.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
class Console
|
|
|
|
{
|
|
|
|
HANDLE m_console;
|
|
|
|
string m_title;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Console::Console(LPCSTR title, bool open)
|
|
|
|
: m_console(NULL)
|
|
|
|
, m_title(title)
|
|
|
|
{
|
|
|
|
if(open) Open();
|
|
|
|
}
|
|
|
|
|
|
|
|
Console::~Console()
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Console::Open()
|
|
|
|
{
|
|
|
|
if(m_console == NULL)
|
|
|
|
{
|
2011-02-19 03:36:30 +00:00
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
|
2011-02-16 03:19:36 +00:00
|
|
|
|
|
|
|
AllocConsole();
|
|
|
|
|
|
|
|
SetConsoleTitle(m_title.c_str());
|
|
|
|
|
|
|
|
m_console = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
|
|
|
|
COORD size;
|
|
|
|
|
|
|
|
size.X = 100;
|
|
|
|
size.Y = 300;
|
|
|
|
|
|
|
|
SetConsoleScreenBufferSize(m_console, size);
|
|
|
|
|
|
|
|
GetConsoleScreenBufferInfo(m_console, &csbiInfo);
|
|
|
|
|
|
|
|
SMALL_RECT rect;
|
|
|
|
|
|
|
|
rect = csbiInfo.srWindow;
|
|
|
|
rect.Right = rect.Left + 99;
|
|
|
|
rect.Bottom = rect.Top + 64;
|
|
|
|
|
|
|
|
SetConsoleWindowInfo(m_console, TRUE, &rect);
|
|
|
|
|
|
|
|
*stdout = *_fdopen(_open_osfhandle((long)m_console, _O_TEXT), "w");
|
|
|
|
|
|
|
|
setvbuf(stdout, NULL, _IONBF, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Console::Close()
|
|
|
|
{
|
|
|
|
if(m_console != NULL)
|
|
|
|
{
|
2011-02-19 03:36:30 +00:00
|
|
|
FreeConsole();
|
|
|
|
|
2011-02-16 03:19:36 +00:00
|
|
|
m_console = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-09-19 11:20:31 +00:00
|
|
|
// lpszCmdLine:
|
|
|
|
// First parameter is the renderer.
|
|
|
|
// Second parameter is the gs file to load and run.
|
2011-02-17 03:24:37 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
EXPORT_C GSReplay(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
|
|
|
|
{
|
|
|
|
int renderer = -1;
|
|
|
|
|
|
|
|
{
|
|
|
|
char* start = lpszCmdLine;
|
|
|
|
char* end = NULL;
|
|
|
|
long n = strtol(lpszCmdLine, &end, 10);
|
|
|
|
if(end > start) {renderer = n; lpszCmdLine = end;}
|
|
|
|
}
|
|
|
|
|
|
|
|
while(*lpszCmdLine == ' ') lpszCmdLine++;
|
|
|
|
|
|
|
|
::SetPriorityClass(::GetCurrentProcess(), HIGH_PRIORITY_CLASS);
|
|
|
|
|
|
|
|
if(FILE* fp = fopen(lpszCmdLine, "rb"))
|
|
|
|
{
|
2011-02-16 03:19:36 +00:00
|
|
|
Console console("GSdx", true);
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
GSinit();
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
uint8 regs[0x2000];
|
2009-02-09 21:15:56 +00:00
|
|
|
GSsetBaseMem(regs);
|
|
|
|
|
2009-12-04 04:50:49 +00:00
|
|
|
s_vsync = !!theApp.GetConfig("vsync", 0);
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
HWND hWnd = NULL;
|
2011-02-19 03:36:30 +00:00
|
|
|
|
|
|
|
_GSopen((void**)&hWnd, "", renderer);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
uint32 crc;
|
2009-02-09 21:15:56 +00:00
|
|
|
fread(&crc, 4, 1, fp);
|
|
|
|
GSsetGameCRC(crc, 0);
|
|
|
|
|
|
|
|
GSFreezeData fd;
|
|
|
|
fread(&fd.size, 4, 1, fp);
|
2009-05-14 16:41:52 +00:00
|
|
|
fd.data = new uint8[fd.size];
|
2009-02-09 21:15:56 +00:00
|
|
|
fread(fd.data, fd.size, 1, fp);
|
|
|
|
GSfreeze(FREEZE_LOAD, &fd);
|
|
|
|
delete [] fd.data;
|
|
|
|
|
|
|
|
fread(regs, 0x2000, 1, fp);
|
|
|
|
|
|
|
|
long start = ftell(fp);
|
|
|
|
|
|
|
|
GSvsync(1);
|
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
struct Packet {uint8 type, param; uint32 size, addr; vector<uint8> buff;};
|
|
|
|
|
|
|
|
list<Packet*> packets;
|
|
|
|
vector<uint8> buff;
|
|
|
|
int type;
|
|
|
|
|
|
|
|
while((type = fgetc(fp)) != EOF)
|
|
|
|
{
|
|
|
|
Packet* p = new Packet();
|
|
|
|
|
|
|
|
p->type = (uint8)type;
|
|
|
|
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
|
|
|
|
p->param = (uint8)fgetc(fp);
|
|
|
|
|
|
|
|
fread(&p->size, 4, 1, fp);
|
|
|
|
|
|
|
|
switch(p->param)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
p->buff.resize(0x4000);
|
|
|
|
p->addr = 0x4000 - p->size;
|
|
|
|
fread(&p->buff[p->addr], p->size, 1, fp);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
p->buff.resize(p->size);
|
|
|
|
fread(&p->buff[0], p->size, 1, fp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
p->param = (uint8)fgetc(fp);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
|
|
fread(&p->size, 4, 1, fp);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
|
|
p->buff.resize(0x2000);
|
|
|
|
|
|
|
|
fread(&p->buff[0], 0x2000, 1, fp);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
packets.push_back(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
Sleep(100);
|
|
|
|
|
|
|
|
while(IsWindowVisible(hWnd))
|
|
|
|
{
|
|
|
|
for(list<Packet*>::iterator i = packets.begin(); i != packets.end(); i++)
|
|
|
|
{
|
|
|
|
Packet* p = *i;
|
|
|
|
|
|
|
|
switch(p->type)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
|
|
|
|
switch(p->param)
|
|
|
|
{
|
|
|
|
case 0: GSgifTransfer1(&p->buff[0], p->addr); break;
|
|
|
|
case 1: GSgifTransfer2(&p->buff[0], p->size / 16); break;
|
|
|
|
case 2: GSgifTransfer3(&p->buff[0], p->size / 16); break;
|
|
|
|
case 3: GSgifTransfer(&p->buff[0], p->size / 16); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
GSvsync(p->param);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
|
|
if(buff.size() < p->size) buff.resize(p->size);
|
|
|
|
|
|
|
|
GSreadFIFO2(&buff[0], p->size / 16);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
|
|
memcpy(regs, &p->buff[0], 0x2000);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(list<Packet*>::iterator i = packets.begin(); i != packets.end(); i++)
|
|
|
|
{
|
|
|
|
delete *i;
|
|
|
|
}
|
|
|
|
|
|
|
|
packets.clear();
|
|
|
|
|
2011-12-20 14:33:28 +00:00
|
|
|
Sleep(100);
|
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
|
|
|
|
/*
|
2012-01-06 00:17:52 +00:00
|
|
|
vector<uint8> buff;
|
2011-02-07 01:59:05 +00:00
|
|
|
bool exit = false;
|
|
|
|
|
2012-01-05 02:40:24 +00:00
|
|
|
int round = 0;
|
|
|
|
|
2011-02-07 01:59:05 +00:00
|
|
|
while(!exit)
|
|
|
|
{
|
|
|
|
uint32 index;
|
|
|
|
uint32 size;
|
|
|
|
uint32 addr;
|
|
|
|
|
|
|
|
int pos;
|
|
|
|
|
|
|
|
switch(fgetc(fp))
|
|
|
|
{
|
|
|
|
case EOF:
|
|
|
|
fseek(fp, start, 0);
|
|
|
|
exit = !IsWindowVisible(hWnd);
|
2012-01-05 02:40:24 +00:00
|
|
|
//exit = ++round == 60;
|
2011-02-07 01:59:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
index = fgetc(fp);
|
|
|
|
fread(&size, 4, 1, fp);
|
|
|
|
|
|
|
|
switch(index)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
if(buff.size() < 0x4000) buff.resize(0x4000);
|
|
|
|
addr = 0x4000 - size;
|
2011-02-07 10:09:58 +00:00
|
|
|
fread(&buff[addr], size, 1, fp);
|
|
|
|
GSgifTransfer1(&buff[0], addr);
|
2011-02-07 01:59:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
if(buff.size() < size) buff.resize(size);
|
2011-02-07 10:09:58 +00:00
|
|
|
fread(&buff[0], size, 1, fp);
|
|
|
|
GSgifTransfer2(&buff[0], size / 16);
|
2011-02-07 01:59:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
if(buff.size() < size) buff.resize(size);
|
2011-02-07 10:09:58 +00:00
|
|
|
fread(&buff[0], size, 1, fp);
|
|
|
|
GSgifTransfer3(&buff[0], size / 16);
|
2011-02-07 01:59:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
if(buff.size() < size) buff.resize(size);
|
2011-02-07 10:09:58 +00:00
|
|
|
fread(&buff[0], size, 1, fp);
|
|
|
|
GSgifTransfer(&buff[0], size / 16);
|
2011-02-07 01:59:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
GSvsync(fgetc(fp));
|
|
|
|
exit = !IsWindowVisible(hWnd);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
fread(&size, 4, 1, fp);
|
|
|
|
if(buff.size() < size) buff.resize(size);
|
|
|
|
GSreadFIFO2(&buff[0], size / 16);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
fread(regs, 0x2000, 1, fp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-01-05 02:40:24 +00:00
|
|
|
*/
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
GSclose();
|
|
|
|
GSshutdown();
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C GSBenchmark(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
|
|
|
|
{
|
|
|
|
::SetPriorityClass(::GetCurrentProcess(), HIGH_PRIORITY_CLASS);
|
|
|
|
|
2013-06-10 15:56:11 +00:00
|
|
|
FILE* file = fopen("c:\\temp1\\log.txt", "a");
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
fprintf(file, "-------------------------\n\n");
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(1)
|
|
|
|
{
|
2014-01-25 15:53:31 +00:00
|
|
|
GSLocalMemory * pMem = new GSLocalMemory();
|
|
|
|
GSLocalMemory& mem(*pMem);
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
static struct {int psm; const char* name;} s_format[] =
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
{PSM_PSMCT32, "32"},
|
|
|
|
{PSM_PSMCT24, "24"},
|
|
|
|
{PSM_PSMCT16, "16"},
|
|
|
|
{PSM_PSMCT16S, "16S"},
|
|
|
|
{PSM_PSMT8, "8"},
|
|
|
|
{PSM_PSMT4, "4"},
|
|
|
|
{PSM_PSMT8H, "8H"},
|
|
|
|
{PSM_PSMT4HL, "4HL"},
|
|
|
|
{PSM_PSMT4HH, "4HH"},
|
|
|
|
{PSM_PSMZ32, "32Z"},
|
|
|
|
{PSM_PSMZ24, "24Z"},
|
|
|
|
{PSM_PSMZ16, "16Z"},
|
|
|
|
{PSM_PSMZ16S, "16ZS"},
|
|
|
|
};
|
|
|
|
|
2011-02-07 01:59:05 +00:00
|
|
|
uint8* ptr = (uint8*)_aligned_malloc(1024 * 1024 * 4, 32);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
for(int i = 0; i < 1024 * 1024 * 4; i++) ptr[i] = (uint8)i;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
//
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
for(int tbw = 5; tbw <= 10; tbw++)
|
|
|
|
{
|
|
|
|
int n = 256 << ((10 - tbw) * 2);
|
|
|
|
|
|
|
|
int w = 1 << tbw;
|
|
|
|
int h = 1 << tbw;
|
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
fprintf(file, "%d x %d\n\n", w, h);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2013-06-29 12:02:03 +00:00
|
|
|
for(size_t i = 0; i < countof(s_format); i++)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
const GSLocalMemory::psm_t& psm = GSLocalMemory::m_psm[s_format[i].psm];
|
|
|
|
|
|
|
|
GSLocalMemory::writeImage wi = psm.wi;
|
|
|
|
GSLocalMemory::readImage ri = psm.ri;
|
|
|
|
GSLocalMemory::readTexture rtx = psm.rtx;
|
|
|
|
GSLocalMemory::readTexture rtxP = psm.rtxP;
|
|
|
|
|
|
|
|
GIFRegBITBLTBUF BITBLTBUF;
|
|
|
|
|
|
|
|
BITBLTBUF.SBP = 0;
|
|
|
|
BITBLTBUF.SBW = w / 64;
|
|
|
|
BITBLTBUF.SPSM = s_format[i].psm;
|
|
|
|
BITBLTBUF.DBP = 0;
|
|
|
|
BITBLTBUF.DBW = w / 64;
|
|
|
|
BITBLTBUF.DPSM = s_format[i].psm;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
GIFRegTRXPOS TRXPOS;
|
|
|
|
|
|
|
|
TRXPOS.SSAX = 0;
|
|
|
|
TRXPOS.SSAY = 0;
|
|
|
|
TRXPOS.DSAX = 0;
|
|
|
|
TRXPOS.DSAY = 0;
|
|
|
|
|
|
|
|
GIFRegTRXREG TRXREG;
|
|
|
|
|
|
|
|
TRXREG.RRW = w;
|
|
|
|
TRXREG.RRH = h;
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
GSVector4i r(0, 0, w, h);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
GIFRegTEX0 TEX0;
|
|
|
|
|
|
|
|
TEX0.TBP0 = 0;
|
|
|
|
TEX0.TBW = w / 64;
|
|
|
|
|
|
|
|
GIFRegTEXA TEXA;
|
|
|
|
|
|
|
|
TEXA.TA0 = 0;
|
|
|
|
TEXA.TA1 = 0x80;
|
|
|
|
TEXA.AEM = 0;
|
|
|
|
|
|
|
|
int trlen = w * h * psm.trbpp / 8;
|
|
|
|
int len = w * h * psm.bpp / 8;
|
|
|
|
|
|
|
|
clock_t start, end;
|
|
|
|
|
|
|
|
_ftprintf(file, _T("[%4s] "), s_format[i].name);
|
|
|
|
|
|
|
|
start = clock();
|
|
|
|
|
|
|
|
for(int j = 0; j < n; j++)
|
|
|
|
{
|
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
|
|
|
|
|
|
|
(mem.*wi)(x, y, ptr, trlen, BITBLTBUF, TRXPOS, TRXREG);
|
|
|
|
}
|
|
|
|
|
|
|
|
end = clock();
|
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
fprintf(file, "%6d %6d | ", (int)((float)trlen * n / (end - start) / 1000), (int)((float)(w * h) * n / (end - start) / 1000));
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
start = clock();
|
|
|
|
|
|
|
|
for(int j = 0; j < n; j++)
|
|
|
|
{
|
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
|
|
|
|
|
|
|
(mem.*ri)(x, y, ptr, trlen, BITBLTBUF, TRXPOS, TRXREG);
|
|
|
|
}
|
|
|
|
|
|
|
|
end = clock();
|
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
fprintf(file, "%6d %6d | ", (int)((float)trlen * n / (end - start) / 1000), (int)((float)(w * h) * n / (end - start) / 1000));
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-07-22 03:55:28 +00:00
|
|
|
const GSOffset* o = mem.GetOffset(TEX0.TBP0, TEX0.TBW, TEX0.PSM);
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
start = clock();
|
|
|
|
|
|
|
|
for(int j = 0; j < n; j++)
|
|
|
|
{
|
2009-07-22 03:55:28 +00:00
|
|
|
(mem.*rtx)(o, r, ptr, w * 4, TEXA);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
end = clock();
|
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
fprintf(file, "%6d %6d ", (int)((float)len * n / (end - start) / 1000), (int)((float)(w * h) * n / (end - start) / 1000));
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(psm.pal > 0)
|
|
|
|
{
|
|
|
|
start = clock();
|
|
|
|
|
|
|
|
for(int j = 0; j < n; j++)
|
|
|
|
{
|
2009-07-22 03:55:28 +00:00
|
|
|
(mem.*rtxP)(o, r, ptr, w, TEXA);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
end = clock();
|
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
fprintf(file, "| %6d %6d ", (int)((float)len * n / (end - start) / 1000), (int)((float)(w * h) * n / (end - start) / 1000));
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
fprintf(file, "\n");
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
fflush(file);
|
|
|
|
}
|
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
fprintf(file, "\n");
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_aligned_free(ptr);
|
2014-01-25 15:53:31 +00:00
|
|
|
delete pMem;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
if(0)
|
|
|
|
{
|
2014-01-25 15:53:31 +00:00
|
|
|
GSLocalMemory * pMem2 = new GSLocalMemory();
|
|
|
|
GSLocalMemory& mem2(*pMem2);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-02-07 01:59:05 +00:00
|
|
|
uint8* ptr = (uint8*)_aligned_malloc(1024 * 1024 * 4, 32);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
for(int i = 0; i < 1024 * 1024 * 4; i++) ptr[i] = (uint8)i;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
const GSLocalMemory::psm_t& psm = GSLocalMemory::m_psm[PSM_PSMCT32];
|
|
|
|
|
|
|
|
GSLocalMemory::writeImage wi = psm.wi;
|
|
|
|
|
|
|
|
GIFRegBITBLTBUF BITBLTBUF;
|
|
|
|
|
|
|
|
BITBLTBUF.DBP = 0;
|
|
|
|
BITBLTBUF.DBW = 32;
|
|
|
|
BITBLTBUF.DPSM = PSM_PSMCT32;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
GIFRegTRXPOS TRXPOS;
|
|
|
|
|
|
|
|
TRXPOS.DSAX = 0;
|
|
|
|
TRXPOS.DSAY = 1;
|
|
|
|
|
|
|
|
GIFRegTRXREG TRXREG;
|
|
|
|
|
|
|
|
TRXREG.RRW = 256;
|
|
|
|
TRXREG.RRH = 256;
|
|
|
|
|
|
|
|
int trlen = 256 * 256 * psm.trbpp / 8;
|
|
|
|
|
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
|
|
|
|
2014-01-25 15:53:31 +00:00
|
|
|
(mem2.*wi)(x, y, ptr, trlen, BITBLTBUF, TRXPOS, TRXREG);
|
|
|
|
delete pMem2;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
fclose(file);
|
2009-09-28 11:13:40 +00:00
|
|
|
PostQuitMessage(0);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-06-16 01:42:08 +00:00
|
|
|
#endif
|
2012-01-06 21:43:39 +00:00
|
|
|
|
|
|
|
#ifdef _LINUX
|
|
|
|
|
2012-01-12 07:29:31 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/timeb.h> // ftime(), struct timeb
|
|
|
|
|
|
|
|
inline unsigned long timeGetTime()
|
|
|
|
{
|
|
|
|
timeb t;
|
|
|
|
ftime(&t);
|
|
|
|
|
|
|
|
return (unsigned long)(t.time*1000 + t.millitm);
|
|
|
|
}
|
|
|
|
|
2012-01-06 21:43:39 +00:00
|
|
|
// Note
|
|
|
|
EXPORT_C GSReplay(char* lpszCmdLine, int renderer)
|
|
|
|
{
|
2013-07-28 14:40:43 +00:00
|
|
|
GLLoader::in_replayer = true;
|
2012-01-06 21:43:39 +00:00
|
|
|
|
|
|
|
// lpszCmdLine:
|
|
|
|
// First parameter is the renderer.
|
|
|
|
// Second parameter is the gs file to load and run.
|
|
|
|
|
|
|
|
//EXPORT_C GSReplay(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
|
|
|
|
#if 0
|
|
|
|
int renderer = -1;
|
|
|
|
|
|
|
|
{
|
|
|
|
char* start = lpszCmdLine;
|
|
|
|
char* end = NULL;
|
|
|
|
long n = strtol(lpszCmdLine, &end, 10);
|
|
|
|
if(end > start) {renderer = n; lpszCmdLine = end;}
|
|
|
|
}
|
|
|
|
|
|
|
|
while(*lpszCmdLine == ' ') lpszCmdLine++;
|
|
|
|
|
|
|
|
::SetPriorityClass(::GetCurrentProcess(), HIGH_PRIORITY_CLASS);
|
|
|
|
#endif
|
2012-03-30 19:02:37 +00:00
|
|
|
// Allow to easyly switch between SW/HW renderer
|
|
|
|
renderer = theApp.GetConfig("renderer", 12);
|
|
|
|
if (renderer != 12 && renderer != 13)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "wrong renderer selected %d\n", renderer);
|
|
|
|
return;
|
|
|
|
}
|
2012-01-06 21:43:39 +00:00
|
|
|
|
2013-06-26 20:09:07 +00:00
|
|
|
vector<float> stats;
|
|
|
|
stats.clear();
|
|
|
|
|
2012-01-06 21:43:39 +00:00
|
|
|
if(FILE* fp = fopen(lpszCmdLine, "rb"))
|
|
|
|
{
|
|
|
|
//Console console("GSdx", true);
|
|
|
|
|
|
|
|
GSinit();
|
|
|
|
|
|
|
|
uint8 regs[0x2000];
|
|
|
|
GSsetBaseMem(regs);
|
|
|
|
|
|
|
|
s_vsync = !!theApp.GetConfig("vsync", 0);
|
|
|
|
|
|
|
|
void* hWnd = NULL;
|
|
|
|
|
2013-07-28 14:40:43 +00:00
|
|
|
int err = _GSopen((void**)&hWnd, "", renderer);
|
|
|
|
if (err != 0) {
|
|
|
|
fprintf(stderr, "Error failed to GSopen\n");
|
|
|
|
return;
|
|
|
|
}
|
2013-06-16 16:33:08 +00:00
|
|
|
if (s_gs->m_wnd == NULL) return;
|
2012-01-06 21:43:39 +00:00
|
|
|
|
|
|
|
uint32 crc;
|
|
|
|
fread(&crc, 4, 1, fp);
|
|
|
|
GSsetGameCRC(crc, 0);
|
|
|
|
|
|
|
|
GSFreezeData fd;
|
|
|
|
fread(&fd.size, 4, 1, fp);
|
|
|
|
fd.data = new uint8[fd.size];
|
|
|
|
fread(fd.data, fd.size, 1, fp);
|
|
|
|
GSfreeze(FREEZE_LOAD, &fd);
|
|
|
|
delete [] fd.data;
|
|
|
|
|
|
|
|
fread(regs, 0x2000, 1, fp);
|
|
|
|
|
|
|
|
GSvsync(1);
|
|
|
|
|
|
|
|
struct Packet {uint8 type, param; uint32 size, addr; vector<uint8> buff;};
|
|
|
|
|
|
|
|
list<Packet*> packets;
|
|
|
|
vector<uint8> buff;
|
|
|
|
int type;
|
|
|
|
|
|
|
|
while((type = fgetc(fp)) != EOF)
|
|
|
|
{
|
|
|
|
Packet* p = new Packet();
|
|
|
|
|
|
|
|
p->type = (uint8)type;
|
|
|
|
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
|
|
|
|
p->param = (uint8)fgetc(fp);
|
|
|
|
|
|
|
|
fread(&p->size, 4, 1, fp);
|
|
|
|
|
|
|
|
switch(p->param)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
p->buff.resize(0x4000);
|
|
|
|
p->addr = 0x4000 - p->size;
|
|
|
|
fread(&p->buff[p->addr], p->size, 1, fp);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
p->buff.resize(p->size);
|
|
|
|
fread(&p->buff[0], p->size, 1, fp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
p->param = (uint8)fgetc(fp);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
|
|
fread(&p->size, 4, 1, fp);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
|
|
p->buff.resize(0x2000);
|
|
|
|
|
|
|
|
fread(&p->buff[0], 0x2000, 1, fp);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
packets.push_back(p);
|
|
|
|
}
|
|
|
|
|
2012-01-08 21:59:42 +00:00
|
|
|
sleep(1);
|
2012-01-06 21:43:39 +00:00
|
|
|
|
|
|
|
//while(IsWindowVisible(hWnd))
|
|
|
|
//FIXME map?
|
2013-06-26 20:09:07 +00:00
|
|
|
int finished = theApp.GetConfig("linux_replay", 1);
|
|
|
|
unsigned long frame_number = 0;
|
2012-01-31 17:08:05 +00:00
|
|
|
while(finished > 0)
|
2012-01-06 21:43:39 +00:00
|
|
|
{
|
2013-06-26 20:09:07 +00:00
|
|
|
frame_number = 0;
|
2012-01-12 07:29:31 +00:00
|
|
|
unsigned long start = timeGetTime();
|
2012-01-06 21:43:39 +00:00
|
|
|
for(auto i = packets.begin(); i != packets.end(); i++)
|
|
|
|
{
|
|
|
|
Packet* p = *i;
|
|
|
|
|
|
|
|
switch(p->type)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
|
|
|
|
switch(p->param)
|
|
|
|
{
|
|
|
|
case 0: GSgifTransfer1(&p->buff[0], p->addr); break;
|
|
|
|
case 1: GSgifTransfer2(&p->buff[0], p->size / 16); break;
|
|
|
|
case 2: GSgifTransfer3(&p->buff[0], p->size / 16); break;
|
|
|
|
case 3: GSgifTransfer(&p->buff[0], p->size / 16); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
|
|
|
|
GSvsync(p->param);
|
2012-01-12 07:29:31 +00:00
|
|
|
frame_number++;
|
2012-01-06 21:43:39 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
|
|
|
if(buff.size() < p->size) buff.resize(p->size);
|
|
|
|
|
|
|
|
GSreadFIFO2(&buff[0], p->size / 16);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
|
|
|
memcpy(regs, &p->buff[0], 0x2000);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-01-12 07:29:31 +00:00
|
|
|
unsigned long end = timeGetTime();
|
2012-06-13 10:43:04 +00:00
|
|
|
fprintf(stderr, "The %ld frames of the scene was render on %ldms\n", frame_number, end - start);
|
2012-01-12 07:29:31 +00:00
|
|
|
fprintf(stderr, "A means of %fms by frame\n", (float)(end - start)/(float)frame_number);
|
2012-01-08 21:59:42 +00:00
|
|
|
|
2013-06-26 20:09:07 +00:00
|
|
|
stats.push_back((float)(end - start));
|
|
|
|
|
|
|
|
|
2012-01-12 07:29:31 +00:00
|
|
|
sleep(1);
|
2012-01-31 17:08:05 +00:00
|
|
|
finished--;
|
2012-01-06 21:43:39 +00:00
|
|
|
}
|
|
|
|
|
2013-07-19 19:25:50 +00:00
|
|
|
if (theApp.GetConfig("linux_replay", 1) > 1) {
|
|
|
|
// Print some nice stats
|
|
|
|
// Skip first frame (shader compilation populate the result)
|
|
|
|
// it divides by 10 the standard deviation...
|
|
|
|
float n = (float)theApp.GetConfig("linux_replay", 1) - 1.0f;
|
|
|
|
float mean = 0;
|
|
|
|
float sd = 0;
|
|
|
|
for (auto i = stats.begin()+1; i != stats.end(); i++) {
|
|
|
|
mean += *i;
|
|
|
|
}
|
|
|
|
mean = mean/n;
|
|
|
|
for (auto i = stats.begin()+1; i != stats.end(); i++) {
|
|
|
|
sd += pow((*i)-mean, 2);
|
|
|
|
}
|
|
|
|
sd = sqrt(sd/n);
|
2013-06-26 20:09:07 +00:00
|
|
|
|
2013-07-19 19:25:50 +00:00
|
|
|
fprintf(stderr, "\n\nMean: %fms\n", mean);
|
|
|
|
fprintf(stderr, "Standard deviation: %fms\n", sd);
|
|
|
|
fprintf(stderr, "Mean by frame: %fms (%ffps)\n", mean/(float)frame_number, 1000.0f*frame_number/mean);
|
|
|
|
fprintf(stderr, "Standard deviatin by frame: %fms\n", sd/(float)frame_number);
|
|
|
|
}
|
2012-01-12 07:29:31 +00:00
|
|
|
|
2012-01-06 21:43:39 +00:00
|
|
|
for(auto i = packets.begin(); i != packets.end(); i++)
|
|
|
|
{
|
|
|
|
delete *i;
|
|
|
|
}
|
|
|
|
|
|
|
|
packets.clear();
|
|
|
|
|
2012-01-08 21:59:42 +00:00
|
|
|
sleep(1);
|
2012-01-06 21:43:39 +00:00
|
|
|
|
|
|
|
GSclose();
|
|
|
|
GSshutdown();
|
|
|
|
|
|
|
|
fclose(fp);
|
2013-06-26 20:09:07 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "failed to open %s\n", lpszCmdLine);
|
2012-01-06 21:43:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|