2010-03-19 00:31:15 +00:00
|
|
|
/* ZZ Open GL graphics plugin
|
2010-07-10 08:20:50 +00:00
|
|
|
* Copyright (c)2009-2010 zeydlitz@gmail.com, arcum42@gmail.com
|
|
|
|
* Based on Zerofrog's ZeroGS KOSMOS (c)2005-2008
|
2010-03-19 00:31:15 +00:00
|
|
|
*
|
|
|
|
* 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
|
2010-07-04 22:49:00 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
2010-03-19 00:31:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
// Save and Load.
|
|
|
|
|
|
|
|
//------------------ Includes
|
2010-11-07 05:51:54 +00:00
|
|
|
#include "Util.h"
|
2010-10-23 08:15:39 +00:00
|
|
|
#include "ZZoglVB.h"
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-10-18 11:24:40 +00:00
|
|
|
extern void ZZGSStateReset();
|
2010-04-25 00:31:27 +00:00
|
|
|
//----------------------- Defines
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
#define VBSAVELIMIT ((u32)((u8*)&vb[0].nNextFrameHeight-(u8*)&vb[0]))
|
|
|
|
#define ZEROGS_SAVEVER 0xaa000005
|
|
|
|
|
|
|
|
//------------------ Variables
|
|
|
|
|
|
|
|
// Hack for save game compatible!
|
|
|
|
#ifdef _DEBUG
|
|
|
|
char *libraryNameX = "ZeroGS-Pg OpenGL (Debug) ";
|
2010-04-25 09:02:36 +00:00
|
|
|
#elif defined(ZEROGS_DEVBUILD)
|
2010-03-19 00:31:15 +00:00
|
|
|
char *libraryNameX = "ZeroGS-Pg OpenGL (Dev) ";
|
2010-04-25 09:02:36 +00:00
|
|
|
#else
|
|
|
|
char *libraryNameX = "ZeroGS Playground OpenGL ";
|
2010-03-19 00:31:15 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//------------------ Code
|
|
|
|
|
|
|
|
extern char *libraryName;
|
|
|
|
extern u32 s_uTex1Data[2][2], s_uClampData[2];
|
|
|
|
|
2010-10-18 11:24:40 +00:00
|
|
|
void SetFogColor(u32 fog);
|
|
|
|
void SetFogColor(GIFRegFOGCOL* fog);
|
|
|
|
|
2010-10-16 11:54:46 +00:00
|
|
|
int ZZSave(s8* pbydata)
|
2010-03-19 00:31:15 +00:00
|
|
|
{
|
2010-05-01 20:33:53 +00:00
|
|
|
if (pbydata == NULL)
|
2010-08-14 08:15:19 +00:00
|
|
|
return 40 + MEMORY_END + sizeof(gs) + 2*VBSAVELIMIT + 2*sizeof(frameInfo) + 4 + 256*4;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
s_RTs.ResolveAll();
|
|
|
|
s_DepthRTs.ResolveAll();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
strcpy((char*)pbydata, libraryNameX);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
*(u32*)(pbydata + 16) = ZEROGS_SAVEVER;
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
pbydata += 32;
|
2010-05-01 20:33:53 +00:00
|
|
|
*(int*)pbydata = icurctx;
|
|
|
|
|
|
|
|
pbydata += 4;
|
|
|
|
*(int*)pbydata = VBSAVELIMIT;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
pbydata += 4;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-08-14 08:15:19 +00:00
|
|
|
memcpy(pbydata, g_pbyGSMemory, MEMORY_END);
|
|
|
|
pbydata += MEMORY_END;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
memcpy(pbydata, g_pbyGSClut, 256*4);
|
2010-05-01 20:33:53 +00:00
|
|
|
pbydata += 256 * 4;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
*(int*)pbydata = sizeof(gs);
|
|
|
|
pbydata += 4;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
memcpy(pbydata, &gs, sizeof(gs));
|
|
|
|
pbydata += sizeof(gs);
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
for (int i = 0; i < 2; ++i)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
memcpy(pbydata, &vb[i], VBSAVELIMIT);
|
|
|
|
pbydata += VBSAVELIMIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
extern u32 g_nCurVBOIndex;
|
2010-10-17 08:47:31 +00:00
|
|
|
|
2010-10-16 11:54:46 +00:00
|
|
|
bool ZZLoad(s8* pbydata)
|
2010-03-19 00:31:15 +00:00
|
|
|
{
|
|
|
|
memset(s_uTex1Data, 0, sizeof(s_uTex1Data));
|
|
|
|
memset(s_uClampData, 0, sizeof(s_uClampData));
|
|
|
|
|
|
|
|
g_nCurVBOIndex = 0;
|
|
|
|
|
|
|
|
// first 32 bytes are the id
|
2010-05-01 20:33:53 +00:00
|
|
|
u32 savever = *(u32*)(pbydata + 16);
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
if (strncmp((char*)pbydata, libraryNameX, 6) == 0 && (savever == ZEROGS_SAVEVER || savever == 0xaa000004))
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
g_MemTargs.Destroy();
|
|
|
|
|
2010-10-16 11:54:46 +00:00
|
|
|
ZZGSStateReset();
|
2010-03-19 00:31:15 +00:00
|
|
|
pbydata += 32;
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
//int context = *(int*)pbydata;
|
2010-03-19 06:38:44 +00:00
|
|
|
pbydata += 4;
|
2010-03-19 00:31:15 +00:00
|
|
|
u32 savelimit = VBSAVELIMIT;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
savelimit = *(u32*)pbydata;
|
|
|
|
pbydata += 4;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-08-14 08:15:19 +00:00
|
|
|
memcpy(g_pbyGSMemory, pbydata, MEMORY_END);
|
|
|
|
pbydata += MEMORY_END;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
memcpy(g_pbyGSClut, pbydata, 256*4);
|
2010-05-01 20:33:53 +00:00
|
|
|
pbydata += 256 * 4;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
memset(&gs, 0, sizeof(gs));
|
|
|
|
|
|
|
|
int savedgssize;
|
2010-05-01 20:33:53 +00:00
|
|
|
|
|
|
|
if (savever == 0xaa000004)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
savedgssize = 0x1d0;
|
2010-05-01 20:33:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
savedgssize = *(int*)pbydata;
|
|
|
|
pbydata += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&gs, pbydata, savedgssize);
|
2010-05-01 20:33:53 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
pbydata += savedgssize;
|
|
|
|
prim = &gs._prim[gs.prac];
|
|
|
|
|
|
|
|
vb[0].Destroy();
|
|
|
|
memcpy(&vb[0], pbydata, min(savelimit, VBSAVELIMIT));
|
|
|
|
pbydata += savelimit;
|
|
|
|
vb[0].pBufferData = NULL;
|
|
|
|
|
|
|
|
vb[1].Destroy();
|
|
|
|
memcpy(&vb[1], pbydata, min(savelimit, VBSAVELIMIT));
|
|
|
|
pbydata += savelimit;
|
|
|
|
vb[1].pBufferData = NULL;
|
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
for (int i = 0; i < 2; ++i)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
vb[i].Init(VB_BUFFERSIZE);
|
|
|
|
vb[i].bNeedZCheck = vb[i].bNeedFrameCheck = 1;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 20:33:53 +00:00
|
|
|
vb[i].bSyncVars = 0;
|
|
|
|
vb[i].bNeedTexCheck = 1;
|
2010-03-19 00:31:15 +00:00
|
|
|
memset(vb[i].uCurTex0Data, 0, sizeof(vb[i].uCurTex0Data));
|
|
|
|
}
|
|
|
|
|
|
|
|
icurctx = -1;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2012-04-19 21:22:08 +00:00
|
|
|
FB::Bind(); // switch to the backbuffer
|
2010-03-19 00:31:15 +00:00
|
|
|
SetFogColor(gs.fogcol);
|
|
|
|
|
|
|
|
GL_REPORT_ERRORD();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|