gpu_unai: merge Franxis' range fix
authornotaz <notasas@gmail.com>
Wed, 1 Aug 2012 22:30:57 +0000 (01:30 +0300)
committernotaz <notasas@gmail.com>
Wed, 1 Aug 2012 22:43:03 +0000 (01:43 +0300)
plugins/gpu_unai/gpu.cpp
plugins/gpu_unai/gpu_raster_line.h
plugins/gpu_unai/gpu_raster_polygon.h
plugins/gpu_unai/gpu_raster_sprite.h
plugins/gpu_unai/gpulib_if.cpp

index 3c30ffa..46552ac 100644 (file)
@@ -107,12 +107,10 @@ u32   GPU_GP1;
 //  GPU Raster Macros
 #define        GPU_RGB16(rgb)        ((((rgb)&0xF80000)>>9)|(((rgb)&0xF800)>>6)|(((rgb)&0xF8)>>3))
 
-#define GPU_EXPANDSIGN_POLY(x)  (((s32)(x)<<20)>>20)
-//#define GPU_EXPANDSIGN_POLY(x)  (((s32)(x)<<21)>>21)
-#define GPU_EXPANDSIGN_SPRT(x)  (((s32)(x)<<21)>>21)
+#define GPU_EXPANDSIGN(x)  (((s32)(x)<<21)>>21)
 
-//#define      GPU_TESTRANGE(x)      { if((u32)(x+1024) > 2047) return; }
-#define        GPU_TESTRANGE(x)      { if ((x<-1023) || (x>1023)) return; }
+#define CHKMAX_X 1024
+#define CHKMAX_Y 512
 
 #define        GPU_SWAP(a,b,t) {(t)=(a);(a)=(b);(b)=(t);}
 
index 6d66c7d..4edfa06 100644 (file)
@@ -18,6 +18,8 @@
 *   51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA.           *
 ***************************************************************************/
 
+#define        GPU_TESTRANGE(x)      { if((u32)(x+1024) > 2047) return; }
+
 ///////////////////////////////////////////////////////////////////////////////
 //  GPU internal line drawing functions
 
index 4b338f7..c4b0350 100644 (file)
 *   51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA.           *
 ***************************************************************************/
 
+#define GPU_TESTRANGE3() \
+{ \
+       if(x0<0) { if((x1-x0)>CHKMAX_X) return; if((x2-x0)>CHKMAX_X) return; } \
+       if(x1<0) { if((x0-x1)>CHKMAX_X) return; if((x2-x1)>CHKMAX_X) return; } \
+       if(x2<0) { if((x0-x2)>CHKMAX_X) return; if((x1-x2)>CHKMAX_X) return; } \
+       if(y0<0) { if((y1-y0)>CHKMAX_Y) return; if((y2-y0)>CHKMAX_Y) return; } \
+       if(y1<0) { if((y0-y1)>CHKMAX_Y) return; if((y2-y1)>CHKMAX_Y) return; } \
+       if(y2<0) { if((y0-y2)>CHKMAX_Y) return; if((y1-y2)>CHKMAX_Y) return; } \
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 //  GPU internal polygon drawing functions
 
@@ -31,12 +41,14 @@ void gpuDrawF3(const PP gpuPolySpanDriver)
        s32 x0, x1, x2, x3, dx3=0, x4, dx4=0, dx;
        s32 y0, y1, y2;
 
-       x0 = GPU_EXPANDSIGN_POLY(PacketBuffer.S2[2]);  GPU_TESTRANGE(x0);
-       y0 = GPU_EXPANDSIGN_POLY(PacketBuffer.S2[3]);  GPU_TESTRANGE(y0);
-       x1 = GPU_EXPANDSIGN_POLY(PacketBuffer.S2[4]);  GPU_TESTRANGE(x1);
-       y1 = GPU_EXPANDSIGN_POLY(PacketBuffer.S2[5]);  GPU_TESTRANGE(y1);
-       x2 = GPU_EXPANDSIGN_POLY(PacketBuffer.S2[6]);  GPU_TESTRANGE(x2);
-       y2 = GPU_EXPANDSIGN_POLY(PacketBuffer.S2[7]);  GPU_TESTRANGE(y2);
+       x0 = GPU_EXPANDSIGN(PacketBuffer.S2[2]);
+       y0 = GPU_EXPANDSIGN(PacketBuffer.S2[3]);
+       x1 = GPU_EXPANDSIGN(PacketBuffer.S2[4]);
+       y1 = GPU_EXPANDSIGN(PacketBuffer.S2[5]);
+       x2 = GPU_EXPANDSIGN(PacketBuffer.S2[6]);
+       y2 = GPU_EXPANDSIGN(PacketBuffer.S2[7]);
+
+       GPU_TESTRANGE3();
 
        x0 += DrawingOffset[0];   x1 += DrawingOffset[0];   x2 += DrawingOffset[0];
        y0 += DrawingOffset[1];   y1 += DrawingOffset[1];   y2 += DrawingOffset[1];
@@ -164,12 +176,14 @@ void gpuDrawFT3(const PP gpuPolySpanDriver)
        s32 u0, u1, u2, u3, du3=0;
        s32 v0, v1, v2, v3, dv3=0;
 
-       x0 = GPU_EXPANDSIGN_POLY(PacketBuffer.S2[2] );   GPU_TESTRANGE(x0);
-       y0 = GPU_EXPANDSIGN_POLY(PacketBuffer.S2[3] );   GPU_TESTRANGE(y0);
-       x1 = GPU_EXPANDSIGN_POLY(PacketBuffer.S2[6] );   GPU_TESTRANGE(x1);
-       y1 = GPU_EXPANDSIGN_POLY(PacketBuffer.S2[7] );   GPU_TESTRANGE(y1);
-       x2 = GPU_EXPANDSIGN_POLY(PacketBuffer.S2[10]);   GPU_TESTRANGE(x2);
-       y2 = GPU_EXPANDSIGN_POLY(PacketBuffer.S2[11]);   GPU_TESTRANGE(y2);
+       x0 = GPU_EXPANDSIGN(PacketBuffer.S2[2] );
+       y0 = GPU_EXPANDSIGN(PacketBuffer.S2[3] );
+       x1 = GPU_EXPANDSIGN(PacketBuffer.S2[6] );
+       y1 = GPU_EXPANDSIGN(PacketBuffer.S2[7] );
+       x2 = GPU_EXPANDSIGN(PacketBuffer.S2[10]);
+       y2 = GPU_EXPANDSIGN(PacketBuffer.S2[11]);
+
+       GPU_TESTRANGE3();
 
        x0 += DrawingOffset[0];   x1 += DrawingOffset[0];   x2 += DrawingOffset[0];
        y0 += DrawingOffset[1];   y1 += DrawingOffset[1];   y2 += DrawingOffset[1];
@@ -352,12 +366,14 @@ void gpuDrawG3(const PP gpuPolySpanDriver)
        s32 g0, g1, g2, g3, dg3=0;
        s32 b0, b1, b2, b3, db3=0;
 
-       x0 = GPU_EXPANDSIGN_POLY(PacketBuffer.S2[2] );    GPU_TESTRANGE(x0);
-       y0 = GPU_EXPANDSIGN_POLY(PacketBuffer.S2[3] );    GPU_TESTRANGE(y0);
-       x1 = GPU_EXPANDSIGN_POLY(PacketBuffer.S2[6] );    GPU_TESTRANGE(x1);
-       y1 = GPU_EXPANDSIGN_POLY(PacketBuffer.S2[7] );    GPU_TESTRANGE(y1);
-       x2 = GPU_EXPANDSIGN_POLY(PacketBuffer.S2[10]);    GPU_TESTRANGE(x2);
-       y2 = GPU_EXPANDSIGN_POLY(PacketBuffer.S2[11]);    GPU_TESTRANGE(y2);
+       x0 = GPU_EXPANDSIGN(PacketBuffer.S2[2] );
+       y0 = GPU_EXPANDSIGN(PacketBuffer.S2[3] );
+       x1 = GPU_EXPANDSIGN(PacketBuffer.S2[6] );
+       y1 = GPU_EXPANDSIGN(PacketBuffer.S2[7] );
+       x2 = GPU_EXPANDSIGN(PacketBuffer.S2[10]);
+       y2 = GPU_EXPANDSIGN(PacketBuffer.S2[11]);
+
+       GPU_TESTRANGE3();
 
        x0 += DrawingOffset[0];   x1 += DrawingOffset[0];   x2 += DrawingOffset[0];
        y0 += DrawingOffset[1];   y1 += DrawingOffset[1];   y2 += DrawingOffset[1];
@@ -536,12 +552,14 @@ void gpuDrawGT3(const PP gpuPolySpanDriver)
        s32 g0, g1, g2, g3, dg3=0;
        s32 b0, b1, b2, b3, db3=0;
 
-       x0 = GPU_EXPANDSIGN_POLY(PacketBuffer.S2[2] );   GPU_TESTRANGE(x0);
-       y0 = GPU_EXPANDSIGN_POLY(PacketBuffer.S2[3] );   GPU_TESTRANGE(y0);
-       x1 = GPU_EXPANDSIGN_POLY(PacketBuffer.S2[8] );   GPU_TESTRANGE(x1);
-       y1 = GPU_EXPANDSIGN_POLY(PacketBuffer.S2[9] );   GPU_TESTRANGE(y1);
-       x2 = GPU_EXPANDSIGN_POLY(PacketBuffer.S2[14]);   GPU_TESTRANGE(x2);
-       y2 = GPU_EXPANDSIGN_POLY(PacketBuffer.S2[15]);   GPU_TESTRANGE(y2);
+       x0 = GPU_EXPANDSIGN(PacketBuffer.S2[2] );
+       y0 = GPU_EXPANDSIGN(PacketBuffer.S2[3] );
+       x1 = GPU_EXPANDSIGN(PacketBuffer.S2[8] );
+       y1 = GPU_EXPANDSIGN(PacketBuffer.S2[9] );
+       x2 = GPU_EXPANDSIGN(PacketBuffer.S2[14]);
+       y2 = GPU_EXPANDSIGN(PacketBuffer.S2[15]);
+
+       GPU_TESTRANGE3();
 
        x0 += DrawingOffset[0];   x1 += DrawingOffset[0];   x2 += DrawingOffset[0];
        y0 += DrawingOffset[1];   y1 += DrawingOffset[1];   y2 += DrawingOffset[1];
index 5075227..a700db3 100644 (file)
@@ -29,8 +29,8 @@ void gpuDrawS(const PS gpuSpriteSpanDriver)
        s32 u0;
        s32 v0;
 
-       x1 = x0 = GPU_EXPANDSIGN_SPRT(PacketBuffer.S2[2]) + DrawingOffset[0];
-       y1 = y0 = GPU_EXPANDSIGN_SPRT(PacketBuffer.S2[3]) + DrawingOffset[1];
+       x1 = x0 = GPU_EXPANDSIGN(PacketBuffer.S2[2]) + DrawingOffset[0];
+       y1 = y0 = GPU_EXPANDSIGN(PacketBuffer.S2[3]) + DrawingOffset[1];
        x1+= PacketBuffer.S2[6];
        y1+= PacketBuffer.S2[7];
 
@@ -95,8 +95,8 @@ void gpuDrawS16(void)
        s32 ymin, ymax;
        u32 h = 16;
 
-       x0 = GPU_EXPANDSIGN_SPRT(PacketBuffer.S2[2]) + DrawingOffset[0];
-       y0 = GPU_EXPANDSIGN_SPRT(PacketBuffer.S2[3]) + DrawingOffset[1];
+       x0 = GPU_EXPANDSIGN(PacketBuffer.S2[2]) + DrawingOffset[0];
+       y0 = GPU_EXPANDSIGN(PacketBuffer.S2[3]) + DrawingOffset[1];
 
        xmin = DrawingArea[0];  xmax = DrawingArea[2];
        ymin = DrawingArea[1];  ymax = DrawingArea[3];
@@ -131,8 +131,8 @@ void gpuDrawT(const PT gpuTileSpanDriver)
        s32 x0, y0;
        s32 x1, y1;
 
-       x1 = x0 = GPU_EXPANDSIGN_SPRT(PacketBuffer.S2[2]) + DrawingOffset[0];
-       y1 = y0 = GPU_EXPANDSIGN_SPRT(PacketBuffer.S2[3]) + DrawingOffset[1];
+       x1 = x0 = GPU_EXPANDSIGN(PacketBuffer.S2[2]) + DrawingOffset[0];
+       y1 = y0 = GPU_EXPANDSIGN(PacketBuffer.S2[3]) + DrawingOffset[1];
        x1+= PacketBuffer.S2[4];
        y1+= PacketBuffer.S2[5];
 
index d665895..38e7ce1 100644 (file)
@@ -111,12 +111,10 @@ static u32   GPU_GP1;
 //  GPU Raster Macros
 #define        GPU_RGB16(rgb)        ((((rgb)&0xF80000)>>9)|(((rgb)&0xF800)>>6)|(((rgb)&0xF8)>>3))
 
-#define GPU_EXPANDSIGN_POLY(x)  (((s32)(x)<<20)>>20)
-//#define GPU_EXPANDSIGN_POLY(x)  (((s32)(x)<<21)>>21)
-#define GPU_EXPANDSIGN_SPRT(x)  (((s32)(x)<<21)>>21)
+#define GPU_EXPANDSIGN(x)  (((s32)(x)<<21)>>21)
 
-//#define      GPU_TESTRANGE(x)      { if((u32)(x+1024) > 2047) return; }
-#define        GPU_TESTRANGE(x)      { if ((x<-1023) || (x>1023)) return; }
+#define CHKMAX_X 1024
+#define CHKMAX_Y 512
 
 #define        GPU_SWAP(a,b,t) {(t)=(a);(a)=(b);(b)=(t);}