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"
|
|
|
|
#include "GSUtil.h"
|
2009-06-27 03:32:33 +00:00
|
|
|
#include "GSRendererDX9.h"
|
|
|
|
#include "GSRendererDX10.h"
|
|
|
|
#include "GSRendererDX11.h"
|
2009-06-12 19:09:17 +00:00
|
|
|
#include "GSRendererOGL.h"
|
2009-02-09 21:15:56 +00:00
|
|
|
#include "GSRendererSW.h"
|
|
|
|
#include "GSRendererNull.h"
|
|
|
|
#include "GSSettingsDlg.h"
|
|
|
|
|
|
|
|
#define PS2E_LT_GS 0x01
|
|
|
|
#define PS2E_GS_VERSION 0x0006
|
|
|
|
#define PS2E_X86 0x01 // 32 bit
|
|
|
|
#define PS2E_X86_64 0x02 // 64 bit
|
|
|
|
|
|
|
|
static HRESULT s_hr = E_FAIL;
|
2009-05-22 01:22:52 +00:00
|
|
|
static GSRenderer* s_gs = NULL;
|
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-02-09 21:15:56 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(char*) PS2EgetLibName()
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C_(uint32) PS2EgetCpuPlatform()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
#if _M_AMD64
|
|
|
|
return PS2E_X86_64;
|
|
|
|
#else
|
|
|
|
return PS2E_X86;
|
|
|
|
#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;
|
|
|
|
if( s_gs )
|
|
|
|
{
|
|
|
|
s_gs->SetRegsMem( s_basemem );
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(INT32) GSinit()
|
|
|
|
{
|
2009-06-23 04:12:32 +00:00
|
|
|
if(!GSUtil::CheckSSE())
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-09-17 07:40:38 +00:00
|
|
|
#ifdef _WINDOWS
|
|
|
|
|
2009-10-12 19:58:03 +00:00
|
|
|
//_CrtSetBreakAlloc( 1273 );
|
|
|
|
|
2009-09-17 07:40:38 +00:00
|
|
|
s_hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
|
|
|
|
|
|
|
if(!GSUtil::CheckDirectX())
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C GSshutdown()
|
|
|
|
{
|
|
|
|
delete s_gs;
|
2009-09-17 07:40:38 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
s_gs = NULL;
|
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
|
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
|
|
|
{
|
2009-09-17 07:40:38 +00:00
|
|
|
if( !s_gs ) return;
|
2009-05-18 11:08:04 +00:00
|
|
|
|
2009-09-17 07:40:38 +00:00
|
|
|
s_gs->ResetDevice();
|
2009-05-18 11:08:04 +00:00
|
|
|
|
2009-09-17 07:40:38 +00:00
|
|
|
delete s_gs->m_dev;
|
|
|
|
s_gs->m_dev = NULL;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-09-17 07:40:38 +00:00
|
|
|
s_gs->m_wnd.Detach();
|
|
|
|
}
|
|
|
|
|
2009-09-18 19:54:56 +00:00
|
|
|
static INT32 _GSopen(void* dsp, char* title, int renderer)
|
2009-09-17 07:40:38 +00:00
|
|
|
{
|
|
|
|
GSclose();
|
|
|
|
|
|
|
|
GSDevice* dev = NULL;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-09-19 11:20:31 +00:00
|
|
|
if( renderer == -1 )
|
|
|
|
{
|
|
|
|
renderer = theApp.GetConfig("renderer", 0);
|
|
|
|
}
|
|
|
|
|
2009-09-18 18:45:37 +00:00
|
|
|
try
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-11-05 00:29:39 +00:00
|
|
|
if (s_renderer != renderer)
|
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
s_gs = NULL;
|
|
|
|
}
|
|
|
|
|
2009-09-17 07:40:38 +00:00
|
|
|
switch(renderer)
|
|
|
|
{
|
|
|
|
default:
|
2009-09-18 18:45:37 +00:00
|
|
|
case 0: case 1: case 2: dev = new GSDevice9(); break;
|
|
|
|
case 3: case 4: case 5: dev = new GSDevice10(); break;
|
|
|
|
case 6: case 7: case 8: dev = new GSDevice11(); break;
|
|
|
|
#if 0
|
|
|
|
case 9: case 10: case 11: dev = new GSDeviceOGL(); break;
|
|
|
|
#endif
|
|
|
|
case 12: case 13: new GSDeviceNull(); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !dev ) return -1;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-09-18 18:45:37 +00:00
|
|
|
if( !s_gs )
|
|
|
|
{
|
|
|
|
switch(renderer)
|
|
|
|
{
|
|
|
|
default:
|
2009-09-18 19:54:56 +00:00
|
|
|
case 0: s_gs = new GSRendererDX9(); break;
|
|
|
|
case 3: s_gs = new GSRendererDX10(); break;
|
|
|
|
case 6: s_gs = new GSRendererDX11(); break;
|
2009-09-18 18:45:37 +00:00
|
|
|
#if 0
|
2009-09-18 19:54:56 +00:00
|
|
|
case 9: s_gs = new GSRendererOGL(); break;
|
2009-09-18 18:45:37 +00:00
|
|
|
#endif
|
|
|
|
case 2: case 5: case 8: case 11: case 13:
|
2009-09-18 19:54:56 +00:00
|
|
|
s_gs = new GSRendererNull(); break;
|
2009-09-18 18:45:37 +00:00
|
|
|
|
|
|
|
case 1: case 4: case 7: case 10: case 12:
|
2009-09-18 19:54:56 +00:00
|
|
|
s_gs = new GSRendererSW(); break;
|
2009-09-18 18:45:37 +00:00
|
|
|
}
|
2009-09-18 23:48:12 +00:00
|
|
|
|
|
|
|
s_renderer = renderer;
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
2009-09-18 18:45:37 +00:00
|
|
|
catch( std::exception& ex )
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
|
|
|
printf( "GSdx error: Exception caught in GSopen: %s", ex.what() );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-09-18 19:54:56 +00:00
|
|
|
s_gs->SetRegsMem(s_basemem);
|
|
|
|
s_gs->SetIrqCallback(s_irq);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-09-17 07:40:38 +00:00
|
|
|
if( *(HWND*)dsp == NULL )
|
|
|
|
{
|
|
|
|
// old-style API expects us to create and manage our own window:
|
|
|
|
|
|
|
|
int w = theApp.GetConfig("ModeWidth", 0);
|
|
|
|
int h = theApp.GetConfig("ModeHeight", 0);
|
|
|
|
|
|
|
|
if(!s_gs->CreateWnd(title, w, h))
|
|
|
|
{
|
|
|
|
GSclose();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
s_gs->m_wnd.Show();
|
|
|
|
*(HWND*)dsp = (HWND)s_gs->m_wnd.GetHandle();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-09-18 19:54:56 +00:00
|
|
|
s_gs->SetMultithreaded( true );
|
2009-09-17 07:40:38 +00:00
|
|
|
s_gs->m_wnd.Attach( *(HWND*)dsp, false );
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-09-17 07:40:38 +00:00
|
|
|
if( !s_gs->CreateDevice(dev) )
|
|
|
|
{
|
|
|
|
GSclose();
|
|
|
|
return -1;
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
// if(mt) _mm_setcsr(MXCSR);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-18 18:45:37 +00:00
|
|
|
EXPORT_C_(INT32) GSopen2( void* dsp, INT32 flags )
|
2009-09-17 07:40:38 +00:00
|
|
|
{
|
2009-09-18 18:45:37 +00:00
|
|
|
theApp.SetConfig("windowed", flags & 1);
|
|
|
|
theApp.SetConfig("vsync", flags & 2);
|
|
|
|
|
2009-09-17 07:40:38 +00:00
|
|
|
int renderer = theApp.GetConfig("renderer", 0);
|
2009-09-18 18:45:37 +00:00
|
|
|
if( flags & 4 )
|
2009-09-17 07:40:38 +00:00
|
|
|
{
|
|
|
|
renderer = 1;
|
|
|
|
}
|
|
|
|
|
2009-09-18 19:54:56 +00:00
|
|
|
return _GSopen( dsp, NULL, renderer );
|
2009-09-17 07:40:38 +00:00
|
|
|
}
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
EXPORT_C_(INT32) GSopen(void* dsp, char* title, int mt)
|
|
|
|
{
|
2009-03-05 20:00:41 +00:00
|
|
|
int renderer;
|
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
if(mt == 2)
|
|
|
|
{
|
|
|
|
// pcsx2 sent a switch renderer request
|
2009-03-05 20:00:41 +00:00
|
|
|
renderer = 1; //DX9 sw
|
|
|
|
mt = 1;
|
|
|
|
}
|
2009-05-11 08:18:00 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// normal init
|
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
|
|
|
|
2009-09-17 07:40:38 +00:00
|
|
|
*(HWND*)dsp = NULL;
|
2009-09-18 19:54:56 +00:00
|
|
|
|
|
|
|
int retval = _GSopen(dsp, title, renderer);
|
|
|
|
|
|
|
|
if( retval == 0 && s_gs )
|
|
|
|
{
|
2009-09-18 22:13:40 +00:00
|
|
|
s_gs->SetMultithreaded( !!mt );
|
2009-09-18 19:54:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C GSreset()
|
|
|
|
{
|
|
|
|
s_gs->Reset();
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C GSgifSoftReset(uint32 mask)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-14 16:41:52 +00:00
|
|
|
s_gs->SoftReset(mask);
|
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
|
|
|
{
|
|
|
|
s_gs->WriteCSR(csr);
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C GSreadFIFO(uint8* mem)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
s_gs->ReadFIFO(mem, 1);
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C GSreadFIFO2(uint8* mem, uint32 size)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
s_gs->ReadFIFO(mem, size);
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C GSgifTransfer1(uint8* mem, uint32 addr)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
s_gs->Transfer<0>(mem + addr, (0x4000 - addr) / 16);
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C GSgifTransfer2(uint8* mem, uint32 size)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
s_gs->Transfer<1>(mem, size);
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C GSgifTransfer3(uint8* mem, uint32 size)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
|
|
|
s_gs->Transfer<2>(mem, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C GSvsync(int field)
|
|
|
|
{
|
2009-05-18 11:08:04 +00:00
|
|
|
#ifdef _WINDOWS
|
|
|
|
|
|
|
|
MSG msg;
|
|
|
|
|
|
|
|
memset(&msg, 0, sizeof(msg));
|
|
|
|
|
|
|
|
while(msg.message != WM_QUIT && PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
s_gs->VSync(field);
|
|
|
|
}
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
EXPORT_C_(uint32) GSmakeSnapshot(char* path)
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2009-05-11 08:18:00 +00:00
|
|
|
return s_gs->MakeSnapshot(string(path) + "gsdx");
|
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
|
|
|
{
|
2009-05-18 11:08:04 +00:00
|
|
|
s_gs->KeyEvent(e);
|
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
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C GSconfigure()
|
|
|
|
{
|
2009-09-18 23:48:12 +00:00
|
|
|
if( GSSettingsDlg().DoModal() == IDOK )
|
|
|
|
{
|
|
|
|
if( s_gs != NULL && s_gs->m_wnd.IsManaged() )
|
|
|
|
{
|
|
|
|
// Legacy apps like gsdxgui expect this...
|
|
|
|
GSshutdown();
|
|
|
|
}
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C_(INT32) GStest()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C GSabout()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C GSirqCallback(void (*irq)())
|
|
|
|
{
|
|
|
|
s_irq = irq;
|
2009-09-18 19:54:56 +00:00
|
|
|
if( s_gs )
|
|
|
|
{
|
|
|
|
s_gs->SetIrqCallback(s_irq);
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-08-16 16:45:26 +00:00
|
|
|
EXPORT_C_(int) GSsetupRecording(int start, void* data)
|
2009-08-16 11:35:30 +00:00
|
|
|
{
|
2009-08-16 16:45:26 +00:00
|
|
|
GSKeyEventData e;
|
|
|
|
|
|
|
|
e.type = KEYPRESS;
|
|
|
|
e.key = VK_F12;
|
|
|
|
|
|
|
|
s_gs->KeyEvent(&e, start & 1);
|
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
|
|
|
{
|
|
|
|
s_gs->SetGameCRC(crc, options);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C GSsetFrameSkip(int frameskip)
|
|
|
|
{
|
|
|
|
s_gs->SetFrameSkip(frameskip);
|
|
|
|
}
|
|
|
|
|
2009-10-31 01:06:23 +00:00
|
|
|
|
2009-07-16 12:38:42 +00:00
|
|
|
EXPORT_C GSsetFrameLimit(int limit)
|
2009-07-15 19:44:06 +00:00
|
|
|
{
|
2009-10-31 01:06:23 +00:00
|
|
|
s_framelimit = limit != 0;
|
|
|
|
if( s_gs )
|
|
|
|
s_gs->SetFrameLimit(s_framelimit);
|
2009-07-15 19:44:06 +00:00
|
|
|
}
|
|
|
|
|
2009-05-18 11:08:04 +00:00
|
|
|
#ifdef _WINDOWS
|
|
|
|
|
2009-09-19 11:20:31 +00:00
|
|
|
// Returns false if the window's been closed or an invalid packet was encountered.
|
|
|
|
static __forceinline bool LoopDatPacket_Thingamajig(HWND hWnd, uint8 (®s)[0x2000], vector<uint8>& buff, FILE* fp, long start)
|
|
|
|
{
|
|
|
|
switch(fgetc(fp))
|
|
|
|
{
|
|
|
|
case EOF:
|
|
|
|
fseek(fp, start, 0);
|
|
|
|
return !!IsWindowVisible(hWnd);
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
uint32 index = fgetc(fp);
|
|
|
|
uint32 size;
|
|
|
|
|
|
|
|
fread(&size, 4, 1, fp);
|
|
|
|
|
|
|
|
switch(index)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
if(buff.size() < 0x4000) buff.resize(0x4000);
|
|
|
|
uint32 addr = 0x4000 - size;
|
|
|
|
fread(&buff[0] + addr, size, 1, fp);
|
|
|
|
GSgifTransfer1(&buff[0], addr);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
if(buff.size() < size) buff.resize(size);
|
|
|
|
fread(&buff[0], size, 1, fp);
|
|
|
|
GSgifTransfer2(&buff[0], size / 16);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
if(buff.size() < size) buff.resize(size);
|
|
|
|
fread(&buff[0], size, 1, fp);
|
|
|
|
GSgifTransfer3(&buff[0], size / 16);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
GSvsync(fgetc(fp));
|
|
|
|
return !!IsWindowVisible(hWnd);
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
uint32 size;
|
|
|
|
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;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// lpszCmdLine:
|
|
|
|
// First parameter is the renderer.
|
|
|
|
// Second parameter is the gs file to load and run.
|
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);
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
vector<uint8> buff;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
if(FILE* fp = fopen(lpszCmdLine, "rb"))
|
|
|
|
{
|
|
|
|
GSinit();
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
uint8 regs[0x2000];
|
2009-02-09 21:15:56 +00:00
|
|
|
GSsetBaseMem(regs);
|
|
|
|
|
|
|
|
HWND hWnd = NULL;
|
2009-09-19 11:20:31 +00:00
|
|
|
_GSopen(&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);
|
|
|
|
|
2009-09-19 11:20:31 +00:00
|
|
|
while( LoopDatPacket_Thingamajig(hWnd, regs, buff, fp, start) ) ;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
GSclose();
|
|
|
|
GSshutdown();
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
}
|
2009-09-28 11:13:40 +00:00
|
|
|
PostQuitMessage(0);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_C GSBenchmark(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
|
|
|
|
{
|
|
|
|
::SetPriorityClass(::GetCurrentProcess(), HIGH_PRIORITY_CLASS);
|
|
|
|
|
2009-05-11 08:18:00 +00:00
|
|
|
FILE* file = fopen("c:\\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)
|
|
|
|
{
|
|
|
|
GSLocalMemory mem;
|
|
|
|
|
2009-05-11 08:18:00 +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"},
|
|
|
|
};
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
uint8* ptr = (uint8*)_aligned_malloc(1024 * 1024 * 4, 16);
|
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
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
for(int i = 0; i < countof(s_format); i++)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
if(0)
|
|
|
|
{
|
|
|
|
GSLocalMemory mem;
|
|
|
|
|
2009-05-14 16:41:52 +00:00
|
|
|
uint8* ptr = (uint8*)_aligned_malloc(1024 * 1024 * 4, 16);
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
(mem.*wi)(x, y, ptr, trlen, BITBLTBUF, TRXPOS, TRXREG);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
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
|