shithub: duke3d

Download patch

ref: bbd9f8059303eb0ec6ea24253a9be1b2e677878c
parent: 6c8d7340dce68608d920aaf8656c65c046df2c9c
author: fabien sanglard <[email protected]>
date: Mon Dec 17 20:36:53 EST 2012

Started to rename a.c methods.

--- a/Engine/src/a.c
+++ b/Engine/src/a.c
@@ -11,9 +11,28 @@
 
 uint32_t pixelsAllowed = 10000000000;
 
+
+static int transrev = 0;
+
+
 #define shrd(a,b,c) (((b)<<(32-(c))) | ((a)>>(c)))
 #define shld(a,b,c) (((b)>>(32-(c))) | ((a)<<(c)))
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/* ---------------  WALLS RENDERING METHOD (USED TO BE HIGHLY OPTIMIZED ASSEMBLY) ----------------------------*/
 extern int32_t asm1;
 extern int32_t asm2;
 extern int32_t asm3;
@@ -30,6 +49,7 @@
 } 
 
 
+
 //FCS:   Draw ceiling/floors
 //Draw a line from destination in the framebuffer to framebuffer-numPixels
 void hlineasm4(int32_t numPixels, int32_t shade, uint32_t i4, uint32_t i5, int32_t destination){
@@ -244,7 +264,7 @@
     return vplce;
 } 
 
-static int transrev = 0;
+
 int32_t tvlineasm1(int32_t i1, int32_t i2, int32_t numPixels, int32_t i4, int32_t i5, int32_t _dest)
 {
 	uint8_t  *source = (uint8_t  *)i5;
@@ -332,8 +352,8 @@
 			val = ((uint8_t  *)tran2pal_ebx)[i3];
 			val |= (((uint8_t  *)i6)[tran2edi]<<8);
 
-			if (transrev) val = 
-				((val>>8)|(val<<8));
+			if (transrev) 
+                val = ((val>>8)|(val<<8));
 
 			if (pixelsAllowed-- > 0)
 				((uint8_t  *)i6)[tran2edi] = transPalette[val];
@@ -367,7 +387,6 @@
     uint32_t temp;
     uint8_t  *dest = (uint8_t  *)i6;
 
-	// FIX_00087: 1024x768 mode being slow. Undone FIX_00070 and fixed font issue again
     for(;i3>=0;i3--)
     {
 		temp = ((uint32_t)vplce) >> machmv;
@@ -383,7 +402,7 @@
 	    dest += bytesperline;
     }
     return vplce;
-} /* mvlineasm1 */
+}
 
 
 void setupvlineasm(int32_t i1)
@@ -391,12 +410,8 @@
     mach3_al = (i1&0x1f);
 }
 
-extern int32_t vplce[4], vince[4], palookupoffse[4], bufplce[4];
-
-
-
-//FCS This is used to fill the inside of a wall
-void vlineasm4(int32_t i1, int32_t i2)
+//FCS This is used to fill the inside of a wall (so it draws VERTICAL column, always).
+void vlineasm4(int32_t columnIndex, int32_t framebuffer)
 {
 
 	if (!RENDER_DRAW_WALL_INSIDE)
@@ -405,8 +420,10 @@
     {
         int i;
         uint32_t temp;
-        uint32_t index = (i2 + ylookup[i1]);
-        uint8_t  *dest = (uint8_t *)(-ylookup[i1]);
+        
+        uint32_t index = (framebuffer + ylookup[columnIndex]);
+        uint8_t  *dest= (uint8_t *)(-ylookup[columnIndex]);
+        
         do {
             for (i = 0; i < 4; i++)
             {
@@ -413,8 +430,10 @@
 				
         	    temp = ((uint32_t)vplce[i]) >> mach3_al;
         	    temp = (((uint8_t *)(bufplce[i]))[temp]);
+                
 				if (pixelsAllowed-- > 0)
         			dest[index+i] = ((uint8_t *)(palookupoffse[i]))[temp];
+                
 	            vplce[i] += vince[i];
             }
             dest += bytesperline;
@@ -425,6 +444,7 @@
 
 void setupmvlineasm(int32_t i1)
 {
+    //Only keep 5 first bits
     machmv = (i1&0x1f);
 } 
 
@@ -456,9 +476,38 @@
         dest += bytesperline;
 
     } while (((uint32_t)dest - bytesperline) < ((uint32_t)dest));
-} /* mvlineasm4 */
+} 
+/* END ---------------  WALLS RENDERING METHOD (USED TO BE HIGHLY OPTIMIZED ASSEMBLY) ----------------------------*/
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/* ---------------  SPRITE RENDERING METHOD (USED TO BE HIGHLY OPTIMIZED ASSEMBLY) ----------------------------*/
 static int32_t spal_eax;
 static int32_t smach_eax;
 static int32_t smach2_eax;
@@ -474,10 +523,9 @@
 } 
 
 
-void spritevline(int32_t i1, uint32_t i2, int32_t i3, uint32_t i4, int32_t i5, int32_t i6)
+void spritevline(int32_t i1, uint32_t i2, int32_t i3, uint32_t i4, uint8_t* source, uint8_t* dest)
 {
-    uint8_t  *source = (uint8_t  *)i5;
-    uint8_t  *dest = (uint8_t  *)i6;
+    
 
 setup:
 
@@ -488,37 +536,35 @@
     else 
 		source += smach2_eax;
 
-draw:
-    i1 = (i1&0xffffff00) | (((uint8_t  *)spal_eax)[i1]&0xff);
+    while(1) {
+        
+        i1 = (i1&0xffffff00) | (((uint8_t  *)spal_eax)[i1]&0xff);
+        
+        if (pixelsAllowed-- > 0)
+            *dest = i1;
+        
+        dest += bytesperline;
 
-	if (pixelsAllowed-- > 0)
-		*dest = i1;
+        i4 += smach_ecx;
+        i4--;
+        if (!((i4 - smach_ecx) > i4) && i4 != 0)
+            goto setup;
+        
+        if (i4 == 0) 
+            return;
+        
+        i2 += smach_eax;
+        
+        i1 = (i1&0xffffff00) | (*source&0xff);
+        
+        if ((i2 - smach_eax) > i2) 
+            source += smach5_eax + 1;
+        else 
+            source += smach5_eax;
+    }
+}
 
-	
 
-    dest += bytesperline;
-
-    i4 += smach_ecx;
-    i4--;
-
-    if (!((i4 - smach_ecx) > i4) && i4 != 0)
-	    goto setup;
-
-    if (i4 == 0) 
-		return;
-
-    i2 += smach_eax;
-    i1 = (i1&0xffffff00) | (*source&0xff);
-
-    if ((i2 - smach_eax) > i2) 
-		source += smach5_eax + 1;
-    else 
-		source += smach5_eax;
-
-    goto draw;
-} /* spritevline */
-
-
 static int32_t mspal_eax;
 static int32_t msmach_eax;
 static int32_t msmach2_eax;
@@ -534,38 +580,49 @@
 } 
 
 
-void mspritevline(int32_t i1, int32_t i2, int32_t i3, int32_t i4, int32_t i5, int32_t i6)
+void mspritevline(int32_t colorIndex, int32_t i2, int32_t i3, int32_t i4, uint8_t  * source, uint8_t  * dest)
 {
-    uint8_t  *source = (uint8_t  *)i5;
-    uint8_t  *dest = (uint8_t  *)i6;
-
+ 
 setup:
     i2 += smach_eax;
-    i1 = (i1&0xffffff00) | (*source&0xff);
-    if ((i2 - smach_eax) > i2) source += smach2_eax + 1;
-    else source += smach2_eax;
+    
+    colorIndex = (colorIndex&0xffffff00) | (*source&0xff);
+    
+    if ((i2 - smach_eax) > i2) 
+        source += smach2_eax + 1;
+    else 
+        source += smach2_eax;
 
-	draw:
-    if ((i1&0xff) != 255)
-    {
-	    i1 = (i1&0xffffff00) | (((uint8_t  *)spal_eax)[i1]&0xff);
-		if (pixelsAllowed-- > 0)
-		  *dest = i1;
-
-	
+	while(1){
+    
+        //Skip transparent pixels (index=255)
+        if ((colorIndex&0xff) != 255)
+        {
+            colorIndex = (colorIndex&0xffffff00) | (((uint8_t  *)spal_eax)[colorIndex]&0xff);
+            
+            if (pixelsAllowed-- > 0)
+                *dest = colorIndex;
+        }
+   
+        dest += bytesperline;
+        i4 += smach_ecx;
+        i4--;
+    
+        if (!((i4 - smach_ecx) > i4) && i4 != 0)
+            goto setup;
+   
+        if (i4 == 0) 
+            return;
+    
+        i2 += smach_eax;
+    
+        colorIndex = (colorIndex&0xffffff00) | (*source&0xff);
+    
+        if ((i2 - smach_eax) > i2) 
+            source += smach5_eax + 1;
+        else 
+            source += smach5_eax;
     }
-    dest += bytesperline;
-
-    i4 += smach_ecx;
-    i4--;
-    if (!((i4 - smach_ecx) > i4) && i4 != 0)
-	    goto setup;
-    if (i4 == 0) return;
-    i2 += smach_eax;
-    i1 = (i1&0xffffff00) | (*source&0xff);
-    if ((i2 - smach_eax) > i2) source += smach5_eax + 1;
-    else source += smach5_eax;
-    goto draw;
 }
 
 
@@ -574,7 +631,7 @@
 uint32_t tsmach_eax2;
 uint32_t tsmach_eax3;
 uint32_t tsmach_ecx;
-void tsetupspritevline(int32_t i1, int32_t i2, int32_t i3, int32_t i4, int32_t i5, int32_t i6)
+void tsetupspritevline(int32_t i1, int32_t i2, int32_t i3, int32_t i4, int32_t i5)
 {
 	tspal = i1;
 	tsmach_eax1 = i5 << 16;
@@ -584,26 +641,36 @@
 } 
 
 
-void tspritevline(int32_t i1, int32_t i2, int32_t numPixels, uint32_t i4, int32_t i5, int32_t dest)
+/*
+ FCS: Draw a sprite vertical line of pixels.
+ */
+void DrawSpriteVerticalLine(int32_t i1, int32_t i2, int32_t numPixels, uint32_t i4, int32_t i5, uint8_t  * dest)
 {
 	while (numPixels)
 	{
 		numPixels--;
+        
 		if (numPixels != 0)
 		{
 			uint32_t adder = tsmach_eax2;
 			i4 += tsmach_ecx;
-			if (i4 < (i4 - tsmach_ecx)) adder = tsmach_eax3;
+            
+			if (i4 < (i4 - tsmach_ecx)) 
+                adder = tsmach_eax3;
+            
 			i1 = *((uint8_t  *)i5);
 			i2 += tsmach_eax1;
-			if (i2 < (i2 - tsmach_eax1)) i5++;
+			if (i2 < (i2 - tsmach_eax1)) 
+                i5++;
+            
 			i5 += adder;
-			// tstartsvline
-			if (i1 != 0xff)
+			
+            //255 is the index of the transparent color: Do not draw it.
+			if (i1 != 255)
 			{
 				uint16_t val;
 				val = ((uint8_t *)tspal)[i1];
-				val |= ((*((uint8_t  *)dest))<<8);
+				val |= (*dest)<<8;
 
 				if (transrev) 
 					val = ((val>>8)|(val<<8));
@@ -611,8 +678,10 @@
 				i1 = transPalette[val];
 
 				if (pixelsAllowed-- > 0)
-					*((uint8_t  *)dest) = (i1&0xff);
+					*dest = (i1&0xff);
 			}
+            
+            //Move down one pixel on the framebuffer
 			dest += bytesperline;
 		}
 
@@ -619,43 +688,74 @@
 		
 	}
 } 
+/* END---------------  SPRITE RENDERING METHOD (USED TO BE HIGHLY OPTIMIZED ASSEMBLY) ----------------------------*/
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/* ---------------  FLOOR/CEILING RENDERING METHOD (USED TO BE HIGHLY OPTIMIZED ASSEMBLY) ----------------------------*/
+
+void settrans(int32_t type){
+	transrev = type;
+}
+
 static int32_t mmach_eax;
 static int32_t mmach_asm3;
 static int32_t mmach_asm1;
 static int32_t mmach_asm2;
 
-void mhline(int32_t i1, int32_t i2, int32_t i3, int32_t i4, int32_t i5, int32_t i6)
+void mhline(int32_t i1, int32_t i2, int32_t i3, int32_t i4, int32_t i5, uint8_t* dest)
 {
     mmach_eax = i1;
     mmach_asm3 = asm3;
     mmach_asm1 = asm1;
     mmach_asm2 = asm2;
-    mhlineskipmodify(asm2,i2,i3,i4,i5,i6);
+    mhlineskipmodify(i2,i3>>16,i4,i5,dest);
 }
 
 
 static uint8_t  mshift_al = 26;
 static uint8_t  mshift_bl = 6;
-void mhlineskipmodify(int32_t i1, uint32_t i2, uint32_t i3, int32_t i4, int32_t i5, int32_t i6)
+void mhlineskipmodify( uint32_t i2, int32_t pixels, int32_t i4, int32_t i5, uint8_t* dest)
 {
     uint32_t ebx;
-    int counter = (i3>>16);
-    while (counter >= 0)
+    int32_t colorIndex;
+    
+    while (pixels >= 0)
     {
 	    ebx = i2 >> mshift_al;
 	    ebx = shld (ebx, (uint32_t)i5, mshift_bl);
-	    i1 = ((uint8_t  *)mmach_eax)[ebx];
+	    colorIndex = ((uint8_t  *)mmach_eax)[ebx];
 
-		if (pixelsAllowed-- > 0)
-			if ((i1&0xff) != 0xff)
-				*((uint8_t  *)i6) = (((uint8_t *)mmach_asm3)[i1]);
-
+        //Skip transparent color.
+		if ((colorIndex&0xff) != 0xff){
+            if (pixelsAllowed-- > 0)
+				*dest = (((uint8_t *)mmach_asm3)[colorIndex]);
+        }
 	    i2 += mmach_asm1;
 	    i5 += mmach_asm2;
-	    i6++;
-	    counter--;
+	    dest++;
+	    pixels--;
 
 		
     }
@@ -825,7 +925,4 @@
 }
 
 
-
-void settrans(int32_t type){
-	transrev = type;
-}
\ No newline at end of file
+/* END ---------------  FLOOR/CEILING RENDERING METHOD (USED TO BE HIGHLY OPTIMIZED ASSEMBLY) ----------------------------*/
\ No newline at end of file
--- a/Engine/src/a.h
+++ b/Engine/src/a.h
@@ -20,6 +20,7 @@
     
 extern uint8_t  *globalpalwritten;
 extern int16_t  globalshiftval;
+extern int32_t vplce[4], vince[4], palookupoffse[4], bufplce[4];
     
 void sethlinesizes(int32_t,int32_t,int32_t);
 
@@ -45,13 +46,13 @@
 void setupmvlineasm(int32_t);
 void mvlineasm4(int32_t,int32_t);
 void setupspritevline(int32_t,int32_t,int32_t,int32_t,int32_t,int32_t);
-void spritevline(int32_t,uint32_t,int32_t,uint32_t,int32_t,int32_t);
+void spritevline(int32_t,uint32_t,int32_t,uint32_t,uint8_t*,uint8_t*);
 void msetupspritevline(int32_t,int32_t,int32_t,int32_t,int32_t,int32_t);
-void mspritevline(int32_t,int32_t,int32_t,int32_t,int32_t,int32_t);
-void tsetupspritevline(int32_t,int32_t,int32_t,int32_t,int32_t,int32_t);
-void tspritevline(int32_t,int32_t,int32_t,uint32_t,int32_t,int32_t);
-void mhline(int32_t,int32_t,int32_t,int32_t,int32_t,int32_t);
-void mhlineskipmodify(int32_t,uint32_t,uint32_t,int32_t,int32_t,int32_t);
+void mspritevline(int32_t,int32_t,int32_t,int32_t,uint8_t  *,uint8_t  *);
+void tsetupspritevline(int32_t,int32_t,int32_t,int32_t,int32_t);
+void DrawSpriteVerticalLine(int32_t,int32_t,int32_t,uint32_t,int32_t,uint8_t*);
+void mhline(int32_t,int32_t,int32_t,int32_t,int32_t,uint8_t*);
+void mhlineskipmodify(uint32_t,int32_t,int32_t,int32_t,uint8_t*);
 void msethlineshift(int32_t,int32_t);
 void thline(int32_t,int32_t,int32_t,int32_t,int32_t,int32_t);
 void thlineskipmodify(int32_t,uint32_t,uint32_t,int32_t,int32_t,int32_t);
--- a/Engine/src/engine.c
+++ b/Engine/src/engine.c
@@ -4109,7 +4109,7 @@
         }
         else
         {
-            tsetupspritevline(palookupoffs,(xv>>16)*ysiz,xv<<16,ysiz,yv,0L);
+            tsetupspritevline(palookupoffs,(xv>>16)*ysiz,xv<<16,ysiz,yv);
 
             if (dastat&32) 
 				settrans(TRANS_REVERSE);
@@ -4163,7 +4163,7 @@
             }
             else
             {
-                tspritevline(0L,by<<16,y2-y1+1,bx<<16,(bx>>16)*ysiz+(by>>16)+bufplc,p);
+                DrawSpriteVerticalLine(0L,by<<16,y2-y1+1,bx<<16,(bx>>16)*ysiz+(by>>16)+bufplc,p);
                 transarea += (y2-y1);
             }
             faketimerhandler();