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)
1081 // rearmed: let's use VFP divider instead
1082 float r = 1024.0f * (float)x / (float)y;
1091 ////////////////////////////////////////////////////////////////////////
1092 ////////////////////////////////////////////////////////////////////////
1093 ////////////////////////////////////////////////////////////////////////
1095 static inline int RightSection_F(void)
1097 soft_vertex * v1 = right_array[ right_section ];
1098 soft_vertex * v2 = right_array[ right_section-1 ];
1100 int height = v2->y - v1->y;
1101 if(height == 0) return 0;
1102 delta_right_x = (v2->x - v1->x) / height;
1105 right_section_height = height;
1109 ////////////////////////////////////////////////////////////////////////
1111 static inline int LeftSection_F(void)
1113 soft_vertex * v1 = left_array[ left_section ];
1114 soft_vertex * v2 = left_array[ left_section-1 ];
1116 int height = v2->y - v1->y;
1117 if(height == 0) return 0;
1118 delta_left_x = (v2->x - v1->x) / height;
1121 left_section_height = height;
1125 ////////////////////////////////////////////////////////////////////////
1127 static inline BOOL NextRow_F(void)
1129 if(--left_section_height<=0)
1131 if(--left_section <= 0) {return TRUE;}
1132 if(LeftSection_F() <= 0) {return TRUE;}
1136 left_x += delta_left_x;
1139 if(--right_section_height<=0)
1141 if(--right_section<=0) {return TRUE;}
1142 if(RightSection_F() <=0) {return TRUE;}
1146 right_x += delta_right_x;
1151 ////////////////////////////////////////////////////////////////////////
1153 static inline BOOL SetupSections_F(short x1, short y1, short x2, short y2, short x3, short y3)
1155 soft_vertex * v1, * v2, * v3;
1158 v1 = vtx; v1->x=x1<<16;v1->y=y1;
1159 v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
1160 v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
1162 if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
1163 if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
1164 if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
1166 height = v3->y - v1->y;
1167 if(height == 0) {return FALSE;}
1168 longest = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
1169 if(longest == 0) {return FALSE;}
1173 right_array[0] = v3;
1174 right_array[1] = v2;
1175 right_array[2] = v1;
1181 if(LeftSection_F() <= 0) return FALSE;
1182 if(RightSection_F() <= 0)
1185 if(RightSection_F() <= 0) return FALSE;
1194 right_array[0] = v3;
1195 right_array[1] = v1;
1198 if(RightSection_F() <= 0) return FALSE;
1199 if(LeftSection_F() <= 0)
1202 if(LeftSection_F() <= 0) return FALSE;
1207 Ymax=min(v3->y-1,drawH);
1212 ////////////////////////////////////////////////////////////////////////
1213 ////////////////////////////////////////////////////////////////////////
1215 static inline int RightSection_G(void)
1217 soft_vertex * v1 = right_array[ right_section ];
1218 soft_vertex * v2 = right_array[ right_section-1 ];
1220 int height = v2->y - v1->y;
1221 if(height == 0) return 0;
1222 delta_right_x = (v2->x - v1->x) / height;
1225 right_section_height = height;
1229 ////////////////////////////////////////////////////////////////////////
1231 static inline int LeftSection_G(void)
1233 soft_vertex * v1 = left_array[ left_section ];
1234 soft_vertex * v2 = left_array[ left_section-1 ];
1236 int height = v2->y - v1->y;
1237 if(height == 0) return 0;
1238 delta_left_x = (v2->x - v1->x) / height;
1241 delta_left_R = ((v2->R - v1->R)) / height;
1243 delta_left_G = ((v2->G - v1->G)) / height;
1245 delta_left_B = ((v2->B - v1->B)) / height;
1248 left_section_height = height;
1252 ////////////////////////////////////////////////////////////////////////
1254 static inline BOOL NextRow_G(void)
1256 if(--left_section_height<=0)
1258 if(--left_section <= 0) {return TRUE;}
1259 if(LeftSection_G() <= 0) {return TRUE;}
1263 left_x += delta_left_x;
1264 left_R += delta_left_R;
1265 left_G += delta_left_G;
1266 left_B += delta_left_B;
1269 if(--right_section_height<=0)
1271 if(--right_section<=0) {return TRUE;}
1272 if(RightSection_G() <=0) {return TRUE;}
1276 right_x += delta_right_x;
1281 ////////////////////////////////////////////////////////////////////////
1283 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)
1285 soft_vertex * v1, * v2, * v3;
1286 int height,longest,temp;
1288 v1 = vtx; v1->x=x1<<16;v1->y=y1;
1289 v1->R=(rgb1) & 0x00ff0000;
1290 v1->G=(rgb1<<8) & 0x00ff0000;
1291 v1->B=(rgb1<<16) & 0x00ff0000;
1292 v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
1293 v2->R=(rgb2) & 0x00ff0000;
1294 v2->G=(rgb2<<8) & 0x00ff0000;
1295 v2->B=(rgb2<<16) & 0x00ff0000;
1296 v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
1297 v3->R=(rgb3) & 0x00ff0000;
1298 v3->G=(rgb3<<8) & 0x00ff0000;
1299 v3->B=(rgb3<<16) & 0x00ff0000;
1301 if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
1302 if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
1303 if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
1305 height = v3->y - v1->y;
1306 if(height == 0) {return FALSE;}
1307 temp=(((v2->y - v1->y) << 16) / height);
1308 longest = temp * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
1309 if(longest == 0) {return FALSE;}
1313 right_array[0] = v3;
1314 right_array[1] = v2;
1315 right_array[2] = v1;
1321 if(LeftSection_G() <= 0) return FALSE;
1322 if(RightSection_G() <= 0)
1325 if(RightSection_G() <= 0) return FALSE;
1327 if(longest > -0x1000) longest = -0x1000;
1335 right_array[0] = v3;
1336 right_array[1] = v1;
1339 if(RightSection_G() <= 0) return FALSE;
1340 if(LeftSection_G() <= 0)
1343 if(LeftSection_G() <= 0) return FALSE;
1345 if(longest < 0x1000) longest = 0x1000;
1349 Ymax=min(v3->y-1,drawH);
1351 delta_right_R=shl10idiv(temp*((v3->R - v1->R)>>10)+((v1->R - v2->R)<<6),longest);
1352 delta_right_G=shl10idiv(temp*((v3->G - v1->G)>>10)+((v1->G - v2->G)<<6),longest);
1353 delta_right_B=shl10idiv(temp*((v3->B - v1->B)>>10)+((v1->B - v2->B)<<6),longest);
1358 ////////////////////////////////////////////////////////////////////////
1359 ////////////////////////////////////////////////////////////////////////
1361 static inline int RightSection_FT(void)
1363 soft_vertex * v1 = right_array[ right_section ];
1364 soft_vertex * v2 = right_array[ right_section-1 ];
1366 int height = v2->y - v1->y;
1367 if(height == 0) return 0;
1368 delta_right_x = (v2->x - v1->x) / height;
1371 right_section_height = height;
1375 ////////////////////////////////////////////////////////////////////////
1377 static inline int LeftSection_FT(void)
1379 soft_vertex * v1 = left_array[ left_section ];
1380 soft_vertex * v2 = left_array[ left_section-1 ];
1382 int height = v2->y - v1->y;
1383 if(height == 0) return 0;
1384 delta_left_x = (v2->x - v1->x) / height;
1387 delta_left_u = ((v2->u - v1->u)) / height;
1389 delta_left_v = ((v2->v - v1->v)) / height;
1392 left_section_height = height;
1396 ////////////////////////////////////////////////////////////////////////
1398 static inline BOOL NextRow_FT(void)
1400 if(--left_section_height<=0)
1402 if(--left_section <= 0) {return TRUE;}
1403 if(LeftSection_FT() <= 0) {return TRUE;}
1407 left_x += delta_left_x;
1408 left_u += delta_left_u;
1409 left_v += delta_left_v;
1412 if(--right_section_height<=0)
1414 if(--right_section<=0) {return TRUE;}
1415 if(RightSection_FT() <=0) {return TRUE;}
1419 right_x += delta_right_x;
1424 ////////////////////////////////////////////////////////////////////////
1426 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)
1428 soft_vertex * v1, * v2, * v3;
1429 int height,longest,temp;
1431 v1 = vtx; v1->x=x1<<16;v1->y=y1;
1432 v1->u=tx1<<16;v1->v=ty1<<16;
1433 v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
1434 v2->u=tx2<<16;v2->v=ty2<<16;
1435 v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
1436 v3->u=tx3<<16;v3->v=ty3<<16;
1438 if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
1439 if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
1440 if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
1442 height = v3->y - v1->y;
1443 if(height == 0) {return FALSE;}
1445 temp=(((v2->y - v1->y) << 16) / height);
1446 longest = temp * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
1448 if(longest == 0) {return FALSE;}
1452 right_array[0] = v3;
1453 right_array[1] = v2;
1454 right_array[2] = v1;
1460 if(LeftSection_FT() <= 0) return FALSE;
1461 if(RightSection_FT() <= 0)
1464 if(RightSection_FT() <= 0) return FALSE;
1466 if(longest > -0x1000) longest = -0x1000;
1474 right_array[0] = v3;
1475 right_array[1] = v1;
1478 if(RightSection_FT() <= 0) return FALSE;
1479 if(LeftSection_FT() <= 0)
1482 if(LeftSection_FT() <= 0) return FALSE;
1484 if(longest < 0x1000) longest = 0x1000;
1488 Ymax=min(v3->y-1,drawH);
1490 delta_right_u=shl10idiv(temp*((v3->u - v1->u)>>10)+((v1->u - v2->u)<<6),longest);
1491 delta_right_v=shl10idiv(temp*((v3->v - v1->v)>>10)+((v1->v - v2->v)<<6),longest);
1496 ////////////////////////////////////////////////////////////////////////
1497 ////////////////////////////////////////////////////////////////////////
1499 static inline int RightSection_GT(void)
1501 soft_vertex * v1 = right_array[ right_section ];
1502 soft_vertex * v2 = right_array[ right_section-1 ];
1504 int height = v2->y - v1->y;
1505 if(height == 0) return 0;
1506 delta_right_x = (v2->x - v1->x) / height;
1509 right_section_height = height;
1513 ////////////////////////////////////////////////////////////////////////
1515 static inline int LeftSection_GT(void)
1517 soft_vertex * v1 = left_array[ left_section ];
1518 soft_vertex * v2 = left_array[ left_section-1 ];
1520 int height = v2->y - v1->y;
1521 if(height == 0) return 0;
1522 delta_left_x = (v2->x - v1->x) / height;
1525 delta_left_u = ((v2->u - v1->u)) / height;
1527 delta_left_v = ((v2->v - v1->v)) / height;
1530 delta_left_R = ((v2->R - v1->R)) / height;
1532 delta_left_G = ((v2->G - v1->G)) / height;
1534 delta_left_B = ((v2->B - v1->B)) / height;
1537 left_section_height = height;
1541 ////////////////////////////////////////////////////////////////////////
1543 static inline BOOL NextRow_GT(void)
1545 if(--left_section_height<=0)
1547 if(--left_section <= 0) {return TRUE;}
1548 if(LeftSection_GT() <= 0) {return TRUE;}
1552 left_x += delta_left_x;
1553 left_u += delta_left_u;
1554 left_v += delta_left_v;
1555 left_R += delta_left_R;
1556 left_G += delta_left_G;
1557 left_B += delta_left_B;
1560 if(--right_section_height<=0)
1562 if(--right_section<=0) {return TRUE;}
1563 if(RightSection_GT() <=0) {return TRUE;}
1567 right_x += delta_right_x;
1572 ////////////////////////////////////////////////////////////////////////
1574 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)
1576 soft_vertex * v1, * v2, * v3;
1577 int height,longest,temp;
1579 v1 = vtx; v1->x=x1<<16;v1->y=y1;
1580 v1->u=tx1<<16;v1->v=ty1<<16;
1581 v1->R=(rgb1) & 0x00ff0000;
1582 v1->G=(rgb1<<8) & 0x00ff0000;
1583 v1->B=(rgb1<<16) & 0x00ff0000;
1585 v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
1586 v2->u=tx2<<16;v2->v=ty2<<16;
1587 v2->R=(rgb2) & 0x00ff0000;
1588 v2->G=(rgb2<<8) & 0x00ff0000;
1589 v2->B=(rgb2<<16) & 0x00ff0000;
1591 v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
1592 v3->u=tx3<<16;v3->v=ty3<<16;
1593 v3->R=(rgb3) & 0x00ff0000;
1594 v3->G=(rgb3<<8) & 0x00ff0000;
1595 v3->B=(rgb3<<16) & 0x00ff0000;
1597 if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
1598 if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
1599 if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
1601 height = v3->y - v1->y;
1602 if(height == 0) {return FALSE;}
1604 temp=(((v2->y - v1->y) << 16) / height);
1605 longest = temp * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
1607 if(longest == 0) {return FALSE;}
1611 right_array[0] = v3;
1612 right_array[1] = v2;
1613 right_array[2] = v1;
1619 if(LeftSection_GT() <= 0) return FALSE;
1620 if(RightSection_GT() <= 0)
1623 if(RightSection_GT() <= 0) return FALSE;
1626 if(longest > -0x1000) longest = -0x1000;
1634 right_array[0] = v3;
1635 right_array[1] = v1;
1638 if(RightSection_GT() <= 0) return FALSE;
1639 if(LeftSection_GT() <= 0)
1642 if(LeftSection_GT() <= 0) return FALSE;
1644 if(longest < 0x1000) longest = 0x1000;
1648 Ymax=min(v3->y-1,drawH);
1650 delta_right_R=shl10idiv(temp*((v3->R - v1->R)>>10)+((v1->R - v2->R)<<6),longest);
1651 delta_right_G=shl10idiv(temp*((v3->G - v1->G)>>10)+((v1->G - v2->G)<<6),longest);
1652 delta_right_B=shl10idiv(temp*((v3->B - v1->B)>>10)+((v1->B - v2->B)<<6),longest);
1654 delta_right_u=shl10idiv(temp*((v3->u - v1->u)>>10)+((v1->u - v2->u)<<6),longest);
1655 delta_right_v=shl10idiv(temp*((v3->v - v1->v)>>10)+((v1->v - v2->v)<<6),longest);
1660 ////////////////////////////////////////////////////////////////////////
1661 ////////////////////////////////////////////////////////////////////////
1663 static inline int RightSection_F4(void)
1665 soft_vertex * v1 = right_array[ right_section ];
1666 soft_vertex * v2 = right_array[ right_section-1 ];
1668 int height = v2->y - v1->y;
1669 right_section_height = height;
1675 delta_right_x = (v2->x - v1->x) / height;
1680 ////////////////////////////////////////////////////////////////////////
1682 static inline int LeftSection_F4(void)
1684 soft_vertex * v1 = left_array[ left_section ];
1685 soft_vertex * v2 = left_array[ left_section-1 ];
1687 int height = v2->y - v1->y;
1688 left_section_height = height;
1694 delta_left_x = (v2->x - v1->x) / height;
1699 ////////////////////////////////////////////////////////////////////////
1701 static inline BOOL NextRow_F4(void)
1703 if(--left_section_height<=0)
1705 if(--left_section > 0)
1706 while(LeftSection_F4()<=0)
1708 if(--left_section <= 0) break;
1713 left_x += delta_left_x;
1716 if(--right_section_height<=0)
1718 if(--right_section > 0)
1719 while(RightSection_F4()<=0)
1721 if(--right_section<=0) break;
1726 right_x += delta_right_x;
1731 ////////////////////////////////////////////////////////////////////////
1733 static inline BOOL SetupSections_F4(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4)
1735 soft_vertex * v1, * v2, * v3, * v4;
1736 int height,width,longest1,longest2;
1738 v1 = vtx; v1->x=x1<<16;v1->y=y1;
1739 v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
1740 v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
1741 v4 = vtx+3; v4->x=x4<<16;v4->y=y4;
1743 if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
1744 if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
1745 if(v1->y > v4->y) { soft_vertex * v = v1; v1 = v4; v4 = v; }
1746 if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
1747 if(v2->y > v4->y) { soft_vertex * v = v2; v2 = v4; v4 = v; }
1748 if(v3->y > v4->y) { soft_vertex * v = v3; v3 = v4; v4 = v; }
1750 height = v4->y - v1->y; if(height == 0) height =1;
1751 width = (v4->x - v1->x)>>16;
1752 longest1 = (((v2->y - v1->y) << 16) / height) * width + (v1->x - v2->x);
1753 longest2 = (((v3->y - v1->y) << 16) / height) * width + (v1->x - v3->x);
1755 if(longest1 < 0) // 2 is right
1757 if(longest2 < 0) // 3 is right
1763 height = v3->y - v1->y; if(height == 0) height=1;
1764 longest1 = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
1767 right_array[0] = v4; // 1
1768 right_array[1] = v3; // 3
1769 right_array[2] = v1; // 4
1774 height = v4->y - v2->y; if(height == 0) height=1;
1775 longest1 = (((v3->y - v2->y) << 16) / height) * ((v4->x - v2->x)>>16) + (v2->x - v3->x);
1778 right_array[0] = v4; // 1
1779 right_array[1] = v2; // 2
1780 right_array[2] = v1; // 4
1785 right_array[0] = v4; // 1
1786 right_array[1] = v3; // 2
1787 right_array[2] = v2; // 3
1788 right_array[3] = v1; // 4
1796 left_array[1] = v3; // 1
1797 left_array[2] = v1; // 2
1798 left_section = 2; // 3
1799 right_array[0] = v4; // 4
1800 right_array[1] = v2;
1801 right_array[2] = v1;
1809 left_array[0] = v4; // 1
1810 left_array[1] = v2; // 2
1811 left_array[2] = v1; // 3
1812 left_section = 2; // 4
1813 right_array[0] = v4;
1814 right_array[1] = v3;
1815 right_array[2] = v1;
1820 right_array[0] = v4;
1821 right_array[1] = v1;
1824 height = v3->y - v1->y; if(height == 0) height=1;
1825 longest1 = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
1828 left_array[0] = v4; // 1
1829 left_array[1] = v3; // 3
1830 left_array[2] = v1; // 4
1835 height = v4->y - v2->y; if(height == 0) height=1;
1836 longest1 = (((v3->y - v2->y) << 16) / height) * ((v4->x - v2->x)>>16) + (v2->x - v3->x);
1839 left_array[0] = v4; // 1
1840 left_array[1] = v2; // 2
1841 left_array[2] = v1; // 4
1846 left_array[0] = v4; // 1
1847 left_array[1] = v3; // 2
1848 left_array[2] = v2; // 3
1849 left_array[3] = v1; // 4
1856 while(LeftSection_F4()<=0)
1858 if(--left_section <= 0) break;
1861 while(RightSection_F4()<=0)
1863 if(--right_section <= 0) break;
1867 Ymax=min(v4->y-1,drawH);
1872 ////////////////////////////////////////////////////////////////////////
1873 ////////////////////////////////////////////////////////////////////////
1875 static inline int RightSection_FT4(void)
1877 soft_vertex * v1 = right_array[ right_section ];
1878 soft_vertex * v2 = right_array[ right_section-1 ];
1880 int height = v2->y - v1->y;
1881 right_section_height = height;
1889 delta_right_x = (v2->x - v1->x) / height;
1890 delta_right_u = (v2->u - v1->u) / height;
1891 delta_right_v = (v2->v - v1->v) / height;
1896 ////////////////////////////////////////////////////////////////////////
1898 static inline int LeftSection_FT4(void)
1900 soft_vertex * v1 = left_array[ left_section ];
1901 soft_vertex * v2 = left_array[ left_section-1 ];
1903 int height = v2->y - v1->y;
1904 left_section_height = height;
1912 delta_left_x = (v2->x - v1->x) / height;
1913 delta_left_u = (v2->u - v1->u) / height;
1914 delta_left_v = (v2->v - v1->v) / height;
1919 ////////////////////////////////////////////////////////////////////////
1921 static inline BOOL NextRow_FT4(void)
1923 if(--left_section_height<=0)
1925 if(--left_section > 0)
1926 while(LeftSection_FT4()<=0)
1928 if(--left_section <= 0) break;
1933 left_x += delta_left_x;
1934 left_u += delta_left_u;
1935 left_v += delta_left_v;
1938 if(--right_section_height<=0)
1940 if(--right_section > 0)
1941 while(RightSection_FT4()<=0)
1943 if(--right_section<=0) break;
1948 right_x += delta_right_x;
1949 right_u += delta_right_u;
1950 right_v += delta_right_v;
1955 ////////////////////////////////////////////////////////////////////////
1957 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)
1959 soft_vertex * v1, * v2, * v3, * v4;
1960 int height,width,longest1,longest2;
1962 v1 = vtx; v1->x=x1<<16;v1->y=y1;
1963 v1->u=tx1<<16;v1->v=ty1<<16;
1965 v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
1966 v2->u=tx2<<16;v2->v=ty2<<16;
1968 v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
1969 v3->u=tx3<<16;v3->v=ty3<<16;
1971 v4 = vtx+3; v4->x=x4<<16;v4->y=y4;
1972 v4->u=tx4<<16;v4->v=ty4<<16;
1974 if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
1975 if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
1976 if(v1->y > v4->y) { soft_vertex * v = v1; v1 = v4; v4 = v; }
1977 if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
1978 if(v2->y > v4->y) { soft_vertex * v = v2; v2 = v4; v4 = v; }
1979 if(v3->y > v4->y) { soft_vertex * v = v3; v3 = v4; v4 = v; }
1981 height = v4->y - v1->y; if(height == 0) height =1;
1982 width = (v4->x - v1->x)>>16;
1983 longest1 = (((v2->y - v1->y) << 16) / height) * width + (v1->x - v2->x);
1984 longest2 = (((v3->y - v1->y) << 16) / height) * width + (v1->x - v3->x);
1986 if(longest1 < 0) // 2 is right
1988 if(longest2 < 0) // 3 is right
1994 height = v3->y - v1->y; if(height == 0) height=1;
1995 longest1 = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
1998 right_array[0] = v4; // 1
1999 right_array[1] = v3; // 3
2000 right_array[2] = v1; // 4
2005 height = v4->y - v2->y; if(height == 0) height=1;
2006 longest1 = (((v3->y - v2->y) << 16) / height) * ((v4->x - v2->x)>>16) + (v2->x - v3->x);
2009 right_array[0] = v4; // 1
2010 right_array[1] = v2; // 2
2011 right_array[2] = v1; // 4
2016 right_array[0] = v4; // 1
2017 right_array[1] = v3; // 2
2018 right_array[2] = v2; // 3
2019 right_array[3] = v1; // 4
2027 left_array[1] = v3; // 1
2028 left_array[2] = v1; // 2
2029 left_section = 2; // 3
2030 right_array[0] = v4; // 4
2031 right_array[1] = v2;
2032 right_array[2] = v1;
2040 left_array[0] = v4; // 1
2041 left_array[1] = v2; // 2
2042 left_array[2] = v1; // 3
2043 left_section = 2; // 4
2044 right_array[0] = v4;
2045 right_array[1] = v3;
2046 right_array[2] = v1;
2051 right_array[0] = v4;
2052 right_array[1] = v1;
2055 height = v3->y - v1->y; if(height == 0) height=1;
2056 longest1 = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
2059 left_array[0] = v4; // 1
2060 left_array[1] = v3; // 3
2061 left_array[2] = v1; // 4
2066 height = v4->y - v2->y; if(height == 0) height=1;
2067 longest1 = (((v3->y - v2->y) << 16) / height) * ((v4->x - v2->x)>>16) + (v2->x - v3->x);
2070 left_array[0] = v4; // 1
2071 left_array[1] = v2; // 2
2072 left_array[2] = v1; // 4
2077 left_array[0] = v4; // 1
2078 left_array[1] = v3; // 2
2079 left_array[2] = v2; // 3
2080 left_array[3] = v1; // 4
2087 while(LeftSection_FT4()<=0)
2089 if(--left_section <= 0) break;
2092 while(RightSection_FT4()<=0)
2094 if(--right_section <= 0) break;
2098 Ymax=min(v4->y-1,drawH);
2103 ////////////////////////////////////////////////////////////////////////
2104 ////////////////////////////////////////////////////////////////////////
2106 static inline int RightSection_GT4(void)
2108 soft_vertex * v1 = right_array[ right_section ];
2109 soft_vertex * v2 = right_array[ right_section-1 ];
2111 int height = v2->y - v1->y;
2112 right_section_height = height;
2124 delta_right_x = (v2->x - v1->x) / height;
2125 delta_right_u = (v2->u - v1->u) / height;
2126 delta_right_v = (v2->v - v1->v) / height;
2127 delta_right_R = (v2->R - v1->R) / height;
2128 delta_right_G = (v2->G - v1->G) / height;
2129 delta_right_B = (v2->B - v1->B) / height;
2134 ////////////////////////////////////////////////////////////////////////
2136 static inline int LeftSection_GT4(void)
2138 soft_vertex * v1 = left_array[ left_section ];
2139 soft_vertex * v2 = left_array[ left_section-1 ];
2141 int height = v2->y - v1->y;
2142 left_section_height = height;
2154 delta_left_x = (v2->x - v1->x) / height;
2155 delta_left_u = (v2->u - v1->u) / height;
2156 delta_left_v = (v2->v - v1->v) / height;
2157 delta_left_R = (v2->R - v1->R) / height;
2158 delta_left_G = (v2->G - v1->G) / height;
2159 delta_left_B = (v2->B - v1->B) / height;
2164 ////////////////////////////////////////////////////////////////////////
2166 static inline BOOL NextRow_GT4(void)
2168 if(--left_section_height<=0)
2170 if(--left_section > 0)
2171 while(LeftSection_GT4()<=0)
2173 if(--left_section <= 0) break;
2178 left_x += delta_left_x;
2179 left_u += delta_left_u;
2180 left_v += delta_left_v;
2181 left_R += delta_left_R;
2182 left_G += delta_left_G;
2183 left_B += delta_left_B;
2186 if(--right_section_height<=0)
2188 if(--right_section > 0)
2189 while(RightSection_GT4()<=0)
2191 if(--right_section<=0) break;
2196 right_x += delta_right_x;
2197 right_u += delta_right_u;
2198 right_v += delta_right_v;
2199 right_R += delta_right_R;
2200 right_G += delta_right_G;
2201 right_B += delta_right_B;
2206 ////////////////////////////////////////////////////////////////////////
2208 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)
2210 soft_vertex * v1, * v2, * v3, * v4;
2211 int height,width,longest1,longest2;
2213 v1 = vtx; v1->x=x1<<16;v1->y=y1;
2214 v1->u=tx1<<16;v1->v=ty1<<16;
2215 v1->R=(rgb1) & 0x00ff0000;
2216 v1->G=(rgb1<<8) & 0x00ff0000;
2217 v1->B=(rgb1<<16) & 0x00ff0000;
2219 v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
2220 v2->u=tx2<<16;v2->v=ty2<<16;
2221 v2->R=(rgb2) & 0x00ff0000;
2222 v2->G=(rgb2<<8) & 0x00ff0000;
2223 v2->B=(rgb2<<16) & 0x00ff0000;
2225 v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
2226 v3->u=tx3<<16;v3->v=ty3<<16;
2227 v3->R=(rgb3) & 0x00ff0000;
2228 v3->G=(rgb3<<8) & 0x00ff0000;
2229 v3->B=(rgb3<<16) & 0x00ff0000;
2231 v4 = vtx+3; v4->x=x4<<16;v4->y=y4;
2232 v4->u=tx4<<16;v4->v=ty4<<16;
2233 v4->R=(rgb4) & 0x00ff0000;
2234 v4->G=(rgb4<<8) & 0x00ff0000;
2235 v4->B=(rgb4<<16) & 0x00ff0000;
2237 if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
2238 if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
2239 if(v1->y > v4->y) { soft_vertex * v = v1; v1 = v4; v4 = v; }
2240 if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
2241 if(v2->y > v4->y) { soft_vertex * v = v2; v2 = v4; v4 = v; }
2242 if(v3->y > v4->y) { soft_vertex * v = v3; v3 = v4; v4 = v; }
2244 height = v4->y - v1->y; if(height == 0) height =1;
2245 width = (v4->x - v1->x)>>16;
2246 longest1 = (((v2->y - v1->y) << 16) / height) * width + (v1->x - v2->x);
2247 longest2 = (((v3->y - v1->y) << 16) / height) * width + (v1->x - v3->x);
2249 if(longest1 < 0) // 2 is right
2251 if(longest2 < 0) // 3 is right
2257 height = v3->y - v1->y; if(height == 0) height=1;
2258 longest1 = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
2261 right_array[0] = v4; // 1
2262 right_array[1] = v3; // 3
2263 right_array[2] = v1; // 4
2268 height = v4->y - v2->y; if(height == 0) height=1;
2269 longest1 = (((v3->y - v2->y) << 16) / height) * ((v4->x - v2->x)>>16) + (v2->x - v3->x);
2272 right_array[0] = v4; // 1
2273 right_array[1] = v2; // 2
2274 right_array[2] = v1; // 4
2279 right_array[0] = v4; // 1
2280 right_array[1] = v3; // 2
2281 right_array[2] = v2; // 3
2282 right_array[3] = v1; // 4
2290 left_array[1] = v3; // 1
2291 left_array[2] = v1; // 2
2292 left_section = 2; // 3
2293 right_array[0] = v4; // 4
2294 right_array[1] = v2;
2295 right_array[2] = v1;
2303 left_array[0] = v4; // 1
2304 left_array[1] = v2; // 2
2305 left_array[2] = v1; // 3
2306 left_section = 2; // 4
2307 right_array[0] = v4;
2308 right_array[1] = v3;
2309 right_array[2] = v1;
2314 right_array[0] = v4;
2315 right_array[1] = v1;
2318 height = v3->y - v1->y; if(height == 0) height=1;
2319 longest1 = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
2322 left_array[0] = v4; // 1
2323 left_array[1] = v3; // 3
2324 left_array[2] = v1; // 4
2329 height = v4->y - v2->y; if(height == 0) height=1;
2330 longest1 = (((v3->y - v2->y) << 16) / height) * ((v4->x - v2->x)>>16) + (v2->x - v3->x);
2333 left_array[0] = v4; // 1
2334 left_array[1] = v2; // 2
2335 left_array[2] = v1; // 4
2340 left_array[0] = v4; // 1
2341 left_array[1] = v3; // 2
2342 left_array[2] = v2; // 3
2343 left_array[3] = v1; // 4
2350 while(LeftSection_GT4()<=0)
2352 if(--left_section <= 0) break;
2355 while(RightSection_GT4()<=0)
2357 if(--right_section <= 0) break;
2361 Ymax=min(v4->y-1,drawH);
2366 ////////////////////////////////////////////////////////////////////////
2367 ////////////////////////////////////////////////////////////////////////
2368 ////////////////////////////////////////////////////////////////////////
2370 ////////////////////////////////////////////////////////////////////////
2371 ////////////////////////////////////////////////////////////////////////
2372 ////////////////////////////////////////////////////////////////////////
2374 ////////////////////////////////////////////////////////////////////////
2375 // POLY 3/4 FLAT SHADED
2376 ////////////////////////////////////////////////////////////////////////
2378 static inline void drawPoly3Fi(short x1,short y1,short x2,short y2,short x3,short y3,int32_t rgb)
2380 int i,j,xmin,xmax,ymin,ymax;
2381 unsigned short color;uint32_t lcolor;
2383 if(x1>drawW && x2>drawW && x3>drawW) return;
2384 if(y1>drawH && y2>drawH && y3>drawH) return;
2385 if(x1<drawX && x2<drawX && x3<drawX) return;
2386 if(y1<drawY && y2<drawY && y3<drawY) return;
2387 if(drawY>=drawH) return;
2388 if(drawX>=drawW) return;
2390 if(!SetupSections_F(x1,y1,x2,y2,x3,y3)) return;
2394 color = ((rgb & 0x00f80000)>>9) | ((rgb & 0x0000f800)>>6) | ((rgb & 0x000000f8)>>3);
2395 lcolor=lSetMask|(((uint32_t)(color))<<16)|color;
2397 for(ymin=Ymin;ymin<drawY;ymin++)
2398 if(NextRow_F()) return;
2402 if(!bCheckMask && !DrawSemiTrans)
2405 for (i=ymin;i<=ymax;i++)
2407 xmin=left_x >> 16; if(drawX>xmin) xmin=drawX;
2408 xmax=(right_x >> 16)-1; if(drawW<xmax) xmax=drawW;
2410 for(j=xmin;j<xmax;j+=2)
2412 PUTLE32(((uint32_t *)&psxVuw[(i<<10)+j]), lcolor);
2414 if(j==xmax) PUTLE16(&psxVuw[(i<<10)+j], color);
2416 if(NextRow_F()) return;
2423 for (i=ymin;i<=ymax;i++)
2425 xmin=left_x >> 16; if(drawX>xmin) xmin=drawX;
2426 xmax=(right_x >> 16)-1; if(drawW<xmax) xmax=drawW;
2428 for(j=xmin;j<xmax;j+=2)
2430 GetShadeTransCol32((uint32_t *)&psxVuw[(i<<10)+j],lcolor);
2433 GetShadeTransCol(&psxVuw[(i<<10)+j],color);
2435 if(NextRow_F()) return;
2439 ////////////////////////////////////////////////////////////////////////
2441 static void drawPoly3F(int32_t rgb)
2443 drawPoly3Fi(lx0,ly0,lx1,ly1,lx2,ly2,rgb);
2448 static void drawPoly4F_TRI(int32_t rgb)
2450 drawPoly3Fi(lx1,ly1,lx3,ly3,lx2,ly2,rgb);
2451 drawPoly3Fi(lx0,ly0,lx1,ly1,lx2,ly2,rgb);
2458 static void drawPoly4F(int32_t rgb)
2460 int i,j,xmin,xmax,ymin,ymax;
2461 unsigned short color;uint32_t lcolor;
2463 if(lx0>drawW && lx1>drawW && lx2>drawW && lx3>drawW) return;
2464 if(ly0>drawH && ly1>drawH && ly2>drawH && ly3>drawH) return;
2465 if(lx0<drawX && lx1<drawX && lx2<drawX && lx3<drawX) return;
2466 if(ly0<drawY && ly1<drawY && ly2<drawY && ly3<drawY) return;
2467 if(drawY>=drawH) return;
2468 if(drawX>=drawW) return;
2470 if(!SetupSections_F4(lx0,ly0,lx1,ly1,lx2,ly2,lx3,ly3)) return;
2474 for(ymin=Ymin;ymin<drawY;ymin++)
2475 if(NextRow_F4()) return;
2477 color = ((rgb & 0x00f80000)>>9) | ((rgb & 0x0000f800)>>6) | ((rgb & 0x000000f8)>>3);
2478 lcolor= lSetMask|(((uint32_t)(color))<<16)|color;
2482 if(!bCheckMask && !DrawSemiTrans)
2485 for (i=ymin;i<=ymax;i++)
2487 xmin=left_x >> 16; if(drawX>xmin) xmin=drawX;
2488 xmax=(right_x >> 16)-1; if(drawW<xmax) xmax=drawW;
2490 for(j=xmin;j<xmax;j+=2)
2492 PUTLE32(((uint32_t *)&psxVuw[(i<<10)+j]), lcolor);
2494 if(j==xmax) PUTLE16(&psxVuw[(i<<10)+j], color);
2496 if(NextRow_F4()) return;
2503 for (i=ymin;i<=ymax;i++)
2505 xmin=left_x >> 16; if(drawX>xmin) xmin=drawX;
2506 xmax=(right_x >> 16)-1; if(drawW<xmax) xmax=drawW;
2508 for(j=xmin;j<xmax;j+=2)
2510 GetShadeTransCol32((uint32_t *)&psxVuw[(i<<10)+j],lcolor);
2512 if(j==xmax) GetShadeTransCol(&psxVuw[(i<<10)+j],color);
2514 if(NextRow_F4()) return;
2518 ////////////////////////////////////////////////////////////////////////
2519 // POLY 3/4 F-SHADED TEX PAL 4
2520 ////////////////////////////////////////////////////////////////////////
2522 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)
2524 int i,j,xmin,xmax,ymin,ymax;
2525 int32_t difX, difY,difX2, difY2;
2526 int32_t posX,posY,YAdjust,XAdjust;
2530 if(x1>drawW && x2>drawW && x3>drawW) return;
2531 if(y1>drawH && y2>drawH && y3>drawH) return;
2532 if(x1<drawX && x2<drawX && x3<drawX) return;
2533 if(y1<drawY && y2<drawY && y3<drawY) return;
2534 if(drawY>=drawH) return;
2535 if(drawX>=drawW) return;
2537 if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
2541 for(ymin=Ymin;ymin<drawY;ymin++)
2542 if(NextRow_FT()) return;
2544 clutP=(clY<<10)+clX;
2546 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
2548 difX=delta_right_u;difX2=difX<<1;
2549 difY=delta_right_v;difY2=difY<<1;
2553 if(!bCheckMask && !DrawSemiTrans)
2555 for (i=ymin;i<=ymax;i++)
2557 xmin=(left_x >> 16);
2558 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!
2559 if(drawW<xmax) xmax=drawW;
2567 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
2569 for(j=xmin;j<xmax;j+=2)
2572 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(XAdjust>>1)];
2573 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
2574 XAdjust=((posX+difX)>>16);
2575 tC2 = psxVub[(((posY+difY)>>5)&(int32_t)0xFFFFF800)+YAdjust+
2577 tC2=(tC2>>((XAdjust&1)<<2))&0xf;
2579 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
2580 GETLE16(&psxVuw[clutP+tC1])|
2581 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
2589 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+
2591 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
2592 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
2605 for (i=ymin;i<=ymax;i++)
2607 xmin=(left_x >> 16);
2608 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!
2609 if(drawW<xmax) xmax=drawW;
2617 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
2619 for(j=xmin;j<xmax;j+=2)
2622 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(XAdjust>>1)];
2623 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
2624 XAdjust=((posX+difX)>>16);
2625 tC2 = psxVub[(((posY+difY)>>5)&(int32_t)0xFFFFF800)+YAdjust+
2627 tC2=(tC2>>((XAdjust&1)<<2))&0xf;
2629 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
2630 GETLE16(&psxVuw[clutP+tC1])|
2631 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
2639 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+
2641 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
2642 GetTextureTransColG(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
2652 ////////////////////////////////////////////////////////////////////////
2654 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)
2656 int i,j,xmin,xmax,ymin,ymax,n_xi,n_yi,TXV;
2657 int32_t difX, difY,difX2, difY2;
2658 int32_t posX,posY,YAdjust,XAdjust;
2662 if(x1>drawW && x2>drawW && x3>drawW) return;
2663 if(y1>drawH && y2>drawH && y3>drawH) return;
2664 if(x1<drawX && x2<drawX && x3<drawX) return;
2665 if(y1<drawY && y2<drawY && y3<drawY) return;
2666 if(drawY>=drawH) return;
2667 if(drawX>=drawW) return;
2669 if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
2673 for(ymin=Ymin;ymin<drawY;ymin++)
2674 if(NextRow_FT()) return;
2676 clutP=(clY<<10)+clX;
2678 YAdjust=(GlobalTextAddrY<<10)+GlobalTextAddrX;
2680 difX=delta_right_u;difX2=difX<<1;
2681 difY=delta_right_v;difY2=difY<<1;
2685 if(!bCheckMask && !DrawSemiTrans)
2687 for (i=ymin;i<=ymax;i++)
2689 xmin=(left_x >> 16);
2690 xmax=(right_x >> 16)-1;
2691 if(drawW<xmax) xmax=drawW;
2699 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
2701 for(j=xmin;j<xmax;j+=2)
2706 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
2707 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
2709 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
2711 XAdjust=((posX+difX)>>16);
2713 TXV=(posY+difY)>>16;
2714 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
2715 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
2717 tC2= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
2719 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
2720 GETLE16(&psxVuw[clutP+tC1])|
2721 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
2731 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
2732 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
2734 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
2736 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
2749 for (i=ymin;i<=ymax;i++)
2751 xmin=(left_x >> 16);
2752 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!
2753 if(drawW<xmax) xmax=drawW;
2761 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
2763 for(j=xmin;j<xmax;j+=2)
2768 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
2769 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
2771 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
2773 XAdjust=((posX+difX)>>16);
2775 TXV=(posY+difY)>>16;
2776 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
2777 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
2779 tC2= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
2781 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
2782 GETLE16(&psxVuw[clutP+tC1])|
2783 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
2793 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
2794 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
2796 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
2798 GetTextureTransColG(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
2808 ////////////////////////////////////////////////////////////////////////
2810 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)
2812 int i,j,xmin,xmax,ymin,ymax;
2813 int32_t difX, difY,difX2, difY2;
2814 int32_t posX,posY,YAdjust,XAdjust;
2818 if(x1>drawW && x2>drawW && x3>drawW) return;
2819 if(y1>drawH && y2>drawH && y3>drawH) return;
2820 if(x1<drawX && x2<drawX && x3<drawX) return;
2821 if(y1<drawY && y2<drawY && y3<drawY) return;
2822 if(drawY>=drawH) return;
2823 if(drawX>=drawW) return;
2825 if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
2829 for(ymin=Ymin;ymin<drawY;ymin++)
2830 if(NextRow_FT()) return;
2832 clutP=(clY<<10)+clX;
2834 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
2835 YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0>>1);
2837 difX=delta_right_u;difX2=difX<<1;
2838 difY=delta_right_v;difY2=difY<<1;
2842 if(!bCheckMask && !DrawSemiTrans)
2844 for (i=ymin;i<=ymax;i++)
2846 xmin=(left_x >> 16);
2847 xmax=(right_x >> 16);//-1; //!!!!!!!!!!!!!!!!
2848 if(xmax>xmin) xmax--;
2850 if(drawW<xmax) xmax=drawW;
2858 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
2860 for(j=xmin;j<xmax;j+=2)
2862 XAdjust=(posX>>16)&TWin.xmask;
2863 tC1 = psxVub[(((posY>>16)&TWin.ymask)<<11)+
2864 YAdjust+(XAdjust>>1)];
2865 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
2866 XAdjust=((posX+difX)>>16)&TWin.xmask;
2867 tC2 = psxVub[((((posY+difY)>>16)&TWin.ymask)<<11)+
2868 YAdjust+(XAdjust>>1)];
2869 tC2=(tC2>>((XAdjust&1)<<2))&0xf;
2871 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
2872 GETLE16(&psxVuw[clutP+tC1])|
2873 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
2880 XAdjust=(posX>>16)&TWin.xmask;
2881 tC1 = psxVub[(((posY>>16)&TWin.ymask)<<11)+
2882 YAdjust+(XAdjust>>1)];
2883 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
2884 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
2897 for (i=ymin;i<=ymax;i++)
2899 xmin=(left_x >> 16);
2900 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!
2901 if(drawW<xmax) xmax=drawW;
2909 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
2911 for(j=xmin;j<xmax;j+=2)
2913 XAdjust=(posX>>16)&TWin.xmask;
2914 tC1 = psxVub[(((posY>>16)&TWin.ymask)<<11)+
2915 YAdjust+(XAdjust>>1)];
2916 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
2917 XAdjust=((posX+difX)>>16)&TWin.xmask;
2918 tC2 = psxVub[((((posY+difY)>>16)&TWin.ymask)<<11)+
2919 YAdjust+(XAdjust>>1)];
2920 tC2=(tC2>>((XAdjust&1)<<2))&0xf;
2922 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
2923 GETLE16(&psxVuw[clutP+tC1])|
2924 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
2931 XAdjust=(posX>>16)&TWin.xmask;
2932 tC1 = psxVub[(((posY>>16)&TWin.ymask)<<11)+
2933 YAdjust+(XAdjust>>1)];
2934 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
2935 GetTextureTransColG(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
2945 ////////////////////////////////////////////////////////////////////////
2949 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)
2951 drawPoly3TEx4(x2,y2,x3,y3,x4,y4,
2952 tx2,ty2,tx3,ty3,tx4,ty4,
2954 drawPoly3TEx4(x1,y1,x2,y2,x4,y4,
2955 tx1,ty1,tx2,ty2,tx4,ty4,
2963 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)
2966 int32_t i,j,xmin,xmax,ymin,ymax;
2967 int32_t difX, difY, difX2, difY2;
2968 int32_t posX,posY,YAdjust,clutP,XAdjust;
2971 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
2972 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
2973 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
2974 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
2975 if(drawY>=drawH) return;
2976 if(drawX>=drawW) return;
2978 if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
2982 for(ymin=Ymin;ymin<drawY;ymin++)
2983 if(NextRow_FT4()) return;
2985 clutP=(clY<<10)+clX;
2987 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
2991 if(!bCheckMask && !DrawSemiTrans)
2993 for (i=ymin;i<=ymax;i++)
2995 xmin=(left_x >> 16);
2996 xmax=(right_x >> 16);
3005 difX=(right_u-posX)/num;
3006 difY=(right_v-posY)/num;
3011 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3012 xmax--;if(drawW<xmax) xmax=drawW;
3014 for(j=xmin;j<xmax;j+=2)
3017 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(XAdjust>>1)];
3018 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
3019 XAdjust=((posX+difX)>>16);
3020 tC2 = psxVub[(((posY+difY)>>5)&(int32_t)0xFFFFF800)+YAdjust+
3022 tC2=(tC2>>((XAdjust&1)<<2))&0xf;
3024 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
3025 GETLE16(&psxVuw[clutP+tC1])|
3026 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3033 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+
3035 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
3036 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3040 if(NextRow_FT4()) return;
3047 for (i=ymin;i<=ymax;i++)
3049 xmin=(left_x >> 16);
3050 xmax=(right_x >> 16);
3059 difX=(right_u-posX)/num;
3060 difY=(right_v-posY)/num;
3065 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3066 xmax--;if(drawW<xmax) xmax=drawW;
3068 for(j=xmin;j<xmax;j+=2)
3071 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(XAdjust>>1)];
3072 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
3073 XAdjust=((posX+difX)>>16);
3074 tC2 = psxVub[(((posY+difY)>>5)&(int32_t)0xFFFFF800)+YAdjust+
3076 tC2=(tC2>>((XAdjust&1)<<2))&0xf;
3078 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
3079 GETLE16(&psxVuw[clutP+tC1])|
3080 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3087 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+
3089 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
3090 GetTextureTransColG(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3093 if(NextRow_FT4()) return;
3097 ////////////////////////////////////////////////////////////////////////
3099 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)
3102 int32_t i,j=0,xmin,xmax,ymin,ymax,n_xi,n_yi,TXV;
3103 int32_t difX, difY, difX2, difY2;
3104 int32_t posX=0,posY=0,YAdjust,clutP,XAdjust;
3107 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
3108 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
3109 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
3110 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
3111 if(drawY>=drawH) return;
3112 if(drawX>=drawW) return;
3114 if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
3118 for(ymin=Ymin;ymin<drawY;ymin++)
3119 if(NextRow_FT4()) return;
3121 clutP=(clY<<10)+clX;
3123 YAdjust=((GlobalTextAddrY)<<10)+GlobalTextAddrX;
3127 if(!bCheckMask && !DrawSemiTrans)
3129 for (i=ymin;i<=ymax;i++)
3131 xmin=(left_x >> 16);
3132 xmax=(right_x >> 16);
3141 difX=(right_u-posX)/num;
3142 difY=(right_v-posY)/num;
3147 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3148 xmax--;if(drawW<xmax) xmax=drawW;
3150 for(j=xmin;j<xmax;j+=2)
3155 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
3156 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
3158 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
3160 XAdjust=((posX+difX)>>16);
3162 TXV=(posY+difY)>>16;
3163 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
3164 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
3166 tC2= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
3168 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
3169 GETLE16(&psxVuw[clutP+tC1])|
3170 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3182 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
3183 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
3185 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
3187 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3191 if(NextRow_FT4()) return;
3195 for (i=ymin;i<=ymax;i++)
3197 xmin=(left_x >> 16);
3198 xmax=(right_x >> 16);
3207 difX=(right_u-posX)/num;
3208 difY=(right_v-posY)/num;
3213 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3214 xmax--;if(drawW<xmax) xmax=drawW;
3216 for(j=xmin;j<xmax;j+=2)
3221 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
3222 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
3224 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
3226 XAdjust=((posX+difX)>>16);
3228 TXV=(posY+difY)>>16;
3229 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
3230 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
3232 tC2= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
3234 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
3235 GETLE16(&psxVuw[clutP+tC1])|
3236 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3244 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
3245 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
3247 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
3249 GetTextureTransColG(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3252 if(NextRow_FT4()) return;
3256 ////////////////////////////////////////////////////////////////////////
3258 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)
3261 int32_t i,j,xmin,xmax,ymin,ymax;
3262 int32_t difX, difY, difX2, difY2;
3263 int32_t posX,posY,YAdjust,clutP,XAdjust;
3266 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
3267 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
3268 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
3269 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
3270 if(drawY>=drawH) return;
3271 if(drawX>=drawW) return;
3273 if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
3277 for(ymin=Ymin;ymin<drawY;ymin++)
3278 if(NextRow_FT4()) return;
3280 clutP=(clY<<10)+clX;
3282 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
3283 YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0>>1);
3287 if(!bCheckMask && !DrawSemiTrans)
3289 for (i=ymin;i<=ymax;i++)
3291 xmin=(left_x >> 16);
3292 xmax=(right_x >> 16);
3301 difX=(right_u-posX)/num;
3302 difY=(right_v-posY)/num;
3307 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3308 xmax--;if(drawW<xmax) xmax=drawW;
3310 for(j=xmin;j<xmax;j+=2)
3312 XAdjust=(posX>>16)&TWin.xmask;
3313 tC1 = psxVub[(((posY>>16)&TWin.ymask)<<11)+
3314 YAdjust+(XAdjust>>1)];
3315 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
3316 XAdjust=((posX+difX)>>16)&TWin.xmask;
3317 tC2 = psxVub[((((posY+difY)>>16)&TWin.ymask)<<11)+
3318 YAdjust+(XAdjust>>1)];
3319 tC2=(tC2>>((XAdjust&1)<<2))&0xf;
3321 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
3322 GETLE16(&psxVuw[clutP+tC1])|
3323 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3329 XAdjust=(posX>>16)&TWin.xmask;
3330 tC1 = psxVub[(((posY>>16)&TWin.ymask)<<11)+
3331 YAdjust+(XAdjust>>1)];
3332 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
3333 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3336 if(NextRow_FT4()) return;
3343 for (i=ymin;i<=ymax;i++)
3345 xmin=(left_x >> 16);
3346 xmax=(right_x >> 16);
3355 difX=(right_u-posX)/num;
3356 difY=(right_v-posY)/num;
3361 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3362 xmax--;if(drawW<xmax) xmax=drawW;
3364 for(j=xmin;j<xmax;j+=2)
3366 XAdjust=(posX>>16)&TWin.xmask;
3367 tC1 = psxVub[(((posY>>16)&TWin.ymask)<<11)+
3368 YAdjust+(XAdjust>>1)];
3369 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
3370 XAdjust=((posX+difX)>>16)&TWin.xmask;
3371 tC2 = psxVub[((((posY+difY)>>16)&TWin.ymask)<<11)+
3372 YAdjust+(XAdjust>>1)];
3373 tC2=(tC2>>((XAdjust&1)<<2))&0xf;
3375 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
3376 GETLE16(&psxVuw[clutP+tC1])|
3377 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3383 XAdjust=(posX>>16)&TWin.xmask;
3384 tC1 = psxVub[(((posY>>16)&TWin.ymask)<<11)+
3385 YAdjust+(XAdjust>>1)];
3386 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
3387 GetTextureTransColG(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3390 if(NextRow_FT4()) return;
3394 ////////////////////////////////////////////////////////////////////////
3396 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)
3399 int32_t i,j,xmin,xmax,ymin,ymax;
3400 int32_t difX, difY, difX2, difY2;
3401 int32_t posX,posY,YAdjust,clutP,XAdjust;
3404 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
3405 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
3406 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
3407 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
3408 if(drawY>=drawH) return;
3409 if(drawX>=drawW) return;
3411 if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
3415 for(ymin=Ymin;ymin<drawY;ymin++)
3416 if(NextRow_FT4()) return;
3418 clutP=(clY<<10)+clX;
3420 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
3421 YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0>>1);
3425 if(!bCheckMask && !DrawSemiTrans)
3427 for (i=ymin;i<=ymax;i++)
3429 xmin=(left_x >> 16);
3430 xmax=(right_x >> 16);
3439 difX=(right_u-posX)/num;
3440 difY=(right_v-posY)/num;
3445 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3446 xmax--;if(drawW<xmax) xmax=drawW;
3448 for(j=xmin;j<xmax;j+=2)
3450 XAdjust=(posX>>16)&TWin.xmask;
3451 tC1 = psxVub[(((posY>>16)&TWin.ymask)<<11)+
3452 YAdjust+(XAdjust>>1)];
3453 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
3454 XAdjust=((posX+difX)>>16)&TWin.xmask;
3455 tC2 = psxVub[((((posY+difY)>>16)&TWin.ymask)<<11)+
3456 YAdjust+(XAdjust>>1)];
3457 tC2=(tC2>>((XAdjust&1)<<2))&0xf;
3459 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
3460 GETLE16(&psxVuw[clutP+tC1])|
3461 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3467 XAdjust=(posX>>16)&TWin.xmask;
3468 tC1 = psxVub[(((posY>>16)&TWin.ymask)<<11)+
3469 YAdjust+(XAdjust>>1)];
3470 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
3471 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3474 if(NextRow_FT4()) return;
3481 for (i=ymin;i<=ymax;i++)
3483 xmin=(left_x >> 16);
3484 xmax=(right_x >> 16);
3493 difX=(right_u-posX)/num;
3494 difY=(right_v-posY)/num;
3499 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3500 xmax--;if(drawW<xmax) xmax=drawW;
3502 for(j=xmin;j<xmax;j+=2)
3504 XAdjust=(posX>>16)&TWin.xmask;
3505 tC1 = psxVub[(((posY>>16)&TWin.ymask)<<11)+
3506 YAdjust+(XAdjust>>1)];
3507 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
3508 XAdjust=((posX+difX)>>16)&TWin.xmask;
3509 tC2 = psxVub[((((posY+difY)>>16)&TWin.ymask)<<11)+
3510 YAdjust+(XAdjust>>1)];
3511 tC2=(tC2>>((XAdjust&1)<<2))&0xf;
3513 GetTextureTransColG32_SPR((uint32_t *)&psxVuw[(i<<10)+j],
3514 GETLE16(&psxVuw[clutP+tC1])|
3515 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3521 XAdjust=(posX>>16)&TWin.xmask;
3522 tC1 = psxVub[(((posY>>16)&TWin.ymask)<<11)+
3523 YAdjust+(XAdjust>>1)];
3524 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
3525 GetTextureTransColG_SPR(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3528 if(NextRow_FT4()) return;
3531 ////////////////////////////////////////////////////////////////////////
3532 // POLY 3 F-SHADED TEX PAL 8
3533 ////////////////////////////////////////////////////////////////////////
3535 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)
3537 int i,j,xmin,xmax,ymin,ymax;
3538 int32_t difX, difY,difX2, difY2;
3539 int32_t posX,posY,YAdjust,clutP;
3542 if(x1>drawW && x2>drawW && x3>drawW) return;
3543 if(y1>drawH && y2>drawH && y3>drawH) return;
3544 if(x1<drawX && x2<drawX && x3<drawX) return;
3545 if(y1<drawY && y2<drawY && y3<drawY) return;
3546 if(drawY>=drawH) return;
3547 if(drawX>=drawW) return;
3549 if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
3553 for(ymin=Ymin;ymin<drawY;ymin++)
3554 if(NextRow_FT()) return;
3556 clutP=(clY<<10)+clX;
3558 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
3560 difX=delta_right_u;difX2=difX<<1;
3561 difY=delta_right_v;difY2=difY<<1;
3565 if(!bCheckMask && !DrawSemiTrans)
3567 for (i=ymin;i<=ymax;i++)
3569 xmin=(left_x >> 16);
3570 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!
3571 if(drawW<xmax) xmax=drawW;
3579 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3581 for(j=xmin;j<xmax;j+=2)
3583 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(posX>>16)];
3584 tC2 = psxVub[(((posY+difY)>>5)&(int32_t)0xFFFFF800)+YAdjust+
3586 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
3587 GETLE16(&psxVuw[clutP+tC1])|
3588 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3595 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(posX>>16)];
3596 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3609 for (i=ymin;i<=ymax;i++)
3611 xmin=(left_x >> 16);
3612 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!
3613 if(drawW<xmax) xmax=drawW;
3621 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3623 for(j=xmin;j<xmax;j+=2)
3625 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(posX>>16)];
3626 tC2 = psxVub[(((posY+difY)>>5)&(int32_t)0xFFFFF800)+YAdjust+
3628 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
3629 GETLE16(&psxVuw[clutP+tC1])|
3630 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3637 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(posX>>16)];
3638 GetTextureTransColG(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3649 ////////////////////////////////////////////////////////////////////////
3651 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)
3653 int i,j,xmin,xmax,ymin,ymax,n_xi,n_yi,TXV,TXU;
3654 int32_t difX, difY,difX2, difY2;
3655 int32_t posX,posY,YAdjust,clutP;
3658 if(x1>drawW && x2>drawW && x3>drawW) return;
3659 if(y1>drawH && y2>drawH && y3>drawH) return;
3660 if(x1<drawX && x2<drawX && x3<drawX) return;
3661 if(y1<drawY && y2<drawY && y3<drawY) return;
3662 if(drawY>=drawH) return;
3663 if(drawX>=drawW) return;
3665 if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
3669 for(ymin=Ymin;ymin<drawY;ymin++)
3670 if(NextRow_FT()) return;
3672 clutP=(clY<<10)+clX;
3674 YAdjust=(GlobalTextAddrY<<10)+GlobalTextAddrX;
3676 difX=delta_right_u;difX2=difX<<1;
3677 difY=delta_right_v;difY2=difY<<1;
3681 if(!bCheckMask && !DrawSemiTrans)
3683 for (i=ymin;i<=ymax;i++)
3685 xmin=(left_x >> 16);
3686 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!
3687 if(drawW<xmax) xmax=drawW;
3695 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3697 for(j=xmin;j<xmax;j+=2)
3701 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
3702 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
3704 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
3706 TXU=(posX+difX)>>16;
3707 TXV=(posY+difY)>>16;
3708 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
3709 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
3711 tC2= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
3713 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
3714 GETLE16(&psxVuw[clutP+tC1])|
3715 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3724 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
3725 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
3727 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
3729 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3742 for (i=ymin;i<=ymax;i++)
3744 xmin=(left_x >> 16);
3745 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!
3746 if(drawW<xmax) xmax=drawW;
3754 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3756 for(j=xmin;j<xmax;j+=2)
3760 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
3761 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
3763 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
3765 TXU=(posX+difX)>>16;
3766 TXV=(posY+difY)>>16;
3767 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
3768 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
3770 tC2= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
3772 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
3773 GETLE16(&psxVuw[clutP+tC1])|
3774 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3783 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
3784 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
3786 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
3788 GetTextureTransColG(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3799 ////////////////////////////////////////////////////////////////////////
3801 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)
3803 int i,j,xmin,xmax,ymin,ymax;
3804 int32_t difX, difY,difX2, difY2;
3805 int32_t posX,posY,YAdjust,clutP;
3808 if(x1>drawW && x2>drawW && x3>drawW) return;
3809 if(y1>drawH && y2>drawH && y3>drawH) return;
3810 if(x1<drawX && x2<drawX && x3<drawX) return;
3811 if(y1<drawY && y2<drawY && y3<drawY) return;
3812 if(drawY>=drawH) return;
3813 if(drawX>=drawW) return;
3815 if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
3819 for(ymin=Ymin;ymin<drawY;ymin++)
3820 if(NextRow_FT()) return;
3822 clutP=(clY<<10)+clX;
3824 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
3825 YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0);
3827 difX=delta_right_u;difX2=difX<<1;
3828 difY=delta_right_v;difY2=difY<<1;
3832 if(!bCheckMask && !DrawSemiTrans)
3834 for (i=ymin;i<=ymax;i++)
3836 xmin=(left_x >> 16);
3837 xmax=(right_x >> 16);//-1; //!!!!!!!!!!!!!!!!
3838 if(xmax>xmin) xmax--;
3840 if(drawW<xmax) xmax=drawW;
3848 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3850 for(j=xmin;j<xmax;j+=2)
3852 tC1 = psxVub[(((posY>>16)&TWin.ymask)<<11)+
3853 YAdjust+((posX>>16)&TWin.xmask)];
3854 tC2 = psxVub[((((posY+difY)>>16)&TWin.ymask)<<11)+
3855 YAdjust+(((posX+difX)>>16)&TWin.xmask)];
3856 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
3857 GETLE16(&psxVuw[clutP+tC1])|
3858 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3865 tC1 = psxVub[(((posY>>16)&TWin.ymask)<<11)+
3866 YAdjust+((posX>>16)&TWin.xmask)];
3867 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3880 for (i=ymin;i<=ymax;i++)
3882 xmin=(left_x >> 16);
3883 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!
3884 if(drawW<xmax) xmax=drawW;
3892 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3894 for(j=xmin;j<xmax;j+=2)
3896 tC1 = psxVub[(((posY>>16)&TWin.ymask)<<11)+
3897 YAdjust+((posX>>16)&TWin.xmask)];
3898 tC2 = psxVub[((((posY+difY)>>16)&TWin.ymask)<<11)+
3899 YAdjust+(((posX+difX)>>16)&TWin.xmask)];
3900 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
3901 GETLE16(&psxVuw[clutP+tC1])|
3902 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
3909 tC1 = psxVub[(((posY>>16)&TWin.ymask)<<11)+
3910 YAdjust+((posX>>16)&TWin.xmask)];
3911 GetTextureTransColG(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
3922 ////////////////////////////////////////////////////////////////////////
3926 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)
3928 drawPoly3TEx8(x2,y2,x3,y3,x4,y4,
3929 tx2,ty2,tx3,ty3,tx4,ty4,
3932 drawPoly3TEx8(x1,y1,x2,y2,x4,y4,
3933 tx1,ty1,tx2,ty2,tx4,ty4,
3941 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)
3944 int32_t i,j,xmin,xmax,ymin,ymax;
3945 int32_t difX, difY, difX2, difY2;
3946 int32_t posX,posY,YAdjust,clutP;
3949 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
3950 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
3951 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
3952 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
3953 if(drawY>=drawH) return;
3954 if(drawX>=drawW) return;
3956 if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
3960 for(ymin=Ymin;ymin<drawY;ymin++)
3961 if(NextRow_FT4()) return;
3963 clutP=(clY<<10)+clX;
3965 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
3969 if(!bCheckMask && !DrawSemiTrans)
3971 for (i=ymin;i<=ymax;i++)
3973 xmin=(left_x >> 16);
3974 xmax=(right_x >> 16);
3983 difX=(right_u-posX)/num;
3984 difY=(right_v-posY)/num;
3989 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
3990 xmax--;if(drawW<xmax) xmax=drawW;
3992 for(j=xmin;j<xmax;j+=2)
3994 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(posX>>16)];
3995 tC2 = psxVub[(((posY+difY)>>5)&(int32_t)0xFFFFF800)+YAdjust+
3997 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
3998 GETLE16(&psxVuw[clutP+tC1])|
3999 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
4005 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(posX>>16)];
4006 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
4009 if(NextRow_FT4()) return;
4016 for (i=ymin;i<=ymax;i++)
4018 xmin=(left_x >> 16);
4019 xmax=(right_x >> 16);
4028 difX=(right_u-posX)/num;
4029 difY=(right_v-posY)/num;
4034 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4035 xmax--;if(drawW<xmax) xmax=drawW;
4037 for(j=xmin;j<xmax;j+=2)
4039 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(posX>>16)];
4040 tC2 = psxVub[(((posY+difY)>>5)&(int32_t)0xFFFFF800)+YAdjust+
4042 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
4043 GETLE16(&psxVuw[clutP+tC1])|
4044 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
4050 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(posX>>16)];
4051 GetTextureTransColG(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
4054 if(NextRow_FT4()) return;
4058 ////////////////////////////////////////////////////////////////////////
4060 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)
4063 int32_t i,j,xmin,xmax,ymin,ymax,n_xi,n_yi,TXV,TXU;
4064 int32_t difX, difY, difX2, difY2;
4065 int32_t posX,posY,YAdjust,clutP;
4068 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
4069 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
4070 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
4071 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
4072 if(drawY>=drawH) return;
4073 if(drawX>=drawW) return;
4075 if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
4079 for(ymin=Ymin;ymin<drawY;ymin++)
4080 if(NextRow_FT4()) return;
4082 clutP=(clY<<10)+clX;
4084 YAdjust=(GlobalTextAddrY<<10)+GlobalTextAddrX;
4088 if(!bCheckMask && !DrawSemiTrans)
4090 for (i=ymin;i<=ymax;i++)
4092 xmin=(left_x >> 16);
4093 xmax=(right_x >> 16);
4102 difX=(right_u-posX)/num;
4103 difY=(right_v-posY)/num;
4108 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4109 xmax--;if(drawW<xmax) xmax=drawW;
4111 for(j=xmin;j<xmax;j+=2)
4115 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
4116 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
4118 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
4120 TXU=(posX+difX)>>16;
4121 TXV=(posY+difY)>>16;
4122 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
4123 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
4125 tC2= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
4127 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
4128 GETLE16(&psxVuw[clutP+tC1])|
4129 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
4137 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
4138 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
4140 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
4142 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
4145 if(NextRow_FT4()) return;
4152 for (i=ymin;i<=ymax;i++)
4154 xmin=(left_x >> 16);
4155 xmax=(right_x >> 16);
4164 difX=(right_u-posX)/num;
4165 difY=(right_v-posY)/num;
4170 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4171 xmax--;if(drawW<xmax) xmax=drawW;
4173 for(j=xmin;j<xmax;j+=2)
4177 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
4178 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
4180 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
4182 TXU=(posX+difX)>>16;
4183 TXV=(posY+difY)>>16;
4184 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
4185 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
4187 tC2= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
4189 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
4190 GETLE16(&psxVuw[clutP+tC1])|
4191 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
4199 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
4200 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
4201 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
4202 GetTextureTransColG(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
4205 if(NextRow_FT4()) return;
4209 ////////////////////////////////////////////////////////////////////////
4211 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)
4214 int32_t i,j,xmin,xmax,ymin,ymax;
4215 int32_t difX, difY, difX2, difY2;
4216 int32_t posX,posY,YAdjust,clutP;
4219 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
4220 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
4221 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
4222 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
4223 if(drawY>=drawH) return;
4224 if(drawX>=drawW) return;
4226 if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
4230 for(ymin=Ymin;ymin<drawY;ymin++)
4231 if(NextRow_FT4()) return;
4233 clutP=(clY<<10)+clX;
4235 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
4236 YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0);
4240 if(!bCheckMask && !DrawSemiTrans)
4242 for (i=ymin;i<=ymax;i++)
4244 xmin=(left_x >> 16);
4245 xmax=(right_x >> 16);
4254 difX=(right_u-posX)/num;
4255 difY=(right_v-posY)/num;
4260 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4261 xmax--;if(drawW<xmax) xmax=drawW;
4263 for(j=xmin;j<xmax;j+=2)
4265 tC1 = psxVub[(((posY>>16)&TWin.ymask)<<11)+
4266 YAdjust+((posX>>16)&TWin.xmask)];
4267 tC2 = psxVub[((((posY+difY)>>16)&TWin.ymask)<<11)+
4268 YAdjust+(((posX+difX)>>16)&TWin.xmask)];
4269 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
4270 GETLE16(&psxVuw[clutP+tC1])|
4271 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
4277 tC1 = psxVub[((((posY+difY)>>16)&TWin.ymask)<<11)+
4278 YAdjust+((posX>>16)&TWin.xmask)];
4279 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
4282 if(NextRow_FT4()) return;
4290 for (i=ymin;i<=ymax;i++)
4292 xmin=(left_x >> 16);
4293 xmax=(right_x >> 16);
4302 difX=(right_u-posX)/num;
4303 difY=(right_v-posY)/num;
4308 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4309 xmax--;if(drawW<xmax) xmax=drawW;
4311 for(j=xmin;j<xmax;j+=2)
4313 tC1 = psxVub[(((posY>>16)&TWin.ymask)<<11)+
4314 YAdjust+((posX>>16)&TWin.xmask)];
4315 tC2 = psxVub[((((posY+difY)>>16)&TWin.ymask)<<11)+
4316 YAdjust+(((posX+difX)>>16)&TWin.xmask)];
4317 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
4318 GETLE16(&psxVuw[clutP+tC1])|
4319 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
4325 tC1 = psxVub[((((posY+difY)>>16)&TWin.ymask)<<11)+
4326 YAdjust+((posX>>16)&TWin.xmask)];
4327 GetTextureTransColG(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
4330 if(NextRow_FT4()) return;
4334 ////////////////////////////////////////////////////////////////////////
4336 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)
4339 int32_t i,j,xmin,xmax,ymin,ymax;
4340 int32_t difX, difY, difX2, difY2;
4341 int32_t posX,posY,YAdjust,clutP;
4344 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
4345 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
4346 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
4347 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
4348 if(drawY>=drawH) return;
4349 if(drawX>=drawW) return;
4351 if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
4355 for(ymin=Ymin;ymin<drawY;ymin++)
4356 if(NextRow_FT4()) return;
4358 clutP=(clY<<10)+clX;
4360 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
4361 YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0);
4365 if(!bCheckMask && !DrawSemiTrans)
4367 for (i=ymin;i<=ymax;i++)
4369 xmin=(left_x >> 16);
4370 xmax=(right_x >> 16);
4379 difX=(right_u-posX)/num;
4380 difY=(right_v-posY)/num;
4385 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4386 xmax--;if(drawW<xmax) xmax=drawW;
4388 for(j=xmin;j<xmax;j+=2)
4390 tC1 = psxVub[(((posY>>16)&TWin.ymask)<<11)+
4391 YAdjust+((posX>>16)&TWin.xmask)];
4392 tC2 = psxVub[((((posY+difY)>>16)&TWin.ymask)<<11)+
4393 YAdjust+(((posX+difX)>>16)&TWin.xmask)];
4394 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
4395 GETLE16(&psxVuw[clutP+tC1])|
4396 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
4402 tC1 = psxVub[((((posY+difY)>>16)&TWin.ymask)<<11)+
4403 YAdjust+((posX>>16)&TWin.xmask)];
4404 GetTextureTransColG_S(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
4407 if(NextRow_FT4()) return;
4415 for (i=ymin;i<=ymax;i++)
4417 xmin=(left_x >> 16);
4418 xmax=(right_x >> 16);
4427 difX=(right_u-posX)/num;
4428 difY=(right_v-posY)/num;
4433 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4434 xmax--;if(drawW<xmax) xmax=drawW;
4436 for(j=xmin;j<xmax;j+=2)
4438 tC1 = psxVub[(((posY>>16)&TWin.ymask)<<11)+
4439 YAdjust+((posX>>16)&TWin.xmask)];
4440 tC2 = psxVub[((((posY+difY)>>16)&TWin.ymask)<<11)+
4441 YAdjust+(((posX+difX)>>16)&TWin.xmask)];
4442 GetTextureTransColG32_SPR((uint32_t *)&psxVuw[(i<<10)+j],
4443 GETLE16(&psxVuw[clutP+tC1])|
4444 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16);
4450 tC1 = psxVub[((((posY+difY)>>16)&TWin.ymask)<<11)+
4451 YAdjust+((posX>>16)&TWin.xmask)];
4452 GetTextureTransColG_SPR(&psxVuw[(i<<10)+j],GETLE16(&psxVuw[clutP+tC1]));
4455 if(NextRow_FT4()) return;
4459 ////////////////////////////////////////////////////////////////////////
4460 // POLY 3 F-SHADED TEX 15 BIT
4461 ////////////////////////////////////////////////////////////////////////
4463 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)
4465 int i,j,xmin,xmax,ymin,ymax;
4466 int32_t difX, difY,difX2, difY2;
4469 if(x1>drawW && x2>drawW && x3>drawW) return;
4470 if(y1>drawH && y2>drawH && y3>drawH) return;
4471 if(x1<drawX && x2<drawX && x3<drawX) return;
4472 if(y1<drawY && y2<drawY && y3<drawY) return;
4473 if(drawY>=drawH) return;
4474 if(drawX>=drawW) return;
4476 if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
4480 for(ymin=Ymin;ymin<drawY;ymin++)
4481 if(NextRow_FT()) return;
4483 difX=delta_right_u;difX2=difX<<1;
4484 difY=delta_right_v;difY2=difY<<1;
4488 if(!bCheckMask && !DrawSemiTrans)
4490 for (i=ymin;i<=ymax;i++)
4492 xmin=(left_x >> 16);
4493 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!
4494 if(drawW<xmax) xmax=drawW;
4502 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4504 for(j=xmin;j<xmax;j+=2)
4506 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
4507 (((int32_t)GETLE16(&psxVuw[((((posY+difY)>>16)+GlobalTextAddrY)<<10)+((posX+difX)>>16)+GlobalTextAddrX]))<<16)|
4508 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+((posX)>>16)+GlobalTextAddrX]));
4514 GetTextureTransColG_S(&psxVuw[(i<<10)+j],
4515 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]));
4527 for (i=ymin;i<=ymax;i++)
4529 xmin=(left_x >> 16);
4530 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!
4531 if(drawW<xmax) xmax=drawW;
4539 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4541 for(j=xmin;j<xmax;j+=2)
4543 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
4544 (((int32_t)GETLE16(&psxVuw[((((posY+difY)>>16)+GlobalTextAddrY)<<10)+((posX+difX)>>16)+GlobalTextAddrX]))<<16)|
4545 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+((posX)>>16)+GlobalTextAddrX]));
4551 GetTextureTransColG(&psxVuw[(i<<10)+j],
4552 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]));
4561 ////////////////////////////////////////////////////////////////////////
4563 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)
4565 int i,j,xmin,xmax,ymin,ymax;
4566 int32_t difX, difY,difX2, difY2;
4569 if(x1>drawW && x2>drawW && x3>drawW) return;
4570 if(y1>drawH && y2>drawH && y3>drawH) return;
4571 if(x1<drawX && x2<drawX && x3<drawX) return;
4572 if(y1<drawY && y2<drawY && y3<drawY) return;
4573 if(drawY>=drawH) return;
4574 if(drawX>=drawW) return;
4576 if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
4580 for(ymin=Ymin;ymin<drawY;ymin++)
4581 if(NextRow_FT()) return;
4583 difX=delta_right_u;difX2=difX<<1;
4584 difY=delta_right_v;difY2=difY<<1;
4588 if(!bCheckMask && !DrawSemiTrans)
4590 for (i=ymin;i<=ymax;i++)
4592 xmin=(left_x >> 16);
4593 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!
4594 if(drawW<xmax) xmax=drawW;
4602 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4604 for(j=xmin;j<xmax;j+=2)
4606 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
4607 (((int32_t)GETLE16(&psxVuw[(((((posY+difY)>>16)&TWin.ymask)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4608 (((posX+difX)>>16)&TWin.xmask)+GlobalTextAddrX+TWin.Position.x0]))<<16)|
4609 GETLE16(&psxVuw[((((posY>>16)&TWin.ymask)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4610 (((posX)>>16)&TWin.xmask)+GlobalTextAddrX+TWin.Position.x0]));
4616 GetTextureTransColG_S(&psxVuw[(i<<10)+j],
4617 GETLE16(&psxVuw[((((posY>>16)&TWin.ymask)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4618 ((posX>>16)&TWin.xmask)+GlobalTextAddrX+TWin.Position.x0]));
4630 for (i=ymin;i<=ymax;i++)
4632 xmin=(left_x >> 16);
4633 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!
4634 if(drawW<xmax) xmax=drawW;
4642 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4644 for(j=xmin;j<xmax;j+=2)
4646 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
4647 (((int32_t)GETLE16(&psxVuw[(((((posY+difY)>>16)&TWin.ymask)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4648 (((posX+difX)>>16)&TWin.xmask)+GlobalTextAddrX+TWin.Position.x0]))<<16)|
4649 GETLE16(&psxVuw[((((posY>>16)&TWin.ymask)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4650 (((posX)>>16)&TWin.xmask)+GlobalTextAddrX+TWin.Position.x0]));
4656 GetTextureTransColG(&psxVuw[(i<<10)+j],
4657 GETLE16(&psxVuw[((((posY>>16)&TWin.ymask)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4658 ((posX>>16)&TWin.xmask)+GlobalTextAddrX+TWin.Position.x0]));
4668 ////////////////////////////////////////////////////////////////////////
4672 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)
4674 drawPoly3TD(x2,y2,x3,y3,x4,y4,
4675 tx2,ty2,tx3,ty3,tx4,ty4);
4676 drawPoly3TD(x1,y1,x2,y2,x4,y4,
4677 tx1,ty1,tx2,ty2,tx4,ty4);
4684 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)
4687 int32_t i,j,xmin,xmax,ymin,ymax;
4688 int32_t difX, difY, difX2, difY2;
4691 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
4692 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
4693 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
4694 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
4695 if(drawY>=drawH) return;
4696 if(drawX>=drawW) return;
4698 if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
4702 for(ymin=Ymin;ymin<drawY;ymin++)
4703 if(NextRow_FT4()) return;
4707 if(!bCheckMask && !DrawSemiTrans)
4709 for (i=ymin;i<=ymax;i++)
4711 xmin=(left_x >> 16);
4712 xmax=(right_x >> 16);
4721 difX=(right_u-posX)/num;
4722 difY=(right_v-posY)/num;
4727 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4728 xmax--;if(drawW<xmax) xmax=drawW;
4730 for(j=xmin;j<xmax;j+=2)
4732 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
4733 (((int32_t)GETLE16(&psxVuw[((((posY+difY)>>16)+GlobalTextAddrY)<<10)+((posX+difX)>>16)+GlobalTextAddrX]))<<16)|
4734 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+((posX)>>16)+GlobalTextAddrX]));
4740 GetTextureTransColG_S(&psxVuw[(i<<10)+j],
4741 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]));
4743 if(NextRow_FT4()) return;
4750 for (i=ymin;i<=ymax;i++)
4752 xmin=(left_x >> 16);
4753 xmax=(right_x >> 16);
4762 difX=(right_u-posX)/num;
4763 difY=(right_v-posY)/num;
4768 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4769 xmax--;if(drawW<xmax) xmax=drawW;
4771 for(j=xmin;j<xmax;j+=2)
4773 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
4774 (((int32_t)GETLE16(&psxVuw[((((posY+difY)>>16)+GlobalTextAddrY)<<10)+((posX+difX)>>16)+GlobalTextAddrX]))<<16)|
4775 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+((posX)>>16)+GlobalTextAddrX]));
4781 GetTextureTransColG(&psxVuw[(i<<10)+j],
4782 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]));
4784 if(NextRow_FT4()) return;
4788 ////////////////////////////////////////////////////////////////////////
4790 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)
4793 int32_t i,j,xmin,xmax,ymin,ymax;
4794 int32_t difX, difY, difX2, difY2;
4797 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
4798 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
4799 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
4800 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
4801 if(drawY>=drawH) return;
4802 if(drawX>=drawW) return;
4804 if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
4808 for(ymin=Ymin;ymin<drawY;ymin++)
4809 if(NextRow_FT4()) return;
4813 if(!bCheckMask && !DrawSemiTrans)
4815 for (i=ymin;i<=ymax;i++)
4817 xmin=(left_x >> 16);
4818 xmax=(right_x >> 16);
4827 difX=(right_u-posX)/num;
4828 difY=(right_v-posY)/num;
4833 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4834 xmax--;if(drawW<xmax) xmax=drawW;
4836 for(j=xmin;j<xmax;j+=2)
4838 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
4839 (((int32_t)GETLE16(&psxVuw[(((((posY+difY)>>16)&TWin.ymask)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4840 (((posX+difX)>>16)&TWin.xmask)+GlobalTextAddrX+TWin.Position.x0]))<<16)|
4841 GETLE16(&psxVuw[((((posY>>16)&TWin.ymask)+GlobalTextAddrY)<<10)+TWin.Position.y0+
4842 ((posX>>16)&TWin.xmask)+GlobalTextAddrX+TWin.Position.x0]));
4848 GetTextureTransColG_S(&psxVuw[(i<<10)+j],
4849 GETLE16(&psxVuw[((((posY>>16)&TWin.ymask)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4850 ((posX>>16)&TWin.xmask)+GlobalTextAddrX+TWin.Position.x0]));
4852 if(NextRow_FT4()) return;
4859 for (i=ymin;i<=ymax;i++)
4861 xmin=(left_x >> 16);
4862 xmax=(right_x >> 16);
4871 difX=(right_u-posX)/num;
4872 difY=(right_v-posY)/num;
4877 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4878 xmax--;if(drawW<xmax) xmax=drawW;
4880 for(j=xmin;j<xmax;j+=2)
4882 GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
4883 (((int32_t)GETLE16(&psxVuw[(((((posY+difY)>>16)&TWin.ymask)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4884 (((posX+difX)>>16)&TWin.xmask)+GlobalTextAddrX+TWin.Position.x0]))<<16)|
4885 GETLE16(&psxVuw[((((posY>>16)&TWin.ymask)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4886 ((posX>>16)&TWin.xmask)+GlobalTextAddrX+TWin.Position.x0]));
4892 GetTextureTransColG(&psxVuw[(i<<10)+j],
4893 GETLE16(&psxVuw[((((posY>>16)&TWin.ymask)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4894 ((posX>>16)&TWin.xmask)+GlobalTextAddrX+TWin.Position.x0]));
4896 if(NextRow_FT4()) return;
4900 ////////////////////////////////////////////////////////////////////////
4902 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)
4905 int32_t i,j,xmin,xmax,ymin,ymax;
4906 int32_t difX, difY, difX2, difY2;
4909 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
4910 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
4911 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
4912 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
4913 if(drawY>=drawH) return;
4914 if(drawX>=drawW) return;
4916 if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
4920 for(ymin=Ymin;ymin<drawY;ymin++)
4921 if(NextRow_FT4()) return;
4925 if(!bCheckMask && !DrawSemiTrans)
4927 for (i=ymin;i<=ymax;i++)
4929 xmin=(left_x >> 16);
4930 xmax=(right_x >> 16);
4939 difX=(right_u-posX)/num;
4940 difY=(right_v-posY)/num;
4945 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4946 xmax--;if(drawW<xmax) xmax=drawW;
4948 for(j=xmin;j<xmax;j+=2)
4950 GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
4951 (((int32_t)GETLE16(&psxVuw[(((((posY+difY)>>16)&TWin.ymask)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4952 (((posX+difX)>>16)&TWin.xmask)+GlobalTextAddrX+TWin.Position.x0]))<<16)|
4953 GETLE16(&psxVuw[((((posY>>16)&TWin.ymask)+GlobalTextAddrY)<<10)+TWin.Position.y0+
4954 ((posX>>16)&TWin.xmask)+GlobalTextAddrX+TWin.Position.x0]));
4960 GetTextureTransColG_S(&psxVuw[(i<<10)+j],
4961 GETLE16(&psxVuw[((((posY>>16)&TWin.ymask)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4962 ((posX>>16)&TWin.xmask)+GlobalTextAddrX+TWin.Position.x0]));
4964 if(NextRow_FT4()) return;
4971 for (i=ymin;i<=ymax;i++)
4973 xmin=(left_x >> 16);
4974 xmax=(right_x >> 16);
4983 difX=(right_u-posX)/num;
4984 difY=(right_v-posY)/num;
4989 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
4990 xmax--;if(drawW<xmax) xmax=drawW;
4992 for(j=xmin;j<xmax;j+=2)
4994 GetTextureTransColG32_SPR((uint32_t *)&psxVuw[(i<<10)+j],
4995 (((int32_t)GETLE16(&psxVuw[(((((posY+difY)>>16)&TWin.ymask)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4996 (((posX+difX)>>16)&TWin.xmask)+GlobalTextAddrX+TWin.Position.x0]))<<16)|
4997 GETLE16(&psxVuw[((((posY>>16)&TWin.ymask)+GlobalTextAddrY+TWin.Position.y0)<<10)+
4998 ((posX>>16)&TWin.xmask)+GlobalTextAddrX+TWin.Position.x0]));
5004 GetTextureTransColG_SPR(&psxVuw[(i<<10)+j],
5005 GETLE16(&psxVuw[((((posY>>16)&TWin.ymask)+GlobalTextAddrY+TWin.Position.y0)<<10)+
5006 ((posX>>16)&TWin.xmask)+GlobalTextAddrX+TWin.Position.x0]));
5008 if(NextRow_FT4()) return;
5012 ////////////////////////////////////////////////////////////////////////
5013 // POLY 3/4 G-SHADED
5014 ////////////////////////////////////////////////////////////////////////
5016 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)
5018 int i,j,xmin,xmax,ymin,ymax;
5019 int32_t cR1,cG1,cB1;
5020 int32_t difR,difB,difG,difR2,difB2,difG2;
5022 if(x1>drawW && x2>drawW && x3>drawW) return;
5023 if(y1>drawH && y2>drawH && y3>drawH) return;
5024 if(x1<drawX && x2<drawX && x3<drawX) return;
5025 if(y1<drawY && y2<drawY && y3<drawY) return;
5026 if(drawY>=drawH) return;
5027 if(drawX>=drawW) return;
5029 if(!SetupSections_G(x1,y1,x2,y2,x3,y3,rgb1,rgb2,rgb3)) return;
5033 for(ymin=Ymin;ymin<drawY;ymin++)
5034 if(NextRow_G()) return;
5045 if(!bCheckMask && !DrawSemiTrans && iDither!=2)
5047 for (i=ymin;i<=ymax;i++)
5049 xmin=(left_x >> 16);
5050 xmax=(right_x >> 16)-1;if(drawW<xmax) xmax=drawW;
5059 {j=drawX-xmin;xmin=drawX;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
5061 for(j=xmin;j<xmax;j+=2)
5063 PUTLE32(((uint32_t *)&psxVuw[(i<<10)+j]),
5064 ((((cR1+difR) <<7)&0x7c000000)|(((cG1+difG) << 2)&0x03e00000)|(((cB1+difB)>>3)&0x001f0000)|
5065 (((cR1) >> 9)&0x7c00)|(((cG1) >> 14)&0x03e0)|(((cB1) >> 19)&0x001f))|lSetMask);
5072 PUTLE16(&psxVuw[(i<<10)+j], (((cR1 >> 9)&0x7c00)|((cG1 >> 14)&0x03e0)|((cB1 >> 19)&0x001f))|sSetMask);
5074 if(NextRow_G()) return;
5082 for (i=ymin;i<=ymax;i++)
5084 xmin=(left_x >> 16);
5085 xmax=(right_x >> 16)-1;if(drawW<xmax) xmax=drawW;
5094 {j=drawX-xmin;xmin=drawX;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
5096 for(j=xmin;j<=xmax;j++)
5098 GetShadeTransCol_Dither(&psxVuw[(i<<10)+j],(cB1>>16),(cG1>>16),(cR1>>16));
5105 if(NextRow_G()) return;
5108 for (i=ymin;i<=ymax;i++)
5110 xmin=(left_x >> 16);
5111 xmax=(right_x >> 16)-1;if(drawW<xmax) xmax=drawW;
5120 {j=drawX-xmin;xmin=drawX;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
5122 for(j=xmin;j<=xmax;j++)
5124 GetShadeTransCol(&psxVuw[(i<<10)+j],((cR1 >> 9)&0x7c00)|((cG1 >> 14)&0x03e0)|((cB1 >> 19)&0x001f));
5131 if(NextRow_G()) return;
5136 ////////////////////////////////////////////////////////////////////////
5138 static void drawPoly3G(int32_t rgb1, int32_t rgb2, int32_t rgb3)
5140 drawPoly3Gi(lx0,ly0,lx1,ly1,lx2,ly2,rgb1,rgb2,rgb3);
5143 // draw two g-shaded tris for right psx shading emulation
5145 static void drawPoly4G(int32_t rgb1, int32_t rgb2, int32_t rgb3, int32_t rgb4)
5147 drawPoly3Gi(lx1,ly1,lx3,ly3,lx2,ly2,
5149 drawPoly3Gi(lx0,ly0,lx1,ly1,lx2,ly2,
5153 ////////////////////////////////////////////////////////////////////////
5154 // POLY 3/4 G-SHADED TEX PAL4
5155 ////////////////////////////////////////////////////////////////////////
5157 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)
5159 int i,j,xmin,xmax,ymin,ymax;
5160 int32_t cR1,cG1,cB1;
5161 int32_t difR,difB,difG,difR2,difB2,difG2;
5162 int32_t difX, difY,difX2, difY2;
5163 int32_t posX,posY,YAdjust,clutP,XAdjust;
5166 if(x1>drawW && x2>drawW && x3>drawW) return;
5167 if(y1>drawH && y2>drawH && y3>drawH) return;
5168 if(x1<drawX && x2<drawX && x3<drawX) return;
5169 if(y1<drawY && y2<drawY && y3<drawY) return;
5170 if(drawY>=drawH) return;
5171 if(drawX>=drawW) return;
5173 if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
5177 for(ymin=Ymin;ymin<drawY;ymin++)
5178 if(NextRow_GT()) return;
5180 clutP=(clY<<10)+clX;
5182 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
5191 difX=delta_right_u;difX2=difX<<1;
5192 difY=delta_right_v;difY2=difY<<1;
5196 if(!bCheckMask && !DrawSemiTrans && !iDither)
5198 for (i=ymin;i<=ymax;i++)
5200 xmin=((left_x) >> 16);
5201 xmax=((right_x) >> 16)-1; //!!!!!!!!!!!!!
5202 if(drawW<xmax) xmax=drawW;
5213 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
5215 for(j=xmin;j<xmax;j+=2)
5218 tC1 = psxVub[((posY>>5)&0xFFFFF800)+YAdjust+(XAdjust>>1)];
5219 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
5220 XAdjust=((posX+difX)>>16);
5221 tC2 = psxVub[(((posY+difY)>>5)&(int32_t)0xFFFFF800)+YAdjust+
5223 tC2=(tC2>>((XAdjust&1)<<2))&0xf;
5225 GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
5226 GETLE16(&psxVuw[clutP+tC1])|
5227 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16,
5228 (cB1>>16)|((cB1+difB)&0xff0000),
5229 (cG1>>16)|((cG1+difG)&0xff0000),
5230 (cR1>>16)|((cR1+difR)&0xff0000));
5240 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(XAdjust>>1)];
5241 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
5242 GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
5243 GETLE16(&psxVuw[clutP+tC1]),
5244 (cB1>>16),(cG1>>16),(cR1>>16));
5257 for (i=ymin;i<=ymax;i++)
5259 xmin=(left_x >> 16);
5260 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!
5261 if(drawW<xmax) xmax=drawW;
5272 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
5274 for(j=xmin;j<=xmax;j++)
5277 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(XAdjust>>1)];
5278 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
5280 GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
5281 GETLE16(&psxVuw[clutP+tC1]),
5282 (cB1>>16),(cG1>>16),(cR1>>16));
5284 GetTextureTransColGX(&psxVuw[(i<<10)+j],
5285 GETLE16(&psxVuw[clutP+tC1]),
5286 (cB1>>16),(cG1>>16),(cR1>>16));
5301 ////////////////////////////////////////////////////////////////////////
5303 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)
5305 int i,j,xmin,xmax,ymin,ymax,n_xi,n_yi,TXV;
5306 int32_t cR1,cG1,cB1;
5307 int32_t difR,difB,difG,difR2,difB2,difG2;
5308 int32_t difX, difY,difX2, difY2;
5309 int32_t posX,posY,YAdjust,clutP,XAdjust;
5312 if(x1>drawW && x2>drawW && x3>drawW) return;
5313 if(y1>drawH && y2>drawH && y3>drawH) return;
5314 if(x1<drawX && x2<drawX && x3<drawX) return;
5315 if(y1<drawY && y2<drawY && y3<drawY) return;
5316 if(drawY>=drawH) return;
5317 if(drawX>=drawW) return;
5319 if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
5323 for(ymin=Ymin;ymin<drawY;ymin++)
5324 if(NextRow_GT()) return;
5326 clutP=(clY<<10)+clX;
5328 YAdjust=(GlobalTextAddrY<<10)+GlobalTextAddrX;
5337 difX=delta_right_u;difX2=difX<<1;
5338 difY=delta_right_v;difY2=difY<<1;
5342 if(!bCheckMask && !DrawSemiTrans && !iDither)
5344 for (i=ymin;i<=ymax;i++)
5346 xmin=((left_x) >> 16);
5347 xmax=((right_x) >> 16)-1; //!!!!!!!!!!!!!
5348 if(drawW<xmax) xmax=drawW;
5359 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
5361 for(j=xmin;j<xmax;j+=2)
5366 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
5367 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
5369 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
5371 XAdjust=((posX+difX)>>16);
5373 TXV=(posY+difY)>>16;
5374 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
5375 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
5377 tC2= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
5379 GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
5380 GETLE16(&psxVuw[clutP+tC1])|
5381 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16,
5382 (cB1>>16)|((cB1+difB)&0xff0000),
5383 (cG1>>16)|((cG1+difG)&0xff0000),
5384 (cR1>>16)|((cR1+difR)&0xff0000));
5396 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
5397 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
5399 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
5401 GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
5402 GETLE16(&psxVuw[clutP+tC1]),
5403 (cB1>>16),(cG1>>16),(cR1>>16));
5416 for (i=ymin;i<=ymax;i++)
5418 xmin=(left_x >> 16);
5419 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!
5420 if(drawW<xmax) xmax=drawW;
5431 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
5433 for(j=xmin;j<=xmax;j++)
5438 n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
5439 n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
5441 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((XAdjust & 0x03)<<2)) & 0x0f ;
5444 GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
5445 GETLE16(&psxVuw[clutP+tC1]),
5446 (cB1>>16),(cG1>>16),(cR1>>16));
5448 GetTextureTransColGX(&psxVuw[(i<<10)+j],
5449 GETLE16(&psxVuw[clutP+tC1]),
5450 (cB1>>16),(cG1>>16),(cR1>>16));
5465 ////////////////////////////////////////////////////////////////////////
5467 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)
5469 int i,j,xmin,xmax,ymin,ymax;
5470 int32_t cR1,cG1,cB1;
5471 int32_t difR,difB,difG,difR2,difB2,difG2;
5472 int32_t difX, difY,difX2, difY2;
5473 int32_t posX,posY,YAdjust,clutP,XAdjust;
5476 if(x1>drawW && x2>drawW && x3>drawW) return;
5477 if(y1>drawH && y2>drawH && y3>drawH) return;
5478 if(x1<drawX && x2<drawX && x3<drawX) return;
5479 if(y1<drawY && y2<drawY && y3<drawY) return;
5480 if(drawY>=drawH) return;
5481 if(drawX>=drawW) return;
5483 if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
5487 for(ymin=Ymin;ymin<drawY;ymin++)
5488 if(NextRow_GT()) return;
5490 clutP=(clY<<10)+clX;
5492 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
5493 YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0>>1);
5502 difX=delta_right_u;difX2=difX<<1;
5503 difY=delta_right_v;difY2=difY<<1;
5507 if(!bCheckMask && !DrawSemiTrans && !iDither)
5509 for (i=ymin;i<=ymax;i++)
5511 xmin=((left_x) >> 16);
5512 xmax=((right_x) >> 16)-1; //!!!!!!!!!!!!!
5513 if(drawW<xmax) xmax=drawW;
5524 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
5526 for(j=xmin;j<xmax;j+=2)
5528 XAdjust=(posX>>16)&TWin.xmask;
5529 tC1 = psxVub[(((posY>>16)&TWin.ymask)<<11)+
5530 YAdjust+(XAdjust>>1)];
5531 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
5532 XAdjust=((posX+difX)>>16)&TWin.xmask;
5533 tC2 = psxVub[((((posY+difY)>>16)&TWin.ymask)<<11)+
5534 YAdjust+(XAdjust>>1)];
5535 tC2=(tC2>>((XAdjust&1)<<2))&0xf;
5536 GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
5537 GETLE16(&psxVuw[clutP+tC1])|
5538 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16,
5539 (cB1>>16)|((cB1+difB)&0xff0000),
5540 (cG1>>16)|((cG1+difG)&0xff0000),
5541 (cR1>>16)|((cR1+difR)&0xff0000));
5550 XAdjust=(posX>>16)&TWin.xmask;
5551 tC1 = psxVub[(((posY>>16)&TWin.ymask)<<11)+
5552 YAdjust+(XAdjust>>1)];
5553 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
5554 GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
5555 GETLE16(&psxVuw[clutP+tC1]),
5556 (cB1>>16),(cG1>>16),(cR1>>16));
5569 for (i=ymin;i<=ymax;i++)
5571 xmin=(left_x >> 16);
5572 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!
5573 if(drawW<xmax) xmax=drawW;
5584 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
5586 for(j=xmin;j<=xmax;j++)
5588 XAdjust=(posX>>16)&TWin.xmask;
5589 tC1 = psxVub[(((posY>>16)&TWin.ymask)<<11)+
5590 YAdjust+(XAdjust>>1)];
5591 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
5593 GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
5594 GETLE16(&psxVuw[clutP+tC1]),
5595 (cB1>>16),(cG1>>16),(cR1>>16));
5597 GetTextureTransColGX(&psxVuw[(i<<10)+j],
5598 GETLE16(&psxVuw[clutP+tC1]),
5599 (cB1>>16),(cG1>>16),(cR1>>16));
5614 ////////////////////////////////////////////////////////////////////////
5616 // note: the psx is doing g-shaded quads as two g-shaded tris,
5617 // like the following func... sadly texturing is not 100%
5618 // correct that way, so small texture distortions can
5621 static void drawPoly4TGEx4_TRI_IL(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
5622 short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
5623 short clX, short clY,
5624 int32_t col1, int32_t col2, int32_t col3, int32_t col4)
5626 drawPoly3TGEx4_IL(x2,y2,x3,y3,x4,y4,
5627 tx2,ty2,tx3,ty3,tx4,ty4,
5630 drawPoly3TGEx4_IL(x1,y1,x2,y2,x4,y4,
5631 tx1,ty1,tx2,ty2,tx4,ty4,
5638 static void drawPoly4TGEx4_TRI(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
5639 short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
5640 short clX, short clY,
5641 int32_t col1, int32_t col2, int32_t col3, int32_t col4)
5643 drawPoly3TGEx4(x2,y2,x3,y3,x4,y4,
5644 tx2,ty2,tx3,ty3,tx4,ty4,
5647 drawPoly3TGEx4(x1,y1,x2,y2,x4,y4,
5648 tx1,ty1,tx2,ty2,tx4,ty4,
5655 ////////////////////////////////////////////////////////////////////////
5657 static void drawPoly4TGEx4(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
5658 short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
5659 short clX, short clY,
5660 int32_t col1, int32_t col2, int32_t col4, int32_t col3)
5663 int32_t i,j,xmin,xmax,ymin,ymax;
5664 int32_t cR1,cG1,cB1;
5665 int32_t difR,difB,difG,difR2,difB2,difG2;
5666 int32_t difX, difY, difX2, difY2;
5667 int32_t posX,posY,YAdjust,clutP,XAdjust;
5670 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
5671 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
5672 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
5673 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
5674 if(drawY>=drawH) return;
5675 if(drawX>=drawW) return;
5677 if(!SetupSections_GT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4,col1,col2,col3,col4)) return;
5681 for(ymin=Ymin;ymin<drawY;ymin++)
5682 if(NextRow_GT4()) return;
5684 clutP=(clY<<10)+clX;
5686 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
5691 if(!bCheckMask && !DrawSemiTrans && !iDither)
5693 for (i=ymin;i<=ymax;i++)
5695 xmin=(left_x >> 16);
5696 xmax=(right_x >> 16);
5705 difX=(right_u-posX)/num;
5706 difY=(right_v-posY)/num;
5713 difR=(right_R-cR1)/num;
5714 difG=(right_G-cG1)/num;
5715 difB=(right_B-cB1)/num;
5721 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
5722 xmax--;if(drawW<xmax) xmax=drawW;
5724 for(j=xmin;j<xmax;j+=2)
5727 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(XAdjust>>1)];
5728 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
5729 XAdjust=((posX+difX)>>16);
5730 tC2 = psxVub[(((posY+difY)>>5)&(int32_t)0xFFFFF800)+YAdjust+
5732 tC2=(tC2>>((XAdjust&1)<<2))&0xf;
5734 GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
5735 GETLE16(&psxVuw[clutP+tC1])|
5736 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16,
5737 (cB1>>16)|((cB1+difB)&0xff0000),
5738 (cG1>>16)|((cG1+difG)&0xff0000),
5739 (cR1>>16)|((cR1+difR)&0xff0000));
5749 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+
5751 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
5753 GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
5754 GETLE16(&psxVuw[clutP+tC1]),
5755 (cB1>>16),(cG1>>16),(cR1>>16));
5758 if(NextRow_GT4()) return;
5765 for (i=ymin;i<=ymax;i++)
5767 xmin=(left_x >> 16);
5768 xmax=(right_x >> 16);
5777 difX=(right_u-posX)/num;
5778 difY=(right_v-posY)/num;
5785 difR=(right_R-cR1)/num;
5786 difG=(right_G-cG1)/num;
5787 difB=(right_B-cB1)/num;
5793 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
5794 xmax--;if(drawW<xmax) xmax=drawW;
5796 for(j=xmin;j<=xmax;j++)
5799 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+
5801 tC1=(tC1>>((XAdjust&1)<<2))&0xf;
5803 GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
5804 GETLE16(&psxVuw[clutP+tC1]),
5805 (cB1>>16),(cG1>>16),(cR1>>16));
5807 GetTextureTransColGX(&psxVuw[(i<<10)+j],
5808 GETLE16(&psxVuw[clutP+tC1]),
5809 (cB1>>16),(cG1>>16),(cR1>>16));
5817 if(NextRow_GT4()) return;
5821 ////////////////////////////////////////////////////////////////////////
5823 static void drawPoly4TGEx4_TW(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
5824 short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
5825 short clX, short clY,
5826 int32_t col1, int32_t col2, int32_t col3, int32_t col4)
5828 drawPoly3TGEx4_TW(x2,y2,x3,y3,x4,y4,
5829 tx2,ty2,tx3,ty3,tx4,ty4,
5833 drawPoly3TGEx4_TW(x1,y1,x2,y2,x4,y4,
5834 tx1,ty1,tx2,ty2,tx4,ty4,
5839 ////////////////////////////////////////////////////////////////////////
5840 // POLY 3/4 G-SHADED TEX PAL8
5841 ////////////////////////////////////////////////////////////////////////
5843 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)
5845 int i,j,xmin,xmax,ymin,ymax;
5846 int32_t cR1,cG1,cB1;
5847 int32_t difR,difB,difG,difR2,difB2,difG2;
5848 int32_t difX, difY,difX2, difY2;
5849 int32_t posX,posY,YAdjust,clutP;
5852 if(x1>drawW && x2>drawW && x3>drawW) return;
5853 if(y1>drawH && y2>drawH && y3>drawH) return;
5854 if(x1<drawX && x2<drawX && x3<drawX) return;
5855 if(y1<drawY && y2<drawY && y3<drawY) return;
5856 if(drawY>=drawH) return;
5857 if(drawX>=drawW) return;
5859 if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
5863 for(ymin=Ymin;ymin<drawY;ymin++)
5864 if(NextRow_GT()) return;
5866 clutP=(clY<<10)+clX;
5868 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
5876 difX=delta_right_u;difX2=difX<<1;
5877 difY=delta_right_v;difY2=difY<<1;
5881 if(!bCheckMask && !DrawSemiTrans && !iDither)
5883 for (i=ymin;i<=ymax;i++)
5885 xmin=(left_x >> 16);
5886 xmax=(right_x >> 16)-1; // !!!!!!!!!!!!!
5887 if(drawW<xmax) xmax=drawW;
5898 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
5900 for(j=xmin;j<xmax;j+=2)
5902 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+((posX>>16))];
5903 tC2 = psxVub[(((posY+difY)>>5)&(int32_t)0xFFFFF800)+YAdjust+
5904 (((posX+difX)>>16))];
5905 GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
5906 GETLE16(&psxVuw[clutP+tC1])|
5907 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16,
5908 (cB1>>16)|((cB1+difB)&0xff0000),
5909 (cG1>>16)|((cG1+difG)&0xff0000),
5910 (cR1>>16)|((cR1+difR)&0xff0000));
5919 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+((posX>>16))];
5920 GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
5921 GETLE16(&psxVuw[clutP+tC1]),
5922 (cB1>>16),(cG1>>16),(cR1>>16));
5935 for (i=ymin;i<=ymax;i++)
5937 xmin=(left_x >> 16);
5938 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!!!!!!
5939 if(drawW<xmax) xmax=drawW;
5950 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
5952 for(j=xmin;j<=xmax;j++)
5954 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+((posX>>16))];
5956 GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
5957 GETLE16(&psxVuw[clutP+tC1]),
5958 (cB1>>16),(cG1>>16),(cR1>>16));
5960 GetTextureTransColGX(&psxVuw[(i<<10)+j],
5961 GETLE16(&psxVuw[clutP+tC1]),
5962 (cB1>>16),(cG1>>16),(cR1>>16));
5977 ////////////////////////////////////////////////////////////////////////
5979 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)
5981 int i,j,xmin,xmax,ymin,ymax,n_xi,n_yi,TXV,TXU;
5982 int32_t cR1,cG1,cB1;
5983 int32_t difR,difB,difG,difR2,difB2,difG2;
5984 int32_t difX, difY,difX2, difY2;
5985 int32_t posX,posY,YAdjust,clutP;
5988 if(x1>drawW && x2>drawW && x3>drawW) return;
5989 if(y1>drawH && y2>drawH && y3>drawH) return;
5990 if(x1<drawX && x2<drawX && x3<drawX) return;
5991 if(y1<drawY && y2<drawY && y3<drawY) return;
5992 if(drawY>=drawH) return;
5993 if(drawX>=drawW) return;
5995 if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
5999 for(ymin=Ymin;ymin<drawY;ymin++)
6000 if(NextRow_GT()) return;
6002 clutP=(clY<<10)+clX;
6004 YAdjust=(GlobalTextAddrY<<10)+GlobalTextAddrX;
6012 difX=delta_right_u;difX2=difX<<1;
6013 difY=delta_right_v;difY2=difY<<1;
6017 if(!bCheckMask && !DrawSemiTrans && !iDither)
6019 for (i=ymin;i<=ymax;i++)
6021 xmin=(left_x >> 16);
6022 xmax=(right_x >> 16)-1; // !!!!!!!!!!!!!
6023 if(drawW<xmax) xmax=drawW;
6034 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
6036 for(j=xmin;j<xmax;j+=2)
6040 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
6041 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
6043 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
6045 TXU=(posX+difX)>>16;
6046 TXV=(posY+difY)>>16;
6047 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
6048 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
6050 tC2= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
6052 GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
6053 GETLE16(&psxVuw[clutP+tC1])|
6054 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16,
6055 (cB1>>16)|((cB1+difB)&0xff0000),
6056 (cG1>>16)|((cG1+difG)&0xff0000),
6057 (cR1>>16)|((cR1+difR)&0xff0000));
6068 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
6069 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
6071 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
6073 GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
6074 GETLE16(&psxVuw[clutP+tC1]),
6075 (cB1>>16),(cG1>>16),(cR1>>16));
6088 for (i=ymin;i<=ymax;i++)
6090 xmin=(left_x >> 16);
6091 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!!!!!!
6092 if(drawW<xmax) xmax=drawW;
6103 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
6105 for(j=xmin;j<=xmax;j++)
6109 n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
6110 n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
6112 tC1= (GETLE16(&psxVuw[(n_yi<<10)+YAdjust+n_xi]) >> ((TXU & 0x01)<<3)) & 0xff;
6115 GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
6116 GETLE16(&psxVuw[clutP+tC1]),
6117 (cB1>>16),(cG1>>16),(cR1>>16));
6119 GetTextureTransColGX(&psxVuw[(i<<10)+j],
6120 GETLE16(&psxVuw[clutP+tC1]),
6121 (cB1>>16),(cG1>>16),(cR1>>16));
6136 ////////////////////////////////////////////////////////////////////////
6138 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)
6140 int i,j,xmin,xmax,ymin,ymax;
6141 int32_t cR1,cG1,cB1;
6142 int32_t difR,difB,difG,difR2,difB2,difG2;
6143 int32_t difX, difY,difX2, difY2;
6144 int32_t posX,posY,YAdjust,clutP;
6147 if(x1>drawW && x2>drawW && x3>drawW) return;
6148 if(y1>drawH && y2>drawH && y3>drawH) return;
6149 if(x1<drawX && x2<drawX && x3<drawX) return;
6150 if(y1<drawY && y2<drawY && y3<drawY) return;
6151 if(drawY>=drawH) return;
6152 if(drawX>=drawW) return;
6154 if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
6158 for(ymin=Ymin;ymin<drawY;ymin++)
6159 if(NextRow_GT()) return;
6161 clutP=(clY<<10)+clX;
6163 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
6164 YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0);
6172 difX=delta_right_u;difX2=difX<<1;
6173 difY=delta_right_v;difY2=difY<<1;
6177 if(!bCheckMask && !DrawSemiTrans && !iDither)
6179 for (i=ymin;i<=ymax;i++)
6181 xmin=(left_x >> 16);
6182 xmax=(right_x >> 16)-1; // !!!!!!!!!!!!!
6183 if(drawW<xmax) xmax=drawW;
6194 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
6196 for(j=xmin;j<xmax;j+=2)
6198 tC1 = psxVub[(((posY>>16)&TWin.ymask)<<11)+
6199 YAdjust+((posX>>16)&TWin.xmask)];
6200 tC2 = psxVub[((((posY+difY)>>16)&TWin.ymask)<<11)+
6201 YAdjust+(((posX+difX)>>16)&TWin.xmask)];
6203 GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
6204 GETLE16(&psxVuw[clutP+tC1])|
6205 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16,
6206 (cB1>>16)|((cB1+difB)&0xff0000),
6207 (cG1>>16)|((cG1+difG)&0xff0000),
6208 (cR1>>16)|((cR1+difR)&0xff0000));
6217 tC1 = psxVub[(((posY>>16)&TWin.ymask)<<11)+
6218 YAdjust+((posX>>16)&TWin.xmask)];
6219 GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
6220 GETLE16(&psxVuw[clutP+tC1]),
6221 (cB1>>16),(cG1>>16),(cR1>>16));
6234 for (i=ymin;i<=ymax;i++)
6236 xmin=(left_x >> 16);
6237 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!!!!!!
6238 if(drawW<xmax) xmax=drawW;
6249 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
6251 for(j=xmin;j<=xmax;j++)
6253 tC1 = psxVub[(((posY>>16)&TWin.ymask)<<11)+
6254 YAdjust+((posX>>16)&TWin.xmask)];
6256 GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
6257 GETLE16(&psxVuw[clutP+tC1]),
6258 (cB1>>16),(cG1>>16),(cR1>>16));
6260 GetTextureTransColGX(&psxVuw[(i<<10)+j],
6261 GETLE16(&psxVuw[clutP+tC1]),
6262 (cB1>>16),(cG1>>16),(cR1>>16));
6277 ////////////////////////////////////////////////////////////////////////
6279 // note: two g-shaded tris: small texture distortions can happen
6281 static void drawPoly4TGEx8_TRI_IL(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
6282 short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
6283 short clX, short clY,
6284 int32_t col1, int32_t col2, int32_t col3, int32_t col4)
6286 drawPoly3TGEx8_IL(x2,y2,x3,y3,x4,y4,
6287 tx2,ty2,tx3,ty3,tx4,ty4,
6290 drawPoly3TGEx8_IL(x1,y1,x2,y2,x4,y4,
6291 tx1,ty1,tx2,ty2,tx4,ty4,
6298 static void drawPoly4TGEx8_TRI(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
6299 short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
6300 short clX, short clY,
6301 int32_t col1, int32_t col2, int32_t col3, int32_t col4)
6303 drawPoly3TGEx8(x2,y2,x3,y3,x4,y4,
6304 tx2,ty2,tx3,ty3,tx4,ty4,
6307 drawPoly3TGEx8(x1,y1,x2,y2,x4,y4,
6308 tx1,ty1,tx2,ty2,tx4,ty4,
6315 static void drawPoly4TGEx8(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
6316 short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
6317 short clX, short clY,
6318 int32_t col1, int32_t col2, int32_t col4, int32_t col3)
6321 int32_t i,j,xmin,xmax,ymin,ymax;
6322 int32_t cR1,cG1,cB1;
6323 int32_t difR,difB,difG,difR2,difB2,difG2;
6324 int32_t difX, difY, difX2, difY2;
6325 int32_t posX,posY,YAdjust,clutP;
6328 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
6329 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
6330 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
6331 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
6332 if(drawY>=drawH) return;
6333 if(drawX>=drawW) return;
6335 if(!SetupSections_GT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4,col1,col2,col3,col4)) return;
6339 for(ymin=Ymin;ymin<drawY;ymin++)
6340 if(NextRow_GT4()) return;
6342 clutP=(clY<<10)+clX;
6344 YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
6348 if(!bCheckMask && !DrawSemiTrans && !iDither)
6350 for (i=ymin;i<=ymax;i++)
6352 xmin=(left_x >> 16);
6353 xmax=(right_x >> 16);
6362 difX=(right_u-posX)/num;
6363 difY=(right_v-posY)/num;
6370 difR=(right_R-cR1)/num;
6371 difG=(right_G-cG1)/num;
6372 difB=(right_B-cB1)/num;
6378 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
6379 xmax--;if(drawW<xmax) xmax=drawW;
6381 for(j=xmin;j<xmax;j+=2)
6383 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(posX>>16)];
6384 tC2 = psxVub[(((posY+difY)>>5)&(int32_t)0xFFFFF800)+YAdjust+
6387 GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
6388 GETLE16(&psxVuw[clutP+tC1])|
6389 ((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16,
6390 (cB1>>16)|((cB1+difB)&0xff0000),
6391 (cG1>>16)|((cG1+difG)&0xff0000),
6392 (cR1>>16)|((cR1+difR)&0xff0000));
6401 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(posX>>16)];
6402 GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
6403 GETLE16(&psxVuw[clutP+tC1]),
6404 (cB1>>16),(cG1>>16),(cR1>>16));
6407 if(NextRow_GT4()) return;
6414 for (i=ymin;i<=ymax;i++)
6416 xmin=(left_x >> 16);
6417 xmax=(right_x >> 16);
6426 difX=(right_u-posX)/num;
6427 difY=(right_v-posY)/num;
6434 difR=(right_R-cR1)/num;
6435 difG=(right_G-cG1)/num;
6436 difB=(right_B-cB1)/num;
6442 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
6443 xmax--;if(drawW<xmax) xmax=drawW;
6445 for(j=xmin;j<=xmax;j++)
6447 tC1 = psxVub[((posY>>5)&(int32_t)0xFFFFF800)+YAdjust+(posX>>16)];
6449 GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
6450 GETLE16(&psxVuw[clutP+tC1]),
6451 (cB1>>16),(cG1>>16),(cR1>>16));
6453 GetTextureTransColGX(&psxVuw[(i<<10)+j],
6454 GETLE16(&psxVuw[clutP+tC1]),
6455 (cB1>>16),(cG1>>16),(cR1>>16));
6463 if(NextRow_GT4()) return;
6467 ////////////////////////////////////////////////////////////////////////
6469 static void drawPoly4TGEx8_TW(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
6470 short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
6471 short clX, short clY,
6472 int32_t col1, int32_t col2, int32_t col3, int32_t col4)
6474 drawPoly3TGEx8_TW(x2,y2,x3,y3,x4,y4,
6475 tx2,ty2,tx3,ty3,tx4,ty4,
6478 drawPoly3TGEx8_TW(x1,y1,x2,y2,x4,y4,
6479 tx1,ty1,tx2,ty2,tx4,ty4,
6484 ////////////////////////////////////////////////////////////////////////
6485 // POLY 3 G-SHADED TEX 15 BIT
6486 ////////////////////////////////////////////////////////////////////////
6488 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)
6490 int i,j,xmin,xmax,ymin,ymax;
6491 int32_t cR1,cG1,cB1;
6492 int32_t difR,difB,difG,difR2,difB2,difG2;
6493 int32_t difX, difY,difX2, difY2;
6496 if(x1>drawW && x2>drawW && x3>drawW) return;
6497 if(y1>drawH && y2>drawH && y3>drawH) return;
6498 if(x1<drawX && x2<drawX && x3<drawX) return;
6499 if(y1<drawY && y2<drawY && y3<drawY) return;
6500 if(drawY>=drawH) return;
6501 if(drawX>=drawW) return;
6503 if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
6507 for(ymin=Ymin;ymin<drawY;ymin++)
6508 if(NextRow_GT()) return;
6516 difX=delta_right_u;difX2=difX<<1;
6517 difY=delta_right_v;difY2=difY<<1;
6521 if(!bCheckMask && !DrawSemiTrans && !iDither)
6523 for (i=ymin;i<=ymax;i++)
6525 xmin=(left_x >> 16);
6526 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!!!
6527 if(drawW<xmax) xmax=drawW;
6538 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
6540 for(j=xmin;j<xmax;j+=2)
6542 GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
6543 (((int32_t)GETLE16(&psxVuw[((((posY+difY)>>16)+GlobalTextAddrY)<<10)+((posX+difX)>>16)+GlobalTextAddrX]))<<16)|
6544 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+((posX)>>16)+GlobalTextAddrX]),
6545 (cB1>>16)|((cB1+difB)&0xff0000),
6546 (cG1>>16)|((cG1+difG)&0xff0000),
6547 (cR1>>16)|((cR1+difR)&0xff0000));
6555 GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
6556 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]),
6557 (cB1>>16),(cG1>>16),(cR1>>16));
6569 for (i=ymin;i<=ymax;i++)
6571 xmin=(left_x >> 16);
6572 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!
6573 if(drawW<xmax) xmax=drawW;
6584 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
6586 for(j=xmin;j<=xmax;j++)
6589 GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
6590 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]),
6591 (cB1>>16),(cG1>>16),(cR1>>16));
6593 GetTextureTransColGX(&psxVuw[(i<<10)+j],
6594 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]),
6595 (cB1>>16),(cG1>>16),(cR1>>16));
6610 ////////////////////////////////////////////////////////////////////////
6612 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)
6614 int i,j,xmin,xmax,ymin,ymax;
6615 int32_t cR1,cG1,cB1;
6616 int32_t difR,difB,difG,difR2,difB2,difG2;
6617 int32_t difX, difY,difX2, difY2;
6620 if(x1>drawW && x2>drawW && x3>drawW) return;
6621 if(y1>drawH && y2>drawH && y3>drawH) return;
6622 if(x1<drawX && x2<drawX && x3<drawX) return;
6623 if(y1<drawY && y2<drawY && y3<drawY) return;
6624 if(drawY>=drawH) return;
6625 if(drawX>=drawW) return;
6627 if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
6631 for(ymin=Ymin;ymin<drawY;ymin++)
6632 if(NextRow_GT()) return;
6640 difX=delta_right_u;difX2=difX<<1;
6641 difY=delta_right_v;difY2=difY<<1;
6645 if(!bCheckMask && !DrawSemiTrans && !iDither)
6647 for (i=ymin;i<=ymax;i++)
6649 xmin=(left_x >> 16);
6650 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!!!
6651 if(drawW<xmax) xmax=drawW;
6662 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
6664 for(j=xmin;j<xmax;j+=2)
6666 GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
6667 (((int32_t)GETLE16(&psxVuw[(((((posY+difY)>>16)&TWin.ymask)+GlobalTextAddrY+TWin.Position.y0)<<10)+
6668 (((posX+difX)>>16)&TWin.xmask)+GlobalTextAddrX+TWin.Position.x0]))<<16)|
6669 GETLE16(&psxVuw[((((posY>>16)&TWin.ymask)+GlobalTextAddrY+TWin.Position.y0)<<10)+
6670 (((posX)>>16)&TWin.xmask)+GlobalTextAddrX+TWin.Position.x0]),
6671 (cB1>>16)|((cB1+difB)&0xff0000),
6672 (cG1>>16)|((cG1+difG)&0xff0000),
6673 (cR1>>16)|((cR1+difR)&0xff0000));
6681 GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
6682 GETLE16(&psxVuw[((((posY>>16)&TWin.ymask)+GlobalTextAddrY+TWin.Position.y0)<<10)+
6683 ((posX>>16)&TWin.xmask)+GlobalTextAddrX+TWin.Position.x0]),
6684 (cB1>>16),(cG1>>16),(cR1>>16));
6696 for (i=ymin;i<=ymax;i++)
6698 xmin=(left_x >> 16);
6699 xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!
6700 if(drawW<xmax) xmax=drawW;
6711 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
6713 for(j=xmin;j<=xmax;j++)
6716 GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
6717 GETLE16(&psxVuw[((((posY>>16)&TWin.ymask)+GlobalTextAddrY+TWin.Position.y0)<<10)+
6718 ((posX>>16)&TWin.xmask)+GlobalTextAddrX+TWin.Position.x0]),
6719 (cB1>>16),(cG1>>16),(cR1>>16));
6721 GetTextureTransColGX(&psxVuw[(i<<10)+j],
6722 GETLE16(&psxVuw[((((posY>>16)&TWin.ymask)+GlobalTextAddrY+TWin.Position.y0)<<10)+
6723 ((posX>>16)&TWin.xmask)+GlobalTextAddrX+TWin.Position.x0]),
6724 (cB1>>16),(cG1>>16),(cR1>>16));
6739 ////////////////////////////////////////////////////////////////////////
6741 // note: two g-shaded tris: small texture distortions can happen
6745 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)
6747 drawPoly3TGD(x2,y2,x3,y3,x4,y4,
6748 tx2,ty2,tx3,ty3,tx4,ty4,
6750 drawPoly3TGD(x1,y1,x2,y2,x4,y4,
6751 tx1,ty1,tx2,ty2,tx4,ty4,
6757 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)
6760 int32_t i,j,xmin,xmax,ymin,ymax;
6761 int32_t cR1,cG1,cB1;
6762 int32_t difR,difB,difG,difR2,difB2,difG2;
6763 int32_t difX, difY, difX2, difY2;
6766 if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
6767 if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
6768 if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
6769 if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
6770 if(drawY>=drawH) return;
6771 if(drawX>=drawW) return;
6773 if(!SetupSections_GT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4,col1,col2,col3,col4)) return;
6777 for(ymin=Ymin;ymin<drawY;ymin++)
6778 if(NextRow_GT4()) return;
6782 if(!bCheckMask && !DrawSemiTrans && !iDither)
6784 for (i=ymin;i<=ymax;i++)
6786 xmin=(left_x >> 16);
6787 xmax=(right_x >> 16);
6796 difX=(right_u-posX)/num;
6797 difY=(right_v-posY)/num;
6804 difR=(right_R-cR1)/num;
6805 difG=(right_G-cG1)/num;
6806 difB=(right_B-cB1)/num;
6812 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
6813 xmax--;if(drawW<xmax) xmax=drawW;
6815 for(j=xmin;j<xmax;j+=2)
6817 GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
6818 (((int32_t)GETLE16(&psxVuw[((((posY+difY)>>16)+GlobalTextAddrY)<<10)+((posX+difX)>>16)+GlobalTextAddrX]))<<16)|
6819 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+((posX)>>16)+GlobalTextAddrX]),
6820 (cB1>>16)|((cB1+difB)&0xff0000),
6821 (cG1>>16)|((cG1+difG)&0xff0000),
6822 (cR1>>16)|((cR1+difR)&0xff0000));
6830 GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
6831 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]),
6832 (cB1>>16),(cG1>>16),(cR1>>16));
6834 if(NextRow_GT4()) return;
6841 for (i=ymin;i<=ymax;i++)
6843 xmin=(left_x >> 16);
6844 xmax=(right_x >> 16);
6853 difX=(right_u-posX)/num;
6854 difY=(right_v-posY)/num;
6861 difR=(right_R-cR1)/num;
6862 difG=(right_G-cG1)/num;
6863 difB=(right_B-cB1)/num;
6869 {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
6870 xmax--;if(drawW<xmax) xmax=drawW;
6872 for(j=xmin;j<=xmax;j++)
6875 GetTextureTransColGX(&psxVuw[(i<<10)+j],
6876 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]),
6877 (cB1>>16),(cG1>>16),(cR1>>16));
6879 GetTextureTransColGX(&psxVuw[(i<<10)+j],
6880 GETLE16(&psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]),
6881 (cB1>>16),(cG1>>16),(cR1>>16));
6889 if(NextRow_GT4()) return;
6893 ////////////////////////////////////////////////////////////////////////
6895 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)
6897 drawPoly3TGD_TW(x2,y2,x3,y3,x4,y4,
6898 tx2,ty2,tx3,ty3,tx4,ty4,
6900 drawPoly3TGD_TW(x1,y1,x2,y2,x4,y4,
6901 tx1,ty1,tx2,ty2,tx4,ty4,
6905 ////////////////////////////////////////////////////////////////////////
6906 ////////////////////////////////////////////////////////////////////////
6907 ////////////////////////////////////////////////////////////////////////
6908 ////////////////////////////////////////////////////////////////////////
6909 ////////////////////////////////////////////////////////////////////////
6910 ////////////////////////////////////////////////////////////////////////
6914 // no real rect test, but it does its job the way I need it
6915 static inline BOOL IsNoRect(void)
6917 if(lx0==lx1 && lx2==lx3) return FALSE;
6918 if(lx0==lx2 && lx1==lx3) return FALSE;
6919 if(lx0==lx3 && lx1==lx2) return FALSE;
6925 static inline BOOL IsNoRect(void)
6927 if(!(dwActFixes&0x200)) return FALSE;
6931 if(lx1==lx3 && ly3==ly2 && lx2==lx0) return FALSE;
6932 if(lx1==lx2 && ly2==ly3 && lx3==lx0) return FALSE;
6938 if(lx2==lx3 && ly3==ly1 && lx1==lx0) return FALSE;
6939 if(lx2==lx1 && ly1==ly3 && lx3==lx0) return FALSE;
6945 if(lx3==lx2 && ly2==ly1 && lx1==lx0) return FALSE;
6946 if(lx3==lx1 && ly1==ly2 && lx2==lx0) return FALSE;
6952 ////////////////////////////////////////////////////////////////////////
6954 static void drawPoly3FT(unsigned char * baseAddr)
6956 uint32_t *gpuData = ((uint32_t *) baseAddr);
6958 if(GlobalTextIL && GlobalTextTP<2)
6961 drawPoly3TEx4_IL(lx0,ly0,lx1,ly1,lx2,ly2,
6962 (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),
6963 ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511));
6965 drawPoly3TEx8_IL(lx0,ly0,lx1,ly1,lx2,ly2,
6966 (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),
6967 ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511));
6971 if(!bUsingTWin && !(dwActFixes&0x100))
6973 switch(GlobalTextTP) // depending on texture mode
6976 drawPoly3TEx4(lx0,ly0,lx1,ly1,lx2,ly2,
6977 (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),
6978 ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511));
6981 drawPoly3TEx8(lx0,ly0,lx1,ly1,lx2,ly2,
6982 (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),
6983 ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511));
6986 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));
6992 switch(GlobalTextTP) // depending on texture mode
6995 drawPoly3TEx4_TW(lx0,ly0,lx1,ly1,lx2,ly2,
6996 (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),
6997 ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511));
7000 drawPoly3TEx8_TW(lx0,ly0,lx1,ly1,lx2,ly2,
7001 (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),
7002 ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511));
7005 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));
7010 ////////////////////////////////////////////////////////////////////////
7012 static void drawPoly4FT(unsigned char * baseAddr)
7014 uint32_t *gpuData = ((uint32_t *) baseAddr);
7016 if(GlobalTextIL && GlobalTextTP<2)
7019 drawPoly4TEx4_IL(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7020 (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));
7022 drawPoly4TEx8_IL(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7023 (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));
7032 switch (GlobalTextTP)
7035 drawPoly4TEx4_TRI(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7036 (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));
7039 drawPoly4TEx8_TRI(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7040 (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));
7043 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));
7050 switch (GlobalTextTP)
7052 case 0: // grandia investigations needed
7053 drawPoly4TEx4(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7054 (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));
7057 drawPoly4TEx8(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7058 (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));
7061 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));
7067 switch (GlobalTextTP)
7070 drawPoly4TEx4_TW(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7071 (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));
7074 drawPoly4TEx8_TW(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7075 (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));
7078 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));
7083 ////////////////////////////////////////////////////////////////////////
7085 static void drawPoly3GT(unsigned char * baseAddr)
7087 uint32_t *gpuData = ((uint32_t *) baseAddr);
7089 if(GlobalTextIL && GlobalTextTP<2)
7092 drawPoly3TGEx4_IL(lx0,ly0,lx1,ly1,lx2,ly2,
7093 (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),
7094 ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511),
7095 GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]));
7097 drawPoly3TGEx8_IL(lx0,ly0,lx1,ly1,lx2,ly2,
7098 (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),
7099 ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511),
7100 GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]));
7106 switch (GlobalTextTP)
7109 drawPoly3TGEx4(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 drawPoly3TGEx8(lx0,ly0,lx1,ly1,lx2,ly2,
7116 (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),
7117 ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511),
7118 GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]));
7121 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]));
7127 switch(GlobalTextTP)
7130 drawPoly3TGEx4_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 drawPoly3TGEx8_TW(lx0,ly0,lx1,ly1,lx2,ly2,
7137 (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),
7138 ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511),
7139 GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]));
7142 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]));
7147 ////////////////////////////////////////////////////////////////////////
7149 static void drawPoly4GT(unsigned char *baseAddr)
7151 uint32_t *gpuData = ((uint32_t *) baseAddr);
7153 if(GlobalTextIL && GlobalTextTP<2)
7156 drawPoly4TGEx4_TRI_IL(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7157 (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),
7158 ((GETLE32(&gpuData[2])>>12) & 0x3f0),((GETLE32(&gpuData[2])>>22) & 511),
7159 GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]),GETLE32(&gpuData[9]));
7161 drawPoly4TGEx8_TRI_IL(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7162 (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),
7163 ((GETLE32(&gpuData[2])>>12) & 0x3f0),((GETLE32(&gpuData[2])>>22) & 511),
7164 GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]),GETLE32(&gpuData[9]));
7173 switch (GlobalTextTP)
7176 drawPoly4TGEx4_TRI(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7177 (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),
7178 ((GETLE32(&gpuData[2])>>12) & 0x3f0),((GETLE32(&gpuData[2])>>22) & 511),
7179 GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]),GETLE32(&gpuData[9]));
7183 drawPoly4TGEx8_TRI(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7184 (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),
7185 ((GETLE32(&gpuData[2])>>12) & 0x3f0),((GETLE32(&gpuData[2])>>22) & 511),
7186 GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]),GETLE32(&gpuData[9]));
7189 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]));
7196 switch (GlobalTextTP)
7199 drawPoly4TGEx4(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7200 (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),
7201 ((GETLE32(&gpuData[2])>>12) & 0x3f0),((GETLE32(&gpuData[2])>>22) & 511),
7202 GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]),GETLE32(&gpuData[9]));
7206 drawPoly4TGEx8(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7207 (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),
7208 ((GETLE32(&gpuData[2])>>12) & 0x3f0),((GETLE32(&gpuData[2])>>22) & 511),
7209 GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]),GETLE32(&gpuData[9]));
7212 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]));
7218 switch (GlobalTextTP)
7221 drawPoly4TGEx4_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 drawPoly4TGEx8_TW(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
7228 (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),
7229 ((GETLE32(&gpuData[2])>>12) & 0x3f0),((GETLE32(&gpuData[2])>>22) & 511),
7230 GETLE32(&gpuData[0]),GETLE32(&gpuData[3]),GETLE32(&gpuData[6]),GETLE32(&gpuData[9]));
7233 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]));
7238 ////////////////////////////////////////////////////////////////////////
7240 ////////////////////////////////////////////////////////////////////////
7242 static void DrawSoftwareSpriteTWin(unsigned char * baseAddr,int32_t w,int32_t h)
7244 uint32_t *gpuData = (uint32_t *)baseAddr;
7245 short sx0,sy0,sx1,sy1,sx2,sy2,sx3,sy3;
7246 short tx0,ty0,tx1,ty1,tx2,ty2,tx3,ty3;
7251 sx0=sx3=sx0+PSXDisplay.DrawOffset.x;
7253 sy0=sy1=sy0+PSXDisplay.DrawOffset.y;
7256 tx0=tx3=GETLE32(&gpuData[2])&0xff;
7258 ty0=ty1=(GETLE32(&gpuData[2])>>8)&0xff;
7261 switch (GlobalTextTP)
7264 drawPoly4TEx4_TW_S(sx0,sy0,sx1,sy1,sx2,sy2,sx3,sy3,
7265 tx0,ty0,tx1,ty1,tx2,ty2,tx3,ty3,
7266 ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511));
7269 drawPoly4TEx8_TW_S(sx0,sy0,sx1,sy1,sx2,sy2,sx3,sy3,
7270 tx0,ty0,tx1,ty1,tx2,ty2,tx3,ty3,
7271 ((GETLE32(&gpuData[2])>>12) & 0x3f0), ((GETLE32(&gpuData[2])>>22) & 511));
7274 drawPoly4TD_TW_S(sx0,sy0,sx1,sy1,sx2,sy2,sx3,sy3,
7275 tx0,ty0,tx1,ty1,tx2,ty2,tx3,ty3);
7280 ////////////////////////////////////////////////////////////////////////
7282 static void DrawSoftwareSpriteMirror(unsigned char * baseAddr,int32_t w,int32_t h)
7284 int32_t sprtY,sprtX,sprtW,sprtH,lXDir,lYDir;
7285 int32_t clutY0,clutX0,clutP,textX0,textY0,sprtYa,sprCY,sprCX,sprA;
7287 uint32_t *gpuData = (uint32_t *)baseAddr;
7292 clutY0 = (GETLE32(&gpuData[2])>>22) & 511;
7293 clutX0 = (GETLE32(&gpuData[2])>>12) & 0x3f0;
7294 clutP = (clutY0<<11) + (clutX0<<1);
7295 textY0 = ((GETLE32(&gpuData[2])>>8) & 0x000000ff) + GlobalTextAddrY;
7296 textX0 = (GETLE32(&gpuData[2]) & 0x000000ff);
7298 sprtX+=PSXDisplay.DrawOffset.x;
7299 sprtY+=PSXDisplay.DrawOffset.y;
7313 if((sprtY+sprtH)<drawY) return;
7314 sprtH-=(drawY-sprtY);
7315 textY0+=(drawY-sprtY);
7321 if((sprtX+sprtW)<drawX) return;
7322 sprtW-=(drawX-sprtX);
7323 textX0+=(drawX-sprtX);
7327 if((sprtY+sprtH)>drawH) sprtH=drawH-sprtY+1;
7328 if((sprtX+sprtW)>drawW) sprtW=drawW-sprtX+1;
7330 if(usMirror&0x1000) lXDir=-1; else lXDir=1;
7331 if(usMirror&0x2000) lYDir=-1; else lYDir=1;
7333 switch (GlobalTextTP)
7335 case 0: // texture is 4-bit
7338 textX0=(GlobalTextAddrX<<1)+(textX0>>1);
7340 clutP=(clutY0<<10)+clutX0;
7341 for (sprCY=0;sprCY<sprtH;sprCY++)
7342 for (sprCX=0;sprCX<sprtW;sprCX++)
7344 tC= psxVub[((textY0+(sprCY*lYDir))<<11) + textX0 +(sprCX*lXDir)];
7345 sprA=sprtYa+(sprCY<<10)+sprtX + (sprCX<<1);
7346 GetTextureTransColG_SPR(&psxVuw[sprA],GETLE16(&psxVuw[clutP+((tC>>4)&0xf)]));
7347 GetTextureTransColG_SPR(&psxVuw[sprA+1],GETLE16(&psxVuw[clutP+(tC&0xf)]));
7354 for(sprCY=0;sprCY<sprtH;sprCY++)
7355 for(sprCX=0;sprCX<sprtW;sprCX++)
7357 tC = psxVub[((textY0+(sprCY*lYDir))<<11)+(GlobalTextAddrX<<1) + textX0 + (sprCX*lXDir)] & 0xff;
7358 GetTextureTransColG_SPR(&psxVuw[((sprtY+sprCY)<<10)+sprtX + sprCX],psxVuw[clutP+tC]);
7364 for (sprCY=0;sprCY<sprtH;sprCY++)
7365 for (sprCX=0;sprCX<sprtW;sprCX++)
7367 GetTextureTransColG_SPR(&psxVuw[((sprtY+sprCY)<<10)+sprtX+sprCX],
7368 GETLE16(&psxVuw[((textY0+(sprCY*lYDir))<<10)+GlobalTextAddrX + textX0 +(sprCX*lXDir)]));
7374 ////////////////////////////////////////////////////////////////////////
7376 void DrawSoftwareSprite_IL(unsigned char * baseAddr,short w,short h,int32_t tx,int32_t ty)
7378 int32_t sprtY,sprtX,sprtW,sprtH,tdx,tdy;
7379 uint32_t *gpuData = (uint32_t *)baseAddr;
7386 sprtX+=PSXDisplay.DrawOffset.x;
7387 sprtY+=PSXDisplay.DrawOffset.y;
7389 if(sprtX>drawW) return;
7390 if(sprtY>drawH) return;
7398 // Pete is too lazy to make a faster version ;)
7401 drawPoly4TEx4_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));
7407 drawPoly4TEx8_IL(sprtX,sprtY,sprtX,sprtH,sprtW,sprtH,sprtW,sprtY,
7408 tx,ty, tx,tdy, tdx,tdy, tdx,ty,
7409 (GETLE32(&gpuData[2])>>12) & 0x3f0, ((GETLE32(&gpuData[2])>>22) & 511));
7412 ////////////////////////////////////////////////////////////////////////
7414 static void DrawSoftwareSprite(unsigned char * baseAddr,short w,short h,int32_t tx,int32_t ty)
7416 int32_t sprtY,sprtX,sprtW,sprtH;
7417 int32_t clutY0,clutX0,clutP,textX0,textY0,sprtYa,sprCY,sprCX,sprA;
7419 uint32_t *gpuData = (uint32_t *)baseAddr;
7423 if(GlobalTextIL && GlobalTextTP<2)
7424 {DrawSoftwareSprite_IL(baseAddr,w,h,tx,ty);return;}
7430 clutY0 = (GETLE32(&gpuData[2])>>22) & 511;
7431 clutX0 = (GETLE32(&gpuData[2])>>12) & 0x3f0;
7433 clutP = (clutY0<<11) + (clutX0<<1);
7435 textY0 =ty+ GlobalTextAddrY;
7438 sprtX+=PSXDisplay.DrawOffset.x;
7439 sprtY+=PSXDisplay.DrawOffset.y;
7453 if((sprtY+sprtH)<drawY) return;
7454 sprtH-=(drawY-sprtY);
7455 textY0+=(drawY-sprtY);
7461 if((sprtX+sprtW)<drawX) return;
7463 sprtW-=(drawX-sprtX);
7464 textX0+=(drawX-sprtX);
7468 if((sprtY+sprtH)>drawH) sprtH=drawH-sprtY+1;
7469 if((sprtX+sprtW)>drawW) sprtW=drawW-sprtX+1;
7475 switch (GlobalTextTP)
7479 if(textX0&1) {bWS=TRUE;sprtW--;}
7480 if(sprtW&1) bWT=TRUE;
7483 textX0=(GlobalTextAddrX<<1)+(textX0>>1)+(textY0<<11);
7484 sprtYa=(sprtY<<10)+sprtX;
7485 clutP=(clutY0<<10)+clutX0;
7489 if(!bCheckMask && !DrawSemiTrans)
7491 for (sprCY=0;sprCY<sprtH;sprCY++)
7493 sprA=sprtYa+(sprCY<<10);
7494 pV=&psxVub[(sprCY<<11)+textX0];
7499 GetTextureTransColG_S(&psxVuw[sprA++],GETLE16(&psxVuw[clutP+((tC>>4)&0xf)]));
7502 for (sprCX=0;sprCX<sprtW;sprCX++,sprA+=2)
7506 GetTextureTransColG32_S((uint32_t *)&psxVuw[sprA],
7507 (((int32_t)GETLE16(&psxVuw[clutP+((tC>>4)&0xf)]))<<16)|
7508 GETLE16(&psxVuw[clutP+(tC&0x0f)]));
7514 GetTextureTransColG_S(&psxVuw[sprA],GETLE16(&psxVuw[clutP+(tC&0x0f)]));
7522 for (sprCY=0;sprCY<sprtH;sprCY++)
7524 sprA=sprtYa+(sprCY<<10);
7525 pV=&psxVub[(sprCY<<11)+textX0];
7530 GetTextureTransColG_SPR(&psxVuw[sprA++],GETLE16(&psxVuw[clutP+((tC>>4)&0xf)]));
7533 for (sprCX=0;sprCX<sprtW;sprCX++,sprA+=2)
7537 GetTextureTransColG32_SPR((uint32_t *)&psxVuw[sprA],
7538 (((int32_t)GETLE16(&psxVuw[clutP+((tC>>4)&0xf)])<<16))|
7539 GETLE16(&psxVuw[clutP+(tC&0x0f)]));
7545 GetTextureTransColG_SPR(&psxVuw[sprA],GETLE16(&psxVuw[clutP+(tC&0x0f)]));
7552 textX0+=(GlobalTextAddrX<<1) + (textY0<<11);
7556 if(!bCheckMask && !DrawSemiTrans)
7558 for(sprCY=0;sprCY<sprtH;sprCY++)
7560 sprA=((sprtY+sprCY)<<10)+sprtX;
7561 pV=&psxVub[(sprCY<<11)+textX0];
7562 for(sprCX=0;sprCX<sprtW;sprCX+=2,sprA+=2)
7564 tC = *pV++;tC2 = *pV++;
7565 GetTextureTransColG32_S((uint32_t *)&psxVuw[sprA],
7566 (((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16)|
7567 GETLE16(&psxVuw[clutP+tC]));
7570 GetTextureTransColG_S(&psxVuw[sprA],GETLE16(&psxVuw[clutP+(*pV)]));
7577 for(sprCY=0;sprCY<sprtH;sprCY++)
7579 sprA=((sprtY+sprCY)<<10)+sprtX;
7580 pV=&psxVub[(sprCY<<11)+textX0];
7581 for(sprCX=0;sprCX<sprtW;sprCX+=2,sprA+=2)
7583 tC = *pV++;tC2 = *pV++;
7584 GetTextureTransColG32_SPR((uint32_t *)&psxVuw[sprA],
7585 (((int32_t)GETLE16(&psxVuw[clutP+tC2]))<<16)|
7586 GETLE16(&psxVuw[clutP+tC]));
7589 GetTextureTransColG_SPR(&psxVuw[sprA],GETLE16(&psxVuw[clutP+(*pV)]));
7595 textX0+=(GlobalTextAddrX) + (textY0<<10);
7600 if(!bCheckMask && !DrawSemiTrans)
7602 for (sprCY=0;sprCY<sprtH;sprCY++)
7604 sprA=((sprtY+sprCY)<<10)+sprtX;
7606 for (sprCX=0;sprCX<sprtW;sprCX+=2,sprA+=2)
7608 GetTextureTransColG32_S((uint32_t *)&psxVuw[sprA],
7609 (((int32_t)GETLE16(&psxVuw[(sprCY<<10) + textX0 + sprCX +1]))<<16)|
7610 GETLE16(&psxVuw[(sprCY<<10) + textX0 + sprCX]));
7613 GetTextureTransColG_S(&psxVuw[sprA],
7614 GETLE16(&psxVuw[(sprCY<<10) + textX0 + sprCX]));
7622 for (sprCY=0;sprCY<sprtH;sprCY++)
7624 sprA=((sprtY+sprCY)<<10)+sprtX;
7626 for (sprCX=0;sprCX<sprtW;sprCX+=2,sprA+=2)
7628 GetTextureTransColG32_SPR((uint32_t *)&psxVuw[sprA],
7629 (((int32_t)GETLE16(&psxVuw[(sprCY<<10) + textX0 + sprCX +1]))<<16)|
7630 GETLE16(&psxVuw[(sprCY<<10) + textX0 + sprCX]));
7633 GetTextureTransColG_SPR(&psxVuw[sprA],
7634 GETLE16(&psxVuw[(sprCY<<10) + textX0 + sprCX]));
7641 ///////////////////////////////////////////////////////////////////////
7643 /////////////////////////////////////////////////////////////////
7644 /////////////////////////////////////////////////////////////////
7645 /////////////////////////////////////////////////////////////////
7647 ////////////////////////////////////////////////////////////////////////
7648 /////////////////////////////////////////////////////////////////
7649 /////////////////////////////////////////////////////////////////
7652 ///////////////////////////////////////////////////////////////////////
7654 static void Line_E_SE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, uint32_t rgb1)
7656 int dx, dy, incrE, incrSE, d;
7657 uint32_t r0, g0, b0, r1, g1, b1;
7660 r0 = (rgb0 & 0x00ff0000);
7661 g0 = (rgb0 & 0x0000ff00) << 8;
7662 b0 = (rgb0 & 0x000000ff) << 16;
7663 r1 = (rgb1 & 0x00ff0000);
7664 g1 = (rgb1 & 0x0000ff00) << 8;
7665 b1 = (rgb1 & 0x000000ff) << 16;
7672 dr = ((int32_t)r1 - (int32_t)r0) / dx;
7673 dg = ((int32_t)g1 - (int32_t)g0) / dx;
7674 db = ((int32_t)b1 - (int32_t)b0) / dx;
7678 dr = ((int32_t)r1 - (int32_t)r0);
7679 dg = ((int32_t)g1 - (int32_t)g0);
7680 db = ((int32_t)b1 - (int32_t)b0);
7683 d = 2*dy - dx; /* Initial value of d */
7684 incrE = 2*dy; /* incr. used for move to E */
7685 incrSE = 2*(dy - dx); /* incr. used for move to SE */
7687 if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
7688 GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
7693 d = d + incrE; /* Choose E */
7697 d = d + incrSE; /* Choose SE */
7706 if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
7707 GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
7711 ///////////////////////////////////////////////////////////////////////
7713 static void Line_S_SE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, uint32_t rgb1)
7715 int dx, dy, incrS, incrSE, d;
7716 uint32_t r0, g0, b0, r1, g1, b1;
7719 r0 = (rgb0 & 0x00ff0000);
7720 g0 = (rgb0 & 0x0000ff00) << 8;
7721 b0 = (rgb0 & 0x000000ff) << 16;
7722 r1 = (rgb1 & 0x00ff0000);
7723 g1 = (rgb1 & 0x0000ff00) << 8;
7724 b1 = (rgb1 & 0x000000ff) << 16;
7731 dr = ((int32_t)r1 - (int32_t)r0) / dy;
7732 dg = ((int32_t)g1 - (int32_t)g0) / dy;
7733 db = ((int32_t)b1 - (int32_t)b0) / dy;
7737 dr = ((int32_t)r1 - (int32_t)r0);
7738 dg = ((int32_t)g1 - (int32_t)g0);
7739 db = ((int32_t)b1 - (int32_t)b0);
7742 d = 2*dx - dy; /* Initial value of d */
7743 incrS = 2*dx; /* incr. used for move to S */
7744 incrSE = 2*(dx - dy); /* incr. used for move to SE */
7746 if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
7747 GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
7752 d = d + incrS; /* Choose S */
7756 d = d + incrSE; /* Choose SE */
7765 if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
7766 GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
7770 ///////////////////////////////////////////////////////////////////////
7772 static void Line_N_NE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, uint32_t rgb1)
7774 int dx, dy, incrN, incrNE, d;
7775 uint32_t r0, g0, b0, r1, g1, b1;
7778 r0 = (rgb0 & 0x00ff0000);
7779 g0 = (rgb0 & 0x0000ff00) << 8;
7780 b0 = (rgb0 & 0x000000ff) << 16;
7781 r1 = (rgb1 & 0x00ff0000);
7782 g1 = (rgb1 & 0x0000ff00) << 8;
7783 b1 = (rgb1 & 0x000000ff) << 16;
7790 dr = ((int32_t)r1 - (int32_t)r0) / dy;
7791 dg = ((int32_t)g1 - (int32_t)g0) / dy;
7792 db = ((int32_t)b1 - (int32_t)b0) / dy;
7796 dr = ((int32_t)r1 - (int32_t)r0);
7797 dg = ((int32_t)g1 - (int32_t)g0);
7798 db = ((int32_t)b1 - (int32_t)b0);
7801 d = 2*dx - dy; /* Initial value of d */
7802 incrN = 2*dx; /* incr. used for move to N */
7803 incrNE = 2*(dx - dy); /* incr. used for move to NE */
7805 if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
7806 GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
7811 d = d + incrN; /* Choose N */
7815 d = d + incrNE; /* Choose NE */
7824 if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
7825 GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
7829 ///////////////////////////////////////////////////////////////////////
7831 static void Line_E_NE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, uint32_t rgb1)
7833 int dx, dy, incrE, incrNE, d;
7834 uint32_t r0, g0, b0, r1, g1, b1;
7837 r0 = (rgb0 & 0x00ff0000);
7838 g0 = (rgb0 & 0x0000ff00) << 8;
7839 b0 = (rgb0 & 0x000000ff) << 16;
7840 r1 = (rgb1 & 0x00ff0000);
7841 g1 = (rgb1 & 0x0000ff00) << 8;
7842 b1 = (rgb1 & 0x000000ff) << 16;
7849 dr = ((int32_t)r1 - (int32_t)r0) / dx;
7850 dg = ((int32_t)g1 - (int32_t)g0) / dx;
7851 db = ((int32_t)b1 - (int32_t)b0) / dx;
7855 dr = ((int32_t)r1 - (int32_t)r0);
7856 dg = ((int32_t)g1 - (int32_t)g0);
7857 db = ((int32_t)b1 - (int32_t)b0);
7860 d = 2*dy - dx; /* Initial value of d */
7861 incrE = 2*dy; /* incr. used for move to E */
7862 incrNE = 2*(dy - dx); /* incr. used for move to NE */
7864 if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
7865 GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
7870 d = d + incrE; /* Choose E */
7874 d = d + incrNE; /* Choose NE */
7883 if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
7884 GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
7888 ///////////////////////////////////////////////////////////////////////
7890 static void VertLineShade(int x, int y0, int y1, uint32_t rgb0, uint32_t rgb1)
7893 uint32_t r0, g0, b0, r1, g1, b1;
7896 r0 = (rgb0 & 0x00ff0000);
7897 g0 = (rgb0 & 0x0000ff00) << 8;
7898 b0 = (rgb0 & 0x000000ff) << 16;
7899 r1 = (rgb1 & 0x00ff0000);
7900 g1 = (rgb1 & 0x0000ff00) << 8;
7901 b1 = (rgb1 & 0x000000ff) << 16;
7907 dr = ((int32_t)r1 - (int32_t)r0) / dy;
7908 dg = ((int32_t)g1 - (int32_t)g0) / dy;
7909 db = ((int32_t)b1 - (int32_t)b0) / dy;
7913 dr = ((int32_t)r1 - (int32_t)r0);
7914 dg = ((int32_t)g1 - (int32_t)g0);
7915 db = ((int32_t)b1 - (int32_t)b0);
7920 r0+=dr*(drawY - y0);
7921 g0+=dg*(drawY - y0);
7922 b0+=db*(drawY - y0);
7929 for (y = y0; y <= y1; y++)
7931 GetShadeTransCol(&psxVuw[(y<<10)+x],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
7938 ///////////////////////////////////////////////////////////////////////
7940 static void HorzLineShade(int y, int x0, int x1, uint32_t rgb0, uint32_t rgb1)
7943 uint32_t r0, g0, b0, r1, g1, b1;
7946 r0 = (rgb0 & 0x00ff0000);
7947 g0 = (rgb0 & 0x0000ff00) << 8;
7948 b0 = (rgb0 & 0x000000ff) << 16;
7949 r1 = (rgb1 & 0x00ff0000);
7950 g1 = (rgb1 & 0x0000ff00) << 8;
7951 b1 = (rgb1 & 0x000000ff) << 16;
7957 dr = ((int32_t)r1 - (int32_t)r0) / dx;
7958 dg = ((int32_t)g1 - (int32_t)g0) / dx;
7959 db = ((int32_t)b1 - (int32_t)b0) / dx;
7963 dr = ((int32_t)r1 - (int32_t)r0);
7964 dg = ((int32_t)g1 - (int32_t)g0);
7965 db = ((int32_t)b1 - (int32_t)b0);
7970 r0+=dr*(drawX - x0);
7971 g0+=dg*(drawX - x0);
7972 b0+=db*(drawX - x0);
7979 for (x = x0; x <= x1; x++)
7981 GetShadeTransCol(&psxVuw[(y<<10)+x],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
7988 ///////////////////////////////////////////////////////////////////////
7990 static void Line_E_SE_Flat(int x0, int y0, int x1, int y1, unsigned short colour)
7992 int dx, dy, incrE, incrSE, d, x, y;
7996 d = 2*dy - dx; /* Initial value of d */
7997 incrE = 2*dy; /* incr. used for move to E */
7998 incrSE = 2*(dy - dx); /* incr. used for move to SE */
8001 if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
8002 GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
8007 d = d + incrE; /* Choose E */
8012 d = d + incrSE; /* Choose SE */
8016 if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
8017 GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
8021 ///////////////////////////////////////////////////////////////////////
8023 static void Line_S_SE_Flat(int x0, int y0, int x1, int y1, unsigned short colour)
8025 int dx, dy, incrS, incrSE, d, x, y;
8029 d = 2*dx - dy; /* Initial value of d */
8030 incrS = 2*dx; /* incr. used for move to S */
8031 incrSE = 2*(dx - dy); /* incr. used for move to SE */
8034 if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
8035 GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
8040 d = d + incrS; /* Choose S */
8045 d = d + incrSE; /* Choose SE */
8049 if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
8050 GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
8054 ///////////////////////////////////////////////////////////////////////
8056 static void Line_N_NE_Flat(int x0, int y0, int x1, int y1, unsigned short colour)
8058 int dx, dy, incrN, incrNE, d, x, y;
8062 d = 2*dx - dy; /* Initial value of d */
8063 incrN = 2*dx; /* incr. used for move to N */
8064 incrNE = 2*(dx - dy); /* incr. used for move to NE */
8067 if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
8068 GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
8073 d = d + incrN; /* Choose N */
8078 d = d + incrNE; /* Choose NE */
8082 if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
8083 GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
8087 ///////////////////////////////////////////////////////////////////////
8089 static void Line_E_NE_Flat(int x0, int y0, int x1, int y1, unsigned short colour)
8091 int dx, dy, incrE, incrNE, d, x, y;
8095 d = 2*dy - dx; /* Initial value of d */
8096 incrE = 2*dy; /* incr. used for move to E */
8097 incrNE = 2*(dy - dx); /* incr. used for move to NE */
8100 if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
8101 GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
8106 d = d + incrE; /* Choose E */
8111 d = d + incrNE; /* Choose NE */
8115 if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
8116 GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
8120 ///////////////////////////////////////////////////////////////////////
8122 static void VertLineFlat(int x, int y0, int y1, unsigned short colour)
8132 for (y = y0; y <= y1; y++)
8133 GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
8136 ///////////////////////////////////////////////////////////////////////
8138 static void HorzLineFlat(int y, int x0, int x1, unsigned short colour)
8148 for (x = x0; x <= x1; x++)
8149 GetShadeTransCol(&psxVuw[(y << 10) + x], colour);
8152 ///////////////////////////////////////////////////////////////////////
8154 /* Bresenham Line drawing function */
8155 static void DrawSoftwareLineShade(int32_t rgb0, int32_t rgb1)
8157 short x0, y0, x1, y1, xt, yt;
8161 if (lx0 > drawW && lx1 > drawW) return;
8162 if (ly0 > drawH && ly1 > drawH) return;
8163 if (lx0 < drawX && lx1 < drawX) return;
8164 if (ly0 < drawY && ly1 < drawY) return;
8165 if (drawY >= drawH) return;
8166 if (drawX >= drawW) return;
8179 VertLineShade(x0, y0, y1, rgb0, rgb1);
8181 VertLineShade(x0, y1, y0, rgb1, rgb0);
8187 HorzLineShade(y0, x0, x1, rgb0, rgb1);
8189 HorzLineShade(y0, x1, x0, rgb1, rgb0);
8214 Line_S_SE_Shade(x0, y0, x1, y1, rgb0, rgb1);
8216 Line_E_SE_Shade(x0, y0, x1, y1, rgb0, rgb1);
8220 Line_N_NE_Shade(x0, y0, x1, y1, rgb0, rgb1);
8222 Line_E_NE_Shade(x0, y0, x1, y1, rgb0, rgb1);
8226 ///////////////////////////////////////////////////////////////////////
8228 static void DrawSoftwareLineFlat(int32_t rgb)
8230 short x0, y0, x1, y1, xt, yt;
8232 unsigned short colour = 0;
8234 if (lx0 > drawW && lx1 > drawW) return;
8235 if (ly0 > drawH && ly1 > drawH) return;
8236 if (lx0 < drawX && lx1 < drawX) return;
8237 if (ly0 < drawY && ly1 < drawY) return;
8238 if (drawY >= drawH) return;
8239 if (drawX >= drawW) return;
8241 colour = ((rgb & 0x00f80000) >> 9) | ((rgb & 0x0000f800) >> 6) | ((rgb & 0x000000f8) >> 3);
8254 return; // Nothing to draw
8256 VertLineFlat(x0, y0, y1, colour);
8258 VertLineFlat(x0, y1, y0, colour);
8264 HorzLineFlat(y0, x0, x1, colour);
8266 HorzLineFlat(y0, x1, x0, colour);
8288 Line_S_SE_Flat(x0, y0, x1, y1, colour);
8290 Line_E_SE_Flat(x0, y0, x1, y1, colour);
8294 Line_N_NE_Flat(x0, y0, x1, y1, colour);
8296 Line_E_NE_Flat(x0, y0, x1, y1, colour);
8300 ///////////////////////////////////////////////////////////////////////