shithub: duke3d

Download patch

ref: 1a6360ad7073cb0f916bbea176b7625692ca6b52
parent: fffc1875f5823796015581a1f0803fcf8173c685
author: Tanguy Fautre <tanguy@fautre.com>
date: Tue Feb 11 18:03:26 EST 2020

64-bit: Fixing immediate engine crash. The game plays the opening demo.

--- a/Engine/src/draw.c
+++ b/Engine/src/draw.c
@@ -114,9 +114,6 @@
 
     numPixels = i1;
     do {
-		
-		
-
 	    i3 = ((i3&0xffffff00)|(*texture));
 	    i4 -= rmach_eax;
 	    ebp = (((i4+rmach_eax) < i4) ? -1 : 0);
@@ -141,9 +138,9 @@
 static int32_t rmmach_eax;
 static int32_t rmmach_ebx;
 static int32_t rmmach_ecx;
-static int32_t rmmach_edx;
+static uint8_t* rmmach_edx;
 static int32_t setupTileHeight;
-void setuprmhlineasm4(int32_t i1, int32_t i2, int32_t i3, int32_t i4, int32_t tileHeight, int32_t i6)
+void setuprmhlineasm4(int32_t i1, int32_t i2, int32_t i3, uint8_t* i4, int32_t tileHeight, int32_t i6)
 {
     rmmach_eax = i1;
     rmmach_ebx = i2;
@@ -154,11 +151,12 @@
 
 
 //FCS: ????
-void rmhlineasm4(int32_t i1, intptr_t shade, int32_t colorIndex, int32_t i4, int32_t i5, int32_t dest)
+void rmhlineasm4(int32_t i1, uint8_t* shade, int32_t colorIndex, int32_t i4, int32_t i5, uint8_t* dest)
 {
     uint32_t ebp = dest - i1;
     uint32_t rmach6b = ebp-1;
     int32_t numPixels;
+	int32_t offset = i1 + 1;
     
     if (i1 <= 0)
         return;
@@ -165,9 +163,6 @@
 
     numPixels = i1;
     do {
-
-	
-
 	    colorIndex = ((colorIndex&0xffffff00)|(*((uint8_t *)shade)));
 	    i4 -= rmmach_eax;
 	    ebp = (((i4+rmmach_eax) < i4) ? -1 : 0);
@@ -184,8 +179,8 @@
 	    if ((colorIndex&0xff) != 255) {
 			if (pixelsAllowed-- > 0)
 			{
-				i1 = ((i1&0xffffff00)|(((uint8_t  *)colorIndex)[rmmach_edx]));
-				((uint8_t  *)rmach6b)[numPixels] = (i1&0xff);
+				i1 = ((i1&0xffffff00)|rmmach_edx[colorIndex]);
+				dest[numPixels - offset] = (i1 & 0xff);
 			}
 	    }
         
@@ -297,9 +292,9 @@
 
 
 static uint8_t  tran2shr;
-static uint32_t tran2pal_ebx;
-static uint32_t tran2pal_ecx;
-void setuptvlineasm2(int32_t i1, int32_t i2, int32_t i3)
+static uint8_t* tran2pal_ebx;
+static uint8_t* tran2pal_ecx;
+void setuptvlineasm2(int32_t i1, uint8_t* i2, uint8_t* i3)
 {
 	tran2shr = (i1&0x1f);
 	tran2pal_ebx = i2;
@@ -330,7 +325,7 @@
 		if (i3 == 255) { // skipdraw1
 			if (i4 != 255) { // skipdraw3
 				uint16_t val;
-				val = ((uint8_t  *)tran2pal_ecx)[i4];
+				val = tran2pal_ecx[i4];
 				val |= (((uint8_t  *)i6)[tran2edi1]<<8);
 
 				if (transrev) 
@@ -341,7 +336,7 @@
 			}
 		} else if (i4 == 255) { // skipdraw2
 			uint16_t val;
-			val = ((uint8_t  *)tran2pal_ebx)[i3];
+			val = tran2pal_ebx[i3];
 			val |= (((uint8_t  *)i6)[tran2edi]<<8);
 
 			if (transrev) 
@@ -352,8 +347,8 @@
 		} else {
 			uint16_t l = ((uint8_t  *)i6)[tran2edi]<<8;
 			uint16_t r = ((uint8_t  *)i6)[tran2edi1]<<8;
-			l |= ((uint8_t  *)tran2pal_ebx)[i3];
-			r |= ((uint8_t  *)tran2pal_ecx)[i4];
+			l |= tran2pal_ebx[i3];
+			r |= tran2pal_ecx[i4];
 			if (transrev) {
 				l = ((l>>8)|(l<<8));
 				r = ((r>>8)|(r<<8));
@@ -850,10 +845,11 @@
 #define high32(a) ((int)(((__int64)a&(__int64)0xffffffff00000000)>>32))
 
 //FCS: Render RENDER_SLOPPED_CEILING_AND_FLOOR
-void slopevlin(intptr_t i1, uint32_t i2, int32_t i3, int32_t i4, int32_t i5, int32_t i6)
+void slopevlin(intptr_t i1, uint32_t i2, intptr_t* i3, uint32_t index, int32_t i4, int32_t i5, int32_t i6)
 {
     bitwisef2i c;
-    uint32_t ecx,eax,ebx,edx,esi,edi;
+	uintptr_t ecx, eax, ebx, edx, esi;
+	uint32_t edi;
 //This is so bad to cast asm3 to int then float :( !!!
     float a = (float)(int32_t) asm3 + asm2_f;
     i1 -= slopemach_ecx;
@@ -899,11 +895,11 @@
 		    ebx &= slopemach_edx;
 		    edi += eax;
 		    i1 += slopemach_ecx;
-		    edx = ((edx&0xffffff00)|((((uint8_t  *)(ebx+edx))[slopemach_ebx])));
-		    ebx = *((uint32_t*)i3); // register trickery
-		    i3 -= 4;
-		    eax = ((eax&0xffffff00)|(*((uint8_t  *)(ebx+edx))));
-		    ebx = esi;
+		    edx = ((edx&0xffffff00)|((((uint8_t *)(ebx+edx))[slopemach_ebx])));
+			ebx = i3[index];
+			index--;
+			eax = ((eax & 0xffffff00) | (*((uint8_t*)(ebx + edx))));
+			ebx = esi;
 
 			if (pixelsAllowed-- > 0)
 				*((uint8_t  *)i1) = (eax&0xff);
--- a/Engine/src/draw.h
+++ b/Engine/src/draw.h
@@ -31,8 +31,8 @@
 void hlineasm4(int32_t,int32_t,uint32_t,uint32_t,uint8_t*);
 void setuprhlineasm4(int32_t,int32_t,int32_t,uint8_t*,int32_t,int32_t);
 void rhlineasm4(int32_t,uint8_t*,int32_t,uint32_t,uint32_t,uint8_t*);
-void setuprmhlineasm4(int32_t,int32_t,int32_t,int32_t,int32_t,int32_t);
-void rmhlineasm4(int32_t,intptr_t,int32_t,int32_t,int32_t,int32_t);
+void setuprmhlineasm4(int32_t,int32_t,int32_t, uint8_t*,int32_t,int32_t);
+void rmhlineasm4(int32_t, uint8_t*,int32_t,int32_t,int32_t, uint8_t*);
 
 
 void setBytesPerLine(int32_t);
@@ -41,7 +41,7 @@
 int32_t vlineasm1(int32_t,uint8_t*,int32_t,int32_t,uint8_t  *,uint8_t*);
 
 int32_t tvlineasm1(int32_t,uint8_t  *,int32_t,int32_t,uint8_t  *,uint8_t  * dest);
-void setuptvlineasm2(int32_t,int32_t,int32_t);
+void setuptvlineasm2(int32_t, uint8_t*, uint8_t*);
 void tvlineasm2(uint32_t,uint32_t,uintptr_t,uintptr_t,uint32_t,uintptr_t);
 int32_t mvlineasm1(int32_t,uint8_t*,int32_t,int32_t,uint8_t* texture,uint8_t* dest);
 void setupvlineasm(int32_t);
@@ -61,7 +61,7 @@
 void thlineskipmodify(int32_t,uint32_t,uint32_t,int32_t,int32_t,uint8_t *);
 void tsethlineshift(int32_t,int32_t);
 void setupslopevlin(int32_t,intptr_t,int32_t);
-void slopevlin(intptr_t,uint32_t,int32_t,int32_t,int32_t,int32_t);
+void slopevlin(intptr_t,uint32_t,intptr_t*,uint32_t,int32_t,int32_t,int32_t);
     
     
 #define TRANS_NORMAL  0
--- a/Engine/src/engine.c
+++ b/Engine/src/engine.c
@@ -62,7 +62,7 @@
 static char  tempbuf[MAXWALLS];
 
 int32_t ebpbak, espbak;
-int32_t slopalookup[16384];
+intptr_t slopalookup[16384];
 
 /*
  * !!! used to be static. If we ever put the original setgamemode() back, this
@@ -1724,9 +1724,9 @@
 #define BITSOFPRECISION 3  /* Don't forget to change this in A.ASM also! */
 static void grouscan (int32_t dax1, int32_t dax2, int32_t sectnum, uint8_t  dastat)
 {
-    int32_t i, j, l, x, y, dx, dy, wx, wy, y1, y2, daz;
+    int32_t i, l, x, y, dx, dy, wx, wy, y1, y2, daz;
     int32_t daslope, dasqr;
-    int32_t shoffs, shinc, m1, m2, *mptr1, *mptr2, *nptr1, *nptr2;
+    intptr_t j, shoffs, shinc, m1, m2, *mptr1, *mptr2, *nptr1, *nptr2;
     walltype *wal;
     sectortype *sec;
 
@@ -1862,7 +1862,7 @@
     if (sec->visibility != 0) globvis = mulscale4(globvis,(int32_t)((uint8_t )(sec->visibility+16)));
     globvis = mulscale13(globvis,daz);
     globvis = mulscale16(globvis,xdimscale);
-    j =(int32_t) FP_OFF(palookup[globalpal]);
+    j = (intptr_t) palookup[globalpal];
 
     setupslopevlin(((int32_t)(picsiz[globalpicnum]&15))+(((int32_t)(picsiz[globalpicnum]>>4))<<8),tiles[globalpicnum].data,-ylookup[1]);
 
@@ -1880,7 +1880,7 @@
     if (globalzd > 0) m1 += (globalzd>>16);
     else m1 -= (globalzd>>16);
     m2 = m1+l;
-    mptr1 = (int32_t *)&slopalookup[y1+(shoffs>>15)];
+    mptr1 = (intptr_t *)&slopalookup[y1+(shoffs>>15)];
     mptr2 = mptr1+1;
 
     for(x=dax1; x<=dax2; x++)
@@ -1895,8 +1895,8 @@
         }
         if (y1 <= y2)
         {
-            nptr1 = (int32_t *)&slopalookup[y1+(shoffs>>15)];
-            nptr2 = (int32_t *)&slopalookup[y2+(shoffs>>15)];
+            nptr1 = (intptr_t *)&slopalookup[y1+(shoffs>>15)];
+            nptr2 = (intptr_t *)&slopalookup[y2+(shoffs>>15)];
             while (nptr1 <= mptr1)
             {
                 *mptr1-- = j + (getpalookup((int32_t)mulscale24(krecipasm(m1),globvis),globalshade)<<8);
@@ -1911,7 +1911,7 @@
             globalx3 = (globalx2>>10);
             globaly3 = (globaly2>>10);
             asm3 = mulscale16(y2,globalzd) + (globalzx>>6);
-            slopevlin(ylookup[y2]+x+frameoffset,krecipasm(asm3>>3),(int32_t)nptr2,y2-y1+1,globalx1,globaly1);
+            slopevlin(ylookup[y2]+x+frameoffset,krecipasm(asm3>>3),slopalookup,y2+(shoffs>>15),y2-y1+1,globalx1,globaly1);
 
             if ((x&15) == 0) faketimerhandler();
         }
@@ -3047,8 +3047,10 @@
 
 static void transmaskvline(int32_t x)
 {
-    int32_t vplc, vinc, i, palookupoffs;
-    intptr_t bufplc, p;
+    int32_t vplc, vinc, i;
+	uint8_t* palookupoffs;
+    uint8_t* bufplc;
+    uint8_t* p;
     short y1v, y2v;
 
     if ((x < 0) || (x >= xdimen)) return;
@@ -3058,7 +3060,7 @@
     y2v--;
     if (y2v < y1v) return;
 
-    palookupoffs = (int32_t)FP_OFF(palookup[globalpal]) + (getpalookup((int32_t)mulscale16(swall[x],globvis),globalshade)<<8);
+    palookupoffs = palookup[globalpal] + (getpalookup((int32_t)mulscale16(swall[x],globvis),globalshade)<<8);
 
     vinc = swall[x]*globalyscale;
     vplc = globalzd + vinc*(y1v-globalhoriz+1);
@@ -4772,8 +4774,7 @@
     by = mulscale14(globaly2*x1+globaly1,v) + globalypanning;
     asm1 = mulscale14(globalx2,v);
     asm2 = mulscale14(globaly2,v);
-
-    asm3 = (int32_t)FP_OFF(palookup[globalpal]) + (getpalookup((int32_t)mulscale28(klabs(v),globvis),globalshade)<<8);
+    asm3 = (intptr_t) palookup[globalpal] + (getpalookup((int32_t)mulscale28(klabs(v),globvis),globalshade)<<8);
 
     if ((globalorientation&2) == 0)
         mhline(globalbufplc,bx,(x2-x1)<<16,0L,by,ylookup[y]+x1+frameoffset);
--- a/Game/src/duke3d.h
+++ b/Game/src/duke3d.h
@@ -525,10 +525,10 @@
 extern uint8_t  playerreadyflag[MAXPLAYERS],playerquitflag[MAXPLAYERS];
 extern char  sounds[NUM_SOUNDS][14];
 
-extern int32_t script[MAXSCRIPTSIZE],*scriptptr,*insptr,*labelcode,labelcnt;
+extern intptr_t script[MAXSCRIPTSIZE],*scriptptr,*insptr,*labelcode,labelcnt;
 extern char  *label,*textptr,error,warning;
 extern uint8_t killit_flag;
-extern int32_t *actorscrptr[MAXTILES],*parsing_actor;
+extern intptr_t*actorscrptr[MAXTILES],*parsing_actor;
 extern uint8_t  actortype[MAXTILES];
 extern uint8_t  *music_pointer;
 
@@ -550,7 +550,7 @@
     short tempang,actorstayput,dispicnum;
     short timetosleep;
     int32_t floorz,ceilingz,lastvx,lastvy,bposx,bposy,bposz;
-    int32_t temp_data[6];
+    intptr_t temp_data[6];
 };
 
 extern struct weaponhit hittype[MAXSPRITES];
--- a/Game/src/gamedef.c
+++ b/Game/src/gamedef.c
@@ -37,7 +37,7 @@
 
 static short g_i,g_p;
 static int32_t g_x;
-static int32_t *g_t;
+static intptr_t *g_t;
 static spritetype *g_sp;
 
 #define NUMKEYWORDS     112
@@ -445,7 +445,8 @@
 
 uint8_t  parsecommand(int readfromGRP)
 {
-    int32_t i, j, k, *tempscrptr;
+    int32_t i, j, k;
+    intptr_t *tempscrptr;
     uint8_t  done, temp_ifelse_check;
     int32_t tw;
     char *origtptr;
@@ -483,7 +484,7 @@
             {
                 getlabel();
                 scriptptr--;
-                labelcode[labelcnt] = (int32_t) scriptptr;
+                labelcode[labelcnt] = (intptr_t) scriptptr;
                 labelcnt++;
 
                 parsing_state = 1;
@@ -628,7 +629,7 @@
                         break;
                     }
                 if(i == labelcnt)
-                    labelcode[labelcnt++] = (int32_t) scriptptr;
+                    labelcode[labelcnt++] = (intptr_t) scriptptr;
                 for(j=0;j<2;j++)
                 {
                     if(keyword() >= 0) break;
@@ -786,7 +787,7 @@
                     }
 
                 if(i == labelcnt)
-                    labelcode[labelcnt++] = (int32_t) scriptptr;
+                    labelcode[labelcnt++] = (intptr_t) scriptptr;
 
                 for(j=0;j<3;j++)
                 {
@@ -840,7 +841,7 @@
                     }
 
                 if(i == labelcnt)
-                    labelcode[labelcnt++] = (int32_t) scriptptr;
+                    labelcode[labelcnt++] = (intptr_t) scriptptr;
 
                 for(j=0;j<5;j++)
                 {
@@ -1017,7 +1018,7 @@
                 tempscrptr = scriptptr;
                 scriptptr++; //Leave a spot for the fail location
                 parsecommand(readfromGRP);
-                *tempscrptr = (int32_t) scriptptr;
+                *tempscrptr = (intptr_t) scriptptr;
             }
             else
             {
@@ -1098,7 +1099,7 @@
 
             parsecommand(readfromGRP);
 
-            *tempscrptr = (int32_t) scriptptr;
+            *tempscrptr = (intptr_t) scriptptr;
 
             checking_ifelse++;
             return 0;
@@ -1585,7 +1586,7 @@
     total_lines = 0;
 
     passone(readfromGRP); //Tokenize
-    *script = (int32_t) scriptptr;
+    *script = (intptr_t) scriptptr;
 
     if(warning|error)
         printf("Found %hhd warning(s), '%c' error(s).\n",warning,error);
@@ -1764,12 +1765,11 @@
 void alterang(short a)
 {
     short aang, angdif, goalang,j;
-    int32_t ticselapsed, *moveptr;
+    int32_t ticselapsed;
+    intptr_t* moveptr;
 
-    moveptr = (int32_t *)g_t[1];
-
+    moveptr = (intptr_t*)g_t[1];
     ticselapsed = (g_t[0])&31;
-
     aang = g_sp->ang;
 
     g_sp->xvel += (*moveptr-g_sp->xvel)/5;
@@ -1831,7 +1831,8 @@
 
 void move()
 {
-    int32_t l, *moveptr;
+    int32_t l;
+	intptr_t *moveptr;
     short a, goalang, angdif;
     int32_t daxvel;
 
@@ -1898,7 +1899,7 @@
         return;
     }
 
-    moveptr = (int32_t *)g_t[1];
+    moveptr = (intptr_t*)g_t[1];
 
     if(a&geth) g_sp->xvel += (*moveptr-g_sp->xvel)>>1;
     if(a&getv) g_sp->zvel += ((*(moveptr+1)<<4)-g_sp->zvel)>>1;
@@ -2187,9 +2188,9 @@
         case 24:
             insptr++;
             g_t[5] = *insptr;
-            g_t[4] = *(int32_t *)(g_t[5]);       // Action
-            g_t[1] = *(int32_t *)(g_t[5]+4);       // move
-            g_sp->hitag = *(int32_t *)(g_t[5]+8);    // Ai
+            g_t[4] = *(intptr_t*)(g_t[5]);       // Action
+            g_t[1] = *(intptr_t*)(g_t[5]+sizeof(intptr_t));       // move
+            g_sp->hitag = *(intptr_t*)(g_t[5]+sizeof(intptr_t)*2);    // Ai
             g_t[0] = g_t[2] = g_t[3] = 0;
             if(g_sp->hitag&random_angle)
                 g_sp->ang = TRAND&2047;
@@ -2224,7 +2225,7 @@
                 hittype[g_i].timetosleep = SLEEPTIME;
             break;
         case 10:
-            insptr = (int32_t *) *(insptr+1);
+            insptr = (intptr_t*) *(insptr+1);
             break;
         case 100:
             insptr++;
@@ -2575,11 +2576,11 @@
             break;
         case 17:
             {
-                int32_t *tempscrptr;
+				intptr_t *tempscrptr;
 
                 tempscrptr = insptr+2;
 
-                insptr = (int32_t *) *(insptr+1);
+                insptr = (intptr_t *) *(insptr+1);
                 while(1) if(parse()) break;
                 insptr = tempscrptr;
             }
@@ -3153,13 +3154,13 @@
     if(g_t[4])
     {
         g_sp->lotag += TICSPERFRAME;
-        if(g_sp->lotag > *(int32_t *)(g_t[4]+16) )
+        if(g_sp->lotag > *(intptr_t*)(g_t[4]+(sizeof(intptr_t) * 4)))
         {
             g_t[2]++;
             g_sp->lotag = 0;
-            g_t[3] +=  *(int32_t *)( g_t[4]+12 );
+            g_t[3] += *(intptr_t*)(g_t[4] + (sizeof(intptr_t) * 3));
         }
-        if( klabs(g_t[3]) >= klabs( *(int32_t *)(g_t[4]+4) * *(int32_t *)(g_t[4]+12) ) )
+        if( klabs(g_t[3]) >= klabs( *(intptr_t*)(g_t[4]+sizeof(intptr_t)) * *(intptr_t*)(g_t[4]+ (sizeof(intptr_t) * 3)) ))
             g_t[3] = 0;
     }
 
--- a/Game/src/global.c
+++ b/Game/src/global.c
@@ -150,8 +150,8 @@
 uint8_t  playerquitflag[MAXPLAYERS];
 int32_t vel, svel, angvel, horiz, ototalclock, respawnactortime=768, respawnitemtime=768, groupfile;
 
-int32_t script[MAXSCRIPTSIZE],*scriptptr,*insptr,*labelcode,labelcnt;
-int32_t *actorscrptr[MAXTILES],*parsing_actor;
+intptr_t script[MAXSCRIPTSIZE],*scriptptr,*insptr,*labelcode,labelcnt;
+intptr_t *actorscrptr[MAXTILES],*parsing_actor;
 char  *label,*textptr,error,warning ;
 uint8_t killit_flag;
 uint8_t  *music_pointer;