/[pcsx2_0.9.7]/trunk/plugins/zzogl-pg/opengl/ZZoglSave.cpp
ViewVC logotype

Contents of /trunk/plugins/zzogl-pg/opengl/ZZoglSave.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 280 - (show annotations) (download)
Thu Dec 23 12:02:12 2010 UTC (9 years, 1 month ago) by william
File size: 3973 byte(s)
re-commit (had local access denied errors when committing)
1 /* ZZ Open GL graphics plugin
2 * Copyright (c)2009-2010 zeydlitz@gmail.com, arcum42@gmail.com
3 * Based on Zerofrog's ZeroGS KOSMOS (c)2005-2008
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20 // Save and Load.
21
22 //------------------ Includes
23 #include "Util.h"
24 #include "ZZoglVB.h"
25
26 extern void ZZGSStateReset();
27 //----------------------- Defines
28
29 #define VBSAVELIMIT ((u32)((u8*)&vb[0].nNextFrameHeight-(u8*)&vb[0]))
30 #define ZEROGS_SAVEVER 0xaa000005
31
32 //------------------ Variables
33
34 // Hack for save game compatible!
35 #ifdef _DEBUG
36 char *libraryNameX = "ZeroGS-Pg OpenGL (Debug) ";
37 #elif defined(ZEROGS_DEVBUILD)
38 char *libraryNameX = "ZeroGS-Pg OpenGL (Dev) ";
39 #else
40 char *libraryNameX = "ZeroGS Playground OpenGL ";
41 #endif
42
43 //------------------ Code
44
45 extern char *libraryName;
46 extern u32 s_uTex1Data[2][2], s_uClampData[2];
47
48 void SetFogColor(u32 fog);
49 void SetFogColor(GIFRegFOGCOL* fog);
50
51 int ZZSave(s8* pbydata)
52 {
53 if (pbydata == NULL)
54 return 40 + MEMORY_END + sizeof(gs) + 2*VBSAVELIMIT + 2*sizeof(frameInfo) + 4 + 256*4;
55
56 s_RTs.ResolveAll();
57 s_DepthRTs.ResolveAll();
58
59 strcpy((char*)pbydata, libraryNameX);
60
61 *(u32*)(pbydata + 16) = ZEROGS_SAVEVER;
62
63 pbydata += 32;
64 *(int*)pbydata = icurctx;
65
66 pbydata += 4;
67 *(int*)pbydata = VBSAVELIMIT;
68
69 pbydata += 4;
70
71 memcpy(pbydata, g_pbyGSMemory, MEMORY_END);
72 pbydata += MEMORY_END;
73
74 memcpy(pbydata, g_pbyGSClut, 256*4);
75 pbydata += 256 * 4;
76
77 *(int*)pbydata = sizeof(gs);
78 pbydata += 4;
79
80 memcpy(pbydata, &gs, sizeof(gs));
81 pbydata += sizeof(gs);
82
83 for (int i = 0; i < 2; ++i)
84 {
85 memcpy(pbydata, &vb[i], VBSAVELIMIT);
86 pbydata += VBSAVELIMIT;
87 }
88
89 return 0;
90 }
91
92 extern u32 s_uFramebuffer;
93 extern int g_nCurVBOIndex;
94
95 bool ZZLoad(s8* pbydata)
96 {
97 memset(s_uTex1Data, 0, sizeof(s_uTex1Data));
98 memset(s_uClampData, 0, sizeof(s_uClampData));
99
100 g_nCurVBOIndex = 0;
101
102 // first 32 bytes are the id
103 u32 savever = *(u32*)(pbydata + 16);
104
105 if (strncmp((char*)pbydata, libraryNameX, 6) == 0 && (savever == ZEROGS_SAVEVER || savever == 0xaa000004))
106 {
107 g_MemTargs.Destroy();
108
109 ZZGSStateReset();
110 pbydata += 32;
111
112 //int context = *(int*)pbydata;
113 pbydata += 4;
114 u32 savelimit = VBSAVELIMIT;
115
116 savelimit = *(u32*)pbydata;
117 pbydata += 4;
118
119 memcpy(g_pbyGSMemory, pbydata, MEMORY_END);
120 pbydata += MEMORY_END;
121
122 memcpy(g_pbyGSClut, pbydata, 256*4);
123 pbydata += 256 * 4;
124
125 memset(&gs, 0, sizeof(gs));
126
127 int savedgssize;
128
129 if (savever == 0xaa000004)
130 {
131 savedgssize = 0x1d0;
132 }
133 else
134 {
135 savedgssize = *(int*)pbydata;
136 pbydata += 4;
137 }
138
139 memcpy(&gs, pbydata, savedgssize);
140
141 pbydata += savedgssize;
142 prim = &gs._prim[gs.prac];
143
144 vb[0].Destroy();
145 memcpy(&vb[0], pbydata, min(savelimit, VBSAVELIMIT));
146 pbydata += savelimit;
147 vb[0].pBufferData = NULL;
148
149 vb[1].Destroy();
150 memcpy(&vb[1], pbydata, min(savelimit, VBSAVELIMIT));
151 pbydata += savelimit;
152 vb[1].pBufferData = NULL;
153
154 for (int i = 0; i < 2; ++i)
155 {
156 vb[i].Init(VB_BUFFERSIZE);
157 vb[i].bNeedZCheck = vb[i].bNeedFrameCheck = 1;
158
159 vb[i].bSyncVars = 0;
160 vb[i].bNeedTexCheck = 1;
161 memset(vb[i].uCurTex0Data, 0, sizeof(vb[i].uCurTex0Data));
162 }
163
164 icurctx = -1;
165
166 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, s_uFramebuffer); // switch to the backbuffer
167 SetFogColor(gs.fogcol);
168
169 GL_REPORT_ERRORD();
170 return true;
171 }
172
173 return false;
174 }
175

  ViewVC Help
Powered by ViewVC 1.1.22