2010-03-19 00:31:15 +00:00
|
|
|
/* ZeroGS KOSMOS
|
|
|
|
* Copyright (C) 2005-2006 zerofrog@gmail.com
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
#if defined(_WIN32)
|
|
|
|
#include <windows.h>
|
|
|
|
#include "Win32.h"
|
|
|
|
#include <io.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#include "GS.h"
|
|
|
|
#include "Mem.h"
|
|
|
|
#include "Regs.h"
|
|
|
|
|
|
|
|
#include "zerogs.h"
|
|
|
|
#include "targets.h"
|
|
|
|
#include "ZeroGSShaders/zerogsshaders.h"
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(disable:4244)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
GSinternal gs;
|
|
|
|
char GStitle[256];
|
|
|
|
GSconf conf;
|
|
|
|
int ppf;
|
|
|
|
primInfo *prim;
|
|
|
|
FILE *gsLog;
|
|
|
|
int g_GSMultiThreaded = 0;
|
|
|
|
void (*GSirq)();
|
|
|
|
u8* g_pBasePS2Mem = NULL;
|
|
|
|
int g_TransferredToGPU = 0;
|
|
|
|
std::string s_strIniPath("inis/"); // Air's new ini path (r2361)
|
|
|
|
|
2010-05-01 23:34:44 +00:00
|
|
|
//static bool g_bHidden = 0;
|
2010-03-19 00:31:15 +00:00
|
|
|
int g_GameSettings = 0;
|
|
|
|
int CurrentSavestate = 0; // Number of SaveSlot. Default is 0
|
|
|
|
bool SaveStateExists = true; // We could not know save slot status before first change occured
|
|
|
|
const char* SaveStateFile = NULL; // Name of SaveFile for access check.
|
|
|
|
|
|
|
|
// statistics
|
|
|
|
u32 g_nGenVars = 0, g_nTexVars = 0, g_nAlphaVars = 0, g_nResolve = 0;
|
|
|
|
|
2010-03-19 01:00:53 +00:00
|
|
|
#define VER 1
|
2010-03-19 00:31:15 +00:00
|
|
|
const unsigned char zgsversion = PS2E_GS_VERSION;
|
|
|
|
unsigned char zgsrevision = 0; // revision and build gives plugin version
|
|
|
|
unsigned char zgsbuild = VER;
|
2010-03-19 01:00:53 +00:00
|
|
|
unsigned char zgsminor = 0;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
#ifdef _DEBUG
|
2010-03-19 01:00:53 +00:00
|
|
|
char *libraryName = "ZZ Ogl PG (Debug) ";
|
2010-04-25 09:02:36 +00:00
|
|
|
#elif defined(ZEROGS_DEVBUILD)
|
|
|
|
char *libraryName = "ZZ Ogl PG (Dev)";
|
2010-03-19 00:31:15 +00:00
|
|
|
#else
|
2010-04-25 09:02:36 +00:00
|
|
|
char *libraryName = "ZZ Ogl PG ";
|
2010-03-19 00:31:15 +00:00
|
|
|
#endif
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
static const char* s_aa[5] = { "AA none |", "AA 2x |", "AA 4x |", "AA 8x |", "AA 16x |" };
|
2010-03-19 01:00:53 +00:00
|
|
|
static const char* s_naa[3] = { "native res |", "res /2 |", "res /4 |" };
|
2010-03-19 00:31:15 +00:00
|
|
|
static const char* pbilinear[] = { "off", "normal", "forced" };
|
|
|
|
|
|
|
|
extern GIFRegHandler g_GIFPackedRegHandlers[];
|
|
|
|
extern GIFRegHandler g_GIFRegHandlers[];
|
|
|
|
GIFRegHandler g_GIFTempRegHandlers[16] = {0};
|
|
|
|
extern int g_nPixelShaderVer;
|
|
|
|
extern int g_nFrameRender;
|
|
|
|
extern int g_nFramesSkipped;
|
|
|
|
|
2010-04-25 09:02:36 +00:00
|
|
|
#if !defined(ZEROGS_DEVBUILD)
|
2010-03-19 00:31:15 +00:00
|
|
|
#define g_bWriteProfile 0
|
|
|
|
#else
|
2010-05-01 23:34:44 +00:00
|
|
|
bool g_bWriteProfile = 0;
|
2010-03-19 00:31:15 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
int s_frameskipping = 0;
|
2010-05-01 20:33:53 +00:00
|
|
|
u32 CALLBACK PS2EgetLibType()
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
return PS2E_LT_GS;
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
char* CALLBACK PS2EgetLibName()
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
return libraryName;
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
u32 CALLBACK PS2EgetLibVersion2(u32 type)
|
|
|
|
{
|
|
|
|
return (zgsversion << 16) | (zgsrevision << 8) | zgsbuild | (zgsminor << 24);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static u64 luPerfFreq;
|
|
|
|
|
2010-03-19 05:24:36 +00:00
|
|
|
GLWindow GLWin;
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
HWND GShwnd = NULL;
|
2010-04-30 04:40:31 +00:00
|
|
|
#endif
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
u32 THR_KeyEvent = 0; // Value for key event processing between threads
|
2010-03-19 00:31:15 +00:00
|
|
|
bool THR_bShift = false;
|
|
|
|
|
2010-04-25 07:21:29 +00:00
|
|
|
namespace ZZLog
|
2010-04-02 05:53:14 +00:00
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
bool IsLogging()
|
|
|
|
{
|
|
|
|
// gsLog can be null if the config dialog is used prior to Pcsx2 starting an emulation session.
|
|
|
|
// (GSinit won't have been called then)
|
|
|
|
return (gsLog != NULL && conf.log);
|
|
|
|
}
|
2010-04-25 09:02:36 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
void WriteToScreen(const char* pstr, u32 ms)
|
|
|
|
{
|
|
|
|
ZeroGS::AddMessage(pstr, ms);
|
|
|
|
}
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
void _Message(const char *str)
|
|
|
|
{
|
|
|
|
SysMessage(str);
|
|
|
|
}
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
void _Log(const char *str)
|
|
|
|
{
|
|
|
|
if (IsLogging()) fprintf(gsLog, str);
|
|
|
|
}
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
void _WriteToConsole(const char *str)
|
|
|
|
{
|
|
|
|
printf("ZZogl-PG: %s", str);
|
|
|
|
}
|
2010-04-25 07:21:29 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
void _Print(const char *str)
|
|
|
|
{
|
|
|
|
printf("ZZogl-PG: %s", str);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (IsLogging()) fprintf(gsLog, str);
|
|
|
|
}
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
void Message(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
char tmp[512];
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
va_start(list, fmt);
|
|
|
|
vsprintf(tmp, fmt, list);
|
|
|
|
va_end(list);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
SysMessage(tmp);
|
|
|
|
}
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
void Log(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
2010-04-25 07:21:29 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
va_start(list, fmt);
|
|
|
|
|
|
|
|
if (IsLogging()) vfprintf(gsLog, fmt, list);
|
|
|
|
|
|
|
|
va_end(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WriteToConsole(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
|
|
|
|
printf("ZZogl-PG: ");
|
|
|
|
vprintf(fmt, list);
|
|
|
|
va_end(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Print(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
|
|
|
|
if (IsLogging()) vfprintf(gsLog, fmt, list);
|
|
|
|
|
|
|
|
printf("ZZogl-PG: ");
|
|
|
|
|
|
|
|
vprintf(fmt, list);
|
|
|
|
|
|
|
|
va_end(list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Greg_Log(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
// Not currently used
|
|
|
|
#if 0
|
|
|
|
va_list list;
|
|
|
|
char tmp[512];
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
|
|
|
|
if (IsLogging()) vfprintf(gsLog, fmt, list);
|
|
|
|
|
|
|
|
va_end(list);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void Prim_Log(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
#if defined(ZEROGS_DEVBUILD) && defined(WRITE_PRIM_LOGS)
|
|
|
|
va_list list;
|
|
|
|
char tmp[512];
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
2010-04-25 07:21:29 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (conf.log /*& 0x00000010*/)
|
|
|
|
{
|
2010-04-25 07:21:29 +00:00
|
|
|
if (IsLogging()) vfprintf(gsLog, fmt, list);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
printf("ZZogl-PG(PRIM): ");
|
|
|
|
|
2010-04-25 07:21:29 +00:00
|
|
|
vprintf(fmt, list);
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
va_end(list);
|
2010-04-25 07:21:29 +00:00
|
|
|
|
|
|
|
#endif
|
2010-05-01 20:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GS_Log(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
#ifdef ZEROGS_DEVBUILD
|
|
|
|
va_list list;
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
|
|
|
|
if (IsLogging())
|
2010-04-25 07:21:29 +00:00
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
vfprintf(gsLog, fmt, list);
|
|
|
|
fprintf(gsLog, "\n");
|
|
|
|
}
|
2010-04-25 07:21:29 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
printf("ZZogl-PG(GS): ");
|
|
|
|
|
|
|
|
vprintf(fmt, list);
|
|
|
|
printf("\n");
|
|
|
|
va_end(list);
|
2010-04-25 07:21:29 +00:00
|
|
|
#endif
|
2010-05-01 20:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Warn_Log(const char *fmt, ...)
|
|
|
|
{
|
2010-04-25 09:02:36 +00:00
|
|
|
#ifdef ZEROGS_DEVBUILD
|
2010-05-01 20:33:53 +00:00
|
|
|
va_list list;
|
2010-04-25 07:21:29 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
va_start(list, fmt);
|
|
|
|
|
|
|
|
if (IsLogging())
|
2010-04-25 07:21:29 +00:00
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
vfprintf(gsLog, fmt, list);
|
|
|
|
fprintf(gsLog, "\n");
|
|
|
|
}
|
2010-04-25 07:21:29 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
printf("ZZogl-PG(Warning): ");
|
|
|
|
|
|
|
|
vprintf(fmt, list);
|
|
|
|
va_end(list);
|
|
|
|
printf("\n");
|
2010-04-25 07:21:29 +00:00
|
|
|
#endif
|
2010-05-01 20:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Debug_Log(const char *fmt, ...)
|
|
|
|
{
|
2010-04-25 07:21:29 +00:00
|
|
|
#if _DEBUG
|
2010-05-01 20:33:53 +00:00
|
|
|
va_list list;
|
2010-04-25 07:21:29 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
va_start(list, fmt);
|
|
|
|
|
|
|
|
if (IsLogging())
|
2010-04-25 07:21:29 +00:00
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
vfprintf(gsLog, fmt, list);
|
|
|
|
fprintf(gsLog, "\n");
|
|
|
|
}
|
2010-04-25 07:21:29 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
printf("ZZogl-PG(Debug): ");
|
|
|
|
|
|
|
|
vprintf(fmt, list);
|
|
|
|
printf("\n");
|
|
|
|
va_end(list);
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void Error_Log(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
|
|
|
|
va_start(list, fmt);
|
|
|
|
|
|
|
|
if (IsLogging())
|
|
|
|
{
|
|
|
|
vfprintf(gsLog, fmt, list);
|
|
|
|
fprintf(gsLog, "\n");
|
2010-04-25 07:21:29 +00:00
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
printf("ZZogl-PG(Error): ");
|
|
|
|
|
|
|
|
vprintf(fmt, list);
|
|
|
|
printf("\n");
|
|
|
|
va_end(list);
|
|
|
|
}
|
2010-04-25 07:21:29 +00:00
|
|
|
};
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
void CALLBACK GSsetBaseMem(void* pmem)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
g_pBasePS2Mem = (u8*)pmem;
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
void CALLBACK GSsetSettingsDir(const char* dir)
|
|
|
|
{
|
|
|
|
s_strIniPath = (dir == NULL) ? "inis/" : dir;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extern int VALIDATE_THRESH;
|
|
|
|
extern u32 TEXDESTROY_THRESH;
|
2010-04-25 11:14:37 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
int g_LastCRC = 0;
|
2010-04-25 11:14:37 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
void CALLBACK GSsetGameCRC(int crc, int options)
|
|
|
|
{
|
2010-04-25 11:14:37 +00:00
|
|
|
// TEXDESTROY_THRESH starts out at 16.
|
2010-03-19 00:31:15 +00:00
|
|
|
VALIDATE_THRESH = 8;
|
2010-03-19 04:36:28 +00:00
|
|
|
conf.mrtdepth = ((conf.gamesettings & GAME_DISABLEMRTDEPTH) != 0);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
if (!conf.mrtdepth)
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("Disabling MRT depth writing.");
|
2010-04-25 00:31:27 +00:00
|
|
|
else
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("Enabling MRT depth writing.");
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
g_GameSettings |= GAME_PATH3HACK;
|
|
|
|
|
2010-04-25 11:14:37 +00:00
|
|
|
bool CRCValueChanged = (g_LastCRC != crc);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
g_LastCRC = crc;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 11:14:37 +00:00
|
|
|
ZZLog::Error_Log("CRC = %x", crc);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (CRCValueChanged && (crc != 0))
|
2010-04-25 11:14:37 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < GAME_INFO_INDEX; i++)
|
|
|
|
{
|
|
|
|
if (crc_game_list[i].crc == crc)
|
|
|
|
{
|
|
|
|
if (crc_game_list[i].v_thresh > 0) VALIDATE_THRESH = crc_game_list[i].v_thresh;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 11:14:37 +00:00
|
|
|
if (crc_game_list[i].t_thresh > 0) TEXDESTROY_THRESH = crc_game_list[i].t_thresh;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 11:14:37 +00:00
|
|
|
conf.gamesettings |= crc_game_list[i].flags;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 11:14:37 +00:00
|
|
|
g_GameSettings = conf.gamesettings | options;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 11:14:37 +00:00
|
|
|
ZZLog::Error_Log("Found CRC[%x] in crc game list.", crc);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 11:14:37 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
g_GameSettings = conf.gamesettings | options;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CALLBACK GSsetFrameSkip(int frameskip)
|
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
s_frameskipping |= frameskip;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (frameskip && g_nFrameRender > 1)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 16; ++i)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
g_GIFPackedRegHandlers[i] = GIFPackedRegHandlerNOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
// still keep certain handlers
|
|
|
|
g_GIFPackedRegHandlers[6] = GIFRegHandlerTEX0_1;
|
|
|
|
g_GIFPackedRegHandlers[7] = GIFRegHandlerTEX0_2;
|
|
|
|
g_GIFPackedRegHandlers[14] = GIFPackedRegHandlerA_D;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
g_GIFRegHandlers[0] = GIFRegHandlerNOP;
|
|
|
|
g_GIFRegHandlers[1] = GIFRegHandlerNOP;
|
|
|
|
g_GIFRegHandlers[2] = GIFRegHandlerNOP;
|
|
|
|
g_GIFRegHandlers[3] = GIFRegHandlerNOP;
|
|
|
|
g_GIFRegHandlers[4] = GIFRegHandlerNOP;
|
|
|
|
g_GIFRegHandlers[5] = GIFRegHandlerNOP;
|
|
|
|
g_GIFRegHandlers[12] = GIFRegHandlerNOP;
|
|
|
|
g_GIFRegHandlers[13] = GIFRegHandlerNOP;
|
|
|
|
g_GIFRegHandlers[26] = GIFRegHandlerNOP;
|
|
|
|
g_GIFRegHandlers[27] = GIFRegHandlerNOP;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
g_nFrameRender = 0;
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
else if (!frameskip && g_nFrameRender <= 0)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
g_nFrameRender = 1;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (g_GIFTempRegHandlers[0] == NULL) return; // not init yet
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
// restore
|
|
|
|
memcpy(g_GIFPackedRegHandlers, g_GIFTempRegHandlers, sizeof(g_GIFTempRegHandlers));
|
|
|
|
|
|
|
|
g_GIFRegHandlers[0] = GIFRegHandlerPRIM;
|
|
|
|
g_GIFRegHandlers[1] = GIFRegHandlerRGBAQ;
|
|
|
|
g_GIFRegHandlers[2] = GIFRegHandlerST;
|
|
|
|
g_GIFRegHandlers[3] = GIFRegHandlerUV;
|
|
|
|
g_GIFRegHandlers[4] = GIFRegHandlerXYZF2;
|
|
|
|
g_GIFRegHandlers[5] = GIFRegHandlerXYZ2;
|
|
|
|
g_GIFRegHandlers[12] = GIFRegHandlerXYZF3;
|
|
|
|
g_GIFRegHandlers[13] = GIFRegHandlerXYZ2;
|
|
|
|
g_GIFRegHandlers[26] = GIFRegHandlerPRMODECONT;
|
|
|
|
g_GIFRegHandlers[27] = GIFRegHandlerPRMODE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
void CALLBACK GSreset()
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
FUNCLOG
|
|
|
|
|
|
|
|
memset(&gs, 0, sizeof(gs));
|
|
|
|
|
|
|
|
ZeroGS::GSStateReset();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
gs.prac = 1;
|
|
|
|
prim = &gs._prim[0];
|
|
|
|
gs.nTriFanVert = -1;
|
|
|
|
gs.imageTransfer = -1;
|
|
|
|
gs.q = 1;
|
|
|
|
}
|
|
|
|
|
2010-04-02 02:44:14 +00:00
|
|
|
void CALLBACK GSgifSoftReset(u32 mask)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
FUNCLOG
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (mask & 1) memset(&gs.path[0], 0, sizeof(gs.path[0]));
|
|
|
|
if (mask & 2) memset(&gs.path[1], 0, sizeof(gs.path[1]));
|
|
|
|
if (mask & 4) memset(&gs.path[2], 0, sizeof(gs.path[2]));
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
gs.imageTransfer = -1;
|
|
|
|
gs.q = 1;
|
|
|
|
gs.nTriFanVert = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 CALLBACK GSinit()
|
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
|
|
|
|
memcpy(g_GIFTempRegHandlers, g_GIFPackedRegHandlers, sizeof(g_GIFTempRegHandlers));
|
|
|
|
|
|
|
|
gsLog = fopen("logs/gsLog.txt", "w");
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (gsLog == NULL)
|
2010-04-25 08:33:05 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
gsLog = fopen("gsLog.txt", "w");
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (gsLog == NULL)
|
2010-04-25 08:33:05 +00:00
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
SysMessage("Can't create gsLog.txt");
|
2010-04-25 08:33:05 +00:00
|
|
|
return -1;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
setvbuf(gsLog, NULL, _IONBF, 0);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::GS_Log("Calling GSinit.");
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
GSreset();
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::GS_Log("GSinit finished.");
|
2010-03-19 00:31:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CALLBACK GSshutdown()
|
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
|
2010-04-25 08:33:05 +00:00
|
|
|
if (gsLog != NULL) fclose(gsLog);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// keyboard functions
|
|
|
|
void OnKeyboardF5(int shift)
|
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
|
|
|
|
char strtitle[256];
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (shift)
|
|
|
|
{
|
|
|
|
if (g_nPixelShaderVer == SHADER_REDUCED)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
conf.bilinear = 0;
|
|
|
|
sprintf(strtitle, "reduced shaders don't support bilinear filtering");
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
conf.bilinear = (conf.bilinear + 1) % 3;
|
2010-03-19 00:31:15 +00:00
|
|
|
sprintf(strtitle, "bilinear filtering - %s", pbilinear[conf.bilinear]);
|
|
|
|
}
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
else
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
conf.interlace++;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (conf.interlace > 2) conf.interlace = 0;
|
|
|
|
|
|
|
|
if (conf.interlace < 2)
|
|
|
|
sprintf(strtitle, "interlace on - mode %d", conf.interlace);
|
|
|
|
else
|
|
|
|
sprintf(strtitle, "interlace off");
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
ZeroGS::AddMessage(strtitle);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
SaveConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnKeyboardF6(int shift)
|
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
|
|
|
|
char strtitle[256];
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (shift)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
conf.aa--; // -1
|
2010-05-01 20:33:53 +00:00
|
|
|
if (conf.aa > 4) conf.aa = 4; // u8 in unsigned, so negative value is 255.
|
2010-03-19 00:31:15 +00:00
|
|
|
sprintf(strtitle, "anti-aliasing - %s", s_aa[conf.aa]);
|
|
|
|
ZeroGS::SetAA(conf.aa);
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
else
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
conf.aa++;
|
2010-05-01 20:33:53 +00:00
|
|
|
if (conf.aa > 4) conf.aa = 0;
|
2010-03-19 00:31:15 +00:00
|
|
|
sprintf(strtitle, "anti-aliasing - %s", s_aa[conf.aa]);
|
|
|
|
ZeroGS::SetAA(conf.aa);
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
ZeroGS::AddMessage(strtitle);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
SaveConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnKeyboardF7(int shift)
|
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
|
|
|
|
char strtitle[256];
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (!shift)
|
|
|
|
{
|
2010-05-01 23:34:44 +00:00
|
|
|
extern bool g_bDisplayFPS;
|
2010-03-19 00:31:15 +00:00
|
|
|
g_bDisplayFPS ^= 1;
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
else
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
conf.options ^= GSOPTION_WIREFRAME;
|
2010-05-01 20:33:53 +00:00
|
|
|
glPolygonMode(GL_FRONT_AND_BACK, (conf.options&GSOPTION_WIREFRAME) ? GL_LINE : GL_FILL);
|
|
|
|
sprintf(strtitle, "wireframe rendering - %s", (conf.options&GSOPTION_WIREFRAME) ? "on" : "off");
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
void OnKeyboardF61(int shift)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
FUNCLOG
|
|
|
|
|
|
|
|
char strtitle[256];
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (shift)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
conf.negaa--; // -1
|
2010-05-01 20:33:53 +00:00
|
|
|
if (conf.negaa > 2) conf.negaa = 2; // u8 in unsigned, so negative value is 255.
|
2010-03-19 00:31:15 +00:00
|
|
|
sprintf(strtitle, "down resolution - %s", s_naa[conf.negaa]);
|
|
|
|
ZeroGS::SetNegAA(conf.negaa);
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
else
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
conf.negaa++;
|
2010-05-01 20:33:53 +00:00
|
|
|
if (conf.negaa > 2) conf.negaa = 0;
|
2010-03-19 00:31:15 +00:00
|
|
|
sprintf(strtitle, "down resolution - %s", s_naa[conf.negaa]);
|
|
|
|
ZeroGS::SetNegAA(conf.negaa);
|
|
|
|
}
|
|
|
|
|
|
|
|
ZeroGS::AddMessage(strtitle);
|
|
|
|
SaveConfig();
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
typedef struct GameHackStruct
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
const char HackName[40];
|
|
|
|
u32 HackMask;
|
|
|
|
} GameHack;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
#define HACK_NUMBER 30
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
GameHack HackinshTable[HACK_NUMBER] =
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
{"*** 0 No Hack", 0},
|
|
|
|
{"*** 1 TexTargets Check", GAME_TEXTURETARGS},
|
|
|
|
{"*** 2 Autoreset Targets", GAME_AUTORESET},
|
|
|
|
{"*** 3 Interlace 2x", GAME_INTERLACE2X},
|
|
|
|
{"*** 4 TexA hack", GAME_TEXAHACK},
|
|
|
|
{"*** 5 No Target Resolve", GAME_NOTARGETRESOLVE},
|
|
|
|
{"*** 6 Exact color", GAME_EXACTCOLOR},
|
|
|
|
{"*** 7 No color clamp", GAME_NOCOLORCLAMP},
|
|
|
|
{"*** 8 FFX hack", GAME_FFXHACK},
|
|
|
|
{"*** 9 No Alpha Fail", GAME_NOALPHAFAIL},
|
|
|
|
{"***10 No Depth Update", GAME_NODEPTHUPDATE},
|
|
|
|
{"***11 Quick Resolve 1", GAME_QUICKRESOLVE1},
|
|
|
|
{"***12 No quick resolve", GAME_NOQUICKRESOLVE},
|
|
|
|
{"***13 Notaget clut", GAME_NOTARGETCLUT},
|
|
|
|
{"***14 No Stencil", GAME_NOSTENCIL},
|
|
|
|
{"***15 No Depth resolve", GAME_NODEPTHRESOLVE},
|
|
|
|
{"***16 Full 16 bit", GAME_FULL16BITRES},
|
2010-05-01 20:33:53 +00:00
|
|
|
{"***17 Resolve promoted", GAME_RESOLVEPROMOTED},
|
2010-03-19 00:31:15 +00:00
|
|
|
{"***18 Fast Update", GAME_FASTUPDATE},
|
2010-03-19 05:24:36 +00:00
|
|
|
{"***19 No Alpha Test", GAME_NOALPHATEST},
|
2010-03-19 00:31:15 +00:00
|
|
|
{"***20 Disable MRT deprh", GAME_DISABLEMRTDEPTH},
|
|
|
|
{"***21 32 bit targes", GAME_32BITTARGS},
|
|
|
|
{"***22 path 3 hack", GAME_PATH3HACK},
|
|
|
|
{"***23 parallelise calls", GAME_DOPARALLELCTX},
|
|
|
|
{"***24 specular highligths", GAME_XENOSPECHACK},
|
|
|
|
{"***25 partial pointers", GAME_PARTIALPOINTERS},
|
|
|
|
{"***26 partial depth", GAME_PARTIALDEPTH},
|
|
|
|
{"***27 reget hack", GAME_REGETHACK},
|
2010-03-27 01:01:31 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
{"***28 gust hack", GAME_GUSTHACK},
|
|
|
|
{"***29 log-Z", GAME_NOLOGZ}
|
|
|
|
};
|
|
|
|
|
|
|
|
int CurrentHackSetting = 0;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
void OnKeyboardF9(int shift)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
FUNCLOG
|
|
|
|
|
|
|
|
// printf ("A %d\n", HackinshTable[CurrentHackSetting].HackMask);
|
|
|
|
conf.gamesettings &= !(HackinshTable[CurrentHackSetting].HackMask);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (shift)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
CurrentHackSetting--;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (CurrentHackSetting == -1) CurrentHackSetting = HACK_NUMBER - 1;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
else
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
CurrentHackSetting++;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (CurrentHackSetting == HACK_NUMBER) CurrentHackSetting = 0;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
conf.gamesettings |= HackinshTable[CurrentHackSetting].HackMask;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
g_GameSettings = conf.gamesettings;
|
|
|
|
ZeroGS::AddMessage(HackinshTable[CurrentHackSetting].HackName);
|
|
|
|
SaveConfig();
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
void OnKeyboardF1(int shift)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
FUNCLOG
|
|
|
|
char strtitle[256];
|
|
|
|
sprintf(strtitle, "Saving in savestate %d", CurrentSavestate);
|
|
|
|
SaveStateExists = true;
|
|
|
|
ZeroGS::AddMessage(HackinshTable[CurrentHackSetting].HackName);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
HANDLE g_hCurrentThread = NULL;
|
|
|
|
#endif
|
|
|
|
|
2010-04-30 04:40:31 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
extern LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
2010-03-19 00:31:15 +00:00
|
|
|
extern HINSTANCE hInst;
|
2010-04-30 04:40:31 +00:00
|
|
|
#endif
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
s32 CALLBACK GSopen(void *pDsp, char *Title, int multithread)
|
2010-03-19 05:24:36 +00:00
|
|
|
{
|
2010-04-30 04:40:31 +00:00
|
|
|
FUNCLOG
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 05:24:36 +00:00
|
|
|
bool err;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
g_GSMultiThreaded = multithread;
|
|
|
|
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::GS_Log("Calling GSopen.");
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-04-30 04:40:31 +00:00
|
|
|
#ifdef _WIN32
|
2010-03-19 00:31:15 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
g_hCurrentThread = GetCurrentThread();
|
|
|
|
#endif
|
2010-04-30 04:40:31 +00:00
|
|
|
#endif
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
LoadConfig();
|
2010-03-19 00:31:15 +00:00
|
|
|
strcpy(GStitle, Title);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-29 21:15:49 +00:00
|
|
|
err = GLWin.CreateWindow(pDsp);
|
2010-04-25 00:31:27 +00:00
|
|
|
if (!err)
|
2010-03-19 05:24:36 +00:00
|
|
|
{
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::GS_Log("Failed to create window. Exiting...");
|
2010-03-19 00:31:15 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Error_Log("Using %s:%d.%d.%d.", libraryName, zgsrevision, zgsbuild, zgsminor);
|
2010-04-30 04:40:31 +00:00
|
|
|
ZZLog::Error_Log("Creating ZZOgl window.");
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-02 02:44:14 +00:00
|
|
|
if (!ZeroGS::Create(conf.width, conf.height)) return -1;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-04-30 04:40:31 +00:00
|
|
|
ZZLog::Error_Log("Initialization successful.");
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
switch (conf.bilinear)
|
2010-04-02 02:44:14 +00:00
|
|
|
{
|
2010-04-30 04:40:31 +00:00
|
|
|
case 2:
|
|
|
|
ZeroGS::AddMessage("bilinear filtering - forced", 1000);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
ZeroGS::AddMessage("bilinear filtering - normal", 1000);
|
|
|
|
break;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-04-30 04:40:31 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-30 04:40:31 +00:00
|
|
|
if (conf.aa)
|
2010-04-02 02:44:14 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
char strtitle[64];
|
2010-04-30 04:40:31 +00:00
|
|
|
sprintf(strtitle, "anti-aliasing - %s", s_aa[conf.aa]);
|
2010-05-01 20:33:53 +00:00
|
|
|
ZeroGS::AddMessage(strtitle, 1000);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2010-04-30 04:40:31 +00:00
|
|
|
luPerfFreq = GetCPUTicks();
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-02 02:44:14 +00:00
|
|
|
gs.path[0].mode = gs.path[1].mode = gs.path[2].mode = 0;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-30 04:40:31 +00:00
|
|
|
ZZLog::GS_Log("GSopen finished.");
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-04-30 04:40:31 +00:00
|
|
|
#ifdef _WIN32
|
2010-03-19 00:31:15 +00:00
|
|
|
void ProcessMessages()
|
|
|
|
{
|
2010-04-25 00:31:27 +00:00
|
|
|
MSG msg;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
ZeroMemory(&msg, sizeof(msg));
|
|
|
|
|
|
|
|
while (1)
|
2010-04-02 02:44:14 +00:00
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
|
2010-03-19 00:31:15 +00:00
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
switch (msg.message)
|
2010-04-02 02:44:14 +00:00
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
case WM_KEYDOWN :
|
2010-04-30 04:40:31 +00:00
|
|
|
int my_KeyEvent = msg.wParam;
|
|
|
|
bool my_bShift = !!(GetKeyState(VK_SHIFT) & 0x8000);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-30 04:40:31 +00:00
|
|
|
switch (msg.wParam)
|
2010-04-02 02:44:14 +00:00
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-30 04:40:31 +00:00
|
|
|
case VK_F5:
|
|
|
|
OnKeyboardF5(my_bShift);
|
|
|
|
break;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-30 04:40:31 +00:00
|
|
|
case VK_F6:
|
|
|
|
OnKeyboardF6(my_bShift);
|
|
|
|
break;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-30 04:40:31 +00:00
|
|
|
case VK_F7:
|
|
|
|
OnKeyboardF7(my_bShift);
|
|
|
|
break;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-30 04:40:31 +00:00
|
|
|
case VK_F9:
|
|
|
|
OnKeyboardF9(my_bShift);
|
|
|
|
break;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-30 04:40:31 +00:00
|
|
|
case VK_ESCAPE:
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (conf.options & GSOPTION_FULLSCREEN)
|
2010-04-30 04:40:31 +00:00
|
|
|
{
|
|
|
|
// destroy that msg
|
|
|
|
conf.options &= ~GSOPTION_FULLSCREEN;
|
|
|
|
ZeroGS::ChangeDeviceSize(conf.width, conf.height);
|
|
|
|
UpdateWindow(GShwnd);
|
|
|
|
continue; // so that msg doesn't get sent
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
else
|
2010-04-30 04:40:31 +00:00
|
|
|
{
|
|
|
|
SendMessage(GShwnd, WM_DESTROY, 0, 0);
|
|
|
|
//g_bHidden = 1;
|
|
|
|
return;
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-30 04:40:31 +00:00
|
|
|
break;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
else
|
2010-04-02 02:44:14 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
break;
|
2010-04-02 02:44:14 +00:00
|
|
|
}
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2010-04-30 04:40:31 +00:00
|
|
|
if ((GetKeyState(VK_MENU) & 0x8000) && (GetKeyState(VK_RETURN) & 0x8000))
|
2010-04-02 02:44:14 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
conf.options ^= GSOPTION_FULLSCREEN;
|
|
|
|
|
|
|
|
ZeroGS::SetChangeDeviceSize(
|
|
|
|
(conf.options&GSOPTION_FULLSCREEN) ? 1280 : conf.width,
|
|
|
|
(conf.options&GSOPTION_FULLSCREEN) ? 960 : conf.height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else // linux
|
|
|
|
|
|
|
|
void ProcessMessages()
|
|
|
|
{
|
|
|
|
FUNCLOG
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// check resizing
|
2010-03-19 02:04:55 +00:00
|
|
|
GLWin.ResizeCheck();
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (THR_KeyEvent) // This values was passed from GSKeyEvents which could be in another thread
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
int my_KeyEvent = THR_KeyEvent;
|
|
|
|
bool my_bShift = THR_bShift;
|
|
|
|
THR_KeyEvent = 0;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
switch (my_KeyEvent)
|
|
|
|
{
|
|
|
|
case XK_F5:
|
|
|
|
OnKeyboardF5(my_bShift);
|
2010-03-19 00:31:15 +00:00
|
|
|
break;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
case XK_F6:
|
|
|
|
OnKeyboardF6(my_bShift);
|
|
|
|
break;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
case XK_F7:
|
|
|
|
OnKeyboardF7(my_bShift);
|
2010-04-25 00:31:27 +00:00
|
|
|
break;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
case XK_F9:
|
|
|
|
OnKeyboardF9(my_bShift);
|
|
|
|
break;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
}
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // linux
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
void CALLBACK GSclose()
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
FUNCLOG
|
|
|
|
|
|
|
|
ZeroGS::Destroy(1);
|
|
|
|
|
2010-03-19 02:04:55 +00:00
|
|
|
GLWin.CloseWindow();
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
SaveStateFile = NULL;
|
|
|
|
SaveStateExists = true; // default value
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
void CALLBACK GSirqCallback(void (*callback)())
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
FUNCLOG
|
|
|
|
|
|
|
|
GSirq = callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CALLBACK GSwriteCSR(u32 write)
|
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
|
|
|
|
gs.CSRw = write;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CALLBACK GSchangeSaveState(int newstate, const char* filename)
|
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
|
|
|
|
char str[255];
|
|
|
|
sprintf(str, "save state %d", newstate);
|
|
|
|
ZeroGS::AddMessage(str);
|
|
|
|
CurrentSavestate = newstate;
|
|
|
|
|
|
|
|
SaveStateFile = filename;
|
|
|
|
SaveStateExists = (access(SaveStateFile, 0) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CALLBACK GSmakeSnapshot(char *path)
|
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
|
|
|
|
FILE *bmpfile;
|
2010-04-25 00:31:27 +00:00
|
|
|
char filename[256];
|
2010-03-19 00:31:15 +00:00
|
|
|
u32 snapshotnr = 0;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// increment snapshot value & try to get filename
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
snapshotnr++;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
sprintf(filename, "%ssnap%03ld.%s", path, snapshotnr, (conf.options&GSOPTION_TGASNAP) ? "bmp" : "jpg");
|
|
|
|
|
|
|
|
bmpfile = fopen(filename, "rb");
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
if (bmpfile == NULL) break;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
fclose(bmpfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
// try opening new snapshot file
|
2010-05-01 20:33:53 +00:00
|
|
|
if ((bmpfile = fopen(filename, "wb")) == NULL)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
char strdir[255];
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
sprintf(strdir, "%s", path);
|
|
|
|
CreateDirectory(strdir, NULL);
|
|
|
|
#else
|
|
|
|
sprintf(strdir, "mkdir %s", path);
|
|
|
|
system(strdir);
|
|
|
|
#endif
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if ((bmpfile = fopen(filename, "wb")) == NULL) return;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose(bmpfile);
|
|
|
|
|
|
|
|
// get the bits
|
|
|
|
ZeroGS::SaveSnapshot(filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
int UPDATE_FRAMES = 16;
|
|
|
|
int g_nFrame = 0;
|
|
|
|
int g_nRealFrame = 0;
|
|
|
|
|
|
|
|
float fFPS = 0;
|
|
|
|
|
|
|
|
void CALLBACK GSvsync(int interlace)
|
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
|
2010-04-25 08:33:05 +00:00
|
|
|
//ZZLog::GS_Log("Calling GSvsync.");
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
static u32 dwTime = timeGetTime();
|
|
|
|
static int nToNextUpdate = 1;
|
|
|
|
char strtitle[256];
|
|
|
|
|
|
|
|
GL_REPORT_ERRORD();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
g_nRealFrame++;
|
|
|
|
|
|
|
|
ZeroGS::RenderCRTC(!interlace);
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
ProcessMessages();
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (--nToNextUpdate <= 0)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
u32 d = timeGetTime();
|
2010-05-01 20:33:53 +00:00
|
|
|
fFPS = UPDATE_FRAMES * 1000.0f / (float)max(d - dwTime, 1);
|
2010-03-19 00:31:15 +00:00
|
|
|
dwTime = d;
|
|
|
|
g_nFrame += UPDATE_FRAMES;
|
|
|
|
|
2010-04-25 09:02:36 +00:00
|
|
|
#if !defined(ZEROGS_DEVBUILD)
|
2010-03-19 00:31:15 +00:00
|
|
|
const char* g_pShaders[4] = { "full", "reduced", "accurate", "accurate-reduced" };
|
|
|
|
const char* g_pInterlace[3] = { "interlace 0 |", "interlace 1 |", "" };
|
|
|
|
const char* g_pBilinear[3] = { "", "bilinear |", "forced bilinear |" };
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
if (SaveStateFile != NULL && !SaveStateExists)
|
|
|
|
SaveStateExists = (access(SaveStateFile, 0) == 0);
|
|
|
|
else
|
|
|
|
SaveStateExists = true;
|
|
|
|
|
|
|
|
sprintf(strtitle, "ZZ Open GL 0.%d.%d | %.1f fps | %s%s%s savestate %d%s | shaders %s | (%.1f)", zgsbuild, zgsminor, fFPS,
|
2010-05-01 20:33:53 +00:00
|
|
|
g_pInterlace[conf.interlace], g_pBilinear[conf.bilinear],
|
|
|
|
(conf.aa >= conf.negaa) ? (conf.aa ? s_aa[conf.aa - conf.negaa] : "") : (conf.negaa ? s_naa[conf.negaa - conf.aa] : ""),
|
|
|
|
CurrentSavestate, (SaveStateExists ? "" : "*"),
|
|
|
|
g_pShaders[g_nPixelShaderVer], (ppf&0xfffff) / (float)UPDATE_FRAMES);
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
#else
|
2010-04-25 00:31:27 +00:00
|
|
|
sprintf(strtitle, "%d | %.1f fps (sk:%d%%) | g: %.1f, t: %.1f, a: %.1f, r: %.1f | p: %.1f | tex: %d %d (%d kbpf)", g_nFrame, fFPS,
|
2010-05-01 20:33:53 +00:00
|
|
|
100*g_nFramesSkipped / g_nFrame,
|
|
|
|
g_nGenVars / (float)UPDATE_FRAMES, g_nTexVars / (float)UPDATE_FRAMES, g_nAlphaVars / (float)UPDATE_FRAMES,
|
|
|
|
g_nResolve / (float)UPDATE_FRAMES, (ppf&0xfffff) / (float)UPDATE_FRAMES,
|
|
|
|
ZeroGS::g_MemTargs.listTargets.size(), ZeroGS::g_MemTargs.listClearedTargets.size(), g_TransferredToGPU >> 10);
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
//_snprintf(strtitle, 512, "%x %x", *(int*)(g_pbyGSMemory + 256 * 0x3e0c + 4), *(int*)(g_pbyGSMemory + 256 * 0x3e04 + 4));
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// if( g_nFrame > 100 && fFPS > 60.0f ) {
|
2010-04-25 08:33:05 +00:00
|
|
|
// ZZLog::Debug_Log("Set profile.");
|
2010-03-19 00:31:15 +00:00
|
|
|
// g_bWriteProfile = 1;
|
|
|
|
// }
|
2010-03-19 05:24:36 +00:00
|
|
|
if (!(conf.options & GSOPTION_FULLSCREEN)) GLWin.SetTitle(strtitle);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (fFPS < 16) UPDATE_FRAMES = 4;
|
|
|
|
else if (fFPS < 32) UPDATE_FRAMES = 8;
|
2010-03-19 00:31:15 +00:00
|
|
|
else UPDATE_FRAMES = 16;
|
|
|
|
|
|
|
|
nToNextUpdate = UPDATE_FRAMES;
|
|
|
|
|
|
|
|
g_TransferredToGPU = 0;
|
|
|
|
g_nGenVars = 0;
|
|
|
|
g_nTexVars = 0;
|
|
|
|
g_nAlphaVars = 0;
|
|
|
|
g_nResolve = 0;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
ppf = 0;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
g_nFramesSkipped = 0;
|
|
|
|
}
|
|
|
|
|
2010-04-25 09:02:36 +00:00
|
|
|
#if defined(ZEROGS_DEVBUILD)
|
2010-05-01 20:33:53 +00:00
|
|
|
if (g_bWriteProfile)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
//g_bWriteProfile = 0;
|
|
|
|
DVProfWrite("prof.txt", UPDATE_FRAMES);
|
|
|
|
DVProfClear();
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
#endif
|
|
|
|
GL_REPORT_ERRORD();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CALLBACK GSreadFIFO(u64 *pMem)
|
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
|
2010-04-25 08:33:05 +00:00
|
|
|
//ZZLog::GS_Log("Calling GSreadFIFO.");
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
ZeroGS::TransferLocalHost((u32*)pMem, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CALLBACK GSreadFIFO2(u64 *pMem, int qwc)
|
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
|
2010-04-25 08:33:05 +00:00
|
|
|
//ZZLog::GS_Log("Calling GSreadFIFO2.");
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
ZeroGS::TransferLocalHost((u32*)pMem, qwc);
|
|
|
|
}
|
|
|
|
|
|
|
|
int CALLBACK GSsetupRecording(int start, void* pData)
|
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (start)
|
|
|
|
{
|
|
|
|
if (conf.options & GSOPTION_CAPTUREAVI) return 1;
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
ZeroGS::StartCapture();
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
conf.options |= GSOPTION_CAPTUREAVI;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Warn_Log("Started recording zerogs.avi.");
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!(conf.options & GSOPTION_CAPTUREAVI)) return 1;
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
conf.options &= ~GSOPTION_CAPTUREAVI;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
ZeroGS::StopCapture();
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-04-25 08:33:05 +00:00
|
|
|
ZZLog::Warn_Log("Stopped recording.");
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
s32 CALLBACK GSfreeze(int mode, freezeData *data)
|
2010-03-19 00:31:15 +00:00
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case FREEZE_LOAD:
|
2010-04-25 08:33:05 +00:00
|
|
|
if (!ZeroGS::Load(data->data)) ZZLog::Error_Log("GS: Bad load format!");
|
2010-03-19 00:31:15 +00:00
|
|
|
g_nRealFrame += 100;
|
|
|
|
break;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
case FREEZE_SAVE:
|
|
|
|
ZeroGS::Save(data->data);
|
|
|
|
break;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
case FREEZE_SIZE:
|
|
|
|
data->size = ZeroGS::Save(NULL);
|
|
|
|
break;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////
|
|
|
|
// Small profiler //
|
|
|
|
////////////////////
|
|
|
|
#include <list>
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2010-04-30 04:40:31 +00:00
|
|
|
#define GET_PROFILE_TIME() GetCPUTicks()
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
struct DVPROFSTRUCT;
|
|
|
|
|
|
|
|
struct DVPROFSTRUCT
|
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
struct DATA
|
|
|
|
{
|
|
|
|
DATA(u64 time, u32 user = 0) : dwTime(time), dwUserData(user) {}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
DATA() : dwTime(0), dwUserData(0) {}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
u64 dwTime;
|
|
|
|
u32 dwUserData;
|
|
|
|
};
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
~DVPROFSTRUCT()
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
list<DVPROFSTRUCT*>::iterator it = listpChild.begin();
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
while (it != listpChild.end())
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
SAFE_DELETE(*it);
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
list<DATA> listTimes; // before DVProfEnd is called, contains the global time it started
|
2010-05-01 20:33:53 +00:00
|
|
|
// after DVProfEnd is called, contains the time it lasted
|
|
|
|
// the list contains all the tracked times
|
2010-03-19 00:31:15 +00:00
|
|
|
char pname[256];
|
|
|
|
|
|
|
|
list<DVPROFSTRUCT*> listpChild; // other profilers called during this profiler period
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DVPROFTRACK
|
|
|
|
{
|
|
|
|
u32 dwUserData;
|
|
|
|
DVPROFSTRUCT::DATA* pdwTime;
|
|
|
|
DVPROFSTRUCT* pprof;
|
|
|
|
};
|
|
|
|
|
|
|
|
list<DVPROFTRACK> g_listCurTracking; // the current profiling functions, the back element is the
|
2010-05-01 20:33:53 +00:00
|
|
|
// one that will first get popped off the list when DVProfEnd is called
|
|
|
|
// the pointer is an element in DVPROFSTRUCT::listTimes
|
2010-03-19 00:31:15 +00:00
|
|
|
list<DVPROFSTRUCT> g_listProfilers; // the current profilers, note that these are the parents
|
2010-05-01 20:33:53 +00:00
|
|
|
// any profiler started during the time of another is held in
|
|
|
|
// DVPROFSTRUCT::listpChild
|
2010-03-19 00:31:15 +00:00
|
|
|
list<DVPROFSTRUCT*> g_listAllProfilers; // ignores the hierarchy, pointer to elements in g_listProfilers
|
|
|
|
|
|
|
|
void DVProfRegister(char* pname)
|
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
if (!g_bWriteProfile)
|
2010-03-19 00:31:15 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
list<DVPROFSTRUCT*>::iterator it = g_listAllProfilers.begin();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// while(it != g_listAllProfilers.end() ) {
|
|
|
|
//
|
|
|
|
// if( _tcscmp(pname, (*it)->pname) == 0 ) {
|
|
|
|
// (*it)->listTimes.push_back(timeGetTime());
|
|
|
|
// DVPROFTRACK dvtrack;
|
|
|
|
// dvtrack.pdwTime = &(*it)->listTimes.back();
|
|
|
|
// dvtrack.pprof = *it;
|
|
|
|
// g_listCurTracking.push_back(dvtrack);
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// ++it;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// else add in a new profiler to the appropriate parent profiler
|
|
|
|
DVPROFSTRUCT* pprof = NULL;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (g_listCurTracking.size() > 0)
|
|
|
|
{
|
|
|
|
assert(g_listCurTracking.back().pprof != NULL);
|
2010-03-19 00:31:15 +00:00
|
|
|
g_listCurTracking.back().pprof->listpChild.push_back(new DVPROFSTRUCT());
|
|
|
|
pprof = g_listCurTracking.back().pprof->listpChild.back();
|
|
|
|
}
|
2010-05-01 20:33:53 +00:00
|
|
|
else
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
g_listProfilers.push_back(DVPROFSTRUCT());
|
|
|
|
pprof = &g_listProfilers.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
strncpy(pprof->pname, pname, 256);
|
|
|
|
|
|
|
|
// setup the profiler for tracking
|
|
|
|
pprof->listTimes.push_back(DVPROFSTRUCT::DATA(GET_PROFILE_TIME()));
|
|
|
|
|
|
|
|
DVPROFTRACK dvtrack;
|
|
|
|
dvtrack.pdwTime = &pprof->listTimes.back();
|
|
|
|
dvtrack.pprof = pprof;
|
|
|
|
dvtrack.dwUserData = 0;
|
|
|
|
|
|
|
|
g_listCurTracking.push_back(dvtrack);
|
|
|
|
|
|
|
|
// add to all profiler list
|
|
|
|
g_listAllProfilers.push_back(pprof);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DVProfEnd(u32 dwUserData)
|
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
if (!g_bWriteProfile)
|
2010-03-19 00:31:15 +00:00
|
|
|
return;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
B_RETURN(g_listCurTracking.size() > 0);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
DVPROFTRACK dvtrack = g_listCurTracking.back();
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
assert(dvtrack.pdwTime != NULL && dvtrack.pprof != NULL);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
dvtrack.pdwTime->dwTime = 1000000 * (GET_PROFILE_TIME() - dvtrack.pdwTime->dwTime) / luPerfFreq;
|
|
|
|
|
|
|
|
dvtrack.pdwTime->dwUserData = dwUserData;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
g_listCurTracking.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
struct DVTIMEINFO
|
|
|
|
{
|
|
|
|
DVTIMEINFO() : uInclusive(0), uExclusive(0) {}
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
u64 uInclusive, uExclusive;
|
|
|
|
};
|
|
|
|
|
|
|
|
map<string, DVTIMEINFO> mapAggregateTimes;
|
|
|
|
|
|
|
|
u64 DVProfWriteStruct(FILE* f, DVPROFSTRUCT* p, int ident)
|
|
|
|
{
|
|
|
|
fprintf(f, "%*s%s - ", ident, "", p->pname);
|
|
|
|
|
|
|
|
list<DVPROFSTRUCT::DATA>::iterator ittime = p->listTimes.begin();
|
|
|
|
|
|
|
|
u32 utime = 0;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
while (ittime != p->listTimes.end())
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
utime += (u32)ittime->dwTime;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (ittime->dwUserData)
|
2010-03-19 00:31:15 +00:00
|
|
|
fprintf(f, "time: %d, user: 0x%8.8x", (u32)ittime->dwTime, ittime->dwUserData);
|
|
|
|
else
|
|
|
|
fprintf(f, "time: %d", (u32)ittime->dwTime);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
++ittime;
|
|
|
|
}
|
|
|
|
|
|
|
|
mapAggregateTimes[p->pname].uInclusive += utime;
|
|
|
|
|
|
|
|
fprintf(f, "\n");
|
|
|
|
|
|
|
|
list<DVPROFSTRUCT*>::iterator itprof = p->listpChild.begin();
|
|
|
|
|
|
|
|
u32 uex = utime;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
while (itprof != p->listpChild.end())
|
|
|
|
{
|
|
|
|
|
|
|
|
uex -= DVProfWriteStruct(f, *itprof, ident + 4);
|
2010-03-19 00:31:15 +00:00
|
|
|
++itprof;
|
|
|
|
}
|
|
|
|
|
|
|
|
mapAggregateTimes[p->pname].uExclusive += uex;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
return utime;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DVProfWrite(char* pfilename, u32 frames)
|
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
assert(pfilename != NULL);
|
2010-03-19 00:31:15 +00:00
|
|
|
FILE* f = fopen(pfilename, "wb");
|
|
|
|
|
|
|
|
mapAggregateTimes.clear();
|
|
|
|
list<DVPROFSTRUCT>::iterator it = g_listProfilers.begin();
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
while (it != g_listProfilers.end())
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
DVProfWriteStruct(f, &(*it), 0);
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
map<string, DVTIMEINFO>::iterator it;
|
|
|
|
fprintf(f, "\n\n-------------------------------------------------------------------\n\n");
|
|
|
|
|
|
|
|
u64 uTotal[2] = {0};
|
|
|
|
double fiTotalTime[2];
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
for (it = mapAggregateTimes.begin(); it != mapAggregateTimes.end(); ++it)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
uTotal[0] += it->second.uExclusive;
|
|
|
|
uTotal[1] += it->second.uInclusive;
|
|
|
|
}
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
fprintf(f, "total times (%d): ex: %Lu ", frames, uTotal[0] / frames);
|
|
|
|
|
|
|
|
fprintf(f, "inc: %Lu\n", uTotal[1] / frames);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
fiTotalTime[0] = 1.0 / (double)uTotal[0];
|
|
|
|
fiTotalTime[1] = 1.0 / (double)uTotal[1];
|
|
|
|
|
|
|
|
// output the combined times
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
for (it = mapAggregateTimes.begin(); it != mapAggregateTimes.end(); ++it)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
fprintf(f, "%s - ex: %f inc: %f\n", it->first.c_str(), (double)it->second.uExclusive * fiTotalTime[0],
|
2010-05-01 20:33:53 +00:00
|
|
|
(double)it->second.uInclusive * fiTotalTime[1]);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DVProfClear()
|
|
|
|
{
|
|
|
|
g_listCurTracking.clear();
|
|
|
|
g_listProfilers.clear();
|
|
|
|
g_listAllProfilers.clear();
|
|
|
|
}
|