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"
|
2010-05-02 03:09:20 +00:00
|
|
|
#include "Profile.h"
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
#include "zerogs.h"
|
|
|
|
#include "targets.h"
|
|
|
|
#include "ZeroGSShaders/zerogsshaders.h"
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(disable:4244)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
GSinternal gs;
|
|
|
|
char GStitle[256];
|
2010-07-02 09:32:04 +00:00
|
|
|
extern FILE *gsLog;
|
2010-03-19 00:31:15 +00:00
|
|
|
GSconf conf;
|
|
|
|
int ppf;
|
|
|
|
primInfo *prim;
|
|
|
|
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-06-11 17:31:45 +00:00
|
|
|
std::string s_strLogPath("logs/");
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2010-07-02 10:33:44 +00:00
|
|
|
extern const char* s_aa[5];
|
|
|
|
extern const char* s_naa[3];
|
|
|
|
extern const char* pbilinear[];
|
2010-03-19 00:31:15 +00:00
|
|
|
// 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-06-11 11:48:07 +00:00
|
|
|
extern GIFRegHandler g_GIFPackedRegHandlers[], g_GIFRegHandlers[];
|
2010-03-19 00:31:15 +00:00
|
|
|
GIFRegHandler g_GIFTempRegHandlers[16] = {0};
|
2010-06-11 11:48:07 +00:00
|
|
|
extern int g_nPixelShaderVer, g_nFrameRender, g_nFramesSkipped;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
int s_frameskipping = 0;
|
2010-06-11 11:48:07 +00:00
|
|
|
|
2010-07-02 10:33:44 +00:00
|
|
|
extern void ProcessMessages();
|
|
|
|
extern void WriteAA();
|
|
|
|
extern void WriteBilinear();
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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-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
|
|
|
}
|
|
|
|
|
2010-06-11 17:31:45 +00:00
|
|
|
void CALLBACK GSsetLogDir(const char* dir)
|
|
|
|
{
|
|
|
|
// Get the path to the log directory.
|
|
|
|
s_strLogPath = (dir==NULL) ? "logs/" : dir;
|
|
|
|
|
|
|
|
// Reload the log file after updated the path
|
|
|
|
if (gsLog != NULL) fclose(gsLog);
|
|
|
|
ZZLog::OpenLog();
|
|
|
|
}
|
|
|
|
|
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-06-19 08:46:40 +00:00
|
|
|
conf.mrtdepth = (conf.settings().disable_mrt_depth != 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
|
|
|
|
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;
|
|
|
|
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-06-19 08:46:40 +00:00
|
|
|
conf.def_hacks._u32 |= crc_game_list[i].flags;
|
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-06-27 08:38:50 +00:00
|
|
|
//#define OLD_GS_SET_FRAMESKIP
|
|
|
|
#ifdef OLD_GS_SET_FRAMESKIP
|
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-06-27 08:38:50 +00:00
|
|
|
#else
|
|
|
|
void CALLBACK GSsetFrameSkip(int frameskip)
|
|
|
|
{
|
|
|
|
FUNCLOG
|
|
|
|
s_frameskipping |= frameskip;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-06-27 08:38:50 +00:00
|
|
|
if (frameskip && g_nFrameRender > 1)
|
|
|
|
{
|
|
|
|
g_GIFPackedRegHandlers[GIF_REG_PRIM] = &GIFPackedRegHandlerNOP;
|
|
|
|
g_GIFPackedRegHandlers[GIF_REG_RGBA] = &GIFPackedRegHandlerNOP;
|
|
|
|
g_GIFPackedRegHandlers[GIF_REG_STQ] = &GIFPackedRegHandlerNOP;
|
|
|
|
g_GIFPackedRegHandlers[GIF_REG_UV] = &GIFPackedRegHandlerNOP;
|
|
|
|
g_GIFPackedRegHandlers[GIF_REG_XYZF2] = &GIFPackedRegHandlerNOP;
|
|
|
|
g_GIFPackedRegHandlers[GIF_REG_XYZ2] = &GIFPackedRegHandlerNOP;
|
|
|
|
g_GIFPackedRegHandlers[GIF_REG_CLAMP_1] = &GIFPackedRegHandlerNOP;
|
|
|
|
g_GIFPackedRegHandlers[GIF_REG_CLAMP_2] = &GIFPackedRegHandlerNOP;
|
|
|
|
g_GIFPackedRegHandlers[GIF_REG_FOG] = &GIFPackedRegHandlerNOP;
|
|
|
|
g_GIFPackedRegHandlers[GIF_REG_XYZF3] = &GIFPackedRegHandlerNOP;
|
|
|
|
g_GIFPackedRegHandlers[GIF_REG_XYZ3] = &GIFPackedRegHandlerNOP;
|
|
|
|
|
|
|
|
g_GIFRegHandlers[GIF_A_D_REG_PRIM] = &GIFRegHandlerNOP;
|
|
|
|
g_GIFRegHandlers[GIF_A_D_REG_RGBAQ] = &GIFRegHandlerNOP;
|
|
|
|
g_GIFRegHandlers[GIF_A_D_REG_ST] = &GIFRegHandlerNOP;
|
|
|
|
g_GIFRegHandlers[GIF_A_D_REG_UV] = &GIFRegHandlerNOP;
|
|
|
|
g_GIFRegHandlers[GIF_A_D_REG_XYZF2] = &GIFRegHandlerNOP;
|
|
|
|
g_GIFRegHandlers[GIF_A_D_REG_XYZ2] = &GIFRegHandlerNOP;
|
|
|
|
g_GIFRegHandlers[GIF_A_D_REG_XYZF3] = &GIFRegHandlerNOP;
|
|
|
|
g_GIFRegHandlers[GIF_A_D_REG_XYZ3] = &GIFRegHandlerNOP;
|
|
|
|
g_GIFRegHandlers[GIF_A_D_REG_PRMODECONT] = &GIFRegHandlerNOP;
|
|
|
|
g_GIFRegHandlers[GIF_A_D_REG_PRMODE] = &GIFRegHandlerNOP;
|
|
|
|
}
|
|
|
|
else if (!frameskip && g_nFrameRender <= 0)
|
|
|
|
{
|
|
|
|
g_GIFPackedRegHandlers[GIF_REG_PRIM] = &GIFPackedRegHandlerPRIM;
|
|
|
|
g_GIFPackedRegHandlers[GIF_REG_RGBA] = &GIFPackedRegHandlerRGBA;
|
|
|
|
g_GIFPackedRegHandlers[GIF_REG_STQ] = &GIFPackedRegHandlerSTQ;
|
|
|
|
g_GIFPackedRegHandlers[GIF_REG_UV] = &GIFPackedRegHandlerUV;
|
|
|
|
g_GIFPackedRegHandlers[GIF_REG_XYZF2] = &GIFPackedRegHandlerXYZF2;
|
|
|
|
g_GIFPackedRegHandlers[GIF_REG_XYZ2] = &GIFPackedRegHandlerXYZ2;
|
|
|
|
g_GIFPackedRegHandlers[GIF_REG_CLAMP_1] = &GIFPackedRegHandlerCLAMP_1;
|
|
|
|
g_GIFPackedRegHandlers[GIF_REG_CLAMP_2] = &GIFPackedRegHandlerCLAMP_2;
|
|
|
|
g_GIFPackedRegHandlers[GIF_REG_FOG] = &GIFPackedRegHandlerFOG;
|
|
|
|
g_GIFPackedRegHandlers[GIF_REG_XYZF3] = &GIFPackedRegHandlerXYZF3;
|
|
|
|
g_GIFPackedRegHandlers[GIF_REG_XYZ3] = &GIFPackedRegHandlerXYZ3;
|
|
|
|
|
|
|
|
g_GIFRegHandlers[GIF_A_D_REG_PRIM] = &GIFRegHandlerPRIM;
|
|
|
|
g_GIFRegHandlers[GIF_A_D_REG_RGBAQ] = &GIFRegHandlerRGBAQ;
|
|
|
|
g_GIFRegHandlers[GIF_A_D_REG_ST] = &GIFRegHandlerST;
|
|
|
|
g_GIFRegHandlers[GIF_A_D_REG_UV] = &GIFRegHandlerUV;
|
|
|
|
g_GIFRegHandlers[GIF_A_D_REG_XYZF2] = &GIFRegHandlerXYZF2;
|
|
|
|
g_GIFRegHandlers[GIF_A_D_REG_XYZ2] = &GIFRegHandlerXYZ2;
|
|
|
|
g_GIFRegHandlers[GIF_A_D_REG_XYZF3] = &GIFRegHandlerXYZF3;
|
|
|
|
g_GIFRegHandlers[GIF_A_D_REG_XYZ3] = &GIFRegHandlerXYZ3;
|
|
|
|
g_GIFRegHandlers[GIF_A_D_REG_PRMODECONT] = &GIFRegHandlerPRMODECONT;
|
|
|
|
g_GIFRegHandlers[GIF_A_D_REG_PRMODE] = &GIFRegHandlerPRMODE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
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));
|
|
|
|
|
2010-06-11 17:31:45 +00:00
|
|
|
if (ZZLog::OpenLog() == false)
|
2010-04-25 08:33:05 +00:00
|
|
|
return -1;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-06-21 12:03:14 +00:00
|
|
|
ZZLog::WriteLn("Calling GSinit.");
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
GSreset();
|
2010-06-21 12:03:14 +00:00
|
|
|
ZZLog::WriteLn("GSinit finished.");
|
2010-03-19 00:31:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#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-06-27 08:38:50 +00:00
|
|
|
extern void ResetRegs();
|
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-06-21 12:03:14 +00:00
|
|
|
ZZLog::WriteLn("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-06-21 12:03:14 +00:00
|
|
|
ZZLog::Error_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-06-21 12:03:14 +00:00
|
|
|
ZZLog::GS_Log("Using %s:%d.%d.%d.", libraryName, zgsrevision, zgsbuild, zgsminor);
|
|
|
|
ZZLog::WriteLn("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-06-21 12:03:14 +00:00
|
|
|
ZZLog::WriteLn("Initialization successful.");
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-07-02 10:33:44 +00:00
|
|
|
WriteBilinear();
|
|
|
|
WriteAA();
|
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-06-27 08:38:50 +00:00
|
|
|
ResetRegs();
|
2010-04-30 04:40:31 +00:00
|
|
|
ZZLog::GS_Log("GSopen finished.");
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-07-02 10:33:44 +00:00
|
|
|
void CALLBACK GSshutdown()
|
2010-03-19 00:31:15 +00:00
|
|
|
{
|
|
|
|
FUNCLOG
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-07-02 10:33:44 +00:00
|
|
|
if (gsLog != NULL) fclose(gsLog);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
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-06-29 16:05:54 +00:00
|
|
|
sprintf(filename, "%s/snap%03ld.%s", path, snapshotnr, (conf.zz_options.tga_snap) ? "bmp" : "jpg");
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
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-06-19 06:23:40 +00:00
|
|
|
if (!(conf.fullscreen())) GLWin.SetTitle(strtitle);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-06-19 06:23:40 +00:00
|
|
|
if (fFPS < 16)
|
|
|
|
UPDATE_FRAMES = 4;
|
|
|
|
else if (fFPS < 32)
|
|
|
|
UPDATE_FRAMES = 8;
|
|
|
|
else
|
|
|
|
UPDATE_FRAMES = 16;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2010-06-19 06:23:40 +00:00
|
|
|
if (conf.captureAvi()) return 1;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
ZeroGS::StartCapture();
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-06-19 06:23:40 +00:00
|
|
|
conf.setCaptureAvi(true);
|
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
|
|
|
|
{
|
2010-06-19 06:23:40 +00:00
|
|
|
if (!(conf.captureAvi())) return 1;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-06-19 06:23:40 +00:00
|
|
|
conf.setCaptureAvi(false);
|
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;
|
|
|
|
}
|