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.
|
|
|
|
*
|
|
|
|
* 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 GNU Make; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
2009-05-18 11:08:04 +00:00
|
|
|
#include "GSdx.h"
|
2009-02-09 21:15:56 +00:00
|
|
|
#include "GSUtil.h"
|
|
|
|
#include "GPURendererSW.h"
|
|
|
|
#include "GSDevice7.h"
|
|
|
|
#include "GSDevice9.h"
|
|
|
|
#include "GSDevice10.h"
|
|
|
|
#include "GPUSettingsDlg.h"
|
|
|
|
|
|
|
|
#define PSE_LT_GPU 2
|
|
|
|
|
|
|
|
static HRESULT s_hr = E_FAIL;
|
2009-05-22 01:22:52 +00:00
|
|
|
static GPURenderer* s_gpu = NULL;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C_(uint32) PSEgetLibType()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
return PSE_LT_GPU;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(char*) PSEgetLibName()
|
|
|
|
{
|
|
|
|
return GSUtil::GetLibName();
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C_(uint32) PSEgetLibVersion()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
static const uint32 version = 1;
|
|
|
|
static const uint32 revision = 1;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
return version << 16 | revision << 8 | PLUGIN_VERSION;
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C_(int32) GPUinit()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C_(int32) GPUshutdown()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C_(int32) GPUclose()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
delete s_gpu;
|
|
|
|
|
|
|
|
s_gpu = NULL;
|
|
|
|
|
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
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C_(int32) GPUopen(HWND hWnd)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-18 11:08:04 +00:00
|
|
|
GPUclose();
|
|
|
|
|
|
|
|
#ifdef _WINDOWS
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
AFX_MANAGE_STATE(AfxGetStaticModuleState());
|
|
|
|
|
2009-05-18 11:08:04 +00:00
|
|
|
s_hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
|
|
|
|
|
|
|
if(!GSUtil::CheckDirectX())
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-05-18 11:08:04 +00:00
|
|
|
#endif
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-18 11:08:04 +00:00
|
|
|
if(!GSUtil::CheckSSE())
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-22 23:23:38 +00:00
|
|
|
int renderer = theApp.GetConfig("Renderer", 1);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
switch(renderer)
|
|
|
|
{
|
|
|
|
default:
|
2009-05-22 23:23:38 +00:00
|
|
|
case 0: s_gpu = new GPURendererSW(new GSDevice7()); break;
|
|
|
|
case 1: s_gpu = new GPURendererSW(new GSDevice9()); break;
|
|
|
|
case 2: s_gpu = new GPURendererSW(new GSDevice10()); break;
|
|
|
|
// TODO: case 3: s_gpu = new GPURendererNull(new GSDeviceNull()); break;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!s_gpu->Create(hWnd))
|
|
|
|
{
|
|
|
|
GPUclose();
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C_(int32) GPUconfigure()
|
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
|
|
|
AFX_MANAGE_STATE(AfxGetStaticModuleState());
|
|
|
|
|
|
|
|
GPUSettingsDlg dlg;
|
|
|
|
|
|
|
|
if(IDOK == dlg.DoModal())
|
|
|
|
{
|
|
|
|
GPUshutdown();
|
|
|
|
GPUinit();
|
|
|
|
}
|
|
|
|
|
2009-05-18 11:08:04 +00:00
|
|
|
#endif
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C_(int32) GPUtest()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C GPUabout()
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C GPUwriteDataMem(const uint8* mem, uint32 size)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
s_gpu->WriteData(mem, size);
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C GPUwriteData(uint32 data)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
s_gpu->WriteData((uint8*)&data, 1);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C GPUreadDataMem(uint8* mem, uint32 size)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
s_gpu->ReadData(mem, size);
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C_(uint32) GPUreadData()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
uint32 data = 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
s_gpu->ReadData((uint8*)&data, 1);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C GPUwriteStatus(uint32 status)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
s_gpu->WriteStatus(status);
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C_(uint32) GPUreadStatus()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
return s_gpu->ReadStatus();
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C_(uint32) GPUdmaChain(const uint8* mem, uint32 addr)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
uint32 last[3];
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
memset(last, 0xff, sizeof(last));
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
if(addr == last[1] || addr == last[2])
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
(addr < last[0] ? last[1] : last[2]) = addr;
|
2009-05-14 16:41:52 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
last[0] = addr;
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
uint8 size = mem[addr + 3];
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(size > 0)
|
|
|
|
{
|
|
|
|
s_gpu->WriteData(&mem[addr + 4], size);
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
addr = *(uint32*)&mem[addr] & 0xffffff;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
while(addr != 0xffffff);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C_(uint32) GPUgetMode()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C GPUsetMode(uint32 mode)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C GPUupdateLace()
|
|
|
|
{
|
|
|
|
s_gpu->VSync();
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C GPUmakeSnapshot()
|
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
s_gpu->MakeSnapshot("c:/"); // TODO
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C GPUdisplayText(char* text)
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C GPUdisplayFlags(uint32 flags)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C_(int32) GPUfreeze(uint32 type, GPUFreezeData* data)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
if(!data || data->version != 1)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(type == 0)
|
|
|
|
{
|
|
|
|
s_gpu->Defrost(data);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if(type == 1)
|
|
|
|
{
|
|
|
|
s_gpu->Freeze(data);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if(type == 2)
|
|
|
|
{
|
|
|
|
int slot = *(int*)data + 1;
|
|
|
|
|
|
|
|
if(slot < 1 || slot > 9)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C GPUgetScreenPic(uint8* mem)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C GPUshowScreenPic(uint8* mem)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C GPUcursor(int player, int x, int y)
|
|
|
|
{
|
|
|
|
// TODO
|
2009-02-06 19:15:15 +00:00
|
|
|
}
|