1 /***************************************************************************
4 begin : Sun Oct 28 2001
5 copyright : (C) 2001 by Pete Bernert
6 email : BlackDove@addcom.de
7 ***************************************************************************/
8 /***************************************************************************
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. See also the license.txt file for *
14 * additional informations. *
16 ***************************************************************************/
18 // switches for painting textured quads as 2 triangles (small glitches, but better shading!)
19 // can be toggled by game fix 0x200 in version 1.17 anyway, so let the defines enabled!
23 // fast solid loops... a bit more additional code, of course
26 // psx blending mode 3 with 25% incoming color (instead 50% without the define)
27 #define HALFBRIGHTMODE3
29 // color decode defines
31 #define XCOL1(x) (x & 0x1f)
32 #define XCOL2(x) (x & 0x3e0)
33 #define XCOL3(x) (x & 0x7c00)
35 #define XCOL1D(x) (x & 0x1f)
36 #define XCOL2D(x) ((x>>5) & 0x1f)
37 #define XCOL3D(x) ((x>>10) & 0x1f)
39 #define X32TCOL1(x) ((x & 0x001f001f)<<7)
40 #define X32TCOL2(x) ((x & 0x03e003e0)<<2)
41 #define X32TCOL3(x) ((x & 0x7c007c00)>>3)
43 #define X32COL1(x) (x & 0x001f001f)
44 #define X32COL2(x) ((x>>5) & 0x001f001f)
45 #define X32COL3(x) ((x>>10) & 0x001f001f)
47 #define X32ACOL1(x) (x & 0x001e001e)
48 #define X32ACOL2(x) ((x>>5) & 0x001e001e)
49 #define X32ACOL3(x) ((x>>10) & 0x001e001e)
51 #define X32BCOL1(x) (x & 0x001c001c)
52 #define X32BCOL2(x) ((x>>5) & 0x001c001c)
53 #define X32BCOL3(x) ((x>>10) & 0x001c001c)
55 #define X32PSXCOL(r,g,b) ((g<<10)|(b<<5)|r)
57 #define XPSXCOL(r,g,b) ((g&0x7c00)|(b&0x3e0)|(r&0x1f))
60 short g_m1=255,g_m2=255,g_m3=255;
61 short DrawSemiTrans=FALSE;
64 short ly0,lx0,ly1,lx1,ly2,lx2,ly3,lx3; // global psx vertex coords
65 int32_t GlobalTextAddrX,GlobalTextAddrY,GlobalTextTP,GlobalTextIL;
66 int32_t GlobalTextREST,GlobalTextABR,GlobalTextPAGE;
68 ////////////////////////////////////////////////////////////////////////
69 // POLYGON OFFSET FUNCS
70 ////////////////////////////////////////////////////////////////////////
72 static void offsetPSX2(void)
74 lx0 += PSXDisplay.DrawOffset.x;
75 ly0 += PSXDisplay.DrawOffset.y;
76 lx1 += PSXDisplay.DrawOffset.x;
77 ly1 += PSXDisplay.DrawOffset.y;
80 static void offsetPSX3(void)
82 lx0 += PSXDisplay.DrawOffset.x;
83 ly0 += PSXDisplay.DrawOffset.y;
84 lx1 += PSXDisplay.DrawOffset.x;
85 ly1 += PSXDisplay.DrawOffset.y;
86 lx2 += PSXDisplay.DrawOffset.x;
87 ly2 += PSXDisplay.DrawOffset.y;
90 static void offsetPSX4(void)
92 lx0 += PSXDisplay.DrawOffset.x;
93 ly0 += PSXDisplay.DrawOffset.y;
94 lx1 += PSXDisplay.DrawOffset.x;
95 ly1 += PSXDisplay.DrawOffset.y;
96 lx2 += PSXDisplay.DrawOffset.x;
97 ly2 += PSXDisplay.DrawOffset.y;
98 lx3 += PSXDisplay.DrawOffset.x;
99 ly3 += PSXDisplay.DrawOffset.y;
102 /////////////////////////////////////////////////////////////////
103 /////////////////////////////////////////////////////////////////
104 /////////////////////////////////////////////////////////////////
106 ////////////////////////////////////////////////////////////////////////
107 /////////////////////////////////////////////////////////////////
108 /////////////////////////////////////////////////////////////////
111 unsigned char dithertable[16] =
119 static inline void Dither16(unsigned short * pdest,uint32_t r,uint32_t g,uint32_t b,unsigned short sM)
122 unsigned char rlow, glow, blow;
129 coeff = dithertable[(y&3)*4+(x&3)];
131 rlow = r&7; glow = g&7; blow = b&7;
135 if ((r < 0x1F) && rlow > coeff) r++;
136 if ((g < 0x1F) && glow > coeff) g++;
137 if ((b < 0x1F) && blow > coeff) b++;
139 PUTLE16(pdest, ((unsigned short)b<<10) |
140 ((unsigned short)g<<5) |
141 (unsigned short)r | sM);
144 /////////////////////////////////////////////////////////////////
145 /////////////////////////////////////////////////////////////////
146 /////////////////////////////////////////////////////////////////
148 static inline void GetShadeTransCol_Dither(unsigned short * pdest, int32_t m1, int32_t m2, int32_t m3)
152 if(bCheckMask && (*pdest & HOST2LE16(0x8000))) return;
156 r=((XCOL1D(GETLE16(pdest)))<<3);
157 b=((XCOL2D(GETLE16(pdest)))<<3);
158 g=((XCOL3D(GETLE16(pdest)))<<3);
179 if(r&0x80000000) r=0;
180 if(b&0x80000000) b=0;
181 if(g&0x80000000) g=0;
185 #ifdef HALFBRIGHTMODE3
203 if(r&0x7FFFFF00) r=0xff;
204 if(b&0x7FFFFF00) b=0xff;
205 if(g&0x7FFFFF00) g=0xff;
207 Dither16(pdest,r,b,g,sSetMask);
210 ////////////////////////////////////////////////////////////////////////
212 static inline void GetShadeTransCol(unsigned short * pdest,unsigned short color)
214 if(bCheckMask && (*pdest & HOST2LE16(0x8000))) return;
222 PUTLE16(pdest, (((GETLE16(pdest)&0x7bde)>>1)+(((color)&0x7bde)>>1))|sSetMask);//0x8000;
228 r=(XCOL1(GETLE16(pdest)))+((XCOL1(color)));
229 b=(XCOL2(GETLE16(pdest)))+((XCOL2(color)));
230 g=(XCOL3(GETLE16(pdest)))+((XCOL3(color)));
235 r=(XCOL1(GETLE16(pdest)))-((XCOL1(color)));
236 b=(XCOL2(GETLE16(pdest)))-((XCOL2(color)));
237 g=(XCOL3(GETLE16(pdest)))-((XCOL3(color)));
238 if(r&0x80000000) r=0;
239 if(b&0x80000000) b=0;
240 if(g&0x80000000) g=0;
244 #ifdef HALFBRIGHTMODE3
245 r=(XCOL1(GETLE16(pdest)))+((XCOL1(color))>>2);
246 b=(XCOL2(GETLE16(pdest)))+((XCOL2(color))>>2);
247 g=(XCOL3(GETLE16(pdest)))+((XCOL3(color))>>2);
249 r=(XCOL1(GETLE16(pdest)))+((XCOL1(color))>>1);
250 b=(XCOL2(GETLE16(pdest)))+((XCOL2(color))>>1);
251 g=(XCOL3(GETLE16(pdest)))+((XCOL3(color))>>1);
255 if(r&0x7FFFFFE0) r=0x1f;
256 if(b&0x7FFFFC00) b=0x3e0;
257 if(g&0x7FFF8000) g=0x7c00;
259 PUTLE16(pdest, (XPSXCOL(r,g,b))|sSetMask);//0x8000;
261 else PUTLE16(pdest, color|sSetMask);
264 ////////////////////////////////////////////////////////////////////////
266 static inline void GetShadeTransCol32(uint32_t * pdest,uint32_t color)
276 PUTLE32(pdest, (((GETLE32(pdest)&0x7bde7bde)>>1)+(((color)&0x7bde7bde)>>1))|lSetMask);//0x80008000;
279 r=(X32ACOL1(GETLE32(pdest))>>1)+((X32ACOL1(color))>>1);
280 b=(X32ACOL2(GETLE32(pdest))>>1)+((X32ACOL2(color))>>1);
281 g=(X32ACOL3(GETLE32(pdest))>>1)+((X32ACOL3(color))>>1);
286 r=(X32COL1(GETLE32(pdest)))+((X32COL1(color)));
287 b=(X32COL2(GETLE32(pdest)))+((X32COL2(color)));
288 g=(X32COL3(GETLE32(pdest)))+((X32COL3(color)));
293 int32_t sr,sb,sg,src,sbc,sgc,c;
294 src=XCOL1(color);sbc=XCOL2(color);sgc=XCOL3(color);
295 c=GETLE32(pdest)>>16;
296 sr=(XCOL1(c))-src; if(sr&0x8000) sr=0;
297 sb=(XCOL2(c))-sbc; if(sb&0x8000) sb=0;
298 sg=(XCOL3(c))-sgc; if(sg&0x8000) sg=0;
299 r=((int32_t)sr)<<16;b=((int32_t)sb)<<11;g=((int32_t)sg)<<6;
300 c=LOWORD(GETLE32(pdest));
301 sr=(XCOL1(c))-src; if(sr&0x8000) sr=0;
302 sb=(XCOL2(c))-sbc; if(sb&0x8000) sb=0;
303 sg=(XCOL3(c))-sgc; if(sg&0x8000) sg=0;
304 r|=sr;b|=sb>>5;g|=sg>>10;
308 #ifdef HALFBRIGHTMODE3
309 r=(X32COL1(GETLE32(pdest)))+((X32BCOL1(color))>>2);
310 b=(X32COL2(GETLE32(pdest)))+((X32BCOL2(color))>>2);
311 g=(X32COL3(GETLE32(pdest)))+((X32BCOL3(color))>>2);
313 r=(X32COL1(GETLE32(pdest)))+((X32ACOL1(color))>>1);
314 b=(X32COL2(GETLE32(pdest)))+((X32ACOL2(color))>>1);
315 g=(X32COL3(GETLE32(pdest)))+((X32ACOL3(color))>>1);
319 if(r&0x7FE00000) r=0x1f0000|(r&0xFFFF);
320 if(r&0x7FE0) r=0x1f |(r&0xFFFF0000);
321 if(b&0x7FE00000) b=0x1f0000|(b&0xFFFF);
322 if(b&0x7FE0) b=0x1f |(b&0xFFFF0000);
323 if(g&0x7FE00000) g=0x1f0000|(g&0xFFFF);
324 if(g&0x7FE0) g=0x1f |(g&0xFFFF0000);
328 uint32_t ma=GETLE32(pdest);
329 PUTLE32(pdest, (X32PSXCOL(r,g,b))|lSetMask);//0x80008000;
330 if(ma&0x80000000) PUTLE32(pdest, (ma&0xFFFF0000)|(*pdest&0xFFFF));
331 if(ma&0x00008000) PUTLE32(pdest, (ma&0xFFFF) |(*pdest&0xFFFF0000));
334 PUTLE32(pdest, (X32PSXCOL(r,g,b))|lSetMask);//0x80008000;
340 uint32_t ma=GETLE32(pdest);
341 PUTLE32(pdest, color|lSetMask);//0x80008000;
342 if(ma&0x80000000) PUTLE32(pdest, (ma&0xFFFF0000)|(GETLE32(pdest)&0xFFFF));
343 if(ma&0x00008000) PUTLE32(pdest, (ma&0xFFFF) |(GETLE32(pdest)&0xFFFF0000));
347 PUTLE32(pdest, color|lSetMask);//0x80008000;
351 ////////////////////////////////////////////////////////////////////////
353 static inline void GetTextureTransColG(unsigned short * pdest,unsigned short color)
355 int32_t r,g,b;unsigned short l;
359 if(bCheckMask && (*pdest & HOST2LE16(0x8000))) return;
361 l=sSetMask|(color&0x8000);
363 if(DrawSemiTrans && (color&0x8000))
368 d =(GETLE16(pdest)&0x7bde)>>1;
369 color =((color) &0x7bde)>>1;
370 r=(XCOL1(d))+((((XCOL1(color)))* g_m1)>>7);
371 b=(XCOL2(d))+((((XCOL2(color)))* g_m2)>>7);
372 g=(XCOL3(d))+((((XCOL3(color)))* g_m3)>>7);
377 r=(XCOL1(GETLE16(pdest)))+((((XCOL1(color)))* g_m1)>>7);
378 b=(XCOL2(GETLE16(pdest)))+((((XCOL2(color)))* g_m2)>>7);
379 g=(XCOL3(GETLE16(pdest)))+((((XCOL3(color)))* g_m3)>>7);
384 r=(XCOL1(GETLE16(pdest)))-((((XCOL1(color)))* g_m1)>>7);
385 b=(XCOL2(GETLE16(pdest)))-((((XCOL2(color)))* g_m2)>>7);
386 g=(XCOL3(GETLE16(pdest)))-((((XCOL3(color)))* g_m3)>>7);
387 if(r&0x80000000) r=0;
388 if(b&0x80000000) b=0;
389 if(g&0x80000000) g=0;
393 #ifdef HALFBRIGHTMODE3
394 r=(XCOL1(GETLE16(pdest)))+((((XCOL1(color))>>2)* g_m1)>>7);
395 b=(XCOL2(GETLE16(pdest)))+((((XCOL2(color))>>2)* g_m2)>>7);
396 g=(XCOL3(GETLE16(pdest)))+((((XCOL3(color))>>2)* g_m3)>>7);
398 r=(XCOL1(GETLE16(pdest)))+((((XCOL1(color))>>1)* g_m1)>>7);
399 b=(XCOL2(GETLE16(pdest)))+((((XCOL2(color))>>1)* g_m2)>>7);
400 g=(XCOL3(GETLE16(pdest)))+((((XCOL3(color))>>1)* g_m3)>>7);
406 r=((XCOL1(color))* g_m1)>>7;
407 b=((XCOL2(color))* g_m2)>>7;
408 g=((XCOL3(color))* g_m3)>>7;
411 if(r&0x7FFFFFE0) r=0x1f;
412 if(b&0x7FFFFC00) b=0x3e0;
413 if(g&0x7FFF8000) g=0x7c00;
415 PUTLE16(pdest, (XPSXCOL(r,g,b))|l);
418 ////////////////////////////////////////////////////////////////////////
420 static inline void GetTextureTransColG_S(unsigned short * pdest,unsigned short color)
422 int32_t r,g,b;unsigned short l;
426 l=sSetMask|(color&0x8000);
428 r=((XCOL1(color))* g_m1)>>7;
429 b=((XCOL2(color))* g_m2)>>7;
430 g=((XCOL3(color))* g_m3)>>7;
432 if(r&0x7FFFFFE0) r=0x1f;
433 if(b&0x7FFFFC00) b=0x3e0;
434 if(g&0x7FFF8000) g=0x7c00;
436 PUTLE16(pdest, (XPSXCOL(r,g,b))|l);
439 ////////////////////////////////////////////////////////////////////////
441 static inline void GetTextureTransColG_SPR(unsigned short * pdest,unsigned short color)
443 int32_t r,g,b;unsigned short l;
447 if(bCheckMask && (GETLE16(pdest) & 0x8000)) return;
449 l=sSetMask|(color&0x8000);
451 if(DrawSemiTrans && (color&0x8000))
456 d =(GETLE16(pdest)&0x7bde)>>1;
457 color =((color) &0x7bde)>>1;
458 r=(XCOL1(d))+((((XCOL1(color)))* g_m1)>>7);
459 b=(XCOL2(d))+((((XCOL2(color)))* g_m2)>>7);
460 g=(XCOL3(d))+((((XCOL3(color)))* g_m3)>>7);
465 r=(XCOL1(GETLE16(pdest)))+((((XCOL1(color)))* g_m1)>>7);
466 b=(XCOL2(GETLE16(pdest)))+((((XCOL2(color)))* g_m2)>>7);
467 g=(XCOL3(GETLE16(pdest)))+((((XCOL3(color)))* g_m3)>>7);
472 r=(XCOL1(GETLE16(pdest)))-((((XCOL1(color)))* g_m1)>>7);
473 b=(XCOL2(GETLE16(pdest)))-((((XCOL2(color)))* g_m2)>>7);
474 g=(XCOL3(GETLE16(pdest)))-((((XCOL3(color)))* g_m3)>>7);
475 if(r&0x80000000) r=0;
476 if(b&0x80000000) b=0;
477 if(g&0x80000000) g=0;
481 #ifdef HALFBRIGHTMODE3
482 r=(XCOL1(GETLE16(pdest)))+((((XCOL1(color))>>2)* g_m1)>>7);
483 b=(XCOL2(GETLE16(pdest)))+((((XCOL2(color))>>2)* g_m2)>>7);
484 g=(XCOL3(GETLE16(pdest)))+((((XCOL3(color))>>2)* g_m3)>>7);
486 r=(XCOL1(GETLE16(pdest)))+((((XCOL1(color))>>1)* g_m1)>>7);
487 b=(XCOL2(GETLE16(pdest)))+((((XCOL2(color))>>1)* g_m2)>>7);
488 g=(XCOL3(GETLE16(pdest)))+((((XCOL3(color))>>1)* g_m3)>>7);
494 r=((XCOL1(color))* g_m1)>>7;
495 b=((XCOL2(color))* g_m2)>>7;
496 g=((XCOL3(color))* g_m3)>>7;
499 if(r&0x7FFFFFE0) r=0x1f;
500 if(b&0x7FFFFC00) b=0x3e0;
501 if(g&0x7FFF8000) g=0x7c00;
503 PUTLE16(pdest, (XPSXCOL(r,g,b))|l);
506 ////////////////////////////////////////////////////////////////////////
508 static inline void GetTextureTransColG32(uint32_t * pdest,uint32_t color)
514 l=lSetMask|(color&0x80008000);
516 if(DrawSemiTrans && (color&0x80008000))
520 r=((((X32TCOL1(GETLE32(pdest)))+((X32COL1(color)) * g_m1))&0xFF00FF00)>>8);
521 b=((((X32TCOL2(GETLE32(pdest)))+((X32COL2(color)) * g_m2))&0xFF00FF00)>>8);
522 g=((((X32TCOL3(GETLE32(pdest)))+((X32COL3(color)) * g_m3))&0xFF00FF00)>>8);
527 r=(X32COL1(GETLE32(pdest)))+(((((X32COL1(color)))* g_m1)&0xFF80FF80)>>7);
528 b=(X32COL2(GETLE32(pdest)))+(((((X32COL2(color)))* g_m2)&0xFF80FF80)>>7);
529 g=(X32COL3(GETLE32(pdest)))+(((((X32COL3(color)))* g_m3)&0xFF80FF80)>>7);
535 r=(((((X32COL1(color)))* g_m1)&0xFF80FF80)>>7);
536 t=(GETLE32(pdest)&0x001f0000)-(r&0x003f0000); if(t&0x80000000) t=0;
537 r=(GETLE32(pdest)&0x0000001f)-(r&0x0000003f); if(r&0x80000000) r=0;
540 b=(((((X32COL2(color)))* g_m2)&0xFF80FF80)>>7);
541 t=((GETLE32(pdest)>>5)&0x001f0000)-(b&0x003f0000); if(t&0x80000000) t=0;
542 b=((GETLE32(pdest)>>5)&0x0000001f)-(b&0x0000003f); if(b&0x80000000) b=0;
545 g=(((((X32COL3(color)))* g_m3)&0xFF80FF80)>>7);
546 t=((GETLE32(pdest)>>10)&0x001f0000)-(g&0x003f0000); if(t&0x80000000) t=0;
547 g=((GETLE32(pdest)>>10)&0x0000001f)-(g&0x0000003f); if(g&0x80000000) g=0;
552 #ifdef HALFBRIGHTMODE3
553 r=(X32COL1(GETLE32(pdest)))+(((((X32BCOL1(color))>>2)* g_m1)&0xFF80FF80)>>7);
554 b=(X32COL2(GETLE32(pdest)))+(((((X32BCOL2(color))>>2)* g_m2)&0xFF80FF80)>>7);
555 g=(X32COL3(GETLE32(pdest)))+(((((X32BCOL3(color))>>2)* g_m3)&0xFF80FF80)>>7);
557 r=(X32COL1(GETLE32(pdest)))+(((((X32ACOL1(color))>>1)* g_m1)&0xFF80FF80)>>7);
558 b=(X32COL2(GETLE32(pdest)))+(((((X32ACOL2(color))>>1)* g_m2)&0xFF80FF80)>>7);
559 g=(X32COL3(GETLE32(pdest)))+(((((X32ACOL3(color))>>1)* g_m3)&0xFF80FF80)>>7);
565 r=(r&0xffff0000)|((((X32COL1(color))* g_m1)&0x0000FF80)>>7);
566 b=(b&0xffff0000)|((((X32COL2(color))* g_m2)&0x0000FF80)>>7);
567 g=(g&0xffff0000)|((((X32COL3(color))* g_m3)&0x0000FF80)>>7);
569 if(!(color&0x80000000))
571 r=(r&0xffff)|((((X32COL1(color))* g_m1)&0xFF800000)>>7);
572 b=(b&0xffff)|((((X32COL2(color))* g_m2)&0xFF800000)>>7);
573 g=(g&0xffff)|((((X32COL3(color))* g_m3)&0xFF800000)>>7);
579 r=(((X32COL1(color))* g_m1)&0xFF80FF80)>>7;
580 b=(((X32COL2(color))* g_m2)&0xFF80FF80)>>7;
581 g=(((X32COL3(color))* g_m3)&0xFF80FF80)>>7;
584 if(r&0x7FE00000) r=0x1f0000|(r&0xFFFF);
585 if(r&0x7FE0) r=0x1f |(r&0xFFFF0000);
586 if(b&0x7FE00000) b=0x1f0000|(b&0xFFFF);
587 if(b&0x7FE0) b=0x1f |(b&0xFFFF0000);
588 if(g&0x7FE00000) g=0x1f0000|(g&0xFFFF);
589 if(g&0x7FE0) g=0x1f |(g&0xFFFF0000);
593 uint32_t ma=GETLE32(pdest);
595 PUTLE32(pdest, (X32PSXCOL(r,g,b))|l);
597 if((color&0xffff)==0 ) PUTLE32(pdest, (ma&0xffff)|(GETLE32(pdest)&0xffff0000));
598 if((color&0xffff0000)==0) PUTLE32(pdest, (ma&0xffff0000)|(GETLE32(pdest)&0xffff));
599 if(ma&0x80000000) PUTLE32(pdest, (ma&0xFFFF0000)|(GETLE32(pdest)&0xFFFF));
600 if(ma&0x00008000) PUTLE32(pdest, (ma&0xFFFF) |(GETLE32(pdest)&0xFFFF0000));
604 if((color&0xffff)==0 ) {PUTLE32(pdest, (GETLE32(pdest)&0xffff)|(((X32PSXCOL(r,g,b))|l)&0xffff0000));return;}
605 if((color&0xffff0000)==0) {PUTLE32(pdest, (GETLE32(pdest)&0xffff0000)|(((X32PSXCOL(r,g,b))|l)&0xffff));return;}
607 PUTLE32(pdest, (X32PSXCOL(r,g,b))|l);
610 ////////////////////////////////////////////////////////////////////////
612 static inline void GetTextureTransColG32_S(uint32_t * pdest,uint32_t color)
618 r=(((X32COL1(color))* g_m1)&0xFF80FF80)>>7;
619 b=(((X32COL2(color))* g_m2)&0xFF80FF80)>>7;
620 g=(((X32COL3(color))* g_m3)&0xFF80FF80)>>7;
622 if(r&0x7FE00000) r=0x1f0000|(r&0xFFFF);
623 if(r&0x7FE0) r=0x1f |(r&0xFFFF0000);
624 if(b&0x7FE00000) b=0x1f0000|(b&0xFFFF);
625 if(b&0x7FE0) b=0x1f |(b&0xFFFF0000);
626 if(g&0x7FE00000) g=0x1f0000|(g&0xFFFF);
627 if(g&0x7FE0) g=0x1f |(g&0xFFFF0000);
629 if((color&0xffff)==0) {PUTLE32(pdest, (GETLE32(pdest)&0xffff)|(((X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000))&0xffff0000));return;}
630 if((color&0xffff0000)==0) {PUTLE32(pdest, (GETLE32(pdest)&0xffff0000)|(((X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000))&0xffff));return;}
632 PUTLE32(pdest, (X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000));
635 ////////////////////////////////////////////////////////////////////////
637 static inline void GetTextureTransColG32_SPR(uint32_t * pdest,uint32_t color)
643 if(DrawSemiTrans && (color&0x80008000))
647 r=((((X32TCOL1(GETLE32(pdest)))+((X32COL1(color)) * g_m1))&0xFF00FF00)>>8);
648 b=((((X32TCOL2(GETLE32(pdest)))+((X32COL2(color)) * g_m2))&0xFF00FF00)>>8);
649 g=((((X32TCOL3(GETLE32(pdest)))+((X32COL3(color)) * g_m3))&0xFF00FF00)>>8);
654 r=(X32COL1(GETLE32(pdest)))+(((((X32COL1(color)))* g_m1)&0xFF80FF80)>>7);
655 b=(X32COL2(GETLE32(pdest)))+(((((X32COL2(color)))* g_m2)&0xFF80FF80)>>7);
656 g=(X32COL3(GETLE32(pdest)))+(((((X32COL3(color)))* g_m3)&0xFF80FF80)>>7);
662 r=(((((X32COL1(color)))* g_m1)&0xFF80FF80)>>7);
663 t=(GETLE32(pdest)&0x001f0000)-(r&0x003f0000); if(t&0x80000000) t=0;
664 r=(GETLE32(pdest)&0x0000001f)-(r&0x0000003f); if(r&0x80000000) r=0;
667 b=(((((X32COL2(color)))* g_m2)&0xFF80FF80)>>7);
668 t=((GETLE32(pdest)>>5)&0x001f0000)-(b&0x003f0000); if(t&0x80000000) t=0;
669 b=((GETLE32(pdest)>>5)&0x0000001f)-(b&0x0000003f); if(b&0x80000000) b=0;
672 g=(((((X32COL3(color)))* g_m3)&0xFF80FF80)>>7);
673 t=((GETLE32(pdest)>>10)&0x001f0000)-(g&0x003f0000); if(t&0x80000000) t=0;
674 g=((GETLE32(pdest)>>10)&0x0000001f)-(g&0x0000003f); if(g&0x80000000) g=0;
679 #ifdef HALFBRIGHTMODE3
680 r=(X32COL1(GETLE32(pdest)))+(((((X32BCOL1(color))>>2)* g_m1)&0xFF80FF80)>>7);
681 b=(X32COL2(GETLE32(pdest)))+(((((X32BCOL2(color))>>2)* g_m2)&0xFF80FF80)>>7);
682 g=(X32COL3(GETLE32(pdest)))+(((((X32BCOL3(color))>>2)* g_m3)&0xFF80FF80)>>7);
684 r=(X32COL1(GETLE32(pdest)))+(((((X32ACOL1(color))>>1)* g_m1)&0xFF80FF80)>>7);
685 b=(X32COL2(GETLE32(pdest)))+(((((X32ACOL2(color))>>1)* g_m2)&0xFF80FF80)>>7);
686 g=(X32COL3(GETLE32(pdest)))+(((((X32ACOL3(color))>>1)* g_m3)&0xFF80FF80)>>7);
692 r=(r&0xffff0000)|((((X32COL1(color))* g_m1)&0x0000FF80)>>7);
693 b=(b&0xffff0000)|((((X32COL2(color))* g_m2)&0x0000FF80)>>7);
694 g=(g&0xffff0000)|((((X32COL3(color))* g_m3)&0x0000FF80)>>7);
696 if(!(color&0x80000000))
698 r=(r&0xffff)|((((X32COL1(color))* g_m1)&0xFF800000)>>7);
699 b=(b&0xffff)|((((X32COL2(color))* g_m2)&0xFF800000)>>7);
700 g=(g&0xffff)|((((X32COL3(color))* g_m3)&0xFF800000)>>7);
706 r=(((X32COL1(color))* g_m1)&0xFF80FF80)>>7;
707 b=(((X32COL2(color))* g_m2)&0xFF80FF80)>>7;
708 g=(((X32COL3(color))* g_m3)&0xFF80FF80)>>7;
711 if(r&0x7FE00000) r=0x1f0000|(r&0xFFFF);
712 if(r&0x7FE0) r=0x1f |(r&0xFFFF0000);
713 if(b&0x7FE00000) b=0x1f0000|(b&0xFFFF);
714 if(b&0x7FE0) b=0x1f |(b&0xFFFF0000);
715 if(g&0x7FE00000) g=0x1f0000|(g&0xFFFF);
716 if(g&0x7FE0) g=0x1f |(g&0xFFFF0000);
720 uint32_t ma=GETLE32(pdest);
722 PUTLE32(pdest, (X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000));
724 if((color&0xffff)==0 ) PUTLE32(pdest, (ma&0xffff)|(GETLE32(pdest)&0xffff0000));
725 if((color&0xffff0000)==0) PUTLE32(pdest, (ma&0xffff0000)|(GETLE32(pdest)&0xffff));
726 if(ma&0x80000000) PUTLE32(pdest, (ma&0xFFFF0000)|(GETLE32(pdest)&0xFFFF));
727 if(ma&0x00008000) PUTLE32(pdest, (ma&0xFFFF) |(GETLE32(pdest)&0xFFFF0000));
731 if((color&0xffff)==0 ) {PUTLE32(pdest, (GETLE32(pdest)&0xffff)|(((X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000))&0xffff0000));return;}
732 if((color&0xffff0000)==0) {PUTLE32(pdest, (GETLE32(pdest)&0xffff0000)|(((X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000))&0xffff));return;}
734 PUTLE32(pdest, (X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000));
737 ////////////////////////////////////////////////////////////////////////
739 static inline void GetTextureTransColGX_Dither(unsigned short * pdest,unsigned short color,int32_t m1,int32_t m2,int32_t m3)
745 if(bCheckMask && (*pdest & HOST2LE16(0x8000))) return;
747 m1=(((XCOL1D(color)))*m1)>>4;
748 m2=(((XCOL2D(color)))*m2)>>4;
749 m3=(((XCOL3D(color)))*m3)>>4;
751 if(DrawSemiTrans && (color&0x8000))
753 r=((XCOL1D(GETLE16(pdest)))<<3);
754 b=((XCOL2D(GETLE16(pdest)))<<3);
755 g=((XCOL3D(GETLE16(pdest)))<<3);
776 if(r&0x80000000) r=0;
777 if(b&0x80000000) b=0;
778 if(g&0x80000000) g=0;
782 #ifdef HALFBRIGHTMODE3
800 if(r&0x7FFFFF00) r=0xff;
801 if(b&0x7FFFFF00) b=0xff;
802 if(g&0x7FFFFF00) g=0xff;
804 Dither16(pdest,r,b,g,sSetMask|(color&0x8000));
808 ////////////////////////////////////////////////////////////////////////
810 static inline void GetTextureTransColGX(unsigned short * pdest,unsigned short color,short m1,short m2,short m3)
812 int32_t r,g,b;unsigned short l;
816 if(bCheckMask && (*pdest & HOST2LE16(0x8000))) return;
818 l=sSetMask|(color&0x8000);
820 if(DrawSemiTrans && (color&0x8000))
825 d =(GETLE16(pdest)&0x7bde)>>1;
826 color =((color) &0x7bde)>>1;
827 r=(XCOL1(d))+((((XCOL1(color)))* m1)>>7);
828 b=(XCOL2(d))+((((XCOL2(color)))* m2)>>7);
829 g=(XCOL3(d))+((((XCOL3(color)))* m3)>>7);
834 r=(XCOL1(GETLE16(pdest)))+((((XCOL1(color)))* m1)>>7);
835 b=(XCOL2(GETLE16(pdest)))+((((XCOL2(color)))* m2)>>7);
836 g=(XCOL3(GETLE16(pdest)))+((((XCOL3(color)))* m3)>>7);
841 r=(XCOL1(GETLE16(pdest)))-((((XCOL1(color)))* m1)>>7);
842 b=(XCOL2(GETLE16(pdest)))-((((XCOL2(color)))* m2)>>7);
843 g=(XCOL3(GETLE16(pdest)))-((((XCOL3(color)))* m3)>>7);
844 if(r&0x80000000) r=0;
845 if(b&0x80000000) b=0;
846 if(g&0x80000000) g=0;
850 #ifdef HALFBRIGHTMODE3
851 r=(XCOL1(GETLE16(pdest)))+((((XCOL1(color))>>2)* m1)>>7);
852 b=(XCOL2(GETLE16(pdest)))+((((XCOL2(color))>>2)* m2)>>7);
853 g=(XCOL3(GETLE16(pdest)))+((((XCOL3(color))>>2)* m3)>>7);
855 r=(XCOL1(GETLE16(pdest)))+((((XCOL1(color))>>1)* m1)>>7);
856 b=(XCOL2(GETLE16(pdest)))+((((XCOL2(color))>>1)* m2)>>7);
857 g=(XCOL3(GETLE16(pdest)))+((((XCOL3(color))>>1)* m3)>>7);
863 r=((XCOL1(color))* m1)>>7;
864 b=((XCOL2(color))* m2)>>7;
865 g=((XCOL3(color))* m3)>>7;
868 if(r&0x7FFFFFE0) r=0x1f;
869 if(b&0x7FFFFC00) b=0x3e0;
870 if(g&0x7FFF8000) g=0x7c00;
872 PUTLE16(pdest, (XPSXCOL(r,g,b))|l);
875 ////////////////////////////////////////////////////////////////////////
877 static inline void GetTextureTransColGX_S(unsigned short * pdest,unsigned short color,short m1,short m2,short m3)
883 r=((XCOL1(color))* m1)>>7;
884 b=((XCOL2(color))* m2)>>7;
885 g=((XCOL3(color))* m3)>>7;
887 if(r&0x7FFFFFE0) r=0x1f;
888 if(b&0x7FFFFC00) b=0x3e0;
889 if(g&0x7FFF8000) g=0x7c00;
891 PUTLE16(pdest, (XPSXCOL(r,g,b))|sSetMask|(color&0x8000));
894 ////////////////////////////////////////////////////////////////////////
896 static inline void GetTextureTransColGX32_S(uint32_t * pdest,uint32_t color,short m1,short m2,short m3)
902 r=(((X32COL1(color))* m1)&0xFF80FF80)>>7;
903 b=(((X32COL2(color))* m2)&0xFF80FF80)>>7;
904 g=(((X32COL3(color))* m3)&0xFF80FF80)>>7;
906 if(r&0x7FE00000) r=0x1f0000|(r&0xFFFF);
907 if(r&0x7FE0) r=0x1f |(r&0xFFFF0000);
908 if(b&0x7FE00000) b=0x1f0000|(b&0xFFFF);
909 if(b&0x7FE0) b=0x1f |(b&0xFFFF0000);
910 if(g&0x7FE00000) g=0x1f0000|(g&0xFFFF);
911 if(g&0x7FE0) g=0x1f |(g&0xFFFF0000);
913 if((color&0xffff)==0) {PUTLE32(pdest, (GETLE32(pdest)&0xffff)|(((X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000))&0xffff0000));return;}
914 if((color&0xffff0000)==0) {PUTLE32(pdest, (GETLE32(pdest)&0xffff0000)|(((X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000))&0xffff));return;}
916 PUTLE32(pdest, (X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000));
919 ////////////////////////////////////////////////////////////////////////
921 ////////////////////////////////////////////////////////////////////////
923 static void FillSoftwareAreaTrans(short x0,short y0,short x1, // FILL AREA TRANS
924 short y1,unsigned short col)
949 if(dx==1 && dy==1 && x0==1020 && y0==511) // special fix for pinball game... emu protection???
953 if(iCheat==1) iCheat=0; else iCheat=1;
957 if(dx&1) // slow fill
959 unsigned short *DSTPtr;
960 unsigned short LineOffset;
961 DSTPtr = psxVuw + (1024*y0) + x0;
962 LineOffset = 1024 - dx;
966 GetShadeTransCol(DSTPtr++,col);
967 DSTPtr += LineOffset;
973 unsigned short LineOffset;
974 uint32_t lcol=lSetMask|(((uint32_t)(col))<<16)|col;
976 DSTPtr = (uint32_t *)(psxVuw + (1024*y0) + x0);
977 LineOffset = 512 - dx;
979 if(!bCheckMask && !DrawSemiTrans)
983 for(j=0;j<dx;j++) { PUTLE32(DSTPtr, lcol); DSTPtr++; }
984 DSTPtr += LineOffset;
992 GetShadeTransCol32(DSTPtr++,lcol);
993 DSTPtr += LineOffset;
999 ////////////////////////////////////////////////////////////////////////
1001 static void FillSoftwareArea(short x0,short y0,short x1, // FILL AREA (BLK FILL)
1002 short y1,unsigned short col) // no draw area check here!
1006 // ?? ff9 pal hooligan crack sets nonsense x0
1017 if(x1>1024) x1=1024;
1022 unsigned short *DSTPtr;
1023 unsigned short LineOffset;
1025 DSTPtr = psxVuw + (1024*y0) + x0;
1026 LineOffset = 1024 - dx;
1030 for(j=0;j<dx;j++) { PUTLE16(DSTPtr, col); DSTPtr++; }
1031 DSTPtr += LineOffset;
1037 unsigned short LineOffset;
1038 uint32_t lcol=(((int32_t)col)<<16)|col;
1040 DSTPtr = (uint32_t *)(psxVuw + (1024*y0) + x0);
1041 LineOffset = 512 - dx;
1045 for(j=0;j<dx;j++) { PUTLE32(DSTPtr, lcol); DSTPtr++; }
1046 DSTPtr += LineOffset;
1051 ////////////////////////////////////////////////////////////////////////
1052 ////////////////////////////////////////////////////////////////////////
1053 ////////////////////////////////////////////////////////////////////////
1054 // EDGE INTERPOLATION
1055 ////////////////////////////////////////////////////////////////////////
1056 ////////////////////////////////////////////////////////////////////////
1057 ////////////////////////////////////////////////////////////////////////
1059 typedef struct SOFTVTAG
1066 static soft_vertex vtx[4];
1067 static soft_vertex * left_array[4], * right_array[4];
1068 static int left_section, right_section;
1069 static int left_section_height, right_section_height;
1070 static int left_x, delta_left_x, right_x, delta_right_x;
1071 static int left_u, delta_left_u, left_v, delta_left_v;
1072 static int right_u, delta_right_u, right_v, delta_right_v;
1073 static int left_R, delta_left_R, right_R, delta_right_R;
1074 static int left_G, delta_left_G, right_G, delta_right_G;
1075 static int left_B, delta_left_B, right_B, delta_right_B;
1078 static inline int shl10idiv(int x, int y)
1085 ////////////////////////////////////////////////////////////////////////
1086 ////////////////////////////////////////////////////////////////////////
1087 ////////////////////////////////////////////////////////////////////////
1089 static inline int RightSection_F(void)
1091 soft_vertex * v1 = right_array[ right_section ];
1092 soft_vertex * v2 = right_array[ right_section-1 ];
1094 int height = v2->y - v1->y;
1095 if(height == 0) return 0;
1096 delta_right_x = (v2->x - v1->x) / height;
1099 right_section_height = height;
1103 ////////////////////////////////////////////////////////////////////////
1105 static inline int LeftSection_F(void)
1107 soft_vertex * v1 = left_array[ left_section ];
1108 soft_vertex * v2 = left_array[ left_section-1 ];
1110 int height = v2->y - v1->y;
1111 if(height == 0) return 0;
1112 delta_left_x = (v2->x - v1->x) / height;
1115 left_section_height = height;
1119 ////////////////////////////////////////////////////////////////////////
1121 static inline BOOL NextRow_F(void)
1123 if(--left_section_height<=0)
1125 if(--left_section <= 0) {return TRUE;}
1126 if(LeftSection_F() <= 0) {return TRUE;}
1130 left_x += delta_left_x;
1133 if(--right_section_height<=0)
1135 if(--right_section<=0) {return TRUE;}
1136 if(RightSection_F() <=0) {return TRUE;}
1140 right_x += delta_right_x;
1145 ////////////////////////////////////////////////////////////////////////
1147 static inline BOOL SetupSections_F(short x1, short y1, short x2, short y2, short x3, short y3)
1149 soft_vertex * v1, * v2, * v3;
1152 v1 = vtx; v1->x=x1<<16;v1->y=y1;
1153 v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
1154 v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
1156 if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
1157 if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
1158 if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
1160 height = v3->y - v1->y;
1161 if(height == 0) {return FALSE;}
1162 longest = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
1163 if(longest == 0) {return FALSE;}
1167 right_array[0] = v3;
1168 right_array[1] = v2;
1169 right_array[2] = v1;
1175 if(LeftSection_F() <= 0) return FALSE;
1176 if(RightSection_F() <= 0)
1179 if(RightSection_F() <= 0) return FALSE;
1188 right_array[0] = v3;
1189 right_array[1] = v1;
1192 if(RightSection_F() <= 0) return FALSE;
1193 if(LeftSection_F() <= 0)
1196 if(LeftSection_F() <= 0) return FALSE;
1201 Ymax=min(v3->y-1,drawH);
1206 ////////////////////////////////////////////////////////////////////////
1207 ////////////////////////////////////////////////////////////////////////
1209 static inline int RightSection_G(void)
1211 soft_vertex * v1 = right_array[ right_section ];
1212 soft_vertex * v2 = right_array[ right_section-1 ];
1214 int height = v2->y - v1->y;
1215 if(height == 0) return 0;
1216 delta_right_x = (v2->x - v1->x) / height;
1219 right_section_height = height;
1223 ////////////////////////////////////////////////////////////////////////
1225 static inline int LeftSection_G(void)
1227 soft_vertex * v1 = left_array[ left_section ];
1228 soft_vertex * v2 = left_array[ left_section-1 ];
1230 int height = v2->y - v1->y;
1231 if(height == 0) return 0;
1232 delta_left_x = (v2->x - v1->x) / height;
1235 delta_left_R = ((v2->R - v1->R)) / height;
1237 delta_left_G = ((v2->G - v1->G)) / height;
1239 delta_left_B = ((v2->B - v1->B)) / height;
1242 left_section_height = height;
1246 ////////////////////////////////////////////////////////////////////////
1248 static inline BOOL NextRow_G(void)
1250 if(--left_section_height<=0)
1252 if(--left_section <= 0) {return TRUE;}
1253 if(LeftSection_G() <= 0) {return TRUE;}
1257 left_x += delta_left_x;
1258 left_R += delta_left_R;
1259 left_G += delta_left_G;
1260 left_B += delta_left_B;
1263 if(--right_section_height<=0)
1265 if(--right_section<=0) {return TRUE;}
1266 if(RightSection_G() <=0) {return TRUE;}
1270 right_x += delta_right_x;
1275 ////////////////////////////////////////////////////////////////////////
1277 static inline BOOL SetupSections_G(short x1,short y1,short x2,short y2,short x3,short y3,int32_t rgb1, int32_t rgb2, int32_t rgb3)
1279 soft_vertex * v1, * v2, * v3;
1280 int height,longest,temp;
1282 v1 = vtx; v1->x=x1<<16;v1->y=y1;
1283 v1->R=(rgb1) & 0x00ff0000;
1284 v1->G=(rgb1<<8) & 0x00ff0000;
1285 v1->B=(rgb1<<16) & 0x00ff0000;
1286 v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
1287 v2->R=(rgb2) & 0x00ff0000;
1288 v2->G=(rgb2<<8) & 0x00ff0000;
1289 v2->B=(rgb2<<16) & 0x00ff0000;
1290 v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
1291 v3->R=(rgb3) & 0x00ff0000;
1292 v3->G=(rgb3<<8) & 0x00ff0000;
1293 v3->B=(rgb3<<16) & 0x00ff0000;
1295 if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
1296 if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
1297 if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
1299 height = v3->y - v1->y;
1300 if(height == 0) {return FALSE;}
1301 temp=(((v2->y - v1->y) << 16) / height);
1302 longest = temp * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
1303 if(longest == 0) {return FALSE;}
1307 right_array[0] = v3;
1308 right_array[1] = v2;
1309 right_array[2] = v1;
1315 if(LeftSection_G() <= 0) return FALSE;
1316 if(RightSection_G() <= 0)
1319 if(RightSection_G() <= 0) return FALSE;
1321 if(longest > -0x1000) longest = -0x1000;
1329 right_array[0] = v3;
1330 right_array[1] = v1;
1333 if(RightSection_G() <= 0) return FALSE;
1334 if(LeftSection_G() <= 0)
1337 if(LeftSection_G() <= 0) return FALSE;
1339 if(longest < 0x1000) longest = 0x1000;
1343 Ymax=min(v3->y-1,drawH);
1345 delta_right_R=shl10idiv(temp*((v3->R - v1->R)>>10)+((v1->R - v2->R)<<6),longest);
1346 delta_right_G=shl10idiv(temp*((v3->G - v1->G)>>10)+((v1->G - v2->G)<<6),longest);
1347 delta_right_B=shl10idiv(temp*((v3->B - v1->B)>>10)+((v1->B - v2->B)<<6),longest);
1352 ////////////////////////////////////////////////////////////////////////
1353 ////////////////////////////////////////////////////////////////////////
1355 static inline int RightSection_FT(void)
1357 soft_vertex * v1 = right_array[ right_section ];
1358 soft_vertex * v2 = right_array[ right_section-1 ];
1360 int height = v2->y - v1->y;
1361 if(height == 0) return 0;
1362 delta_right_x = (v2->x - v1->x) / height;
1365 right_section_height = height;
1369 ////////////////////////////////////////////////////////////////////////
1371 static inline int LeftSection_FT(void)
1373 soft_vertex * v1 = left_array[ left_section ];
1374 soft_vertex * v2 = left_array[ left_section-1 ];
1376 int height = v2->y - v1->y;
1377 if(height == 0) return 0;
1378 delta_left_x = (v2->x - v1->x) / height;
1381 delta_left_u = ((v2->u - v1->u)) / height;
1383 delta_left_v = ((v2->v - v1->v)) / height;
1386 left_section_height = height;
1390 ////////////////////////////////////////////////////////////////////////
1392 static inline BOOL NextRow_FT(void)
1394 if(--left_section_height<=0)
1396 if(--left_section <= 0) {return TRUE;}
1397 if(LeftSection_FT() <= 0) {return TRUE;}
1401 left_x += delta_left_x;
1402 left_u += delta_left_u;
1403 left_v += delta_left_v;
1406 if(--right_section_height<=0)
1408 if(--right_section<=0) {return TRUE;}
1409 if(RightSection_FT() <=0) {return TRUE;}
1413 right_x += delta_right_x;
1418 ////////////////////////////////////////////////////////////////////////
1420 static inline BOOL SetupSections_FT(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3)
1422 soft_vertex * v1, * v2, * v3;
1423 int height,longest,temp;
1425 v1 = vtx; v1->x=x1<<16;v1->y=y1;
1426 v1->u=tx1<<16;v1->v=ty1<<16;
1427 v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
1428 v2->u=tx2<<16;v2->v=ty2<<16;
1429 v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
1430 v3->u=tx3<<16;v3->v=ty3<<16;
1432 if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
1433 if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
1434 if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
1436 height = v3->y - v1->y;
1437 if(height == 0) {return FALSE;}
1439 temp=(((v2->y - v1->y) << 16) / height);
1440 longest = temp * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
1442 if(longest == 0) {return FALSE;}
1446 right_array[0] = v3;
1447 right_array[1] = v2;
1448 right_array[2] = v1;
1454 if(LeftSection_FT() <= 0) return FALSE;
1455 if(RightSection_FT() <= 0)
1458 if(RightSection_FT() <= 0) return FALSE;
1460 if(longest > -0x1000) longest = -0x1000;
1468 right_array[0] = v3;
1469 right_array[1] = v1;
1472 if(RightSection_FT() <= 0) return FALSE;
1473 if(LeftSection_FT() <= 0)
1476 if(LeftSection_FT() <= 0) return FALSE;
1478 if(longest < 0x1000) longest = 0x1000;
1482 Ymax=min(v3->y-1,drawH);
1484 delta_right_u=shl10idiv(temp*((v3->u - v1->u)>>10)+((v1->u - v2->u)<<6),longest);
1485 delta_right_v=shl10idiv(temp*((v3->v - v1->v)>>10)+((v1->v - v2->v)<<6),longest);
1490 ////////////////////////////////////////////////////////////////////////
1491 ////////////////////////////////////////////////////////////////////////
1493 static inline int RightSection_GT(void)
1495 soft_vertex * v1 = right_array[ right_section ];
1496 soft_vertex * v2 = right_array[ right_section-1 ];
1498 int height = v2->y - v1->y;
1499 if(height == 0) return 0;
1500 delta_right_x = (v2->x - v1->x) / height;
1503 right_section_height = height;
1507 ////////////////////////////////////////////////////////////////////////
1509 static inline int LeftSection_GT(void)
1511 soft_vertex * v1 = left_array[ left_section ];
1512 soft_vertex * v2 = left_array[ left_section-1 ];
1514 int height = v2->y - v1->y;
1515 if(height == 0) return 0;
1516 delta_left_x = (v2->x - v1->x) / height;
1519 delta_left_u = ((v2->u - v1->u)) / height;
1521 delta_left_v = ((v2->v - v1->v)) / height;
1524 delta_left_R = ((v2->R - v1->R)) / height;
1526 delta_left_G = ((v2->G - v1->G)) / height;
1528 delta_left_B = ((v2->B - v1->B)) / height;
1531 left_section_height = height;
1535 ////////////////////////////////////////////////////////////////////////
1537 static inline BOOL NextRow_GT(void)
1539 if(--left_section_height<=0)
1541 if(--left_section <= 0) {return TRUE;}
1542 if(LeftSection_GT() <= 0) {return TRUE;}
1546 left_x += delta_left_x;
1547 left_u += delta_left_u;
1548 left_v += delta_left_v;
1549 left_R += delta_left_R;
1550 left_G += delta_left_G;
1551 left_B += delta_left_B;
1554 if(--right_section_height<=0)
1556 if(--right_section<=0) {return TRUE;}
1557 if(RightSection_GT() <=0) {return TRUE;}
1561 right_x += delta_right_x;
1566 ////////////////////////////////////////////////////////////////////////
1568 static inline BOOL SetupSections_GT(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, int32_t rgb1, int32_t rgb2, int32_t rgb3)
1570 soft_vertex * v1, * v2, * v3;
1571 int height,longest,temp;
1573 v1 = vtx; v1->x=x1<<16;v1->y=y1;
1574 v1->u=tx1<<16;v1->v=ty1<<16;
1575 v1->R=(rgb1) & 0x00ff0000;
1576 v1->G=(rgb1<<8) & 0x00ff0000;
1577 v1->B=(rgb1<<16) & 0x00ff0000;
1579 v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
1580 v2->u=tx2<<16;v2->v=ty2<<16;
1581 v2->R=(rgb2) & 0x00ff0000;
1582 v2->G=(rgb2<<8) & 0x00ff0000;
1583 v2->B=(rgb2<<16) & 0x00ff0000;
1585 v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
1586 v3->u=tx3<<16;v3->v=ty3<<16;
1587 v3->R=(rgb3) & 0x00ff0000;
1588 v3->G=(rgb3<<8) & 0x00ff0000;
1589 v3->B=(rgb3<<16) & 0x00ff0000;
1591 if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
1592 if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
1593 if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
1595 height = v3->y - v1->y;
1596 if(height == 0) {return FALSE;}
1598 temp=(((v2->y - v1->y) << 16) / height);
1599 longest = temp * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
1601 if(longest == 0) {return FALSE;}
1605 right_array[0] = v3;
1606 right_array[1] = v2;
1607 right_array[2] = v1;
1613 if(LeftSection_GT() <= 0) return FALSE;
1614 if(RightSection_GT() <= 0)
1617 if(RightSection_GT() <= 0) return FALSE;
1620 if(longest > -0x1000) longest = -0x1000;
1628 right_array[0] = v3;
1629 right_array[1] = v1;
1632 if(RightSection_GT() <= 0) return FALSE;
1633 if(LeftSection_GT() <= 0)
1636 if(LeftSection_GT() <= 0) return FALSE;
1638 if(longest < 0x1000) longest = 0x1000;
1642 Ymax=min(v3->y-1,drawH);
1644 delta_right_R=shl10idiv(temp*((v3->R - v1->R)>>10)+((v1->R - v2->R)<<6),longest);
1645 delta_right_G=shl10idiv(temp*((v3->G - v1->G)>>10)+((v1->G - v2->G)<<6),longest);
1646 delta_right_B=shl10idiv(temp*((v3->B - v1->B)>>10)+((v1->B - v2->B)<<6),longest);
1648 delta_right_u=shl10idiv(temp*((v3->u - v1->u)>>10)+((v1->u - v2->u)<<6),longest);
1649 delta_right_v=shl10idiv(temp*((v3->v - v1->v)>>10)+((v1->v - v2->v)<<6),longest);
1654 ////////////////////////////////////////////////////////////////////////
1655 ////////////////////////////////////////////////////////////////////////
1657 static inline int RightSection_F4(void)
1659 soft_vertex * v1 = right_array[ right_section ];
1660 soft_vertex * v2 = right_array[ right_section-1 ];
1662 int height = v2->y - v1->y;
1663 right_section_height = height;
1669 delta_right_x = (v2->x - v1->x) / height;
1674 ////////////////////////////////////////////////////////////////////////
1676 static inline int LeftSection_F4(void)
1678 soft_vertex * v1 = left_array[ left_section ];
1679 soft_vertex * v2 = left_array[ left_section-1 ];
1681 int height = v2->y - v1->y;
1682 left_section_height = height;
1688 delta_left_x = (v2->x - v1->x) / height;
1693 ////////////////////////////////////////////////////////////////////////
1695 static inline BOOL NextRow_F4(void)
1697 if(--left_section_height<=0)
1699 if(--left_section > 0)
1700 while(LeftSection_F4()<=0)
1702 if(--left_section <= 0) break;
1707 left_x += delta_left_x;
1710 if(--right_section_height<=0)
1712 if(--right_section > 0)
1713 while(RightSection_F4()<=0)
1715 if(--right_section<=0) break;
1720 right_x += delta_right_x;
1725 ////////////////////////////////////////////////////////////////////////
1727 static inline BOOL SetupSections_F4(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4)
1729 soft_vertex * v1, * v2, * v3, * v4;
1730 int height,width,longest1,longest2;
1732 v1 = vtx; v1->x=x1<<16;v1->y=y1;
1733 v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
1734 v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
1735 v4 = vtx+3; v4->x=x4<<16;v4->y=y4;
1737 if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
1738 if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
1739 if(v1->y > v4->y) { soft_vertex * v = v1; v1 = v4; v4 = v; }
1740 if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
1741 if(v2->y > v4->y) { soft_vertex * v = v2; v2 = v4; v4 = v; }
1742 if(v3->y > v4->y) { soft_vertex * v = v3; v3 = v4; v4 = v; }
1744 height = v4->y - v1->y; if(height == 0) height =1;
1745 width = (v4->x - v1->x)>>16;
1746 longest1 = (((v2->y - v1->y) << 16) / height) * width + (v1->x - v2->x);
1747 longest2 = (((v3->y - v1->y) << 16) / height) * width + (v1->x - v3->x);
1749 if(longest1 < 0) // 2 is right
1751 if(longest2 < 0) // 3 is right
1757 height = v3->y - v1->y; if(height == 0) height=1;
1758 longest1 = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
1761 right_array[0] = v4; // 1
1762 right_array[1] = v3; // 3
1763 right_array[2] = v1; // 4
1768 height = v4->y - v2->y; if(height == 0) height=1;
1769 longest1 = (((v3->y - v2->y) << 16) / height) * ((v4->x - v2->x)>>16) + (v2->x - v3->x);
1772 right_array[0] = v4; // 1
1773 right_array[1] = v2; // 2
1774 right_array[2] = v1; // 4
1779 right_array[0] = v4; // 1
1780 right_array[1] = v3; // 2
1781 right_array[2] = v2; // 3
1782 right_array[3] = v1; // 4
1790 left_array[1] = v3; // 1
1791 left_array[2] = v1; // 2
1792 left_section = 2; // 3
1793 right_array[0] = v4; // 4
1794 right_array[1] = v2;
1795 right_array[2] = v1;
1803 left_array[0] = v4; // 1
1804 left_array[1] = v2; // 2
1805 left_array[2] = v1; // 3
1806 left_section = 2; // 4
1807 right_array[0] = v4;
1808 right_array[1] = v3;
1809 right_array[2] = v1;
1814 right_array[0] = v4;
1815 right_array[1] = v1;
1818 height = v3->y - v1->y; if(height == 0) height=1;
1819 longest1 = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
1822 left_array[0] = v4; // 1
1823 left_array[1] = v3; // 3
1824 left_array[2] = v1; // 4
1829 height = v4->y - v2->y; if(height == 0) height=1;
1830 longest1 = (((v3->y - v2->y) << 16) / height) * ((v4->x - v2->x)>>16) + (v2->x - v3->x);
1833 left_array[0] = v4; // 1
1834 left_array[1] = v2; // 2
1835 left_array[2] = v1; // 4
1840 left_array[0] = v4; // 1
1841 left_array[1] = v3; // 2
1842 left_array[2] = v2; // 3
1843 left_array[3] = v1; // 4
1850 while(LeftSection_F4()<=0)
1852 if(--left_section <= 0) break;
1855 while(RightSection_F4()<=0)
1857 if(--right_section <= 0) break;
1861 Ymax=min(v4->y-1,drawH);
1866 ////////////////////////////////////////////////////////////////////////
1867 ////////////////////////////////////////////////////////////////////////
1869 static inline int RightSection_FT4(void)
1871 soft_vertex * v1 = right_array[ right_section ];
1872 soft_vertex * v2 = right_array[ right_section-1 ];
1874 int height = v2->y - v1->y;
1875 right_section_height = height;
1883 delta_right_x = (v2->x - v1->x) / height;
1884 delta_right_u = (v2->u - v1->u) / height;
1885 delta_right_v = (v2->v - v1->v) / height;
1890 ////////////////////////////////////////////////////////////////////////
1892 static inline int LeftSection_FT4(void)
1894 soft_vertex * v1 = left_array[ left_section ];
1895 soft_vertex * v2 = left_array[ left_section-1 ];
1897 int height = v2->y - v1->y;
1898 left_section_height = height;
1906 delta_left_x = (v2->x - v1->x) / height;
1907 delta_left_u = (v2->u - v1->u) / height;
1908 delta_left_v = (v2->v - v1->v) / height;
1913 ////////////////////////////////////////////////////////////////////////
1915 static inline BOOL NextRow_FT4(void)
1917 if(--left_section_height<=0)
1919 if(--left_section > 0)
1920 while(LeftSection_FT4()<=0)
1922 if(--left_section <= 0) break;
1927 left_x += delta_left_x;
1928 left_u += delta_left_u;
1929 left_v += delta_left_v;
1932 if(--right_section_height<=0)
1934 if(--right_section > 0)
1935 while(RightSection_FT4()<=0)
1937 if(--right_section<=0) break;
1942 right_x += delta_right_x;
1943 right_u += delta_right_u;
1944 right_v += delta_right_v;
1949 ////////////////////////////////////////////////////////////////////////
1951 static inline BOOL SetupSections_FT4(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4)
1953 soft_vertex * v1, * v2, * v3, * v4;
1954 int height,width,longest1,longest2;
1956 v1 = vtx; v1->x=x1<<16;v1->y=y1;
1957 v1->u=tx1<<16;v1->v=ty1<<16;
1959 v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
1960 v2->u=tx2<<16;v2->v=ty2<<16;
1962 v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
1963 v3->u=tx3<<16;v3->v=ty3<<16;
1965 v4 = vtx+3; v4->x=x4<<16;v4->y=y4;
1966 v4->u=tx4<<16;v4->v=ty4<<16;
1968 if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
1969 if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
1970 if(v1->y > v4->y) { soft_vertex * v = v1; v1 = v4; v4 = v; }
1971 if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
1972 if(v2->y > v4->y) { soft_vertex * v = v2; v2 = v4; v4 = v; }
1973 if(v3->y > v4->y) { soft_vertex * v = v3; v3 = v4; v4 = v; }
1975 height = v4->y - v1->y; if(height == 0) height =1;
1976 width = (v4->x - v1->x)>>16;
1977 longest1 = (((v2->y - v1->y) << 16) / height) * width + (v1->x - v2->x);
1978 longest2 = (((v3->y - v1->y) << 16) / height) * width + (v1->x - v3->x);
1980 if(longest1 < 0) // 2 is right
1982 if(longest2 < 0) // 3 is right
1988 height = v3->y - v1->y; if(height == 0) height=1;
1989 longest1 = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
1992 right_array[0] = v4; // 1
1993 right_array[1] = v3; // 3
1994 right_array[2] = v1; // 4
1999 height = v4->y - v2->y; if(height == 0) height=1;
2000 longest1 = (((v3->y - v2->y) << 16) / height) * ((v4->x - v2->x)>>16) + (v2->x - v3->x);
2003 right_array[0] = v4; // 1
2004 right_array[1] = v2; // 2
2005 right_array[2] = v1; // 4
2010 right_array[0] = v4; // 1
2011 right_array[1] = v3; // 2
2012 right_array[2] = v2; // 3
2013 right_array[3] = v1; // 4
2021 left_array[1] = v3; // 1
2022 left_array[2] = v1; // 2
2023 left_section = 2; // 3
2024 right_array[0] = v4; // 4
2025 right_array[1] = v2;
2026 right_array[2] = v1;
2034 left_array[0] = v4; // 1
2035 left_array[1] = v2; // 2
2036 left_array[2] = v1; // 3
2037 left_section = 2; // 4
2038 right_array[0] = v4;
2039 right_array[1] = v3;
2040 right_array[2] = v1;
2045 right_array[0] = v4;
2046 right_array[1] = v1;
2049 height = v3->y - v1->y; if(height == 0) height=1;
2050 longest1 = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
2053 left_array[0] = v4; // 1
2054 left_array[1] = v3; // 3
2055 left_array[2] = v1; // 4
2060 height = v4->y - v2->y; if(height == 0) height=1;
2061 longest1 = (((v3->y - v2->y) << 16) / height) * ((v4->x - v2->x)>>16) + (v2->x - v3->x);
2064 left_array[0] = v4; // 1
2065 left_array[1] = v2; // 2
2066 left_array[2] = v1; // 4
2071 left_array[0] = v4; // 1
2072 left_array[1] = v3; // 2
2073 left_array[2] = v2; // 3
2074 left_array[3] = v1; // 4
2081 while(LeftSection_FT4()<=0)
2083 if(--left_section <= 0) break;
2086 while(RightSection_FT4()<=0)
2088 if(--right_section <= 0) break;
2092 Ymax=min(v4->y-1,drawH);
2097 ////////////////////////////////////////////////////////////////////////
2098 ////////////////////////////////////////////////////////////////////////
2100 static inline int RightSection_GT4(void)
2102 soft_vertex * v1 = right_array[ right_section ];
2103 soft_vertex * v2 = right_array[ right_section-1 ];
2105 int height = v2->y - v1->y;
2106 right_section_height = height;
2118 delta_right_x = (v2->x - v1->x) / height;
2119 delta_right_u = (v2->u - v1->u) / height;
2120 delta_right_v = (v2->v - v1->v) / height;
2121 delta_right_R = (v2->R - v1->R) / height;
2122 delta_right_G = (v2->G - v1->G) / height;
2123 delta_right_B = (v2->B - v1->B) / height;
2128 ////////////////////////////////////////////////////////////////////////
2130 static inline int LeftSection_GT4(void)
2132 soft_vertex * v1 = left_array[ left_section ];
2133 soft_vertex * v2 = left_array[ left_section-1 ];
2135 int height = v2->y - v1->y;
2136 left_section_height = height;
2148 delta_left_x = (v2->x - v1->x) / height;
2149 delta_left_u = (v2->u - v1->u) / height;
2150 delta_left_v = (v2->v - v1->v) / height;
2151 delta_left_R = (v2->R - v1->R) / height;
2152 delta_left_G = (v2->G - v1->G) / height;
2153 delta_left_B = (v2->B - v1->B) / height;
2158 ////////////////////////////////////////////////////////////////////////
2160 static inline BOOL NextRow_GT4(void)
2162 if(--left_section_height<=0)
2164 if(--left_section > 0)
2165 while(LeftSection_GT4()<=0)
2167 if(--left_section <= 0) break;
2172 left_x += delta_left_x;
2173 left_u += delta_left_u;
2174 left_v += delta_left_v;
2175 left_R += delta_left_R;
2176 left_G += delta_left_G;
2177 left_B += delta_left_B;
2180 if(--right_section_height<=0)
2182 if(--right_section > 0)
2183 while(RightSection_GT4()<=0)
2185 if(--right_section<=0) break;
2190 right_x += delta_right_x;
2191 right_u += delta_right_u;
2192 right_v += delta_right_v;
2193 right_R += delta_right_R;
2194 right_G += delta_right_G;
2195 right_B += delta_right_B;
2200 ////////////////////////////////////////////////////////////////////////
2202 static inline BOOL SetupSections_GT4(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,int32_t rgb1,int32_t rgb2,int32_t rgb3,int32_t rgb4)
2204 soft_vertex * v1, * v2, * v3, * v4;
2205 int height,width,longest1,longest2;
2207 v1 = vtx; v1->x=x1<<16;v1->y=y1;
2208 v1->u=tx1<<16;v1->v=ty1<<16;
2209 v1->R=(rgb1) & 0x00ff0000;
2210 v1->G=(rgb1<<8) & 0x00ff0000;
2211 v1->B=(rgb1<<16) & 0x00ff0000;
2213 v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
2214 v2->u=tx2<<16;v2->v=ty2<<16;
2215 v2->R=(rgb2) & 0x00ff0000;
2216 v2->G=(rgb2<<8) & 0x00ff0000;
2217 v2->B=(rgb2<<16) & 0x00ff0000;
2219 v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
2220 v3->u=tx3<<16;v3->v=ty3<<16;
2221 v3->R=(rgb3) & 0x00ff0000;
2222 v3->G=(rgb3<<8) & 0x00ff0000;
2223 v3->B=(rgb3<<16) & 0x00ff0000;
2225 v4 = vtx+3; v4->x=x4<<16;v4->y=y4;
2226 v4->u=tx4<<16;v4->v=ty4<<16;
2227 v4->R=(rgb4) & 0x00ff0000;
2228 v4->G=(rgb4<<8) & 0x00ff0000;
2229 v4->B=(rgb4<<16) & 0x00ff0000;
2231 if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
2232 if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
2233 if(v1->y > v4->y) { soft_vertex * v = v1; v1 = v4; v4 = v; }
2234 if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
2235 if(v2->y > v4->y) { soft_vertex * v = v2; v2 = v4; v4 = v; }
2236 if(v3->y > v4->y) { soft_vertex * v = v3; v3 = v4; v4 = v; }
2238 height = v4->y - v1->y; if(height == 0) height =1;
2239 width = (v4->x - v1->x)>>16;
2240 longest1 = (((v2->y - v1->y) << 16) / height) * width + (v1->x - v2->x);
2241 longest2 = (((v3->y - v1->y) << 16) / height) * width + (v1->x - v3->x);
2243 if(longest1 < 0) // 2 is right
2245 if(longest2 < 0) // 3 is right
2251 height = v3->y - v1->y; if(height == 0) height=1;
2252 longest1 = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
2255 right_array[0] = v4; // 1
2256 right_array[1] = v3; // 3
2257 right_array[2] = v1; // 4
2262 height = v4->y - v2->y; if(height == 0) height=1;
2263 longest1 = (((v3->y - v2->y) << 16) / height) * ((v4->x - v2->x)>>16) + (v2->x - v3->x);
2266 right_array[0] = v4; // 1
2267 right_array[1] = v2; // 2
2268 right_array[2] = v1; // 4
2273 right_array[0] = v4; // 1
2274 right_array[1] = v3; // 2
2275 right_array[2] = v2; // 3
2276 right_array[3] = v1; // 4
2284 left_array[1] = v3; // 1
2285 left_array[2] = v1; // 2
2286 left_section = 2; // 3
2287 right_array[0] = v4; // 4
2288 right_array[1] = v2;
2289 right_array[2] = v1;
2297 left_array[0] = v4; // 1
2298 left_array[1] = v2; // 2
2299 left_array[2] = v1; // 3
2300 left_section = 2; // 4
2301 right_array[0] = v4;
2302 right_array[1] = v3;
2303 right_array[2] = v1;
2308 right_array[0] = v4;
2309 right_array[1] = v1;
2312 height = v3->y - v1->y; if(height == 0) height=1;
2313 longest1 = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
2316 left_array[0] = v4; // 1
2317 left_array[1] = v3; // 3
2318 left_array[2] = v1; // 4
2323 height = v4->y - v2->y; if(height == 0) height=1;
2324 longest1 = (((v3->y - v2->y) << 16) / height) * ((v4->x - v2->x)>>16) + (v2->x - v3->x);
2327 left_array[0] = v4; // 1
2328 left_array[1] = v2; // 2
2329 left_array[2] = v1; // 4
2334 left_array[0] = v4; // 1
2335 left_array[1] = v3; // 2
2336 left_array[2] = v2; // 3
2337 left_array[3] = v1; // 4
2344 while(LeftSection_GT4()<=0)
2346 if(--left_section <= 0) break;
2349 while(RightSection_GT4()<=0)
2351 if(--right_section <= 0) break;
2355 Ymax=min(v4->y-1,drawH);
2360 ////////////////////////////////////////////////////////////////////////
2361 ////////////////////////////////////////////////////////////////////////
2362 ////////////////////////////////////////////////////////////////////////
2364 ////////////////////////////////////////////////////////////////////////
2365 ////////////////////////////////////////////////////////////////////////
2366 ////////////////////////////////////////////////////////////////////////
2368 ////////////////////////////////////////////////////////////////////////
2369 // POLY 3/4 FLAT SHADED
2370 ////////////////////////////////////////////////////////////////////////
2372 static inline void drawPoly3Fi(short x1,short y1,short x2,short y2,short x3,short y3,int32_t rgb)
2374 int i,j,xmin,xmax,ymin,ymax;
2375 unsigned short color;uint32_t lcolor;
2377 if(x1>drawW && x2>drawW && x3>drawW) return;
2378 if(y1>drawH && y2>drawH && y3>drawH) return;
2379 if(x1<drawX && x2<drawX && x3<drawX) return;
2380 if(y1<drawY && y2<drawY && y3<drawY) return;
2381 if(drawY>=drawH) return;
2382 if(drawX>=drawW) return;
2384 if(!SetupSections_F(x1,y1,x2,y2,x3,y3)) return;
2388 color = ((rgb & 0x00f80000)>>9) | ((rgb & 0x0000f800)>>6) | ((rgb & 0x000000f8)>>3);
2389 lcolor=lSetMask|(((uint32_t)(color))<<16)|color;
2391 for(ymin=Ymin;ymin<drawY;ymin++)
2392 if(NextRow_F()) return;
2396 if(!bCheckMask && !DrawSemiTrans)
2399 for (i=ymin;i<=ymax;i++)
2401 xmin=left_x >> 16; if(drawX>xmin) xmin=drawX;
2402 xmax=(right_x >> 16)-1; if(drawW<xmax) xmax=drawW;
2404 for(j=xmin;j<xmax;j+=2)
2406 PUTLE32(((uint32_t *)&psxVuw[(i<<10)+j]), lcolor);
2408 if(j==xmax) PUTLE16(&psxVuw[(i<<10)+j], color);
2410 if(NextRow_F()) return;
2417 for (i=ymin;i<=ymax;i++)
2419 xmin=left_x >> 16; if(drawX>xmin) xmin=drawX;
2420 xmax=(right_x >> 16)-1; if(drawW<xmax) xmax=drawW;
2422 for(j=xmin;j<xmax;j+=2)
2424 GetShadeTransCol32((uint32_t *)&psxVuw[(i<<10)+j],lcolor);
2427 GetShadeTransCol(&psxVuw[(i<<10)+j],color);
2429 if(NextRow_F()) return;
2433 ////////////////////////////////////////////////////////////////////////
2435 static void drawPoly3F(int32_t rgb)
2437 drawPoly3Fi(lx0,ly0,lx1,ly1,lx2,ly2,rgb);
2442 static void drawPoly4F_TRI(int32_t rgb)
2444 drawPoly3Fi(lx1,ly1,lx3,ly3,lx2,ly2,rgb);
2445 drawPoly3Fi(lx0,ly0,lx1,ly1,lx2,ly2,rgb);
2452 static void drawPoly4F(int32_t rgb)
2454 int i,j,xmin,xmax,ymin,ymax;
2455 unsigned short color;uint32_t lcolor;
2457 if(lx0>drawW && lx1>drawW && lx2>drawW && lx3>drawW) return;
2458 if(ly0>drawH && ly1>drawH && ly2>drawH && ly3>drawH) return;
2459 if(lx0<drawX && lx1<drawX && lx2<drawX && lx3<drawX) return;
2460 if(ly0<drawY && ly1<drawY && ly2<drawY && ly3<drawY) return;
2461 if(drawY>=drawH) return;
2462 if(drawX>=drawW) return;
2464 if(!SetupSections_F4(lx0,ly0,lx1,ly1,lx2,ly2,lx3,ly3)) return;
2468 for(ymin=Ymin;ymin<drawY;ymin++)
2469 if(NextRow_F4()) return;
2471 color = ((rgb & 0x00f80000)>>9) | ((rgb & 0x0000f800)>>6) | ((rgb & 0x000000f8)>>3);
2472 lcolor= lSetMask|(((uint32_t)(color))<<16)|color;
2476 if(!bCheckMask && !DrawSemiTrans)
2479 for (i=ymin;i<=ymax;i++)
2481 xmin=left_x >> 16; if(drawX>xmin) xmin=drawX;
2482 xmax=(right_x >> 16)-1; if(drawW<xmax) xmax=drawW;
2484 for(j=xmin;j<xmax;j+=2)
2486 PUTLE32(((uint32_t *)&psxVuw[(i<<10)+j]), lcolor);
2488 if(j==xmax) PUTLE16(&psxVuw[(i<<10)+j], color);
2490 if(NextRow_F4()) return;
2497 for (i=ymin;i<=ymax;i++)
2499 xmin=left_x >> 16; if(drawX>xmin) xmin=drawX;
2500 xmax=(right_x >> 16)-1; if(drawW<xmax) xmax=drawW;
2502 for(j=xmin;j<xmax;j+=2)
2504 GetShadeTransCol32((uint32_t *)&psxVuw[(i<<10)+j],lcolor);
2506 if(j==xmax) GetShadeTransCol(&psxVuw[(i<<10)+j],color);
2508 if(NextRow_F4()) return;
2512 ////////////////////////////////////////////////////////////////////////
2513 // POLY 3/4 F-SHADED TEX PAL 4
2514 ////////////////////////////////////////////////////////////////////////
2516 static void drawPoly3TEx4(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3,short clX, short clY)
2518 int i,j,xmin,xmax,ymin,ymax;
2519 int32_t difX, difY,difX2, difY2;
2520 int32_t posX,posY,YAdjust,XAdjust;
2524 if(x1>drawW && x2>drawW && x3>drawW) return;
2525 if(y1>drawH && y2>drawH && y3>drawH) return;
2526 if(x1<drawX && x2<drawX && x3<drawX) return;
2527 if(y1<drawY && y2<drawY && y3<drawY) return;
2528 if(drawY>=drawH) return;
2529 if(drawX>=drawW) return;
2531 if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
2535 for(ymin=Ymin;ymin<drawY;ymin++)
2536 if(NextRow_FT()) return;
2538 clutP=(clY<<10)+clX;
2540 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
2542 difX=delta_right_u;difX2=difX<<1;
2543 difY=delta_right_v;difY2=difY<<1;
2547 if(!bCheckMask && !DrawSemiTrans)
2549 for (i=ymin;i<=ymax;i++)
2551 xmin=(left_x >> 16);
2552 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!
2553 if(drawW<xmax) xmax=drawW;
2561 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
2563 for(j=xmin;j<xmax;j+=2)
2566 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(XAdjust>>1)];
2567 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
2568 XAdjust=((posX+difX)>>16);
2569 tC2 = psxVub[(((posY+difY)>>5)&(int32_t)0xFFFFF800)+YAdjust+
2571 tC2=(tC2>>((XAdjust&1)<<2))&0xf;
2573 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
2574 GETLE16(&psxVuw[clutP+tC1])|
2575 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
2583 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+
2585 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
2586 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
2599 for (i=ymin;i<=ymax;i++)
2601 xmin=(left_x >> 16);
2602 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!
2603 if(drawW<xmax) xmax=drawW;
2611 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
2613 for(j=xmin;j<xmax;j+=2)
2616 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(XAdjust>>1)];
2617 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
2618 XAdjust=((posX+difX)>>16);
2619 tC2 = psxVub[(((posY+difY)>>5)&(int32_t)0xFFFFF800)+YAdjust+
2621 tC2=(tC2>>((XAdjust&1)<<2))&0xf;
2623 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
2624 GETLE16(&psxVuw[clutP+tC1])|
2625 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
2633 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+
2635 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
2636 GetTextureTransColG(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
2646 ////////////////////////////////////////////////////////////////////////
2648 static void drawPoly3TEx4_IL(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3,short clX, short clY)
2650 int i,j,xmin,xmax,ymin,ymax,n_xi,n_yi,TXV;
2651 int32_t difX, difY,difX2, difY2;
2652 int32_t posX,posY,YAdjust,XAdjust;
2656 if(x1>drawW && x2>drawW && x3>drawW) return;
2657 if(y1>drawH && y2>drawH && y3>drawH) return;
2658 if(x1<drawX && x2<drawX && x3<drawX) return;
2659 if(y1<drawY && y2<drawY && y3<drawY) return;
2660 if(drawY>=drawH) return;
2661 if(drawX>=drawW) return;
2663 if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
2667 for(ymin=Ymin;ymin<drawY;ymin++)
2668 if(NextRow_FT()) return;
2670 clutP=(clY<<10)+clX;
2672 YAdjust=(GlobalTextAddrY<<10)+GlobalTextAddrX;
2674 difX=delta_right_u;difX2=difX<<1;
2675 difY=delta_right_v;difY2=difY<<1;
2679 if(!bCheckMask && !DrawSemiTrans)
2681 for (i=ymin;i<=ymax;i++)
2683 xmin=(left_x >> 16);
2684 xmax=(right_x >> 16)-1;
2685 if(drawW<xmax) xmax=drawW;
2693 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
2695 for(j=xmin;j<xmax;j+=2)
2700 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
2701 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
2703 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
2705 XAdjust=((posX+difX)>>16);
2707 TXV=(posY+difY)>>16;
2708 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
2709 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
2711 tC2= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
2713 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
2714 GETLE16(&psxVuw[clutP+tC1])|
2715 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
2725 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
2726 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
2728 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
2730 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
2743 for (i=ymin;i<=ymax;i++)
2745 xmin=(left_x >> 16);
2746 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!
2747 if(drawW<xmax) xmax=drawW;
2755 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
2757 for(j=xmin;j<xmax;j+=2)
2762 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
2763 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
2765 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
2767 XAdjust=((posX+difX)>>16);
2769 TXV=(posY+difY)>>16;
2770 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
2771 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
2773 tC2= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
2775 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
2776 GETLE16(&psxVuw[clutP+tC1])|
2777 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
2787 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
2788 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
2790 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
2792 GetTextureTransColG(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
2802 ////////////////////////////////////////////////////////////////////////
2804 static void drawPoly3TEx4_TW(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3,short clX, short clY)
2806 int i,j,xmin,xmax,ymin,ymax;
2807 int32_t difX, difY,difX2, difY2;
2808 int32_t posX,posY,YAdjust,XAdjust;
2812 if(x1>drawW && x2>drawW && x3>drawW) return;
2813 if(y1>drawH && y2>drawH && y3>drawH) return;
2814 if(x1<drawX && x2<drawX && x3<drawX) return;
2815 if(y1<drawY && y2<drawY && y3<drawY) return;
2816 if(drawY>=drawH) return;
2817 if(drawX>=drawW) return;
2819 if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
2823 for(ymin=Ymin;ymin<drawY;ymin++)
2824 if(NextRow_FT()) return;
2826 clutP=(clY<<10)+clX;
2828 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
2829 YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0>>1);
2831 difX=delta_right_u;difX2=difX<<1;
2832 difY=delta_right_v;difY2=difY<<1;
2836 if(!bCheckMask && !DrawSemiTrans)
2838 for (i=ymin;i<=ymax;i++)
2840 xmin=(left_x >> 16);
2841 xmax=(right_x >> 16);//-1; //!!!!!!!!!!!!!!!!
2842 if(xmax>xmin) xmax--;
2844 if(drawW<xmax) xmax=drawW;
2852 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
2854 for(j=xmin;j<xmax;j+=2)
2856 XAdjust=(posX>>16)%TWin.Position.x1;
2857 tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
2858 YAdjust+(XAdjust>>1)];
2859 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
2860 XAdjust=((posX+difX)>>16)%TWin.Position.x1;
2861 tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
2862 YAdjust+(XAdjust>>1)];
2863 tC2=(tC2>>((XAdjust&1)<<2))&0xf;
2865 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
2866 GETLE16(&psxVuw[clutP+tC1])|
2867 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
2874 XAdjust=(posX>>16)%TWin.Position.x1;
2875 tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
2876 YAdjust+(XAdjust>>1)];
2877 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
2878 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
2891 for (i=ymin;i<=ymax;i++)
2893 xmin=(left_x >> 16);
2894 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!
2895 if(drawW<xmax) xmax=drawW;
2903 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
2905 for(j=xmin;j<xmax;j+=2)
2907 XAdjust=(posX>>16)%TWin.Position.x1;
2908 tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
2909 YAdjust+(XAdjust>>1)];
2910 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
2911 XAdjust=((posX+difX)>>16)%TWin.Position.x1;
2912 tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
2913 YAdjust+(XAdjust>>1)];
2914 tC2=(tC2>>((XAdjust&1)<<2))&0xf;
2916 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
2917 GETLE16(&psxVuw[clutP+tC1])|
2918 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
2925 XAdjust=(posX>>16)%TWin.Position.x1;
2926 tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
2927 YAdjust+(XAdjust>>1)];
2928 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
2929 GetTextureTransColG(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
2939 ////////////////////////////////////////////////////////////////////////
2943 static void drawPoly4TEx4_TRI(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
2945 drawPoly3TEx4(x2,y2,x3,y3,x4,y4,
2946 tx2,ty2,tx3,ty3,tx4,ty4,
2948 drawPoly3TEx4(x1,y1,x2,y2,x4,y4,
2949 tx1,ty1,tx2,ty2,tx4,ty4,
2957 static void drawPoly4TEx4(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
2960 int32_t i,j,xmin,xmax,ymin,ymax;
2961 int32_t difX, difY, difX2, difY2;
2962 int32_t posX,posY,YAdjust,clutP,XAdjust;
2965 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
2966 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
2967 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
2968 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
2969 if(drawY>=drawH) return;
2970 if(drawX>=drawW) return;
2972 if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
2976 for(ymin=Ymin;ymin<drawY;ymin++)
2977 if(NextRow_FT4()) return;
2979 clutP=(clY<<10)+clX;
2981 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
2985 if(!bCheckMask && !DrawSemiTrans)
2987 for (i=ymin;i<=ymax;i++)
2989 xmin=(left_x >> 16);
2990 xmax=(right_x >> 16);
2999 difX=(right_u-posX)/num;
3000 difY=(right_v-posY)/num;
3005 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3006 xmax--;if(drawW<xmax) xmax=drawW;
3008 for(j=xmin;j<xmax;j+=2)
3011 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(XAdjust>>1)];
3012 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
3013 XAdjust=((posX+difX)>>16);
3014 tC2 = psxVub[(((posY+difY)>>5)&(int32_t)0xFFFFF800)+YAdjust+
3016 tC2=(tC2>>((XAdjust&1)<<2))&0xf;
3018 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
3019 GETLE16(&psxVuw[clutP+tC1])|
3020 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3027 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+
3029 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
3030 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3034 if(NextRow_FT4()) return;
3041 for (i=ymin;i<=ymax;i++)
3043 xmin=(left_x >> 16);
3044 xmax=(right_x >> 16);
3053 difX=(right_u-posX)/num;
3054 difY=(right_v-posY)/num;
3059 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3060 xmax--;if(drawW<xmax) xmax=drawW;
3062 for(j=xmin;j<xmax;j+=2)
3065 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(XAdjust>>1)];
3066 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
3067 XAdjust=((posX+difX)>>16);
3068 tC2 = psxVub[(((posY+difY)>>5)&(int32_t)0xFFFFF800)+YAdjust+
3070 tC2=(tC2>>((XAdjust&1)<<2))&0xf;
3072 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
3073 GETLE16(&psxVuw[clutP+tC1])|
3074 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3081 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+
3083 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
3084 GetTextureTransColG(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3087 if(NextRow_FT4()) return;
3091 ////////////////////////////////////////////////////////////////////////
3093 static void drawPoly4TEx4_IL(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
3096 int32_t i,j=0,xmin,xmax,ymin,ymax,n_xi,n_yi,TXV;
3097 int32_t difX, difY, difX2, difY2;
3098 int32_t posX=0,posY=0,YAdjust,clutP,XAdjust;
3101 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
3102 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
3103 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
3104 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
3105 if(drawY>=drawH) return;
3106 if(drawX>=drawW) return;
3108 if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
3112 for(ymin=Ymin;ymin<drawY;ymin++)
3113 if(NextRow_FT4()) return;
3115 clutP=(clY<<10)+clX;
3117 YAdjust=((GlobalTextAddrY)<<10)+GlobalTextAddrX;
3121 if(!bCheckMask && !DrawSemiTrans)
3123 for (i=ymin;i<=ymax;i++)
3125 xmin=(left_x >> 16);
3126 xmax=(right_x >> 16);
3135 difX=(right_u-posX)/num;
3136 difY=(right_v-posY)/num;
3141 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3142 xmax--;if(drawW<xmax) xmax=drawW;
3144 for(j=xmin;j<xmax;j+=2)
3149 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
3150 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
3152 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
3154 XAdjust=((posX+difX)>>16);
3156 TXV=(posY+difY)>>16;
3157 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
3158 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
3160 tC2= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
3162 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
3163 GETLE16(&psxVuw[clutP+tC1])|
3164 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3176 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
3177 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
3179 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
3181 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3185 if(NextRow_FT4()) return;
3189 for (i=ymin;i<=ymax;i++)
3191 xmin=(left_x >> 16);
3192 xmax=(right_x >> 16);
3201 difX=(right_u-posX)/num;
3202 difY=(right_v-posY)/num;
3207 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3208 xmax--;if(drawW<xmax) xmax=drawW;
3210 for(j=xmin;j<xmax;j+=2)
3215 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
3216 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
3218 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
3220 XAdjust=((posX+difX)>>16);
3222 TXV=(posY+difY)>>16;
3223 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
3224 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
3226 tC2= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
3228 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
3229 GETLE16(&psxVuw[clutP+tC1])|
3230 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3238 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
3239 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
3241 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
3243 GetTextureTransColG(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3246 if(NextRow_FT4()) return;
3250 ////////////////////////////////////////////////////////////////////////
3252 static void drawPoly4TEx4_TW(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
3255 int32_t i,j,xmin,xmax,ymin,ymax;
3256 int32_t difX, difY, difX2, difY2;
3257 int32_t posX,posY,YAdjust,clutP,XAdjust;
3260 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
3261 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
3262 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
3263 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
3264 if(drawY>=drawH) return;
3265 if(drawX>=drawW) return;
3267 if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
3271 for(ymin=Ymin;ymin<drawY;ymin++)
3272 if(NextRow_FT4()) return;
3274 clutP=(clY<<10)+clX;
3276 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
3277 YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0>>1);
3281 if(!bCheckMask && !DrawSemiTrans)
3283 for (i=ymin;i<=ymax;i++)
3285 xmin=(left_x >> 16);
3286 xmax=(right_x >> 16);
3295 difX=(right_u-posX)/num;
3296 difY=(right_v-posY)/num;
3301 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3302 xmax--;if(drawW<xmax) xmax=drawW;
3304 for(j=xmin;j<xmax;j+=2)
3306 XAdjust=(posX>>16)%TWin.Position.x1;
3307 tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
3308 YAdjust+(XAdjust>>1)];
3309 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
3310 XAdjust=((posX+difX)>>16)%TWin.Position.x1;
3311 tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
3312 YAdjust+(XAdjust>>1)];
3313 tC2=(tC2>>((XAdjust&1)<<2))&0xf;
3315 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
3316 GETLE16(&psxVuw[clutP+tC1])|
3317 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3323 XAdjust=(posX>>16)%TWin.Position.x1;
3324 tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
3325 YAdjust+(XAdjust>>1)];
3326 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
3327 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3330 if(NextRow_FT4()) return;
3337 for (i=ymin;i<=ymax;i++)
3339 xmin=(left_x >> 16);
3340 xmax=(right_x >> 16);
3349 difX=(right_u-posX)/num;
3350 difY=(right_v-posY)/num;
3355 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3356 xmax--;if(drawW<xmax) xmax=drawW;
3358 for(j=xmin;j<xmax;j+=2)
3360 XAdjust=(posX>>16)%TWin.Position.x1;
3361 tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
3362 YAdjust+(XAdjust>>1)];
3363 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
3364 XAdjust=((posX+difX)>>16)%TWin.Position.x1;
3365 tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
3366 YAdjust+(XAdjust>>1)];
3367 tC2=(tC2>>((XAdjust&1)<<2))&0xf;
3369 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
3370 GETLE16(&psxVuw[clutP+tC1])|
3371 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3377 XAdjust=(posX>>16)%TWin.Position.x1;
3378 tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
3379 YAdjust+(XAdjust>>1)];
3380 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
3381 GetTextureTransColG(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3384 if(NextRow_FT4()) return;
3388 ////////////////////////////////////////////////////////////////////////
3390 static void drawPoly4TEx4_TW_S(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
3393 int32_t i,j,xmin,xmax,ymin,ymax;
3394 int32_t difX, difY, difX2, difY2;
3395 int32_t posX,posY,YAdjust,clutP,XAdjust;
3398 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
3399 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
3400 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
3401 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
3402 if(drawY>=drawH) return;
3403 if(drawX>=drawW) return;
3405 if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
3409 for(ymin=Ymin;ymin<drawY;ymin++)
3410 if(NextRow_FT4()) return;
3412 clutP=(clY<<10)+clX;
3414 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
3415 YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0>>1);
3419 if(!bCheckMask && !DrawSemiTrans)
3421 for (i=ymin;i<=ymax;i++)
3423 xmin=(left_x >> 16);
3424 xmax=(right_x >> 16);
3433 difX=(right_u-posX)/num;
3434 difY=(right_v-posY)/num;
3439 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3440 xmax--;if(drawW<xmax) xmax=drawW;
3442 for(j=xmin;j<xmax;j+=2)
3444 XAdjust=(posX>>16)%TWin.Position.x1;
3445 tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
3446 YAdjust+(XAdjust>>1)];
3447 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
3448 XAdjust=((posX+difX)>>16)%TWin.Position.x1;
3449 tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
3450 YAdjust+(XAdjust>>1)];
3451 tC2=(tC2>>((XAdjust&1)<<2))&0xf;
3453 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
3454 GETLE16(&psxVuw[clutP+tC1])|
3455 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3461 XAdjust=(posX>>16)%TWin.Position.x1;
3462 tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
3463 YAdjust+(XAdjust>>1)];
3464 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
3465 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3468 if(NextRow_FT4()) return;
3475 for (i=ymin;i<=ymax;i++)
3477 xmin=(left_x >> 16);
3478 xmax=(right_x >> 16);
3487 difX=(right_u-posX)/num;
3488 difY=(right_v-posY)/num;
3493 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3494 xmax--;if(drawW<xmax) xmax=drawW;
3496 for(j=xmin;j<xmax;j+=2)
3498 XAdjust=(posX>>16)%TWin.Position.x1;
3499 tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
3500 YAdjust+(XAdjust>>1)];
3501 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
3502 XAdjust=((posX+difX)>>16)%TWin.Position.x1;
3503 tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
3504 YAdjust+(XAdjust>>1)];
3505 tC2=(tC2>>((XAdjust&1)<<2))&0xf;
3507 GetTextureTransColG32_SPR((uint32_t *)&psxVuw[(i<<10)+j],
3508 GETLE16(&psxVuw[clutP+tC1])|
3509 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3515 XAdjust=(posX>>16)%TWin.Position.x1;
3516 tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
3517 YAdjust+(XAdjust>>1)];
3518 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
3519 GetTextureTransColG_SPR(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3522 if(NextRow_FT4()) return;
3525 ////////////////////////////////////////////////////////////////////////
3526 // POLY 3 F-SHADED TEX PAL 8
3527 ////////////////////////////////////////////////////////////////////////
3529 static void drawPoly3TEx8(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3,short clX, short clY)
3531 int i,j,xmin,xmax,ymin,ymax;
3532 int32_t difX, difY,difX2, difY2;
3533 int32_t posX,posY,YAdjust,clutP;
3536 if(x1>drawW && x2>drawW && x3>drawW) return;
3537 if(y1>drawH && y2>drawH && y3>drawH) return;
3538 if(x1<drawX && x2<drawX && x3<drawX) return;
3539 if(y1<drawY && y2<drawY && y3<drawY) return;
3540 if(drawY>=drawH) return;
3541 if(drawX>=drawW) return;
3543 if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
3547 for(ymin=Ymin;ymin<drawY;ymin++)
3548 if(NextRow_FT()) return;
3550 clutP=(clY<<10)+clX;
3552 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
3554 difX=delta_right_u;difX2=difX<<1;
3555 difY=delta_right_v;difY2=difY<<1;
3559 if(!bCheckMask && !DrawSemiTrans)
3561 for (i=ymin;i<=ymax;i++)
3563 xmin=(left_x >> 16);
3564 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!
3565 if(drawW<xmax) xmax=drawW;
3573 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3575 for(j=xmin;j<xmax;j+=2)
3577 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(posX>>16)];
3578 tC2 = psxVub[(((posY+difY)>>5)&(int32_t)0xFFFFF800)+YAdjust+
3580 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
3581 GETLE16(&psxVuw[clutP+tC1])|
3582 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3589 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(posX>>16)];
3590 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3603 for (i=ymin;i<=ymax;i++)
3605 xmin=(left_x >> 16);
3606 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!
3607 if(drawW<xmax) xmax=drawW;
3615 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3617 for(j=xmin;j<xmax;j+=2)
3619 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(posX>>16)];
3620 tC2 = psxVub[(((posY+difY)>>5)&(int32_t)0xFFFFF800)+YAdjust+
3622 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
3623 GETLE16(&psxVuw[clutP+tC1])|
3624 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3631 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(posX>>16)];
3632 GetTextureTransColG(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3643 ////////////////////////////////////////////////////////////////////////
3645 static void drawPoly3TEx8_IL(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3,short clX, short clY)
3647 int i,j,xmin,xmax,ymin,ymax,n_xi,n_yi,TXV,TXU;
3648 int32_t difX, difY,difX2, difY2;
3649 int32_t posX,posY,YAdjust,clutP;
3652 if(x1>drawW && x2>drawW && x3>drawW) return;
3653 if(y1>drawH && y2>drawH && y3>drawH) return;
3654 if(x1<drawX && x2<drawX && x3<drawX) return;
3655 if(y1<drawY && y2<drawY && y3<drawY) return;
3656 if(drawY>=drawH) return;
3657 if(drawX>=drawW) return;
3659 if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
3663 for(ymin=Ymin;ymin<drawY;ymin++)
3664 if(NextRow_FT()) return;
3666 clutP=(clY<<10)+clX;
3668 YAdjust=(GlobalTextAddrY<<10)+GlobalTextAddrX;
3670 difX=delta_right_u;difX2=difX<<1;
3671 difY=delta_right_v;difY2=difY<<1;
3675 if(!bCheckMask && !DrawSemiTrans)
3677 for (i=ymin;i<=ymax;i++)
3679 xmin=(left_x >> 16);
3680 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!
3681 if(drawW<xmax) xmax=drawW;
3689 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3691 for(j=xmin;j<xmax;j+=2)
3695 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
3696 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
3698 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
3700 TXU=(posX+difX)>>16;
3701 TXV=(posY+difY)>>16;
3702 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
3703 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
3705 tC2= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
3707 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
3708 GETLE16(&psxVuw[clutP+tC1])|
3709 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3718 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
3719 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
3721 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
3723 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3736 for (i=ymin;i<=ymax;i++)
3738 xmin=(left_x >> 16);
3739 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!
3740 if(drawW<xmax) xmax=drawW;
3748 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3750 for(j=xmin;j<xmax;j+=2)
3754 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
3755 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
3757 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
3759 TXU=(posX+difX)>>16;
3760 TXV=(posY+difY)>>16;
3761 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
3762 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
3764 tC2= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
3766 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
3767 GETLE16(&psxVuw[clutP+tC1])|
3768 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3777 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
3778 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
3780 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
3782 GetTextureTransColG(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3793 ////////////////////////////////////////////////////////////////////////
3795 static void drawPoly3TEx8_TW(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3,short clX, short clY)
3797 int i,j,xmin,xmax,ymin,ymax;
3798 int32_t difX, difY,difX2, difY2;
3799 int32_t posX,posY,YAdjust,clutP;
3802 if(x1>drawW && x2>drawW && x3>drawW) return;
3803 if(y1>drawH && y2>drawH && y3>drawH) return;
3804 if(x1<drawX && x2<drawX && x3<drawX) return;
3805 if(y1<drawY && y2<drawY && y3<drawY) return;
3806 if(drawY>=drawH) return;
3807 if(drawX>=drawW) return;
3809 if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
3813 for(ymin=Ymin;ymin<drawY;ymin++)
3814 if(NextRow_FT()) return;
3816 clutP=(clY<<10)+clX;
3818 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
3819 YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0);
3821 difX=delta_right_u;difX2=difX<<1;
3822 difY=delta_right_v;difY2=difY<<1;
3826 if(!bCheckMask && !DrawSemiTrans)
3828 for (i=ymin;i<=ymax;i++)
3830 xmin=(left_x >> 16);
3831 xmax=(right_x >> 16);//-1; //!!!!!!!!!!!!!!!!
3832 if(xmax>xmin) xmax--;
3834 if(drawW<xmax) xmax=drawW;
3842 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3844 for(j=xmin;j<xmax;j+=2)
3846 tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
3847 YAdjust+((posX>>16)%TWin.Position.x1)];
3848 tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
3849 YAdjust+(((posX+difX)>>16)%TWin.Position.x1)];
3850 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
3851 GETLE16(&psxVuw[clutP+tC1])|
3852 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3859 tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
3860 YAdjust+((posX>>16)%TWin.Position.x1)];
3861 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3874 for (i=ymin;i<=ymax;i++)
3876 xmin=(left_x >> 16);
3877 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!
3878 if(drawW<xmax) xmax=drawW;
3886 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3888 for(j=xmin;j<xmax;j+=2)
3890 tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
3891 YAdjust+((posX>>16)%TWin.Position.x1)];
3892 tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
3893 YAdjust+(((posX+difX)>>16)%TWin.Position.x1)];
3894 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
3895 GETLE16(&psxVuw[clutP+tC1])|
3896 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3903 tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
3904 YAdjust+((posX>>16)%TWin.Position.x1)];
3905 GetTextureTransColG(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3916 ////////////////////////////////////////////////////////////////////////
3920 static void drawPoly4TEx8_TRI(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
3922 drawPoly3TEx8(x2,y2,x3,y3,x4,y4,
3923 tx2,ty2,tx3,ty3,tx4,ty4,
3926 drawPoly3TEx8(x1,y1,x2,y2,x4,y4,
3927 tx1,ty1,tx2,ty2,tx4,ty4,
3935 static void drawPoly4TEx8(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
3938 int32_t i,j,xmin,xmax,ymin,ymax;
3939 int32_t difX, difY, difX2, difY2;
3940 int32_t posX,posY,YAdjust,clutP;
3943 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
3944 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
3945 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
3946 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
3947 if(drawY>=drawH) return;
3948 if(drawX>=drawW) return;
3950 if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
3954 for(ymin=Ymin;ymin<drawY;ymin++)
3955 if(NextRow_FT4()) return;
3957 clutP=(clY<<10)+clX;
3959 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
3963 if(!bCheckMask && !DrawSemiTrans)
3965 for (i=ymin;i<=ymax;i++)
3967 xmin=(left_x >> 16);
3968 xmax=(right_x >> 16);
3977 difX=(right_u-posX)/num;
3978 difY=(right_v-posY)/num;
3983 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3984 xmax--;if(drawW<xmax) xmax=drawW;
3986 for(j=xmin;j<xmax;j+=2)
3988 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(posX>>16)];
3989 tC2 = psxVub[(((posY+difY)>>5)&(int32_t)0xFFFFF800)+YAdjust+
3991 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
3992 GETLE16(&psxVuw[clutP+tC1])|
3993 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3999 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(posX>>16)];
4000 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
4003 if(NextRow_FT4()) return;
4010 for (i=ymin;i<=ymax;i++)
4012 xmin=(left_x >> 16);
4013 xmax=(right_x >> 16);
4022 difX=(right_u-posX)/num;
4023 difY=(right_v-posY)/num;
4028 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4029 xmax--;if(drawW<xmax) xmax=drawW;
4031 for(j=xmin;j<xmax;j+=2)
4033 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(posX>>16)];
4034 tC2 = psxVub[(((posY+difY)>>5)&(int32_t)0xFFFFF800)+YAdjust+
4036 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
4037 GETLE16(&psxVuw[clutP+tC1])|
4038 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
4044 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(posX>>16)];
4045 GetTextureTransColG(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
4048 if(NextRow_FT4()) return;
4052 ////////////////////////////////////////////////////////////////////////
4054 static void drawPoly4TEx8_IL(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
4057 int32_t i,j,xmin,xmax,ymin,ymax,n_xi,n_yi,TXV,TXU;
4058 int32_t difX, difY, difX2, difY2;
4059 int32_t posX,posY,YAdjust,clutP;
4062 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
4063 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
4064 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
4065 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
4066 if(drawY>=drawH) return;
4067 if(drawX>=drawW) return;
4069 if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
4073 for(ymin=Ymin;ymin<drawY;ymin++)
4074 if(NextRow_FT4()) return;
4076 clutP=(clY<<10)+clX;
4078 YAdjust=(GlobalTextAddrY<<10)+GlobalTextAddrX;
4082 if(!bCheckMask && !DrawSemiTrans)
4084 for (i=ymin;i<=ymax;i++)
4086 xmin=(left_x >> 16);
4087 xmax=(right_x >> 16);
4096 difX=(right_u-posX)/num;
4097 difY=(right_v-posY)/num;
4102 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4103 xmax--;if(drawW<xmax) xmax=drawW;
4105 for(j=xmin;j<xmax;j+=2)
4109 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
4110 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
4112 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
4114 TXU=(posX+difX)>>16;
4115 TXV=(posY+difY)>>16;
4116 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
4117 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
4119 tC2= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
4121 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
4122 GETLE16(&psxVuw[clutP+tC1])|
4123 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
4131 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
4132 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
4134 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
4136 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
4139 if(NextRow_FT4()) return;
4146 for (i=ymin;i<=ymax;i++)
4148 xmin=(left_x >> 16);
4149 xmax=(right_x >> 16);
4158 difX=(right_u-posX)/num;
4159 difY=(right_v-posY)/num;
4164 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4165 xmax--;if(drawW<xmax) xmax=drawW;
4167 for(j=xmin;j<xmax;j+=2)
4171 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
4172 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
4174 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
4176 TXU=(posX+difX)>>16;
4177 TXV=(posY+difY)>>16;
4178 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
4179 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
4181 tC2= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
4183 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
4184 GETLE16(&psxVuw[clutP+tC1])|
4185 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
4193 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
4194 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
4195 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
4196 GetTextureTransColG(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
4199 if(NextRow_FT4()) return;
4203 ////////////////////////////////////////////////////////////////////////
4205 static void drawPoly4TEx8_TW(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
4208 int32_t i,j,xmin,xmax,ymin,ymax;
4209 int32_t difX, difY, difX2, difY2;
4210 int32_t posX,posY,YAdjust,clutP;
4213 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
4214 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
4215 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
4216 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
4217 if(drawY>=drawH) return;
4218 if(drawX>=drawW) return;
4220 if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
4224 for(ymin=Ymin;ymin<drawY;ymin++)
4225 if(NextRow_FT4()) return;
4227 clutP=(clY<<10)+clX;
4229 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
4230 YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0);
4234 if(!bCheckMask && !DrawSemiTrans)
4236 for (i=ymin;i<=ymax;i++)
4238 xmin=(left_x >> 16);
4239 xmax=(right_x >> 16);
4248 difX=(right_u-posX)/num;
4249 difY=(right_v-posY)/num;
4254 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4255 xmax--;if(drawW<xmax) xmax=drawW;
4257 for(j=xmin;j<xmax;j+=2)
4259 tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
4260 YAdjust+((posX>>16)%TWin.Position.x1)];
4261 tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
4262 YAdjust+(((posX+difX)>>16)%TWin.Position.x1)];
4263 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
4264 GETLE16(&psxVuw[clutP+tC1])|
4265 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
4271 tC1 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
4272 YAdjust+((posX>>16)%TWin.Position.x1)];
4273 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
4276 if(NextRow_FT4()) return;
4284 for (i=ymin;i<=ymax;i++)
4286 xmin=(left_x >> 16);
4287 xmax=(right_x >> 16);
4296 difX=(right_u-posX)/num;
4297 difY=(right_v-posY)/num;
4302 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4303 xmax--;if(drawW<xmax) xmax=drawW;
4305 for(j=xmin;j<xmax;j+=2)
4307 tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
4308 YAdjust+((posX>>16)%TWin.Position.x1)];
4309 tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
4310 YAdjust+(((posX+difX)>>16)%TWin.Position.x1)];
4311 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
4312 GETLE16(&psxVuw[clutP+tC1])|
4313 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
4319 tC1 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
4320 YAdjust+((posX>>16)%TWin.Position.x1)];
4321 GetTextureTransColG(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
4324 if(NextRow_FT4()) return;
4328 ////////////////////////////////////////////////////////////////////////
4330 static void drawPoly4TEx8_TW_S(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
4333 int32_t i,j,xmin,xmax,ymin,ymax;
4334 int32_t difX, difY, difX2, difY2;
4335 int32_t posX,posY,YAdjust,clutP;
4338 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
4339 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
4340 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
4341 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
4342 if(drawY>=drawH) return;
4343 if(drawX>=drawW) return;
4345 if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
4349 for(ymin=Ymin;ymin<drawY;ymin++)
4350 if(NextRow_FT4()) return;
4352 clutP=(clY<<10)+clX;
4354 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
4355 YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0);
4359 if(!bCheckMask && !DrawSemiTrans)
4361 for (i=ymin;i<=ymax;i++)
4363 xmin=(left_x >> 16);
4364 xmax=(right_x >> 16);
4373 difX=(right_u-posX)/num;
4374 difY=(right_v-posY)/num;
4379 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4380 xmax--;if(drawW<xmax) xmax=drawW;
4382 for(j=xmin;j<xmax;j+=2)
4384 tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
4385 YAdjust+((posX>>16)%TWin.Position.x1)];
4386 tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
4387 YAdjust+(((posX+difX)>>16)%TWin.Position.x1)];
4388 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
4389 GETLE16(&psxVuw[clutP+tC1])|
4390 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
4396 tC1 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
4397 YAdjust+((posX>>16)%TWin.Position.x1)];
4398 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
4401 if(NextRow_FT4()) return;
4409 for (i=ymin;i<=ymax;i++)
4411 xmin=(left_x >> 16);
4412 xmax=(right_x >> 16);
4421 difX=(right_u-posX)/num;
4422 difY=(right_v-posY)/num;
4427 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4428 xmax--;if(drawW<xmax) xmax=drawW;
4430 for(j=xmin;j<xmax;j+=2)
4432 tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
4433 YAdjust+((posX>>16)%TWin.Position.x1)];
4434 tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
4435 YAdjust+(((posX+difX)>>16)%TWin.Position.x1)];
4436 GetTextureTransColG32_SPR((uint32_t *)&psxVuw[(i<<10)+j],
4437 GETLE16(&psxVuw[clutP+tC1])|
4438 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
4444 tC1 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
4445 YAdjust+((posX>>16)%TWin.Position.x1)];
4446 GetTextureTransColG_SPR(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
4449 if(NextRow_FT4()) return;
4453 ////////////////////////////////////////////////////////////////////////
4454 // POLY 3 F-SHADED TEX 15 BIT
4455 ////////////////////////////////////////////////////////////////////////
4457 static void drawPoly3TD(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3)
4459 int i,j,xmin,xmax,ymin,ymax;
4460 int32_t difX, difY,difX2, difY2;
4463 if(x1>drawW && x2>drawW && x3>drawW) return;
4464 if(y1>drawH && y2>drawH && y3>drawH) return;
4465 if(x1<drawX && x2<drawX && x3<drawX) return;
4466 if(y1<drawY && y2<drawY && y3<drawY) return;
4467 if(drawY>=drawH) return;
4468 if(drawX>=drawW) return;
4470 if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
4474 for(ymin=Ymin;ymin<drawY;ymin++)
4475 if(NextRow_FT()) return;
4477 difX=delta_right_u;difX2=difX<<1;
4478 difY=delta_right_v;difY2=difY<<1;
4482 if(!bCheckMask && !DrawSemiTrans)
4484 for (i=ymin;i<=ymax;i++)
4486 xmin=(left_x >> 16);
4487 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!
4488 if(drawW<xmax) xmax=drawW;
4496 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4498 for(j=xmin;j<xmax;j+=2)
4500 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
4501 (((int32_t)GETLE16(&psxVuw[((((posY+difY)>>16)+GlobalTextAddrY)<<10)+((posX+difX)>>16)+GlobalTextAddrX]))<<16)|
4502 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+((posX)>>16)+GlobalTextAddrX]));
4508 GetTextureTransColG_S(&psxVuw[(i<<10)+j],
4509 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]));
4521 for (i=ymin;i<=ymax;i++)
4523 xmin=(left_x >> 16);
4524 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!
4525 if(drawW<xmax) xmax=drawW;
4533 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4535 for(j=xmin;j<xmax;j+=2)
4537 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
4538 (((int32_t)GETLE16(&psxVuw[((((posY+difY)>>16)+GlobalTextAddrY)<<10)+((posX+difX)>>16)+GlobalTextAddrX]))<<16)|
4539 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+((posX)>>16)+GlobalTextAddrX]));
4545 GetTextureTransColG(&psxVuw[(i<<10)+j],
4546 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]));
4555 ////////////////////////////////////////////////////////////////////////
4557 static void drawPoly3TD_TW(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3)
4559 int i,j,xmin,xmax,ymin,ymax;
4560 int32_t difX, difY,difX2, difY2;
4563 if(x1>drawW && x2>drawW && x3>drawW) return;
4564 if(y1>drawH && y2>drawH && y3>drawH) return;
4565 if(x1<drawX && x2<drawX && x3<drawX) return;
4566 if(y1<drawY && y2<drawY && y3<drawY) return;
4567 if(drawY>=drawH) return;
4568 if(drawX>=drawW) return;
4570 if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
4574 for(ymin=Ymin;ymin<drawY;ymin++)
4575 if(NextRow_FT()) return;
4577 difX=delta_right_u;difX2=difX<<1;
4578 difY=delta_right_v;difY2=difY<<1;
4582 if(!bCheckMask && !DrawSemiTrans)
4584 for (i=ymin;i<=ymax;i++)
4586 xmin=(left_x >> 16);
4587 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!
4588 if(drawW<xmax) xmax=drawW;
4596 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4598 for(j=xmin;j<xmax;j+=2)
4600 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
4601 (((int32_t)GETLE16(&psxVuw[(((((posY+difY)>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4602 (((posX+difX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]))<<16)|
4603 GETLE16(&psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4604 (((posX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]));
4610 GetTextureTransColG_S(&psxVuw[(i<<10)+j],
4611 GETLE16(&psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4612 ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]));
4624 for (i=ymin;i<=ymax;i++)
4626 xmin=(left_x >> 16);
4627 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!
4628 if(drawW<xmax) xmax=drawW;
4636 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4638 for(j=xmin;j<xmax;j+=2)
4640 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
4641 (((int32_t)GETLE16(&psxVuw[(((((posY+difY)>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4642 (((posX+difX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]))<<16)|
4643 GETLE16(&psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4644 (((posX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]));
4650 GetTextureTransColG(&psxVuw[(i<<10)+j],
4651 GETLE16(&psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4652 ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]));
4662 ////////////////////////////////////////////////////////////////////////
4666 static void drawPoly4TD_TRI(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4)
4668 drawPoly3TD(x2,y2,x3,y3,x4,y4,
4669 tx2,ty2,tx3,ty3,tx4,ty4);
4670 drawPoly3TD(x1,y1,x2,y2,x4,y4,
4671 tx1,ty1,tx2,ty2,tx4,ty4);
4678 static void drawPoly4TD(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4)
4681 int32_t i,j,xmin,xmax,ymin,ymax;
4682 int32_t difX, difY, difX2, difY2;
4685 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
4686 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
4687 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
4688 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
4689 if(drawY>=drawH) return;
4690 if(drawX>=drawW) return;
4692 if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
4696 for(ymin=Ymin;ymin<drawY;ymin++)
4697 if(NextRow_FT4()) return;
4701 if(!bCheckMask && !DrawSemiTrans)
4703 for (i=ymin;i<=ymax;i++)
4705 xmin=(left_x >> 16);
4706 xmax=(right_x >> 16);
4715 difX=(right_u-posX)/num;
4716 difY=(right_v-posY)/num;
4721 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4722 xmax--;if(drawW<xmax) xmax=drawW;
4724 for(j=xmin;j<xmax;j+=2)
4726 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
4727 (((int32_t)GETLE16(&psxVuw[((((posY+difY)>>16)+GlobalTextAddrY)<<10)+((posX+difX)>>16)+GlobalTextAddrX]))<<16)|
4728 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+((posX)>>16)+GlobalTextAddrX]));
4734 GetTextureTransColG_S(&psxVuw[(i<<10)+j],
4735 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]));
4737 if(NextRow_FT4()) return;
4744 for (i=ymin;i<=ymax;i++)
4746 xmin=(left_x >> 16);
4747 xmax=(right_x >> 16);
4756 difX=(right_u-posX)/num;
4757 difY=(right_v-posY)/num;
4762 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4763 xmax--;if(drawW<xmax) xmax=drawW;
4765 for(j=xmin;j<xmax;j+=2)
4767 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
4768 (((int32_t)GETLE16(&psxVuw[((((posY+difY)>>16)+GlobalTextAddrY)<<10)+((posX+difX)>>16)+GlobalTextAddrX]))<<16)|
4769 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+((posX)>>16)+GlobalTextAddrX]));
4775 GetTextureTransColG(&psxVuw[(i<<10)+j],
4776 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]));
4778 if(NextRow_FT4()) return;
4782 ////////////////////////////////////////////////////////////////////////
4784 static void drawPoly4TD_TW(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4)
4787 int32_t i,j,xmin,xmax,ymin,ymax;
4788 int32_t difX, difY, difX2, difY2;
4791 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
4792 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
4793 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
4794 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
4795 if(drawY>=drawH) return;
4796 if(drawX>=drawW) return;
4798 if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
4802 for(ymin=Ymin;ymin<drawY;ymin++)
4803 if(NextRow_FT4()) return;
4807 if(!bCheckMask && !DrawSemiTrans)
4809 for (i=ymin;i<=ymax;i++)
4811 xmin=(left_x >> 16);
4812 xmax=(right_x >> 16);
4821 difX=(right_u-posX)/num;
4822 difY=(right_v-posY)/num;
4827 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4828 xmax--;if(drawW<xmax) xmax=drawW;
4830 for(j=xmin;j<xmax;j+=2)
4832 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
4833 (((int32_t)GETLE16(&psxVuw[(((((posY+difY)>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4834 (((posX+difX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]))<<16)|
4835 GETLE16(&psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY)<<10)+TWin.Position.y0+
4836 ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]));
4842 GetTextureTransColG_S(&psxVuw[(i<<10)+j],
4843 GETLE16(&psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4844 ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]));
4846 if(NextRow_FT4()) return;
4853 for (i=ymin;i<=ymax;i++)
4855 xmin=(left_x >> 16);
4856 xmax=(right_x >> 16);
4865 difX=(right_u-posX)/num;
4866 difY=(right_v-posY)/num;
4871 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4872 xmax--;if(drawW<xmax) xmax=drawW;
4874 for(j=xmin;j<xmax;j+=2)
4876 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
4877 (((int32_t)GETLE16(&psxVuw[(((((posY+difY)>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4878 (((posX+difX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]))<<16)|
4879 GETLE16(&psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4880 ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]));
4886 GetTextureTransColG(&psxVuw[(i<<10)+j],
4887 GETLE16(&psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4888 ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]));
4890 if(NextRow_FT4()) return;
4894 ////////////////////////////////////////////////////////////////////////
4896 static void drawPoly4TD_TW_S(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4)
4899 int32_t i,j,xmin,xmax,ymin,ymax;
4900 int32_t difX, difY, difX2, difY2;
4903 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
4904 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
4905 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
4906 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
4907 if(drawY>=drawH) return;
4908 if(drawX>=drawW) return;
4910 if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
4914 for(ymin=Ymin;ymin<drawY;ymin++)
4915 if(NextRow_FT4()) return;
4919 if(!bCheckMask && !DrawSemiTrans)
4921 for (i=ymin;i<=ymax;i++)
4923 xmin=(left_x >> 16);
4924 xmax=(right_x >> 16);
4933 difX=(right_u-posX)/num;
4934 difY=(right_v-posY)/num;
4939 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4940 xmax--;if(drawW<xmax) xmax=drawW;
4942 for(j=xmin;j<xmax;j+=2)
4944 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
4945 (((int32_t)GETLE16(&psxVuw[(((((posY+difY)>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4946 (((posX+difX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]))<<16)|
4947 GETLE16(&psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY)<<10)+TWin.Position.y0+
4948 ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]));
4954 GetTextureTransColG_S(&psxVuw[(i<<10)+j],
4955 GETLE16(&psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4956 ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]));
4958 if(NextRow_FT4()) return;
4965 for (i=ymin;i<=ymax;i++)
4967 xmin=(left_x >> 16);
4968 xmax=(right_x >> 16);
4977 difX=(right_u-posX)/num;
4978 difY=(right_v-posY)/num;
4983 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4984 xmax--;if(drawW<xmax) xmax=drawW;
4986 for(j=xmin;j<xmax;j+=2)
4988 GetTextureTransColG32_SPR((uint32_t *)&psxVuw[(i<<10)+j],
4989 (((int32_t)GETLE16(&psxVuw[(((((posY+difY)>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4990 (((posX+difX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]))<<16)|
4991 GETLE16(&psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4992 ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]));
4998 GetTextureTransColG_SPR(&psxVuw[(i<<10)+j],
4999 GETLE16(&psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
5000 ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]));
5002 if(NextRow_FT4()) return;
5006 ////////////////////////////////////////////////////////////////////////
5007 // POLY 3/4 G-SHADED
5008 ////////////////////////////////////////////////////////////////////////
5010 static inline void drawPoly3Gi(short x1,short y1,short x2,short y2,short x3,short y3,int32_t rgb1, int32_t rgb2, int32_t rgb3)
5012 int i,j,xmin,xmax,ymin,ymax;
5013 int32_t cR1,cG1,cB1;
5014 int32_t difR,difB,difG,difR2,difB2,difG2;
5016 if(x1>drawW && x2>drawW && x3>drawW) return;
5017 if(y1>drawH && y2>drawH && y3>drawH) return;
5018 if(x1<drawX && x2<drawX && x3<drawX) return;
5019 if(y1<drawY && y2<drawY && y3<drawY) return;
5020 if(drawY>=drawH) return;
5021 if(drawX>=drawW) return;
5023 if(!SetupSections_G(x1,y1,x2,y2,x3,y3,rgb1,rgb2,rgb3)) return;
5027 for(ymin=Ymin;ymin<drawY;ymin++)
5028 if(NextRow_G()) return;
5039 if(!bCheckMask && !DrawSemiTrans && iDither!=2)
5041 for (i=ymin;i<=ymax;i++)
5043 xmin=(left_x >> 16);
5044 xmax=(right_x >> 16)-1;if(drawW<xmax) xmax=drawW;
5053 {j=drawX-xmin;xmin=drawX;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
5055 for(j=xmin;j<xmax;j+=2)
5057 PUTLE32(((uint32_t *)&psxVuw[(i<<10)+j]),
5058 ((((cR1+difR) <<7)&0x7c000000)|(((cG1+difG) << 2)&0x03e00000)|(((cB1+difB)>>3)&0x001f0000)|
5059 (((cR1) >> 9)&0x7c00)|(((cG1) >> 14)&0x03e0)|(((cB1) >> 19)&0x001f))|lSetMask);
5066 PUTLE16(&psxVuw[(i<<10)+j], (((cR1 >> 9)&0x7c00)|((cG1 >> 14)&0x03e0)|((cB1 >> 19)&0x001f))|sSetMask);
5068 if(NextRow_G()) return;
5076 for (i=ymin;i<=ymax;i++)
5078 xmin=(left_x >> 16);
5079 xmax=(right_x >> 16)-1;if(drawW<xmax) xmax=drawW;
5088 {j=drawX-xmin;xmin=drawX;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
5090 for(j=xmin;j<=xmax;j++)
5092 GetShadeTransCol_Dither(&psxVuw[(i<<10)+j],(cB1>>16),(cG1>>16),(cR1>>16));
5099 if(NextRow_G()) return;
5102 for (i=ymin;i<=ymax;i++)
5104 xmin=(left_x >> 16);
5105 xmax=(right_x >> 16)-1;if(drawW<xmax) xmax=drawW;
5114 {j=drawX-xmin;xmin=drawX;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
5116 for(j=xmin;j<=xmax;j++)
5118 GetShadeTransCol(&psxVuw[(i<<10)+j],((cR1 >> 9)&0x7c00)|((cG1 >> 14)&0x03e0)|((cB1 >> 19)&0x001f));
5125 if(NextRow_G()) return;
5130 ////////////////////////////////////////////////////////////////////////
5132 static void drawPoly3G(int32_t rgb1, int32_t rgb2, int32_t rgb3)
5134 drawPoly3Gi(lx0,ly0,lx1,ly1,lx2,ly2,rgb1,rgb2,rgb3);
5137 // draw two g-shaded tris for right psx shading emulation
5139 static void drawPoly4G(int32_t rgb1, int32_t rgb2, int32_t rgb3, int32_t rgb4)
5141 drawPoly3Gi(lx1,ly1,lx3,ly3,lx2,ly2,
5143 drawPoly3Gi(lx0,ly0,lx1,ly1,lx2,ly2,
5147 ////////////////////////////////////////////////////////////////////////
5148 // POLY 3/4 G-SHADED TEX PAL4
5149 ////////////////////////////////////////////////////////////////////////
5151 static void drawPoly3TGEx4(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short clX, short clY,int32_t col1, int32_t col2, int32_t col3)
5153 int i,j,xmin,xmax,ymin,ymax;
5154 int32_t cR1,cG1,cB1;
5155 int32_t difR,difB,difG,difR2,difB2,difG2;
5156 int32_t difX, difY,difX2, difY2;
5157 int32_t posX,posY,YAdjust,clutP,XAdjust;
5160 if(x1>drawW && x2>drawW && x3>drawW) return;
5161 if(y1>drawH && y2>drawH && y3>drawH) return;
5162 if(x1<drawX && x2<drawX && x3<drawX) return;
5163 if(y1<drawY && y2<drawY && y3<drawY) return;
5164 if(drawY>=drawH) return;
5165 if(drawX>=drawW) return;
5167 if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
5171 for(ymin=Ymin;ymin<drawY;ymin++)
5172 if(NextRow_GT()) return;
5174 clutP=(clY<<10)+clX;
5176 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
5185 difX=delta_right_u;difX2=difX<<1;
5186 difY=delta_right_v;difY2=difY<<1;
5190 if(!bCheckMask && !DrawSemiTrans && !iDither)
5192 for (i=ymin;i<=ymax;i++)
5194 xmin=((left_x) >> 16);
5195 xmax=((right_x) >> 16)-1; //!!!!!!!!!!!!!
5196 if(drawW<xmax) xmax=drawW;
5207 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
5209 for(j=xmin;j<xmax;j+=2)
5212 tC1 = psxVub[((posY>>5)&0xFFFFF800)+YAdjust+(XAdjust>>1)];
5213 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
5214 XAdjust=((posX+difX)>>16);
5215 tC2 = psxVub[(((posY+difY)>>5)&(int32_t)0xFFFFF800)+YAdjust+
5217 tC2=(tC2>>((XAdjust&1)<<2))&0xf;
5219 GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
5220 GETLE16(&psxVuw[clutP+tC1])|
5221 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16,
5222 (cB1>>16)|((cB1+difB)&0xff0000),
5223 (cG1>>16)|((cG1+difG)&0xff0000),
5224 (cR1>>16)|((cR1+difR)&0xff0000));
5234 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(XAdjust>>1)];
5235 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
5236 GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
5237 GETLE16(&psxVuw[clutP+tC1]),
5238 (cB1>>16),(cG1>>16),(cR1>>16));
5251 for (i=ymin;i<=ymax;i++)
5253 xmin=(left_x >> 16);
5254 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!
5255 if(drawW<xmax) xmax=drawW;
5266 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
5268 for(j=xmin;j<=xmax;j++)
5271 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(XAdjust>>1)];
5272 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
5274 GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
5275 GETLE16(&psxVuw[clutP+tC1]),
5276 (cB1>>16),(cG1>>16),(cR1>>16));
5278 GetTextureTransColGX(&psxVuw[(i<<10)+j],
5279 GETLE16(&psxVuw[clutP+tC1]),
5280 (cB1>>16),(cG1>>16),(cR1>>16));
5295 ////////////////////////////////////////////////////////////////////////
5297 static void drawPoly3TGEx4_IL(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short clX, short clY,int32_t col1, int32_t col2, int32_t col3)
5299 int i,j,xmin,xmax,ymin,ymax,n_xi,n_yi,TXV;
5300 int32_t cR1,cG1,cB1;
5301 int32_t difR,difB,difG,difR2,difB2,difG2;
5302 int32_t difX, difY,difX2, difY2;
5303 int32_t posX,posY,YAdjust,clutP,XAdjust;
5306 if(x1>drawW && x2>drawW && x3>drawW) return;
5307 if(y1>drawH && y2>drawH && y3>drawH) return;
5308 if(x1<drawX && x2<drawX && x3<drawX) return;
5309 if(y1<drawY && y2<drawY && y3<drawY) return;
5310 if(drawY>=drawH) return;
5311 if(drawX>=drawW) return;
5313 if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
5317 for(ymin=Ymin;ymin<drawY;ymin++)
5318 if(NextRow_GT()) return;
5320 clutP=(clY<<10)+clX;
5322 YAdjust=(GlobalTextAddrY<<10)+GlobalTextAddrX;
5331 difX=delta_right_u;difX2=difX<<1;
5332 difY=delta_right_v;difY2=difY<<1;
5336 if(!bCheckMask && !DrawSemiTrans && !iDither)
5338 for (i=ymin;i<=ymax;i++)
5340 xmin=((left_x) >> 16);
5341 xmax=((right_x) >> 16)-1; //!!!!!!!!!!!!!
5342 if(drawW<xmax) xmax=drawW;
5353 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
5355 for(j=xmin;j<xmax;j+=2)
5360 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
5361 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
5363 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
5365 XAdjust=((posX+difX)>>16);
5367 TXV=(posY+difY)>>16;
5368 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
5369 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
5371 tC2= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
5373 GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
5374 GETLE16(&psxVuw[clutP+tC1])|
5375 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16,
5376 (cB1>>16)|((cB1+difB)&0xff0000),
5377 (cG1>>16)|((cG1+difG)&0xff0000),
5378 (cR1>>16)|((cR1+difR)&0xff0000));
5390 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
5391 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
5393 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
5395 GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
5396 GETLE16(&psxVuw[clutP+tC1]),
5397 (cB1>>16),(cG1>>16),(cR1>>16));
5410 for (i=ymin;i<=ymax;i++)
5412 xmin=(left_x >> 16);
5413 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!
5414 if(drawW<xmax) xmax=drawW;
5425 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
5427 for(j=xmin;j<=xmax;j++)
5432 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
5433 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
5435 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
5438 GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
5439 GETLE16(&psxVuw[clutP+tC1]),
5440 (cB1>>16),(cG1>>16),(cR1>>16));
5442 GetTextureTransColGX(&psxVuw[(i<<10)+j],
5443 GETLE16(&psxVuw[clutP+tC1]),
5444 (cB1>>16),(cG1>>16),(cR1>>16));
5459 ////////////////////////////////////////////////////////////////////////
5461 static void drawPoly3TGEx4_TW(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short clX, short clY,int32_t col1, int32_t col2, int32_t col3)
5463 int i,j,xmin,xmax,ymin,ymax;
5464 int32_t cR1,cG1,cB1;
5465 int32_t difR,difB,difG,difR2,difB2,difG2;
5466 int32_t difX, difY,difX2, difY2;
5467 int32_t posX,posY,YAdjust,clutP,XAdjust;
5470 if(x1>drawW && x2>drawW && x3>drawW) return;
5471 if(y1>drawH && y2>drawH && y3>drawH) return;
5472 if(x1<drawX && x2<drawX && x3<drawX) return;
5473 if(y1<drawY && y2<drawY && y3<drawY) return;
5474 if(drawY>=drawH) return;
5475 if(drawX>=drawW) return;
5477 if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
5481 for(ymin=Ymin;ymin<drawY;ymin++)
5482 if(NextRow_GT()) return;
5484 clutP=(clY<<10)+clX;
5486 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
5487 YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0>>1);
5496 difX=delta_right_u;difX2=difX<<1;
5497 difY=delta_right_v;difY2=difY<<1;
5501 if(!bCheckMask && !DrawSemiTrans && !iDither)
5503 for (i=ymin;i<=ymax;i++)
5505 xmin=((left_x) >> 16);
5506 xmax=((right_x) >> 16)-1; //!!!!!!!!!!!!!
5507 if(drawW<xmax) xmax=drawW;
5518 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
5520 for(j=xmin;j<xmax;j+=2)
5522 XAdjust=(posX>>16)%TWin.Position.x1;
5523 tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
5524 YAdjust+(XAdjust>>1)];
5525 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
5526 XAdjust=((posX+difX)>>16)%TWin.Position.x1;
5527 tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
5528 YAdjust+(XAdjust>>1)];
5529 tC2=(tC2>>((XAdjust&1)<<2))&0xf;
5530 GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
5531 GETLE16(&psxVuw[clutP+tC1])|
5532 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16,
5533 (cB1>>16)|((cB1+difB)&0xff0000),
5534 (cG1>>16)|((cG1+difG)&0xff0000),
5535 (cR1>>16)|((cR1+difR)&0xff0000));
5544 XAdjust=(posX>>16)%TWin.Position.x1;
5545 tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
5546 YAdjust+(XAdjust>>1)];
5547 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
5548 GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
5549 GETLE16(&psxVuw[clutP+tC1]),
5550 (cB1>>16),(cG1>>16),(cR1>>16));
5563 for (i=ymin;i<=ymax;i++)
5565 xmin=(left_x >> 16);
5566 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!
5567 if(drawW<xmax) xmax=drawW;
5578 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
5580 for(j=xmin;j<=xmax;j++)
5582 XAdjust=(posX>>16)%TWin.Position.x1;
5583 tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
5584 YAdjust+(XAdjust>>1)];
5585 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
5587 GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
5588 GETLE16(&psxVuw[clutP+tC1]),
5589 (cB1>>16),(cG1>>16),(cR1>>16));
5591 GetTextureTransColGX(&psxVuw[(i<<10)+j],
5592 GETLE16(&psxVuw[clutP+tC1]),
5593 (cB1>>16),(cG1>>16),(cR1>>16));
5608 ////////////////////////////////////////////////////////////////////////
5610 // note: the psx is doing g-shaded quads as two g-shaded tris,
5611 // like the following func... sadly texturing is not 100%
5612 // correct that way, so small texture distortions can
5615 static void drawPoly4TGEx4_TRI_IL(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
5616 short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
5617 short clX, short clY,
5618 int32_t col1, int32_t col2, int32_t col3, int32_t col4)
5620 drawPoly3TGEx4_IL(x2,y2,x3,y3,x4,y4,
5621 tx2,ty2,tx3,ty3,tx4,ty4,
5624 drawPoly3TGEx4_IL(x1,y1,x2,y2,x4,y4,
5625 tx1,ty1,tx2,ty2,tx4,ty4,
5632 static void drawPoly4TGEx4_TRI(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
5633 short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
5634 short clX, short clY,
5635 int32_t col1, int32_t col2, int32_t col3, int32_t col4)
5637 drawPoly3TGEx4(x2,y2,x3,y3,x4,y4,
5638 tx2,ty2,tx3,ty3,tx4,ty4,
5641 drawPoly3TGEx4(x1,y1,x2,y2,x4,y4,
5642 tx1,ty1,tx2,ty2,tx4,ty4,
5649 ////////////////////////////////////////////////////////////////////////
5651 static void drawPoly4TGEx4(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
5652 short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
5653 short clX, short clY,
5654 int32_t col1, int32_t col2, int32_t col4, int32_t col3)
5657 int32_t i,j,xmin,xmax,ymin,ymax;
5658 int32_t cR1,cG1,cB1;
5659 int32_t difR,difB,difG,difR2,difB2,difG2;
5660 int32_t difX, difY, difX2, difY2;
5661 int32_t posX,posY,YAdjust,clutP,XAdjust;
5664 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
5665 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
5666 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
5667 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
5668 if(drawY>=drawH) return;
5669 if(drawX>=drawW) return;
5671 if(!SetupSections_GT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4,col1,col2,col3,col4)) return;
5675 for(ymin=Ymin;ymin<drawY;ymin++)
5676 if(NextRow_GT4()) return;
5678 clutP=(clY<<10)+clX;
5680 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
5685 if(!bCheckMask && !DrawSemiTrans && !iDither)
5687 for (i=ymin;i<=ymax;i++)
5689 xmin=(left_x >> 16);
5690 xmax=(right_x >> 16);
5699 difX=(right_u-posX)/num;
5700 difY=(right_v-posY)/num;
5707 difR=(right_R-cR1)/num;
5708 difG=(right_G-cG1)/num;
5709 difB=(right_B-cB1)/num;
5715 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
5716 xmax--;if(drawW<xmax) xmax=drawW;
5718 for(j=xmin;j<xmax;j+=2)
5721 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(XAdjust>>1)];
5722 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
5723 XAdjust=((posX+difX)>>16);
5724 tC2 = psxVub[(((posY+difY)>>5)&(int32_t)0xFFFFF800)+YAdjust+
5726 tC2=(tC2>>((XAdjust&1)<<2))&0xf;
5728 GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
5729 GETLE16(&psxVuw[clutP+tC1])|
5730 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16,
5731 (cB1>>16)|((cB1+difB)&0xff0000),
5732 (cG1>>16)|((cG1+difG)&0xff0000),
5733 (cR1>>16)|((cR1+difR)&0xff0000));
5743 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+
5745 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
5747 GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
5748 GETLE16(&psxVuw[clutP+tC1]),
5749 (cB1>>16),(cG1>>16),(cR1>>16));
5752 if(NextRow_GT4()) return;
5759 for (i=ymin;i<=ymax;i++)
5761 xmin=(left_x >> 16);
5762 xmax=(right_x >> 16);
5771 difX=(right_u-posX)/num;
5772 difY=(right_v-posY)/num;
5779 difR=(right_R-cR1)/num;
5780 difG=(right_G-cG1)/num;
5781 difB=(right_B-cB1)/num;
5787 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
5788 xmax--;if(drawW<xmax) xmax=drawW;
5790 for(j=xmin;j<=xmax;j++)
5793 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+
5795 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
5797 GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
5798 GETLE16(&psxVuw[clutP+tC1]),
5799 (cB1>>16),(cG1>>16),(cR1>>16));
5801 GetTextureTransColGX(&psxVuw[(i<<10)+j],
5802 GETLE16(&psxVuw[clutP+tC1]),
5803 (cB1>>16),(cG1>>16),(cR1>>16));
5811 if(NextRow_GT4()) return;
5815 ////////////////////////////////////////////////////////////////////////
5817 static void drawPoly4TGEx4_TW(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
5818 short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
5819 short clX, short clY,
5820 int32_t col1, int32_t col2, int32_t col3, int32_t col4)
5822 drawPoly3TGEx4_TW(x2,y2,x3,y3,x4,y4,
5823 tx2,ty2,tx3,ty3,tx4,ty4,
5827 drawPoly3TGEx4_TW(x1,y1,x2,y2,x4,y4,
5828 tx1,ty1,tx2,ty2,tx4,ty4,
5833 ////////////////////////////////////////////////////////////////////////
5834 // POLY 3/4 G-SHADED TEX PAL8
5835 ////////////////////////////////////////////////////////////////////////
5837 static void drawPoly3TGEx8(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short clX, short clY,int32_t col1, int32_t col2, int32_t col3)
5839 int i,j,xmin,xmax,ymin,ymax;
5840 int32_t cR1,cG1,cB1;
5841 int32_t difR,difB,difG,difR2,difB2,difG2;
5842 int32_t difX, difY,difX2, difY2;
5843 int32_t posX,posY,YAdjust,clutP;
5846 if(x1>drawW && x2>drawW && x3>drawW) return;
5847 if(y1>drawH && y2>drawH && y3>drawH) return;
5848 if(x1<drawX && x2<drawX && x3<drawX) return;
5849 if(y1<drawY && y2<drawY && y3<drawY) return;
5850 if(drawY>=drawH) return;
5851 if(drawX>=drawW) return;
5853 if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
5857 for(ymin=Ymin;ymin<drawY;ymin++)
5858 if(NextRow_GT()) return;
5860 clutP=(clY<<10)+clX;
5862 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
5870 difX=delta_right_u;difX2=difX<<1;
5871 difY=delta_right_v;difY2=difY<<1;
5875 if(!bCheckMask && !DrawSemiTrans && !iDither)
5877 for (i=ymin;i<=ymax;i++)
5879 xmin=(left_x >> 16);
5880 xmax=(right_x >> 16)-1; // !!!!!!!!!!!!!
5881 if(drawW<xmax) xmax=drawW;
5892 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
5894 for(j=xmin;j<xmax;j+=2)
5896 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+((posX>>16))];
5897 tC2 = psxVub[(((posY+difY)>>5)&(int32_t)0xFFFFF800)+YAdjust+
5898 (((posX+difX)>>16))];
5899 GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
5900 GETLE16(&psxVuw[clutP+tC1])|
5901 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16,
5902 (cB1>>16)|((cB1+difB)&0xff0000),
5903 (cG1>>16)|((cG1+difG)&0xff0000),
5904 (cR1>>16)|((cR1+difR)&0xff0000));
5913 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+((posX>>16))];
5914 GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
5915 GETLE16(&psxVuw[clutP+tC1]),
5916 (cB1>>16),(cG1>>16),(cR1>>16));
5929 for (i=ymin;i<=ymax;i++)
5931 xmin=(left_x >> 16);
5932 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!!!!!!
5933 if(drawW<xmax) xmax=drawW;
5944 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
5946 for(j=xmin;j<=xmax;j++)
5948 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+((posX>>16))];
5950 GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
5951 GETLE16(&psxVuw[clutP+tC1]),
5952 (cB1>>16),(cG1>>16),(cR1>>16));
5954 GetTextureTransColGX(&psxVuw[(i<<10)+j],
5955 GETLE16(&psxVuw[clutP+tC1]),
5956 (cB1>>16),(cG1>>16),(cR1>>16));
5971 ////////////////////////////////////////////////////////////////////////
5973 static void drawPoly3TGEx8_IL(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short clX, short clY,int32_t col1, int32_t col2, int32_t col3)
5975 int i,j,xmin,xmax,ymin,ymax,n_xi,n_yi,TXV,TXU;
5976 int32_t cR1,cG1,cB1;
5977 int32_t difR,difB,difG,difR2,difB2,difG2;
5978 int32_t difX, difY,difX2, difY2;
5979 int32_t posX,posY,YAdjust,clutP;
5982 if(x1>drawW && x2>drawW && x3>drawW) return;
5983 if(y1>drawH && y2>drawH && y3>drawH) return;
5984 if(x1<drawX && x2<drawX && x3<drawX) return;
5985 if(y1<drawY && y2<drawY && y3<drawY) return;
5986 if(drawY>=drawH) return;
5987 if(drawX>=drawW) return;
5989 if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
5993 for(ymin=Ymin;ymin<drawY;ymin++)
5994 if(NextRow_GT()) return;
5996 clutP=(clY<<10)+clX;
5998 YAdjust=(GlobalTextAddrY<<10)+GlobalTextAddrX;
6006 difX=delta_right_u;difX2=difX<<1;
6007 difY=delta_right_v;difY2=difY<<1;
6011 if(!bCheckMask && !DrawSemiTrans && !iDither)
6013 for (i=ymin;i<=ymax;i++)
6015 xmin=(left_x >> 16);
6016 xmax=(right_x >> 16)-1; // !!!!!!!!!!!!!
6017 if(drawW<xmax) xmax=drawW;
6028 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
6030 for(j=xmin;j<xmax;j+=2)
6034 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
6035 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
6037 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
6039 TXU=(posX+difX)>>16;
6040 TXV=(posY+difY)>>16;
6041 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
6042 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
6044 tC2= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
6046 GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
6047 GETLE16(&psxVuw[clutP+tC1])|
6048 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16,
6049 (cB1>>16)|((cB1+difB)&0xff0000),
6050 (cG1>>16)|((cG1+difG)&0xff0000),
6051 (cR1>>16)|((cR1+difR)&0xff0000));
6062 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
6063 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
6065 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
6067 GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
6068 GETLE16(&psxVuw[clutP+tC1]),
6069 (cB1>>16),(cG1>>16),(cR1>>16));
6082 for (i=ymin;i<=ymax;i++)
6084 xmin=(left_x >> 16);
6085 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!!!!!!
6086 if(drawW<xmax) xmax=drawW;
6097 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
6099 for(j=xmin;j<=xmax;j++)
6103 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
6104 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
6106 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
6109 GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
6110 GETLE16(&psxVuw[clutP+tC1]),
6111 (cB1>>16),(cG1>>16),(cR1>>16));
6113 GetTextureTransColGX(&psxVuw[(i<<10)+j],
6114 GETLE16(&psxVuw[clutP+tC1]),
6115 (cB1>>16),(cG1>>16),(cR1>>16));
6130 ////////////////////////////////////////////////////////////////////////
6132 static void drawPoly3TGEx8_TW(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short clX, short clY,int32_t col1, int32_t col2, int32_t col3)
6134 int i,j,xmin,xmax,ymin,ymax;
6135 int32_t cR1,cG1,cB1;
6136 int32_t difR,difB,difG,difR2,difB2,difG2;
6137 int32_t difX, difY,difX2, difY2;
6138 int32_t posX,posY,YAdjust,clutP;
6141 if(x1>drawW && x2>drawW && x3>drawW) return;
6142 if(y1>drawH && y2>drawH && y3>drawH) return;
6143 if(x1<drawX && x2<drawX && x3<drawX) return;
6144 if(y1<drawY && y2<drawY && y3<drawY) return;
6145 if(drawY>=drawH) return;
6146 if(drawX>=drawW) return;
6148 if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
6152 for(ymin=Ymin;ymin<drawY;ymin++)
6153 if(NextRow_GT()) return;
6155 clutP=(clY<<10)+clX;
6157 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
6158 YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0);
6166 difX=delta_right_u;difX2=difX<<1;
6167 difY=delta_right_v;difY2=difY<<1;
6171 if(!bCheckMask && !DrawSemiTrans && !iDither)
6173 for (i=ymin;i<=ymax;i++)
6175 xmin=(left_x >> 16);
6176 xmax=(right_x >> 16)-1; // !!!!!!!!!!!!!
6177 if(drawW<xmax) xmax=drawW;
6188 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
6190 for(j=xmin;j<xmax;j+=2)
6192 tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
6193 YAdjust+((posX>>16)%TWin.Position.x1)];
6194 tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
6195 YAdjust+(((posX+difX)>>16)%TWin.Position.x1)];
6197 GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
6198 GETLE16(&psxVuw[clutP+tC1])|
6199 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16,
6200 (cB1>>16)|((cB1+difB)&0xff0000),
6201 (cG1>>16)|((cG1+difG)&0xff0000),
6202 (cR1>>16)|((cR1+difR)&0xff0000));
6211 tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
6212 YAdjust+((posX>>16)%TWin.Position.x1)];
6213 GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
6214 GETLE16(&psxVuw[clutP+tC1]),
6215 (cB1>>16),(cG1>>16),(cR1>>16));
6228 for (i=ymin;i<=ymax;i++)
6230 xmin=(left_x >> 16);
6231 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!!!!!!
6232 if(drawW<xmax) xmax=drawW;
6243 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
6245 for(j=xmin;j<=xmax;j++)
6247 tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
6248 YAdjust+((posX>>16)%TWin.Position.x1)];
6250 GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
6251 GETLE16(&psxVuw[clutP+tC1]),
6252 (cB1>>16),(cG1>>16),(cR1>>16));
6254 GetTextureTransColGX(&psxVuw[(i<<10)+j],
6255 GETLE16(&psxVuw[clutP+tC1]),
6256 (cB1>>16),(cG1>>16),(cR1>>16));
6271 ////////////////////////////////////////////////////////////////////////
6273 // note: two g-shaded tris: small texture distortions can happen
6275 static void drawPoly4TGEx8_TRI_IL(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
6276 short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
6277 short clX, short clY,
6278 int32_t col1, int32_t col2, int32_t col3, int32_t col4)
6280 drawPoly3TGEx8_IL(x2,y2,x3,y3,x4,y4,
6281 tx2,ty2,tx3,ty3,tx4,ty4,
6284 drawPoly3TGEx8_IL(x1,y1,x2,y2,x4,y4,
6285 tx1,ty1,tx2,ty2,tx4,ty4,
6292 static void drawPoly4TGEx8_TRI(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
6293 short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
6294 short clX, short clY,
6295 int32_t col1, int32_t col2, int32_t col3, int32_t col4)
6297 drawPoly3TGEx8(x2,y2,x3,y3,x4,y4,
6298 tx2,ty2,tx3,ty3,tx4,ty4,
6301 drawPoly3TGEx8(x1,y1,x2,y2,x4,y4,
6302 tx1,ty1,tx2,ty2,tx4,ty4,
6309 static void drawPoly4TGEx8(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
6310 short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
6311 short clX, short clY,
6312 int32_t col1, int32_t col2, int32_t col4, int32_t col3)
6315 int32_t i,j,xmin,xmax,ymin,ymax;
6316 int32_t cR1,cG1,cB1;
6317 int32_t difR,difB,difG,difR2,difB2,difG2;
6318 int32_t difX, difY, difX2, difY2;
6319 int32_t posX,posY,YAdjust,clutP;
6322 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
6323 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
6324 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
6325 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
6326 if(drawY>=drawH) return;
6327 if(drawX>=drawW) return;
6329 if(!SetupSections_GT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4,col1,col2,col3,col4)) return;
6333 for(ymin=Ymin;ymin<drawY;ymin++)
6334 if(NextRow_GT4()) return;
6336 clutP=(clY<<10)+clX;
6338 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
6342 if(!bCheckMask && !DrawSemiTrans && !iDither)
6344 for (i=ymin;i<=ymax;i++)
6346 xmin=(left_x >> 16);
6347 xmax=(right_x >> 16);
6356 difX=(right_u-posX)/num;
6357 difY=(right_v-posY)/num;
6364 difR=(right_R-cR1)/num;
6365 difG=(right_G-cG1)/num;
6366 difB=(right_B-cB1)/num;
6372 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
6373 xmax--;if(drawW<xmax) xmax=drawW;
6375 for(j=xmin;j<xmax;j+=2)
6377 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(posX>>16)];
6378 tC2 = psxVub[(((posY+difY)>>5)&(int32_t)0xFFFFF800)+YAdjust+
6381 GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
6382 GETLE16(&psxVuw[clutP+tC1])|
6383 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16,
6384 (cB1>>16)|((cB1+difB)&0xff0000),
6385 (cG1>>16)|((cG1+difG)&0xff0000),
6386 (cR1>>16)|((cR1+difR)&0xff0000));
6395 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(posX>>16)];
6396 GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
6397 GETLE16(&psxVuw[clutP+tC1]),
6398 (cB1>>16),(cG1>>16),(cR1>>16));
6401 if(NextRow_GT4()) return;
6408 for (i=ymin;i<=ymax;i++)
6410 xmin=(left_x >> 16);
6411 xmax=(right_x >> 16);
6420 difX=(right_u-posX)/num;
6421 difY=(right_v-posY)/num;
6428 difR=(right_R-cR1)/num;
6429 difG=(right_G-cG1)/num;
6430 difB=(right_B-cB1)/num;
6436 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
6437 xmax--;if(drawW<xmax) xmax=drawW;
6439 for(j=xmin;j<=xmax;j++)
6441 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(posX>>16)];
6443 GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
6444 GETLE16(&psxVuw[clutP+tC1]),
6445 (cB1>>16),(cG1>>16),(cR1>>16));
6447 GetTextureTransColGX(&psxVuw[(i<<10)+j],
6448 GETLE16(&psxVuw[clutP+tC1]),
6449 (cB1>>16),(cG1>>16),(cR1>>16));
6457 if(NextRow_GT4()) return;
6461 ////////////////////////////////////////////////////////////////////////
6463 static void drawPoly4TGEx8_TW(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
6464 short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
6465 short clX, short clY,
6466 int32_t col1, int32_t col2, int32_t col3, int32_t col4)
6468 drawPoly3TGEx8_TW(x2,y2,x3,y3,x4,y4,
6469 tx2,ty2,tx3,ty3,tx4,ty4,
6472 drawPoly3TGEx8_TW(x1,y1,x2,y2,x4,y4,
6473 tx1,ty1,tx2,ty2,tx4,ty4,
6478 ////////////////////////////////////////////////////////////////////////
6479 // POLY 3 G-SHADED TEX 15 BIT
6480 ////////////////////////////////////////////////////////////////////////
6482 static void drawPoly3TGD(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3,int32_t col1, int32_t col2, int32_t col3)
6484 int i,j,xmin,xmax,ymin,ymax;
6485 int32_t cR1,cG1,cB1;
6486 int32_t difR,difB,difG,difR2,difB2,difG2;
6487 int32_t difX, difY,difX2, difY2;
6490 if(x1>drawW && x2>drawW && x3>drawW) return;
6491 if(y1>drawH && y2>drawH && y3>drawH) return;
6492 if(x1<drawX && x2<drawX && x3<drawX) return;
6493 if(y1<drawY && y2<drawY && y3<drawY) return;
6494 if(drawY>=drawH) return;
6495 if(drawX>=drawW) return;
6497 if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
6501 for(ymin=Ymin;ymin<drawY;ymin++)
6502 if(NextRow_GT()) return;
6510 difX=delta_right_u;difX2=difX<<1;
6511 difY=delta_right_v;difY2=difY<<1;
6515 if(!bCheckMask && !DrawSemiTrans && !iDither)
6517 for (i=ymin;i<=ymax;i++)
6519 xmin=(left_x >> 16);
6520 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!!!
6521 if(drawW<xmax) xmax=drawW;
6532 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
6534 for(j=xmin;j<xmax;j+=2)
6536 GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
6537 (((int32_t)GETLE16(&psxVuw[((((posY+difY)>>16)+GlobalTextAddrY)<<10)+((posX+difX)>>16)+GlobalTextAddrX]))<<16)|
6538 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+((posX)>>16)+GlobalTextAddrX]),
6539 (cB1>>16)|((cB1+difB)&0xff0000),
6540 (cG1>>16)|((cG1+difG)&0xff0000),
6541 (cR1>>16)|((cR1+difR)&0xff0000));
6549 GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
6550 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]),
6551 (cB1>>16),(cG1>>16),(cR1>>16));
6563 for (i=ymin;i<=ymax;i++)
6565 xmin=(left_x >> 16);
6566 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!
6567 if(drawW<xmax) xmax=drawW;
6578 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
6580 for(j=xmin;j<=xmax;j++)
6583 GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
6584 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]),
6585 (cB1>>16),(cG1>>16),(cR1>>16));
6587 GetTextureTransColGX(&psxVuw[(i<<10)+j],
6588 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]),
6589 (cB1>>16),(cG1>>16),(cR1>>16));
6604 ////////////////////////////////////////////////////////////////////////
6606 static void drawPoly3TGD_TW(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3,int32_t col1, int32_t col2, int32_t col3)
6608 int i,j,xmin,xmax,ymin,ymax;
6609 int32_t cR1,cG1,cB1;
6610 int32_t difR,difB,difG,difR2,difB2,difG2;
6611 int32_t difX, difY,difX2, difY2;
6614 if(x1>drawW && x2>drawW && x3>drawW) return;
6615 if(y1>drawH && y2>drawH && y3>drawH) return;
6616 if(x1<drawX && x2<drawX && x3<drawX) return;
6617 if(y1<drawY && y2<drawY && y3<drawY) return;
6618 if(drawY>=drawH) return;
6619 if(drawX>=drawW) return;
6621 if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
6625 for(ymin=Ymin;ymin<drawY;ymin++)
6626 if(NextRow_GT()) return;
6634 difX=delta_right_u;difX2=difX<<1;
6635 difY=delta_right_v;difY2=difY<<1;
6639 if(!bCheckMask && !DrawSemiTrans && !iDither)
6641 for (i=ymin;i<=ymax;i++)
6643 xmin=(left_x >> 16);
6644 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!!!
6645 if(drawW<xmax) xmax=drawW;
6656 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
6658 for(j=xmin;j<xmax;j+=2)
6660 GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
6661 (((int32_t)GETLE16(&psxVuw[(((((posY+difY)>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
6662 (((posX+difX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]))<<16)|
6663 GETLE16(&psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
6664 (((posX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]),
6665 (cB1>>16)|((cB1+difB)&0xff0000),
6666 (cG1>>16)|((cG1+difG)&0xff0000),
6667 (cR1>>16)|((cR1+difR)&0xff0000));
6675 GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
6676 GETLE16(&psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
6677 ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]),
6678 (cB1>>16),(cG1>>16),(cR1>>16));
6690 for (i=ymin;i<=ymax;i++)
6692 xmin=(left_x >> 16);
6693 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!
6694 if(drawW<xmax) xmax=drawW;
6705 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
6707 for(j=xmin;j<=xmax;j++)
6710 GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
6711 GETLE16(&psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
6712 ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]),
6713 (cB1>>16),(cG1>>16),(cR1>>16));
6715 GetTextureTransColGX(&psxVuw[(i<<10)+j],
6716 GETLE16(&psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
6717 ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]),
6718 (cB1>>16),(cG1>>16),(cR1>>16));
6733 ////////////////////////////////////////////////////////////////////////
6735 // note: two g-shaded tris: small texture distortions can happen
6739 static void drawPoly4TGD_TRI(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4, int32_t col1, int32_t col2, int32_t col3, int32_t col4)
6741 drawPoly3TGD(x2,y2,x3,y3,x4,y4,
6742 tx2,ty2,tx3,ty3,tx4,ty4,
6744 drawPoly3TGD(x1,y1,x2,y2,x4,y4,
6745 tx1,ty1,tx2,ty2,tx4,ty4,
6751 static void drawPoly4TGD(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4, int32_t col1, int32_t col2, int32_t col4, int32_t col3)
6754 int32_t i,j,xmin,xmax,ymin,ymax;
6755 int32_t cR1,cG1,cB1;
6756 int32_t difR,difB,difG,difR2,difB2,difG2;
6757 int32_t difX, difY, difX2, difY2;
6760 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
6761 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
6762 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
6763 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
6764 if(drawY>=drawH) return;
6765 if(drawX>=drawW) return;
6767 if(!SetupSections_GT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4,col1,col2,col3,col4)) return;
6771 for(ymin=Ymin;ymin<drawY;ymin++)
6772 if(NextRow_GT4()) return;
6776 if(!bCheckMask && !DrawSemiTrans && !iDither)
6778 for (i=ymin;i<=ymax;i++)
6780 xmin=(left_x >> 16);
6781 xmax=(right_x >> 16);
6790 difX=(right_u-posX)/num;
6791 difY=(right_v-posY)/num;
6798 difR=(right_R-cR1)/num;
6799 difG=(right_G-cG1)/num;
6800 difB=(right_B-cB1)/num;
6806 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
6807 xmax--;if(drawW<xmax) xmax=drawW;
6809 for(j=xmin;j<xmax;j+=2)
6811 GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
6812 (((int32_t)GETLE16(&psxVuw[((((posY+difY)>>16)+GlobalTextAddrY)<<10)+((posX+difX)>>16)+GlobalTextAddrX]))<<16)|
6813 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+((posX)>>16)+GlobalTextAddrX]),
6814 (cB1>>16)|((cB1+difB)&0xff0000),
6815 (cG1>>16)|((cG1+difG)&0xff0000),
6816 (cR1>>16)|((cR1+difR)&0xff0000));
6824 GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
6825 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]),
6826 (cB1>>16),(cG1>>16),(cR1>>16));
6828 if(NextRow_GT4()) return;
6835 for (i=ymin;i<=ymax;i++)
6837 xmin=(left_x >> 16);
6838 xmax=(right_x >> 16);
6847 difX=(right_u-posX)/num;
6848 difY=(right_v-posY)/num;
6855 difR=(right_R-cR1)/num;
6856 difG=(right_G-cG1)/num;
6857 difB=(right_B-cB1)/num;
6863 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
6864 xmax--;if(drawW<xmax) xmax=drawW;
6866 for(j=xmin;j<=xmax;j++)
6869 GetTextureTransColGX(&psxVuw[(i<<10)+j],
6870 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]),
6871 (cB1>>16),(cG1>>16),(cR1>>16));
6873 GetTextureTransColGX(&psxVuw[(i<<10)+j],
6874 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]),
6875 (cB1>>16),(cG1>>16),(cR1>>16));
6883 if(NextRow_GT4()) return;
6887 ////////////////////////////////////////////////////////////////////////
6889 static void drawPoly4TGD_TW(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4, int32_t col1, int32_t col2, int32_t col3, int32_t col4)
6891 drawPoly3TGD_TW(x2,y2,x3,y3,x4,y4,
6892 tx2,ty2,tx3,ty3,tx4,ty4,
6894 drawPoly3TGD_TW(x1,y1,x2,y2,x4,y4,
6895 tx1,ty1,tx2,ty2,tx4,ty4,
6899 ////////////////////////////////////////////////////////////////////////
6900 ////////////////////////////////////////////////////////////////////////
6901 ////////////////////////////////////////////////////////////////////////
6902 ////////////////////////////////////////////////////////////////////////
6903 ////////////////////////////////////////////////////////////////////////
6904 ////////////////////////////////////////////////////////////////////////
6908 // no real rect test, but it does its job the way I need it
6909 static inline BOOL IsNoRect(void)
6911 if(lx0==lx1 && lx2==lx3) return FALSE;
6912 if(lx0==lx2 && lx1==lx3) return FALSE;
6913 if(lx0==lx3 && lx1==lx2) return FALSE;
6919 static inline BOOL IsNoRect(void)
6921 if(!(dwActFixes&0x200)) return FALSE;
6925 if(lx1==lx3 && ly3==ly2 && lx2==lx0) return FALSE;
6926 if(lx1==lx2 && ly2==ly3 && lx3==lx0) return FALSE;
6932 if(lx2==lx3 && ly3==ly1 && lx1==lx0) return FALSE;
6933 if(lx2==lx1 && ly1==ly3 && lx3==lx0) return FALSE;
6939 if(lx3==lx2 && ly2==ly1 && lx1==lx0) return FALSE;
6940 if(lx3==lx1 && ly1==ly2 && lx2==lx0) return FALSE;
6946 ////////////////////////////////////////////////////////////////////////
6948 static void drawPoly3FT(unsigned char * baseAddr)
6950 uint32_t *gpuData = ((uint32_t *) baseAddr);
6952 if(GlobalTextIL && GlobalTextTP<2)
6955 drawPoly3TEx4_IL(lx0,ly0,lx1,ly1,lx2,ly2,
6956 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[4]) & 0x000000ff), ((GETLE32(&gpuData[4])>>8) & 0x000000ff),(GETLE32(&gpuData[6]) & 0x000000ff), ((GETLE32(&gpuData[6])>>8) & 0x000000ff),
6957 ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511));
6959 drawPoly3TEx8_IL(lx0,ly0,lx1,ly1,lx2,ly2,
6960 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[4]) & 0x000000ff), ((GETLE32(&gpuData[4])>>8) & 0x000000ff),(GETLE32(&gpuData[6]) & 0x000000ff), ((GETLE32(&gpuData[6])>>8) & 0x000000ff),
6961 ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511));
6965 if(!bUsingTWin && !(dwActFixes&0x100))
6967 switch(GlobalTextTP) // depending on texture mode
6970 drawPoly3TEx4(lx0,ly0,lx1,ly1,lx2,ly2,
6971 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[4]) & 0x000000ff), ((GETLE32(&gpuData[4])>>8) & 0x000000ff),(GETLE32(&gpuData[6]) & 0x000000ff), ((GETLE32(&gpuData[6])>>8) & 0x000000ff),
6972 ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511));
6975 drawPoly3TEx8(lx0,ly0,lx1,ly1,lx2,ly2,
6976 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[4]) & 0x000000ff), ((GETLE32(&gpuData[4])>>8) & 0x000000ff),(GETLE32(&gpuData[6]) & 0x000000ff), ((GETLE32(&gpuData[6])>>8) & 0x000000ff),
6977 ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511));
6980 drawPoly3TD(lx0,ly0,lx1,ly1,lx2,ly2,(GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[4]) & 0x000000ff), ((GETLE32(&gpuData[4])>>8) & 0x000000ff),(GETLE32(&gpuData[6]) & 0x000000ff), ((GETLE32(&gpuData[6])>>8) & 0x000000ff));
6986 switch(GlobalTextTP) // depending on texture mode
6989 drawPoly3TEx4_TW(lx0,ly0,lx1,ly1,lx2,ly2,
6990 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[4]) & 0x000000ff), ((GETLE32(&gpuData[4])>>8) & 0x000000ff),(GETLE32(&gpuData[6]) & 0x000000ff), ((GETLE32(&gpuData[6])>>8) & 0x000000ff),
6991 ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511));
6994 drawPoly3TEx8_TW(lx0,ly0,lx1,ly1,lx2,ly2,
6995 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[4]) & 0x000000ff), ((GETLE32(&gpuData[4])>>8) & 0x000000ff),(GETLE32(&gpuData[6]) & 0x000000ff), ((GETLE32(&gpuData[6])>>8) & 0x000000ff),
6996 ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511));
6999 drawPoly3TD_TW(lx0,ly0,lx1,ly1,lx2,ly2,(GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[4]) & 0x000000ff), ((GETLE32(&gpuData[4])>>8) & 0x000000ff),(GETLE32(&gpuData[6]) & 0x000000ff), ((GETLE32(&gpuData[6])>>8) & 0x000000ff));
7004 ////////////////////////////////////////////////////////////////////////
7006 static void drawPoly4FT(unsigned char * baseAddr)
7008 uint32_t *gpuData = ((uint32_t *) baseAddr);
7010 if(GlobalTextIL && GlobalTextTP<2)
7013 drawPoly4TEx4_IL(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7014 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[4]) & 0x000000ff), ((GETLE32(&gpuData[4])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),(GETLE32(&gpuData[6]) & 0x000000ff), ((GETLE32(&gpuData[6])>>8) & 0x000000ff), ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511));
7016 drawPoly4TEx8_IL(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7017 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[4]) & 0x000000ff), ((GETLE32(&gpuData[4])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),(GETLE32(&gpuData[6]) & 0x000000ff), ((GETLE32(&gpuData[6])>>8) & 0x000000ff), ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511));
7026 switch (GlobalTextTP)
7029 drawPoly4TEx4_TRI(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7030 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[4]) & 0x000000ff), ((GETLE32(&gpuData[4])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),(GETLE32(&gpuData[6]) & 0x000000ff), ((GETLE32(&gpuData[6])>>8) & 0x000000ff), ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511));
7033 drawPoly4TEx8_TRI(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7034 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[4]) & 0x000000ff), ((GETLE32(&gpuData[4])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),(GETLE32(&gpuData[6]) & 0x000000ff), ((GETLE32(&gpuData[6])>>8) & 0x000000ff), ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511));
7037 drawPoly4TD_TRI(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,(GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[4]) & 0x000000ff), ((GETLE32(&gpuData[4])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),(GETLE32(&gpuData[6]) & 0x000000ff), ((GETLE32(&gpuData[6])>>8) & 0x000000ff));
7044 switch (GlobalTextTP)
7046 case 0: // grandia investigations needed
7047 drawPoly4TEx4(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7048 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[4]) & 0x000000ff), ((GETLE32(&gpuData[4])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),(GETLE32(&gpuData[6]) & 0x000000ff), ((GETLE32(&gpuData[6])>>8) & 0x000000ff), ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511));
7051 drawPoly4TEx8(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7052 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[4]) & 0x000000ff), ((GETLE32(&gpuData[4])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),(GETLE32(&gpuData[6]) & 0x000000ff), ((GETLE32(&gpuData[6])>>8) & 0x000000ff), ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511));
7055 drawPoly4TD(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,(GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[4]) & 0x000000ff), ((GETLE32(&gpuData[4])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),(GETLE32(&gpuData[6]) & 0x000000ff), ((GETLE32(&gpuData[6])>>8) & 0x000000ff));
7061 switch (GlobalTextTP)
7064 drawPoly4TEx4_TW(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7065 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[4]) & 0x000000ff), ((GETLE32(&gpuData[4])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),(GETLE32(&gpuData[6]) & 0x000000ff), ((GETLE32(&gpuData[6])>>8) & 0x000000ff), ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511));
7068 drawPoly4TEx8_TW(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7069 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[4]) & 0x000000ff), ((GETLE32(&gpuData[4])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),(GETLE32(&gpuData[6]) & 0x000000ff), ((GETLE32(&gpuData[6])>>8) & 0x000000ff), ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511));
7072 drawPoly4TD_TW(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,(GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[4]) & 0x000000ff), ((GETLE32(&gpuData[4])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),(GETLE32(&gpuData[6]) & 0x000000ff), ((GETLE32(&gpuData[6])>>8) & 0x000000ff));
7077 ////////////////////////////////////////////////////////////////////////
7079 static void drawPoly3GT(unsigned char * baseAddr)
7081 uint32_t *gpuData = ((uint32_t *) baseAddr);
7083 if(GlobalTextIL && GlobalTextTP<2)
7086 drawPoly3TGEx4_IL(lx0,ly0,lx1,ly1,lx2,ly2,
7087 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[5]) & 0x000000ff), ((GETLE32(&gpuData[5])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),
7088 ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511),
7089 GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]));
7091 drawPoly3TGEx8_IL(lx0,ly0,lx1,ly1,lx2,ly2,
7092 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[5]) & 0x000000ff), ((GETLE32(&gpuData[5])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),
7093 ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511),
7094 GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]));
7100 switch (GlobalTextTP)
7103 drawPoly3TGEx4(lx0,ly0,lx1,ly1,lx2,ly2,
7104 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[5]) & 0x000000ff), ((GETLE32(&gpuData[5])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),
7105 ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511),
7106 GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]));
7109 drawPoly3TGEx8(lx0,ly0,lx1,ly1,lx2,ly2,
7110 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[5]) & 0x000000ff), ((GETLE32(&gpuData[5])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),
7111 ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511),
7112 GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]));
7115 drawPoly3TGD(lx0,ly0,lx1,ly1,lx2,ly2,(GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[5]) & 0x000000ff), ((GETLE32(&gpuData[5])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]));
7121 switch(GlobalTextTP)
7124 drawPoly3TGEx4_TW(lx0,ly0,lx1,ly1,lx2,ly2,
7125 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[5]) & 0x000000ff), ((GETLE32(&gpuData[5])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),
7126 ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511),
7127 GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]));
7130 drawPoly3TGEx8_TW(lx0,ly0,lx1,ly1,lx2,ly2,
7131 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[5]) & 0x000000ff), ((GETLE32(&gpuData[5])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),
7132 ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511),
7133 GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]));
7136 drawPoly3TGD_TW(lx0,ly0,lx1,ly1,lx2,ly2,(GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[5]) & 0x000000ff), ((GETLE32(&gpuData[5])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]));
7141 ////////////////////////////////////////////////////////////////////////
7143 static void drawPoly4GT(unsigned char *baseAddr)
7145 uint32_t *gpuData = ((uint32_t *) baseAddr);
7147 if(GlobalTextIL && GlobalTextTP<2)
7150 drawPoly4TGEx4_TRI_IL(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7151 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[5]) & 0x000000ff), ((GETLE32(&gpuData[5])>>8) & 0x000000ff),(GETLE32(&gpuData[11]) & 0x000000ff), ((GETLE32(&gpuData[11])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),
7152 ((GETLE32(&gpuData[2])>>12) & 0x3f0),((GETLE32(&gpuData[2])>>22) & 511),
7153 GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]),GETLE32(&gpuData[9]));
7155 drawPoly4TGEx8_TRI_IL(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7156 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[5]) & 0x000000ff), ((GETLE32(&gpuData[5])>>8) & 0x000000ff),(GETLE32(&gpuData[11]) & 0x000000ff), ((GETLE32(&gpuData[11])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),
7157 ((GETLE32(&gpuData[2])>>12) & 0x3f0),((GETLE32(&gpuData[2])>>22) & 511),
7158 GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]),GETLE32(&gpuData[9]));
7167 switch (GlobalTextTP)
7170 drawPoly4TGEx4_TRI(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7171 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[5]) & 0x000000ff), ((GETLE32(&gpuData[5])>>8) & 0x000000ff),(GETLE32(&gpuData[11]) & 0x000000ff), ((GETLE32(&gpuData[11])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),
7172 ((GETLE32(&gpuData[2])>>12) & 0x3f0),((GETLE32(&gpuData[2])>>22) & 511),
7173 GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]),GETLE32(&gpuData[9]));
7177 drawPoly4TGEx8_TRI(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7178 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[5]) & 0x000000ff), ((GETLE32(&gpuData[5])>>8) & 0x000000ff),(GETLE32(&gpuData[11]) & 0x000000ff), ((GETLE32(&gpuData[11])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),
7179 ((GETLE32(&gpuData[2])>>12) & 0x3f0),((GETLE32(&gpuData[2])>>22) & 511),
7180 GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]),GETLE32(&gpuData[9]));
7183 drawPoly4TGD_TRI(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,(GETLE32(&gpuData[2]) & 0x000000ff),((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[5]) & 0x000000ff), ((GETLE32(&gpuData[5])>>8) & 0x000000ff),(GETLE32(&gpuData[11]) & 0x000000ff), ((GETLE32(&gpuData[11])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]),GETLE32(&gpuData[9]));
7190 switch (GlobalTextTP)
7193 drawPoly4TGEx4(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7194 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[5]) & 0x000000ff), ((GETLE32(&gpuData[5])>>8) & 0x000000ff),(GETLE32(&gpuData[11]) & 0x000000ff), ((GETLE32(&gpuData[11])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),
7195 ((GETLE32(&gpuData[2])>>12) & 0x3f0),((GETLE32(&gpuData[2])>>22) & 511),
7196 GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]),GETLE32(&gpuData[9]));
7200 drawPoly4TGEx8(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7201 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[5]) & 0x000000ff), ((GETLE32(&gpuData[5])>>8) & 0x000000ff),(GETLE32(&gpuData[11]) & 0x000000ff), ((GETLE32(&gpuData[11])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),
7202 ((GETLE32(&gpuData[2])>>12) & 0x3f0),((GETLE32(&gpuData[2])>>22) & 511),
7203 GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]),GETLE32(&gpuData[9]));
7206 drawPoly4TGD(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,(GETLE32(&gpuData[2]) & 0x000000ff),((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[5]) & 0x000000ff), ((GETLE32(&gpuData[5])>>8) & 0x000000ff),(GETLE32(&gpuData[11]) & 0x000000ff), ((GETLE32(&gpuData[11])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]),GETLE32(&gpuData[9]));
7212 switch (GlobalTextTP)
7215 drawPoly4TGEx4_TW(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7216 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[5]) & 0x000000ff), ((GETLE32(&gpuData[5])>>8) & 0x000000ff),(GETLE32(&gpuData[11]) & 0x000000ff), ((GETLE32(&gpuData[11])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),
7217 ((GETLE32(&gpuData[2])>>12) & 0x3f0),((GETLE32(&gpuData[2])>>22) & 511),
7218 GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]),GETLE32(&gpuData[9]));
7221 drawPoly4TGEx8_TW(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7222 (GETLE32(&gpuData[2]) & 0x000000ff), ((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[5]) & 0x000000ff), ((GETLE32(&gpuData[5])>>8) & 0x000000ff),(GETLE32(&gpuData[11]) & 0x000000ff), ((GETLE32(&gpuData[11])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),
7223 ((GETLE32(&gpuData[2])>>12) & 0x3f0),((GETLE32(&gpuData[2])>>22) & 511),
7224 GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]),GETLE32(&gpuData[9]));
7227 drawPoly4TGD_TW(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,(GETLE32(&gpuData[2]) & 0x000000ff),((GETLE32(&gpuData[2])>>8) & 0x000000ff), (GETLE32(&gpuData[5]) & 0x000000ff), ((GETLE32(&gpuData[5])>>8) & 0x000000ff),(GETLE32(&gpuData[11]) & 0x000000ff), ((GETLE32(&gpuData[11])>>8) & 0x000000ff),(GETLE32(&gpuData[8]) & 0x000000ff), ((GETLE32(&gpuData[8])>>8) & 0x000000ff),GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]),GETLE32(&gpuData[9]));
7232 ////////////////////////////////////////////////////////////////////////
7234 ////////////////////////////////////////////////////////////////////////
7236 static void DrawSoftwareSpriteTWin(unsigned char * baseAddr,int32_t w,int32_t h)
7238 uint32_t *gpuData = (uint32_t *)baseAddr;
7239 short sx0,sy0,sx1,sy1,sx2,sy2,sx3,sy3;
7240 short tx0,ty0,tx1,ty1,tx2,ty2,tx3,ty3;
7245 sx0=sx3=sx0+PSXDisplay.DrawOffset.x;
7247 sy0=sy1=sy0+PSXDisplay.DrawOffset.y;
7250 tx0=tx3=GETLE32(&gpuData[2])&0xff;
7252 ty0=ty1=(GETLE32(&gpuData[2])>>8)&0xff;
7255 switch (GlobalTextTP)
7258 drawPoly4TEx4_TW_S(sx0,sy0,sx1,sy1,sx2,sy2,sx3,sy3,
7259 tx0,ty0,tx1,ty1,tx2,ty2,tx3,ty3,
7260 ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511));
7263 drawPoly4TEx8_TW_S(sx0,sy0,sx1,sy1,sx2,sy2,sx3,sy3,
7264 tx0,ty0,tx1,ty1,tx2,ty2,tx3,ty3,
7265 ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511));
7268 drawPoly4TD_TW_S(sx0,sy0,sx1,sy1,sx2,sy2,sx3,sy3,
7269 tx0,ty0,tx1,ty1,tx2,ty2,tx3,ty3);
7274 ////////////////////////////////////////////////////////////////////////
7276 static void DrawSoftwareSpriteMirror(unsigned char * baseAddr,int32_t w,int32_t h)
7278 int32_t sprtY,sprtX,sprtW,sprtH,lXDir,lYDir;
7279 int32_t clutY0,clutX0,clutP,textX0,textY0,sprtYa,sprCY,sprCX,sprA;
7281 uint32_t *gpuData = (uint32_t *)baseAddr;
7286 clutY0 = (GETLE32(&gpuData[2])>>22) & 511;
7287 clutX0 = (GETLE32(&gpuData[2])>>12) & 0x3f0;
7288 clutP = (clutY0<<11) + (clutX0<<1);
7289 textY0 = ((GETLE32(&gpuData[2])>>8) & 0x000000ff) + GlobalTextAddrY;
7290 textX0 = (GETLE32(&gpuData[2]) & 0x000000ff);
7292 sprtX+=PSXDisplay.DrawOffset.x;
7293 sprtY+=PSXDisplay.DrawOffset.y;
7307 if((sprtY+sprtH)<drawY) return;
7308 sprtH-=(drawY-sprtY);
7309 textY0+=(drawY-sprtY);
7315 if((sprtX+sprtW)<drawX) return;
7316 sprtW-=(drawX-sprtX);
7317 textX0+=(drawX-sprtX);
7321 if((sprtY+sprtH)>drawH) sprtH=drawH-sprtY+1;
7322 if((sprtX+sprtW)>drawW) sprtW=drawW-sprtX+1;
7324 if(usMirror&0x1000) lXDir=-1; else lXDir=1;
7325 if(usMirror&0x2000) lYDir=-1; else lYDir=1;
7327 switch (GlobalTextTP)
7329 case 0: // texture is 4-bit
7332 textX0=(GlobalTextAddrX<<1)+(textX0>>1);
7334 clutP=(clutY0<<10)+clutX0;
7335 for (sprCY=0;sprCY<sprtH;sprCY++)
7336 for (sprCX=0;sprCX<sprtW;sprCX++)
7338 tC= psxVub[((textY0+(sprCY*lYDir))<<11) + textX0 +(sprCX*lXDir)];
7339 sprA=sprtYa+(sprCY<<10)+sprtX + (sprCX<<1);
7340 GetTextureTransColG_SPR(&psxVuw[sprA],GETLE16(&psxVuw[clutP+((tC>>4)&0xf)]));
7341 GetTextureTransColG_SPR(&psxVuw[sprA+1],GETLE16(&psxVuw[clutP+(tC&0xf)]));
7348 for(sprCY=0;sprCY<sprtH;sprCY++)
7349 for(sprCX=0;sprCX<sprtW;sprCX++)
7351 tC = psxVub[((textY0+(sprCY*lYDir))<<11)+(GlobalTextAddrX<<1) + textX0 + (sprCX*lXDir)] & 0xff;
7352 GetTextureTransColG_SPR(&psxVuw[((sprtY+sprCY)<<10)+sprtX + sprCX],psxVuw[clutP+tC]);
7358 for (sprCY=0;sprCY<sprtH;sprCY++)
7359 for (sprCX=0;sprCX<sprtW;sprCX++)
7361 GetTextureTransColG_SPR(&psxVuw[((sprtY+sprCY)<<10)+sprtX+sprCX],
7362 GETLE16(&psxVuw[((textY0+(sprCY*lYDir))<<10)+GlobalTextAddrX + textX0 +(sprCX*lXDir)]));
7368 ////////////////////////////////////////////////////////////////////////
7370 void DrawSoftwareSprite_IL(unsigned char * baseAddr,short w,short h,int32_t tx,int32_t ty)
7372 int32_t sprtY,sprtX,sprtW,sprtH,tdx,tdy;
7373 uint32_t *gpuData = (uint32_t *)baseAddr;
7380 sprtX+=PSXDisplay.DrawOffset.x;
7381 sprtY+=PSXDisplay.DrawOffset.y;
7383 if(sprtX>drawW) return;
7384 if(sprtY>drawH) return;
7392 // Pete is too lazy to make a faster version ;)
7395 drawPoly4TEx4_IL(sprtX,sprtY,sprtX,sprtH,sprtW,sprtH,sprtW,sprtY,
7396 tx,ty, tx,tdy, tdx,tdy, tdx,ty,
7397 (GETLE32(&gpuData[2])>>12) & 0x3f0, ((GETLE32(&gpuData[2])>>22) & 511));
7401 drawPoly4TEx8_IL(sprtX,sprtY,sprtX,sprtH,sprtW,sprtH,sprtW,sprtY,
7402 tx,ty, tx,tdy, tdx,tdy, tdx,ty,
7403 (GETLE32(&gpuData[2])>>12) & 0x3f0, ((GETLE32(&gpuData[2])>>22) & 511));
7406 ////////////////////////////////////////////////////////////////////////
7408 static void DrawSoftwareSprite(unsigned char * baseAddr,short w,short h,int32_t tx,int32_t ty)
7410 int32_t sprtY,sprtX,sprtW,sprtH;
7411 int32_t clutY0,clutX0,clutP,textX0,textY0,sprtYa,sprCY,sprCX,sprA;
7413 uint32_t *gpuData = (uint32_t *)baseAddr;
7417 if(GlobalTextIL && GlobalTextTP<2)
7418 {DrawSoftwareSprite_IL(baseAddr,w,h,tx,ty);return;}
7424 clutY0 = (GETLE32(&gpuData[2])>>22) & 511;
7425 clutX0 = (GETLE32(&gpuData[2])>>12) & 0x3f0;
7427 clutP = (clutY0<<11) + (clutX0<<1);
7429 textY0 =ty+ GlobalTextAddrY;
7432 sprtX+=PSXDisplay.DrawOffset.x;
7433 sprtY+=PSXDisplay.DrawOffset.y;
7447 if((sprtY+sprtH)<drawY) return;
7448 sprtH-=(drawY-sprtY);
7449 textY0+=(drawY-sprtY);
7455 if((sprtX+sprtW)<drawX) return;
7457 sprtW-=(drawX-sprtX);
7458 textX0+=(drawX-sprtX);
7462 if((sprtY+sprtH)>drawH) sprtH=drawH-sprtY+1;
7463 if((sprtX+sprtW)>drawW) sprtW=drawW-sprtX+1;
7469 switch (GlobalTextTP)
7473 if(textX0&1) {bWS=TRUE;sprtW--;}
7474 if(sprtW&1) bWT=TRUE;
7477 textX0=(GlobalTextAddrX<<1)+(textX0>>1)+(textY0<<11);
7478 sprtYa=(sprtY<<10)+sprtX;
7479 clutP=(clutY0<<10)+clutX0;
7483 if(!bCheckMask && !DrawSemiTrans)
7485 for (sprCY=0;sprCY<sprtH;sprCY++)
7487 sprA=sprtYa+(sprCY<<10);
7488 pV=&psxVub[(sprCY<<11)+textX0];
7493 GetTextureTransColG_S(&psxVuw[sprA++],GETLE16(&psxVuw[clutP+((tC>>4)&0xf)]));
7496 for (sprCX=0;sprCX<sprtW;sprCX++,sprA+=2)
7500 GetTextureTransColG32_S((uint32_t *)&psxVuw[sprA],
7501 (((int32_t)GETLE16(&psxVuw[clutP+((tC>>4)&0xf)]))<<16)|
7502 GETLE16(&psxVuw[clutP+(tC&0x0f)]));
7508 GetTextureTransColG_S(&psxVuw[sprA],GETLE16(&psxVuw[clutP+(tC&0x0f)]));
7516 for (sprCY=0;sprCY<sprtH;sprCY++)
7518 sprA=sprtYa+(sprCY<<10);
7519 pV=&psxVub[(sprCY<<11)+textX0];
7524 GetTextureTransColG_SPR(&psxVuw[sprA++],GETLE16(&psxVuw[clutP+((tC>>4)&0xf)]));
7527 for (sprCX=0;sprCX<sprtW;sprCX++,sprA+=2)
7531 GetTextureTransColG32_SPR((uint32_t *)&psxVuw[sprA],
7532 (((int32_t)GETLE16(&psxVuw[clutP+((tC>>4)&0xf)])<<16))|
7533 GETLE16(&psxVuw[clutP+(tC&0x0f)]));
7539 GetTextureTransColG_SPR(&psxVuw[sprA],GETLE16(&psxVuw[clutP+(tC&0x0f)]));
7546 textX0+=(GlobalTextAddrX<<1) + (textY0<<11);
7550 if(!bCheckMask && !DrawSemiTrans)
7552 for(sprCY=0;sprCY<sprtH;sprCY++)
7554 sprA=((sprtY+sprCY)<<10)+sprtX;
7555 pV=&psxVub[(sprCY<<11)+textX0];
7556 for(sprCX=0;sprCX<sprtW;sprCX+=2,sprA+=2)
7558 tC = *pV++;tC2 = *pV++;
7559 GetTextureTransColG32_S((uint32_t *)&psxVuw[sprA],
7560 (((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16)|
7561 GETLE16(&psxVuw[clutP+tC]));
7564 GetTextureTransColG_S(&psxVuw[sprA],GETLE16(&psxVuw[clutP+(*pV)]));
7571 for(sprCY=0;sprCY<sprtH;sprCY++)
7573 sprA=((sprtY+sprCY)<<10)+sprtX;
7574 pV=&psxVub[(sprCY<<11)+textX0];
7575 for(sprCX=0;sprCX<sprtW;sprCX+=2,sprA+=2)
7577 tC = *pV++;tC2 = *pV++;
7578 GetTextureTransColG32_SPR((uint32_t *)&psxVuw[sprA],
7579 (((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16)|
7580 GETLE16(&psxVuw[clutP+tC]));
7583 GetTextureTransColG_SPR(&psxVuw[sprA],GETLE16(&psxVuw[clutP+(*pV)]));
7589 textX0+=(GlobalTextAddrX) + (textY0<<10);
7594 if(!bCheckMask && !DrawSemiTrans)
7596 for (sprCY=0;sprCY<sprtH;sprCY++)
7598 sprA=((sprtY+sprCY)<<10)+sprtX;
7600 for (sprCX=0;sprCX<sprtW;sprCX+=2,sprA+=2)
7602 GetTextureTransColG32_S((uint32_t *)&psxVuw[sprA],
7603 (((int32_t)GETLE16(&psxVuw[(sprCY<<10) + textX0 + sprCX +1]))<<16)|
7604 GETLE16(&psxVuw[(sprCY<<10) + textX0 + sprCX]));
7607 GetTextureTransColG_S(&psxVuw[sprA],
7608 GETLE16(&psxVuw[(sprCY<<10) + textX0 + sprCX]));
7616 for (sprCY=0;sprCY<sprtH;sprCY++)
7618 sprA=((sprtY+sprCY)<<10)+sprtX;
7620 for (sprCX=0;sprCX<sprtW;sprCX+=2,sprA+=2)
7622 GetTextureTransColG32_SPR((uint32_t *)&psxVuw[sprA],
7623 (((int32_t)GETLE16(&psxVuw[(sprCY<<10) + textX0 + sprCX +1]))<<16)|
7624 GETLE16(&psxVuw[(sprCY<<10) + textX0 + sprCX]));
7627 GetTextureTransColG_SPR(&psxVuw[sprA],
7628 GETLE16(&psxVuw[(sprCY<<10) + textX0 + sprCX]));
7635 ///////////////////////////////////////////////////////////////////////
7637 /////////////////////////////////////////////////////////////////
7638 /////////////////////////////////////////////////////////////////
7639 /////////////////////////////////////////////////////////////////
7641 ////////////////////////////////////////////////////////////////////////
7642 /////////////////////////////////////////////////////////////////
7643 /////////////////////////////////////////////////////////////////
7646 ///////////////////////////////////////////////////////////////////////
7648 static void Line_E_SE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, uint32_t rgb1)
7650 int dx, dy, incrE, incrSE, d;
7651 uint32_t r0, g0, b0, r1, g1, b1;
7654 r0 = (rgb0 & 0x00ff0000);
7655 g0 = (rgb0 & 0x0000ff00) << 8;
7656 b0 = (rgb0 & 0x000000ff) << 16;
7657 r1 = (rgb1 & 0x00ff0000);
7658 g1 = (rgb1 & 0x0000ff00) << 8;
7659 b1 = (rgb1 & 0x000000ff) << 16;
7666 dr = ((int32_t)r1 - (int32_t)r0) / dx;
7667 dg = ((int32_t)g1 - (int32_t)g0) / dx;
7668 db = ((int32_t)b1 - (int32_t)b0) / dx;
7672 dr = ((int32_t)r1 - (int32_t)r0);
7673 dg = ((int32_t)g1 - (int32_t)g0);
7674 db = ((int32_t)b1 - (int32_t)b0);
7677 d = 2*dy - dx; /* Initial value of d */
7678 incrE = 2*dy; /* incr. used for move to E */
7679 incrSE = 2*(dy - dx); /* incr. used for move to SE */
7681 if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
7682 GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
7687 d = d + incrE; /* Choose E */
7691 d = d + incrSE; /* Choose SE */
7700 if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
7701 GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
7705 ///////////////////////////////////////////////////////////////////////
7707 static void Line_S_SE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, uint32_t rgb1)
7709 int dx, dy, incrS, incrSE, d;
7710 uint32_t r0, g0, b0, r1, g1, b1;
7713 r0 = (rgb0 & 0x00ff0000);
7714 g0 = (rgb0 & 0x0000ff00) << 8;
7715 b0 = (rgb0 & 0x000000ff) << 16;
7716 r1 = (rgb1 & 0x00ff0000);
7717 g1 = (rgb1 & 0x0000ff00) << 8;
7718 b1 = (rgb1 & 0x000000ff) << 16;
7725 dr = ((int32_t)r1 - (int32_t)r0) / dy;
7726 dg = ((int32_t)g1 - (int32_t)g0) / dy;
7727 db = ((int32_t)b1 - (int32_t)b0) / dy;
7731 dr = ((int32_t)r1 - (int32_t)r0);
7732 dg = ((int32_t)g1 - (int32_t)g0);
7733 db = ((int32_t)b1 - (int32_t)b0);
7736 d = 2*dx - dy; /* Initial value of d */
7737 incrS = 2*dx; /* incr. used for move to S */
7738 incrSE = 2*(dx - dy); /* incr. used for move to SE */
7740 if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
7741 GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
7746 d = d + incrS; /* Choose S */
7750 d = d + incrSE; /* Choose SE */
7759 if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
7760 GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
7764 ///////////////////////////////////////////////////////////////////////
7766 static void Line_N_NE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, uint32_t rgb1)
7768 int dx, dy, incrN, incrNE, d;
7769 uint32_t r0, g0, b0, r1, g1, b1;
7772 r0 = (rgb0 & 0x00ff0000);
7773 g0 = (rgb0 & 0x0000ff00) << 8;
7774 b0 = (rgb0 & 0x000000ff) << 16;
7775 r1 = (rgb1 & 0x00ff0000);
7776 g1 = (rgb1 & 0x0000ff00) << 8;
7777 b1 = (rgb1 & 0x000000ff) << 16;
7784 dr = ((int32_t)r1 - (int32_t)r0) / dy;
7785 dg = ((int32_t)g1 - (int32_t)g0) / dy;
7786 db = ((int32_t)b1 - (int32_t)b0) / dy;
7790 dr = ((int32_t)r1 - (int32_t)r0);
7791 dg = ((int32_t)g1 - (int32_t)g0);
7792 db = ((int32_t)b1 - (int32_t)b0);
7795 d = 2*dx - dy; /* Initial value of d */
7796 incrN = 2*dx; /* incr. used for move to N */
7797 incrNE = 2*(dx - dy); /* incr. used for move to NE */
7799 if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
7800 GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
7805 d = d + incrN; /* Choose N */
7809 d = d + incrNE; /* Choose NE */
7818 if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
7819 GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
7823 ///////////////////////////////////////////////////////////////////////
7825 static void Line_E_NE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, uint32_t rgb1)
7827 int dx, dy, incrE, incrNE, d;
7828 uint32_t r0, g0, b0, r1, g1, b1;
7831 r0 = (rgb0 & 0x00ff0000);
7832 g0 = (rgb0 & 0x0000ff00) << 8;
7833 b0 = (rgb0 & 0x000000ff) << 16;
7834 r1 = (rgb1 & 0x00ff0000);
7835 g1 = (rgb1 & 0x0000ff00) << 8;
7836 b1 = (rgb1 & 0x000000ff) << 16;
7843 dr = ((int32_t)r1 - (int32_t)r0) / dx;
7844 dg = ((int32_t)g1 - (int32_t)g0) / dx;
7845 db = ((int32_t)b1 - (int32_t)b0) / dx;
7849 dr = ((int32_t)r1 - (int32_t)r0);
7850 dg = ((int32_t)g1 - (int32_t)g0);
7851 db = ((int32_t)b1 - (int32_t)b0);
7854 d = 2*dy - dx; /* Initial value of d */
7855 incrE = 2*dy; /* incr. used for move to E */
7856 incrNE = 2*(dy - dx); /* incr. used for move to NE */
7858 if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
7859 GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
7864 d = d + incrE; /* Choose E */
7868 d = d + incrNE; /* Choose NE */
7877 if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
7878 GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
7882 ///////////////////////////////////////////////////////////////////////
7884 static void VertLineShade(int x, int y0, int y1, uint32_t rgb0, uint32_t rgb1)
7887 uint32_t r0, g0, b0, r1, g1, b1;
7890 r0 = (rgb0 & 0x00ff0000);
7891 g0 = (rgb0 & 0x0000ff00) << 8;
7892 b0 = (rgb0 & 0x000000ff) << 16;
7893 r1 = (rgb1 & 0x00ff0000);
7894 g1 = (rgb1 & 0x0000ff00) << 8;
7895 b1 = (rgb1 & 0x000000ff) << 16;
7901 dr = ((int32_t)r1 - (int32_t)r0) / dy;
7902 dg = ((int32_t)g1 - (int32_t)g0) / dy;
7903 db = ((int32_t)b1 - (int32_t)b0) / dy;
7907 dr = ((int32_t)r1 - (int32_t)r0);
7908 dg = ((int32_t)g1 - (int32_t)g0);
7909 db = ((int32_t)b1 - (int32_t)b0);
7914 r0+=dr*(drawY - y0);
7915 g0+=dg*(drawY - y0);
7916 b0+=db*(drawY - y0);
7923 for (y = y0; y <= y1; y++)
7925 GetShadeTransCol(&psxVuw[(y<<10)+x],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
7932 ///////////////////////////////////////////////////////////////////////
7934 static void HorzLineShade(int y, int x0, int x1, uint32_t rgb0, uint32_t rgb1)
7937 uint32_t r0, g0, b0, r1, g1, b1;
7940 r0 = (rgb0 & 0x00ff0000);
7941 g0 = (rgb0 & 0x0000ff00) << 8;
7942 b0 = (rgb0 & 0x000000ff) << 16;
7943 r1 = (rgb1 & 0x00ff0000);
7944 g1 = (rgb1 & 0x0000ff00) << 8;
7945 b1 = (rgb1 & 0x000000ff) << 16;
7951 dr = ((int32_t)r1 - (int32_t)r0) / dx;
7952 dg = ((int32_t)g1 - (int32_t)g0) / dx;
7953 db = ((int32_t)b1 - (int32_t)b0) / dx;
7957 dr = ((int32_t)r1 - (int32_t)r0);
7958 dg = ((int32_t)g1 - (int32_t)g0);
7959 db = ((int32_t)b1 - (int32_t)b0);
7964 r0+=dr*(drawX - x0);
7965 g0+=dg*(drawX - x0);
7966 b0+=db*(drawX - x0);
7973 for (x = x0; x <= x1; x++)
7975 GetShadeTransCol(&psxVuw[(y<<10)+x],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
7982 ///////////////////////////////////////////////////////////////////////
7984 static void Line_E_SE_Flat(int x0, int y0, int x1, int y1, unsigned short colour)
7986 int dx, dy, incrE, incrSE, d, x, y;
7990 d = 2*dy - dx; /* Initial value of d */
7991 incrE = 2*dy; /* incr. used for move to E */
7992 incrSE = 2*(dy - dx); /* incr. used for move to SE */
7995 if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
7996 GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
8001 d = d + incrE; /* Choose E */
8006 d = d + incrSE; /* Choose SE */
8010 if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
8011 GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
8015 ///////////////////////////////////////////////////////////////////////
8017 static void Line_S_SE_Flat(int x0, int y0, int x1, int y1, unsigned short colour)
8019 int dx, dy, incrS, incrSE, d, x, y;
8023 d = 2*dx - dy; /* Initial value of d */
8024 incrS = 2*dx; /* incr. used for move to S */
8025 incrSE = 2*(dx - dy); /* incr. used for move to SE */
8028 if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
8029 GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
8034 d = d + incrS; /* Choose S */
8039 d = d + incrSE; /* Choose SE */
8043 if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
8044 GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
8048 ///////////////////////////////////////////////////////////////////////
8050 static void Line_N_NE_Flat(int x0, int y0, int x1, int y1, unsigned short colour)
8052 int dx, dy, incrN, incrNE, d, x, y;
8056 d = 2*dx - dy; /* Initial value of d */
8057 incrN = 2*dx; /* incr. used for move to N */
8058 incrNE = 2*(dx - dy); /* incr. used for move to NE */
8061 if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
8062 GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
8067 d = d + incrN; /* Choose N */
8072 d = d + incrNE; /* Choose NE */
8076 if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
8077 GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
8081 ///////////////////////////////////////////////////////////////////////
8083 static void Line_E_NE_Flat(int x0, int y0, int x1, int y1, unsigned short colour)
8085 int dx, dy, incrE, incrNE, d, x, y;
8089 d = 2*dy - dx; /* Initial value of d */
8090 incrE = 2*dy; /* incr. used for move to E */
8091 incrNE = 2*(dy - dx); /* incr. used for move to NE */
8094 if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
8095 GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
8100 d = d + incrE; /* Choose E */
8105 d = d + incrNE; /* Choose NE */
8109 if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
8110 GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
8114 ///////////////////////////////////////////////////////////////////////
8116 static void VertLineFlat(int x, int y0, int y1, unsigned short colour)
8126 for (y = y0; y <= y1; y++)
8127 GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
8130 ///////////////////////////////////////////////////////////////////////
8132 static void HorzLineFlat(int y, int x0, int x1, unsigned short colour)
8142 for (x = x0; x <= x1; x++)
8143 GetShadeTransCol(&psxVuw[(y << 10) + x], colour);
8146 ///////////////////////////////////////////////////////////////////////
8148 /* Bresenham Line drawing function */
8149 static void DrawSoftwareLineShade(int32_t rgb0, int32_t rgb1)
8151 short x0, y0, x1, y1, xt, yt;
8155 if (lx0 > drawW && lx1 > drawW) return;
8156 if (ly0 > drawH && ly1 > drawH) return;
8157 if (lx0 < drawX && lx1 < drawX) return;
8158 if (ly0 < drawY && ly1 < drawY) return;
8159 if (drawY >= drawH) return;
8160 if (drawX >= drawW) return;
8173 VertLineShade(x0, y0, y1, rgb0, rgb1);
8175 VertLineShade(x0, y1, y0, rgb1, rgb0);
8181 HorzLineShade(y0, x0, x1, rgb0, rgb1);
8183 HorzLineShade(y0, x1, x0, rgb1, rgb0);
8208 Line_S_SE_Shade(x0, y0, x1, y1, rgb0, rgb1);
8210 Line_E_SE_Shade(x0, y0, x1, y1, rgb0, rgb1);
8214 Line_N_NE_Shade(x0, y0, x1, y1, rgb0, rgb1);
8216 Line_E_NE_Shade(x0, y0, x1, y1, rgb0, rgb1);
8220 ///////////////////////////////////////////////////////////////////////
8222 static void DrawSoftwareLineFlat(int32_t rgb)
8224 short x0, y0, x1, y1, xt, yt;
8226 unsigned short colour = 0;
8228 if (lx0 > drawW && lx1 > drawW) return;
8229 if (ly0 > drawH && ly1 > drawH) return;
8230 if (lx0 < drawX && lx1 < drawX) return;
8231 if (ly0 < drawY && ly1 < drawY) return;
8232 if (drawY >= drawH) return;
8233 if (drawX >= drawW) return;
8235 colour = ((rgb & 0x00f80000) >> 9) | ((rgb & 0x0000f800) >> 6) | ((rgb & 0x000000f8) >> 3);
8248 return; // Nothing to draw
8250 VertLineFlat(x0, y0, y1, colour);
8252 VertLineFlat(x0, y1, y0, colour);
8258 HorzLineFlat(y0, x0, x1, colour);
8260 HorzLineFlat(y0, x1, x0, colour);
8282 Line_S_SE_Flat(x0, y0, x1, y1, colour);
8284 Line_E_SE_Flat(x0, y0, x1, y1, colour);
8288 Line_N_NE_Flat(x0, y0, x1, y1, colour);
8290 Line_E_NE_Flat(x0, y0, x1, y1, colour);
8294 ///////////////////////////////////////////////////////////////////////