1 /***************************************************************************
2 prim.c - description
3 -------------------
4 begin : Sun Mar 08 2009
5 copyright : (C) 1999-2009 by Pete Bernert
6 web : www.pbernert.com
7 ***************************************************************************/
8
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. See also the license.txt file for *
15 * additional informations. *
16 * *
17 ***************************************************************************/
18
19 //*************************************************************************//
20 // History of changes:
21 //
22 // 2009/03/08 - Pete
23 // - generic cleanup for the Peops release
24 //
25 //*************************************************************************//
26
27 #define _IN_PRIMDRAW
28
29 #include "gpuStdafx.h"
30 #include "gpuExternals.h"
31 #include "gpuPlugin.h"
32 #include "gpuDraw.h"
33 #include "gpuTexture.h"
34 #include "gpuPrim.h"
35
36 ////////////////////////////////////////////////////////////////////////
37 // defines
38 ////////////////////////////////////////////////////////////////////////
39
40 #define DEFOPAQUEON glAlphaFunc(GL_EQUAL,0.0f);bBlendEnable=FALSE;glDisable(GL_BLEND);
41 #define DEFOPAQUEOFF glAlphaFunc(GL_GREATER,0.49f);
42 #define fpoint(x) x
43 ////////////////////////////////////////////////////////////////////////
44 // globals
45 ////////////////////////////////////////////////////////////////////////
46
47
48 BOOL bDrawTextured; // current active drawing states
49 BOOL bDrawSmoothShaded;
50 BOOL bOldSmoothShaded;
51 BOOL bDrawNonShaded;
52 BOOL bDrawMultiPass;
53 int iOffscreenDrawing;
54 int iDrawnSomething=0;
55
56 BOOL bRenderFrontBuffer=FALSE; // flag for front buffer rendering
57
58 GLubyte ubGloAlpha; // texture alpha
59 GLubyte ubGloColAlpha; // color alpha
60 int iFilterType; // type of filter
61 BOOL bFullVRam=FALSE; // sign for tex win
62 BOOL bDrawDither; // sign for dither
63 BOOL bUseMultiPass; // sign for multi pass
64 GLuint gTexName; // binded texture
65 BOOL bTexEnabled; // texture enable flag
66 BOOL bBlendEnable; // blend enable flag
67 PSXRect_t xrUploadArea; // rect to upload
68 PSXRect_t xrUploadAreaIL; // rect to upload
69 PSXRect_t xrUploadAreaRGB24; // rect to upload rgb24
70 int iSpriteTex=0; // flag for "hey, it's a sprite"
71 unsigned short usMirror; // mirror, mirror on the wall
72
73 BOOL bNeedUploadAfter=FALSE; // sign for uploading in next frame
74 BOOL bNeedUploadTest=FALSE; // sign for upload test
75 BOOL bUsingTWin=FALSE; // tex win active flag
76 BOOL bUsingMovie=FALSE; // movie active flag
77 PSXRect_t xrMovieArea; // rect for movie upload
78 short sSprite_ux2; // needed for sprire adjust
79 short sSprite_vy2; //
80 unsigned long ulOLDCOL=0; // active color
81 unsigned long ulClutID; // clut
82
83 unsigned long dwCfgFixes; // game fixes
84 unsigned long dwActFixes=0;
85 unsigned long dwEmuFixes=0;
86 BOOL bUseFixes;
87
88 long drawX,drawY,drawW,drawH; // offscreen drawing checkers
89 short sxmin,sxmax,symin,symax;
90 unsigned int CSVERTEX=0,CSCOLOR=0,CSTEXTURE=0;
91
offsetPSX4(void)92 void offsetPSX4(void)
93 {
94 lx0 += PSXDisplay.DrawOffset.x;
95 ly0 += PSXDisplay.DrawOffset.y;
96 lx1 += PSXDisplay.DrawOffset.x;
97 ly1 += PSXDisplay.DrawOffset.y;
98 lx2 += PSXDisplay.DrawOffset.x;
99 ly2 += PSXDisplay.DrawOffset.y;
100 lx3 += PSXDisplay.DrawOffset.x;
101 ly3 += PSXDisplay.DrawOffset.y;
102 }
103
104 ////////////////////////////////////////////////////////////////////////
105 // Update global TP infos
106 ////////////////////////////////////////////////////////////////////////
107
UpdateGlobalTP(unsigned short gdata)108 void UpdateGlobalTP(unsigned short gdata)
109 {
110 GlobalTextAddrX = (gdata << 6) & 0x3c0;
111
112 if(iGPUHeight==1024) // ZN mode
113 {
114 if(dwGPUVersion==2) // very special zn gpu
115 {
116 GlobalTextAddrY =((gdata & 0x60 ) << 3);
117 GlobalTextIL =(gdata & 0x2000) >> 13;
118 GlobalTextABR = (unsigned short)((gdata >> 7) & 0x3);
119 GlobalTextTP = (gdata >> 9) & 0x3;
120 if(GlobalTextTP==3) GlobalTextTP=2;
121 GlobalTexturePage = (GlobalTextAddrX>>6)+(GlobalTextAddrY>>4);
122 usMirror =0;
123 STATUSREG = (STATUSREG & 0xffffe000 ) | (gdata & 0x1fff );
124 return;
125 }
126 else // "enhanced" psx gpu
127 {
128 GlobalTextAddrY = (unsigned short)(((gdata << 4) & 0x100) | ((gdata >> 2) & 0x200));
129 }
130 }
131 else GlobalTextAddrY = (gdata << 4) & 0x100; // "normal" psx gpu
132
133 usMirror=gdata&0x3000;
134
135 GlobalTextTP = (gdata >> 7) & 0x3; // tex mode (4,8,15)
136 if(GlobalTextTP==3) GlobalTextTP=2; // seen in Wild9 :(
137 GlobalTextABR = (gdata >> 5) & 0x3; // blend mode
138
139 GlobalTexturePage = (GlobalTextAddrX>>6)+(GlobalTextAddrY>>4);
140
141 STATUSREG&=~0x07ff; // Clear the necessary bits
142 STATUSREG|=(gdata & 0x07ff); // set the necessary bits
143 }
144
145 ////////////////////////////////////////////////////////////////////////
146 // Some ASM color convertion... Lewpy's special...
147 ////////////////////////////////////////////////////////////////////////
148
149
DoubleBGR2RGB(unsigned long BGR)150 unsigned long DoubleBGR2RGB (unsigned long BGR)
151 {
152 unsigned long ebx,eax,edx;
153
154 ebx=(BGR&0x000000ff)<<1;
155 if(ebx&0x00000100) ebx=0x000000ff;
156
157 eax=(BGR&0x0000ff00)<<1;
158 if(eax&0x00010000) eax=0x0000ff00;
159
160 edx=(BGR&0x00ff0000)<<1;
161 if(edx&0x01000000) edx=0x00ff0000;
162
163 return (ebx|eax|edx);
164 }
165
BGR24to16(unsigned long BGR)166 unsigned short BGR24to16 (unsigned long BGR)
167 {
168 return ((BGR>>3)&0x1f)|((BGR&0xf80000)>>9)|((BGR&0xf800)>>6);
169 }
170
171
172 ////////////////////////////////////////////////////////////////////////
173 // OpenGL primitive drawing commands
174 ////////////////////////////////////////////////////////////////////////
175
PRIMdrawTexturedQuad(OGLVertex * vertex1,OGLVertex * vertex2,OGLVertex * vertex3,OGLVertex * vertex4)176 void PRIMdrawTexturedQuad(OGLVertex* vertex1, OGLVertex* vertex2,
177 OGLVertex* vertex3, OGLVertex* vertex4)
178 {
179
180
181 Vertex v[4];
182
183 v[0].xyz.x = fpoint(vertex1->x);
184 v[0].xyz.y = fpoint(vertex1->y);
185 v[0].xyz.z = fpoint(vertex1->z);
186 v[0].st.x = fpoint(vertex1->sow);
187 v[0].st.y = fpoint(vertex1->tow);
188
189 v[1].xyz.x = fpoint(vertex2->x);
190 v[1].xyz.y = fpoint(vertex2->y);
191 v[1].xyz.z = fpoint(vertex2->z);
192 v[1].st.x = fpoint(vertex2->sow);
193 v[1].st.y = fpoint(vertex2->tow);
194
195 v[2].xyz.x = fpoint(vertex4->x);
196 v[2].xyz.y = fpoint(vertex4->y);
197 v[2].xyz.z = fpoint(vertex4->z);
198 v[2].st.x = fpoint(vertex4->sow);
199 v[2].st.y = fpoint(vertex4->tow);
200
201 v[3].xyz.x = fpoint(vertex3->x);
202 v[3].xyz.y = fpoint(vertex3->y);
203 v[3].xyz.z = fpoint(vertex3->z);
204 v[3].st.x = fpoint(vertex3->sow);
205 v[3].st.y = fpoint(vertex3->tow);
206 if (CSCOLOR==1) glDisableClientState(GL_COLOR_ARRAY);glError();
207 if (CSTEXTURE==0) glEnableClientState(GL_TEXTURE_COORD_ARRAY);glError();
208 if (CSVERTEX==0) glEnableClientState(GL_VERTEX_ARRAY);glError();
209 glTexCoordPointer(2, GL_FLOAT, sizeof(v[0]), &v[0].st);glError();
210 glVertexPointer(3, GL_FLOAT, sizeof(v[0]), &v[0].xyz);glError();
211 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);glError();
212 CSTEXTURE=CSVERTEX=1;
213 CSCOLOR=0;
214 }
215
216 /////////////////////////////////////////////////////////
217
PRIMdrawTexturedTri(OGLVertex * vertex1,OGLVertex * vertex2,OGLVertex * vertex3)218 void PRIMdrawTexturedTri(OGLVertex* vertex1, OGLVertex* vertex2,
219 OGLVertex* vertex3)
220 {
221 Vertex v[3];
222 if (vertex1->x==0&&vertex1->y==0&&vertex2->x==0&&vertex2->y==0&&vertex3->x==0&&vertex3->y==0) return;
223
224 v[0].xyz.x = fpoint(vertex1->x);
225 v[0].xyz.y = fpoint(vertex1->y);
226 v[0].xyz.z = fpoint(vertex1->z);
227 v[0].st.x = fpoint(vertex1->sow);
228 v[0].st.y = fpoint(vertex1->tow);
229
230 v[1].xyz.x = fpoint(vertex2->x);
231 v[1].xyz.y = fpoint(vertex2->y);
232 v[1].xyz.z = fpoint(vertex2->z);
233 v[1].st.x = fpoint(vertex2->sow);
234 v[1].st.y = fpoint(vertex2->tow);
235
236 v[2].xyz.x = fpoint(vertex3->x);
237 v[2].xyz.y = fpoint(vertex3->y);
238 v[2].xyz.z = fpoint(vertex3->z);
239 v[2].st.x = fpoint(vertex3->sow);
240 v[2].st.y = fpoint(vertex3->tow);
241 if (CSCOLOR==1) glDisableClientState(GL_COLOR_ARRAY);glError();
242 if (CSTEXTURE==0) glEnableClientState(GL_TEXTURE_COORD_ARRAY);glError();
243 if (CSVERTEX==0) glEnableClientState(GL_VERTEX_ARRAY);glError();
244 glTexCoordPointer(2, GL_FLOAT, sizeof(v[0]), &v[0].st);glError();
245 glVertexPointer(3, GL_FLOAT, sizeof(v[0]), &v[0].xyz);glError();
246 glDrawArrays(GL_TRIANGLES, 0, 3);glError();
247 CSTEXTURE=CSVERTEX=1;
248 CSCOLOR=0;
249
250 }
251
252 /////////////////////////////////////////////////////////
253
PRIMdrawTexGouraudTriColor(OGLVertex * vertex1,OGLVertex * vertex2,OGLVertex * vertex3)254 void PRIMdrawTexGouraudTriColor(OGLVertex* vertex1, OGLVertex* vertex2,
255 OGLVertex* vertex3)
256 {
257
258 Vertex2 v[3];
259 if (vertex1->x==0&&vertex1->y==0&&vertex2->x==0&&vertex2->y==0&&vertex3->x==0&&vertex3->y==0) return;
260
261 v[0].xyz.x = fpoint(vertex1->x);
262 v[0].xyz.y = fpoint(vertex1->y);
263 v[0].xyz.z = fpoint(vertex1->z);
264 v[0].st.x = fpoint(vertex1->sow);
265 v[0].st.y = fpoint(vertex1->tow);
266 v[0].rgba.r = vertex1->c.col[0];
267 v[0].rgba.g = vertex1->c.col[1];
268 v[0].rgba.b = vertex1->c.col[2];
269 v[0].rgba.a = vertex1->c.col[3];
270
271 v[1].xyz.x = fpoint(vertex2->x);
272 v[1].xyz.y = fpoint(vertex2->y);
273 v[1].xyz.z = fpoint(vertex2->z);
274 v[1].st.x = fpoint(vertex2->sow);
275 v[1].st.y = fpoint(vertex2->tow);
276 v[1].rgba.r = vertex2->c.col[0];
277 v[1].rgba.g = vertex2->c.col[1];
278 v[1].rgba.b = vertex2->c.col[2];
279 v[1].rgba.a = vertex2->c.col[3];
280
281 v[2].xyz.x = fpoint(vertex3->x);
282 v[2].xyz.y = fpoint(vertex3->y);
283 v[2].xyz.z = fpoint(vertex3->z);
284 v[2].st.x = fpoint(vertex3->sow);
285 v[2].st.y = fpoint(vertex3->tow);
286 v[2].rgba.r = vertex3->c.col[0];
287 v[2].rgba.g = vertex3->c.col[1];
288 v[2].rgba.b = vertex3->c.col[2];
289 v[2].rgba.a = vertex3->c.col[3];
290
291 if (CSTEXTURE==0) glEnableClientState(GL_TEXTURE_COORD_ARRAY);glError();
292 if (CSVERTEX==0) glEnableClientState(GL_VERTEX_ARRAY);glError();
293 if (CSCOLOR==0) glEnableClientState(GL_COLOR_ARRAY);glError();
294
295 glTexCoordPointer(2, GL_FLOAT, sizeof(v[0]), &v[0].st);glError();
296 glVertexPointer(3, GL_FLOAT, sizeof(v[0]), &v[0].xyz);glError();
297 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(v[0]), &v[0].rgba);glError();
298
299 glDrawArrays(GL_TRIANGLES, 0, 3);glError();
300 CSTEXTURE=CSVERTEX=CSCOLOR=1;
301 }
302
303 /////////////////////////////////////////////////////////
304
PRIMdrawTexGouraudTriColorQuad(OGLVertex * vertex1,OGLVertex * vertex2,OGLVertex * vertex3,OGLVertex * vertex4)305 void PRIMdrawTexGouraudTriColorQuad(OGLVertex* vertex1, OGLVertex* vertex2,
306 OGLVertex* vertex3, OGLVertex* vertex4)
307 {
308 Vertex2 v[4];
309 if (vertex1->x==0&&vertex1->y==0&&vertex2->x==0&&vertex2->y==0&&vertex3->x==0&&vertex3->y==0&&vertex4->x==0&&vertex4->y==0) return;
310
311 v[0].xyz.x = fpoint(vertex1->x);
312 v[0].xyz.y = fpoint(vertex1->y);
313 v[0].xyz.z = fpoint(vertex1->z);
314 v[0].st.x = fpoint(vertex1->sow);
315 v[0].st.y = fpoint(vertex1->tow);
316 v[0].rgba.r = vertex1->c.col[0];
317 v[0].rgba.g = vertex1->c.col[1];
318 v[0].rgba.b = vertex1->c.col[2];
319 v[0].rgba.a = vertex1->c.col[3];
320
321 v[1].xyz.x = fpoint(vertex2->x);
322 v[1].xyz.y = fpoint(vertex2->y);
323 v[1].xyz.z = fpoint(vertex2->z);
324 v[1].st.x = fpoint(vertex2->sow);
325 v[1].st.y = fpoint(vertex2->tow);
326 v[1].rgba.r = vertex2->c.col[0];
327 v[1].rgba.g = vertex2->c.col[1];
328 v[1].rgba.b = vertex2->c.col[2];
329 v[1].rgba.a = vertex2->c.col[3];
330
331 v[2].xyz.x = fpoint(vertex4->x);
332 v[2].xyz.y = fpoint(vertex4->y);
333 v[2].xyz.z = fpoint(vertex4->z);
334 v[2].st.x = fpoint(vertex4->sow);
335 v[2].st.y = fpoint(vertex4->tow);
336 v[2].rgba.r = vertex4->c.col[0];
337 v[2].rgba.g = vertex4->c.col[1];
338 v[2].rgba.b = vertex4->c.col[2];
339 v[2].rgba.a = vertex4->c.col[3];
340
341 v[3].xyz.x = fpoint(vertex3->x);
342 v[3].xyz.y = fpoint(vertex3->y);
343 v[3].xyz.z = fpoint(vertex3->z);
344 v[3].st.x = fpoint(vertex3->sow);
345 v[3].st.y = fpoint(vertex3->tow);
346 v[3].rgba.r = vertex3->c.col[0];
347 v[3].rgba.g = vertex3->c.col[1];
348 v[3].rgba.b = vertex3->c.col[2];
349 v[3].rgba.a = vertex3->c.col[3];
350
351 if (CSTEXTURE==0) glEnableClientState(GL_TEXTURE_COORD_ARRAY);glError();
352 if (CSVERTEX==0) glEnableClientState(GL_VERTEX_ARRAY);glError();
353 if (CSCOLOR==0) glEnableClientState(GL_COLOR_ARRAY);glError();
354
355 glTexCoordPointer(2, GL_FLOAT, sizeof(v[0]), &v[0].st);glError();
356 glVertexPointer(3, GL_FLOAT, sizeof(v[0]), &v[0].xyz);glError();
357 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(v[0]), &v[0].rgba);glError();
358
359 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);glError();
360 CSTEXTURE=CSVERTEX=CSCOLOR=1;
361 }
362
363 /////////////////////////////////////////////////////////
364
PRIMdrawTri(OGLVertex * vertex1,OGLVertex * vertex2,OGLVertex * vertex3)365 void PRIMdrawTri(OGLVertex* vertex1, OGLVertex* vertex2, OGLVertex* vertex3)
366 {
367 Vec3f v[3];
368 if (vertex1->x==0&&vertex1->y==0&&vertex2->x==0&&vertex2->y==0&&vertex3->x==0&&vertex3->y==0) return;
369
370 v[0].x = fpoint(vertex1->x);
371 v[0].y = fpoint(vertex1->y);
372 v[0].z = fpoint(vertex1->z);
373
374 v[1].x = fpoint(vertex2->x);
375 v[1].y = fpoint(vertex2->y);
376 v[1].z = fpoint(vertex2->z);
377
378 v[2].x = fpoint(vertex3->x);
379 v[2].y = fpoint(vertex3->y);
380 v[2].z = fpoint(vertex3->z);
381
382 if (CSVERTEX==0) glEnableClientState(GL_VERTEX_ARRAY);glError();
383 if (CSTEXTURE==1) glDisableClientState(GL_TEXTURE_COORD_ARRAY);glError();
384 if (CSCOLOR==1) glDisableClientState(GL_COLOR_ARRAY);glError();
385
386 glVertexPointer(3, GL_FLOAT, sizeof(v[0]), &v[0]);glError();
387 glDrawArrays(GL_TRIANGLES, 0, 3);glError();
388 CSVERTEX=1;
389 CSTEXTURE=CSCOLOR=0;
390
391 }
392
393 /////////////////////////////////////////////////////////
394
PRIMdrawTri2(OGLVertex * vertex1,OGLVertex * vertex2,OGLVertex * vertex3,OGLVertex * vertex4)395 void PRIMdrawTri2(OGLVertex* vertex1, OGLVertex* vertex2,
396 OGLVertex* vertex3, OGLVertex* vertex4)
397 {
398 Vec3f v[4];
399 if (vertex1->x==0&&vertex1->y==0&&vertex2->x==0&&vertex2->y==0&&vertex3->x==0&&vertex3->y==0&&vertex4->x==0&&vertex4->y==0) return;
400
401 v[0].x = fpoint(vertex1->x);
402 v[0].y = fpoint(vertex1->y);
403 v[0].z = fpoint(vertex1->z);
404
405 v[1].x = fpoint(vertex3->x);
406 v[1].y = fpoint(vertex3->y);
407 v[1].z = fpoint(vertex3->z);
408
409 v[2].x = fpoint(vertex2->x);
410 v[2].y = fpoint(vertex2->y);
411 v[2].z = fpoint(vertex2->z);
412
413 v[3].x = fpoint(vertex4->x);
414 v[3].y = fpoint(vertex4->y);
415 v[3].z = fpoint(vertex4->z);
416
417 if (CSVERTEX==0) glEnableClientState(GL_VERTEX_ARRAY);glError();
418 if (CSTEXTURE==1) glDisableClientState(GL_TEXTURE_COORD_ARRAY);glError();
419 if (CSCOLOR==1) glDisableClientState(GL_COLOR_ARRAY);glError();
420
421 glVertexPointer(3, GL_FLOAT, sizeof(v[0]), &v[0]);glError();
422 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);glError();
423 CSVERTEX=1;
424 CSTEXTURE=CSCOLOR=0;
425 }
426
427 /////////////////////////////////////////////////////////
428
PRIMdrawGouraudTriColor(OGLVertex * vertex1,OGLVertex * vertex2,OGLVertex * vertex3)429 void PRIMdrawGouraudTriColor(OGLVertex* vertex1, OGLVertex* vertex2,
430 OGLVertex* vertex3)
431 {
432 Vertex2 v[3];
433 if (vertex1->x==0&&vertex1->y==0&&vertex2->x==0&&vertex2->y==0&&vertex3->x==0&&vertex3->y==0) return;
434
435 v[0].xyz.x = fpoint(vertex1->x);
436 v[0].xyz.y = fpoint(vertex1->y);
437 v[0].xyz.z = fpoint(vertex1->z);
438 v[0].rgba.r = vertex1->c.col[0];
439 v[0].rgba.g = vertex1->c.col[1];
440 v[0].rgba.b = vertex1->c.col[2];
441 v[0].rgba.a = vertex1->c.col[3];
442
443 v[1].xyz.x = fpoint(vertex2->x);
444 v[1].xyz.y = fpoint(vertex2->y);
445 v[1].xyz.z = fpoint(vertex2->z);
446 v[1].rgba.r = vertex2->c.col[0];
447 v[1].rgba.g = vertex2->c.col[1];
448 v[1].rgba.b = vertex2->c.col[2];
449 v[1].rgba.a = vertex2->c.col[3];
450
451 v[2].xyz.x = fpoint(vertex3->x);
452 v[2].xyz.y = fpoint(vertex3->y);
453 v[2].xyz.z = fpoint(vertex3->z);
454 v[2].rgba.r = vertex3->c.col[0];
455 v[2].rgba.g = vertex3->c.col[1];
456 v[2].rgba.b = vertex3->c.col[2];
457 v[2].rgba.a = vertex3->c.col[3];
458
459 if (CSVERTEX==0) glEnableClientState(GL_VERTEX_ARRAY);glError();
460 if (CSCOLOR==0) glEnableClientState(GL_COLOR_ARRAY);glError();
461 if (CSTEXTURE==1) glDisableClientState(GL_TEXTURE_COORD_ARRAY);glError();
462
463 glVertexPointer(3, GL_FLOAT, sizeof(v[0]), &v[0].xyz);glError();
464 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(v[0]), &v[0].rgba);glError();
465
466 glDrawArrays(GL_TRIANGLES, 0, 3);glError();
467 CSVERTEX=CSCOLOR=1;
468 CSTEXTURE=0;
469 }
470
471 /////////////////////////////////////////////////////////
472
PRIMdrawGouraudTri2Color(OGLVertex * vertex1,OGLVertex * vertex2,OGLVertex * vertex3,OGLVertex * vertex4)473 void PRIMdrawGouraudTri2Color(OGLVertex* vertex1, OGLVertex* vertex2,
474 OGLVertex* vertex3, OGLVertex* vertex4)
475 {
476 Vertex2 v[4];
477 if (vertex1->x==0&&vertex1->y==0&&vertex2->x==0&&vertex2->y==0&&vertex3->x==0&&vertex3->y==0&&vertex4->x==0&&vertex4->y==0) return;
478
479 v[0].xyz.x = fpoint(vertex1->x);
480 v[0].xyz.y = fpoint(vertex1->y);
481 v[0].xyz.z = fpoint(vertex1->z);
482 v[0].rgba.r = vertex1->c.col[0];
483 v[0].rgba.g = vertex1->c.col[1];
484 v[0].rgba.b = vertex1->c.col[2];
485 v[0].rgba.a = vertex1->c.col[3];
486
487 v[1].xyz.x = fpoint(vertex2->x);
488 v[1].xyz.y = fpoint(vertex2->y);
489 v[1].xyz.z = fpoint(vertex2->z);
490 v[1].rgba.r = vertex2->c.col[0];
491 v[1].rgba.g = vertex2->c.col[1];
492 v[1].rgba.b = vertex2->c.col[2];
493 v[1].rgba.a = vertex2->c.col[3];
494
495 v[2].xyz.x = fpoint(vertex3->x);
496 v[2].xyz.y = fpoint(vertex3->y);
497 v[2].xyz.z = fpoint(vertex3->z);
498 v[2].rgba.r = vertex3->c.col[0];
499 v[2].rgba.g = vertex3->c.col[1];
500 v[2].rgba.b = vertex3->c.col[2];
501 v[2].rgba.a = vertex3->c.col[3];
502
503 v[3].xyz.x = fpoint(vertex4->x);
504 v[3].xyz.y = fpoint(vertex4->y);
505 v[3].xyz.z = fpoint(vertex4->z);
506 v[3].rgba.r = vertex4->c.col[0];
507 v[3].rgba.g = vertex4->c.col[1];
508 v[3].rgba.b = vertex4->c.col[2];
509 v[3].rgba.a = vertex4->c.col[3];
510
511 if (CSTEXTURE==1) glDisableClientState(GL_TEXTURE_COORD_ARRAY);glError();
512 if (CSVERTEX==0) glEnableClientState(GL_VERTEX_ARRAY);glError();
513 if (CSCOLOR==0) glEnableClientState(GL_COLOR_ARRAY);glError();
514
515 glVertexPointer(3, GL_FLOAT, sizeof(v[0]), &v[0].xyz);glError();
516 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(v[0]), &v[0].rgba);glError();
517
518 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);glError();
519 CSTEXTURE=0;
520 CSVERTEX=CSCOLOR=1;
521 }
522
523 /////////////////////////////////////////////////////////
524
PRIMdrawFlatLine(OGLVertex * vertex1,OGLVertex * vertex2,OGLVertex * vertex3,OGLVertex * vertex4)525 void PRIMdrawFlatLine(OGLVertex* vertex1, OGLVertex* vertex2,OGLVertex* vertex3, OGLVertex* vertex4)
526 {
527 Vertex2 v[4];
528 if (vertex1->x==0&&vertex1->y==0&&vertex2->x==0&&vertex2->y==0&&vertex3->x==0&&vertex3->y==0&&vertex4->x==0&&vertex4->y==0) return;
529
530 v[0].xyz.x = fpoint(vertex1->x);
531 v[0].xyz.y = fpoint(vertex1->y);
532 v[0].xyz.z = fpoint(vertex1->z);
533 v[0].rgba.r = vertex1->c.col[0];
534 v[0].rgba.g = vertex1->c.col[1];
535 v[0].rgba.b = vertex1->c.col[2];
536 v[0].rgba.a = vertex1->c.col[3];
537
538 v[1].xyz.x = fpoint(vertex2->x);
539 v[1].xyz.y = fpoint(vertex2->y);
540 v[1].xyz.z = fpoint(vertex2->z);
541 v[1].rgba.r = vertex1->c.col[0];
542 v[1].rgba.g = vertex1->c.col[1];
543 v[1].rgba.b = vertex1->c.col[2];
544 v[1].rgba.a = vertex1->c.col[3];
545
546 v[2].xyz.x = fpoint(vertex4->x);
547 v[2].xyz.y = fpoint(vertex4->y);
548 v[2].xyz.z = fpoint(vertex4->z);
549 v[2].rgba.r = vertex1->c.col[0];
550 v[2].rgba.g = vertex1->c.col[1];
551 v[2].rgba.b = vertex1->c.col[2];
552 v[2].rgba.a = vertex1->c.col[3];
553
554 v[3].xyz.x = fpoint(vertex3->x);
555 v[3].xyz.y = fpoint(vertex3->y);
556 v[3].xyz.z = fpoint(vertex3->z);
557 v[3].rgba.r = vertex1->c.col[0];
558 v[3].rgba.g = vertex1->c.col[1];
559 v[3].rgba.b = vertex1->c.col[2];
560 v[3].rgba.a = vertex1->c.col[3];
561
562 if (CSTEXTURE==1) glDisableClientState(GL_TEXTURE_COORD_ARRAY);glError();
563 if (CSVERTEX==0) glEnableClientState(GL_VERTEX_ARRAY);glError();
564 if (CSCOLOR==0) glEnableClientState(GL_COLOR_ARRAY);glError();
565
566 glVertexPointer(3, GL_FLOAT, sizeof(v[0]), &v[0].xyz);glError();
567 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(v[0]), &v[0].rgba);glError();
568
569 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);glError();
570
571 CSTEXTURE=0;
572 CSVERTEX=CSCOLOR=1;
573
574
575 }
576
577 /////////////////////////////////////////////////////////
578
PRIMdrawGouraudLine(OGLVertex * vertex1,OGLVertex * vertex2,OGLVertex * vertex3,OGLVertex * vertex4)579 void PRIMdrawGouraudLine(OGLVertex* vertex1, OGLVertex* vertex2,OGLVertex* vertex3, OGLVertex* vertex4)
580 {
581 Vertex2 v[4];
582 if (vertex1->x==0&&vertex1->y==0&&vertex2->x==0&&vertex2->y==0&&vertex3->x==0&&vertex3->y==0&&vertex4->x==0&&vertex4->y==0) return;
583
584 v[0].xyz.x = fpoint(vertex1->x);
585 v[0].xyz.y = fpoint(vertex1->y);
586 v[0].xyz.z = fpoint(vertex1->z);
587 v[0].rgba.r = vertex1->c.col[0];
588 v[0].rgba.g = vertex1->c.col[1];
589 v[0].rgba.b = vertex1->c.col[2];
590 v[0].rgba.a = vertex1->c.col[3];
591
592 v[1].xyz.x = fpoint(vertex2->x);
593 v[1].xyz.y = fpoint(vertex2->y);
594 v[1].xyz.z = fpoint(vertex2->z);
595 v[1].rgba.r = vertex2->c.col[0];
596 v[1].rgba.g = vertex2->c.col[1];
597 v[1].rgba.b = vertex2->c.col[2];
598 v[1].rgba.a = vertex2->c.col[3];
599
600 v[3].xyz.x = fpoint(vertex3->x);
601 v[3].xyz.y = fpoint(vertex3->y);
602 v[3].xyz.z = fpoint(vertex3->z);
603 v[3].rgba.r = vertex3->c.col[0];
604 v[3].rgba.g = vertex3->c.col[1];
605 v[3].rgba.b = vertex3->c.col[2];
606 v[3].rgba.a = vertex3->c.col[3];
607
608 v[2].xyz.x = fpoint(vertex4->x);
609 v[2].xyz.y = fpoint(vertex4->y);
610 v[2].xyz.z = fpoint(vertex4->z);
611 v[2].rgba.r = vertex4->c.col[0];
612 v[2].rgba.g = vertex4->c.col[1];
613 v[2].rgba.b = vertex4->c.col[2];
614 v[2].rgba.a = vertex4->c.col[3];
615
616 if (CSTEXTURE==1) glDisableClientState(GL_TEXTURE_COORD_ARRAY);glError();
617 if (CSVERTEX==0) glEnableClientState(GL_VERTEX_ARRAY);glError();
618 if (CSCOLOR==0) glEnableClientState(GL_COLOR_ARRAY);glError();
619
620 glVertexPointer(3, GL_FLOAT, sizeof(v[0]), &v[0].xyz);glError();
621 glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(v[0]), &v[0].rgba);glError();
622
623 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);glError();
624 CSTEXTURE=0;
625 CSVERTEX=CSCOLOR=1;
626 }
627
628 /////////////////////////////////////////////////////////
629
PRIMdrawQuad(OGLVertex * vertex1,OGLVertex * vertex2,OGLVertex * vertex3,OGLVertex * vertex4)630 void PRIMdrawQuad(OGLVertex* vertex1, OGLVertex* vertex2,
631 OGLVertex* vertex3, OGLVertex* vertex4)
632 {
633 Vec3f v[4];
634 if (vertex1->x==0&&vertex1->y==0&&vertex2->x==0&&vertex2->y==0&&vertex3->x==0&&vertex3->y==0&&vertex4->x==0&&vertex4->y==0) return;
635
636 v[0].x = fpoint(vertex1->x);
637 v[0].y = fpoint(vertex1->y);
638 v[0].z = fpoint(vertex1->z);
639
640 v[1].x = fpoint(vertex2->x);
641 v[1].y = fpoint(vertex2->y);
642 v[1].z = fpoint(vertex2->z);
643
644 v[2].x = fpoint(vertex4->x);
645 v[2].y = fpoint(vertex4->y);
646 v[2].z = fpoint(vertex4->z);
647
648 v[3].x = fpoint(vertex3->x);
649 v[3].y = fpoint(vertex3->y);
650 v[3].z = fpoint(vertex3->z);
651
652 if (CSTEXTURE==1) glDisableClientState(GL_TEXTURE_COORD_ARRAY);glError();
653 if (CSVERTEX==0) glEnableClientState(GL_VERTEX_ARRAY);glError();
654 if (CSCOLOR==1) glDisableClientState(GL_COLOR_ARRAY);glError();
655
656 glVertexPointer(3, GL_FLOAT, sizeof(v[0]), &v[0]);glError();
657 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);glError();
658 CSTEXTURE=0;
659 CSVERTEX=1;
660 CSCOLOR=0;
661 }
662
663 ////////////////////////////////////////////////////////////////////////
664 // Transparent blending settings
665 ////////////////////////////////////////////////////////////////////////
666
667 static GLenum obm1=GL_ZERO;
668 static GLenum obm2=GL_ZERO;
669
670 typedef struct SEMITRANSTAG
671 {
672 GLenum srcFac;
673 GLenum dstFac;
674 GLubyte alpha;
675 } SemiTransParams;
676
677 SemiTransParams TransSets[4]=
678 {
679 {GL_SRC_ALPHA,GL_SRC_ALPHA, 127},
680 {GL_ONE, GL_ONE, 255},
681 {GL_ZERO, GL_ONE_MINUS_SRC_COLOR,255},
682 {GL_ONE_MINUS_SRC_ALPHA,GL_ONE, 192}
683 };
684
685 ////////////////////////////////////////////////////////////////////////
686
SetSemiTrans(void)687 void SetSemiTrans(void)
688 {
689 /*
690 * 0.5 x B + 0.5 x F
691 * 1.0 x B + 1.0 x F
692 * 1.0 x B - 1.0 x F
693 * 1.0 x B +0.25 x F
694 */
695
696 if(!DrawSemiTrans) // no semi trans at all?
697 {
698 if(bBlendEnable)
699 {glDisable(GL_BLEND);glError();bBlendEnable=FALSE;}// -> don't wanna blend
700 ubGloAlpha=ubGloColAlpha=255; // -> full alpha
701 return; // -> and bye
702 }
703
704 ubGloAlpha=ubGloColAlpha=TransSets[GlobalTextABR].alpha;
705
706 if(!bBlendEnable)
707 {glEnable(GL_BLEND);glError();bBlendEnable=TRUE;} // wanna blend
708
709 if(TransSets[GlobalTextABR].srcFac!=obm1 ||
710 TransSets[GlobalTextABR].dstFac!=obm2)
711 {
712 //if(glBlendEquationEXTEx==NULL)
713 {
714 obm1=TransSets[GlobalTextABR].srcFac;
715 obm2=TransSets[GlobalTextABR].dstFac;
716 glBlendFunc(obm1,obm2); glError(); // set blend func
717 }
718 /*else
719 if(TransSets[GlobalTextABR].dstFac !=GL_ONE_MINUS_SRC_COLOR)
720 {
721 if(obm2==GL_ONE_MINUS_SRC_COLOR)
722 glBlendEquationEXTEx(FUNC_ADD_EXT);
723 obm1=TransSets[GlobalTextABR].srcFac;
724 obm2=TransSets[GlobalTextABR].dstFac;
725 glBlendFunc(obm1,obm2); // set blend func
726 }
727 else
728 {
729 glBlendEquationEXTEx(FUNC_REVERSESUBTRACT_EXT);
730 obm1=TransSets[GlobalTextABR].srcFac;
731 obm2=TransSets[GlobalTextABR].dstFac;
732 glBlendFunc(GL_ONE,GL_ONE); // set blend func
733 }*/
734 }
735 }
736
SetScanTrans(void)737 void SetScanTrans(void) // blending for scan lines
738 {
739 /* if(glBlendEquationEXTEx!=NULL)
740 {
741 if(obm2==GL_ONE_MINUS_SRC_COLOR)
742 glBlendEquationEXTEx(FUNC_ADD_EXT);
743 }
744 */
745 obm1=TransSets[0].srcFac;
746 obm2=TransSets[0].dstFac;
747 glBlendFunc(obm1,obm2); glError(); // set blend func
748 }
749
SetScanTexTrans(void)750 void SetScanTexTrans(void) // blending for scan mask texture
751 {
752 /* if(glBlendEquationEXTEx!=NULL)
753 {
754 if(obm2==GL_ONE_MINUS_SRC_COLOR)
755 glBlendEquationEXTEx(FUNC_ADD_EXT);
756 }
757 */
758 obm1=TransSets[2].srcFac;
759 obm2=TransSets[2].dstFac;
760 glBlendFunc(obm1,obm2); glError(); // set blend func
761 }
762
763 ////////////////////////////////////////////////////////////////////////
764 // multi pass in old 'Advanced blending' mode... got it from Lewpy :)
765 ////////////////////////////////////////////////////////////////////////
766
767 SemiTransParams MultiTexTransSets[4][2]=
768 {
769 {
770 {GL_ONE ,GL_SRC_ALPHA, 127},
771 {GL_SRC_ALPHA,GL_ONE, 127}
772 },
773 {
774 {GL_ONE, GL_SRC_ALPHA, 255},
775 {GL_SRC_ALPHA,GL_ONE, 255}
776 },
777 {
778 {GL_ZERO, GL_ONE_MINUS_SRC_COLOR,255},
779 {GL_ZERO, GL_ONE_MINUS_SRC_COLOR,255}
780 },
781 {
782 {GL_SRC_ALPHA,GL_ONE, 127},
783 {GL_ONE_MINUS_SRC_ALPHA,GL_ONE, 255}
784 }
785 };
786
787 ////////////////////////////////////////////////////////////////////////
788
789 SemiTransParams MultiColTransSets[4]=
790 {
791 {GL_ONE_MINUS_SRC_ALPHA,GL_SRC_ALPHA,127},
792 {GL_ONE, GL_ONE, 255},
793 {GL_ZERO, GL_ONE_MINUS_SRC_COLOR,255},
794 {GL_SRC_ALPHA,GL_ONE, 127}
795 };
796
797 ////////////////////////////////////////////////////////////////////////
798
SetSemiTransMulti(int Pass)799 void SetSemiTransMulti(int Pass)
800 {
801 static GLenum bm1=GL_ZERO;
802 static GLenum bm2=GL_ONE;
803
804 ubGloAlpha=255;
805 ubGloColAlpha=255;
806
807 // are we enabling SemiTransparent mode?
808 if(DrawSemiTrans)
809 {
810 if(bDrawTextured)
811 {
812 bm1=MultiTexTransSets[GlobalTextABR][Pass].srcFac;
813 bm2=MultiTexTransSets[GlobalTextABR][Pass].dstFac;
814 ubGloAlpha=MultiTexTransSets[GlobalTextABR][Pass].alpha;
815 }
816 // no texture
817 else
818 {
819 bm1=MultiColTransSets[GlobalTextABR].srcFac;
820 bm2=MultiColTransSets[GlobalTextABR].dstFac;
821 ubGloColAlpha=MultiColTransSets[GlobalTextABR].alpha;
822 }
823 }
824 // no shading
825 else
826 {
827 if(Pass==0)
828 {
829 // disable blending
830 bm1=GL_ONE;bm2=GL_ZERO;
831 }
832 else
833 {
834 // disable blending, but add src col a second time
835 bm1=GL_ONE;bm2=GL_ONE;
836 }
837 }
838
839 if(!bBlendEnable)
840 {glEnable(GL_BLEND);glError();bBlendEnable=TRUE;} // wanna blend
841
842 if(bm1!=obm1 || bm2!=obm2)
843 {
844 glBlendFunc(bm1,bm2); glError(); // set blend func
845 obm1=bm1;obm2=bm2;
846 }
847 }
848
849 ////////////////////////////////////////////////////////////////////////
850 // Set several rendering stuff including blending
851 ////////////////////////////////////////////////////////////////////////
852
SetZMask3O(void)853 void SetZMask3O(void)
854 {
855 if(iUseMask && DrawSemiTrans && !iSetMask)
856 {
857 vertex[0].z=vertex[1].z=vertex[2].z=gl_z;
858 gl_z+=0.00004f;
859 }
860 }
861
SetZMask3(void)862 void SetZMask3(void)
863 {
864 if(iUseMask)
865 {
866 if(iSetMask || DrawSemiTrans)
867 {vertex[0].z=vertex[1].z=vertex[2].z=0.95f;}
868 else
869 {
870 vertex[0].z=vertex[1].z=vertex[2].z=gl_z;
871 gl_z+=0.00004f;
872 }
873 }
874 }
875
SetZMask3NT(void)876 void SetZMask3NT(void)
877 {
878 if(iUseMask)
879 {
880 if(iSetMask)
881 {vertex[0].z=vertex[1].z=vertex[2].z=0.95f;}
882 else
883 {
884 vertex[0].z=vertex[1].z=vertex[2].z=gl_z;
885 gl_z+=0.00004f;
886 }
887 }
888 }
889
890 ////////////////////////////////////////////////////////////////////////
891
SetZMask4O(void)892 void SetZMask4O(void)
893 {
894 if(iUseMask && DrawSemiTrans && !iSetMask)
895 {
896 vertex[0].z=vertex[1].z=vertex[2].z=vertex[3].z=gl_z;
897 gl_z+=0.00004f;
898 }
899 }
900
SetZMask4(void)901 void SetZMask4(void)
902 {
903 if(iUseMask)
904 {
905 if(iSetMask || DrawSemiTrans)
906 {vertex[0].z=vertex[1].z=vertex[2].z=vertex[3].z=0.95f;}
907 else
908 {
909 vertex[0].z=vertex[1].z=vertex[2].z=vertex[3].z=gl_z;
910 gl_z+=0.00004f;
911 }
912 }
913 }
914
SetZMask4NT(void)915 void SetZMask4NT(void)
916 {
917 if(iUseMask)
918 {
919 if(iSetMask==1)
920 {vertex[0].z=vertex[1].z=vertex[2].z=vertex[3].z=0.95f;}
921 else
922 {
923 vertex[0].z=vertex[1].z=vertex[2].z=vertex[3].z=gl_z;
924 gl_z+=0.00004f;
925 }
926 }
927 }
928
SetZMask4SP(void)929 void SetZMask4SP(void)
930 {
931 if(iUseMask)
932 {
933 if(iSetMask==1)
934 {vertex[0].z=vertex[1].z=vertex[2].z=vertex[3].z=0.95f;}
935 else
936 {
937 if(bCheckMask)
938 {
939 vertex[0].z=vertex[1].z=vertex[2].z=vertex[3].z=gl_z;
940 gl_z+=0.00004f;
941 }
942 else
943 {vertex[0].z=vertex[1].z=vertex[2].z=vertex[3].z=0.95f;}
944 }
945 }
946 }
947
948 ////////////////////////////////////////////////////////////////////////
949
SetRenderState(unsigned long DrawAttributes)950 void SetRenderState(unsigned long DrawAttributes)
951 {
952 bDrawNonShaded = (SHADETEXBIT(DrawAttributes)) ? TRUE : FALSE;
953 DrawSemiTrans = (SEMITRANSBIT(DrawAttributes)) ? TRUE : FALSE;
954 }
955
956 ////////////////////////////////////////////////////////////////////////
957
SetRenderColor(unsigned long DrawAttributes)958 void SetRenderColor(unsigned long DrawAttributes)
959 {
960 if(bDrawNonShaded) {g_m1=g_m2=g_m3=128;}
961 else
962 {
963 g_m1=DrawAttributes&0xff;
964 g_m2=(DrawAttributes>>8)&0xff;
965 g_m3=(DrawAttributes>>16)&0xff;
966 }
967 }
968
969 ////////////////////////////////////////////////////////////////////////
970
SetRenderMode(unsigned long DrawAttributes,BOOL bSCol)971 void SetRenderMode(unsigned long DrawAttributes,BOOL bSCol)
972 {
973 if((bUseMultiPass) && (bDrawTextured) && !(bDrawNonShaded))
974 {bDrawMultiPass = TRUE; SetSemiTransMulti(0);}
975 else {bDrawMultiPass = FALSE;SetSemiTrans();}
976
977 if(bDrawTextured) // texture ? build it/get it from cache
978 {
979 GLuint currTex;
980 if(bUsingTWin) currTex=LoadTextureWnd(GlobalTexturePage,GlobalTextTP, ulClutID);
981 else if(bUsingMovie) currTex=LoadTextureMovie();
982 else currTex=SelectSubTextureS(GlobalTextTP,ulClutID);
983
984 if(gTexName!=currTex)
985 {gTexName=currTex;glBindTexture(GL_TEXTURE_2D,currTex); glError();}
986
987 if(!bTexEnabled) // -> turn texturing on
988 {bTexEnabled=TRUE;glEnable(GL_TEXTURE_2D); glError();}
989 }
990 else // no texture ?
991 if(bTexEnabled)
992 {bTexEnabled=FALSE;glDisable(GL_TEXTURE_2D); glError();} // -> turn texturing off
993
994 if(bSCol) // also set color ?
995 {
996 if((dwActFixes&4) && ((DrawAttributes&0x00ffffff)==0))
997 DrawAttributes|=0x007f7f7f;
998
999 if(bDrawNonShaded) // -> non shaded?
1000 {
1001 /* if(bGLBlend) vertex[0].c.lcol=0x7f7f7f; // --> solid color...
1002 else */vertex[0].c.lcol=0xffffff;
1003 }
1004 else // -> shaded?
1005 {
1006 // if(!bUseMultiPass && !bGLBlend) // --> given color...
1007 vertex[0].c.lcol=DoubleBGR2RGB(DrawAttributes);
1008 // else vertex[0].c.lcol=DrawAttributes;
1009 }
1010 vertex[0].c.col[3]=ubGloAlpha; // -> set color with
1011 SETCOL(vertex[0]); // texture alpha
1012 }
1013
1014 if(bDrawSmoothShaded!=bOldSmoothShaded) // shading changed?
1015 {
1016 if(bDrawSmoothShaded) glShadeModel(GL_SMOOTH); // -> set actual shading
1017 else glShadeModel(GL_FLAT);
1018 glError();
1019 bOldSmoothShaded=bDrawSmoothShaded;
1020 }
1021 }
1022
1023 ////////////////////////////////////////////////////////////////////////
1024 // Set Opaque multipass color
1025 ////////////////////////////////////////////////////////////////////////
1026
SetOpaqueColor(unsigned long DrawAttributes)1027 void SetOpaqueColor(unsigned long DrawAttributes)
1028 {
1029 if(bDrawNonShaded) return; // no shading? bye
1030
1031 DrawAttributes=DoubleBGR2RGB(DrawAttributes); // multipass is just half color, so double it on opaque pass
1032 vertex[0].c.lcol=DrawAttributes|0xff000000;
1033 SETCOL(vertex[0]); // set color
1034 }
1035
1036 ////////////////////////////////////////////////////////////////////////
1037 // Fucking stupid screen coord checking
1038 ////////////////////////////////////////////////////////////////////////
1039
ClipVertexListScreen(void)1040 BOOL ClipVertexListScreen(void)
1041 {
1042 if (lx0 >= PSXDisplay.DisplayEnd.x) goto NEXTSCRTEST;
1043 if (ly0 >= PSXDisplay.DisplayEnd.y) goto NEXTSCRTEST;
1044 if (lx2 < PSXDisplay.DisplayPosition.x) goto NEXTSCRTEST;
1045 if (ly2 < PSXDisplay.DisplayPosition.y) goto NEXTSCRTEST;
1046
1047 return TRUE;
1048
1049 NEXTSCRTEST:
1050 if(PSXDisplay.InterlacedTest) return FALSE;
1051
1052 if (lx0 >= PreviousPSXDisplay.DisplayEnd.x) return FALSE;
1053 if (ly0 >= PreviousPSXDisplay.DisplayEnd.y) return FALSE;
1054 if (lx2 < PreviousPSXDisplay.DisplayPosition.x) return FALSE;
1055 if (ly2 < PreviousPSXDisplay.DisplayPosition.y) return FALSE;
1056
1057 return TRUE;
1058 }
1059
1060 ////////////////////////////////////////////////////////////////////////
1061
bDrawOffscreenFront(void)1062 BOOL bDrawOffscreenFront(void)
1063 {
1064 if(sxmin < PSXDisplay.DisplayPosition.x) return FALSE; // must be complete in front
1065 if(symin < PSXDisplay.DisplayPosition.y) return FALSE;
1066 if(sxmax > PSXDisplay.DisplayEnd.x) return FALSE;
1067 if(symax > PSXDisplay.DisplayEnd.y) return FALSE;
1068 return TRUE;
1069 }
1070
bOnePointInFront(void)1071 BOOL bOnePointInFront(void)
1072 {
1073 if(sxmax< PSXDisplay.DisplayPosition.x)
1074 return FALSE;
1075
1076 if(symax< PSXDisplay.DisplayPosition.y)
1077 return FALSE;
1078
1079 if(sxmin>=PSXDisplay.DisplayEnd.x)
1080 return FALSE;
1081
1082 if(symin>=PSXDisplay.DisplayEnd.y)
1083 return FALSE;
1084
1085 return TRUE;
1086 }
1087
1088
bOnePointInBack(void)1089 BOOL bOnePointInBack(void)
1090 {
1091 if(sxmax< PreviousPSXDisplay.DisplayPosition.x)
1092 return FALSE;
1093
1094 if(symax< PreviousPSXDisplay.DisplayPosition.y)
1095 return FALSE;
1096
1097 if(sxmin>=PreviousPSXDisplay.DisplayEnd.x)
1098 return FALSE;
1099
1100 if(symin>=PreviousPSXDisplay.DisplayEnd.y)
1101 return FALSE;
1102
1103 return TRUE;
1104 }
1105
bDrawOffscreen4(void)1106 BOOL bDrawOffscreen4(void)
1107 {
1108 BOOL bFront;short sW,sH;
1109
1110 sxmax=max(lx0,max(lx1,max(lx2,lx3)));
1111 if(sxmax<drawX) return FALSE;
1112 sxmin=min(lx0,min(lx1,min(lx2,lx3)));
1113 if(sxmin>drawW) return FALSE;
1114 symax=max(ly0,max(ly1,max(ly2,ly3)));
1115 if(symax<drawY) return FALSE;
1116 symin=min(ly0,min(ly1,min(ly2,ly3)));
1117 if(symin>drawH) return FALSE;
1118
1119 if(PSXDisplay.Disabled) return TRUE; // disabled? ever
1120
1121 if(iOffscreenDrawing==1) return bFullVRam;
1122
1123 if(dwActFixes&1 && iOffscreenDrawing==4)
1124 {
1125 if(PreviousPSXDisplay.DisplayPosition.x==PSXDisplay.DisplayPosition.x &&
1126 PreviousPSXDisplay.DisplayPosition.y==PSXDisplay.DisplayPosition.y &&
1127 PreviousPSXDisplay.DisplayEnd.x==PSXDisplay.DisplayEnd.x &&
1128 PreviousPSXDisplay.DisplayEnd.y==PSXDisplay.DisplayEnd.y)
1129 {
1130 bRenderFrontBuffer=TRUE;
1131 return FALSE;
1132 }
1133 }
1134
1135 sW=drawW-1;sH=drawH-1;
1136
1137 sxmin=min(sW,max(sxmin,drawX));
1138 sxmax=max(drawX,min(sxmax,sW));
1139 symin=min(sH,max(symin,drawY));
1140 symax=max(drawY,min(symax,sH));
1141
1142 if(bOnePointInBack()) return bFullVRam;
1143
1144 if(iOffscreenDrawing==2)
1145 bFront=bDrawOffscreenFront();
1146 else bFront=bOnePointInFront();
1147
1148 if(bFront)
1149 {
1150 if(PSXDisplay.InterlacedTest) return bFullVRam; // -> ok, no need for adjust
1151
1152 vertex[0].x=lx0 - PSXDisplay.DisplayPosition.x+PreviousPSXDisplay.Range.x0;
1153 vertex[1].x=lx1 - PSXDisplay.DisplayPosition.x+PreviousPSXDisplay.Range.x0;
1154 vertex[2].x=lx2 - PSXDisplay.DisplayPosition.x+PreviousPSXDisplay.Range.x0;
1155 vertex[3].x=lx3 - PSXDisplay.DisplayPosition.x+PreviousPSXDisplay.Range.x0;
1156 vertex[0].y=ly0 - PSXDisplay.DisplayPosition.y+PreviousPSXDisplay.Range.y0;
1157 vertex[1].y=ly1 - PSXDisplay.DisplayPosition.y+PreviousPSXDisplay.Range.y0;
1158 vertex[2].y=ly2 - PSXDisplay.DisplayPosition.y+PreviousPSXDisplay.Range.y0;
1159 vertex[3].y=ly3 - PSXDisplay.DisplayPosition.y+PreviousPSXDisplay.Range.y0;
1160
1161 if(iOffscreenDrawing==4 && !(dwActFixes&1)) // -> frontbuffer wanted
1162 {
1163 bRenderFrontBuffer=TRUE;
1164 //return TRUE;
1165 }
1166 return bFullVRam; // -> but no od
1167 }
1168
1169 return TRUE;
1170 }
1171
1172 ////////////////////////////////////////////////////////////////////////
1173
bDrawOffscreen3(void)1174 BOOL bDrawOffscreen3(void)
1175 {
1176 BOOL bFront;short sW,sH;
1177
1178 sxmax=max(lx0,max(lx1,lx2));
1179 if(sxmax<drawX) return FALSE;
1180 sxmin=min(lx0,min(lx1,lx2));
1181 if(sxmin>drawW) return FALSE;
1182 symax=max(ly0,max(ly1,ly2));
1183 if(symax<drawY) return FALSE;
1184 symin=min(ly0,min(ly1,ly2));
1185 if(symin>drawH) return FALSE;
1186
1187 if(PSXDisplay.Disabled) return TRUE; // disabled? ever
1188
1189 if(iOffscreenDrawing==1) return bFullVRam;
1190
1191 sW=drawW-1;sH=drawH-1;
1192 sxmin=min(sW,max(sxmin,drawX));
1193 sxmax=max(drawX,min(sxmax,sW));
1194 symin=min(sH,max(symin,drawY));
1195 symax=max(drawY,min(symax,sH));
1196
1197 if(bOnePointInBack()) return bFullVRam;
1198
1199 if(iOffscreenDrawing==2)
1200 bFront=bDrawOffscreenFront();
1201 else bFront=bOnePointInFront();
1202
1203 if(bFront)
1204 {
1205 if(PSXDisplay.InterlacedTest) return bFullVRam; // -> ok, no need for adjust
1206
1207 vertex[0].x=lx0 - PSXDisplay.DisplayPosition.x+PreviousPSXDisplay.Range.x0;
1208 vertex[1].x=lx1 - PSXDisplay.DisplayPosition.x+PreviousPSXDisplay.Range.x0;
1209 vertex[2].x=lx2 - PSXDisplay.DisplayPosition.x+PreviousPSXDisplay.Range.x0;
1210 vertex[0].y=ly0 - PSXDisplay.DisplayPosition.y+PreviousPSXDisplay.Range.y0;
1211 vertex[1].y=ly1 - PSXDisplay.DisplayPosition.y+PreviousPSXDisplay.Range.y0;
1212 vertex[2].y=ly2 - PSXDisplay.DisplayPosition.y+PreviousPSXDisplay.Range.y0;
1213
1214 if(iOffscreenDrawing==4) // -> frontbuffer wanted
1215 {
1216 bRenderFrontBuffer=TRUE;
1217 // return TRUE;
1218 }
1219
1220 return bFullVRam; // -> but no od
1221 }
1222
1223 return TRUE;
1224 }
1225
1226 ////////////////////////////////////////////////////////////////////////
1227
FastCheckAgainstScreen(short imageX0,short imageY0,short imageX1,short imageY1)1228 BOOL FastCheckAgainstScreen(short imageX0,short imageY0,short imageX1,short imageY1)
1229 {
1230 PSXRect_t xUploadArea;
1231
1232 imageX1 += imageX0;
1233 imageY1 += imageY0;
1234
1235 if (imageX0 < PreviousPSXDisplay.DisplayPosition.x)
1236 xUploadArea.x0 = PreviousPSXDisplay.DisplayPosition.x;
1237 else
1238 if (imageX0 > PreviousPSXDisplay.DisplayEnd.x)
1239 xUploadArea.x0 = PreviousPSXDisplay.DisplayEnd.x;
1240 else
1241 xUploadArea.x0 = imageX0;
1242
1243 if(imageX1 < PreviousPSXDisplay.DisplayPosition.x)
1244 xUploadArea.x1 = PreviousPSXDisplay.DisplayPosition.x;
1245 else
1246 if (imageX1 > PreviousPSXDisplay.DisplayEnd.x)
1247 xUploadArea.x1 = PreviousPSXDisplay.DisplayEnd.x;
1248 else
1249 xUploadArea.x1 = imageX1;
1250
1251 if (imageY0 < PreviousPSXDisplay.DisplayPosition.y)
1252 xUploadArea.y0 = PreviousPSXDisplay.DisplayPosition.y;
1253 else
1254 if (imageY0 > PreviousPSXDisplay.DisplayEnd.y)
1255 xUploadArea.y0 = PreviousPSXDisplay.DisplayEnd.y;
1256 else
1257 xUploadArea.y0 = imageY0;
1258
1259 if (imageY1 < PreviousPSXDisplay.DisplayPosition.y)
1260 xUploadArea.y1 = PreviousPSXDisplay.DisplayPosition.y;
1261 else
1262 if (imageY1 > PreviousPSXDisplay.DisplayEnd.y)
1263 xUploadArea.y1 = PreviousPSXDisplay.DisplayEnd.y;
1264 else
1265 xUploadArea.y1 = imageY1;
1266
1267 if ((xUploadArea.x0 != xUploadArea.x1) && (xUploadArea.y0 != xUploadArea.y1))
1268 return TRUE;
1269 else return FALSE;
1270 }
1271
CheckAgainstScreen(short imageX0,short imageY0,short imageX1,short imageY1)1272 BOOL CheckAgainstScreen(short imageX0,short imageY0,short imageX1,short imageY1)
1273 {
1274 imageX1 += imageX0;
1275 imageY1 += imageY0;
1276
1277 if (imageX0 < PreviousPSXDisplay.DisplayPosition.x)
1278 xrUploadArea.x0 = PreviousPSXDisplay.DisplayPosition.x;
1279 else
1280 if (imageX0 > PreviousPSXDisplay.DisplayEnd.x)
1281 xrUploadArea.x0 = PreviousPSXDisplay.DisplayEnd.x;
1282 else
1283 xrUploadArea.x0 = imageX0;
1284
1285 if(imageX1 < PreviousPSXDisplay.DisplayPosition.x)
1286 xrUploadArea.x1 = PreviousPSXDisplay.DisplayPosition.x;
1287 else
1288 if (imageX1 > PreviousPSXDisplay.DisplayEnd.x)
1289 xrUploadArea.x1 = PreviousPSXDisplay.DisplayEnd.x;
1290 else
1291 xrUploadArea.x1 = imageX1;
1292
1293 if (imageY0 < PreviousPSXDisplay.DisplayPosition.y)
1294 xrUploadArea.y0 = PreviousPSXDisplay.DisplayPosition.y;
1295 else
1296 if (imageY0 > PreviousPSXDisplay.DisplayEnd.y)
1297 xrUploadArea.y0 = PreviousPSXDisplay.DisplayEnd.y;
1298 else
1299 xrUploadArea.y0 = imageY0;
1300
1301 if (imageY1 < PreviousPSXDisplay.DisplayPosition.y)
1302 xrUploadArea.y1 = PreviousPSXDisplay.DisplayPosition.y;
1303 else
1304 if (imageY1 > PreviousPSXDisplay.DisplayEnd.y)
1305 xrUploadArea.y1 = PreviousPSXDisplay.DisplayEnd.y;
1306 else
1307 xrUploadArea.y1 = imageY1;
1308
1309 if ((xrUploadArea.x0 != xrUploadArea.x1) && (xrUploadArea.y0 != xrUploadArea.y1))
1310 return TRUE;
1311 else return FALSE;
1312 }
1313
FastCheckAgainstFrontScreen(short imageX0,short imageY0,short imageX1,short imageY1)1314 BOOL FastCheckAgainstFrontScreen(short imageX0,short imageY0,short imageX1,short imageY1)
1315 {
1316 PSXRect_t xUploadArea;
1317
1318 imageX1 += imageX0;
1319 imageY1 += imageY0;
1320
1321 if (imageX0 < PSXDisplay.DisplayPosition.x)
1322 xUploadArea.x0 = PSXDisplay.DisplayPosition.x;
1323 else
1324 if (imageX0 > PSXDisplay.DisplayEnd.x)
1325 xUploadArea.x0 = PSXDisplay.DisplayEnd.x;
1326 else
1327 xUploadArea.x0 = imageX0;
1328
1329 if(imageX1 < PSXDisplay.DisplayPosition.x)
1330 xUploadArea.x1 = PSXDisplay.DisplayPosition.x;
1331 else
1332 if (imageX1 > PSXDisplay.DisplayEnd.x)
1333 xUploadArea.x1 = PSXDisplay.DisplayEnd.x;
1334 else
1335 xUploadArea.x1 = imageX1;
1336
1337 if (imageY0 < PSXDisplay.DisplayPosition.y)
1338 xUploadArea.y0 = PSXDisplay.DisplayPosition.y;
1339 else
1340 if (imageY0 > PSXDisplay.DisplayEnd.y)
1341 xUploadArea.y0 = PSXDisplay.DisplayEnd.y;
1342 else
1343 xUploadArea.y0 = imageY0;
1344
1345 if (imageY1 < PSXDisplay.DisplayPosition.y)
1346 xUploadArea.y1 = PSXDisplay.DisplayPosition.y;
1347 else
1348 if (imageY1 > PSXDisplay.DisplayEnd.y)
1349 xUploadArea.y1 = PSXDisplay.DisplayEnd.y;
1350 else
1351 xUploadArea.y1 = imageY1;
1352
1353 if ((xUploadArea.x0 != xUploadArea.x1) && (xUploadArea.y0 != xUploadArea.y1))
1354 return TRUE;
1355 else return FALSE;
1356 }
1357
CheckAgainstFrontScreen(short imageX0,short imageY0,short imageX1,short imageY1)1358 BOOL CheckAgainstFrontScreen(short imageX0,short imageY0,short imageX1,short imageY1)
1359 {
1360 imageX1 += imageX0;
1361 imageY1 += imageY0;
1362
1363 if (imageX0 < PSXDisplay.DisplayPosition.x)
1364 xrUploadArea.x0 = PSXDisplay.DisplayPosition.x;
1365 else
1366 if (imageX0 > PSXDisplay.DisplayEnd.x)
1367 xrUploadArea.x0 = PSXDisplay.DisplayEnd.x;
1368 else
1369 xrUploadArea.x0 = imageX0;
1370
1371 if(imageX1 < PSXDisplay.DisplayPosition.x)
1372 xrUploadArea.x1 = PSXDisplay.DisplayPosition.x;
1373 else
1374 if (imageX1 > PSXDisplay.DisplayEnd.x)
1375 xrUploadArea.x1 = PSXDisplay.DisplayEnd.x;
1376 else
1377 xrUploadArea.x1 = imageX1;
1378
1379 if (imageY0 < PSXDisplay.DisplayPosition.y)
1380 xrUploadArea.y0 = PSXDisplay.DisplayPosition.y;
1381 else
1382 if (imageY0 > PSXDisplay.DisplayEnd.y)
1383 xrUploadArea.y0 = PSXDisplay.DisplayEnd.y;
1384 else
1385 xrUploadArea.y0 = imageY0;
1386
1387 if (imageY1 < PSXDisplay.DisplayPosition.y)
1388 xrUploadArea.y1 = PSXDisplay.DisplayPosition.y;
1389 else
1390 if (imageY1 > PSXDisplay.DisplayEnd.y)
1391 xrUploadArea.y1 = PSXDisplay.DisplayEnd.y;
1392 else
1393 xrUploadArea.y1 = imageY1;
1394
1395 if ((xrUploadArea.x0 != xrUploadArea.x1) && (xrUploadArea.y0 != xrUploadArea.y1))
1396 return TRUE;
1397 else return FALSE;
1398 }
1399
1400 ////////////////////////////////////////////////////////////////////////
1401
PrepareFullScreenUpload(long Position)1402 void PrepareFullScreenUpload (long Position)
1403 {
1404 if (Position==-1) // rgb24
1405 {
1406 if(PSXDisplay.Interlaced)
1407 {
1408 xrUploadArea.x0 = PSXDisplay.DisplayPosition.x;
1409 xrUploadArea.x1 = PSXDisplay.DisplayEnd.x;
1410 xrUploadArea.y0 = PSXDisplay.DisplayPosition.y;
1411 xrUploadArea.y1 = PSXDisplay.DisplayEnd.y;
1412 }
1413 else
1414 {
1415 xrUploadArea.x0 = PreviousPSXDisplay.DisplayPosition.x;
1416 xrUploadArea.x1 = PreviousPSXDisplay.DisplayEnd.x;
1417 xrUploadArea.y0 = PreviousPSXDisplay.DisplayPosition.y;
1418 xrUploadArea.y1 = PreviousPSXDisplay.DisplayEnd.y;
1419 }
1420
1421 if(bNeedRGB24Update)
1422 {
1423 if(lClearOnSwap)
1424 {
1425 // lClearOnSwap=0;
1426 }
1427 else
1428 if(PSXDisplay.Interlaced && PreviousPSXDisplay.RGB24<2) // in interlaced mode we upload at least two full frames (GT1 menu)
1429 {
1430 PreviousPSXDisplay.RGB24++;
1431 }
1432 else
1433 {
1434 xrUploadArea.y1 = min(xrUploadArea.y0+xrUploadAreaRGB24.y1,xrUploadArea.y1);
1435 xrUploadArea.y0+=xrUploadAreaRGB24.y0;
1436 }
1437 }
1438 }
1439 else
1440 if (Position)
1441 {
1442 xrUploadArea.x0 = PSXDisplay.DisplayPosition.x;
1443 xrUploadArea.x1 = PSXDisplay.DisplayEnd.x;
1444 xrUploadArea.y0 = PSXDisplay.DisplayPosition.y;
1445 xrUploadArea.y1 = PSXDisplay.DisplayEnd.y;
1446 }
1447 else
1448 {
1449 xrUploadArea.x0 = PreviousPSXDisplay.DisplayPosition.x;
1450 xrUploadArea.x1 = PreviousPSXDisplay.DisplayEnd.x;
1451 xrUploadArea.y0 = PreviousPSXDisplay.DisplayPosition.y;
1452 xrUploadArea.y1 = PreviousPSXDisplay.DisplayEnd.y;
1453 }
1454
1455 if (xrUploadArea.x0 < 0) xrUploadArea.x0 = 0;
1456 else
1457 if (xrUploadArea.x0 > 1023) xrUploadArea.x0 = 1023;
1458
1459 if (xrUploadArea.x1 < 0) xrUploadArea.x1 = 0;
1460 else
1461 if (xrUploadArea.x1 > 1024) xrUploadArea.x1 = 1024;
1462
1463 if (xrUploadArea.y0 < 0) xrUploadArea.y0 = 0;
1464 else
1465 if (xrUploadArea.y0 > iGPUHeightMask) xrUploadArea.y0 = iGPUHeightMask;
1466
1467 if (xrUploadArea.y1 < 0) xrUploadArea.y1 = 0;
1468 else
1469 if (xrUploadArea.y1 > iGPUHeight) xrUploadArea.y1 = iGPUHeight;
1470
1471 if (PSXDisplay.RGB24)
1472 {
1473 InvalidateTextureArea(xrUploadArea.x0,xrUploadArea.y0,xrUploadArea.x1-xrUploadArea.x0,xrUploadArea.y1-xrUploadArea.y0);
1474 }
1475 }
1476
1477 ////////////////////////////////////////////////////////////////////////
1478 // Upload screen (MDEC and such)
1479 ////////////////////////////////////////////////////////////////////////
1480 ////////////////////////////////////////////////////////////////////////
1481
1482 unsigned char * LoadDirectMovieFast(void);
1483
UploadScreenEx(long Position)1484 void UploadScreenEx(long Position)
1485 {
1486 short ya,yb,xa,xb,x, y, YStep, XStep, U, UStep,ux[4],vy[4];
1487
1488 if(!PSXDisplay.DisplayMode.x) return;
1489 if(!PSXDisplay.DisplayMode.y) return;
1490
1491 glDisable(GL_SCISSOR_TEST); glError();
1492 glShadeModel(GL_FLAT); glError();
1493 bOldSmoothShaded=FALSE;
1494 glDisable(GL_BLEND); glError();
1495 bBlendEnable=FALSE;
1496 glDisable(GL_TEXTURE_2D); glError();
1497 bTexEnabled=FALSE;
1498 glDisable(GL_ALPHA_TEST); glError();
1499
1500 //glPixelZoom(((float)rRatioRect.right)/((float)PSXDisplay.DisplayMode.x),
1501 // -1.0f*(((float)rRatioRect.bottom)/((float)PSXDisplay.DisplayMode.y)));
1502
1503 //----------------------------------------------------//
1504
1505 YStep = 256; // max texture size
1506 XStep = 256;
1507 UStep = (PSXDisplay.RGB24 ? 128 : 0);
1508 ya = xrUploadArea.y0;
1509 yb = xrUploadArea.y1;
1510 xa = xrUploadArea.x0;
1511 xb = xrUploadArea.x1;
1512
1513 for(y=ya;y<=yb;y+=YStep) // loop y
1514 {
1515 U = 0;
1516 for(x=xa;x<=xb;x+=XStep) // loop x
1517 {
1518 ly0 = ly1 = y; // -> get y coords
1519 ly2 = y + YStep;
1520 if (ly2 > yb) ly2 = yb;
1521 ly3 = ly2;
1522
1523 lx0 = lx3 = x; // -> get x coords
1524 lx1 = x + XStep;
1525 if (lx1 > xb) lx1 = xb;
1526
1527 lx2 = lx1;
1528
1529 ux[0]=ux[3]=(xa - x); // -> set tex x coords
1530 if (ux[0] < 0) ux[0]=ux[3]=0;
1531 ux[2]=ux[1]=(xb - x);
1532 if (ux[2] > 256) ux[2]=ux[1]=256;
1533
1534 vy[0]=vy[1]=(ya - y); // -> set tex y coords
1535 if (vy[0] < 0) vy[0]=vy[1]=0;
1536 vy[2]=vy[3]=(yb - y);
1537 if (vy[2] > 256) vy[2]=vy[3]=256;
1538
1539 if ((ux[0] >= ux[2]) || // -> cheaters never win...
1540 (vy[0] >= vy[2])) continue; // (but winners always cheat...)
1541
1542 xrMovieArea.x0=lx0+U; xrMovieArea.y0=ly0;
1543 xrMovieArea.x1=lx2+U; xrMovieArea.y1=ly2;
1544
1545 offsetScreenUpload(Position);
1546
1547 //glRasterPos2f(vertex[0].x,vertex[0].y);
1548
1549 //glDrawPixels(xrMovieArea.x1-xrMovieArea.x0,
1550 // xrMovieArea.y1-xrMovieArea.y0,
1551 // GL_RGBA,GL_UNSIGNED_BYTE,
1552 LoadDirectMovieFast();//);
1553
1554 U+=UStep;
1555 }
1556 }
1557
1558 //----------------------------------------------------//
1559
1560 // glPixelZoom(1.0F,1.0F);
1561
1562 glEnable(GL_ALPHA_TEST); glError();
1563 glEnable(GL_SCISSOR_TEST); glError();
1564 }
1565
1566 ////////////////////////////////////////////////////////////////////////
1567
UploadScreen(long Position)1568 void UploadScreen(long Position)
1569 {
1570 short x, y, YStep, XStep, U, s, UStep,ux[4],vy[4];
1571 short xa,xb,ya,yb;
1572
1573 if(xrUploadArea.x0>1023) xrUploadArea.x0=1023;
1574 if(xrUploadArea.x1>1024) xrUploadArea.x1=1024;
1575 if(xrUploadArea.y0>iGPUHeightMask) xrUploadArea.y0=iGPUHeightMask;
1576 if(xrUploadArea.y1>iGPUHeight) xrUploadArea.y1=iGPUHeight;
1577
1578 if(xrUploadArea.x0==xrUploadArea.x1) return;
1579 if(xrUploadArea.y0==xrUploadArea.y1) return;
1580
1581 if(PSXDisplay.Disabled && iOffscreenDrawing<4) return;
1582
1583 iDrawnSomething = 2;
1584 iLastRGB24=PSXDisplay.RGB24+1;
1585
1586 if(bSkipNextFrame) return;
1587
1588 if(dwActFixes & 2) {UploadScreenEx(Position);return;}
1589
1590 bUsingMovie = TRUE;
1591 bDrawTextured = TRUE; // just doing textures
1592 bDrawSmoothShaded = FALSE;
1593
1594 /* if(bGLBlend) vertex[0].c.lcol=0xff7f7f7f; // set solid col
1595 else */vertex[0].c.lcol=0xffffffff;
1596 SETCOL(vertex[0]);
1597
1598 SetOGLDisplaySettings(0);
1599
1600 YStep = 256; // max texture size
1601 XStep = 256;
1602
1603 UStep = (PSXDisplay.RGB24 ? 128 : 0);
1604
1605 ya=xrUploadArea.y0;
1606 yb=xrUploadArea.y1;
1607 xa=xrUploadArea.x0;
1608 xb=xrUploadArea.x1;
1609
1610 for(y=ya;y<=yb;y+=YStep) // loop y
1611 {
1612 U = 0;
1613 for(x=xa;x<=xb;x+=XStep) // loop x
1614 {
1615 ly0 = ly1 = y; // -> get y coords
1616 ly2 = y + YStep;
1617 if (ly2 > yb) ly2 = yb;
1618 ly3 = ly2;
1619
1620 lx0 = lx3 = x; // -> get x coords
1621 lx1 = x + XStep;
1622 if (lx1 > xb) lx1 = xb;
1623
1624 lx2 = lx1;
1625
1626 ux[0]=ux[3]=(xa - x); // -> set tex x coords
1627 if (ux[0] < 0) ux[0]=ux[3]=0;
1628 ux[2]=ux[1]=(xb - x);
1629 if (ux[2] > 256) ux[2]=ux[1]=256;
1630
1631 vy[0]=vy[1]=(ya - y); // -> set tex y coords
1632 if (vy[0] < 0) vy[0]=vy[1]=0;
1633 vy[2]=vy[3]=(yb - y);
1634 if (vy[2] > 256) vy[2]=vy[3]=256;
1635
1636 if ((ux[0] >= ux[2]) || // -> cheaters never win...
1637 (vy[0] >= vy[2])) continue; // (but winners always cheat...)
1638
1639 xrMovieArea.x0=lx0+U; xrMovieArea.y0=ly0;
1640 xrMovieArea.x1=lx2+U; xrMovieArea.y1=ly2;
1641
1642 s=ux[2] - ux[0]; if(s>255) s=255;
1643
1644 gl_ux[2] = gl_ux[1] = s;
1645 s=vy[2] - vy[0]; if(s>255) s=255;
1646 gl_vy[2] = gl_vy[3] = s;
1647 gl_ux[0] = gl_ux[3] = gl_vy[0] = gl_vy[1] = 0;
1648
1649 SetRenderState((unsigned long)0x01000000);
1650 SetRenderMode((unsigned long)0x01000000, FALSE); // upload texture data
1651 offsetScreenUpload(Position);
1652 assignTextureVRAMWrite();
1653
1654 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
1655
1656 U+=UStep;
1657 }
1658 }
1659
1660 bUsingMovie=FALSE; // done...
1661 bDisplayNotSet = TRUE;
1662 }
1663
1664 ////////////////////////////////////////////////////////////////////////
1665 // Detect next screen
1666 ////////////////////////////////////////////////////////////////////////
1667
IsCompleteInsideNextScreen(short x,short y,short xoff,short yoff)1668 BOOL IsCompleteInsideNextScreen(short x, short y, short xoff, short yoff)
1669 {
1670 if (x > PSXDisplay.DisplayPosition.x+1) return FALSE;
1671 if ((x + xoff) < PSXDisplay.DisplayEnd.x-1) return FALSE;
1672 yoff+=y;
1673 if (y >= PSXDisplay.DisplayPosition.y &&
1674 y <= PSXDisplay.DisplayEnd.y )
1675 {
1676 if ((yoff) >= PSXDisplay.DisplayPosition.y &&
1677 (yoff) <= PSXDisplay.DisplayEnd.y ) return TRUE;
1678 }
1679 if (y > PSXDisplay.DisplayPosition.y+1) return FALSE;
1680 if (yoff < PSXDisplay.DisplayEnd.y-1) return FALSE;
1681 return TRUE;
1682 }
1683
IsPrimCompleteInsideNextScreen(short x,short y,short xoff,short yoff)1684 BOOL IsPrimCompleteInsideNextScreen(short x, short y, short xoff, short yoff)
1685 {
1686 x+=PSXDisplay.DrawOffset.x;
1687 if (x > PSXDisplay.DisplayPosition.x+1) return FALSE;
1688 y+=PSXDisplay.DrawOffset.y;
1689 if (y > PSXDisplay.DisplayPosition.y+1) return FALSE;
1690 xoff+=PSXDisplay.DrawOffset.x;
1691 if (xoff < PSXDisplay.DisplayEnd.x-1) return FALSE;
1692 yoff+=PSXDisplay.DrawOffset.y;
1693 if (yoff < PSXDisplay.DisplayEnd.y-1) return FALSE;
1694 return TRUE;
1695 }
1696
IsInsideNextScreen(short x,short y,short xoff,short yoff)1697 BOOL IsInsideNextScreen(short x, short y, short xoff, short yoff)
1698 {
1699 if (x > PSXDisplay.DisplayEnd.x) return FALSE;
1700 if (y > PSXDisplay.DisplayEnd.y) return FALSE;
1701 if ((x + xoff) < PSXDisplay.DisplayPosition.x) return FALSE;
1702 if ((y + yoff) < PSXDisplay.DisplayPosition.y) return FALSE;
1703 return TRUE;
1704 }
1705
1706 ////////////////////////////////////////////////////////////////////////
1707 // mask stuff...
1708 ////////////////////////////////////////////////////////////////////////
1709
1710 //Mask1 Set mask bit while drawing. 1 = on
1711 //Mask2 Do not draw to mask areas. 1= on
1712
cmdSTP(unsigned char * baseAddr)1713 void cmdSTP(unsigned char * baseAddr)
1714 {
1715 unsigned long gdata = ((unsigned long*)baseAddr)[0];
1716
1717 STATUSREG&=~0x1800; // clear the necessary bits
1718 STATUSREG|=((gdata & 0x03) << 11); // set the current bits
1719
1720 if(!iUseMask) return;
1721
1722 if(gdata&1) {sSetMask=0x8000;lSetMask=0x80008000;iSetMask=1;}
1723 else {sSetMask=0; lSetMask=0; iSetMask=0;}
1724
1725 if(gdata&2)
1726 {
1727 if(!(gdata&1)) iSetMask=2;
1728 bCheckMask=TRUE;
1729 if(iDepthFunc==0) return;
1730 iDepthFunc=0;
1731 glDepthFunc(GL_LESS); glError();
1732 }
1733 else
1734 {
1735 bCheckMask=FALSE;
1736 if(iDepthFunc==1) return;
1737 glDepthFunc(GL_ALWAYS); glError();
1738 iDepthFunc=1;
1739 }
1740 }
1741
1742 ////////////////////////////////////////////////////////////////////////
1743 // cmd: Set texture page infos
1744 ////////////////////////////////////////////////////////////////////////
1745
cmdTexturePage(unsigned char * baseAddr)1746 void cmdTexturePage(unsigned char * baseAddr)
1747 {
1748 unsigned long gdata = ((unsigned long*)baseAddr)[0];
1749 UpdateGlobalTP((unsigned short)gdata);
1750 GlobalTextREST = (gdata&0x00ffffff)>>9;
1751 }
1752
1753 ////////////////////////////////////////////////////////////////////////
1754 // cmd: turn on/off texture window
1755 ////////////////////////////////////////////////////////////////////////
1756
cmdTextureWindow(unsigned char * baseAddr)1757 void cmdTextureWindow(unsigned char *baseAddr)
1758 {
1759 unsigned long gdata = ((unsigned long*)baseAddr)[0];
1760
1761 unsigned long YAlign,XAlign;
1762
1763 ulGPUInfoVals[INFO_TW]=gdata&0xFFFFF;
1764
1765 if(gdata & 0x020)
1766 TWin.Position.y1 = 8; // xxxx1
1767 else if (gdata & 0x040)
1768 TWin.Position.y1 = 16; // xxx10
1769 else if (gdata & 0x080)
1770 TWin.Position.y1 = 32; // xx100
1771 else if (gdata & 0x100)
1772 TWin.Position.y1 = 64; // x1000
1773 else if (gdata & 0x200)
1774 TWin.Position.y1 = 128; // 10000
1775 else
1776 TWin.Position.y1 = 256; // 00000
1777
1778 // Texture window size is determined by the least bit set of the relevant 5 bits
1779
1780 if (gdata & 0x001)
1781 TWin.Position.x1 = 8; // xxxx1
1782 else if (gdata & 0x002)
1783 TWin.Position.x1 = 16; // xxx10
1784 else if (gdata & 0x004)
1785 TWin.Position.x1 = 32; // xx100
1786 else if (gdata & 0x008)
1787 TWin.Position.x1 = 64; // x1000
1788 else if (gdata & 0x010)
1789 TWin.Position.x1 = 128; // 10000
1790 else
1791 TWin.Position.x1 = 256; // 00000
1792
1793 // Re-calculate the bit field, because we can't trust what is passed in the data
1794
1795 YAlign = (unsigned long)(32 - (TWin.Position.y1 >> 3));
1796 XAlign = (unsigned long)(32 - (TWin.Position.x1 >> 3));
1797
1798 // Absolute position of the start of the texture window
1799
1800 TWin.Position.y0 = (short)(((gdata >> 15) & YAlign) << 3);
1801 TWin.Position.x0 = (short)(((gdata >> 10) & XAlign) << 3);
1802
1803 if((TWin.Position.x0 == 0 && // tw turned off
1804 TWin.Position.y0 == 0 &&
1805 TWin.Position.x1 == 0 &&
1806 TWin.Position.y1 == 0) ||
1807 (TWin.Position.x1 == 256 &&
1808 TWin.Position.y1 == 256))
1809 {
1810 bUsingTWin = FALSE; // -> just do it
1811
1812 #ifdef OWNSCALE
1813 TWin.UScaleFactor = 1.0f;
1814 TWin.VScaleFactor = 1.0f;
1815 #else
1816 TWin.UScaleFactor =
1817 TWin.VScaleFactor = 1.0f/256.0f;
1818 #endif
1819 }
1820 else // tw turned on
1821 {
1822 bUsingTWin = TRUE;
1823
1824 TWin.OPosition.y1 = TWin.Position.y1; // -> get psx sizes
1825 TWin.OPosition.x1 = TWin.Position.x1;
1826
1827 if(TWin.Position.x1<=2) TWin.Position.x1=2; // -> set OGL sizes
1828 else
1829 if(TWin.Position.x1<=4) TWin.Position.x1=4;
1830 else
1831 if(TWin.Position.x1<=8) TWin.Position.x1=8;
1832 else
1833 if(TWin.Position.x1<=16) TWin.Position.x1=16;
1834 else
1835 if(TWin.Position.x1<=32) TWin.Position.x1=32;
1836 else
1837 if(TWin.Position.x1<=64) TWin.Position.x1=64;
1838 else
1839 if(TWin.Position.x1<=128) TWin.Position.x1=128;
1840 else
1841 if(TWin.Position.x1<=256) TWin.Position.x1=256;
1842
1843 if(TWin.Position.y1<=2) TWin.Position.y1=2;
1844 else
1845 if(TWin.Position.y1<=4) TWin.Position.y1=4;
1846 else
1847 if(TWin.Position.y1<=8) TWin.Position.y1=8;
1848 else
1849 if(TWin.Position.y1<=16) TWin.Position.y1=16;
1850 else
1851 if(TWin.Position.y1<=32) TWin.Position.y1=32;
1852 else
1853 if(TWin.Position.y1<=64) TWin.Position.y1=64;
1854 else
1855 if(TWin.Position.y1<=128) TWin.Position.y1=128;
1856 else
1857 if(TWin.Position.y1<=256) TWin.Position.y1=256;
1858
1859 #ifdef OWNSCALE
1860 TWin.UScaleFactor = (float)TWin.Position.x1;
1861 TWin.VScaleFactor = (float)TWin.Position.y1;
1862 #else
1863 TWin.UScaleFactor = ((float)TWin.Position.x1)/256.0f; // -> set scale factor
1864 TWin.VScaleFactor = ((float)TWin.Position.y1)/256.0f;
1865 #endif
1866 }
1867 }
1868
1869 ////////////////////////////////////////////////////////////////////////
1870 // mmm, Lewpy uses that in TileS ... I don't ;)
1871 ////////////////////////////////////////////////////////////////////////
1872
1873 /*
1874 void ClampToPSXDrawAreaOffset(short *x0, short *y0, short *x1, short *y1)
1875 {
1876 if (*x0 < PSXDisplay.DrawArea.x0)
1877 {
1878 *x1 -= (PSXDisplay.DrawArea.x0 - *x0);
1879 *x0 = PSXDisplay.DrawArea.x0;
1880 }
1881 else
1882 if (*x0 > PSXDisplay.DrawArea.x1)
1883 {
1884 *x0 = PSXDisplay.DrawArea.x1;
1885 *x1 = 0;
1886 }
1887
1888 if (*y0 < PSXDisplay.DrawArea.y0)
1889 {
1890 *y1 -= (PSXDisplay.DrawArea.y0 - *y0);
1891 *y0 = PSXDisplay.DrawArea.y0;
1892 }
1893 else
1894 if (*y0 > PSXDisplay.DrawArea.y1)
1895 {
1896 *y0 = PSXDisplay.DrawArea.y1;
1897 *y1 = 0;
1898 }
1899
1900 if (*x1 < 0) *x1 = 0;
1901
1902 if ((*x1 + *x0) > PSXDisplay.DrawArea.x1)
1903 *x1 = (PSXDisplay.DrawArea.x1 - *x0 + 1);
1904
1905 if (*y1 < 0) *y1 = 0;
1906
1907 if ((*y1 + *y0) > PSXDisplay.DrawArea.y1)
1908 *y1 = (PSXDisplay.DrawArea.y1 - *y0 + 1);
1909 }
1910 */
1911
1912 ////////////////////////////////////////////////////////////////////////
1913 // Check draw area dimensions
1914 ////////////////////////////////////////////////////////////////////////
1915
ClampToPSXScreen(short * x0,short * y0,short * x1,short * y1)1916 void ClampToPSXScreen(short *x0, short *y0, short *x1, short *y1)
1917 {
1918 if (*x0 < 0) *x0 = 0;
1919 else
1920 if (*x0 > 1023) *x0 = 1023;
1921
1922 if (*x1 < 0) *x1 = 0;
1923 else
1924 if (*x1 > 1023) *x1 = 1023;
1925
1926 if (*y0 < 0) *y0 = 0;
1927 else
1928 if (*y0 > iGPUHeightMask) *y0 = iGPUHeightMask;
1929
1930 if (*y1 < 0) *y1 = 0;
1931 else
1932 if (*y1 > iGPUHeightMask) *y1 = iGPUHeightMask;
1933 }
1934
1935 ////////////////////////////////////////////////////////////////////////
1936 // Used in Load Image and Blk Fill
1937 ////////////////////////////////////////////////////////////////////////
1938
ClampToPSXScreenOffset(short * x0,short * y0,short * x1,short * y1)1939 void ClampToPSXScreenOffset(short *x0, short *y0, short *x1, short *y1)
1940 {
1941 if (*x0 < 0)
1942 { *x1 += *x0; *x0 = 0; }
1943 else
1944 if (*x0 > 1023)
1945 { *x0 = 1023; *x1 = 0; }
1946
1947 if (*y0 < 0)
1948 { *y1 += *y0; *y0 = 0; }
1949 else
1950 if (*y0 > iGPUHeightMask)
1951 { *y0 = iGPUHeightMask; *y1 = 0; }
1952
1953 if (*x1 < 0) *x1 = 0;
1954
1955 if ((*x1 + *x0) > 1024) *x1 = (1024 - *x0);
1956
1957 if (*y1 < 0) *y1 = 0;
1958
1959 if ((*y1 + *y0) > iGPUHeight) *y1 = (iGPUHeight - *y0);
1960 }
1961
1962 ////////////////////////////////////////////////////////////////////////
1963 // cmd: start of drawing area... primitives will be clipped inside
1964 ////////////////////////////////////////////////////////////////////////
1965
cmdDrawAreaStart(unsigned char * baseAddr)1966 void cmdDrawAreaStart(unsigned char * baseAddr)
1967 {
1968 unsigned long gdata = ((unsigned long*)baseAddr)[0];
1969
1970 drawX = gdata & 0x3ff; // for soft drawing
1971 if(drawX>=1024) drawX=1023;
1972
1973 if(dwGPUVersion==2)
1974 {
1975 ulGPUInfoVals[INFO_DRAWSTART]=gdata&0x3FFFFF;
1976 drawY = (gdata>>12)&0x3ff;
1977 }
1978 else
1979 {
1980 ulGPUInfoVals[INFO_DRAWSTART]=gdata&0xFFFFF;
1981 drawY = (gdata>>10)&0x3ff;
1982 }
1983
1984 if(drawY>=iGPUHeight) drawY=iGPUHeightMask;
1985
1986 PreviousPSXDisplay.DrawArea.y0=PSXDisplay.DrawArea.y0;
1987 PreviousPSXDisplay.DrawArea.x0=PSXDisplay.DrawArea.x0;
1988
1989 PSXDisplay.DrawArea.y0 = (short)drawY; // for OGL drawing
1990 PSXDisplay.DrawArea.x0 = (short)drawX;
1991 }
1992
1993 ////////////////////////////////////////////////////////////////////////
1994 // cmd: end of drawing area... primitives will be clipped inside
1995 ////////////////////////////////////////////////////////////////////////
1996
cmdDrawAreaEnd(unsigned char * baseAddr)1997 void cmdDrawAreaEnd(unsigned char * baseAddr)
1998 {
1999 unsigned long gdata = ((unsigned long*)baseAddr)[0];
2000
2001 drawW = gdata & 0x3ff; // for soft drawing
2002 if(drawW>=1024) drawW=1023;
2003
2004 if(dwGPUVersion==2)
2005 {
2006 ulGPUInfoVals[INFO_DRAWEND]=gdata&0x3FFFFF;
2007 drawH = (gdata>>12)&0x3ff;
2008 }
2009 else
2010 {
2011 ulGPUInfoVals[INFO_DRAWEND]=gdata&0xFFFFF;
2012 drawH = (gdata>>10)&0x3ff;
2013 }
2014
2015 if(drawH>=iGPUHeight) drawH=iGPUHeightMask;
2016
2017 PSXDisplay.DrawArea.y1 = (short)drawH; // for OGL drawing
2018 PSXDisplay.DrawArea.x1 = (short)drawW;
2019
2020 ClampToPSXScreen(&PSXDisplay.DrawArea.x0, // clamp
2021 &PSXDisplay.DrawArea.y0,
2022 &PSXDisplay.DrawArea.x1,
2023 &PSXDisplay.DrawArea.y1);
2024
2025 bDisplayNotSet = TRUE;
2026 }
2027
2028 ////////////////////////////////////////////////////////////////////////
2029 // cmd: draw offset... will be added to prim coords
2030 ////////////////////////////////////////////////////////////////////////
2031
cmdDrawOffset(unsigned char * baseAddr)2032 void cmdDrawOffset(unsigned char * baseAddr)
2033 {
2034 unsigned long gdata = ((unsigned long*)baseAddr)[0];
2035
2036 PreviousPSXDisplay.DrawOffset.x =
2037 PSXDisplay.DrawOffset.x = (short)(gdata & 0x7ff);
2038
2039 if(dwGPUVersion==2)
2040 {
2041 ulGPUInfoVals[INFO_DRAWOFF]=gdata&0x7FFFFF;
2042 PSXDisplay.DrawOffset.y = (short)((gdata>>12) & 0x7ff);
2043 }
2044 else
2045 {
2046 ulGPUInfoVals[INFO_DRAWOFF]=gdata&0x3FFFFF;
2047 PSXDisplay.DrawOffset.y = (short)((gdata>>11) & 0x7ff);
2048 }
2049
2050 PSXDisplay.DrawOffset.x=(short)(((int)PSXDisplay.DrawOffset.x<<21)>>21);
2051 PSXDisplay.DrawOffset.y=(short)(((int)PSXDisplay.DrawOffset.y<<21)>>21);
2052
2053 PSXDisplay.CumulOffset.x = // new OGL prim offsets
2054 PSXDisplay.DrawOffset.x - PSXDisplay.GDrawOffset.x + PreviousPSXDisplay.Range.x0;
2055 PSXDisplay.CumulOffset.y =
2056 PSXDisplay.DrawOffset.y - PSXDisplay.GDrawOffset.y + PreviousPSXDisplay.Range.y0;
2057 }
2058
2059 ////////////////////////////////////////////////////////////////////////
2060 // cmd: load image to vram
2061 ////////////////////////////////////////////////////////////////////////
2062
primLoadImage(unsigned char * baseAddr)2063 void primLoadImage(unsigned char * baseAddr)
2064 {
2065 unsigned short *sgpuData = ((unsigned short *) baseAddr);
2066
2067 VRAMWrite.x = sgpuData[2]&0x03ff;
2068 VRAMWrite.y = sgpuData[3]&iGPUHeightMask;
2069 VRAMWrite.Width = sgpuData[4];
2070 VRAMWrite.Height = sgpuData[5];
2071
2072 iDataWriteMode = DR_VRAMTRANSFER;
2073 VRAMWrite.ImagePtr = psxVuw + (VRAMWrite.y<<10) + VRAMWrite.x;
2074 VRAMWrite.RowsRemaining = VRAMWrite.Width;
2075 VRAMWrite.ColsRemaining = VRAMWrite.Height;
2076
2077 bNeedWriteUpload=TRUE;
2078 }
2079
2080 ////////////////////////////////////////////////////////////////////////
2081
PrepareRGB24Upload(void)2082 void PrepareRGB24Upload(void)
2083 {
2084 VRAMWrite.x=(VRAMWrite.x*2)/3;
2085 VRAMWrite.Width=(VRAMWrite.Width*2)/3;
2086
2087 if(!PSXDisplay.InterlacedTest && // NEW
2088 CheckAgainstScreen(VRAMWrite.x, VRAMWrite.y, VRAMWrite.Width, VRAMWrite.Height))
2089 {
2090 xrUploadArea.x0-=PreviousPSXDisplay.DisplayPosition.x;
2091 xrUploadArea.x1-=PreviousPSXDisplay.DisplayPosition.x;
2092 xrUploadArea.y0-=PreviousPSXDisplay.DisplayPosition.y;
2093 xrUploadArea.y1-=PreviousPSXDisplay.DisplayPosition.y;
2094 }
2095 else
2096 if(CheckAgainstFrontScreen(VRAMWrite.x, VRAMWrite.y, VRAMWrite.Width, VRAMWrite.Height))
2097 {
2098 xrUploadArea.x0-=PSXDisplay.DisplayPosition.x;
2099 xrUploadArea.x1-=PSXDisplay.DisplayPosition.x;
2100 xrUploadArea.y0-=PSXDisplay.DisplayPosition.y;
2101 xrUploadArea.y1-=PSXDisplay.DisplayPosition.y;
2102 }
2103 else return;
2104
2105 if(bRenderFrontBuffer)
2106 {
2107 updateFrontDisplay();
2108 }
2109
2110 if(bNeedRGB24Update==FALSE)
2111 {
2112 xrUploadAreaRGB24=xrUploadArea;
2113 bNeedRGB24Update=TRUE;
2114 }
2115 else
2116 {
2117 xrUploadAreaRGB24.x0=min(xrUploadAreaRGB24.x0,xrUploadArea.x0);
2118 xrUploadAreaRGB24.x1=max(xrUploadAreaRGB24.x1,xrUploadArea.x1);
2119 xrUploadAreaRGB24.y0=min(xrUploadAreaRGB24.y0,xrUploadArea.y0);
2120 xrUploadAreaRGB24.y1=max(xrUploadAreaRGB24.y1,xrUploadArea.y1);
2121 }
2122 }
2123
2124 ////////////////////////////////////////////////////////////////////////
2125
CheckWriteUpdate()2126 void CheckWriteUpdate()
2127 {
2128 int iX=0,iY=0;
2129
2130 if(VRAMWrite.Width) iX=1;
2131 if(VRAMWrite.Height) iY=1;
2132
2133 InvalidateTextureArea(VRAMWrite.x, VRAMWrite.y, VRAMWrite.Width-iX, VRAMWrite.Height-iY);
2134
2135 if(PSXDisplay.Interlaced && !iOffscreenDrawing) return;
2136
2137 if(PSXDisplay.RGB24) {PrepareRGB24Upload();return;}
2138
2139 if(!PSXDisplay.InterlacedTest &&
2140 CheckAgainstScreen(VRAMWrite.x, VRAMWrite.y, VRAMWrite.Width, VRAMWrite.Height))
2141 {
2142 if(dwActFixes&0x800) return;
2143
2144 if(bRenderFrontBuffer)
2145 {
2146 updateFrontDisplay();
2147 }
2148
2149 UploadScreen(FALSE);
2150
2151 bNeedUploadTest=TRUE;
2152 }
2153 else
2154 if(iOffscreenDrawing)
2155 {
2156 if (CheckAgainstFrontScreen(VRAMWrite.x, VRAMWrite.y, VRAMWrite.Width, VRAMWrite.Height))
2157 {
2158 if(PSXDisplay.InterlacedTest)
2159 {
2160 if(PreviousPSXDisplay.InterlacedNew)
2161 {
2162 PreviousPSXDisplay.InterlacedNew=FALSE;
2163 bNeedInterlaceUpdate=TRUE;
2164 xrUploadAreaIL.x0=PSXDisplay.DisplayPosition.x;
2165 xrUploadAreaIL.y0=PSXDisplay.DisplayPosition.y;
2166 xrUploadAreaIL.x1=PSXDisplay.DisplayPosition.x+PSXDisplay.DisplayModeNew.x;
2167 xrUploadAreaIL.y1=PSXDisplay.DisplayPosition.y+PSXDisplay.DisplayModeNew.y;
2168 if(xrUploadAreaIL.x1>1023) xrUploadAreaIL.x1=1023;
2169 if(xrUploadAreaIL.y1>511) xrUploadAreaIL.y1=511;
2170 }
2171
2172 if(bNeedInterlaceUpdate==FALSE)
2173 {
2174 xrUploadAreaIL=xrUploadArea;
2175 bNeedInterlaceUpdate=TRUE;
2176 }
2177 else
2178 {
2179 xrUploadAreaIL.x0=min(xrUploadAreaIL.x0,xrUploadArea.x0);
2180 xrUploadAreaIL.x1=max(xrUploadAreaIL.x1,xrUploadArea.x1);
2181 xrUploadAreaIL.y0=min(xrUploadAreaIL.y0,xrUploadArea.y0);
2182 xrUploadAreaIL.y1=max(xrUploadAreaIL.y1,xrUploadArea.y1);
2183 }
2184 return;
2185 }
2186
2187 if(!bNeedUploadAfter)
2188 {
2189 bNeedUploadAfter = TRUE;
2190 xrUploadArea.x0=VRAMWrite.x;
2191 xrUploadArea.x1=VRAMWrite.x+VRAMWrite.Width;
2192 xrUploadArea.y0=VRAMWrite.y;
2193 xrUploadArea.y1=VRAMWrite.y+VRAMWrite.Height;
2194 }
2195 else
2196 {
2197 xrUploadArea.x0=min(xrUploadArea.x0,VRAMWrite.x);
2198 xrUploadArea.x1=max(xrUploadArea.x1,VRAMWrite.x+VRAMWrite.Width);
2199 xrUploadArea.y0=min(xrUploadArea.y0,VRAMWrite.y);
2200 xrUploadArea.y1=max(xrUploadArea.y1,VRAMWrite.y+VRAMWrite.Height);
2201 }
2202
2203 if(dwActFixes&0x8000)
2204 {
2205 if((xrUploadArea.x1-xrUploadArea.x0)>=(PSXDisplay.DisplayMode.x-32) &&
2206 (xrUploadArea.y1-xrUploadArea.y0)>=(PSXDisplay.DisplayMode.y-32))
2207 {
2208 UploadScreen(-1);
2209 updateFrontDisplay();
2210 }
2211 }
2212 }
2213 }
2214 }
2215
2216 ////////////////////////////////////////////////////////////////////////
2217 // cmd: vram -> psx mem
2218 ////////////////////////////////////////////////////////////////////////
2219
primStoreImage(unsigned char * baseAddr)2220 void primStoreImage(unsigned char * baseAddr)
2221 {
2222 unsigned short *sgpuData = ((unsigned short *) baseAddr);
2223
2224 VRAMRead.x = sgpuData[2]&0x03ff;
2225 VRAMRead.y = sgpuData[3]&iGPUHeightMask;
2226 VRAMRead.Width = sgpuData[4];
2227 VRAMRead.Height = sgpuData[5];
2228
2229 VRAMRead.ImagePtr = psxVuw + (VRAMRead.y<<10) + VRAMRead.x;
2230 VRAMRead.RowsRemaining = VRAMRead.Width;
2231 VRAMRead.ColsRemaining = VRAMRead.Height;
2232
2233 iDataReadMode = DR_VRAMTRANSFER;
2234
2235 STATUSREG |= GPUSTATUS_READYFORVRAM;
2236 }
2237
2238 ////////////////////////////////////////////////////////////////////////
2239 // cmd: blkfill - NO primitive! Doesn't care about draw areas...
2240 ////////////////////////////////////////////////////////////////////////
2241
primBlkFill(unsigned char * baseAddr)2242 void primBlkFill(unsigned char * baseAddr)
2243 {
2244 unsigned long *gpuData = ((unsigned long *) baseAddr);
2245 short *sgpuData = ((short *) baseAddr);
2246
2247 iDrawnSomething=1;
2248
2249 sprtX = sgpuData[2];
2250 sprtY = sgpuData[3];
2251 sprtW = sgpuData[4] & 0x3ff;
2252 sprtH = sgpuData[5] & iGPUHeightMask;
2253
2254 sprtW = (sprtW+15) & ~15;
2255
2256 // Increase H & W if they are one short of full values, because they never can be full values
2257 if (sprtH == iGPUHeightMask) sprtH=iGPUHeight;
2258 if (sprtW == 1023) sprtW=1024;
2259
2260 // x and y of start
2261 ly0 = ly1 = sprtY;
2262 ly2 = ly3 = (sprtY+sprtH);
2263 lx0 = lx3 = sprtX;
2264 lx1 = lx2 = (sprtX+sprtW);
2265
2266 offsetBlk();
2267
2268 if(ClipVertexListScreen())
2269 {
2270 PSXDisplay_t * pd;
2271 if(PSXDisplay.InterlacedTest) pd=&PSXDisplay;
2272 else pd=&PreviousPSXDisplay;
2273
2274 if ((lx0 <= pd->DisplayPosition.x+16) &&
2275 (ly0 <= pd->DisplayPosition.y+16) &&
2276 (lx2 >= pd->DisplayEnd.x-16) &&
2277 (ly2 >= pd->DisplayEnd.y-16))
2278 {
2279 GLclampf g,b,r;
2280 g=((GLclampf)GREEN(gpuData[0]))/255.0f;
2281 b=((GLclampf)BLUE(gpuData[0]))/255.0f;
2282 r=((GLclampf)RED(gpuData[0]))/255.0f;
2283
2284 //glDisable(GL_SCISSOR_TEST); glError();
2285 glClearColor(r,g,b,1.0f); glError();
2286 glClear(uiBufferBits); glError();
2287 gl_z=0.0f;
2288
2289 if(gpuData[0]!=0x02000000 &&
2290 (ly0>pd->DisplayPosition.y ||
2291 ly2<pd->DisplayEnd.y))
2292 {
2293 bDrawTextured = FALSE;
2294 bDrawSmoothShaded = FALSE;
2295 SetRenderState((unsigned long)0x01000000);
2296 SetRenderMode((unsigned long)0x01000000, FALSE);
2297 vertex[0].c.lcol=0xff000000;
2298 SETCOL(vertex[0]);
2299 if(ly0>pd->DisplayPosition.y)
2300 {
2301 vertex[0].x=0;vertex[0].y=0;
2302 vertex[1].x=pd->DisplayEnd.x-pd->DisplayPosition.x;vertex[1].y=0;
2303 vertex[2].x=vertex[1].x;vertex[2].y=ly0-pd->DisplayPosition.y;
2304 vertex[3].x=0;vertex[3].y=vertex[2].y;
2305 PRIMdrawQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
2306 }
2307 if(ly2<pd->DisplayEnd.y)
2308 {
2309 vertex[0].x=0;vertex[0].y=(pd->DisplayEnd.y-pd->DisplayPosition.y)-(pd->DisplayEnd.y-ly2);
2310 vertex[1].x=pd->DisplayEnd.x-pd->DisplayPosition.x;vertex[1].y=vertex[0].y;
2311 vertex[2].x=vertex[1].x;vertex[2].y=pd->DisplayEnd.y;
2312 vertex[3].x=0;vertex[3].y=vertex[2].y;
2313 PRIMdrawQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
2314 }
2315 }
2316
2317 //glEnable(GL_SCISSOR_TEST); glError();
2318 }
2319 else
2320 {
2321 bDrawTextured = FALSE;
2322 bDrawSmoothShaded = FALSE;
2323 SetRenderState((unsigned long)0x01000000);
2324 SetRenderMode((unsigned long)0x01000000, FALSE);
2325 vertex[0].c.lcol=gpuData[0]|0xff000000;
2326 SETCOL(vertex[0]);
2327 //glDisable(GL_SCISSOR_TEST); glError();
2328 PRIMdrawQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
2329 //glEnable(GL_SCISSOR_TEST); glError();
2330 }
2331 }
2332
2333 //mmm... will clean all stuff, also if not all _should_ be cleaned...
2334 //if (IsInsideNextScreen(sprtX, sprtY, sprtW, sprtH))
2335 // try this:
2336 if (IsCompleteInsideNextScreen(sprtX, sprtY, sprtW, sprtH))
2337 {
2338 lClearOnSwapColor = COLOR(gpuData[0]);
2339 lClearOnSwap = 1;
2340 }
2341
2342 /* if(iOffscreenDrawing)
2343 {
2344 ClampToPSXScreenOffset( &sprtX, &sprtY, &sprtW, &sprtH);
2345 if ((sprtW == 0) || (sprtH == 0)) return;
2346 InvalidateTextureArea(sprtX, sprtY, sprtW-1, sprtH-1);
2347
2348 sprtW+=sprtX;
2349 sprtH+=sprtY;
2350
2351 FillSoftwareArea(sprtX, sprtY, sprtW, sprtH, BGR24to16(gpuData[0]));
2352 }*/
2353 }
2354
2355 ////////////////////////////////////////////////////////////////////////
2356 // cmd: move image vram -> vram
2357 ////////////////////////////////////////////////////////////////////////
2358
MoveImageWrapped(short imageX0,short imageY0,short imageX1,short imageY1,short imageSX,short imageSY)2359 void MoveImageWrapped(short imageX0,short imageY0,
2360 short imageX1,short imageY1,
2361 short imageSX,short imageSY)
2362 {
2363 int i,j,imageXE,imageYE;
2364
2365 if(iFrameReadType&2)
2366 {
2367 imageXE=imageX0+imageSX;
2368 imageYE=imageY0+imageSY;
2369
2370 if(imageYE>iGPUHeight && imageXE>1024)
2371 {
2372 CheckVRamRead(0,0,
2373 (imageXE&0x3ff),
2374 (imageY0&iGPUHeightMask),
2375 FALSE);
2376 }
2377
2378 if(imageXE>1024)
2379 {
2380 CheckVRamRead(0,imageY0,
2381 (imageXE&0x3ff),
2382 (imageYE>iGPUHeight)?iGPUHeight:imageYE,
2383 FALSE);
2384 }
2385
2386 if(imageYE>iGPUHeight)
2387 {
2388 CheckVRamRead(imageX0,0,
2389 (imageXE>1024)?1024:imageXE,
2390 imageYE&iGPUHeightMask,
2391 FALSE);
2392 }
2393
2394 CheckVRamRead(imageX0,imageY0,
2395 (imageXE>1024)?1024:imageXE,
2396 (imageYE>iGPUHeight)?iGPUHeight:imageYE,
2397 FALSE);
2398 }
2399
2400 for(j=0;j<imageSY;j++)
2401 for(i=0;i<imageSX;i++)
2402 psxVuw [(1024*((imageY1+j)&iGPUHeightMask))+((imageX1+i)&0x3ff)]=
2403 psxVuw[(1024*((imageY0+j)&iGPUHeightMask))+((imageX0+i)&0x3ff)];
2404
2405 if(!PSXDisplay.RGB24)
2406 {
2407 imageXE=imageX1+imageSX;
2408 imageYE=imageY1+imageSY;
2409
2410 if(imageYE>iGPUHeight && imageXE>1024)
2411 {
2412 InvalidateTextureArea(0,0,
2413 (imageXE&0x3ff)-1,
2414 (imageYE&iGPUHeightMask)-1);
2415 }
2416
2417 if(imageXE>1024)
2418 {
2419 InvalidateTextureArea(0,imageY1,
2420 (imageXE&0x3ff)-1,
2421 ((imageYE>iGPUHeight)?iGPUHeight:imageYE)-imageY1-1);
2422 }
2423
2424 if(imageYE>iGPUHeight)
2425 {
2426 InvalidateTextureArea(imageX1,0,
2427 ((imageXE>1024)?1024:imageXE)-imageX1-1,
2428 (imageYE&iGPUHeightMask)-1);
2429 }
2430
2431 InvalidateTextureArea(imageX1,imageY1,
2432 ((imageXE>1024)?1024:imageXE)-imageX1-1,
2433 ((imageYE>iGPUHeight)?iGPUHeight:imageYE)-imageY1-1);
2434 }
2435 }
2436
2437 ////////////////////////////////////////////////////////////////////////
2438
primMoveImage(unsigned char * baseAddr)2439 void primMoveImage(unsigned char * baseAddr)
2440 {
2441 short *sgpuData = ((short *) baseAddr);
2442 short imageY0,imageX0,imageY1,imageX1,imageSX,imageSY,i,j;
2443
2444 imageX0 = sgpuData[2]&0x03ff;
2445 imageY0 = sgpuData[3]&iGPUHeightMask;
2446 imageX1 = sgpuData[4]&0x03ff;
2447 imageY1 = sgpuData[5]&iGPUHeightMask;
2448 imageSX = sgpuData[6];
2449 imageSY = sgpuData[7];
2450
2451 if((imageX0 == imageX1) && (imageY0 == imageY1)) return;
2452 if(imageSX<=0) return;
2453 if(imageSY<=0) return;
2454
2455 if(iGPUHeight==1024 && sgpuData[7]>1024) return;
2456
2457 if((imageY0+imageSY)>iGPUHeight ||
2458 (imageX0+imageSX)>1024 ||
2459 (imageY1+imageSY)>iGPUHeight ||
2460 (imageX1+imageSX)>1024)
2461 {
2462 MoveImageWrapped(imageX0,imageY0,imageX1,imageY1,imageSX,imageSY);
2463 if((imageY0+imageSY)>iGPUHeight) imageSY=iGPUHeight-imageY0;
2464 if((imageX0+imageSX)>1024) imageSX=1024-imageX0;
2465 if((imageY1+imageSY)>iGPUHeight) imageSY=iGPUHeight-imageY1;
2466 if((imageX1+imageSX)>1024) imageSX=1024-imageX1;
2467 }
2468
2469 if(iFrameReadType&2)
2470 CheckVRamRead(imageX0,imageY0,
2471 imageX0+imageSX,
2472 imageY0+imageSY,
2473 FALSE);
2474
2475 if(imageSX&1)
2476 {
2477 unsigned short *SRCPtr, *DSTPtr;
2478 unsigned short LineOffset;
2479
2480 SRCPtr = psxVuw + (1024*imageY0) + imageX0;
2481 DSTPtr = psxVuw + (1024*imageY1) + imageX1;
2482
2483 LineOffset = 1024 - imageSX;
2484
2485 for(j=0;j<imageSY;j++)
2486 {
2487 for(i=0;i<imageSX;i++) *DSTPtr++ = *SRCPtr++;
2488 SRCPtr += LineOffset;
2489 DSTPtr += LineOffset;
2490 }
2491 }
2492 else
2493 {
2494 unsigned long *SRCPtr, *DSTPtr;
2495 unsigned short LineOffset;
2496 int dx=imageSX>>1;
2497
2498 SRCPtr = (unsigned long *)(psxVuw + (1024*imageY0) + imageX0);
2499 DSTPtr = (unsigned long *)(psxVuw + (1024*imageY1) + imageX1);
2500
2501 LineOffset = 512 - dx;
2502
2503 for(j=0;j<imageSY;j++)
2504 {
2505 for(i=0;i<dx;i++) *DSTPtr++ = *SRCPtr++;
2506 SRCPtr += LineOffset;
2507 DSTPtr += LineOffset;
2508 }
2509 }
2510
2511 if (!PSXDisplay.RGB24)
2512 {
2513 InvalidateTextureArea(imageX1,imageY1,imageSX-1,imageSY-1);
2514
2515 if (CheckAgainstScreen(imageX1,imageY1,imageSX,imageSY))
2516 {
2517 if(imageX1>=PreviousPSXDisplay.DisplayPosition.x &&
2518 imageX1<PreviousPSXDisplay.DisplayEnd.x &&
2519 imageY1>=PreviousPSXDisplay.DisplayPosition.y &&
2520 imageY1<PreviousPSXDisplay.DisplayEnd.y)
2521 {
2522 imageX1 += imageSX;
2523 imageY1 += imageSY;
2524
2525 if(imageX1>=PreviousPSXDisplay.DisplayPosition.x &&
2526 imageX1<=PreviousPSXDisplay.DisplayEnd.x &&
2527 imageY1>=PreviousPSXDisplay.DisplayPosition.y &&
2528 imageY1<=PreviousPSXDisplay.DisplayEnd.y)
2529 {
2530 if(!(
2531 imageX0>=PSXDisplay.DisplayPosition.x &&
2532 imageX0<PSXDisplay.DisplayEnd.x &&
2533 imageY0>=PSXDisplay.DisplayPosition.y &&
2534 imageY0<PSXDisplay.DisplayEnd.y
2535 ))
2536 {
2537 if(bRenderFrontBuffer)
2538 {
2539 updateFrontDisplay();
2540 }
2541
2542 UploadScreen(FALSE);
2543 }
2544 else bFakeFrontBuffer=TRUE;
2545 }
2546 }
2547
2548 bNeedUploadTest=TRUE;
2549 }
2550 else
2551 if(iOffscreenDrawing)
2552 {
2553 if (CheckAgainstFrontScreen(imageX1,imageY1,imageSX,imageSY))
2554 {
2555 if(!PSXDisplay.InterlacedTest &&
2556 // !bFullVRam &&
2557 ((
2558 imageX0>=PreviousPSXDisplay.DisplayPosition.x &&
2559 imageX0<PreviousPSXDisplay.DisplayEnd.x &&
2560 imageY0>=PreviousPSXDisplay.DisplayPosition.y &&
2561 imageY0<PreviousPSXDisplay.DisplayEnd.y
2562 ) ||
2563 (
2564 imageX0>=PSXDisplay.DisplayPosition.x &&
2565 imageX0<PSXDisplay.DisplayEnd.x &&
2566 imageY0>=PSXDisplay.DisplayPosition.y &&
2567 imageY0<PSXDisplay.DisplayEnd.y
2568 )))
2569 return;
2570
2571 bNeedUploadTest=TRUE;
2572
2573 if(!bNeedUploadAfter)
2574 {
2575 bNeedUploadAfter = TRUE;
2576 xrUploadArea.x0=imageX0;
2577 xrUploadArea.x1=imageX0+imageSX;
2578 xrUploadArea.y0=imageY0;
2579 xrUploadArea.y1=imageY0+imageSY;
2580 }
2581 else
2582 {
2583 xrUploadArea.x0=min(xrUploadArea.x0,imageX0);
2584 xrUploadArea.x1=max(xrUploadArea.x1,imageX0+imageSX);
2585 xrUploadArea.y0=min(xrUploadArea.y0,imageY0);
2586 xrUploadArea.y1=max(xrUploadArea.y1,imageY0+imageSY);
2587 }
2588 }
2589 }
2590 }
2591 }
2592
2593
2594 ////////////////////////////////////////////////////////////////////////
2595 // cmd: draw free-size Tile
2596 ////////////////////////////////////////////////////////////////////////
2597
primTileS(unsigned char * baseAddr)2598 void primTileS(unsigned char * baseAddr)
2599 {
2600 unsigned long *gpuData = ((unsigned long*)baseAddr);
2601 short *sgpuData = ((short *) baseAddr);
2602
2603 sprtX = sgpuData[2];
2604 sprtY = sgpuData[3];
2605 sprtW = sgpuData[4] & 0x3ff;
2606 sprtH = sgpuData[5] & iGPUHeightMask;
2607
2608 // x and y of start
2609
2610 lx0 = sprtX;
2611 ly0 = sprtY;
2612
2613 offsetST();
2614
2615 if((dwActFixes&1) && // FF7 special game gix (battle cursor)
2616 sprtX==0 && sprtY==0 && sprtW==24 && sprtH==16)
2617 return;
2618
2619 bDrawTextured = FALSE;
2620 bDrawSmoothShaded = FALSE;
2621
2622 SetRenderState(gpuData[0]);
2623
2624 /* if(iOffscreenDrawing)
2625 {
2626 if(IsPrimCompleteInsideNextScreen(lx0,ly0,lx2,ly2) ||
2627 (ly0==-6 && ly2==10)) // OH MY GOD... I DIDN'T WANT TO DO IT... BUT I'VE FOUND NO OTHER WAY... HACK FOR GRADIUS SHOOTER :(
2628 {
2629 lClearOnSwapColor = COLOR(gpuData[0]);
2630 lClearOnSwap = 1;
2631 }
2632
2633 offsetPSX4();
2634 if(bDrawOffscreen4())
2635 {
2636 if(!(iTileCheat && sprtH==32 && gpuData[0]==0x60ffffff)) // special cheat for certain ZiNc games
2637 {
2638 InvalidateTextureAreaEx();
2639 FillSoftwareAreaTrans(lx0,ly0,lx2,ly2,
2640 BGR24to16(gpuData[0]));
2641 }
2642 }
2643 }*/
2644
2645 SetRenderMode(gpuData[0], FALSE);
2646 SetZMask4NT();
2647
2648 if(bIgnoreNextTile) {bIgnoreNextTile=FALSE;return;}
2649
2650 vertex[0].c.lcol=gpuData[0];
2651 vertex[0].c.col[3]=ubGloColAlpha;
2652 SETCOL(vertex[0]);
2653
2654 PRIMdrawQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
2655
2656 iDrawnSomething=1;
2657 }
2658
2659 ////////////////////////////////////////////////////////////////////////
2660 // cmd: draw 1 dot Tile (point)
2661 ////////////////////////////////////////////////////////////////////////
2662
primTile1(unsigned char * baseAddr)2663 void primTile1(unsigned char * baseAddr)
2664 {
2665 unsigned long *gpuData = ((unsigned long*)baseAddr);
2666 short *sgpuData = ((short *) baseAddr);
2667
2668 sprtX = sgpuData[2];
2669 sprtY = sgpuData[3];
2670 sprtW = 1;
2671 sprtH = 1;
2672
2673 lx0 = sprtX;
2674 ly0 = sprtY;
2675
2676 offsetST();
2677
2678 bDrawTextured = FALSE;
2679 bDrawSmoothShaded = FALSE;
2680
2681 SetRenderState(gpuData[0]);
2682
2683 /* if(iOffscreenDrawing)
2684 {
2685 offsetPSX4();
2686
2687 if(bDrawOffscreen4())
2688 {
2689 InvalidateTextureAreaEx();
2690 FillSoftwareAreaTrans(lx0,ly0,lx2,ly2,
2691 BGR24to16(gpuData[0]));
2692 }
2693 }
2694 */
2695 SetRenderMode(gpuData[0], FALSE);
2696 SetZMask4NT();
2697
2698 vertex[0].c.lcol=gpuData[0];vertex[0].c.col[3]=ubGloColAlpha;
2699 SETCOL(vertex[0]);
2700
2701 PRIMdrawQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
2702
2703 iDrawnSomething=1;
2704 }
2705
2706 ////////////////////////////////////////////////////////////////////////
2707 // cmd: draw 8 dot Tile (small rect)
2708 ////////////////////////////////////////////////////////////////////////
2709
primTile8(unsigned char * baseAddr)2710 void primTile8(unsigned char * baseAddr)
2711 {
2712 unsigned long *gpuData = ((unsigned long*)baseAddr);
2713 short *sgpuData = ((short *) baseAddr);
2714
2715 sprtX = sgpuData[2];
2716 sprtY = sgpuData[3];
2717 sprtW = 8;
2718 sprtH = 8;
2719
2720 lx0 = sprtX;
2721 ly0 = sprtY;
2722
2723 offsetST();
2724
2725 bDrawTextured = FALSE;
2726 bDrawSmoothShaded = FALSE;
2727 SetRenderState(gpuData[0]);
2728
2729 /* if(iOffscreenDrawing)
2730 {
2731 offsetPSX4();
2732
2733 if(bDrawOffscreen4())
2734 {
2735 InvalidateTextureAreaEx();
2736 FillSoftwareAreaTrans(lx0,ly0,lx2,ly2,
2737 BGR24to16(gpuData[0]));
2738 }
2739 }
2740 */
2741 SetRenderMode(gpuData[0], FALSE);
2742 SetZMask4NT();
2743
2744 vertex[0].c.lcol=gpuData[0];
2745 vertex[0].c.col[3]=ubGloColAlpha;
2746 SETCOL(vertex[0]);
2747
2748 PRIMdrawQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
2749
2750 iDrawnSomething=1;
2751 }
2752
2753 ////////////////////////////////////////////////////////////////////////
2754 // cmd: draw 16 dot Tile (medium rect)
2755 ////////////////////////////////////////////////////////////////////////
2756
primTile16(unsigned char * baseAddr)2757 void primTile16(unsigned char * baseAddr)
2758 {
2759 unsigned long *gpuData = ((unsigned long*)baseAddr);
2760 short *sgpuData = ((short *) baseAddr);
2761
2762 sprtX = sgpuData[2];
2763 sprtY = sgpuData[3];
2764 sprtW = 16;
2765 sprtH = 16;
2766 // x and y of start
2767 lx0 = sprtX;
2768 ly0 = sprtY;
2769
2770 offsetST();
2771
2772 bDrawTextured = FALSE;
2773 bDrawSmoothShaded = FALSE;
2774 SetRenderState(gpuData[0]);
2775
2776 /* if(iOffscreenDrawing)
2777 {
2778 offsetPSX4();
2779
2780 if(bDrawOffscreen4())
2781 {
2782 InvalidateTextureAreaEx();
2783 FillSoftwareAreaTrans(lx0,ly0,lx2,ly2,
2784 BGR24to16(gpuData[0]));
2785 }
2786 }
2787 */
2788 SetRenderMode(gpuData[0], FALSE);
2789 SetZMask4NT();
2790
2791 vertex[0].c.lcol=gpuData[0];
2792 vertex[0].c.col[3]=ubGloColAlpha;
2793 SETCOL(vertex[0]);
2794
2795 PRIMdrawQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
2796
2797 iDrawnSomething=1;
2798 }
2799
2800 ////////////////////////////////////////////////////////////////////////
2801 // helper: filter effect by multipass rendering
2802 ////////////////////////////////////////////////////////////////////////
2803
2804 /*void DrawMultiBlur(void)
2805 {
2806 long lABR,lDST;float fx,fy;
2807
2808 lABR=GlobalTextABR;
2809 lDST=DrawSemiTrans;
2810
2811 fx=(float)PSXDisplay.DisplayMode.x/(float)(iResX);
2812 fy=(float)PSXDisplay.DisplayMode.y/(float)(iResY);
2813
2814 vertex[0].x+=fx;vertex[1].x+=fx;
2815 vertex[2].x+=fx;vertex[3].x+=fx;
2816
2817 GlobalTextABR=0;
2818 DrawSemiTrans=1;
2819 SetSemiTrans();
2820
2821 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
2822
2823 vertex[0].y+=fy;vertex[1].y+=fy;
2824 vertex[2].y+=fy;vertex[3].y+=fy;
2825 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
2826
2827 if(bDrawMultiPass) {obm1=obm2=GL_SRC_ALPHA;}
2828
2829 GlobalTextABR=lABR;
2830 DrawSemiTrans=lDST;
2831 }
2832 */
2833 ////////////////////////////////////////////////////////////////////////
2834
2835 #define POFF 0.375f
2836
DrawMultiFilterSprite(void)2837 void DrawMultiFilterSprite(void)
2838 {
2839 long lABR,lDST;
2840
2841 if(bUseMultiPass || DrawSemiTrans || ubOpaqueDraw)
2842 {
2843 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
2844 return;
2845 }
2846
2847 lABR=GlobalTextABR;
2848 lDST=DrawSemiTrans;
2849 vertex[0].c.col[3]=ubGloAlpha/2; // -> set color with
2850 SETCOL(vertex[0]); // texture alpha
2851 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
2852 vertex[0].x+=POFF;vertex[1].x+=POFF;
2853 vertex[2].x+=POFF;vertex[3].x+=POFF;
2854 vertex[0].y+=POFF;vertex[1].y+=POFF;
2855 vertex[2].y+=POFF;vertex[3].y+=POFF;
2856 GlobalTextABR=0;
2857 DrawSemiTrans=1;
2858 SetSemiTrans();
2859 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
2860 GlobalTextABR=lABR;
2861 DrawSemiTrans=lDST;
2862 }
2863
2864 ////////////////////////////////////////////////////////////////////////
2865 // cmd: small sprite (textured rect)
2866 ////////////////////////////////////////////////////////////////////////
2867
primSprt8(unsigned char * baseAddr)2868 void primSprt8(unsigned char * baseAddr)
2869 {
2870 unsigned long *gpuData = ((unsigned long *) baseAddr);
2871 short *sgpuData = ((short *) baseAddr);
2872 short s;
2873
2874 iSpriteTex=1;
2875
2876 sprtX = sgpuData[2];
2877 sprtY = sgpuData[3];
2878 sprtW = 8;
2879 sprtH = 8;
2880
2881 lx0 = sprtX;
2882 ly0 = sprtY;
2883
2884 offsetST();
2885
2886 // do texture stuff
2887 gl_ux[0]=gl_ux[3]=baseAddr[8];//gpuData[2]&0xff;
2888
2889 if(usMirror & 0x1000)
2890 {
2891 s=gl_ux[0];
2892 s-=sprtW-1;
2893 if(s<0) {s=0;}
2894 gl_ux[0]=gl_ux[3]=s;
2895 }
2896
2897 sSprite_ux2=s=gl_ux[0]+sprtW;
2898 if(s) s--;
2899 if(s>255) s=255;
2900 gl_ux[1]=gl_ux[2]=s;
2901 // Y coords
2902 gl_vy[0]=gl_vy[1]=baseAddr[9];//(gpuData[2]>>8)&0xff;
2903
2904 if(usMirror & 0x2000)
2905 {
2906 s=gl_vy[0];
2907 s-=sprtH-1;
2908 if(s<0) {s=0;}
2909 gl_vy[0]=gl_vy[1]=s;
2910 }
2911
2912 sSprite_vy2=s=gl_vy[0]+sprtH;
2913 if(s) s--;
2914 if(s>255) s=255;
2915 gl_vy[2]=gl_vy[3]=s;
2916
2917 ulClutID=(gpuData[2]>>16);
2918
2919 bDrawTextured = TRUE;
2920 bDrawSmoothShaded = FALSE;
2921 SetRenderState(gpuData[0]);
2922
2923 /* if(iOffscreenDrawing)
2924 {
2925 offsetPSX4();
2926
2927 if(bDrawOffscreen4())
2928 {
2929 InvalidateTextureAreaEx();
2930 SetRenderColor(gpuData[0]);
2931 lx0-=PSXDisplay.DrawOffset.x;
2932 ly0-=PSXDisplay.DrawOffset.y;
2933
2934 if(bUsingTWin) DrawSoftwareSpriteTWin(baseAddr,8,8);
2935 else
2936 if(usMirror) DrawSoftwareSpriteMirror(baseAddr,8,8);
2937 else
2938 DrawSoftwareSprite(baseAddr,8,8,baseAddr[8],baseAddr[9]);
2939 }
2940 }
2941 */
2942 SetRenderMode(gpuData[0], TRUE);
2943 SetZMask4SP();
2944
2945 sSprite_ux2=gl_ux[0]+sprtW;
2946 sSprite_vy2=gl_vy[0]+sprtH;
2947
2948 assignTextureSprite();
2949
2950 if(iFilterType>4)
2951 DrawMultiFilterSprite();
2952 else
2953 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
2954
2955 if(bDrawMultiPass)
2956 {
2957 SetSemiTransMulti(1);
2958 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
2959 }
2960
2961 if(ubOpaqueDraw)
2962 {
2963 SetZMask4O();
2964 if(bUseMultiPass) SetOpaqueColor(gpuData[0]);
2965 DEFOPAQUEON
2966
2967 /* if(bSmallAlpha && iFilterType<=2)
2968 {
2969 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
2970 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2971 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
2972 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
2973 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
2974 SetZMask4O();
2975 }
2976 */
2977 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
2978 DEFOPAQUEOFF
2979 }
2980
2981 iSpriteTex=0;
2982 iDrawnSomething=1;
2983 }
2984
2985 ////////////////////////////////////////////////////////////////////////
2986 // cmd: medium sprite (textured rect)
2987 ////////////////////////////////////////////////////////////////////////
2988
primSprt16(unsigned char * baseAddr)2989 void primSprt16(unsigned char * baseAddr)
2990 {
2991 unsigned long *gpuData = ((unsigned long *) baseAddr);
2992 short *sgpuData = ((short *) baseAddr);
2993 short s;
2994
2995 iSpriteTex=1;
2996
2997 sprtX = sgpuData[2];
2998 sprtY = sgpuData[3];
2999 sprtW = 16;
3000 sprtH = 16;
3001
3002 lx0 = sprtX;
3003 ly0 = sprtY;
3004
3005 offsetST();
3006
3007 // do texture stuff
3008 gl_ux[0]=gl_ux[3]=baseAddr[8];//gpuData[2]&0xff;
3009
3010 if(usMirror & 0x1000)
3011 {
3012 s=gl_ux[0];
3013 s-=sprtW-1;
3014 if(s<0) {s=0;}
3015 gl_ux[0]=gl_ux[3]=s;
3016 }
3017
3018 sSprite_ux2=s=gl_ux[0]+sprtW;
3019 if(s) s--;
3020 if(s>255) s=255;
3021 gl_ux[1]=gl_ux[2]=s;
3022 // Y coords
3023 gl_vy[0]=gl_vy[1]=baseAddr[9];//(gpuData[2]>>8)&0xff;
3024
3025 if(usMirror & 0x2000)
3026 {
3027 s=gl_vy[0];
3028 s-=sprtH-1;
3029 if(s<0) {s=0;}
3030 gl_vy[0]=gl_vy[1]=s;
3031 }
3032
3033 sSprite_vy2=s=gl_vy[0]+sprtH;
3034 if(s) s--;
3035 if(s>255) s=255;
3036 gl_vy[2]=gl_vy[3]=s;
3037
3038 ulClutID=(gpuData[2]>>16);
3039
3040 bDrawTextured = TRUE;
3041 bDrawSmoothShaded = FALSE;
3042 SetRenderState(gpuData[0]);
3043
3044 /* if(iOffscreenDrawing)
3045 {
3046 offsetPSX4();
3047
3048 if(bDrawOffscreen4())
3049 {
3050 InvalidateTextureAreaEx();
3051 SetRenderColor(gpuData[0]);
3052 lx0-=PSXDisplay.DrawOffset.x;
3053 ly0-=PSXDisplay.DrawOffset.y;
3054 if(bUsingTWin) DrawSoftwareSpriteTWin(baseAddr,16,16);
3055 else
3056 if(usMirror) DrawSoftwareSpriteMirror(baseAddr,16,16);
3057 else
3058 DrawSoftwareSprite(baseAddr,16,16,baseAddr[8],baseAddr[9]);
3059 }
3060 }
3061 */
3062 SetRenderMode(gpuData[0], TRUE);
3063 SetZMask4SP();
3064
3065 sSprite_ux2=gl_ux[0]+sprtW;
3066 sSprite_vy2=gl_vy[0]+sprtH;
3067
3068 assignTextureSprite();
3069
3070 if(iFilterType>4)
3071 DrawMultiFilterSprite();
3072 else
3073 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
3074
3075 if(bDrawMultiPass)
3076 {
3077 SetSemiTransMulti(1);
3078 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
3079 }
3080
3081 if(ubOpaqueDraw)
3082 {
3083 SetZMask4O();
3084 if(bUseMultiPass) SetOpaqueColor(gpuData[0]);
3085 DEFOPAQUEON
3086
3087 /* if(bSmallAlpha && iFilterType<=2)
3088 {
3089 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3090 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3091 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
3092 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3093 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3094 SetZMask4O();
3095 }
3096 */
3097 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
3098 DEFOPAQUEOFF
3099 }
3100
3101 iSpriteTex=0;
3102 iDrawnSomething=1;
3103 }
3104
3105 ////////////////////////////////////////////////////////////////////////
3106 // cmd: free-size sprite (textured rect)
3107 ////////////////////////////////////////////////////////////////////////
3108
primSprtSRest(unsigned char * baseAddr,unsigned short type)3109 void primSprtSRest(unsigned char * baseAddr,unsigned short type)
3110 {
3111 unsigned long *gpuData = ((unsigned long *) baseAddr);
3112 short *sgpuData = ((short *) baseAddr);
3113 short s;unsigned short sTypeRest=0;
3114
3115 sprtX = sgpuData[2];
3116 sprtY = sgpuData[3];
3117 sprtW = sgpuData[6] & 0x3ff;
3118 sprtH = sgpuData[7] & 0x1ff;
3119
3120
3121 // do texture stuff
3122 switch(type)
3123 {
3124 case 1:
3125 gl_vy[0]=gl_vy[1]=baseAddr[9];
3126 s=256-baseAddr[8];
3127 sprtW-=s;
3128 sprtX+=s;
3129 gl_ux[0]=gl_ux[3]=0;
3130 break;
3131 case 2:
3132 gl_ux[0]=gl_ux[3]=baseAddr[8];
3133 s=256-baseAddr[9];
3134 sprtH-=s;
3135 sprtY+=s;
3136 gl_vy[0]=gl_vy[1]=0;
3137 break;
3138 case 3:
3139 s=256-baseAddr[8];
3140 sprtW-=s;
3141 sprtX+=s;
3142 gl_ux[0]=gl_ux[3]=0;
3143 s=256-baseAddr[9];
3144 sprtH-=s;
3145 sprtY+=s;
3146 gl_vy[0]=gl_vy[1]=0;
3147 break;
3148
3149 case 4:
3150 gl_vy[0]=gl_vy[1]=baseAddr[9];
3151 s=512-baseAddr[8];
3152 sprtW-=s;
3153 sprtX+=s;
3154 gl_ux[0]=gl_ux[3]=0;
3155 break;
3156 case 5:
3157 gl_ux[0]=gl_ux[3]=baseAddr[8];
3158 s=512-baseAddr[9];
3159 sprtH-=s;
3160 sprtY+=s;
3161 gl_vy[0]=gl_vy[1]=0;
3162 break;
3163 case 6:
3164 s=512-baseAddr[8];
3165 sprtW-=s;
3166 sprtX+=s;
3167 gl_ux[0]=gl_ux[3]=0;
3168 s=512-baseAddr[9];
3169 sprtH-=s;
3170 sprtY+=s;
3171 gl_vy[0]=gl_vy[1]=0;
3172 break;
3173
3174 }
3175
3176 if(usMirror & 0x1000)
3177 {
3178 s=gl_ux[0];
3179 s-=sprtW-1;if(s<0) s=0;
3180 gl_ux[0]=gl_ux[3]=s;
3181 }
3182 if(usMirror & 0x2000)
3183 {
3184 s=gl_vy[0];
3185 s-=sprtH-1;if(s<0) {s=0;}
3186 gl_vy[0]=gl_vy[1]=s;
3187 }
3188
3189 sSprite_ux2=s=gl_ux[0]+sprtW;
3190 if(s>255) s=255;
3191 gl_ux[1]=gl_ux[2]=s;
3192 sSprite_vy2=s=gl_vy[0]+sprtH;
3193 if(s>255) s=255;
3194 gl_vy[2]=gl_vy[3]=s;
3195
3196 if(!bUsingTWin)
3197 {
3198 if(sSprite_ux2>256)
3199 {sprtW=256-gl_ux[0];sSprite_ux2=256;sTypeRest+=1;}
3200 if(sSprite_vy2>256)
3201 {sprtH=256-gl_vy[0];sSprite_vy2=256;sTypeRest+=2;}
3202 }
3203
3204 lx0 = sprtX;
3205 ly0 = sprtY;
3206
3207 offsetST();
3208
3209 ulClutID=(gpuData[2]>>16);
3210
3211 bDrawTextured = TRUE;
3212 bDrawSmoothShaded = FALSE;
3213 SetRenderState(gpuData[0]);
3214
3215 /* if(iOffscreenDrawing)
3216 {
3217 offsetPSX4();
3218
3219 if(bDrawOffscreen4())
3220 {
3221 InvalidateTextureAreaEx();
3222 SetRenderColor(gpuData[0]);
3223 lx0-=PSXDisplay.DrawOffset.x;
3224 ly0-=PSXDisplay.DrawOffset.y;
3225 if(bUsingTWin) DrawSoftwareSpriteTWin(baseAddr,sprtW,sprtH);
3226 else
3227 if(usMirror) DrawSoftwareSpriteMirror(baseAddr,sprtW,sprtH);
3228 else
3229 DrawSoftwareSprite(baseAddr,sprtW,sprtH,baseAddr[8],baseAddr[9]);
3230 }
3231 }
3232 */
3233 SetRenderMode(gpuData[0], TRUE);
3234 SetZMask4SP();
3235
3236 sSprite_ux2=gl_ux[0]+sprtW;
3237 sSprite_vy2=gl_vy[0]+sprtH;
3238
3239 assignTextureSprite();
3240
3241 if(iFilterType>4)
3242 DrawMultiFilterSprite();
3243 else
3244 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
3245
3246 if(bDrawMultiPass)
3247 {
3248 SetSemiTransMulti(1);
3249 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
3250 }
3251
3252 if(ubOpaqueDraw)
3253 {
3254 SetZMask4O();
3255 if(bUseMultiPass) SetOpaqueColor(gpuData[0]);
3256 DEFOPAQUEON
3257
3258 /* if(bSmallAlpha && iFilterType<=2)
3259 {
3260 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3261 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3262 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
3263 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3264 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3265 SetZMask4O();
3266 }
3267 */
3268 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
3269 DEFOPAQUEOFF
3270 }
3271
3272 if(sTypeRest && type<4)
3273 {
3274 if(sTypeRest&1 && type==1) primSprtSRest(baseAddr,4);
3275 if(sTypeRest&2 && type==2) primSprtSRest(baseAddr,5);
3276 if(sTypeRest==3 && type==3) primSprtSRest(baseAddr,6);
3277 }
3278 }
3279
primSprtS(unsigned char * baseAddr)3280 void primSprtS(unsigned char * baseAddr)
3281 {
3282 unsigned long *gpuData = ((unsigned long *) baseAddr);
3283 short *sgpuData = ((short *) baseAddr);
3284
3285 short s;unsigned short sTypeRest=0;
3286
3287 sprtX = sgpuData[2];
3288 sprtY = sgpuData[3];
3289 sprtW = sgpuData[6] & 0x3ff;
3290 sprtH = sgpuData[7] & 0x1ff;
3291
3292 if(!sprtH) return;
3293 if(!sprtW) return;
3294
3295 iSpriteTex=1;
3296
3297 // do texture stuff
3298 gl_ux[0]=gl_ux[3]=baseAddr[8];//gpuData[2]&0xff;
3299 gl_vy[0]=gl_vy[1]=baseAddr[9];//(gpuData[2]>>8)&0xff;
3300
3301 if(usMirror & 0x1000)
3302 {
3303 s=gl_ux[0];
3304 s-=sprtW-1;
3305 if(s<0) {s=0;}
3306 gl_ux[0]=gl_ux[3]=s;
3307 }
3308 if(usMirror & 0x2000)
3309 {
3310 s=gl_vy[0];
3311 s-=sprtH-1;
3312 if(s<0) {s=0;}
3313 gl_vy[0]=gl_vy[1]=s;
3314 }
3315
3316 sSprite_ux2=s=gl_ux[0]+sprtW;
3317 if(s) s--;
3318 if(s>255) s=255;
3319 gl_ux[1]=gl_ux[2]=s;
3320 sSprite_vy2=s=gl_vy[0]+sprtH;
3321 if(s) s--;
3322 if(s>255) s=255;
3323 gl_vy[2]=gl_vy[3]=s;
3324
3325 if(!bUsingTWin)
3326 {
3327 if(sSprite_ux2>256)
3328 {sprtW=256-gl_ux[0];sSprite_ux2=256;sTypeRest+=1;}
3329 if(sSprite_vy2>256)
3330 {sprtH=256-gl_vy[0];sSprite_vy2=256;sTypeRest+=2;}
3331 }
3332
3333 lx0 = sprtX;
3334 ly0 = sprtY;
3335
3336 offsetST();
3337
3338 ulClutID=(gpuData[2]>>16);
3339
3340 bDrawTextured = TRUE;
3341 bDrawSmoothShaded = FALSE;
3342 SetRenderState(gpuData[0]);
3343
3344 /* if(iOffscreenDrawing)
3345 {
3346 offsetPSX4();
3347
3348 if(bDrawOffscreen4())
3349 {
3350 InvalidateTextureAreaEx();
3351 SetRenderColor(gpuData[0]);
3352 lx0-=PSXDisplay.DrawOffset.x;
3353 ly0-=PSXDisplay.DrawOffset.y;
3354 if(bUsingTWin) DrawSoftwareSpriteTWin(baseAddr,sprtW,sprtH);
3355 else
3356 if(usMirror) DrawSoftwareSpriteMirror(baseAddr,sprtW,sprtH);
3357 else
3358 DrawSoftwareSprite(baseAddr,sprtW,sprtH,baseAddr[8],baseAddr[9]);
3359 }
3360 }
3361 */
3362 SetRenderMode(gpuData[0], TRUE);
3363 SetZMask4SP();
3364
3365 if((dwActFixes&1) && gTexFrameName && gTexName==gTexFrameName)
3366 {iSpriteTex=0;return;}
3367
3368 sSprite_ux2=gl_ux[0]+sprtW;
3369 sSprite_vy2=gl_vy[0]+sprtH;
3370
3371 assignTextureSprite();
3372
3373 if(iFilterType>4)
3374 DrawMultiFilterSprite();
3375 else
3376 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
3377
3378 if(bDrawMultiPass)
3379 {
3380 SetSemiTransMulti(1);
3381 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
3382 }
3383
3384 if(ubOpaqueDraw)
3385 {
3386 SetZMask4O();
3387 if(bUseMultiPass) SetOpaqueColor(gpuData[0]);
3388 DEFOPAQUEON
3389
3390 /* if(bSmallAlpha && iFilterType<=2)
3391 {
3392 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3393 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3394 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
3395 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3396 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3397 SetZMask4O();
3398 }
3399 */
3400 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
3401 DEFOPAQUEOFF
3402 }
3403
3404 if(sTypeRest)
3405 {
3406 if(sTypeRest&1) primSprtSRest(baseAddr,1);
3407 if(sTypeRest&2) primSprtSRest(baseAddr,2);
3408 if(sTypeRest==3) primSprtSRest(baseAddr,3);
3409 }
3410
3411 iSpriteTex=0;
3412 iDrawnSomething=1;
3413 }
3414
3415 ////////////////////////////////////////////////////////////////////////
3416 // cmd: flat shaded Poly4
3417 ////////////////////////////////////////////////////////////////////////
3418
primPolyF4(unsigned char * baseAddr)3419 void primPolyF4(unsigned char *baseAddr)
3420 {
3421 unsigned long *gpuData = ((unsigned long *) baseAddr);
3422 short *sgpuData = ((short *) baseAddr);
3423
3424 lx0 = sgpuData[2];
3425 ly0 = sgpuData[3];
3426 lx1 = sgpuData[4];
3427 ly1 = sgpuData[5];
3428 lx2 = sgpuData[6];
3429 ly2 = sgpuData[7];
3430 lx3 = sgpuData[8];
3431 ly3 = sgpuData[9];
3432
3433 if(offset4()) return;
3434
3435 bDrawTextured = FALSE;
3436 bDrawSmoothShaded = FALSE;
3437 SetRenderState(gpuData[0]);
3438
3439 /* if(iOffscreenDrawing)
3440 {
3441 offsetPSX4();
3442 if(bDrawOffscreen4())
3443 {
3444 InvalidateTextureAreaEx();
3445 drawPoly4F(gpuData[0]);
3446 }
3447 }
3448 */
3449 SetRenderMode(gpuData[0], FALSE);
3450 SetZMask4NT();
3451
3452 vertex[0].c.lcol=gpuData[0];vertex[0].c.col[3]=ubGloColAlpha;
3453 SETCOL(vertex[0]);
3454
3455 PRIMdrawTri2(&vertex[0], &vertex[1], &vertex[2],&vertex[3]);
3456
3457 iDrawnSomething=1;
3458 }
3459
3460 ////////////////////////////////////////////////////////////////////////
3461 // cmd: smooth shaded Poly4
3462 ////////////////////////////////////////////////////////////////////////
3463
3464 void primPolyG4(unsigned char * baseAddr);
3465
bDrawOffscreenFrontFF9G4(void)3466 BOOL bDrawOffscreenFrontFF9G4(void)
3467 {
3468 if(lx0< PSXDisplay.DisplayPosition.x) return FALSE; // must be complete in front
3469 if(lx0> PSXDisplay.DisplayEnd.x) return FALSE;
3470 if(ly0< PSXDisplay.DisplayPosition.y) return FALSE;
3471 if(ly0> PSXDisplay.DisplayEnd.y) return FALSE;
3472 if(lx1< PSXDisplay.DisplayPosition.x) return FALSE;
3473 if(lx1> PSXDisplay.DisplayEnd.x) return FALSE;
3474 if(ly1< PSXDisplay.DisplayPosition.y) return FALSE;
3475 if(ly1> PSXDisplay.DisplayEnd.y) return FALSE;
3476 if(lx2< PSXDisplay.DisplayPosition.x) return FALSE;
3477 if(lx2> PSXDisplay.DisplayEnd.x) return FALSE;
3478 if(ly2< PSXDisplay.DisplayPosition.y) return FALSE;
3479 if(ly2> PSXDisplay.DisplayEnd.y) return FALSE;
3480 if(lx3< PSXDisplay.DisplayPosition.x) return FALSE;
3481 if(lx3> PSXDisplay.DisplayEnd.x) return FALSE;
3482 if(ly3< PSXDisplay.DisplayPosition.y) return FALSE;
3483 if(ly3> PSXDisplay.DisplayEnd.y) return FALSE;
3484 return TRUE;
3485 }
3486
bCheckFF9G4(unsigned char * baseAddr)3487 BOOL bCheckFF9G4(unsigned char * baseAddr)
3488 {
3489 static unsigned char pFF9G4Cache[32];
3490 static int iFF9Fix=0;
3491
3492 if(baseAddr)
3493 {
3494 if(iFF9Fix==0)
3495 {
3496 if(bDrawOffscreenFrontFF9G4())
3497 {
3498 short *sgpuData = ((short *) pFF9G4Cache);
3499 iFF9Fix=2;
3500 memcpy(pFF9G4Cache,baseAddr,32);
3501
3502 if(sgpuData[2]==142)
3503 {
3504 sgpuData[2] +=65;
3505 sgpuData[10]+=65;
3506 }
3507 return TRUE;
3508 }
3509 else iFF9Fix=1;
3510 }
3511 return FALSE;
3512 }
3513
3514 if(iFF9Fix==2)
3515 {
3516 long labr=GlobalTextABR;
3517 GlobalTextABR=1;
3518 primPolyG4(pFF9G4Cache);
3519 GlobalTextABR=labr;
3520 }
3521 iFF9Fix=0;
3522
3523 return FALSE;
3524 }
3525
3526 ////////////////////////////////////////////////////////////////////////
3527
primPolyG4(unsigned char * baseAddr)3528 void primPolyG4(unsigned char * baseAddr)
3529 {
3530 unsigned long *gpuData = (unsigned long *)baseAddr;
3531 short *sgpuData = ((short *) baseAddr);
3532
3533 lx0 = sgpuData[2];
3534 ly0 = sgpuData[3];
3535 lx1 = sgpuData[6];
3536 ly1 = sgpuData[7];
3537 lx2 = sgpuData[10];
3538 ly2 = sgpuData[11];
3539 lx3 = sgpuData[14];
3540 ly3 = sgpuData[15];
3541
3542 if(offset4()) return;
3543
3544 bDrawTextured = FALSE;
3545 bDrawSmoothShaded = TRUE;
3546 SetRenderState(gpuData[0]);
3547
3548 /* if(iOffscreenDrawing)
3549 {
3550 offsetPSX4();
3551
3552 if((dwActFixes&512) && bCheckFF9G4(baseAddr)) return;
3553
3554 if(bDrawOffscreen4())
3555 {
3556 InvalidateTextureAreaEx();
3557 drawPoly4G(gpuData[0], gpuData[2], gpuData[4], gpuData[6]);
3558 }
3559 }
3560 */
3561 SetRenderMode(gpuData[0], FALSE);
3562 SetZMask4NT();
3563
3564 vertex[0].c.lcol=gpuData[0];
3565 vertex[1].c.lcol=gpuData[2];
3566 vertex[2].c.lcol=gpuData[4];
3567 vertex[3].c.lcol=gpuData[6];
3568
3569 vertex[0].c.col[3]=vertex[1].c.col[3]=vertex[2].c.col[3]=vertex[3].c.col[3]=ubGloAlpha;
3570
3571
3572 PRIMdrawGouraudTri2Color(&vertex[0],&vertex[1], &vertex[2], &vertex[3]);
3573
3574 iDrawnSomething=1;
3575 }
3576
3577 ////////////////////////////////////////////////////////////////////////
3578 // cmd: flat shaded Texture3
3579 ////////////////////////////////////////////////////////////////////////
3580
DoLineCheck(unsigned long * gpuData)3581 BOOL DoLineCheck(unsigned long * gpuData)
3582 {
3583 BOOL bQuad=FALSE;short dx,dy;
3584
3585 if(lx0==lx1)
3586 {
3587 dx=lx0-lx2;if(dx<0) dx=-dx;
3588
3589 if(ly1==ly2)
3590 {
3591 dy=ly1-ly0;if(dy<0) dy=-dy;
3592 if(dx<=1)
3593 {
3594 vertex[3]=vertex[2];
3595 vertex[2]=vertex[0];
3596 vertex[2].x=vertex[3].x;
3597 }
3598 else
3599 if(dy<=1)
3600 {
3601 vertex[3]=vertex[2];
3602 vertex[2].y=vertex[0].y;
3603 }
3604 else return FALSE;
3605
3606 bQuad=TRUE;
3607 }
3608 else
3609 if(ly0==ly2)
3610 {
3611 dy=ly0-ly1;if(dy<0) dy=-dy;
3612 if(dx<=1)
3613 {
3614 vertex[3]=vertex[1];
3615 vertex[3].x=vertex[2].x;
3616 }
3617 else
3618 if(dy<=1)
3619 {
3620 vertex[3]=vertex[2];
3621 vertex[3].y=vertex[1].y;
3622 }
3623 else return FALSE;
3624
3625 bQuad=TRUE;
3626 }
3627 }
3628
3629 if(lx0==lx2)
3630 {
3631 dx=lx0-lx1;if(dx<0) dx=-dx;
3632
3633 if(ly2==ly1)
3634 {
3635 dy=ly2-ly0;if(dy<0) dy=-dy;
3636 if(dx<=1)
3637 {
3638 vertex[3]=vertex[1];
3639 vertex[1]=vertex[0];
3640 vertex[1].x=vertex[3].x;
3641 }
3642 else
3643 if(dy<=1)
3644 {
3645 vertex[3]=vertex[1];
3646 vertex[1].y=vertex[0].y;
3647 }
3648 else return FALSE;
3649
3650 bQuad=TRUE;
3651 }
3652 else
3653 if(ly0==ly1)
3654 {
3655 dy=ly2-ly0;if(dy<0) dy=-dy;
3656 if(dx<=1)
3657 {
3658 vertex[3]=vertex[2];
3659 vertex[3].x=vertex[1].x;
3660 }
3661 else
3662 if(dy<=1)
3663 {
3664 vertex[3]=vertex[1];
3665 vertex[3].y=vertex[2].y;
3666 }
3667 else return FALSE;
3668
3669 bQuad=TRUE;
3670 }
3671 }
3672
3673 if(lx1==lx2)
3674 {
3675 dx=lx1-lx0;if(dx<0) dx=-dx;
3676
3677 if(ly1==ly0)
3678 {
3679 dy=ly1-ly2;if(dy<0) dy=-dy;
3680
3681 if(dx<=1)
3682 {
3683 vertex[3]=vertex[2];
3684 vertex[2].x=vertex[0].x;
3685 }
3686 else
3687 if(dy<=1)
3688 {
3689 vertex[3]=vertex[2];
3690 vertex[2]=vertex[0];
3691 vertex[2].y=vertex[3].y;
3692 }
3693 else return FALSE;
3694
3695 bQuad=TRUE;
3696 }
3697 else
3698 if(ly2==ly0)
3699 {
3700 dy=ly2-ly1;if(dy<0) dy=-dy;
3701
3702 if(dx<=1)
3703 {
3704 vertex[3]=vertex[1];
3705 vertex[1].x=vertex[0].x;
3706 }
3707 else
3708 if(dy<=1)
3709 {
3710 vertex[3]=vertex[1];
3711 vertex[1]=vertex[0];
3712 vertex[1].y=vertex[3].y;
3713 }
3714 else return FALSE;
3715
3716 bQuad=TRUE;
3717 }
3718 }
3719
3720 if(!bQuad) return FALSE;
3721
3722 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[3], &vertex[2]);
3723
3724 if(bDrawMultiPass)
3725 {
3726 SetSemiTransMulti(1);
3727 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[3], &vertex[2]);
3728 }
3729
3730 if(ubOpaqueDraw)
3731 {
3732 SetZMask4O();
3733 if(bUseMultiPass) SetOpaqueColor(gpuData[0]);
3734 DEFOPAQUEON
3735 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[3], &vertex[2]);
3736 DEFOPAQUEOFF
3737 }
3738
3739 iDrawnSomething=1;
3740
3741 return TRUE;
3742 }
3743
3744 ////////////////////////////////////////////////////////////////////////
3745
primPolyFT3(unsigned char * baseAddr)3746 void primPolyFT3(unsigned char * baseAddr)
3747 {
3748 unsigned long *gpuData = ((unsigned long *) baseAddr);
3749 short *sgpuData = ((short *) baseAddr);
3750
3751 lx0 = sgpuData[2];
3752 ly0 = sgpuData[3];
3753 lx1 = sgpuData[6];
3754 ly1 = sgpuData[7];
3755 lx2 = sgpuData[10];
3756 ly2 = sgpuData[11];
3757
3758 if(offset3()) return;
3759
3760 // do texture UV coordinates stuff
3761 gl_ux[0]=gl_ux[3]=baseAddr[8];//gpuData[2]&0xff;
3762 gl_vy[0]=gl_vy[3]=baseAddr[9];//(gpuData[2]>>8)&0xff;
3763 gl_ux[1]=baseAddr[16];//gpuData[4]&0xff;
3764 gl_vy[1]=baseAddr[17];//(gpuData[4]>>8)&0xff;
3765 gl_ux[2]=baseAddr[24];//gpuData[6]&0xff;
3766 gl_vy[2]=baseAddr[25];//(gpuData[6]>>8)&0xff;
3767
3768 UpdateGlobalTP((unsigned short)(gpuData[4]>>16));
3769 ulClutID=gpuData[2]>>16;
3770
3771 bDrawTextured = TRUE;
3772 bDrawSmoothShaded = FALSE;
3773 SetRenderState(gpuData[0]);
3774
3775 /* if(iOffscreenDrawing)
3776 {
3777 offsetPSX3();
3778 if(bDrawOffscreen3())
3779 {
3780 InvalidateTextureAreaEx();
3781 SetRenderColor(gpuData[0]);
3782 drawPoly3FT(baseAddr);
3783 }
3784 }
3785 */
3786 SetRenderMode(gpuData[0], TRUE);
3787 SetZMask3();
3788
3789 assignTexture3();
3790
3791 if(!(dwActFixes&0x10))
3792 {
3793 if(DoLineCheck(gpuData)) return;
3794 }
3795
3796 PRIMdrawTexturedTri(&vertex[0], &vertex[1], &vertex[2]);
3797
3798 if(bDrawMultiPass)
3799 {
3800 SetSemiTransMulti(1);
3801 PRIMdrawTexturedTri(&vertex[0], &vertex[1], &vertex[2]);
3802 }
3803
3804 if(ubOpaqueDraw)
3805 {
3806 SetZMask3O();
3807 if(bUseMultiPass) SetOpaqueColor(gpuData[0]);
3808 DEFOPAQUEON
3809 PRIMdrawTexturedTri(&vertex[0], &vertex[1], &vertex[2]);
3810 DEFOPAQUEOFF
3811 }
3812
3813 iDrawnSomething=1;
3814 }
3815
3816 ////////////////////////////////////////////////////////////////////////
3817 // cmd: flat shaded Texture4
3818 ////////////////////////////////////////////////////////////////////////
3819
3820 #define ST_FAC 255.99f
3821
RectTexAlign(void)3822 void RectTexAlign(void)
3823 {
3824 int UFlipped = FALSE;
3825 int VFlipped = FALSE;
3826
3827 if(gTexName==gTexFrameName) return;
3828
3829 if(ly0==ly1)
3830 {
3831 if(!((lx1==lx3 && ly3==ly2 && lx2==lx0) ||
3832 (lx1==lx2 && ly2==ly3 && lx3==lx0)))
3833 return;
3834
3835 if(ly0<ly2)
3836 {
3837 if (vertex[0].tow > vertex[2].tow)
3838 VFlipped = 1;
3839 }
3840 else
3841 {
3842 if (vertex[0].tow < vertex[2].tow)
3843 VFlipped = 2;
3844 }
3845 }
3846 else
3847 if(ly0==ly2)
3848 {
3849 if(!((lx2==lx3 && ly3==ly1 && lx1==lx0) ||
3850 (lx2==lx1 && ly1==ly3 && lx3==lx0)))
3851 return;
3852
3853 if(ly0<ly1)
3854 {
3855 if (vertex[0].tow > vertex[1].tow)
3856 VFlipped = 3;
3857 }
3858 else
3859 {
3860 if (vertex[0].tow < vertex[1].tow)
3861 VFlipped = 4;
3862 }
3863 }
3864 else
3865 if(ly0==ly3)
3866 {
3867 if(!((lx3==lx2 && ly2==ly1 && lx1==lx0) ||
3868 (lx3==lx1 && ly1==ly2 && lx2==lx0)))
3869 return;
3870
3871 if(ly0<ly1)
3872 {
3873 if (vertex[0].tow > vertex[1].tow)
3874 VFlipped = 5;
3875 }
3876 else
3877 {
3878 if (vertex[0].tow < vertex[1].tow)
3879 VFlipped = 6;
3880 }
3881 }
3882 else return;
3883
3884 if(lx0==lx1)
3885 {
3886 if(lx0<lx2)
3887 {
3888 if (vertex[0].sow > vertex[2].sow)
3889 UFlipped = 1;
3890 }
3891 else
3892 {
3893 if (vertex[0].sow < vertex[2].sow)
3894 UFlipped = 2;
3895 }
3896 }
3897 else
3898 if(lx0==lx2)
3899 {
3900 if(lx0<lx1)
3901 {
3902 if (vertex[0].sow > vertex[1].sow)
3903 UFlipped = 3;
3904 }
3905 else
3906 {
3907 if (vertex[0].sow < vertex[1].sow)
3908 UFlipped = 4;
3909 }
3910 }
3911 else
3912 if(lx0==lx3)
3913 {
3914 if(lx0<lx1)
3915 {
3916 if (vertex[0].sow > vertex[1].sow)
3917 UFlipped = 5;
3918 }
3919 else
3920 {
3921 if (vertex[0].sow < vertex[1].sow)
3922 UFlipped = 6;
3923 }
3924 }
3925
3926 if (UFlipped)
3927 {
3928 #ifdef OWNSCALE
3929 if(bUsingTWin)
3930 {
3931 switch(UFlipped)
3932 {
3933 case 1:
3934 vertex[2].sow+=0.95f/TWin.UScaleFactor;
3935 vertex[3].sow+=0.95f/TWin.UScaleFactor;
3936 break;
3937 case 2:
3938 vertex[0].sow+=0.95f/TWin.UScaleFactor;
3939 vertex[1].sow+=0.95f/TWin.UScaleFactor;
3940 break;
3941 case 3:
3942 vertex[1].sow+=0.95f/TWin.UScaleFactor;
3943 vertex[3].sow+=0.95f/TWin.UScaleFactor;
3944 break;
3945 case 4:
3946 vertex[0].sow+=0.95f/TWin.UScaleFactor;
3947 vertex[2].sow+=0.95f/TWin.UScaleFactor;
3948 break;
3949 case 5:
3950 vertex[1].sow+=0.95f/TWin.UScaleFactor;
3951 vertex[2].sow+=0.95f/TWin.UScaleFactor;
3952 break;
3953 case 6:
3954 vertex[0].sow+=0.95f/TWin.UScaleFactor;
3955 vertex[3].sow+=0.95f/TWin.UScaleFactor;
3956 break;
3957 }
3958 }
3959 else
3960 {
3961 switch(UFlipped)
3962 {
3963 case 1:
3964 vertex[2].sow+=1.0f/ST_FAC;
3965 vertex[3].sow+=1.0f/ST_FAC;
3966 break;
3967 case 2:
3968 vertex[0].sow+=1.0f/ST_FAC;
3969 vertex[1].sow+=1.0f/ST_FAC;
3970 break;
3971 case 3:
3972 vertex[1].sow+=1.0f/ST_FAC;
3973 vertex[3].sow+=1.0f/ST_FAC;
3974 break;
3975 case 4:
3976 vertex[0].sow+=1.0f/ST_FAC;
3977 vertex[2].sow+=1.0f/ST_FAC;
3978 break;
3979 case 5:
3980 vertex[1].sow+=1.0f/ST_FAC;
3981 vertex[2].sow+=1.0f/ST_FAC;
3982 break;
3983 case 6:
3984 vertex[0].sow+=1.0f/ST_FAC;
3985 vertex[3].sow+=1.0f/ST_FAC;
3986 break;
3987 }
3988 }
3989 #else
3990 if(bUsingTWin)
3991 {
3992 switch(UFlipped)
3993 {
3994 case 1:
3995 vertex[2].sow+=1.0f/TWin.UScaleFactor;
3996 vertex[3].sow+=1.0f/TWin.UScaleFactor;
3997 break;
3998 case 2:
3999 vertex[0].sow+=1.0f/TWin.UScaleFactor;
4000 vertex[1].sow+=1.0f/TWin.UScaleFactor;
4001 break;
4002 case 3:
4003 vertex[1].sow+=1.0f/TWin.UScaleFactor;
4004 vertex[3].sow+=1.0f/TWin.UScaleFactor;
4005 break;
4006 case 4:
4007 vertex[0].sow+=1.0f/TWin.UScaleFactor;
4008 vertex[2].sow+=1.0f/TWin.UScaleFactor;
4009 break;
4010 case 5:
4011 vertex[1].sow+=1.0f/TWin.UScaleFactor;
4012 vertex[2].sow+=1.0f/TWin.UScaleFactor;
4013 break;
4014 case 6:
4015 vertex[0].sow+=1.0f/TWin.UScaleFactor;
4016 vertex[3].sow+=1.0f/TWin.UScaleFactor;
4017 break;
4018 }
4019 }
4020 else
4021 {
4022 switch(UFlipped)
4023 {
4024 case 1:
4025 vertex[2].sow+=1.0f;
4026 vertex[3].sow+=1.0f;
4027 break;
4028 case 2:
4029 vertex[0].sow+=1.0f;
4030 vertex[1].sow+=1.0f;
4031 break;
4032 case 3:
4033 vertex[1].sow+=1.0f;
4034 vertex[3].sow+=1.0f;
4035 break;
4036 case 4:
4037 vertex[0].sow+=1.0f;
4038 vertex[2].sow+=1.0f;
4039 break;
4040 case 5:
4041 vertex[1].sow+=1.0f;
4042 vertex[2].sow+=1.0f;
4043 break;
4044 case 6:
4045 vertex[0].sow+=1.0f;
4046 vertex[3].sow+=1.0f;
4047 break;
4048 }
4049 }
4050 #endif
4051 }
4052
4053 if (VFlipped)
4054 {
4055 #ifdef OWNSCALE
4056 if(bUsingTWin)
4057 {
4058 switch(VFlipped)
4059 {
4060 case 1:
4061 vertex[2].tow+=0.95f/TWin.VScaleFactor;
4062 vertex[3].tow+=0.95f/TWin.VScaleFactor;
4063 break;
4064 case 2:
4065 vertex[0].tow+=0.95f/TWin.VScaleFactor;
4066 vertex[1].tow+=0.95f/TWin.VScaleFactor;
4067 break;
4068 case 3:
4069 vertex[1].tow+=0.95f/TWin.VScaleFactor;
4070 vertex[3].tow+=0.95f/TWin.VScaleFactor;
4071 break;
4072 case 4:
4073 vertex[0].tow+=0.95f/TWin.VScaleFactor;
4074 vertex[2].tow+=0.95f/TWin.VScaleFactor;
4075 break;
4076 case 5:
4077 vertex[1].tow+=0.95f/TWin.VScaleFactor;
4078 vertex[2].tow+=0.95f/TWin.VScaleFactor;
4079 break;
4080 case 6:
4081 vertex[0].tow+=0.95f/TWin.VScaleFactor;
4082 vertex[3].tow+=0.95f/TWin.VScaleFactor;
4083 break;
4084 }
4085 }
4086 else
4087 {
4088 switch(VFlipped)
4089 {
4090 case 1:
4091 vertex[2].tow+=1.0f/ST_FAC;
4092 vertex[3].tow+=1.0f/ST_FAC;
4093 break;
4094 case 2:
4095 vertex[0].tow+=1.0f/ST_FAC;
4096 vertex[1].tow+=1.0f/ST_FAC;
4097 break;
4098 case 3:
4099 vertex[1].tow+=1.0f/ST_FAC;
4100 vertex[3].tow+=1.0f/ST_FAC;
4101 break;
4102 case 4:
4103 vertex[0].tow+=1.0f/ST_FAC;
4104 vertex[2].tow+=1.0f/ST_FAC;
4105 break;
4106 case 5:
4107 vertex[1].tow+=1.0f/ST_FAC;
4108 vertex[2].tow+=1.0f/ST_FAC;
4109 break;
4110 case 6:
4111 vertex[0].tow+=1.0f/ST_FAC;
4112 vertex[3].tow+=1.0f/ST_FAC;
4113 break;
4114 }
4115 }
4116 #else
4117 if(bUsingTWin)
4118 {
4119 switch(VFlipped)
4120 {
4121 case 1:
4122 vertex[2].tow+=1.0f/TWin.VScaleFactor;
4123 vertex[3].tow+=1.0f/TWin.VScaleFactor;
4124 break;
4125 case 2:
4126 vertex[0].tow+=1.0f/TWin.VScaleFactor;
4127 vertex[1].tow+=1.0f/TWin.VScaleFactor;
4128 break;
4129 case 3:
4130 vertex[1].tow+=1.0f/TWin.VScaleFactor;
4131 vertex[3].tow+=1.0f/TWin.VScaleFactor;
4132 break;
4133 case 4:
4134 vertex[0].tow+=1.0f/TWin.VScaleFactor;
4135 vertex[2].tow+=1.0f/TWin.VScaleFactor;
4136 break;
4137 case 5:
4138 vertex[1].tow+=1.0f/TWin.VScaleFactor;
4139 vertex[2].tow+=1.0f/TWin.VScaleFactor;
4140 break;
4141 case 6:
4142 vertex[0].tow+=1.0f/TWin.VScaleFactor;
4143 vertex[3].tow+=1.0f/TWin.VScaleFactor;
4144 break;
4145 }
4146 }
4147 else
4148 {
4149 switch(VFlipped)
4150 {
4151 case 1:
4152 vertex[2].tow+=1.0f;
4153 vertex[3].tow+=1.0f;
4154 break;
4155 case 2:
4156 vertex[0].tow+=1.0f;
4157 vertex[1].tow+=1.0f;
4158 break;
4159 case 3:
4160 vertex[1].tow+=1.0f;
4161 vertex[3].tow+=1.0f;
4162 break;
4163 case 4:
4164 vertex[0].tow+=1.0f;
4165 vertex[2].tow+=1.0f;
4166 break;
4167 case 5:
4168 vertex[1].tow+=1.0f;
4169 vertex[2].tow+=1.0f;
4170 break;
4171 case 6:
4172 vertex[0].tow+=1.0f;
4173 vertex[3].tow+=1.0f;
4174 break;
4175 }
4176 }
4177 #endif
4178 }
4179
4180 }
4181
primPolyFT4(unsigned char * baseAddr)4182 void primPolyFT4(unsigned char * baseAddr)
4183 {
4184 unsigned long *gpuData = ((unsigned long *) baseAddr);
4185 short *sgpuData = ((short *) baseAddr);
4186
4187 lx0 = sgpuData[2];
4188 ly0 = sgpuData[3];
4189 lx1 = sgpuData[6];
4190 ly1 = sgpuData[7];
4191 lx2 = sgpuData[10];
4192 ly2 = sgpuData[11];
4193 lx3 = sgpuData[14];
4194 ly3 = sgpuData[15];
4195
4196 if(offset4()) return;
4197
4198 gl_vy[0]=baseAddr[9];//((gpuData[2]>>8)&0xff);
4199 gl_vy[1]=baseAddr[17];//((gpuData[4]>>8)&0xff);
4200 gl_vy[2]=baseAddr[25];//((gpuData[6]>>8)&0xff);
4201 gl_vy[3]=baseAddr[33];//((gpuData[8]>>8)&0xff);
4202
4203 gl_ux[0]=baseAddr[8];//(gpuData[2]&0xff);
4204 gl_ux[1]=baseAddr[16];//(gpuData[4]&0xff);
4205 gl_ux[2]=baseAddr[24];//(gpuData[6]&0xff);
4206 gl_ux[3]=baseAddr[32];//(gpuData[8]&0xff);
4207
4208 UpdateGlobalTP((unsigned short)(gpuData[4]>>16));
4209 ulClutID=(gpuData[2]>>16);
4210
4211 bDrawTextured = TRUE;
4212 bDrawSmoothShaded = FALSE;
4213 SetRenderState(gpuData[0]);
4214
4215 /* if(iOffscreenDrawing)
4216 {
4217 offsetPSX4();
4218 if(bDrawOffscreen4())
4219 {
4220 InvalidateTextureAreaEx();
4221 SetRenderColor(gpuData[0]);
4222 drawPoly4FT(baseAddr);
4223 }
4224 }
4225 */
4226 SetRenderMode(gpuData[0], TRUE);
4227
4228 SetZMask4();
4229
4230 assignTexture4();
4231
4232 RectTexAlign();
4233
4234 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[3], &vertex[2]);
4235
4236 if(bDrawMultiPass)
4237 {
4238 SetSemiTransMulti(1);
4239 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[3], &vertex[2]);
4240 }
4241
4242 if(ubOpaqueDraw)
4243 {
4244 SetZMask4O();
4245 if(bUseMultiPass) SetOpaqueColor(gpuData[0]);
4246 DEFOPAQUEON
4247
4248 /* if(bSmallAlpha && iFilterType<=2)
4249 {
4250 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4251 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4252 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[3], &vertex[2]);
4253 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
4254 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
4255 SetZMask4O();
4256 }
4257 */
4258
4259 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[3], &vertex[2]);
4260 DEFOPAQUEOFF
4261 }
4262
4263 iDrawnSomething=1;
4264 }
4265
4266 ////////////////////////////////////////////////////////////////////////
4267 // cmd: smooth shaded Texture3
4268 ////////////////////////////////////////////////////////////////////////
4269
primPolyGT3(unsigned char * baseAddr)4270 void primPolyGT3(unsigned char *baseAddr)
4271 {
4272 unsigned long *gpuData = ((unsigned long *) baseAddr);
4273 short *sgpuData = ((short *) baseAddr);
4274
4275 lx0 = sgpuData[2];
4276 ly0 = sgpuData[3];
4277 lx1 = sgpuData[8];
4278 ly1 = sgpuData[9];
4279 lx2 = sgpuData[14];
4280 ly2 = sgpuData[15];
4281
4282 if(offset3()) return;
4283
4284 // do texture stuff
4285 gl_ux[0]=gl_ux[3]=baseAddr[8];//gpuData[2]&0xff;
4286 gl_vy[0]=gl_vy[3]=baseAddr[9];//(gpuData[2]>>8)&0xff;
4287 gl_ux[1]=baseAddr[20];//gpuData[5]&0xff;
4288 gl_vy[1]=baseAddr[21];//(gpuData[5]>>8)&0xff;
4289 gl_ux[2]=baseAddr[32];//gpuData[8]&0xff;
4290 gl_vy[2]=baseAddr[33];//(gpuData[8]>>8)&0xff;
4291
4292 UpdateGlobalTP((unsigned short)(gpuData[5]>>16));
4293 ulClutID=(gpuData[2]>>16);
4294
4295 bDrawTextured = TRUE;
4296 bDrawSmoothShaded = TRUE;
4297 SetRenderState(gpuData[0]);
4298
4299 /* if(iOffscreenDrawing)
4300 {
4301 offsetPSX3();
4302 if(bDrawOffscreen3())
4303 {
4304 InvalidateTextureAreaEx();
4305 drawPoly3GT(baseAddr);
4306 }
4307 }
4308 */
4309 SetRenderMode(gpuData[0], FALSE);
4310 SetZMask3();
4311
4312 assignTexture3();
4313
4314 if(bDrawNonShaded)
4315 {
4316 //if(!bUseMultiPass) vertex[0].lcol=DoubleBGR2RGB(gpuData[0]); else vertex[0].lcol=gpuData[0];
4317 // eat this...
4318 /* if(bGLBlend) vertex[0].c.lcol=0x7f7f7f;
4319 else */vertex[0].c.lcol=0xffffff;
4320 vertex[0].c.col[3]=ubGloAlpha;
4321 SETCOL(vertex[0]);
4322
4323 PRIMdrawTexturedTri(&vertex[0], &vertex[1], &vertex[2]);
4324
4325 if(ubOpaqueDraw)
4326 {
4327 SetZMask3O();
4328 DEFOPAQUEON
4329 PRIMdrawTexturedTri(&vertex[0], &vertex[1], &vertex[2]);
4330 DEFOPAQUEOFF
4331 }
4332 return;
4333 }
4334
4335 /* if(!bUseMultiPass && !bGLBlend)
4336 {
4337 */ vertex[0].c.lcol=DoubleBGR2RGB(gpuData[0]);
4338 vertex[1].c.lcol=DoubleBGR2RGB(gpuData[3]);
4339 vertex[2].c.lcol=DoubleBGR2RGB(gpuData[6]);
4340 /*}
4341 else
4342 {
4343 vertex[0].c.lcol=gpuData[0];
4344 vertex[1].c.lcol=gpuData[3];
4345 vertex[2].c.lcol=gpuData[6];
4346 }*/
4347 vertex[0].c.col[3]=vertex[1].c.col[3]=vertex[2].c.col[3]=ubGloAlpha;
4348
4349 PRIMdrawTexGouraudTriColor(&vertex[0], &vertex[1], &vertex[2]);
4350
4351 if(bDrawMultiPass)
4352 {
4353 SetSemiTransMulti(1);
4354 PRIMdrawTexGouraudTriColor(&vertex[0], &vertex[1], &vertex[2]);
4355 }
4356
4357 if(ubOpaqueDraw)
4358 {
4359 SetZMask3O();
4360 if(bUseMultiPass)
4361 {
4362 vertex[0].c.lcol=DoubleBGR2RGB(gpuData[0]);
4363 vertex[1].c.lcol=DoubleBGR2RGB(gpuData[3]);
4364 vertex[2].c.lcol=DoubleBGR2RGB(gpuData[6]);
4365 vertex[0].c.col[3]=vertex[1].c.col[3]=vertex[2].c.col[3]=ubGloAlpha;
4366 }
4367 DEFOPAQUEON
4368 PRIMdrawTexGouraudTriColor(&vertex[0], &vertex[1], &vertex[2]);
4369 DEFOPAQUEOFF
4370 }
4371
4372 iDrawnSomething=1;
4373 }
4374
4375 ////////////////////////////////////////////////////////////////////////
4376 // cmd: smooth shaded Poly3
4377 ////////////////////////////////////////////////////////////////////////
4378
primPolyG3(unsigned char * baseAddr)4379 void primPolyG3(unsigned char *baseAddr)
4380 {
4381 unsigned long *gpuData = ((unsigned long *) baseAddr);
4382 short *sgpuData = ((short *) baseAddr);
4383
4384 lx0 = sgpuData[2];
4385 ly0 = sgpuData[3];
4386 lx1 = sgpuData[6];
4387 ly1 = sgpuData[7];
4388 lx2 = sgpuData[10];
4389 ly2 = sgpuData[11];
4390
4391 if(offset3()) return;
4392
4393 bDrawTextured = FALSE;
4394 bDrawSmoothShaded = TRUE;
4395 SetRenderState(gpuData[0]);
4396
4397 /* if(iOffscreenDrawing)
4398 {
4399 offsetPSX3();
4400 if(bDrawOffscreen3())
4401 {
4402 InvalidateTextureAreaEx();
4403 drawPoly3G(gpuData[0], gpuData[2], gpuData[4]);
4404 }
4405 }
4406 */
4407 SetRenderMode(gpuData[0], FALSE);
4408 SetZMask3NT();
4409
4410 vertex[0].c.lcol=gpuData[0];
4411 vertex[1].c.lcol=gpuData[2];
4412 vertex[2].c.lcol=gpuData[4];
4413 vertex[0].c.col[3]=vertex[1].c.col[3]=vertex[2].c.col[3]=ubGloColAlpha;
4414
4415 PRIMdrawGouraudTriColor(&vertex[0], &vertex[1], &vertex[2]);
4416
4417 iDrawnSomething=1;
4418 }
4419
4420 ////////////////////////////////////////////////////////////////////////
4421 // cmd: smooth shaded Texture4
4422 ////////////////////////////////////////////////////////////////////////
4423
primPolyGT4(unsigned char * baseAddr)4424 void primPolyGT4(unsigned char *baseAddr)
4425 {
4426 unsigned long *gpuData = ((unsigned long *) baseAddr);
4427 short *sgpuData = ((short *) baseAddr);
4428
4429 lx0 = sgpuData[2];
4430 ly0 = sgpuData[3];
4431 lx1 = sgpuData[8];
4432 ly1 = sgpuData[9];
4433 lx2 = sgpuData[14];
4434 ly2 = sgpuData[15];
4435 lx3 = sgpuData[20];
4436 ly3 = sgpuData[21];
4437
4438 if(offset4()) return;
4439
4440 // do texture stuff
4441 gl_ux[0]=baseAddr[8];//gpuData[2]&0xff;
4442 gl_vy[0]=baseAddr[9];//(gpuData[2]>>8)&0xff;
4443 gl_ux[1]=baseAddr[20];//gpuData[5]&0xff;
4444 gl_vy[1]=baseAddr[21];//(gpuData[5]>>8)&0xff;
4445 gl_ux[2]=baseAddr[32];//gpuData[8]&0xff;
4446 gl_vy[2]=baseAddr[33];//(gpuData[8]>>8)&0xff;
4447 gl_ux[3]=baseAddr[44];//gpuData[11]&0xff;
4448 gl_vy[3]=baseAddr[45];//(gpuData[11]>>8)&0xff;
4449
4450 UpdateGlobalTP((unsigned short)(gpuData[5]>>16));
4451 ulClutID=(gpuData[2]>>16);
4452
4453 bDrawTextured = TRUE;
4454 bDrawSmoothShaded = TRUE;
4455 SetRenderState(gpuData[0]);
4456
4457 /* if(iOffscreenDrawing)
4458 {
4459 offsetPSX4();
4460 if(bDrawOffscreen4())
4461 {
4462 InvalidateTextureAreaEx();
4463 drawPoly4GT(baseAddr);
4464 }
4465 }
4466 */
4467 SetRenderMode(gpuData[0], FALSE);
4468 SetZMask4();
4469
4470 assignTexture4();
4471
4472 RectTexAlign();
4473
4474 if(bDrawNonShaded)
4475 {
4476 //if(!bUseMultiPass) vertex[0].lcol=DoubleBGR2RGB(gpuData[0]); else vertex[0].lcol=gpuData[0];
4477 /* if(bGLBlend) vertex[0].c.lcol=0x7f7f7f;
4478 else */vertex[0].c.lcol=0xffffff;
4479 vertex[0].c.col[3]=ubGloAlpha;
4480 SETCOL(vertex[0]);
4481
4482 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[3], &vertex[2]);
4483
4484 if(ubOpaqueDraw)
4485 {
4486 SetZMask4O();
4487 ubGloAlpha=ubGloColAlpha=0xff;
4488 DEFOPAQUEON
4489 PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[3], &vertex[2]);
4490 DEFOPAQUEOFF
4491 }
4492 return;
4493 }
4494
4495 // if(!bUseMultiPass && !bGLBlend)
4496 {
4497 vertex[0].c.lcol=DoubleBGR2RGB(gpuData[0]);
4498 vertex[1].c.lcol=DoubleBGR2RGB(gpuData[3]);
4499 vertex[2].c.lcol=DoubleBGR2RGB(gpuData[6]);
4500 vertex[3].c.lcol=DoubleBGR2RGB(gpuData[9]);
4501 }
4502 /*else
4503 {
4504 vertex[0].c.lcol=gpuData[0];
4505 vertex[1].c.lcol=gpuData[3];
4506 vertex[2].c.lcol=gpuData[6];
4507 vertex[3].c.lcol=gpuData[9];
4508 }*/
4509
4510 vertex[0].c.col[3]=vertex[1].c.col[3]=vertex[2].c.col[3]=vertex[3].c.col[3]=ubGloAlpha;
4511
4512 PRIMdrawTexGouraudTriColorQuad(&vertex[0], &vertex[1], &vertex[3],&vertex[2]);
4513
4514 if(bDrawMultiPass)
4515 {
4516 SetSemiTransMulti(1);
4517 PRIMdrawTexGouraudTriColorQuad(&vertex[0], &vertex[1], &vertex[3],&vertex[2]);
4518 }
4519
4520 if(ubOpaqueDraw)
4521 {
4522 SetZMask4O();
4523 if(bUseMultiPass)
4524 {
4525 vertex[0].c.lcol=DoubleBGR2RGB(gpuData[0]);
4526 vertex[1].c.lcol=DoubleBGR2RGB(gpuData[3]);
4527 vertex[2].c.lcol=DoubleBGR2RGB(gpuData[6]);
4528 vertex[3].c.lcol=DoubleBGR2RGB(gpuData[9]);
4529 vertex[0].c.col[3]=vertex[1].c.col[3]=vertex[2].c.col[3]=vertex[3].c.col[3]=ubGloAlpha;
4530 }
4531 ubGloAlpha=ubGloColAlpha=0xff;
4532 DEFOPAQUEON
4533 PRIMdrawTexGouraudTriColorQuad(&vertex[0], &vertex[1], &vertex[3],&vertex[2]);
4534 DEFOPAQUEOFF
4535 }
4536
4537 iDrawnSomething=1;
4538 }
4539
4540 ////////////////////////////////////////////////////////////////////////
4541 // cmd: smooth shaded Poly3
4542 ////////////////////////////////////////////////////////////////////////
4543
primPolyF3(unsigned char * baseAddr)4544 void primPolyF3(unsigned char *baseAddr)
4545 {
4546 unsigned long *gpuData = ((unsigned long *) baseAddr);
4547 short *sgpuData = ((short *) baseAddr);
4548
4549 lx0 = sgpuData[2];
4550 ly0 = sgpuData[3];
4551 lx1 = sgpuData[4];
4552 ly1 = sgpuData[5];
4553 lx2 = sgpuData[6];
4554 ly2 = sgpuData[7];
4555
4556 if(offset3()) return;
4557
4558 bDrawTextured = FALSE;
4559 bDrawSmoothShaded = FALSE;
4560 SetRenderState(gpuData[0]);
4561
4562 /* if(iOffscreenDrawing)
4563 {
4564 offsetPSX3();
4565 if(bDrawOffscreen3())
4566 {
4567 InvalidateTextureAreaEx();
4568 drawPoly3F(gpuData[0]);
4569 }
4570 }
4571 */
4572 SetRenderMode(gpuData[0], FALSE);
4573 SetZMask3NT();
4574
4575 vertex[0].c.lcol=gpuData[0];
4576 vertex[0].c.col[3]=ubGloColAlpha;
4577 SETCOL(vertex[0]);
4578
4579 PRIMdrawTri(&vertex[0], &vertex[1], &vertex[2]);
4580
4581 iDrawnSomething=1;
4582 }
4583
4584 ////////////////////////////////////////////////////////////////////////
4585 // cmd: skipping shaded polylines
4586 ////////////////////////////////////////////////////////////////////////
4587
primLineGSkip(unsigned char * baseAddr)4588 void primLineGSkip(unsigned char *baseAddr)
4589 {
4590 unsigned long *gpuData = ((unsigned long *) baseAddr);
4591 short *sgpuData = ((short *) baseAddr);
4592 int iMax=255;
4593 int i=2;
4594
4595 lx1 = sgpuData[2];
4596 ly1 = sgpuData[3];
4597
4598 while(!(((gpuData[i] & 0xF000F000) == 0x50005000) && i>=4))
4599 {
4600 i++;
4601
4602 ly1 = (short)((gpuData[i]>>16) & 0xffff);
4603 lx1 = (short)(gpuData[i] & 0xffff);
4604
4605 i++;if(i>iMax) break;
4606 }
4607 }
4608
4609 ////////////////////////////////////////////////////////////////////////
4610 // cmd: shaded polylines
4611 ////////////////////////////////////////////////////////////////////////
4612
primLineGEx(unsigned char * baseAddr)4613 void primLineGEx(unsigned char *baseAddr)
4614 {
4615 unsigned long *gpuData = ((unsigned long *) baseAddr);
4616 int iMax=255;
4617 short cx0,cx1,cy0,cy1;int i;BOOL bDraw=TRUE;
4618
4619 bDrawTextured = FALSE;
4620 bDrawSmoothShaded = TRUE;
4621 SetRenderState(gpuData[0]);
4622 SetRenderMode(gpuData[0], FALSE);
4623 SetZMask4NT();
4624
4625 vertex[0].c.lcol=vertex[3].c.lcol=gpuData[0];
4626 vertex[0].c.col[3]=vertex[3].c.col[3]=ubGloColAlpha;
4627 ly1 = (short)((gpuData[1]>>16) & 0xffff);
4628 lx1 = (short)(gpuData[1] & 0xffff);
4629
4630 i=2;
4631
4632 //while((gpuData[i]>>24)!=0x55)
4633 //while((gpuData[i]&0x50000000)!=0x50000000)
4634 // currently best way to check for poly line end:
4635 while(!(((gpuData[i] & 0xF000F000) == 0x50005000) && i>=4))
4636 {
4637 ly0 = ly1;lx0=lx1;
4638 vertex[1].c.lcol=vertex[2].c.lcol=vertex[0].c.lcol;
4639 vertex[0].c.lcol=vertex[3].c.lcol=gpuData[i];
4640 vertex[0].c.col[3]=vertex[3].c.col[3]=ubGloColAlpha;
4641
4642 i++;
4643
4644 ly1 = (short)((gpuData[i]>>16) & 0xffff);
4645 lx1 = (short)(gpuData[i] & 0xffff);
4646
4647 if(offsetline()) bDraw=FALSE; else bDraw=TRUE;
4648
4649 if (bDraw && ((lx0 != lx1) || (ly0 != ly1)))
4650 {
4651 /* if(iOffscreenDrawing)
4652 {
4653 cx0=lx0;cx1=lx1;cy0=ly0;cy1=ly1;
4654 offsetPSXLine();
4655 if(bDrawOffscreen4())
4656 {
4657 InvalidateTextureAreaEx();
4658 drawPoly4G(gpuData[i-3],gpuData[i-1],gpuData[i-3],gpuData[i-1]);
4659 }
4660 lx0=cx0;lx1=cx1;ly0=cy0;ly1=cy1;
4661 }*/
4662
4663 PRIMdrawGouraudLine(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
4664 }
4665 i++;
4666
4667 if(i>iMax) break;
4668 }
4669
4670 iDrawnSomething=1;
4671 }
4672
4673 ////////////////////////////////////////////////////////////////////////
4674 // cmd: shaded polyline2
4675 ////////////////////////////////////////////////////////////////////////
4676
primLineG2(unsigned char * baseAddr)4677 void primLineG2(unsigned char *baseAddr)
4678 {
4679 unsigned long *gpuData = ((unsigned long *) baseAddr);
4680 short *sgpuData = ((short *) baseAddr);
4681
4682 lx0 = sgpuData[2];
4683 ly0 = sgpuData[3];
4684 lx1 = sgpuData[6];
4685 ly1 = sgpuData[7];
4686
4687 vertex[0].c.lcol=vertex[3].c.lcol=gpuData[0];
4688 vertex[1].c.lcol=vertex[2].c.lcol=gpuData[2];
4689 vertex[0].c.col[3]=vertex[1].c.col[3]=vertex[2].c.col[3]=vertex[3].c.col[3]=ubGloColAlpha;
4690
4691 bDrawTextured = FALSE;
4692 bDrawSmoothShaded = TRUE;
4693
4694 if((lx0 == lx1) && (ly0 == ly1)) return;
4695
4696 if(offsetline()) return;
4697
4698 SetRenderState(gpuData[0]);
4699 SetRenderMode(gpuData[0], FALSE);
4700 SetZMask4NT();
4701
4702 /* if(iOffscreenDrawing)
4703 {
4704 offsetPSXLine();
4705 if(bDrawOffscreen4())
4706 {
4707 InvalidateTextureAreaEx();
4708 drawPoly4G(gpuData[0],gpuData[2],gpuData[0],gpuData[2]);
4709 }
4710 }
4711 */
4712 //if(ClipVertexList4())
4713 PRIMdrawGouraudLine(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
4714
4715 iDrawnSomething=1;
4716 }
4717
4718 ////////////////////////////////////////////////////////////////////////
4719 // cmd: skipping flat polylines
4720 ////////////////////////////////////////////////////////////////////////
4721
primLineFSkip(unsigned char * baseAddr)4722 void primLineFSkip(unsigned char *baseAddr)
4723 {
4724 unsigned long *gpuData = ((unsigned long *) baseAddr);
4725 int i=2,iMax=255;
4726
4727 ly1 = (short)((gpuData[1]>>16) & 0xffff);
4728 lx1 = (short)(gpuData[1] & 0xffff);
4729
4730 while(!(((gpuData[i] & 0xF000F000) == 0x50005000) && i>=3))
4731 {
4732 ly1 = (short)((gpuData[i]>>16) & 0xffff);
4733 lx1 = (short)(gpuData[i] & 0xffff);
4734 i++;if(i>iMax) break;
4735 }
4736 }
4737
4738 ////////////////////////////////////////////////////////////////////////
4739 // cmd: drawing flat polylines
4740 ////////////////////////////////////////////////////////////////////////
4741
primLineFEx(unsigned char * baseAddr)4742 void primLineFEx(unsigned char *baseAddr)
4743 {
4744 unsigned long *gpuData = ((unsigned long *) baseAddr);
4745 int iMax;
4746 short cx0,cx1,cy0,cy1;int i;
4747
4748 iMax=255;
4749
4750 bDrawTextured = FALSE;
4751 bDrawSmoothShaded = FALSE;
4752 SetRenderState(gpuData[0]);
4753 SetRenderMode(gpuData[0], FALSE);
4754 SetZMask4NT();
4755
4756 vertex[0].c.lcol=gpuData[0];
4757 vertex[0].c.col[3]=ubGloColAlpha;
4758
4759 ly1 = (short)((gpuData[1]>>16) & 0xffff);
4760 lx1 = (short)(gpuData[1] & 0xffff);
4761
4762 i=2;
4763
4764 // while(!(gpuData[i]&0x40000000))
4765 // while((gpuData[i]>>24)!=0x55)
4766 // while((gpuData[i]&0x50000000)!=0x50000000)
4767 // currently best way to check for poly line end:
4768 while(!(((gpuData[i] & 0xF000F000) == 0x50005000) && i>=3))
4769 {
4770 ly0 = ly1;lx0=lx1;
4771 ly1 = (short)((gpuData[i]>>16) & 0xffff);
4772 lx1 = (short)(gpuData[i] & 0xffff);
4773
4774 if(!offsetline())
4775 {
4776 /* if(iOffscreenDrawing)
4777 {
4778 cx0=lx0;cx1=lx1;cy0=ly0;cy1=ly1;
4779 offsetPSXLine();
4780 if(bDrawOffscreen4())
4781 {
4782 InvalidateTextureAreaEx();
4783 drawPoly4F(gpuData[0]);
4784 }
4785 lx0=cx0;lx1=cx1;ly0=cy0;ly1=cy1;
4786 }*/
4787 PRIMdrawFlatLine(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
4788 }
4789
4790 i++;if(i>iMax) break;
4791 }
4792
4793 iDrawnSomething=1;
4794 }
4795
4796 ////////////////////////////////////////////////////////////////////////
4797 // cmd: drawing flat polyline2
4798 ////////////////////////////////////////////////////////////////////////
4799
primLineF2(unsigned char * baseAddr)4800 void primLineF2(unsigned char *baseAddr)
4801 {
4802 unsigned long *gpuData = ((unsigned long *) baseAddr);
4803 short *sgpuData = ((short *) baseAddr);
4804
4805 lx0 = sgpuData[2];
4806 ly0 = sgpuData[3];
4807 lx1 = sgpuData[4];
4808 ly1 = sgpuData[5];
4809
4810 if(offsetline()) return;
4811
4812 bDrawTextured = FALSE;
4813 bDrawSmoothShaded = FALSE;
4814 SetRenderState(gpuData[0]);
4815 SetRenderMode(gpuData[0], FALSE);
4816 SetZMask4NT();
4817
4818 vertex[0].c.lcol=gpuData[0];
4819 vertex[0].c.col[3]=ubGloColAlpha;
4820
4821 /* if(iOffscreenDrawing)
4822 {
4823 offsetPSXLine();
4824 if(bDrawOffscreen4())
4825 {
4826 InvalidateTextureAreaEx();
4827 drawPoly4F(gpuData[0]);
4828 }
4829 }
4830 */
4831 //if(ClipVertexList4())
4832 PRIMdrawFlatLine(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
4833
4834 iDrawnSomething=1;
4835 }
4836
4837 ////////////////////////////////////////////////////////////////////////
4838 // cmd: well, easiest command... not implemented
4839 ////////////////////////////////////////////////////////////////////////
4840
primNI(unsigned char * bA)4841 void primNI(unsigned char *bA)
4842 {
4843 }
4844
4845 ////////////////////////////////////////////////////////////////////////
4846 // cmd func ptr table
4847 ////////////////////////////////////////////////////////////////////////
4848
4849 void (*primTableJ[256])(unsigned char *) =
4850 {
4851 // 00
4852 primNI,primNI,primBlkFill,primNI,primNI,primNI,primNI,primNI,
4853 // 08
4854 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4855 // 10
4856 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4857 // 18
4858 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4859 // 20
4860 primPolyF3,primPolyF3,primPolyF3,primPolyF3,primPolyFT3,primPolyFT3,primPolyFT3,primPolyFT3,
4861 // 28
4862 primPolyF4,primPolyF4,primPolyF4,primPolyF4,primPolyFT4,primPolyFT4,primPolyFT4,primPolyFT4,
4863 // 30
4864 primPolyG3,primPolyG3,primPolyG3,primPolyG3,primPolyGT3,primPolyGT3,primPolyGT3,primPolyGT3,
4865 // 38
4866 primPolyG4,primPolyG4,primPolyG4,primPolyG4,primPolyGT4,primPolyGT4,primPolyGT4,primPolyGT4,
4867 // 40
4868 primLineF2,primLineF2,primLineF2,primLineF2,primNI,primNI,primNI,primNI,
4869 // 48
4870 primLineFEx,primLineFEx,primLineFEx,primLineFEx,primLineFEx,primLineFEx,primLineFEx,primLineFEx,
4871 // 50
4872 primLineG2,primLineG2,primLineG2,primLineG2,primNI,primNI,primNI,primNI,
4873 // 58
4874 primLineGEx,primLineGEx,primLineGEx,primLineGEx,primLineGEx,primLineGEx,primLineGEx,primLineGEx,
4875 // 60
4876 primTileS,primTileS,primTileS,primTileS,primSprtS,primSprtS,primSprtS,primSprtS,
4877 // 68
4878 primTile1,primTile1,primTile1,primTile1,primNI,primNI,primNI,primNI,
4879 // 70
4880 primTile8,primTile8,primTile8,primTile8,primSprt8,primSprt8,primSprt8,primSprt8,
4881 // 78
4882 primTile16,primTile16,primTile16,primTile16,primSprt16,primSprt16,primSprt16,primSprt16,
4883 // 80
4884 primMoveImage,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4885 // 88
4886 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4887 // 90
4888 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4889 // 98
4890 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4891 // a0
4892 primLoadImage,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4893 // a8
4894 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4895 // b0
4896 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4897 // b8
4898 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4899 // c0
4900 primStoreImage,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4901 // c8
4902 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4903 // d0
4904 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4905 // d8
4906 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4907 // e0
4908 primNI,cmdTexturePage,cmdTextureWindow,cmdDrawAreaStart,cmdDrawAreaEnd,cmdDrawOffset,cmdSTP,primNI,
4909 // e8
4910 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4911 // f0
4912 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4913 // f8
4914 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI
4915 };
4916
4917 ////////////////////////////////////////////////////////////////////////
4918 // cmd func ptr table for skipping
4919 ////////////////////////////////////////////////////////////////////////
4920
4921 void (*primTableSkip[256])(unsigned char *) =
4922 {
4923 // 00
4924 primNI,primNI,primBlkFill,primNI,primNI,primNI,primNI,primNI,
4925 // 08
4926 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4927 // 10
4928 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4929 // 18
4930 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4931 // 20
4932 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4933 // 28
4934 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4935 // 30
4936 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4937 // 38
4938 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4939 // 40
4940 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4941 // 48
4942 primLineFSkip,primLineFSkip,primLineFSkip,primLineFSkip,primLineFSkip,primLineFSkip,primLineFSkip,primLineFSkip,
4943 // 50
4944 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4945 // 58
4946 primLineGSkip,primLineGSkip,primLineGSkip,primLineGSkip,primLineGSkip,primLineGSkip,primLineGSkip,primLineGSkip,
4947 // 60
4948 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4949 // 68
4950 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4951 // 70
4952 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4953 // 78
4954 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4955 // 80
4956 primMoveImage,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4957 // 88
4958 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4959 // 90
4960 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4961 // 98
4962 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4963 // a0
4964 primLoadImage,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4965 // a8
4966 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4967 // b0
4968 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4969 // b8
4970 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4971 // c0
4972 primStoreImage,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4973 // c8
4974 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4975 // d0
4976 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4977 // d8
4978 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4979 // e0
4980 primNI,cmdTexturePage,cmdTextureWindow,cmdDrawAreaStart,cmdDrawAreaEnd,cmdDrawOffset,cmdSTP,primNI,
4981 // e8
4982 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4983 // f0
4984 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI,
4985 // f8
4986 primNI,primNI,primNI,primNI,primNI,primNI,primNI,primNI
4987 };
4988