shithub: duke3d

Download patch

ref: d84248993018cff6ee20e10549ac56d947ebd817
parent: d74a2542f79ae3b033311fe6ddcbbc2f1fa475f9
author: Fabien Sanglard <[email protected]>
date: Fri Dec 14 04:39:27 EST 2012

Formatted code

--- a/Engine/src/engine.c
+++ b/Engine/src/engine.c
@@ -65,7 +65,7 @@
 /* used to be static. --ryan. */
 int32_t curbrightness = 0;
 
-	/* Textured Map variables */
+/* Textured Map variables */
 static uint8_t  globalpolytype;
 static short *dotp1[MAXYDIM], *dotp2[MAXYDIM];
 
@@ -243,16 +243,16 @@
     unsigned short *shlookup_a = (unsigned short*)shlookup;
     unsigned short *sqrtable_a = (unsigned short*)sqrtable;
     unsigned short cx;
-
+    
     if (param & 0xff000000)
 	    cx = shlookup_a[(param>>24)+4096];
     else
 	    cx = shlookup_a[param>>12];
-
+    
     param = param >> (cx&0xff);
     param = ((param&0xffff0000)|sqrtable_a[param]);
     param = param >> ((cx&0xff00)>>8);
-
+    
     return param;
 }
 
@@ -295,9 +295,9 @@
 }
 
 /*
-   FCS: 
-   Scan through sectors using portals (a portal is wall with a nextsector attribute >= 0).
-   Flood is prevented if a portal does not face the POV.
+ FCS:
+ Scan through sectors using portals (a portal is wall with a nextsector attribute >= 0).
+ Flood is prevented if a portal does not face the POV.
  */
 static void scansector (short sectnum)
 {
@@ -306,23 +306,23 @@
 	int32_t xs, ys, x1, y1, x2, y2, xp1, yp1, xp2=0, yp2=0, tempint;
 	short z, zz, startwall, endwall, numscansbefore, scanfirst, bunchfrst;
 	short nextsectnum;
-
+    
 	if (sectnum < 0) return;
-
+    
 	if (automapping) show2dsector[sectnum>>3] |= pow2char[sectnum&7];
-
+    
 	sectorborder[0] = sectnum, sectorbordercnt = 1;
 	do
 	{
 		sectnum = sectorborder[--sectorbordercnt];
-
+        
         //Add every script in the current sector as potentially visible.
 		for(z=headspritesect[sectnum];z>=0;z=nextspritesect[z])
 		{
 			spr = &sprite[z];
 			if ((((spr->cstat&0x8000) == 0) || (showinvisibility)) &&
-				  (spr->xrepeat > 0) && (spr->yrepeat > 0) &&
-				  (spritesortcnt < MAXSPRITESONSCREEN))
+                (spr->xrepeat > 0) && (spr->yrepeat > 0) &&
+                (spritesortcnt < MAXSPRITESONSCREEN))
 			{
 				xs = spr->x-globalposx; ys = spr->y-globalposy;
 				if ((spr->cstat&48) || (xs*cosglobalang+ys*singlobalang > 0))
@@ -332,13 +332,13 @@
 				}
 			}
 		}
-
+        
         //Mark the current sector as "visited"
 		gotsector[sectnum>>3] |= pow2char[sectnum&7];
-
+        
 		bunchfrst = numbunches;
 		numscansbefore = numscans;
-
+        
 		startwall = sector[sectnum].wallptr;
 		endwall = startwall + sector[sectnum].wallnum;
 		scanfirst = numscans;
@@ -345,17 +345,17 @@
 		for(z=startwall,wal=&wall[z];z<endwall;z++,wal++)
 		{
 			nextsectnum = wal->nextsector;
-
+            
 			wal2 = &wall[wal->point2];
             
             // In camera space the center is the player.
             // Make the camera the center of the world for the 2 Wall endpoints (x,y)
-			x1 = wal->x-globalposx;
+            x1 = wal->x-globalposx;
             y1 = wal->y-globalposy;
 			
             x2 = wal2->x-globalposx;
             y2 = wal2->y-globalposy;
-
+            
             // If this is a portal...
 			if ((nextsectnum >= 0) && ((wal->cstat&32) == 0))
                 //If this portal has not been visited yet.
@@ -374,7 +374,7 @@
 							sectorborder[sectorbordercnt++] = nextsectnum;
                     }
 				}
-
+            
             // Rotate the wall endpoint position according to the player orientation.
             // This is a regular rotation matrix using [29.3] fixed point.
 			if ((z == startwall) || (wall[z-1].point2 != z))
@@ -398,10 +398,10 @@
             
             // No idea what this is.
 			if ((yp1 < 256) && (yp2 < 256)) goto skipitaddwall;
-
+            
             /* If wall's NOT facing you */
 			if (dmulscale32(xp1,yp2,-xp2,yp1) >= 0) goto skipitaddwall;
-
+            
             // The wall is still not eligible for rendition: Let's do some more Frustrum culling !!
             
 			if (xp1 >= -yp1)
@@ -431,7 +431,7 @@
 			}
 			if (yb1[numscans] < 256)
                 goto skipitaddwall;
-
+            
 			if (xp2 <= yp2)
 			{
 				if ((xp2 < -yp2) || (yp2 == 0)) goto skipitaddwall;
@@ -449,21 +449,21 @@
 				yb2[numscans] = yp1 + scale(yp2-yp1,yp1-xp1,tempint);
 			}
 			if ((yb2[numscans] < 256) || (xb1[numscans] > xb2[numscans])) goto skipitaddwall;
-
-				/* Made it all the way! */
-			thesector[numscans] = sectnum; 
+            
+            /* Made it all the way! */
+			thesector[numscans] = sectnum;
 			thewall[numscans] = z;
-
+            
 			//Save the camera space wall endpoints coordinate (camera origin at player location + rotated according to player orientation).
-			rx1[numscans] = xp1; 
+			rx1[numscans] = xp1;
 			ry1[numscans] = yp1;
-			rx2[numscans] = xp2; 
+			rx2[numscans] = xp2;
 			ry2[numscans] = yp2;
-
+            
 			p2[numscans] = numscans+1;
 			numscans++;
-skipitaddwall:
-
+        skipitaddwall:
+            
 			if ((wall[z].point2 < z) && (scanfirst < numscans))
 			{
 				p2[numscans-1] = scanfirst;
@@ -470,7 +470,7 @@
 				scanfirst = numscans;
 			}
 		}
-
+        
         //FCS: TODO rename this p2[] to bunchList[] or something like that. This name is an abomination
 		for(z=numscansbefore;z<numscans;z++)
 		{
@@ -480,14 +480,14 @@
 				p2[z] = -1;
 			}
 		}
-
+        
         //For each bunch, cache the last wall of the bunch in bunchlast.
 		for(z=bunchfrst;z<numbunches;z++)
 		{
 			for(zz=bunchfirst[z];p2[zz]>=0;zz=p2[zz]);
-				bunchlast[z] = zz;
+            bunchlast[z] = zz;
 		}
-    
+        
 	} while (sectorbordercnt > 0);
 }
 
@@ -495,19 +495,19 @@
 static void prepwall(int32_t z, walltype *wal)
 {
 	int32_t i, l=0, ol=0, splc, sinc, x, topinc, top, botinc, bot, walxrepeat;
-
+    
 	walxrepeat = (wal->xrepeat<<3);
-
-		/* lwall calculation */
+    
+    /* lwall calculation */
 	i = xb1[z]-halfxdimen;
 	topinc = -(ry1[z]>>2);
 	botinc = ((ry2[z]-ry1[z])>>8);
 	top = mulscale5(rx1[z],xdimen)+mulscale2(topinc,i);
 	bot = mulscale11(rx1[z]-rx2[z],xdimen)+mulscale2(botinc,i);
-
+    
 	splc = mulscale19(ry1[z],xdimscale);
 	sinc = mulscale16(ry2[z]-ry1[z],xdimscale);
-
+    
 	x = xb1[z];
 	if (bot != 0)
 	{
@@ -559,7 +559,7 @@
 			lwall[x+1] = mulscale18(l,walxrepeat);
 		}
 	}
-
+    
 	if (lwall[xb1[z]] < 0) lwall[xb1[z]] = 0;
 	if ((lwall[xb2[z]] >= walxrepeat) && (walxrepeat)) lwall[xb2[z]] = walxrepeat-1;
 	if (wal->cstat&8)
@@ -579,15 +579,15 @@
 static void hline (int32_t xr, int32_t yp)
 {
 	int32_t xl, r, s;
-
+    
 	xl = lastx[yp]; if (xl > xr) return;
 	r = horizlookup2[yp-globalhoriz+horizycent];
 	asm1 = globalx1*r;
 	asm2 = globaly2*r;
 	s = ((int32_t)getpalookup((int32_t)mulscale16(r,globvis),globalshade)<<8);
-
+    
 	hlineasm4(xr-xl,0L,s,globalx2*r+globalypanning,globaly1*r+globalxpanning,
-		ylookup[yp]+xr+frameoffset);
+              ylookup[yp]+xr+frameoffset);
 }
 
 
@@ -594,21 +594,21 @@
 static void slowhline (int32_t xr, int32_t yp)
 {
 	int32_t xl, r;
-
+    
 	xl = lastx[yp]; if (xl > xr) return;
 	r = horizlookup2[yp-globalhoriz+horizycent];
 	asm1 = globalx1*r;
 	asm2 = globaly2*r;
-
+    
 	asm3 = (long)globalpalwritten + ((long)getpalookup((long)mulscale16(r,globvis),globalshade)<<8);
 	if (!(globalorientation&256))
 	{
 		mhline(globalbufplc,globaly1*r+globalxpanning-asm1*(xr-xl),(xr-xl)<<16,0L,
-			globalx2*r+globalypanning-asm2*(xr-xl),ylookup[yp]+xl+frameoffset);
+               globalx2*r+globalypanning-asm2*(xr-xl),ylookup[yp]+xl+frameoffset);
 		return;
 	}
 	thline(globalbufplc,globaly1*r+globalxpanning-asm1*(xr-xl),(xr-xl)<<16,0L,
-		globalx2*r+globalypanning-asm2*(xr-xl),ylookup[yp]+xl+frameoffset);
+           globalx2*r+globalypanning-asm2*(xr-xl),ylookup[yp]+xl+frameoffset);
 	transarea += (xr-xl);
 }
 
@@ -616,7 +616,7 @@
 static int animateoffs(int16_t tilenum, int16_t fakevar)
 {
 	int32_t i, k, offs;
-
+    
 	offs = 0;
 	i = (totalclocklock>>((picanm[tilenum]>>24)&15));
 	if ((picanm[tilenum]&63) > 0)
@@ -632,7 +632,7 @@
 				break;
 			case 128:
 				offs = (i%((picanm[tilenum]&63)+1));
-					break;
+                break;
 			case 192:
 				offs = -(i%((picanm[tilenum]&63)+1));
 		}
@@ -646,7 +646,7 @@
 {
 	int32_t i, j, ox, oy, x, y1, y2, twall, bwall;
 	sectortype *sec;
-
+    
 	sec = &sector[sectnum];
 	if (palookup[sec->ceilingpal] != globalpalwritten)
 	{
@@ -653,7 +653,7 @@
 		globalpalwritten = palookup[sec->ceilingpal];
 		setpalookupaddress(globalpalwritten);
 	}
-
+    
 	globalzd = sec->ceilingz-globalposz;
 	if (globalzd > 0) return;
 	globalpicnum = sec->ceilingpicnum;
@@ -661,16 +661,16 @@
 	setgotpic(globalpicnum);
 	if ((tilesizx[globalpicnum] <= 0) || (tilesizy[globalpicnum] <= 0)) return;
 	if (picanm[globalpicnum]&192) globalpicnum += animateoffs((short)globalpicnum,(short)sectnum);
-
+    
 	if (waloff[globalpicnum] == 0) loadtile(globalpicnum);
 	globalbufplc = waloff[globalpicnum];
-
+    
 	globalshade = (long)sec->ceilingshade;
 	globvis = globalcisibility;
 	if (sec->visibility != 0) globvis = mulscale4(globvis,(long)((uint8_t )(sec->visibility+16)));
 	globalorientation = (long)sec->ceilingstat;
-
-
+    
+    
 	if ((globalorientation&64) == 0)
 	{
 		globalx1 = singlobalang; globalx2 = singlobalang;
@@ -688,7 +688,7 @@
 		globaly1 = mulscale10(dmulscale10(ox,cosglobalang,oy,singlobalang),i);
 		globalx2 = -globalx1;
 		globaly2 = -globaly1;
-
+        
 		ox = ((wall[j].x-globalposx)<<6); oy = ((wall[j].y-globalposy)<<6);
 		i = dmulscale14(oy,cosglobalang,-ox,singlobalang);
 		j = dmulscale14(ox,cosglobalang,oy,singlobalang);
@@ -701,7 +701,7 @@
 	globalxshift = (8-(picsiz[globalpicnum]&15));
 	globalyshift = (8-(picsiz[globalpicnum]>>4));
 	if (globalorientation&8) { globalxshift++; globalyshift++; }
-
+    
 	if ((globalorientation&0x4) > 0)
 	{
 		i = globalxpanning; globalxpanning = globalypanning; globalypanning = i;
@@ -717,9 +717,9 @@
 	globalypanning += (((long)sec->ceilingypanning)<<24);
 	globaly1 = (-globalx1-globaly1)*halfxdimen;
 	globalx2 = (globalx2-globaly2)*halfxdimen;
-
+    
 	sethlinesizes(picsiz[globalpicnum]&15,picsiz[globalpicnum]>>4,globalbufplc);
-
+    
 	globalx2 += globaly2*(x1-1);
 	globaly1 += globalx1*(x1-1);
 	globalx1 = mulscale16(globalx1,globalzd);
@@ -727,7 +727,7 @@
 	globaly1 = mulscale16(globaly1,globalzd);
 	globaly2 = mulscale16(globaly2,globalzd);
 	globvis = klabs(mulscale10(globvis,globalzd));
-
+    
 	if (!(globalorientation&0x180))
 	{
 		y1 = umost[x1]; y2 = y1;
@@ -761,7 +761,7 @@
 		faketimerhandler();
 		return;
 	}
-
+    
 	switch(globalorientation&0x180)
 	{
 		case 128:
@@ -776,7 +776,7 @@
 			tsethlineshift(picsiz[globalpicnum]&15,picsiz[globalpicnum]>>4);
 			break;
 	}
-
+    
 	y1 = umost[x1]; y2 = y1;
 	for(x=x1;x<=x2;x++)
 	{
@@ -814,7 +814,7 @@
 {
 	int32_t i, j, ox, oy, x, y1, y2, twall, bwall;
 	sectortype *sec;
-
+    
 	sec = &sector[sectnum];
 	if (palookup[sec->floorpal] != globalpalwritten)
 	{
@@ -821,7 +821,7 @@
 		globalpalwritten = palookup[sec->floorpal];
 		setpalookupaddress(globalpalwritten);
 	}
-
+    
 	globalzd = globalposz-sec->floorz;
 	if (globalzd > 0) return;
 	globalpicnum = sec->floorpicnum;
@@ -829,16 +829,16 @@
 	setgotpic(globalpicnum);
 	if ((tilesizx[globalpicnum] <= 0) || (tilesizy[globalpicnum] <= 0)) return;
 	if (picanm[globalpicnum]&192) globalpicnum += animateoffs((short)globalpicnum,(short)sectnum);
-
+    
 	if (waloff[globalpicnum] == 0) loadtile(globalpicnum);
 	globalbufplc = waloff[globalpicnum];
-
+    
 	globalshade = (long)sec->floorshade;
 	globvis = globalcisibility;
 	if (sec->visibility != 0) globvis = mulscale4(globvis,(long)((uint8_t )(sec->visibility+16)));
 	globalorientation = (long)sec->floorstat;
-
-
+    
+    
 	if ((globalorientation&64) == 0)
 	{
 		globalx1 = singlobalang; globalx2 = singlobalang;
@@ -856,7 +856,7 @@
 		globaly1 = mulscale10(dmulscale10(ox,cosglobalang,oy,singlobalang),i);
 		globalx2 = -globalx1;
 		globaly2 = -globaly1;
-
+        
 		ox = ((wall[j].x-globalposx)<<6); oy = ((wall[j].y-globalposy)<<6);
 		i = dmulscale14(oy,cosglobalang,-ox,singlobalang);
 		j = dmulscale14(ox,cosglobalang,oy,singlobalang);
@@ -869,7 +869,7 @@
 	globalxshift = (8-(picsiz[globalpicnum]&15));
 	globalyshift = (8-(picsiz[globalpicnum]>>4));
 	if (globalorientation&8) { globalxshift++; globalyshift++; }
-
+    
 	if ((globalorientation&0x4) > 0)
 	{
 		i = globalxpanning; globalxpanning = globalypanning; globalypanning = i;
@@ -885,9 +885,9 @@
 	globalypanning += (((long)sec->floorypanning)<<24);
 	globaly1 = (-globalx1-globaly1)*halfxdimen;
 	globalx2 = (globalx2-globaly2)*halfxdimen;
-
+    
 	sethlinesizes(picsiz[globalpicnum]&15,picsiz[globalpicnum]>>4,globalbufplc);
-
+    
 	globalx2 += globaly2*(x1-1);
 	globaly1 += globalx1*(x1-1);
 	globalx1 = mulscale16(globalx1,globalzd);
@@ -895,7 +895,7 @@
 	globaly1 = mulscale16(globaly1,globalzd);
 	globaly2 = mulscale16(globaly2,globalzd);
 	globvis = klabs(mulscale10(globvis,globalzd));
-
+    
 	if (!(globalorientation&0x180))
 	{
 		y1 = max(dplc[x1],umost[x1]); y2 = y1;
@@ -929,7 +929,7 @@
 		faketimerhandler();
 		return;
 	}
-
+    
 	switch(globalorientation&0x180)
 	{
 		case 128:
@@ -944,7 +944,7 @@
 			tsethlineshift(picsiz[globalpicnum]&15,picsiz[globalpicnum]>>4);
 			break;
 	}
-
+    
 	y1 = max(dplc[x1],umost[x1]); y2 = y1;
 	for(x=x1;x<=x2;x++)
 	{
@@ -1008,7 +1008,7 @@
 	int32_t i, x, xnice, ynice, fpalookup;
 	int32_t y1ve[4], y2ve[4], u4, d4, z, tsizx, tsizy;
 	uint8_t  bad;
-
+    
 	tsizx = tilesizx[globalpicnum];
 	tsizy = tilesizy[globalpicnum];
 	setgotpic(globalpicnum);
@@ -1015,29 +1015,29 @@
 	if ((tsizx <= 0) || (tsizy <= 0)) return;
 	if ((uwal[x1] > ydimen) && (uwal[x2] > ydimen)) return;
 	if ((dwal[x1] < 0) && (dwal[x2] < 0)) return;
-
+    
 	if (waloff[globalpicnum] == 0) loadtile(globalpicnum);
-
+    
 	xnice = (pow2long[picsiz[globalpicnum]&15] == tsizx);
 	if (xnice) tsizx--;
 	ynice = (pow2long[picsiz[globalpicnum]>>4] == tsizy);
 	if (ynice) tsizy = (picsiz[globalpicnum]>>4);
-
+    
 	fpalookup = (long)FP_OFF(palookup[globalpal]);
-
+    
 	setupvlineasm(globalshiftval);
-
+    
 	x = x1;
 	while ((umost[x] > dmost[x]) && (x <= x2)) x++;
-
+    
 	for(;(x<=x2)&&((x+frameoffset)&3);x++)
 	{
 		y1ve[0] = max(uwal[x],umost[x]);
 		y2ve[0] = min(dwal[x],dmost[x]);
 		if (y2ve[0] <= y1ve[0]) continue;
-
+        
 		palookupoffse[0] = fpalookup+(getpalookup((long)mulscale16(swal[x],globvis),globalshade)<<8);
-
+        
 		bufplce[0] = lwal[x] + globalxpanning;
 		if (bufplce[0] >= tsizx)
         {
@@ -1051,10 +1051,10 @@
             bufplce[0] *= tsizy;
         else
             bufplce[0] <<= tsizy;
-
+        
 		vince[0] = swal[x]*globalyscale;
 		vplce[0] = globalzd + vince[0]*(y1ve[0]-globalhoriz+1);
-
+        
 		vlineasm1(vince[0],palookupoffse[0],y2ve[0]-y1ve[0]-1,vplce[0],bufplce[0]+waloff[globalpicnum],x+frameoffset+ylookup[y1ve[0]]);
 	}
 	for(;x<=x2-3;x+=4)
@@ -1070,21 +1070,21 @@
                 bad += pow2char[z];
                 continue;
             }
-
+            
 			i = lwal[x+z] + globalxpanning;
 			if (i >= tsizx) { if (xnice == 0) i %= tsizx; else i &= tsizx; }
 			if (ynice == 0) i *= tsizy; else i <<= tsizy;
 			bufplce[z] = waloff[globalpicnum]+i;
-
+            
 			vince[z] = swal[x+z]*globalyscale;
 			vplce[z] = globalzd + vince[z]*(y1ve[z]-globalhoriz+1);
 		}
         
 		if (bad == 15) continue;
-
+        
 		palookupoffse[0] = fpalookup+(getpalookup((long)mulscale16(swal[x],globvis),globalshade)<<8);
 		palookupoffse[3] = fpalookup+(getpalookup((long)mulscale16(swal[x+3],globvis),globalshade)<<8);
-
+        
 		if ((palookupoffse[0] == palookupoffse[3]) && ((bad&0x9) == 0))
 		{
 			palookupoffse[1] = palookupoffse[0];
@@ -1095,10 +1095,10 @@
 			palookupoffse[1] = fpalookup+(getpalookup((long)mulscale16(swal[x+1],globvis),globalshade)<<8);
 			palookupoffse[2] = fpalookup+(getpalookup((long)mulscale16(swal[x+2],globvis),globalshade)<<8);
 		}
-
+        
 		u4 = max(max(y1ve[0],y1ve[1]),max(y1ve[2],y1ve[3]));
 		d4 = min(min(y2ve[0],y2ve[1]),min(y2ve[2],y2ve[3]));
-
+        
 		if ((bad != 0) || (u4 >= d4))
 		{
 			if (!(bad&1)) prevlineasm1(vince[0],palookupoffse[0],y2ve[0]-y1ve[0],vplce[0],bufplce[0],ylookup[y1ve[0]]+x+frameoffset+0);
@@ -1107,14 +1107,14 @@
 			if (!(bad&8)) prevlineasm1(vince[3],palookupoffse[3],y2ve[3]-y1ve[3],vplce[3],bufplce[3],ylookup[y1ve[3]]+x+frameoffset+3);
 			continue;
 		}
-
+        
 		if (u4 > y1ve[0]) vplce[0] = prevlineasm1(vince[0],palookupoffse[0],u4-y1ve[0]-1,vplce[0],bufplce[0],ylookup[y1ve[0]]+x+frameoffset+0);
 		if (u4 > y1ve[1]) vplce[1] = prevlineasm1(vince[1],palookupoffse[1],u4-y1ve[1]-1,vplce[1],bufplce[1],ylookup[y1ve[1]]+x+frameoffset+1);
 		if (u4 > y1ve[2]) vplce[2] = prevlineasm1(vince[2],palookupoffse[2],u4-y1ve[2]-1,vplce[2],bufplce[2],ylookup[y1ve[2]]+x+frameoffset+2);
 		if (u4 > y1ve[3]) vplce[3] = prevlineasm1(vince[3],palookupoffse[3],u4-y1ve[3]-1,vplce[3],bufplce[3],ylookup[y1ve[3]]+x+frameoffset+3);
-
+        
 		if (d4 >= u4) vlineasm4(d4-u4+1,ylookup[u4]+x+frameoffset);
-
+        
 		i = x+frameoffset+ylookup[d4+1];
 		if (y2ve[0] > d4) prevlineasm1(vince[0],palookupoffse[0],y2ve[0]-d4-1,vplce[0],bufplce[0],i+0);
 		if (y2ve[1] > d4) prevlineasm1(vince[1],palookupoffse[1],y2ve[1]-d4-1,vplce[1],bufplce[1],i+1);
@@ -1126,16 +1126,16 @@
 		y1ve[0] = max(uwal[x],umost[x]);
 		y2ve[0] = min(dwal[x],dmost[x]);
 		if (y2ve[0] <= y1ve[0]) continue;
-
+        
 		palookupoffse[0] = fpalookup+(getpalookup((long)mulscale16(swal[x],globvis),globalshade)<<8);
-
+        
 		bufplce[0] = lwal[x] + globalxpanning;
 		if (bufplce[0] >= tsizx) { if (xnice == 0) bufplce[0] %= tsizx; else bufplce[0] &= tsizx; }
 		if (ynice == 0) bufplce[0] *= tsizy; else bufplce[0] <<= tsizy;
-
+        
 		vince[0] = swal[x]*globalyscale;
 		vplce[0] = globalzd + vince[0]*(y1ve[0]-globalhoriz+1);
-
+        
 		vlineasm1(vince[0],palookupoffse[0],y2ve[0]-y1ve[0]-1,vplce[0],bufplce[0]+waloff[globalpicnum],x+frameoffset+ylookup[y1ve[0]]);
 	}
 	faketimerhandler();
@@ -1150,7 +1150,7 @@
 	int32_t i, x, startx, xnice, ynice, fpalookup;
 	int32_t y1ve[4], y2ve[4], u4, d4, dax, z, p, tsizx, tsizy;
 	uint8_t  bad;
-
+    
 	tsizx = tilesizx[globalpicnum];
 	tsizy = tilesizy[globalpicnum];
 	setgotpic(globalpicnum);
@@ -1157,40 +1157,40 @@
 	if ((tsizx <= 0) || (tsizy <= 0)) return;
 	if ((uwal[x1] > ydimen) && (uwal[x2] > ydimen)) return;
 	if ((dwal[x1] < 0) && (dwal[x2] < 0)) return;
-
+    
 	if (waloff[globalpicnum] == 0) loadtile(globalpicnum);
-
+    
 	startx = x1;
-
+    
 	xnice = (pow2long[picsiz[globalpicnum]&15] == tsizx);
 	if (xnice) tsizx = (tsizx-1);
 	ynice = (pow2long[picsiz[globalpicnum]>>4] == tsizy);
 	if (ynice) tsizy = (picsiz[globalpicnum]>>4);
-
+    
 	fpalookup = (long)FP_OFF(palookup[globalpal]);
-
+    
 	setupmvlineasm(globalshiftval);
-
+    
 	x = startx;
 	while ((startumost[x+windowx1] > startdmost[x+windowx1]) && (x <= x2)) x++;
-
+    
 	p = x+frameoffset;
-
+    
 	for(;(x<=x2)&&(p&3);x++,p++)
 	{
 		y1ve[0] = max(uwal[x],startumost[x+windowx1]-windowy1);
 		y2ve[0] = min(dwal[x],startdmost[x+windowx1]-windowy1);
 		if (y2ve[0] <= y1ve[0]) continue;
-
+        
 		palookupoffse[0] = fpalookup+(getpalookup((long)mulscale16(swal[x],globvis),globalshade)<<8);
-
+        
 		bufplce[0] = lwal[x] + globalxpanning;
 		if (bufplce[0] >= tsizx) { if (xnice == 0) bufplce[0] %= tsizx; else bufplce[0] &= tsizx; }
 		if (ynice == 0) bufplce[0] *= tsizy; else bufplce[0] <<= tsizy;
-
+        
 		vince[0] = swal[x]*globalyscale;
 		vplce[0] = globalzd + vince[0]*(y1ve[0]-globalhoriz+1);
-
+        
 		mvlineasm1(vince[0],palookupoffse[0],y2ve[0]-y1ve[0]-1,vplce[0],bufplce[0]+waloff[globalpicnum],p+ylookup[y1ve[0]]);
 	}
 	for(;x<=x2-3;x+=4,p+=4)
@@ -1201,20 +1201,20 @@
 			y1ve[z] = max(uwal[dax],startumost[dax+windowx1]-windowy1);
 			y2ve[z] = min(dwal[dax],startdmost[dax+windowx1]-windowy1)-1;
 			if (y2ve[z] < y1ve[z]) { bad += pow2char[z]; continue; }
-
+            
 			i = lwal[dax] + globalxpanning;
 			if (i >= tsizx) { if (xnice == 0) i %= tsizx; else i &= tsizx; }
 			if (ynice == 0) i *= tsizy; else i <<= tsizy;
 			bufplce[z] = waloff[globalpicnum]+i;
-
+            
 			vince[z] = swal[dax]*globalyscale;
 			vplce[z] = globalzd + vince[z]*(y1ve[z]-globalhoriz+1);
 		}
 		if (bad == 15) continue;
-
+        
 		palookupoffse[0] = fpalookup+(getpalookup((long)mulscale16(swal[x],globvis),globalshade)<<8);
 		palookupoffse[3] = fpalookup+(getpalookup((long)mulscale16(swal[x+3],globvis),globalshade)<<8);
-
+        
 		if ((palookupoffse[0] == palookupoffse[3]) && ((bad&0x9) == 0))
 		{
 			palookupoffse[1] = palookupoffse[0];
@@ -1225,10 +1225,10 @@
 			palookupoffse[1] = fpalookup+(getpalookup((long)mulscale16(swal[x+1],globvis),globalshade)<<8);
 			palookupoffse[2] = fpalookup+(getpalookup((long)mulscale16(swal[x+2],globvis),globalshade)<<8);
 		}
-
+        
 		u4 = max(max(y1ve[0],y1ve[1]),max(y1ve[2],y1ve[3]));
 		d4 = min(min(y2ve[0],y2ve[1]),min(y2ve[2],y2ve[3]));
-
+        
 		if ((bad > 0) || (u4 >= d4))
 		{
 			if (!(bad&1)) mvlineasm1(vince[0],palookupoffse[0],y2ve[0]-y1ve[0],vplce[0],bufplce[0],ylookup[y1ve[0]]+p+0);
@@ -1237,14 +1237,14 @@
 			if (!(bad&8)) mvlineasm1(vince[3],palookupoffse[3],y2ve[3]-y1ve[3],vplce[3],bufplce[3],ylookup[y1ve[3]]+p+3);
 			continue;
 		}
-
+        
 		if (u4 > y1ve[0]) vplce[0] = mvlineasm1(vince[0],palookupoffse[0],u4-y1ve[0]-1,vplce[0],bufplce[0],ylookup[y1ve[0]]+p+0);
 		if (u4 > y1ve[1]) vplce[1] = mvlineasm1(vince[1],palookupoffse[1],u4-y1ve[1]-1,vplce[1],bufplce[1],ylookup[y1ve[1]]+p+1);
 		if (u4 > y1ve[2]) vplce[2] = mvlineasm1(vince[2],palookupoffse[2],u4-y1ve[2]-1,vplce[2],bufplce[2],ylookup[y1ve[2]]+p+2);
 		if (u4 > y1ve[3]) vplce[3] = mvlineasm1(vince[3],palookupoffse[3],u4-y1ve[3]-1,vplce[3],bufplce[3],ylookup[y1ve[3]]+p+3);
-
+        
 		if (d4 >= u4) mvlineasm4(d4-u4+1,ylookup[u4]+p);
-
+        
 		i = p+ylookup[d4+1];
 		if (y2ve[0] > d4) mvlineasm1(vince[0],palookupoffse[0],y2ve[0]-d4-1,vplce[0],bufplce[0],i+0);
 		if (y2ve[1] > d4) mvlineasm1(vince[1],palookupoffse[1],y2ve[1]-d4-1,vplce[1],bufplce[1],i+1);
@@ -1256,16 +1256,16 @@
 		y1ve[0] = max(uwal[x],startumost[x+windowx1]-windowy1);
 		y2ve[0] = min(dwal[x],startdmost[x+windowx1]-windowy1);
 		if (y2ve[0] <= y1ve[0]) continue;
-
+        
 		palookupoffse[0] = fpalookup+(getpalookup((long)mulscale16(swal[x],globvis),globalshade)<<8);
-
+        
 		bufplce[0] = lwal[x] + globalxpanning;
 		if (bufplce[0] >= tsizx) { if (xnice == 0) bufplce[0] %= tsizx; else bufplce[0] &= tsizx; }
 		if (ynice == 0) bufplce[0] *= tsizy; else bufplce[0] <<= tsizy;
-
+        
 		vince[0] = swal[x]*globalyscale;
 		vplce[0] = globalzd + vince[0]*(y1ve[0]-globalhoriz+1);
-
+        
 		mvlineasm1(vince[0],palookupoffse[0],y2ve[0]-y1ve[0]-1,vplce[0],bufplce[0]+waloff[globalpicnum],p+ylookup[y1ve[0]]);
 	}
 	faketimerhandler();
@@ -1278,9 +1278,9 @@
 	sectortype *sec;
 	int32_t j, k, l, m, n, x, z, wallnum, nextsectnum, globalhorizbak;
 	short *topptr, *botptr;
-
+    
 	sectnum = thesector[bunchfirst[bunch]]; sec = &sector[sectnum];
-
+    
 	globalhorizbak = globalhoriz;
 	if (parallaxyscale != 65536)
 		globalhoriz = mulscale16(globalhoriz-(ydimen>>1),parallaxyscale) + (ydimen>>1);
@@ -1287,7 +1287,7 @@
 	globvis = globalpisibility;
 	/* globalorientation = 0L; */
 	if (sec->visibility != 0) globvis = mulscale4(globvis,(long)((uint8_t )(sec->visibility+16)));
-
+    
 	if (dastat == 0)
 	{
 		globalpal = sec->ceilingpal;
@@ -1308,7 +1308,7 @@
 		topptr = dplc;
 		botptr = dmost;
 	}
-
+    
 	if ((unsigned)globalpicnum >= (unsigned)MAXTILES) globalpicnum = 0;
 	if (picanm[globalpicnum]&192) globalpicnum += animateoffs(globalpicnum,(short)sectnum);
 	globalshiftval = (picsiz[globalpicnum]>>4);
@@ -1317,21 +1317,21 @@
 	globalzd = (((tilesizy[globalpicnum]>>1)+parallaxyoffs)<<globalshiftval)+(globalypanning<<24);
 	globalyscale = (8<<(globalshiftval-19));
 	/*if (globalorientation&256) globalyscale = -globalyscale, globalzd = -globalzd;*/
-
+    
 	k = 11 - (picsiz[globalpicnum]&15) - pskybits;
 	x = -1;
-
+    
 	for(z=bunchfirst[bunch];z>=0;z=p2[z])
 	{
 		wallnum = thewall[z]; nextsectnum = wall[wallnum].nextsector;
-
+        
 		if (dastat == 0) j = sector[nextsectnum].ceilingstat;
-						else j = sector[nextsectnum].floorstat;
-
+        else j = sector[nextsectnum].floorstat;
+        
 		if ((nextsectnum < 0) || (wall[wallnum].cstat&32) || ((j&1) == 0))
 		{
 			if (x == -1) x = xb1[z];
-
+            
 			if (parallaxtype == 0)
 			{
 				n = mulscale16(xdimenrecip,viewingrange);
@@ -1356,7 +1356,7 @@
 		{
 			l = globalpicnum; m = (picsiz[globalpicnum]&15);
 			globalpicnum = l+pskyoff[lplc[x]>>m];
-
+            
 			if (((lplc[x]^lplc[xb1[z]-1])>>m) == 0)
 				wallscan(x,xb1[z]-1,topptr,botptr,swplc,lplc);
 			else
@@ -1376,17 +1376,17 @@
 				if (j < x)
 					wallscan(j,x-1,topptr,botptr,swplc,lplc);
 			}
-
+            
 			globalpicnum = l;
 			x = -1;
 		}
 	}
-
+    
 	if (x >= 0)
 	{
 		l = globalpicnum; m = (picsiz[globalpicnum]&15);
 		globalpicnum = l+pskyoff[lplc[x]>>m];
-
+        
 		if (((lplc[x]^lplc[xb2[bunchlast[bunch]]])>>m) == 0)
 			wallscan(x,xb2[bunchlast[bunch]],topptr,botptr,swplc,lplc);
 		else
@@ -1420,9 +1420,9 @@
 	int32_t shoffs, shinc, m1, m2, *mptr1, *mptr2, *nptr1, *nptr2;
 	walltype *wal;
 	sectortype *sec;
-
+    
 	sec = &sector[sectnum];
-
+    
 	if (dastat == 0)
 	{
 		if (globalposz <= getceilzofslope((short) sectnum,globalposx,globalposy))
@@ -1445,12 +1445,12 @@
 		daslope = sec->floorheinum;
 		daz = sec->floorz;
 	}
-
+    
 	if ((picanm[globalpicnum]&192) != 0) globalpicnum += animateoffs(globalpicnum,(short) sectnum);
 	setgotpic(globalpicnum);
 	if ((tilesizx[globalpicnum] <= 0) || (tilesizy[globalpicnum] <= 0)) return;
 	if (waloff[globalpicnum] == 0) loadtile(globalpicnum);
-
+    
 	wal = &wall[sec->wallptr];
 	wx = wall[wal->point2].x - wal->x;
 	wy = wall[wal->point2].y - wal->y;
@@ -1457,7 +1457,7 @@
 	dasqr = krecipasm(nsqrtasm(wx*wx+wy*wy));
 	i = mulscale21(daslope,dasqr);
 	wx *= i; wy *= i;
-
+    
 	globalx = -mulscale19(singlobalang,xdimenrecip);
 	globaly = mulscale19(cosglobalang,xdimenrecip);
 	globalx1 = (globalposx<<8);
@@ -1468,22 +1468,22 @@
 	globalzd = (xdimscale<<9);
 	globalzx = -dmulscale17(wx,globaly2,-wy,globalx2) + mulscale10(1-globalhoriz,globalzd);
 	globalz = -dmulscale25(wx,globaly,-wy,globalx);
-
+    
 	if (globalorientation&64)  /* Relative alignment */
 	{
 		dx = mulscale14(wall[wal->point2].x-wal->x,dasqr);
 		dy = mulscale14(wall[wal->point2].y-wal->y,dasqr);
-
+        
 		i = nsqrtasm(daslope*daslope+16777216);
-
+        
 		x = globalx; y = globaly;
 		globalx = dmulscale16(x,dx,y,dy);
 		globaly = mulscale12(dmulscale16(-y,dx,x,dy),i);
-
+        
 		x = ((wal->x-globalposx)<<8); y = ((wal->y-globalposy)<<8);
 		globalx1 = dmulscale16(-x,dx,-y,dy);
 		globaly1 = mulscale12(dmulscale16(-y,dx,x,dy),i);
-
+        
 		x = globalx2; y = globaly2;
 		globalx2 = dmulscale16(x,dx,y,dy);
 		globaly2 = mulscale12(dmulscale16(-y,dx,x,dy),i);
@@ -1496,16 +1496,16 @@
 	}
 	if (globalorientation&0x10) { globalx1 = -globalx1, globalx2 = -globalx2, globalx = -globalx; }
 	if (globalorientation&0x20) { globaly1 = -globaly1, globaly2 = -globaly2, globaly = -globaly; }
-
+    
 	daz = dmulscale9(wx,globalposy-wal->y,-wy,globalposx-wal->x) + ((daz-globalposz)<<8);
 	globalx2 = mulscale20(globalx2,daz); globalx = mulscale28(globalx,daz);
 	globaly2 = mulscale20(globaly2,-daz); globaly = mulscale28(globaly,-daz);
-
+    
 	i = 8-(picsiz[globalpicnum]&15); j = 8-(picsiz[globalpicnum]>>4);
 	if (globalorientation&8) { i++; j++; }
 	globalx1 <<= (i+12); globalx2 <<= i; globalx <<= i;
 	globaly1 <<= (j+12); globaly2 <<= j; globaly <<= j;
-
+    
 	if (dastat == 0)
 	{
 		globalx1 += (((long)sec->ceilingxpanning)<<24);
@@ -1516,28 +1516,28 @@
 		globalx1 += (((long)sec->floorxpanning)<<24);
 		globaly1 += (((long)sec->floorypanning)<<24);
 	}
-
+    
 	asm1 = -(globalzd>>(16-BITSOFPRECISION));
-
+    
 	globvis = globalvisibility;
 	if (sec->visibility != 0) globvis = mulscale4(globvis,(long)((uint8_t )(sec->visibility+16)));
 	globvis = mulscale13(globvis,daz);
 	globvis = mulscale16(globvis,xdimscale);
 	j =(long) FP_OFF(palookup[globalpal]);
-
+    
 	setupslopevlin(((long)(picsiz[globalpicnum]&15))+(((long)(picsiz[globalpicnum]>>4))<<8),waloff[globalpicnum],-ylookup[1]);
-
+    
 	l = (globalzd>>16);
-
+    
 	shinc = mulscale16(globalz,xdimenscale);
 	if (shinc > 0) shoffs = (4<<15); else shoffs = ((16380-ydimen)<<15);	// JBF: was 2044     16380
 	if (dastat == 0) y1 = umost[dax1]; else y1 = max(umost[dax1],dplc[dax1]);
 	m1 = mulscale16(y1,globalzd) + (globalzx>>6);
-		/* Avoid visibility overflow by crossing horizon */
+    /* Avoid visibility overflow by crossing horizon */
 	if (globalzd > 0) m1 += (globalzd>>16); else m1 -= (globalzd>>16);
 	m2 = m1+l;
 	mptr1 = (int32_t *)&slopalookup[y1+(shoffs>>15)]; mptr2 = mptr1+1;
-
+    
 	for(x=dax1;x<=dax2;x++)
 	{
 		if (dastat == 0) { y1 = umost[x]; y2 = min(dmost[x],uplc[x])-1; }
@@ -1556,12 +1556,12 @@
 				*mptr2++ = j + (getpalookup((long)mulscale24(krecipasm(m2),globvis),globalshade)<<8);
 				m2 += l;
 			}
-
+            
 			globalx3 = (globalx2>>10);
 			globaly3 = (globaly2>>10);
-			asm3 = mulscale16(y2,globalzd) + (globalzx>>6);		
+			asm3 = mulscale16(y2,globalzd) + (globalzx>>6);
 			slopevlin(ylookup[y2]+x+frameoffset,krecipasm(asm3>>3),(long)nptr2,y2-y1+1,globalx1,globaly1);
-
+            
 			if ((x&15) == 0) faketimerhandler();
 		}
 		globalx2 += globalx;
@@ -1576,33 +1576,33 @@
 {
 	int32_t bad, inty, xcross, y, yinc;
 	int32_t s1, s2, s3, s4, ix1, ix2, iy1, iy2, t;
-
+    
 	z <<= 7;
 	s1 = mulscale20(globaluclip,yb1[w]); s2 = mulscale20(globaluclip,yb2[w]);
 	s3 = mulscale20(globaldclip,yb1[w]); s4 = mulscale20(globaldclip,yb2[w]);
 	bad = (z<s1)+((z<s2)<<1)+((z>s3)<<2)+((z>s4)<<3);
-
+    
 	ix1 = xb1[w]; iy1 = yb1[w];
 	ix2 = xb2[w]; iy2 = yb2[w];
-
+    
 	if ((bad&3) == 3)
 	{
 		clearbufbyte(&mostbuf[ix1],(ix2-ix1+1)*sizeof(mostbuf[0]),0L);
 		return(bad);
 	}
-
+    
 	if ((bad&12) == 12)
 	{
 		clearbufbyte(&mostbuf[ix1],(ix2-ix1+1)*sizeof(mostbuf[0]),ydimen+(ydimen<<16));
 		return(bad);
 	}
-
+    
 	if (bad&3)
 	{
 		t = divscale30(z-s1,s2-s1);
 		inty = yb1[w] + mulscale30(yb2[w]-yb1[w],t);
 		xcross = xb1[w] + scale(mulscale30(yb2[w],t),xb2[w]-xb1[w],inty);
-
+        
 		if ((bad&3) == 2)
 		{
 			if (xb1[w] <= xcross) { iy2 = inty; ix2 = xcross; }
@@ -1614,13 +1614,13 @@
 			clearbufbyte(&mostbuf[xb1[w]],(xcross-xb1[w]+1)*sizeof(mostbuf[0]),0L);
 		}
 	}
-
+    
 	if (bad&12)
 	{
 		t = divscale30(z-s3,s4-s3);
 		inty = yb1[w] + mulscale30(yb2[w]-yb1[w],t);
 		xcross = xb1[w] + scale(mulscale30(yb2[w],t),xb2[w]-xb1[w],inty);
-
+        
 		if ((bad&12) == 8)
 		{
 			if (xb1[w] <= xcross) { iy2 = inty; ix2 = xcross; }
@@ -1632,16 +1632,16 @@
 			clearbufbyte(&mostbuf[xb1[w]],(xcross-xb1[w]+1)*sizeof(mostbuf[0]),ydimen+(ydimen<<16));
 		}
 	}
-
+    
 	y = (scale(z,xdimenscale,iy1)<<4);
 	yinc = ((scale(z,xdimenscale,iy2)<<4)-y) / (ix2-ix1+1);
 	qinterpolatedown16short((int32_t *)&mostbuf[ix1],ix2-ix1+1,y+(globalhoriz<<16),yinc);
-
+    
 	if (mostbuf[ix1] < 0) mostbuf[ix1] = 0;
 	if (mostbuf[ix1] > ydimen) mostbuf[ix1] = ydimen;
 	if (mostbuf[ix2] < 0) mostbuf[ix2] = 0;
 	if (mostbuf[ix2] > ydimen) mostbuf[ix2] = ydimen;
-
+    
 	return(bad);
 }
 
@@ -1651,7 +1651,7 @@
 	int32_t bad, i, j, t, y, z, inty, intz, xcross, yinc, fw;
 	int32_t x1, y1, z1, x2, y2, z2, xv, yv, dx, dy, dasqr, oz1, oz2;
 	int32_t s1, s2, s3, s4, ix1, ix2, iy1, iy2;
-
+    
 	if (dastat == 0)
 	{
 		z = sector[sectnum].ceilingz-globalposz;
@@ -1662,21 +1662,21 @@
 		z = sector[sectnum].floorz-globalposz;
 		if ((sector[sectnum].floorstat&2) == 0) return(owallmost(mostbuf,w,z));
 	}
-
+    
 	i = thewall[w];
 	if (i == sector[sectnum].wallptr) return(owallmost(mostbuf,w,z));
-
+    
 	x1 = wall[i].x; x2 = wall[wall[i].point2].x-x1;
 	y1 = wall[i].y; y2 = wall[wall[i].point2].y-y1;
-
+    
 	fw = sector[sectnum].wallptr; i = wall[fw].point2;
 	dx = wall[i].x-wall[fw].x; dy = wall[i].y-wall[fw].y;
 	dasqr = krecipasm(nsqrtasm(dx*dx+dy*dy));
-
+    
 	if (xb1[w] == 0)
-		{ xv = cosglobalang+sinviewingrangeglobalang; yv = singlobalang-cosviewingrangeglobalang; }
+    { xv = cosglobalang+sinviewingrangeglobalang; yv = singlobalang-cosviewingrangeglobalang; }
 	else
-		{ xv = x1-globalposx; yv = y1-globalposy; }
+    { xv = x1-globalposx; yv = y1-globalposy; }
 	i = xv*(y1-globalposy)-yv*(x1-globalposx); j = yv*x2-xv*y2;
 	if (klabs(j) > klabs(i>>3)) i = divscale28(i,j);
 	if (dastat == 0)
@@ -1690,13 +1690,13 @@
 		z1 = sector[sectnum].floorz;
 	}
 	z1 = dmulscale24(dx*t,mulscale20(y2,i)+((y1-wall[fw].y)<<8),
-						 -dy*t,mulscale20(x2,i)+((x1-wall[fw].x)<<8))+((z1-globalposz)<<7);
-
-
+                     -dy*t,mulscale20(x2,i)+((x1-wall[fw].x)<<8))+((z1-globalposz)<<7);
+    
+    
 	if (xb2[w] == xdimen-1)
-		{ xv = cosglobalang-sinviewingrangeglobalang; yv = singlobalang+cosviewingrangeglobalang; }
+    { xv = cosglobalang-sinviewingrangeglobalang; yv = singlobalang+cosviewingrangeglobalang; }
 	else
-		{ xv = (x2+x1)-globalposx; yv = (y2+y1)-globalposy; }
+    { xv = (x2+x1)-globalposx; yv = (y2+y1)-globalposy; }
 	i = xv*(y1-globalposy)-yv*(x1-globalposx); j = yv*x2-xv*y2;
 	if (klabs(j) > klabs(i>>3)) i = divscale28(i,j);
 	if (dastat == 0)
@@ -1710,43 +1710,43 @@
 		z2 = sector[sectnum].floorz;
 	}
 	z2 = dmulscale24(dx*t,mulscale20(y2,i)+((y1-wall[fw].y)<<8),
-						 -dy*t,mulscale20(x2,i)+((x1-wall[fw].x)<<8))+((z2-globalposz)<<7);
-
-
+                     -dy*t,mulscale20(x2,i)+((x1-wall[fw].x)<<8))+((z2-globalposz)<<7);
+    
+    
 	s1 = mulscale20(globaluclip,yb1[w]); s2 = mulscale20(globaluclip,yb2[w]);
 	s3 = mulscale20(globaldclip,yb1[w]); s4 = mulscale20(globaldclip,yb2[w]);
 	bad = (z1<s1)+((z2<s2)<<1)+((z1>s3)<<2)+((z2>s4)<<3);
-
+    
 	ix1 = xb1[w]; ix2 = xb2[w];
 	iy1 = yb1[w]; iy2 = yb2[w];
 	oz1 = z1; oz2 = z2;
-
+    
 	if ((bad&3) == 3)
 	{
 		clearbufbyte(&mostbuf[ix1],(ix2-ix1+1)*sizeof(mostbuf[0]),0L);
 		return(bad);
 	}
-
+    
 	if ((bad&12) == 12)
 	{
 		clearbufbyte(&mostbuf[ix1],(ix2-ix1+1)*sizeof(mostbuf[0]),ydimen+(ydimen<<16));
 		return(bad);
 	}
-
+    
 	if (bad&3)
 	{
-			/* inty = intz / (globaluclip>>16) */
+        /* inty = intz / (globaluclip>>16) */
 		t = divscale30(oz1-s1,s2-s1+oz1-oz2);
 		inty = yb1[w] + mulscale30(yb2[w]-yb1[w],t);
 		intz = oz1 + mulscale30(oz2-oz1,t);
 		xcross = xb1[w] + scale(mulscale30(yb2[w],t),xb2[w]-xb1[w],inty);
-
+        
 		/*
 		 * t = divscale30((x1<<4)-xcross*yb1[w],xcross*(yb2[w]-yb1[w])-((x2-x1)<<4));
 		 * inty = yb1[w] + mulscale30(yb2[w]-yb1[w],t);
 		 * intz = z1 + mulscale30(z2-z1,t);
          */
-
+        
 		if ((bad&3) == 2)
 		{
 			if (xb1[w] <= xcross) { z2 = intz; iy2 = inty; ix2 = xcross; }
@@ -1758,21 +1758,21 @@
 			clearbufbyte(&mostbuf[xb1[w]],(xcross-xb1[w]+1)*sizeof(mostbuf[0]),0L);
 		}
 	}
-
+    
 	if (bad&12)
 	{
-			/* inty = intz / (globaldclip>>16) */
+        /* inty = intz / (globaldclip>>16) */
 		t = divscale30(oz1-s3,s4-s3+oz1-oz2);
 		inty = yb1[w] + mulscale30(yb2[w]-yb1[w],t);
 		intz = oz1 + mulscale30(oz2-oz1,t);
 		xcross = xb1[w] + scale(mulscale30(yb2[w],t),xb2[w]-xb1[w],inty);
-
+        
 		/*
 		 * t = divscale30((x1<<4)-xcross*yb1[w],xcross*(yb2[w]-yb1[w])-((x2-x1)<<4));
 		 * inty = yb1[w] + mulscale30(yb2[w]-yb1[w],t);
 		 * intz = z1 + mulscale30(z2-z1,t);
          */
-
+        
 		if ((bad&12) == 8)
 		{
 			if (xb1[w] <= xcross) { z2 = intz; iy2 = inty; ix2 = xcross; }
@@ -1784,16 +1784,16 @@
 			clearbufbyte(&mostbuf[xb1[w]],(xcross-xb1[w]+1)*sizeof(mostbuf[0]),ydimen+(ydimen<<16));
 		}
 	}
-
+    
 	y = (scale(z1,xdimenscale,iy1)<<4);
 	yinc = ((scale(z2,xdimenscale,iy2)<<4)-y) / (ix2-ix1+1);
 	qinterpolatedown16short((int32_t *)&mostbuf[ix1],ix2-ix1+1,y+(globalhoriz<<16),yinc);
-
+    
 	if (mostbuf[ix1] < 0) mostbuf[ix1] = 0;
 	if (mostbuf[ix1] > ydimen) mostbuf[ix1] = ydimen;
 	if (mostbuf[ix2] < 0) mostbuf[ix2] = 0;
 	if (mostbuf[ix2] > ydimen) mostbuf[ix2] = ydimen;
-
+    
 	return(bad);
 }
 
@@ -1806,10 +1806,10 @@
 	int32_t z, wallnum, sectnum, nextsectnum;
 	int32_t startsmostwallcnt, startsmostcnt, gotswall;
 	uint8_t  andwstat1, andwstat2;
-
+    
 	z = bunchfirst[bunch];
 	sectnum = thesector[z]; sec = &sector[sectnum];
-
+    
 	andwstat1 = 0xff; andwstat2 = 0xff;
 	for(;z>=0;z=p2[z])  /* uplc/dplc calculation */
 	{
@@ -1816,7 +1816,7 @@
 		andwstat1 &= wallmost(uplc,z,sectnum,(uint8_t )0);
 		andwstat2 &= wallmost(dplc,z,sectnum,(uint8_t )1);
 	}
-
+    
 	if ((andwstat1&3) != 3)     /* draw ceilings */
 	{
 		if ((sec->ceilingstat&3) == 2)
@@ -1835,8 +1835,8 @@
 		else
 			parascan(xb1[bunchfirst[bunch]],xb2[bunchlast[bunch]],sectnum,1,bunch);
 	}
-
-		/* DRAW WALLS SECTION! */
+    
+    /* DRAW WALLS SECTION! */
 	for(z=bunchfirst[bunch];z>=0;z=p2[z])
 	{
 		x1 = xb1[z]; x2 = xb2[z];
@@ -1852,15 +1852,15 @@
 				continue;
 			}
 		}
-
+        
 		wallnum = thewall[z]; wal = &wall[wallnum];
 		nextsectnum = wal->nextsector; nextsec = &sector[nextsectnum];
-
+        
 		gotswall = 0;
-
+        
 		startsmostwallcnt = smostwallcnt;
 		startsmostcnt = smostcnt;
-
+        
 		if ((searchit == 2) && (searchx >= x1) && (searchx <= x2))
 		{
 			if (searchy <= uplc[searchx]) /* ceiling */
@@ -1874,7 +1874,7 @@
 				searchstat = 2; searchit = 1;
 			}
 		}
-
+        
 		if (nextsectnum >= 0)
 		{
 			getzsofslope((short)sectnum,wal->x,wal->y,&cz[0],&fz[0]);
@@ -1882,9 +1882,9 @@
 			getzsofslope((short)nextsectnum,wal->x,wal->y,&cz[2],&fz[2]);
 			getzsofslope((short)nextsectnum,wall[wal->point2].x,wall[wal->point2].y,&cz[3],&fz[3]);
 			getzsofslope((short)nextsectnum,globalposx,globalposy,&cz[4],&fz[4]);
-
+            
 			if ((wal->cstat&48) == 16) maskwall[maskwallcnt++] = z;
-
+            
 			if (((sec->ceilingstat&1) == 0) || ((nextsec->ceilingstat&1) == 0))
 			{
 				if ((cz[2] <= cz[0]) && (cz[3] <= cz[1]))
@@ -1903,7 +1903,7 @@
 					wallmost(dwall,z,nextsectnum,(uint8_t )0);
 					if ((cz[2] > fz[0]) || (cz[3] > fz[1]))
 						for(i=x1;i<=x2;i++) if (dwall[i] > dplc[i]) dwall[i] = dplc[i];
-
+                    
 					if ((searchit == 2) && (searchx >= x1) && (searchx <= x2))
 						if (searchy <= dwall[searchx]) /* wall */
 						{
@@ -1910,7 +1910,7 @@
 							searchsector = sectnum; searchwall = wallnum;
 							searchstat = 0; searchit = 1;
 						}
-
+                    
 					globalorientation = (long)wal->cstat;
 					globalpicnum = wal->picnum;
 					if ((unsigned)globalpicnum >= (unsigned)MAXTILES) globalpicnum = 0;
@@ -1931,10 +1931,10 @@
 						globalzd = (((globalposz-sec->ceilingz)*globalyscale)<<8);
 					globalzd += (globalypanning<<24);
 					if (globalorientation&256) globalyscale = -globalyscale, globalzd = -globalzd;
-
+                    
 					if (gotswall == 0) { gotswall = 1; prepwall(z,wal); }
 					wallscan(x1,x2,uplc,dwall,swall,lwall);
-
+                    
 					if ((cz[2] >= cz[0]) && (cz[3] >= cz[1]))
 					{
 						for(x=x1;x<=x2;x++)
@@ -1991,7 +1991,7 @@
 					wallmost(uwall,z,nextsectnum,(uint8_t )1);
 					if ((fz[2] < cz[0]) || (fz[3] < cz[1]))
 						for(i=x1;i<=x2;i++) if (uwall[i] < uplc[i]) uwall[i] = uplc[i];
-
+                    
 					if ((searchit == 2) && (searchx >= x1) && (searchx <= x2))
 						if (searchy >= uwall[searchx]) /* wall */
 						{
@@ -1999,7 +1999,7 @@
 							if ((wal->cstat&2) > 0) searchwall = wal->nextwall;
 							searchstat = 0; searchit = 1;
 						}
-
+                    
 					if ((wal->cstat&2) > 0)
 					{
 						wallnum = wal->nextwall; wal = &wall[wallnum];
@@ -2036,10 +2036,10 @@
 						globalzd = (((globalposz-sec->ceilingz)*globalyscale)<<8);
 					globalzd += (globalypanning<<24);
 					if (globalorientation&256) globalyscale = -globalyscale, globalzd = -globalzd;
-
+                    
 					if (gotswall == 0) { gotswall = 1; prepwall(z,wal); }
 					wallscan(x1,x2,uwall,dplc,swall,lwall);
-
+                    
 					if ((fz[2] <= fz[0]) && (fz[3] <= fz[1]))
 					{
 						for(x=x1;x<=x2;x++)
@@ -2087,12 +2087,12 @@
 				{
 					for(x=x1;x<x2;x++)
 						if (umost[x] < dmost[x])
-							{ scansector((short) nextsectnum); break; }
-
-						/*
-						 * If can't see sector beyond, then cancel smost array and just
-						 *  store wall!
-					     */
+                        { scansector((short) nextsectnum); break; }
+                    
+                    /*
+                     * If can't see sector beyond, then cancel smost array and just
+                     *  store wall!
+                     */
 					if (x == x2)
 					{
 						smostwallcnt = startsmostwallcnt;
@@ -2108,7 +2108,7 @@
 		{
 			globalorientation = (long)wal->cstat;
 			if (nextsectnum < 0) globalpicnum = wal->picnum;
-								  else globalpicnum = wal->overpicnum;
+            else globalpicnum = wal->overpicnum;
 			if ((unsigned)globalpicnum >= (unsigned)MAXTILES) globalpicnum = 0;
 			globalxpanning = (long)wal->xpanning;
 			globalypanning = (long)wal->ypanning;
@@ -2124,26 +2124,26 @@
 			if (nextsectnum >= 0)
 			{
 				if ((globalorientation&4) == 0) globalzd = globalposz-nextsec->ceilingz;
-													else globalzd = globalposz-sec->ceilingz;
+                else globalzd = globalposz-sec->ceilingz;
 			}
 			else
 			{
 				if ((globalorientation&4) == 0) globalzd = globalposz-sec->ceilingz;
-													else globalzd = globalposz-sec->floorz;
+                else globalzd = globalposz-sec->floorz;
 			}
 			globalzd = ((globalzd*globalyscale)<<8) + (globalypanning<<24);
 			if (globalorientation&256) globalyscale = -globalyscale, globalzd = -globalzd;
-
+            
 			if (gotswall == 0) { gotswall = 1; prepwall(z,wal); }
 			wallscan(x1,x2,uplc,dplc,swall,lwall);
-
+            
 			for(x=x1;x<=x2;x++)
 				if (umost[x] <= dmost[x])
-					{ umost[x] = 1; dmost[x] = 0; numhits--; }
+                { umost[x] = 1; dmost[x] = 0; numhits--; }
 			smostwall[smostwallcnt] = z;
 			smostwalltype[smostwallcnt] = 0;
 			smostwallcnt++;
-
+            
 			if ((searchit == 2) && (searchx >= x1) && (searchx <= x2))
 			{
 				searchit = 1; searchsector = sectnum; searchwall = wallnum;
@@ -2157,7 +2157,7 @@
 static void dosetaspect(void)
 {
 	int32_t i, j, k, x, xinc;
-
+    
 	if (xyaspect != oxyaspect)
 	{
 		oxyaspect = xyaspect;
@@ -2195,12 +2195,12 @@
 {
 	walltype *wal;
 	int32_t x11, y11, x21, y21, x12, y12, x22, y22, dx, dy, t1, t2;
-
+    
 	wal = &wall[thewall[l1]]; x11 = wal->x; y11 = wal->y;
 	wal = &wall[wal->point2]; x21 = wal->x; y21 = wal->y;
 	wal = &wall[thewall[l2]]; x12 = wal->x; y12 = wal->y;
 	wal = &wall[wal->point2]; x22 = wal->x; y22 = wal->y;
-
+    
 	dx = x21-x11; dy = y21-y11;
 	t1 = dmulscale2(x12-x11,dy,-dx,y12-y11); /* p1(l2) vs. l1 */
 	t2 = dmulscale2(x22-x11,dy,-dx,y22-y11); /* p2(l2) vs. l1 */
@@ -2211,7 +2211,7 @@
 		t2 = dmulscale2(globalposx-x11,dy,-dx,globalposy-y11); /* pos vs. l1 */
 		return((t2^t1) >= 0);
 	}
-
+    
 	dx = x22-x12; dy = y22-y12;
 	t1 = dmulscale2(x11-x12,dy,-dx,y11-y12); /* p1(l1) vs. l2 */
 	t2 = dmulscale2(x21-x12,dy,-dx,y21-y12); /* p2(l1) vs. l2 */
@@ -2229,12 +2229,12 @@
 static int bunchfront(int32_t b1, int32_t b2)
 {
 	int32_t x1b1, x2b1, x1b2, x2b2, b1f, b2f, i;
-
+    
 	b1f = bunchfirst[b1]; x1b1 = xb1[b1f]; x2b2 = xb2[bunchlast[b2]]+1;
 	if (x1b1 >= x2b2) return(-1);
 	b2f = bunchfirst[b2]; x1b2 = xb1[b2f]; x2b1 = xb2[bunchlast[b1]]+1;
 	if (x1b2 >= x2b1) return(-1);
-
+    
 	if (x1b1 >= x1b2)
 	{
 		for(i=b2f;xb2[i]<x1b1;i=p2[i]);
@@ -2250,31 +2250,31 @@
 {
 	int32_t i, j, z, cz, fz, closest;
 	short *shortptr1, *shortptr2;
-
+    
 	beforedrawrooms = 0;
 	totalarea += (windowx2+1-windowx1)*(windowy2+1-windowy1);
-
+    
 	globalposx = daposx; globalposy = daposy; globalposz = daposz;
 	globalang = (daang&2047);
-
+    
 	globalhoriz = mulscale16(dahoriz-100,xdimenscale)+(ydimen>>1);
 	globaluclip = (0-globalhoriz)*xdimscale;
 	globaldclip = (ydimen-globalhoriz)*xdimscale;
-
+    
 	i = mulscale16(xdimenscale,viewingrangerecip);
 	globalpisibility = mulscale16(parallaxvisibility,i);
 	globalvisibility = mulscale16(visibility,i);
 	globalhisibility = mulscale16(globalvisibility,xyaspect);
 	globalcisibility = mulscale8(globalhisibility,320);
-
+    
 	globalcursectnum = dacursectnum;
 	totalclocklock = totalclock;
-
+    
 	cosglobalang = sintable[(globalang+512)&2047];
 	singlobalang = sintable[globalang&2047];
 	cosviewingrangeglobalang = mulscale16(cosglobalang,viewingrange);
 	sinviewingrangeglobalang = mulscale16(singlobalang,viewingrange);
-
+    
 	if ((stereomode != 0) || (vidoption == 6))
 	{
 		if (stereopixelwidth != ostereopixelwidth)
@@ -2284,7 +2284,7 @@
 			xdimenrecip = divscale32(1L,xdimen);
 			setaspect((long)divscale16(xdimen,windowx2-windowx1+1),yxaspect);
 		}
-
+        
 		if ((!(activepage&1)) ^ inpreparemirror)
 		{
 			for(i=windowx1;i<windowx1+(stereopixelwidth<<1);i++) { startumost[i] = 1, startdmost[i] = 0; }
@@ -2303,14 +2303,14 @@
 		globalposy -= mulscale24(cosglobalang,i);
 		if (vidoption == 6) frameplace = (long)FP_OFF(screen)+(activepage&1)*65536;
 	}
-
+    
 	if ((xyaspect != oxyaspect) || (xdimen != oxdimen) || (viewingrange != oviewingrange))
 		dosetaspect();
-
+    
 	frameoffset = frameplace+viewoffset;
-
+    
 	clearbufbyte(&gotsector[0],(long)((numsectors+7)>>3),0L);
-
+    
 	shortptr1 = (short *)&startumost[windowx1];
 	shortptr2 = (short *)&startdmost[windowx1];
 	i = xdimen-1;
@@ -2322,25 +2322,25 @@
 	} while (i != 0);
 	umost[0] = shortptr1[0]-windowy1;
 	dmost[0] = shortptr2[0]-windowy1;
-
-/*
- * every cycle counts...and the CRC gets checked at the start, so this only
- *  would trigger only if they've changed it in memory after loading (and what
- *  would anyone do that for on purpose?), or if they've just defeated the
- *  first CRC check...but if they've hacked the binary/source in that way,
- *  then they'll just take this check out, too. In short, it ain't worth it.
- *
- *    --ryan.
- */
+    
+    /*
+     * every cycle counts...and the CRC gets checked at the start, so this only
+     *  would trigger only if they've changed it in memory after loading (and what
+     *  would anyone do that for on purpose?), or if they've just defeated the
+     *  first CRC check...but if they've hacked the binary/source in that way,
+     *  then they'll just take this check out, too. In short, it ain't worth it.
+     *
+     *    --ryan.
+     */
 #if 0
 	if (smostwallcnt < 0)
 		if (getkensmessagecrc(FP_OFF(kensmessage)) != 0x56c764d4)
-			{ setvmode(0x3); printf("Nice try.\n"); Error(EXIT_SUCCESS, ""); }
+        { setvmode(0x3); printf("Nice try.\n"); Error(EXIT_SUCCESS, ""); }
 #endif
-
+    
 	numhits = xdimen; numscans = 0; numbunches = 0;
 	maskwallcnt = 0; smostwallcnt = 0; smostcnt = 0; spritesortcnt = 0;
-
+    
 	if (globalcursectnum >= MAXSECTORS)
 		globalcursectnum -= MAXSECTORS;
 	else
@@ -2349,15 +2349,15 @@
 		updatesector(globalposx,globalposy,&globalcursectnum);
 		if (globalcursectnum < 0) globalcursectnum = i;
 	}
-
+    
 	globparaceilclip = 1;
 	globparaflorclip = 1;
 	getzsofslope(globalcursectnum,globalposx,globalposy,&cz,&fz);
 	if (globalposz < cz) globparaceilclip = 0;
 	if (globalposz > fz) globparaflorclip = 0;
-
+    
 	scansector(globalcursectnum);
-
+    
 	if (inpreparemirror)
 	{
 		inpreparemirror = 0;
@@ -2368,34 +2368,34 @@
 			if (xb1[i] < mirrorsx1) mirrorsx1 = xb1[i];
 			if (xb2[i] > mirrorsx2) mirrorsx2 = xb2[i];
 		}
-
+        
 		if (stereomode)
 		{
 			mirrorsx1 += (stereopixelwidth<<1);
 			mirrorsx2 += (stereopixelwidth<<1);
 		}
-
+        
 		for(i=0;i<mirrorsx1;i++)
 			if (umost[i] <= dmost[i])
-				{ umost[i] = 1; dmost[i] = 0; numhits--; }
+            { umost[i] = 1; dmost[i] = 0; numhits--; }
 		for(i=mirrorsx2+1;i<xdimen;i++)
 			if (umost[i] <= dmost[i])
-				{ umost[i] = 1; dmost[i] = 0; numhits--; }
-
+            { umost[i] = 1; dmost[i] = 0; numhits--; }
+        
 		drawalls(0L);
 		numbunches--;
 		bunchfirst[0] = bunchfirst[numbunches];
 		bunchlast[0] = bunchlast[numbunches];
-
+        
 		mirrorsy1 = min(umost[mirrorsx1],umost[mirrorsx2]);
 		mirrorsy2 = max(dmost[mirrorsx1],dmost[mirrorsx2]);
 	}
-
+    
 	while ((numbunches > 0) && (numhits > 0))
 	{
 		clearbuf(&tempbuf[0],(long)((numbunches+3)>>2),0L);
 		tempbuf[0] = 1;
-
+        
 		closest = 0;              /* Almost works, but not quite :( */
 		for(i=1;i<numbunches;i++)
 		{
@@ -2410,16 +2410,16 @@
 			tempbuf[i] = 1;
 			if (j == 0) tempbuf[closest] = 1, closest = i, i = 0;
 		}
-
+        
         //Draw every solid walls in the bunch "closest"
 		drawalls(closest);
-
+        
 		if (automapping)
 		{
 			for(z=bunchfirst[closest];z>=0;z=p2[z])
 				show2dwall[thewall[z]>>3] |= pow2char[thewall[z]&7];
 		}
-
+        
 		numbunches--;
 		bunchfirst[closest] = bunchfirst[numbunches];
 		bunchlast[closest] = bunchlast[numbunches];
@@ -2431,7 +2431,7 @@
 {
 	walltype *wal;
 	int32_t x1, y1;
-
+    
 	wal = &wall[w]; x1 = wal->x; y1 = wal->y;
 	wal = &wall[wal->point2];
 	return (dmulscale32(wal->x-x1,s->y-y1,-(s->x-x1),wal->y-y1) >= 0);
@@ -2442,27 +2442,27 @@
 {
 	int32_t vplc, vinc, p, i, palookupoffs, bufplc;
 	short y1v, y2v;
-
+    
 	if ((x < 0) || (x >= xdimen)) return;
-
+    
 	y1v = max(uwall[x],startumost[x+windowx1]-windowy1);
 	y2v = min(dwall[x],startdmost[x+windowx1]-windowy1);
 	y2v--;
 	if (y2v < y1v) return;
-
+    
 	palookupoffs = (long)FP_OFF(palookup[globalpal]) + (getpalookup((long)mulscale16(swall[x],globvis),globalshade)<<8);
-
+    
 	vinc = swall[x]*globalyscale;
 	vplc = globalzd + vinc*(y1v-globalhoriz+1);
-
+    
 	i = lwall[x]+globalxpanning;
 	if (i >= tilesizx[globalpicnum]) i %= tilesizx[globalpicnum];
 	bufplc = waloff[globalpicnum]+i*tilesizy[globalpicnum];
-
+    
 	p = ylookup[y1v]+x+frameoffset;
-
+    
 	tvlineasm1(vinc,palookupoffs,y2v-y1v,vplc,bufplc,p);
-
+    
 	transarea += y2v-y1v;
 }
 
@@ -2470,12 +2470,12 @@
 {
 	int32_t i, y1, y2, x2;
 	short y1ve[2], y2ve[2];
-
+    
 	if ((x < 0) || (x >= xdimen)) return;
 	if (x == xdimen-1) { transmaskvline(x); return; }
-
+    
 	x2 = x+1;
-
+    
 	y1ve[0] = max(uwall[x],startumost[x+windowx1]-windowy1);
 	y2ve[0] = min(dwall[x],startdmost[x+windowx1]-windowy1)-1;
 	if (y2ve[0] < y1ve[0]) { transmaskvline(x2); return; }
@@ -2482,30 +2482,30 @@
 	y1ve[1] = max(uwall[x2],startumost[x2+windowx1]-windowy1);
 	y2ve[1] = min(dwall[x2],startdmost[x2+windowx1]-windowy1)-1;
 	if (y2ve[1] < y1ve[1]) { transmaskvline(x); return; }
-
+    
 	palookupoffse[0] = (long)FP_OFF(palookup[globalpal]) + (getpalookup((long)mulscale16(swall[x],globvis),globalshade)<<8);
 	palookupoffse[1] = (long)FP_OFF(palookup[globalpal]) + (getpalookup((long)mulscale16(swall[x2],globvis),globalshade)<<8);
-
+    
 	setuptvlineasm2(globalshiftval,palookupoffse[0],palookupoffse[1]);
-
+    
 	vince[0] = swall[x]*globalyscale;
 	vince[1] = swall[x2]*globalyscale;
 	vplce[0] = globalzd + vince[0]*(y1ve[0]-globalhoriz+1);
 	vplce[1] = globalzd + vince[1]*(y1ve[1]-globalhoriz+1);
-
+    
 	i = lwall[x] + globalxpanning;
 	if (i >= tilesizx[globalpicnum]) i %= tilesizx[globalpicnum];
 	bufplce[0] = waloff[globalpicnum]+i*tilesizy[globalpicnum];
-
+    
 	i = lwall[x2] + globalxpanning;
 	if (i >= tilesizx[globalpicnum]) i %= tilesizx[globalpicnum];
 	bufplce[1] = waloff[globalpicnum]+i*tilesizy[globalpicnum];
-
+    
 	y1 = max(y1ve[0],y1ve[1]);
 	y2 = min(y2ve[0],y2ve[1]);
-
+    
 	i = x+frameoffset;
-
+    
 	if (y1ve[0] != y1ve[1])
 	{
 		if (y1ve[0] < y1)
@@ -2513,7 +2513,7 @@
 		else
 			vplce[1] = tvlineasm1(vince[1],palookupoffse[1],y1-y1ve[1]-1,vplce[1],bufplce[1],ylookup[y1ve[1]]+i+1);
 	}
-
+    
 	if (y2 > y1)
 	{
 		asm1 = vince[1];
@@ -2526,12 +2526,12 @@
 		asm1 = vplce[0];
 		asm2 = vplce[1];
 	}
-
+    
 	if (y2ve[0] > y2ve[1])
 		tvlineasm1(vince[0],palookupoffse[0],y2ve[0]-y2-1,asm1,bufplce[0],ylookup[y2+1]+i);
 	else if (y2ve[0] < y2ve[1])
 		tvlineasm1(vince[1],palookupoffse[1],y2ve[1]-y2-1,asm2,bufplce[1],ylookup[y2+1]+i+1);
-
+    
 	faketimerhandler();
 }
 
@@ -2538,14 +2538,14 @@
 static void transmaskwallscan(int32_t x1, int32_t x2)
 {
 	int32_t x;
-
+    
 	setgotpic(globalpicnum);
 	if ((tilesizx[globalpicnum] <= 0) || (tilesizy[globalpicnum] <= 0)) return;
-
+    
 	if (waloff[globalpicnum] == 0) loadtile(globalpicnum);
-
+    
 	setuptvlineasm(globalshiftval);
-
+    
 	x = x1;
 	while ((startumost[x+windowx1] > startdmost[x+windowx1]) && (x <= x2)) x++;
 	if ((x <= x2) && (x&1)) transmaskvline(x), x++;
@@ -2562,33 +2562,33 @@
     sectortype *sect;
     spritetype *s;
     walltype *w;
-
+    
     x = 0;
-
+    
 	// FIX_00058: Save/load game crash in both single and multiplayer
 	// We have to reset those arrays since the same
-	// arrays are used as temporary space in the 
+	// arrays are used as temporary space in the
 	// compilecons() function like "label = (uint8_t  *)&sprite[0];"
-	// to save memory space I guess. 
-	// Not reseting the array will leave dumps fooling 
+	// to save memory space I guess.
+	// Not reseting the array will leave dumps fooling
 	// the function saveplayer(), eg at if(actorscrptr[PN] == 0)
 	// where PN is sprite[i].picnum was beyong actorscrptr[] size)
 	memset(sprite, 0, sizeof(sprite));
 	memset(sector, 0, sizeof(sector));
 	memset(wall, 0, sizeof(wall));
-
+    
 	if ((fil = kopen4load(filename, 0)) == -1)
-		{ mapversion = 7L; return(-1); }
-
+    { mapversion = 7L; return(-1); }
+    
 	kread32(fil,&mapversion);
 	if (mapversion != 7L) return(-1);
-
+    
 	initspritelists();
-
+    
 	clearbuf(&show2dsector[0],(long)((MAXSECTORS+3)>>5),0L);
 	clearbuf(&show2dsprite[0],(long)((MAXSPRITES+3)>>5),0L);
 	clearbuf(&show2dwall[0],(long)((MAXWALLS+3)>>5),0L);
-
+    
 	kread32(fil,daposx);
 	kread32(fil,daposy);
 	kread32(fil,daposz);
@@ -2595,7 +2595,7 @@
 	kread16(fil,daang);
 	kread16(fil,dacursectnum);
 	kread16(fil,&numsectors);
-
+    
 	for (x = 0, sect = &sector[0]; x < numsectors; x++, sect++)
 	{
 		kread16(fil,&sect->wallptr);
@@ -2622,7 +2622,7 @@
 		kread16(fil,&sect->hitag);
 		kread16(fil,&sect->extra);
 	}
-
+    
 	kread16(fil,&numwalls);
 	for (x = 0, w = &wall[0]; x < numwalls; x++, w++)
 	{
@@ -2634,17 +2634,17 @@
 		kread16(fil,&w->cstat);
 		kread16(fil,&w->picnum);
 		kread16(fil,&w->overpicnum);
-		 kread8(fil,(uint8_t *)&w->shade);
-		 kread8(fil,&w->pal);
-		 kread8(fil,&w->xrepeat);
-		 kread8(fil,&w->yrepeat);
-		 kread8(fil,&w->xpanning);
-		 kread8(fil,&w->ypanning);
+        kread8(fil,(uint8_t *)&w->shade);
+        kread8(fil,&w->pal);
+        kread8(fil,&w->xrepeat);
+        kread8(fil,&w->yrepeat);
+        kread8(fil,&w->xpanning);
+        kread8(fil,&w->ypanning);
 		kread16(fil,&w->lotag);
 		kread16(fil,&w->hitag);
 		kread16(fil,&w->extra);
 	}
-
+    
     kread16(fil,&numsprites);
 	for (x = 0, s = &sprite[0]; x < numsprites; x++, s++)
 	{
@@ -2653,14 +2653,14 @@
 		kread32(fil,&s->z);
 		kread16(fil,&s->cstat);
 		kread16(fil,&s->picnum);
-		 kread8(fil,(uint8_t *)&s->shade);
-		 kread8(fil,(uint8_t *)&s->pal);
- 		 kread8(fil,(uint8_t *)&s->clipdist);
-		 kread8(fil,(uint8_t *)&s->filler);
-		 kread8(fil,(uint8_t *)&s->xrepeat);
-		 kread8(fil,(uint8_t *)&s->yrepeat);
-		 kread8(fil,(uint8_t *)&s->xoffset);
-		 kread8(fil,(uint8_t *)&s->yoffset);
+        kread8(fil,(uint8_t *)&s->shade);
+        kread8(fil,(uint8_t *)&s->pal);
+        kread8(fil,(uint8_t *)&s->clipdist);
+        kread8(fil,(uint8_t *)&s->filler);
+        kread8(fil,(uint8_t *)&s->xrepeat);
+        kread8(fil,(uint8_t *)&s->yrepeat);
+        kread8(fil,(uint8_t *)&s->xoffset);
+        kread8(fil,(uint8_t *)&s->yoffset);
 		kread16(fil,&s->sectnum);
 		kread16(fil,&s->statnum);
 		kread16(fil,&s->ang);
@@ -2672,22 +2672,22 @@
 		kread16(fil,&s->hitag);
 		kread16(fil,&s->extra);
 	}
-
-
+    
+    
 	for(i=0;i<numsprites;i++)
 		insertsprite(sprite[i].sectnum,sprite[i].statnum);
-
-		/* Must be after loading sectors, etc! */
+    
+    /* Must be after loading sectors, etc! */
 	updatesector(*daposx,*daposy,dacursectnum);
-
+    
 	kclose(fil);
-
+    
 	// FIX_00009: Show map CRC and GRP file version of each player in case of Out Of Synch
-
+    
 	mapCRC = crc16((uint8_t *)sector, numsectors*sizeof(sectortype));
 	mapCRC += crc16((uint8_t *)wall, numwalls*sizeof(walltype));
 	mapCRC += crc16((uint8_t *)sprite, numsprites*sizeof(spritetype));
-
+    
 	return(0);
 }
 
@@ -2719,13 +2719,13 @@
     int permissions = 0;
     walltype *w;
     sectortype *sect;
-
-    #if ((defined PLATFORM_DOS) || (defined PLATFORM_WIN32))
-        permissions = S_IWRITE;
-    #elif (defined PLATFORM_UNIX)
-        permissions = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
-    #endif
-
+    
+#if ((defined PLATFORM_DOS) || (defined PLATFORM_WIN32))
+    permissions = S_IWRITE;
+#elif (defined PLATFORM_UNIX)
+    permissions = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
+#endif
+    
 	if ((fil = open(filename,
                     O_BINARY|O_TRUNC|O_CREAT|O_WRONLY,
                     permissions)) == -1)
@@ -2732,15 +2732,15 @@
     {
 		return(-1);
     }
-
+    
 	write32(fil,mapversion);
-
+    
 	write32(fil,*daposx);
 	write32(fil,*daposy);
 	write32(fil,*daposz);
 	write16(fil,*daang);
 	write16(fil,*dacursectnum);
-
+    
 	write16(fil,numsectors);
     for (x = 0, sect = &sector[0]; x < numsectors; x++, sect++)
     {
@@ -2752,23 +2752,23 @@
 		write16(fil,sect->floorstat);
 		write16(fil,sect->ceilingpicnum);
 		write16(fil,sect->ceilingheinum);
-		 write8(fil,sect->ceilingshade);
-		 write8(fil,sect->ceilingpal);
-		 write8(fil,sect->ceilingxpanning);
-		 write8(fil,sect->ceilingypanning);
+        write8(fil,sect->ceilingshade);
+        write8(fil,sect->ceilingpal);
+        write8(fil,sect->ceilingxpanning);
+        write8(fil,sect->ceilingypanning);
 		write16(fil,sect->floorpicnum);
 		write16(fil,sect->floorheinum);
-		 write8(fil,sect->floorshade);
-		 write8(fil,sect->floorpal);
-		 write8(fil,sect->floorxpanning);
-		 write8(fil,sect->floorypanning);
-		 write8(fil,sect->visibility);
-		 write8(fil,sect->filler);
+        write8(fil,sect->floorshade);
+        write8(fil,sect->floorpal);
+        write8(fil,sect->floorxpanning);
+        write8(fil,sect->floorypanning);
+        write8(fil,sect->visibility);
+        write8(fil,sect->filler);
 		write16(fil,sect->lotag);
 		write16(fil,sect->hitag);
 		write16(fil,sect->extra);
     }
-
+    
 	write16(fil,numwalls);
     for (x = 0, w = &wall[0]; x < numwalls; x++, w++)
     {
@@ -2780,17 +2780,17 @@
 		write16(fil,w->cstat);
 		write16(fil,w->picnum);
 		write16(fil,w->overpicnum);
-		 write8(fil,w->shade);
-		 write8(fil,w->pal);
-		 write8(fil,w->xrepeat);
-		 write8(fil,w->yrepeat);
-		 write8(fil,w->xpanning);
-		 write8(fil,w->ypanning);
+        write8(fil,w->shade);
+        write8(fil,w->pal);
+        write8(fil,w->xrepeat);
+        write8(fil,w->yrepeat);
+        write8(fil,w->xpanning);
+        write8(fil,w->ypanning);
 		write16(fil,w->lotag);
 		write16(fil,w->hitag);
 		write16(fil,w->extra);
     }
-
+    
 	numsprites = 0;
 	for(j=0;j<MAXSTATUS;j++)
 	{
@@ -2802,7 +2802,7 @@
 		}
 	}
 	write16(fil,numsprites);
-
+    
 	for(j=0;j<MAXSTATUS;j++)
 	{
 		i = headspritestat[j];
@@ -2814,14 +2814,14 @@
 			write32(fil,s->z);
 			write16(fil,s->cstat);
 			write16(fil,s->picnum);
-			 write8(fil,s->shade);
-			 write8(fil,s->pal);
-			 write8(fil,s->clipdist);
-			 write8(fil,s->filler);
-			 write8(fil,s->xrepeat);
-			 write8(fil,s->yrepeat);
-			 write8(fil,s->xoffset);
-			 write8(fil,s->yoffset);
+            write8(fil,s->shade);
+            write8(fil,s->pal);
+            write8(fil,s->clipdist);
+            write8(fil,s->filler);
+            write8(fil,s->xrepeat);
+            write8(fil,s->yrepeat);
+            write8(fil,s->xoffset);
+            write8(fil,s->yoffset);
 			write16(fil,s->sectnum);
 			write16(fil,s->statnum);
 			write16(fil,s->ang);
@@ -2832,11 +2832,11 @@
 			write16(fil,s->lotag);
 			write16(fil,s->hitag);
 			write16(fil,s->extra);
-
+            
 			i = nextspritestat[i];
 		}
 	}
-
+    
 	close(fil);
 	return(0);
 }
@@ -2845,7 +2845,7 @@
 static void initksqrt(void)
 {
 	int32_t i, j, k;
-
+    
 	j = 1; k = 0;
 	for(i=0;i<4096;i++)
 	{
@@ -2860,21 +2860,21 @@
 static void loadtables(void)
 {
 	int32_t i, fil;
-
+    
 	if (tablesloaded == 0)
 	{
 		initksqrt();
-
+        
 		for(i=0;i<2048;i++) reciptable[i] = divscale30(2048L,i+2048);
-
+        
 		if ((fil = TCkopen4load("tables.dat",0)) != -1)
 		{
             for (i = 0; i < 2048; i++)
 				kread16(fil,&sintable[i]);
-
+            
             for (i = 0; i < 640; i++)
 				kread16(fil,&radarang[i]);
-
+            
 			for(i=0;i<640;i++) radarang[1279-i] = -radarang[i];
 			kread(fil,textfont,1024);
 			kread(fil,smalltextfont,1024);
@@ -2890,7 +2890,7 @@
 {
 	int32_t i, j, x, y, z;
 	uint8_t  *pal1;
-
+    
 	j = 0;
 	for(i=64;i>=0;i--)
 	{
@@ -2900,10 +2900,10 @@
 		bdist[i] = bdist[128-i] = j*bscale;
 		j += 129-(i<<1);
 	}
-
+    
 	clearbufbyte((void *)FP_OFF(colhere),sizeof(colhere),0L);
 	clearbufbyte((void *)FP_OFF(colhead),sizeof(colhead),0L);
-
+    
 	pal1 = (uint8_t  *)&palette[768-3];
 	for(i=255;i>=0;i--,pal1-=3)
 	{
@@ -2912,7 +2912,7 @@
 		colhead[j] = i;
 		colhere[j>>3] |= pow2char[j&7];
 	}
-
+    
 	i = 0;
 	for(x=-FASTPALGRIDSIZ*FASTPALGRIDSIZ;x<=FASTPALGRIDSIZ*FASTPALGRIDSIZ;x+=FASTPALGRIDSIZ*FASTPALGRIDSIZ)
 		for(y=-FASTPALGRIDSIZ;y<=FASTPALGRIDSIZ;y+=FASTPALGRIDSIZ)
@@ -2926,36 +2926,36 @@
 {
 	int32_t i, j, k, dist, fil;
 	uint8_t  *ptr;
-
+    
 	if (paletteloaded != 0) return;
 	if ((fil = TCkopen4load("palette.dat",0)) == -1) return;
-
+    
 	kread(fil,palette,768);
 	kread16(fil,&numpalookups);
-
+    
 	if ((palookup[0] = (uint8_t  *)kkmalloc(numpalookups<<8)) == NULL)
 		allocache((int32_t *)&palookup[0],numpalookups<<8,&permanentlock);
 	if ((transluc = (uint8_t  *)kkmalloc(65536L)) == NULL)
 		allocache((int32_t *)&transluc,65536,&permanentlock);
-
+    
 	globalpalwritten = palookup[0]; globalpal = 0;
 	setpalookupaddress(globalpalwritten);
-
+    
 	fixtransluscence((long)FP_OFF(transluc));
-
+    
 	kread(fil,palookup[globalpal],numpalookups<<8);
-
-
+    
+    
 	/*kread(fil,transluc,65536);*/
 	for (k = 0; k < (65536 / 4); k++)
 	    kread32(fil, ((int32_t *) transluc) + k);
-
+    
 	kclose(fil);
-
+    
 	initfastcolorlookup(30L,59L,11L);
-
+    
 	paletteloaded = 1;
-
+    
 	if (vidoption == 6)
 	{
 		for(k=0;k<MAXPALOOKUPS;k++)
@@ -2967,7 +2967,7 @@
 					for(j=0;j<32;j++)
 						ptr[j<<8] = (uint8_t )min(max(mulscale10(dist,32-j),0),15);
 				}
-
+        
 		if (transluc != NULL)
 		{
 			for(i=0;i<16;i++)
@@ -2983,7 +2983,7 @@
 {
 	strcpy(kensmessage,"!!!! BUILD engine&tools programmed by Ken Silverman of E.G. RI.  (c) Copyright 1995 Ken Silverman.  Summary:  BUILD = Ken. !!!!");
 	if (getkensmessagecrc(FP_OFF(kensmessage)) != 0x56c764d4)
-		{ setvmode(0x3); printf("Nice try.\n"); Error(EXIT_SUCCESS, ""); }
+    { setvmode(0x3); printf("Nice try.\n"); Error(EXIT_SUCCESS, ""); }
     return(_setgamemode(davidoption, daxdim, daydim));
 } /* setgamemode */
 
@@ -3007,46 +3007,46 @@
 void initengine(void)
 {
     int32_t i;
-
-
-
+    
+    
+    
     initengine_called = 1;
-
+    
 	if (dommxoverlay)
         mmxoverlay();
-
+    
 	loadtables();
-
+    
 	xyaspect = -1;
-
+    
 	pskyoff[0] = 0; pskybits = 0;
-
+    
 	parallaxtype = 2; parallaxyoffs = 0L; parallaxyscale = 65536;
 	showinvisibility = 0;
-
+    
 	paletteloaded = 0;
-
+    
 	searchit = 0; searchstat = -1;
-
+    
 	for(i=0;i<MAXPALOOKUPS;i++) palookup[i] = NULL;
-
+    
 	clearbuf(&waloff[0],(long)MAXTILES,0L);
-
+    
 	clearbuf(&show2dsector[0],(long)((MAXSECTORS+3)>>5),0L);
 	clearbuf(&show2dsprite[0],(long)((MAXSPRITES+3)>>5),0L);
 	clearbuf(&show2dwall[0],(long)((MAXWALLS+3)>>5),0L);
 	automapping = 0;
-
+    
 	validmodecnt = 0;
-
+    
 	pointhighlight = -1;
 	linehighlight = -1;
 	highlightcnt = 0;
-
+    
 	totalclock = 0;
 	visibility = 512;
 	parallaxvisibility = 512;
-
+    
 	loadpalette();
 }
 
@@ -3060,53 +3060,53 @@
 }
 
 
-	/* Assume npoints=4 with polygon on &rx1,&ry1 */
+/* Assume npoints=4 with polygon on &rx1,&ry1 */
 static int clippoly4(int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2)
 {
 	int32_t n, nn, z, zz, x, x1, x2, y, y1, y2, t;
-
+    
 	nn = 0; z = 0;
 	do
 	{
 		zz = ((z+1)&3);
 		x1 = rx1[z]; x2 = rx1[zz]-x1;
-
+        
 		if ((cx1 <= x1) && (x1 <= cx2))
 			rx2[nn] = x1, ry2[nn] = ry1[z], nn++;
-
+        
 		if (x2 <= 0) x = cx2; else x = cx1;
 		t = x-x1;
 		if (((t-x2)^t) < 0)
 			rx2[nn] = x, ry2[nn] = ry1[z]+scale(t,ry1[zz]-ry1[z],x2), nn++;
-
+        
 		if (x2 <= 0) x = cx1; else x = cx2;
 		t = x-x1;
 		if (((t-x2)^t) < 0)
 			rx2[nn] = x, ry2[nn] = ry1[z]+scale(t,ry1[zz]-ry1[z],x2), nn++;
-
+        
 		z = zz;
 	} while (z != 0);
 	if (nn < 3) return(0);
-
+    
 	n = 0; z = 0;
 	do
 	{
 		zz = z+1; if (zz == nn) zz = 0;
 		y1 = ry2[z]; y2 = ry2[zz]-y1;
-
+        
 		if ((cy1 <= y1) && (y1 <= cy2))
 			ry1[n] = y1, rx1[n] = rx2[z], n++;
-
+        
 		if (y2 <= 0) y = cy2; else y = cy1;
 		t = y-y1;
 		if (((t-y2)^t) < 0)
 			ry1[n] = y, rx1[n] = rx2[z]+scale(t,rx2[zz]-rx2[z],y2), n++;
-
+        
 		if (y2 <= 0) y = cy1; else y = cy2;
 		t = y-y1;
 		if (((t-y2)^t) < 0)
 			ry1[n] = y, rx1[n] = rx2[z]+scale(t,rx2[zz]-rx2[z],y2), n++;
-
+        
 		z = zz;
 	} while (z != 0);
 	return(n);
@@ -3115,8 +3115,8 @@
 
 
 static void dorotatesprite (int32_t sx, int32_t sy, int32_t z, short a, short picnum,
-	int8_t dashade, uint8_t  dapalnum, uint8_t  dastat, int32_t cx1,
-	int32_t cy1, int32_t cx2, int32_t cy2)
+                            int8_t dashade, uint8_t  dapalnum, uint8_t  dastat, int32_t cx1,
+                            int32_t cy1, int32_t cx2, int32_t cy2)
 {
 	int32_t cosang, sinang, v, nextv, dax1, dax2, oy, bx, by, ny1, ny2;
 	int32_t i, x, y, x1, y1, x2, y2, gx1, gy1, p, bufplc, palookupoffs;
@@ -3123,7 +3123,7 @@
 	int32_t xsiz, ysiz, xoff, yoff, npoints, yplc, yinc, lx, rx, xx, xend;
 	int32_t xv, yv, xv2, yv2, obuffermode=0, qlinemode=0, y1ve[4], y2ve[4], u4, d4;
 	uint8_t  bad;
-
+    
 	xsiz = tilesizx[picnum]; ysiz = tilesizy[picnum];
 	if (dastat&16) { xoff = 0; yoff = 0; }
 	else
@@ -3131,11 +3131,11 @@
 		xoff = (int32_t)((int8_t )((picanm[picnum]>>8)&255))+(xsiz>>1);
 		yoff = (int32_t)((int8_t )((picanm[picnum]>>16)&255))+(ysiz>>1);
 	}
-
+    
 	if (dastat&4) yoff = ysiz-yoff;
-
+    
 	cosang = sintable[(a+512)&2047]; sinang = sintable[a&2047];
-
+    
 	if ((dastat&2) != 0)  /* Auto window size scaling */
 	{
 		if ((dastat&8) == 0)
@@ -3147,10 +3147,10 @@
 		}
 		else
 		{
-			  /*
-			   * If not clipping to startmosts, & auto-scaling on, as a
-			   *  hard-coded bonus, scale to full screen instead
-               */
+            /*
+             * If not clipping to startmosts, & auto-scaling on, as a
+             *  hard-coded bonus, scale to full screen instead
+             */
             x = scale(xdim,yxaspect,320);
 			sx = (xdim<<15)+32768+scale(sx-(320<<15),xdim,320);
 			sy = (ydim<<15)+32768+mulscale16(sy-(200<<15),x);
@@ -3157,7 +3157,7 @@
 		}
 		z = mulscale16(z,x);
 	}
-
+    
 	xv = mulscale14(cosang,z);
 	yv = mulscale14(sinang,z);
 	if (((dastat&2) != 0) || ((dastat&8) == 0)) /* Don't aspect unscaled perms */
@@ -3170,7 +3170,7 @@
 		xv2 = xv;
 		yv2 = yv;
 	}
-
+    
 	ry1[0] = sy - (yv*xoff + xv*yoff);
 	ry1[1] = ry1[0] + yv*xsiz;
 	ry1[3] = ry1[0] + xv*ysiz;
@@ -3177,7 +3177,7 @@
 	ry1[2] = ry1[1]+ry1[3]-ry1[0];
 	i = (cy1<<16); if ((ry1[0]<i) && (ry1[1]<i) && (ry1[2]<i) && (ry1[3]<i)) return;
 	i = (cy2<<16); if ((ry1[0]>i) && (ry1[1]>i) && (ry1[2]>i) && (ry1[3]>i)) return;
-
+    
 	rx1[0] = sx - (xv2*xoff - yv2*yoff);
 	rx1[1] = rx1[0] + xv2*xsiz;
 	rx1[3] = rx1[0] - yv2*ysiz;
@@ -3184,13 +3184,13 @@
 	rx1[2] = rx1[1]+rx1[3]-rx1[0];
 	i = (cx1<<16); if ((rx1[0]<i) && (rx1[1]<i) && (rx1[2]<i) && (rx1[3]<i)) return;
 	i = (cx2<<16); if ((rx1[0]>i) && (rx1[1]>i) && (rx1[2]>i) && (rx1[3]>i)) return;
-
+    
 	gx1 = rx1[0]; gy1 = ry1[0];   /* back up these before clipping */
-
+    
 	if ((npoints = clippoly4(cx1<<16,cy1<<16,(cx2+1)<<16,(cy2+1)<<16)) < 3) return;
-
+    
 	lx = rx1[0]; rx = rx1[0];
-
+    
 	nextv = 0;
 	for(v=npoints-1;v>=0;v--)
 	{
@@ -3214,13 +3214,13 @@
 		}
 		nextv = v;
 	}
-
+    
 	if (waloff[picnum] == 0) loadtile(picnum);
 	setgotpic(picnum);
 	bufplc = waloff[picnum];
-
+    
 	palookupoffs = (long) FP_OFF(palookup[dapalnum]) + (getpalookup(0L,(long)dashade)<<8);
-
+    
 	i = divscale32(1L,z);
 	xv = mulscale14(sinang,i);
 	yv = mulscale14(cosang,i);
@@ -3234,15 +3234,15 @@
 		yv2 = -xv;
 		xv2 = yv;
 	}
-
+    
 	x1 = (lx>>16); x2 = (rx>>16);
-
+    
 	oy = 0;
 	x = (x1<<16)-1-gx1; y = (oy<<16)+65535-gy1;
 	bx = dmulscale16(x,xv2,y,xv);
 	by = dmulscale16(x,yv2,y,yv);
 	if (dastat&4) { yv = -yv; yv2 = -yv2; by = (ysiz<<16)-1-by; }
-
+    
 	if ((vidoption == 1) && (origbuffermode == 0))
 	{
 		if (dastat&128)
@@ -3253,8 +3253,8 @@
 		}
 	}
 	else if (dastat&8)
-		 permanentupdate = 1;
-
+        permanentupdate = 1;
+    
 	if ((dastat&1) == 0)
 	{
 		if (((a&1023) == 0) && (ysiz <= 256))  /* vlineasm4 has 256 high limit! */
@@ -3265,10 +3265,10 @@
                 setupmvlineasm(24L);
             
 			by <<= 8; yv <<= 8; yv2 <<= 8;
-
+            
 			palookupoffse[0] = palookupoffse[1] = palookupoffse[2] = palookupoffse[3] = palookupoffs;
 			vince[0] = vince[1] = vince[2] = vince[3] = yv;
-
+            
 			for(x=x1;x<x2;x+=4)
 			{
 				bad = 15; xend = min(x2-x,4);
@@ -3275,7 +3275,7 @@
 				for(xx=0;xx<xend;xx++)
 				{
 					bx += xv2;
-
+                    
 					y1 = uplc[x+xx]; y2 = dplc[x+xx];
 					if ((dastat&8) == 0)
 					{
@@ -3283,9 +3283,9 @@
 						if (startdmost[x+xx] < y2) y2 = startdmost[x+xx];
 					}
 					if (y2 <= y1) continue;
-
+                    
 					by += yv*(y1-oy); oy = y1;
-
+                    
 					bufplce[xx] = (bx>>16)*ysiz+bufplc;
 					vplce[xx] = by;
 					y1ve[xx] = y1;
@@ -3292,12 +3292,12 @@
 					y2ve[xx] = y2-1;
 					bad &= ~pow2char[xx];
 				}
-
+                
 				p = x+frameplace;
-
+                
 				u4 = max(max(y1ve[0],y1ve[1]),max(y1ve[2],y1ve[3]));
 				d4 = min(min(y2ve[0],y2ve[1]),min(y2ve[2],y2ve[3]));
-
+                
 				if (dastat&64)
 				{
 					if ((bad != 0) || (u4 >= d4))
@@ -3308,14 +3308,14 @@
 						if (!(bad&8)) prevlineasm1(vince[3],palookupoffse[3],y2ve[3]-y1ve[3],vplce[3],bufplce[3],ylookup[y1ve[3]]+p+3);
 						continue;
 					}
-
+                    
 					if (u4 > y1ve[0]) vplce[0] = prevlineasm1(vince[0],palookupoffse[0],u4-y1ve[0]-1,vplce[0],bufplce[0],ylookup[y1ve[0]]+p+0);
 					if (u4 > y1ve[1]) vplce[1] = prevlineasm1(vince[1],palookupoffse[1],u4-y1ve[1]-1,vplce[1],bufplce[1],ylookup[y1ve[1]]+p+1);
 					if (u4 > y1ve[2]) vplce[2] = prevlineasm1(vince[2],palookupoffse[2],u4-y1ve[2]-1,vplce[2],bufplce[2],ylookup[y1ve[2]]+p+2);
 					if (u4 > y1ve[3]) vplce[3] = prevlineasm1(vince[3],palookupoffse[3],u4-y1ve[3]-1,vplce[3],bufplce[3],ylookup[y1ve[3]]+p+3);
-
+                    
 					if (d4 >= u4) vlineasm4(d4-u4+1,ylookup[u4]+p);
-
+                    
 					i = p+ylookup[d4+1];
 					if (y2ve[0] > d4) prevlineasm1(vince[0],palookupoffse[0],y2ve[0]-d4-1,vplce[0],bufplce[0],i+0);
 					if (y2ve[1] > d4) prevlineasm1(vince[1],palookupoffse[1],y2ve[1]-d4-1,vplce[1],bufplce[1],i+1);
@@ -3332,14 +3332,14 @@
 						if (!(bad&8)) mvlineasm1(vince[3],palookupoffse[3],y2ve[3]-y1ve[3],vplce[3],bufplce[3],ylookup[y1ve[3]]+p+3);
 						continue;
 					}
-
+                    
 					if (u4 > y1ve[0]) vplce[0] = mvlineasm1(vince[0],palookupoffse[0],u4-y1ve[0]-1,vplce[0],bufplce[0],ylookup[y1ve[0]]+p+0);
 					if (u4 > y1ve[1]) vplce[1] = mvlineasm1(vince[1],palookupoffse[1],u4-y1ve[1]-1,vplce[1],bufplce[1],ylookup[y1ve[1]]+p+1);
 					if (u4 > y1ve[2]) vplce[2] = mvlineasm1(vince[2],palookupoffse[2],u4-y1ve[2]-1,vplce[2],bufplce[2],ylookup[y1ve[2]]+p+2);
 					if (u4 > y1ve[3]) vplce[3] = mvlineasm1(vince[3],palookupoffse[3],u4-y1ve[3]-1,vplce[3],bufplce[3],ylookup[y1ve[3]]+p+3);
-
+                    
 					if (d4 >= u4) mvlineasm4(d4-u4+1,ylookup[u4]+p);
-
+                    
 					i = p+ylookup[d4+1];
 					if (y2ve[0] > d4) mvlineasm1(vince[0],palookupoffse[0],y2ve[0]-d4-1,vplce[0],bufplce[0],i+0);
 					if (y2ve[1] > d4) mvlineasm1(vince[1],palookupoffse[1],y2ve[1]-d4-1,vplce[1],bufplce[1],i+1);
@@ -3346,7 +3346,7 @@
 					if (y2ve[2] > d4) mvlineasm1(vince[2],palookupoffse[2],y2ve[2]-d4-1,vplce[2],bufplce[2],i+2);
 					if (y2ve[3] > d4) mvlineasm1(vince[3],palookupoffse[3],y2ve[3]-d4-1,vplce[3],bufplce[3],i+3);
 				}
-
+                
 				faketimerhandler();
 			}
 		}
@@ -3367,7 +3367,7 @@
 			}
 			else
 				setuprmhlineasm4(xv2<<16,yv2<<16,(xv2>>16)*ysiz+(yv2>>16),palookupoffs,ysiz,0L);
-
+            
 			y1 = uplc[x1];
 			if (((dastat&8) == 0) && (startumost[x1] > y1)) y1 = startumost[x1];
 			y2 = y1;
@@ -3379,7 +3379,7 @@
 					if (startumost[x]-1 > ny1) ny1 = startumost[x]-1;
 					if (startdmost[x] < ny2) ny2 = startdmost[x];
 				}
-
+                
 				if (ny1 < ny2-1)
 				{
 					if (ny1 >= y2)
@@ -3387,12 +3387,12 @@
 						while (y1 < y2-1)
 						{
 							y1++; if ((y1&31) == 0) faketimerhandler();
-
-								/* x,y1 */
+                            
+                            /* x,y1 */
 							bx += xv*(y1-oy); by += yv*(y1-oy); oy = y1;
 							if (dastat&64) {  if (qlinemode) rhlineasm4(x-lastx[y1],(bx>>16)*ysiz+(by>>16)+bufplc,0L,0L    ,by<<16,ylookup[y1]+x+frameplace);
-																  else rhlineasm4(x-lastx[y1],(bx>>16)*ysiz+(by>>16)+bufplc,0L,bx<<16,by<<16,ylookup[y1]+x+frameplace);
-															  } else rmhlineasm4(x-lastx[y1],(bx>>16)*ysiz+(by>>16)+bufplc,0L,bx<<16,by<<16,ylookup[y1]+x+frameplace);
+                            else rhlineasm4(x-lastx[y1],(bx>>16)*ysiz+(by>>16)+bufplc,0L,bx<<16,by<<16,ylookup[y1]+x+frameplace);
+                            } else rmhlineasm4(x-lastx[y1],(bx>>16)*ysiz+(by>>16)+bufplc,0L,bx<<16,by<<16,ylookup[y1]+x+frameplace);
 						}
 						y1 = ny1;
 					}
@@ -3401,12 +3401,12 @@
 						while (y1 < ny1)
 						{
 							y1++; if ((y1&31) == 0) faketimerhandler();
-
-								/* x,y1 */
+                            
+                            /* x,y1 */
 							bx += xv*(y1-oy); by += yv*(y1-oy); oy = y1;
 							if (dastat&64) {  if (qlinemode) rhlineasm4(x-lastx[y1],(bx>>16)*ysiz+(by>>16)+bufplc,0L,0L    ,by<<16,ylookup[y1]+x+frameplace);
-																  else rhlineasm4(x-lastx[y1],(bx>>16)*ysiz+(by>>16)+bufplc,0L,bx<<16,by<<16,ylookup[y1]+x+frameplace);
-															  } else rmhlineasm4(x-lastx[y1],(bx>>16)*ysiz+(by>>16)+bufplc,0L,bx<<16,by<<16,ylookup[y1]+x+frameplace);
+                            else rhlineasm4(x-lastx[y1],(bx>>16)*ysiz+(by>>16)+bufplc,0L,bx<<16,by<<16,ylookup[y1]+x+frameplace);
+                            } else rmhlineasm4(x-lastx[y1],(bx>>16)*ysiz+(by>>16)+bufplc,0L,bx<<16,by<<16,ylookup[y1]+x+frameplace);
 						}
 						while (y1 > ny1) lastx[y1--] = x;
 					}
@@ -3413,12 +3413,12 @@
 					while (y2 > ny2)
 					{
 						y2--; if ((y2&31) == 0) faketimerhandler();
-
-							/* x,y2 */
+                        
+                        /* x,y2 */
 						bx += xv*(y2-oy); by += yv*(y2-oy); oy = y2;
 						if (dastat&64) {  if (qlinemode) rhlineasm4(x-lastx[y2],(bx>>16)*ysiz+(by>>16)+bufplc,0L,0L    ,by<<16,ylookup[y2]+x+frameplace);
-															  else rhlineasm4(x-lastx[y2],(bx>>16)*ysiz+(by>>16)+bufplc,0L,bx<<16,by<<16,ylookup[y2]+x+frameplace);
-														  } else rmhlineasm4(x-lastx[y2],(bx>>16)*ysiz+(by>>16)+bufplc,0L,bx<<16,by<<16,ylookup[y2]+x+frameplace);
+                        else rhlineasm4(x-lastx[y2],(bx>>16)*ysiz+(by>>16)+bufplc,0L,bx<<16,by<<16,ylookup[y2]+x+frameplace);
+                        } else rmhlineasm4(x-lastx[y2],(bx>>16)*ysiz+(by>>16)+bufplc,0L,bx<<16,by<<16,ylookup[y2]+x+frameplace);
 					}
 					while (y2 < ny2) lastx[y2++] = x;
 				}
@@ -3427,8 +3427,8 @@
 					while (y1 < y2-1)
 					{
 						y1++; if ((y1&31) == 0) faketimerhandler();
-
-							/* x,y1 */
+                        
+                        /* x,y1 */
 						bx += xv*(y1-oy); by += yv*(y1-oy); oy = y1;
 						if (dastat&64)
                         {
@@ -3459,81 +3459,81 @@
 			while (y1 < y2-1)
 			{
 				y1++; if ((y1&31) == 0) faketimerhandler();
-
-					/* x2,y1 */
+                
+                /* x2,y1 */
 				bx += xv*(y1-oy); by += yv*(y1-oy); oy = y1;
 				if (dastat&64) {  if (qlinemode) rhlineasm4(x2-lastx[y1],(bx>>16)*ysiz+(by>>16)+bufplc,0L,0L    ,by<<16,ylookup[y1]+x2+frameplace);
-													  else rhlineasm4(x2-lastx[y1],(bx>>16)*ysiz+(by>>16)+bufplc,0L,bx<<16,by<<16,ylookup[y1]+x2+frameplace);
-												  } else rmhlineasm4(x2-lastx[y1],(bx>>16)*ysiz+(by>>16)+bufplc,0L,bx<<16,by<<16,ylookup[y1]+x2+frameplace);
+                else rhlineasm4(x2-lastx[y1],(bx>>16)*ysiz+(by>>16)+bufplc,0L,bx<<16,by<<16,ylookup[y1]+x2+frameplace);
+                } else rmhlineasm4(x2-lastx[y1],(bx>>16)*ysiz+(by>>16)+bufplc,0L,bx<<16,by<<16,ylookup[y1]+x2+frameplace);
 			}
 		}
 	}
 	else
 	{
-	if ((dastat&1) == 0)
-	{
-		if (dastat&64)
-            setupspritevline(palookupoffs,(xv>>16)*ysiz,xv<<16,ysiz,yv,0L);
-		else
-            msetupspritevline(palookupoffs,(xv>>16)*ysiz,xv<<16,ysiz,yv,0L);
-	}
-	else
-	{
+        if ((dastat&1) == 0)
+        {
+            if (dastat&64)
+                setupspritevline(palookupoffs,(xv>>16)*ysiz,xv<<16,ysiz,yv,0L);
+            else
+                msetupspritevline(palookupoffs,(xv>>16)*ysiz,xv<<16,ysiz,yv,0L);
+        }
+        else
+        {
 			tsetupspritevline(palookupoffs,(xv>>16)*ysiz,xv<<16,ysiz,yv,0L);
-		if (dastat&32) settransreverse(); else settransnormal();
-	}
+            if (dastat&32) settransreverse(); else settransnormal();
+        }
         
-	for(x=x1;x<x2;x++)
-	{
-		bx += xv2; by += yv2;
-
-		y1 = uplc[x]; y2 = dplc[x];
-		if ((dastat&8) == 0)
-		{
-			if (startumost[x] > y1) y1 = startumost[x];
-			if (startdmost[x] < y2) y2 = startdmost[x];
-		}
-		if (y2 <= y1) continue;
-
-		switch(y1-oy)
-		{
-		case -1:
-                bx -= xv;
-                by -= yv;
-                oy = y1;
-                break;
-		case 0:
-                break;
-		case 1:
-                bx += xv;
-                by += yv;
-                oy = y1;
-                break;
-		default:
-                bx += xv*(y1-oy);
-                by += yv*(y1-oy);
-                oy = y1;
-                break;
-		}
-
-		p = ylookup[y1]+x+frameplace;
-
-		if ((dastat&1) == 0)
-		{
-			if (dastat&64)
-                spritevline(0L,by<<16,y2-y1+1,bx<<16,(bx>>16)*ysiz+(by>>16)+bufplc,p);
-			else
-                mspritevline(0L,by<<16,y2-y1+1,bx<<16,(bx>>16)*ysiz+(by>>16)+bufplc,p);
-		}
-		else
-		{
-            tspritevline(0L,by<<16,y2-y1+1,bx<<16,(bx>>16)*ysiz+(by>>16)+bufplc,p);
-            transarea += (y2-y1);
-		}
-		faketimerhandler();
+        for(x=x1;x<x2;x++)
+        {
+            bx += xv2; by += yv2;
+            
+            y1 = uplc[x]; y2 = dplc[x];
+            if ((dastat&8) == 0)
+            {
+                if (startumost[x] > y1) y1 = startumost[x];
+                if (startdmost[x] < y2) y2 = startdmost[x];
+            }
+            if (y2 <= y1) continue;
+            
+            switch(y1-oy)
+            {
+                case -1:
+                    bx -= xv;
+                    by -= yv;
+                    oy = y1;
+                    break;
+                case 0:
+                    break;
+                case 1:
+                    bx += xv;
+                    by += yv;
+                    oy = y1;
+                    break;
+                default:
+                    bx += xv*(y1-oy);
+                    by += yv*(y1-oy);
+                    oy = y1;
+                    break;
+            }
+            
+            p = ylookup[y1]+x+frameplace;
+            
+            if ((dastat&1) == 0)
+            {
+                if (dastat&64)
+                    spritevline(0L,by<<16,y2-y1+1,bx<<16,(bx>>16)*ysiz+(by>>16)+bufplc,p);
+                else
+                    mspritevline(0L,by<<16,y2-y1+1,bx<<16,(bx>>16)*ysiz+(by>>16)+bufplc,p);
+            }
+            else
+            {
+                tspritevline(0L,by<<16,y2-y1+1,bx<<16,(bx>>16)*ysiz+(by>>16)+bufplc,p);
+                transarea += (y2-y1);
+            }
+            faketimerhandler();
+        }
 	}
-	}
-
+    
 	if ((vidoption == 1) && (dastat&128) && (origbuffermode == 0))
 	{
 		buffermode = obuffermode;
@@ -3546,7 +3546,7 @@
 {
 	int32_t i;
 	permfifotype *per;
-
+    
     if (qsetmode == 200)
     {
   		for(i=permtail;i!=permhead;i=((i+1)&(MAXPERMS-1)))
@@ -3554,14 +3554,14 @@
    			per = &permfifo[i];
    			if ((per->pagesleft > 0) && (per->pagesleft <= numpages))
    				dorotatesprite(per->sx,per->sy,per->z,per->a,per->picnum,
-   									per->dashade,per->dapalnum,per->dastat,
-   									per->cx1,per->cy1,per->cx2,per->cy2);
+                               per->dashade,per->dapalnum,per->dastat,
+                               per->cx1,per->cy1,per->cx2,per->cy2);
    		}
     } /* if */
-
+    
     _nextpage();  /* video driver specific. */
-
-
+    
+    
     if (qsetmode == 200)
     {
    		for(i=permtail;i!=permhead;i=((i+1)&(MAXPERMS-1)))
@@ -3569,19 +3569,19 @@
    			per = &permfifo[i];
    			if (per->pagesleft >= 130)
    				dorotatesprite(per->sx,per->sy,per->z,per->a,per->picnum,
-   									per->dashade,per->dapalnum,per->dastat,
-   									per->cx1,per->cy1,per->cx2,per->cy2);
-				if (per->pagesleft&127) per->pagesleft--;
+                               per->dashade,per->dapalnum,per->dastat,
+                               per->cx1,per->cy1,per->cx2,per->cy2);
+            if (per->pagesleft&127) per->pagesleft--;
    			if (((per->pagesleft&127) == 0) && (i == permtail))
    				permtail = ((permtail+1)&(MAXPERMS-1));
    		}
     } /* if */
-
+    
 	faketimerhandler();
-
+    
 	if ((totalclock >= lastageclock+8) || (totalclock < lastageclock))
-		{ lastageclock = totalclock; agecache(); }
-
+    { lastageclock = totalclock; agecache(); }
+    
 	beforedrawrooms = 1;
 	numframes++;
 }
@@ -3591,11 +3591,11 @@
 {
 	uint8_t  *ptr;
 	int32_t i, dasiz;
-
+    
 	if ((unsigned)tilenume >= (unsigned)MAXTILES) return;
 	dasiz = tilesizx[tilenume]*tilesizy[tilenume];
 	if (dasiz <= 0) return;
-
+    
 	i = tilefilenum[tilenume];
 	if (i != artfilnum)
 	{
@@ -3602,7 +3602,7 @@
 		if (artfil != -1) kclose(artfil);
 		artfilnum = i;
 		artfilplc = 0L;
-
+        
 		artfilename[7] = (i%10)+48;
 		artfilename[6] = ((i/10)%10)+48;
 		artfilename[5] = ((i/100)%10)+48;
@@ -3609,17 +3609,17 @@
 		artfil = TCkopen4load(artfilename,0);
 		faketimerhandler();
 	}
-
-	#if BUILD_CACHEDEBUG
-        fprintf(stderr, "BUILDCACHE: Tile:%d\n", tilenume);
-    #endif
-
+    
+#if BUILD_CACHEDEBUG
+    fprintf(stderr, "BUILDCACHE: Tile:%d\n", tilenume);
+#endif
+    
 	if (waloff[tilenume] == 0)
 	{
 		walock[tilenume] = 199;
 		allocache(&waloff[tilenume],dasiz,(uint8_t  *) &walock[tilenume]);
 	}
-
+    
 	if (artfilplc != tilefileoffs[tilenume])
 	{
 		klseek(artfil,tilefileoffs[tilenume]-artfilplc,SEEK_CUR);
@@ -3635,24 +3635,24 @@
 int allocatepermanenttile(short tilenume, int32_t xsiz, int32_t ysiz)
 {
 	int32_t j, dasiz;
-
+    
 	if ((xsiz <= 0) || (ysiz <= 0) || ((unsigned)tilenume >= (unsigned)MAXTILES))
 		return(0);
-
+    
 	dasiz = xsiz*ysiz;
-
+    
 	walock[tilenume] = 255;
 	allocache(&waloff[tilenume],dasiz,(uint8_t  *) &walock[tilenume]);
-
+    
 	tilesizx[tilenume] = xsiz;
 	tilesizy[tilenume] = ysiz;
 	picanm[tilenume] = 0;
-
+    
 	j = 15; while ((j > 1) && (pow2long[j] > xsiz)) j--;
 	picsiz[tilenume] = ((uint8_t )j);
 	j = 15; while ((j > 1) && (pow2long[j] > ysiz)) j--;
 	picsiz[tilenume] += ((uint8_t )(j<<4));
-
+    
 	return(waloff[tilenume]);
 }
 
@@ -3663,9 +3663,9 @@
 	int32_t offscount, localtilestart, localtileend, dasiz;
 	short fil, i, j, k;
 	//uint8_t  fullpathartfilename[512];
-
+    
 	strcpy(artfilename,filename);
-
+    
 	for(i=0;i<MAXTILES;i++)
 	{
 		tilesizx[i] = 0;
@@ -3672,41 +3672,41 @@
 		tilesizy[i] = 0;
 		picanm[i] = 0L;
 	}
-
+    
 	artsize = 0L;
-
+    
 	numtilefiles = 0;
 	do
 	{
 		k = numtilefiles;
-
+        
 		artfilename[7] = (k%10)+48;
 		artfilename[6] = ((k/10)%10)+48;
 		artfilename[5] = ((k/100)%10)+48;
-
-	
-
+        
+        
+        
 		if ((fil = TCkopen4load(artfilename,0)) != -1)
 		{
 			kread32(fil,&artversion);
 			if (artversion != 1) return(-1);
-
+            
 			kread32(fil,&numtiles);
 			kread32(fil,&localtilestart);
 			kread32(fil,&localtileend);
-
+            
 			/*kread(fil,&tilesizx[localtilestart],(localtileend-localtilestart+1)<<1);*/
 			for (i = localtilestart; i <= localtileend; i++)
 				kread16(fil,&tilesizx[i]);
-
+            
 			/*kread(fil,&tilesizy[localtilestart],(localtileend-localtilestart+1)<<1);*/
 			for (i = localtilestart; i <= localtileend; i++)
 			    kread16(fil,&tilesizy[i]);
-
+            
 			/*kread(fil,&picanm[localtilestart],(localtileend-localtilestart+1)<<2);*/
 			for (i = localtilestart; i <= localtileend; i++)
 			    kread32(fil,&picanm[i]);
-
+            
 			offscount = 4+4+4+4+((localtileend-localtilestart+1)<<3);
 			for(i=localtilestart;i<=localtileend;i++)
 			{
@@ -3717,17 +3717,17 @@
 				artsize += ((dasiz+15)&0xfffffff0);
 			}
 			kclose(fil);
-
+            
 			numtilefiles++;
-
+            
 		}
 	}
 	while (k != numtilefiles);
 	printf("Art files loaded\n");
 	clearbuf(&gotpic[0],(long)((MAXTILES+31)>>5),0L);
-
+    
 	/* try dpmi_DETERMINEMAXREALALLOC! */
-
+    
 	cachesize = max(artsize,1048576);
 	while ((pic = (uint8_t  *)kkmalloc(cachesize)) == NULL)
 	{
@@ -3735,7 +3735,7 @@
 		if (cachesize < 65536) return(-1);
 	}
 	initcache(((long)FP_OFF(pic)+15)&0xfffffff0,(cachesize-((-(long)FP_OFF(pic))&15))&0xfffffff0);
-
+    
 	for(i=0;i<MAXTILES;i++)
 	{
 		j = 15;
@@ -3745,11 +3745,11 @@
 		while ((j > 1) && (pow2long[j] > tilesizy[i])) j--;
 		picsiz[i] += ((uint8_t )(j<<4));
 	}
-
+    
 	artfil = -1;
 	artfilnum = -1;
 	artfilplc = 0L;
-
+    
 	return(0);
 }
 
@@ -3759,16 +3759,16 @@
 {
 	walltype *wal;
 	int32_t x1, y1, x2, y2, r;
-
+    
 	r = (walldist<<1);
 	wal = &wall[wallnum];     x1 = wal->x+walldist-x; y1 = wal->y+walldist-y;
 	wal = &wall[wal->point2]; x2 = wal->x+walldist-x; y2 = wal->y+walldist-y;
-
+    
 	if ((x1 < 0) && (x2 < 0)) return(0);
 	if ((y1 < 0) && (y2 < 0)) return(0);
 	if ((x1 >= r) && (x2 >= r)) return(0);
 	if ((y1 >= r) && (y2 >= r)) return(0);
-
+    
 	x2 -= x1; y2 -= y1;
 	if (x2*(walldist-y1) >= y2*(walldist-x1))  /* Front */
 	{
@@ -3784,17 +3784,17 @@
 static int clipinsideboxline(int32_t x, int32_t y, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t walldist)
 {
 	int32_t r;
-
+    
 	r = (walldist<<1);
-
+    
 	x1 += walldist-x; x2 += walldist-x;
 	if ((x1 < 0) && (x2 < 0)) return(0);
 	if ((x1 >= r) && (x2 >= r)) return(0);
-
+    
 	y1 += walldist-y; y2 += walldist-y;
 	if ((y1 < 0) && (y2 < 0)) return(0);
 	if ((y1 >= r) && (y2 >= r)) return(0);
-
+    
 	x2 -= x1; y2 -= y1;
 	if (x2*(walldist-y1) >= y2*(walldist-x1))  /* Front */
 	{
@@ -3811,9 +3811,9 @@
 void drawline256 (int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint8_t  col)
 {
 	int32_t dx, dy, i, j, p, inc, plc, daend;
-
+    
 	col = palookup[0][col];
-
+    
 	dx = x2-x1; dy = y2-y1;
 	if (dx >= 0)
 	{
@@ -3839,7 +3839,7 @@
 		if (y2 < wy1) x2 += scale(wy1-y2,dx,dy), y2 = wy1;
 		if (y1 > wy2) x1 += scale(wy2-y1,dx,dy), y1 = wy2;
 	}
-
+    
 	if (klabs(dx) >= klabs(dy))
 	{
 		if (dx == 0) return;
@@ -3848,7 +3848,7 @@
 			i = x1; x1 = x2; x2 = i;
 			i = y1; y1 = y2; y2 = i;
 		}
-
+        
 		inc = divscale12(dy,dx);
 		plc = y1+mulscale12((2047-x1)&4095,inc);
 		i = ((x1+2048)>>12); daend = ((x2+2048)>>12);
@@ -3867,7 +3867,7 @@
 			i = x1; x1 = x2; x2 = i;
 			i = y1; y1 = y2; y2 = i;
 		}
-
+        
 		inc = divscale12(dx,dy);
 		plc = x1+mulscale12((2047-y1)&4095,inc);
 		i = ((y1+2048)>>12); daend = ((y2+2048)>>12);
@@ -3883,20 +3883,20 @@
 }
 
 /*
-    FCS: Return true if the point (x,Y) is inside the sector sectnum.
-	Note that a sector is closed to the answer is always 0 or 1.
-
-	Algorithm: For each wall one after an other....???
-*/
+ FCS: Return true if the point (x,Y) is inside the sector sectnum.
+ Note that a sector is closed to the answer is always 0 or 1.
+ 
+ Algorithm: For each wall one after an other....???
+ */
 int inside(int32_t x, int32_t y, short sectnum)
 {
 	walltype *wal;
 	int32_t i, x1, y1, x2, y2;
 	uint32_t  cnt;
-
+    
 	//Quick check if the sector ID is valid.
 	if ((sectnum < 0) || (sectnum >= numsectors)) return(-1);
-
+    
 	cnt = 0;
 	wal = &wall[sector[sectnum].wallptr];
 	i = sector[sectnum].wallnum;
@@ -3904,7 +3904,7 @@
 	{
 		y1 = wal->y-y;
         y2 = wall[wal->point2].y-y;
-
+        
 		// Compare the sign of y1 and y2.
 		// If (y1^y2) < 0 then y is above or below both wal->y and wall[wal->point2].y.
 		if ((y1^y2) < 0)
@@ -3924,12 +3924,12 @@
                 cnt ^= (x1*y2-x2*y1)^y2;
             }
 		}
-
-		wal++; 
+        
+		wal++;
 		i--;
-
+        
 	} while (i);
-
+    
     //Just return the sign.
 	return(cnt>>31);
 }
@@ -3959,7 +3959,7 @@
 {
 	uint8_t  *ptr1, *ptr2, dat;
 	int32_t xsiz1, ysiz1, xsiz2, ysiz2, i, j, x1, y1, x2, y2;
-
+    
 	xsiz1 = tilesizx[tilenume1]; ysiz1 = tilesizy[tilenume1];
 	xsiz2 = tilesizx[tilenume2]; ysiz2 = tilesizy[tilenume2];
 	if ((xsiz1 > 0) && (ysiz1 > 0) && (xsiz2 > 0) && (ysiz2 > 0))
@@ -3966,7 +3966,7 @@
 	{
 		if (waloff[tilenume1] == 0) loadtile((short) tilenume1);
 		if (waloff[tilenume2] == 0) loadtile((short) tilenume2);
-
+        
 		x1 = sx1;
 		for(i=0;i<xsiz;i++)
 		{
@@ -3983,7 +3983,7 @@
 					if (dat != 255)
 						*ptr2 = *ptr1;
 				}
-
+                
 				y1++; if (y1 >= ysiz1) y1 = 0;
 			}
 			x1++; if (x1 >= xsiz1) x1 = 0;
@@ -3997,7 +3997,7 @@
 	int32_t i, j, k, x, z, sectnum, z1, z2, lx, rx;
 	sectortype *sec, *nsec;
 	walltype *wal;
-
+    
 	z = maskwall[damaskwallcnt];
 	wal = &wall[thewall[z]];
 	sectnum = thesector[z]; sec = &sector[sectnum];
@@ -4004,7 +4004,7 @@
 	nsec = &sector[wal->nextsector];
 	z1 = max(nsec->ceilingz,sec->ceilingz);
 	z2 = min(nsec->floorz,sec->floorz);
-
+    
 	wallmost(uwall,z,sectnum,(uint8_t )0);
 	wallmost(uplc,z,(long)wal->nextsector,(uint8_t )0);
 	for(x=xb1[z];x<=xb2[z];x++) if (uplc[x] > uwall[x]) uwall[x] = uplc[x];
@@ -4012,7 +4012,7 @@
 	wallmost(dplc,z,(long)wal->nextsector,(uint8_t )1);
 	for(x=xb1[z];x<=xb2[z];x++) if (dplc[x] < dwall[x]) dwall[x] = dplc[x];
 	prepwall(z,wal);
-
+    
 	globalorientation = (long)wal->cstat;
 	globalpicnum = wal->overpicnum;
 	if ((unsigned)globalpicnum >= (unsigned)MAXTILES) globalpicnum = 0;
@@ -4033,15 +4033,15 @@
 		globalzd = (((globalposz-z2)*globalyscale)<<8);
 	globalzd += (globalypanning<<24);
 	if (globalorientation&256) globalyscale = -globalyscale, globalzd = -globalzd;
-
+    
 	for(i=smostwallcnt-1;i>=0;i--)
 	{
 		j = smostwall[i];
 		if ((xb1[j] > xb2[z]) || (xb2[j] < xb1[z])) continue;
 		if (wallfront(j,z)) continue;
-
+        
 		lx = max(xb1[j],xb1[z]); rx = min(xb2[j],xb2[z]);
-
+        
 		switch(smostwalltype[i])
 		{
 			case 0:
@@ -4063,8 +4063,8 @@
 				break;
 		}
 	}
-
-		/* maskwall */
+    
+    /* maskwall */
 	if ((searchit >= 1) && (searchx >= xb1[z]) && (searchx <= xb2[z]))
 		if ((searchy >= uwall[searchx]) && (searchy <= dwall[searchx]))
 		{
@@ -4071,7 +4071,7 @@
 			searchsector = sectnum; searchwall = thewall[z];
 			searchstat = 4; searchit = 1;
 		}
-
+    
 	if ((globalorientation&128) == 0)
 		maskwallscan(xb1[z],xb2[z],uwall,dwall,swall,lwall);
 	else
@@ -4088,23 +4088,23 @@
 static void ceilspritehline (int32_t x2, int32_t y)
 {
 	int32_t x1, v, bx, by;
-
+    
 	/*
 	 * x = x1 + (x2-x1)t + (y1-y2)u  �  x = 160v
 	 * y = y1 + (y2-y1)t + (x2-x1)u  �  y = (scrx-160)v
 	 * z = z1 = z2                   �  z = posz + (scry-horiz)v
      */
-
+    
 	x1 = lastx[y]; if (x2 < x1) return;
-
+    
 	v = mulscale20(globalzd,horizlookup[y-globalhoriz+horizycent]);
 	bx = mulscale14(globalx2*x1+globalx1,v) + globalxpanning;
 	by = mulscale14(globaly2*x1+globaly1,v) + globalypanning;
 	asm1 = mulscale14(globalx2,v);
 	asm2 = mulscale14(globaly2,v);
-
+    
 	asm3 = (long)FP_OFF(palookup[globalpal]) + (getpalookup((long)mulscale28(klabs(v),globvis),globalshade)<<8);
-
+    
 	if ((globalorientation&2) == 0)
 		mhline(globalbufplc,bx,(x2-x1)<<16,0L,by,ylookup[y]+x1+frameoffset);
 	else
@@ -4118,7 +4118,7 @@
 static void ceilspritescan (int32_t x1, int32_t x2)
 {
 	int32_t x, y1, y2, twall, bwall;
-
+    
 	y1 = uwall[x1]; y2 = y1;
 	for(x=x1;x<=x2;x++)
 	{
@@ -4162,19 +4162,19 @@
 	int32_t npoints, npoints2, zz, t, zsgn, zzsgn;
 	short tilenum, spritenum;
 	uint8_t  swapped, daclip;
-
-    #ifdef SUPERBUILD
-        int32_t *longptr;
-    #endif
-
+    
+#ifdef SUPERBUILD
+    int32_t *longptr;
+#endif
+    
 	tspr = tspriteptr[snum];
-
+    
 	xb = spritesx[snum];
 	yp = spritesy[snum];
 	tilenum = tspr->picnum;
 	spritenum = tspr->owner;
 	cstat = tspr->cstat;
-
+    
 	if ((cstat&48) != 48)
 	{
 		if (picanm[tilenum]&192) tilenum += animateoffs(tilenum,(short) (spritenum+32768));
@@ -4182,11 +4182,11 @@
 			return;
 	}
 	if ((tspr->xrepeat <= 0) || (tspr->yrepeat <= 0)) return;
-
+    
 	sectnum = tspr->sectnum; sec = &sector[sectnum];
 	globalpal = tspr->pal;
 	// FIX_00088: crash on maps using a bad palette index (like the end of roch3.map)
-	if (!palookup[globalpal]) 
+	if (!palookup[globalpal])
 		globalpal = 0; // seem to crash when globalpal > 25
 	globalshade = tspr->shade;
 	if (cstat&2)
@@ -4193,31 +4193,31 @@
 	{
 		if (cstat&512) settransreverse(); else settransnormal();
 	}
-
+    
 	xoff = (long)((int8_t )((picanm[tilenum]>>8)&255))+((long)tspr->xoffset);
 	yoff = (long)((int8_t )((picanm[tilenum]>>16)&255))+((long)tspr->yoffset);
-
+    
 	if ((cstat&48) == 0)
 	{
 		if (yp <= (4<<8)) return;
-
+        
 		siz = divscale19(xdimenscale,yp);
-
+        
 		xv = mulscale16(((long)tspr->xrepeat)<<16,xyaspect);
-
+        
 		xspan = tilesizx[tilenum];
 		yspan = tilesizy[tilenum];
 		xsiz = mulscale30(siz,xv*xspan);
 		ysiz = mulscale14(siz,tspr->yrepeat*yspan);
-
+        
 		if (((tilesizx[tilenum]>>11) >= xsiz) || (yspan >= (ysiz>>1)))
 			return;  /* Watch out for divscale overflow */
-
+        
 		x1 = xb-(xsiz>>1);
 		if (xspan&1) x1 += mulscale31(siz,xv);  /* Odd xspans */
 		i = mulscale30(siz,xv*xoff);
 		if ((cstat&4) == 0) x1 -= i; else x1 += i;
-
+        
 		y1 = mulscale16(tspr->z-globalposz,siz);
 		y1 -= mulscale14(siz,tspr->yrepeat*yoff);
 		y1 += (globalhoriz<<8)-ysiz;
@@ -4226,17 +4226,17 @@
 			y1 += (ysiz>>1);
 			if (yspan&1) y1 += mulscale15(siz,tspr->yrepeat);  /* Odd yspans */
 		}
-
+        
 		x2 = x1+xsiz-1;
 		y2 = y1+ysiz-1;
 		if ((y1|255) >= (y2|255)) return;
-
+        
 		lx = (x1>>8)+1; if (lx < 0) lx = 0;
 		rx = (x2>>8); if (rx >= xdimen) rx = xdimen-1;
 		if (lx > rx) return;
-
+        
 		yinc = divscale32(yspan,ysiz);
-
+        
 		if ((sec->ceilingstat&3) == 0)
 			startum = globalhoriz+mulscale24(siz,sec->ceilingz-globalposz)-1;
 		else
@@ -4247,11 +4247,11 @@
 			startdm = 0x7fffffff;
 		if ((y1>>8) > startum) startum = (y1>>8);
 		if ((y2>>8) < startdm) startdm = (y2>>8);
-
+        
 		if (startum < -32768) startum = -32768;
 		if (startdm > 32767) startdm = 32767;
 		if (startum >= startdm) return;
-
+        
 		if ((cstat&4) == 0)
 		{
 			linuminc = divscale24(xspan,xsiz);
@@ -4267,7 +4267,7 @@
 			yinc = -yinc;
 			i = y1; y1 = y2; y2 = i;
 		}
-
+        
 		for(x=lx;x<=rx;x++)
 		{
 			uwall[x] = max(startumost[x+windowx1]-windowy1,(short)startum);
@@ -4281,9 +4281,9 @@
 			if ((xb1[j] > rx) || (xb2[j] < lx)) continue;
 			if ((yp <= yb1[j]) && (yp <= yb2[j])) continue;
 			if (spritewallfront(tspr,(long)thewall[j]) && ((yp <= yb1[j]) || (yp <= yb2[j]))) continue;
-
+            
 			dalx2 = max(xb1[j],lx); darx2 = min(xb2[j],rx);
-
+            
 			switch(smostwalltype[i])
 			{
 				case 0:
@@ -4307,7 +4307,7 @@
 					break;
 			}
 		}
-
+        
 		if (uwall[rx] >= dwall[rx])
 		{
 			for(x=lx;x<rx;x++)
@@ -4314,8 +4314,8 @@
 				if (uwall[x] < dwall[x]) break;
 			if (x == rx) return;
 		}
-
-			/* sprite */
+        
+        /* sprite */
 		if ((searchit >= 1) && (searchx >= lx) && (searchx <= rx))
 			if ((searchy >= uwall[searchx]) && (searchy < dwall[searchx]))
 			{
@@ -4322,7 +4322,7 @@
 				searchsector = sectnum; searchwall = spritenum;
 				searchstat = 3; searchit = 1;
 			}
-
+        
 		z2 = tspr->z - ((yoff*tspr->yrepeat)<<2);
 		if (cstat&128)
 		{
@@ -4330,7 +4330,7 @@
 			if (yspan&1) z2 += (tspr->yrepeat<<1);        /* Odd yspans */
 		}
 		z1 = z2 - ((yspan*tspr->yrepeat)<<2);
-
+        
 		globalorientation = 0;
 		globalpicnum = tilenum;
 		if ((unsigned)globalpicnum >= (unsigned)MAXTILES) globalpicnum = 0;
@@ -4348,10 +4348,10 @@
 			globalyscale = -globalyscale;
 			globalzd = (((globalposz-z2)*globalyscale)<<8);
 		}
-
+        
 		qinterpolatedown16((int32_t *)&lwall[lx],rx-lx+1,linum,linuminc);
 		clearbuf(&swall[lx],rx-lx+1,mulscale19(yp,xdimscale));
-
+        
 		if ((cstat&2) == 0)
 			maskwallscan(lx,rx,uwall,dwall,swall,lwall);
 		else
@@ -4361,7 +4361,7 @@
 	{
 		if ((cstat&4) > 0) xoff = -xoff;
 		if ((cstat&8) > 0) yoff = -yoff;
-
+        
 		xspan = tilesizx[tilenum]; yspan = tilesizy[tilenum];
 		xv = tspr->xrepeat*sintable[(tspr->ang+2560+1536)&2047];
 		yv = tspr->xrepeat*sintable[(tspr->ang+2048+1536)&2047];
@@ -4368,16 +4368,16 @@
 		i = (xspan>>1)+xoff;
 		x1 = tspr->x-globalposx-mulscale16(xv,i); x2 = x1+mulscale16(xv,xspan);
 		y1 = tspr->y-globalposy-mulscale16(yv,i); y2 = y1+mulscale16(yv,xspan);
-
+        
 		yp1 = dmulscale6(x1,cosviewingrangeglobalang,y1,sinviewingrangeglobalang);
 		yp2 = dmulscale6(x2,cosviewingrangeglobalang,y2,sinviewingrangeglobalang);
 		if ((yp1 <= 0) && (yp2 <= 0)) return;
 		xp1 = dmulscale6(y1,cosglobalang,-x1,singlobalang);
 		xp2 = dmulscale6(y2,cosglobalang,-x2,singlobalang);
-
+        
 		x1 += globalposx; y1 += globalposy;
 		x2 += globalposx; y2 += globalposy;
-
+        
 		swapped = 0;
 		if (dmulscale32(xp1,yp2,-xp2,yp1) >= 0)  /* If wall's NOT facing you */
 		{
@@ -4388,11 +4388,11 @@
 			i = y1, y1 = y2, y2 = i;
 			swapped = 1;
 		}
-
+        
 		if (xp1 >= -yp1)
 		{
 			if (xp1 > yp1) return;
-
+            
 			if (yp1 == 0) return;
 			xb1[MAXWALLSB-1] = halfxdimen + scale(xp1,halfxdimen,yp1);
 			if (xp1 >= 0) xb1[MAXWALLSB-1]++;   /* Fix for SIGNED divide */
@@ -4410,7 +4410,7 @@
 		if (xp2 <= yp2)
 		{
 			if (xp2 < -yp2) return;
-
+            
 			if (yp2 == 0) return;
 			xb2[MAXWALLSB-1] = halfxdimen + scale(xp2,halfxdimen,yp2) - 1;
 			if (xp2 >= 0) xb2[MAXWALLSB-1]++;   /* Fix for SIGNED divide */
@@ -4420,21 +4420,21 @@
 		else
 		{
 			if (xp1 > yp1) return;
-
+            
 			xb2[MAXWALLSB-1] = xdimen-1;
 			i = xp2-xp1+yp1-yp2;
 			if (i == 0) return;
 			yb2[MAXWALLSB-1] = yp1 + scale(yp2-yp1,yp1-xp1,i);
 		}
-
+        
 		if ((yb1[MAXWALLSB-1] < 256) || (yb2[MAXWALLSB-1] < 256) || (xb1[MAXWALLSB-1] > xb2[MAXWALLSB-1]))
 			return;
-
+        
 		topinc = -mulscale10(yp1,xspan);
 		top = (((mulscale10(xp1,xdimen) - mulscale9(xb1[MAXWALLSB-1]-halfxdimen,yp1))*xspan)>>3);
 		botinc = ((yp2-yp1)>>8);
 		bot = mulscale11(xp1-xp2,xdimen) + mulscale2(xb1[MAXWALLSB-1]-halfxdimen,botinc);
-
+        
 		j = xb2[MAXWALLSB-1]+3;
 		z = mulscale20(top,krecipasm(bot));
 		lwall[xb1[MAXWALLSB-1]] = (z>>8);
@@ -4448,10 +4448,10 @@
 			lwall[x-3] = ((i+zz)>>9);
 			lwall[x-1] = ((i+z)>>9);
 		}
-
+        
 		if (lwall[xb1[MAXWALLSB-1]] < 0) lwall[xb1[MAXWALLSB-1]] = 0;
 		if (lwall[xb2[MAXWALLSB-1]] >= xspan) lwall[xb2[MAXWALLSB-1]] = xspan-1;
-
+        
 		if ((swapped^((cstat&4)>0)) > 0)
 		{
 			j = xspan-1;
@@ -4458,14 +4458,14 @@
 			for(x=xb1[MAXWALLSB-1];x<=xb2[MAXWALLSB-1];x++)
 				lwall[x] = j-lwall[x];
 		}
-
+        
 		rx1[MAXWALLSB-1] = xp1; ry1[MAXWALLSB-1] = yp1;
 		rx2[MAXWALLSB-1] = xp2; ry2[MAXWALLSB-1] = yp2;
-
+        
 		hplc = divscale19(xdimenscale,yb1[MAXWALLSB-1]);
 		hinc = divscale19(xdimenscale,yb2[MAXWALLSB-1]);
 		hinc = (hinc-hplc)/(xb2[MAXWALLSB-1]-xb1[MAXWALLSB-1]+1);
-
+        
 		z2 = tspr->z - ((yoff*tspr->yrepeat)<<2);
 		if (cstat&128)
 		{
@@ -4473,7 +4473,7 @@
 			if (yspan&1) z2 += (tspr->yrepeat<<1);        /* Odd yspans */
 		}
 		z1 = z2 - ((yspan*tspr->yrepeat)<<2);
-
+        
 		globalorientation = 0;
 		globalpicnum = tilenum;
 		if ((unsigned)globalpicnum >= (unsigned)MAXTILES) globalpicnum = 0;
@@ -4491,23 +4491,23 @@
 			globalyscale = -globalyscale;
 			globalzd = (((globalposz-z2)*globalyscale)<<8);
 		}
-
+        
 		if (((sec->ceilingstat&1) == 0) && (z1 < sec->ceilingz))
 			z1 = sec->ceilingz;
 		if (((sec->floorstat&1) == 0) && (z2 > sec->floorz))
 			z2 = sec->floorz;
-
+        
 		owallmost(uwall,(long)(MAXWALLSB-1),z1-globalposz);
 		owallmost(dwall,(long)(MAXWALLSB-1),z2-globalposz);
 		for(i=xb1[MAXWALLSB-1];i<=xb2[MAXWALLSB-1];i++)
-			{ swall[i] = (krecipasm(hplc)<<2); hplc += hinc; }
-
+        { swall[i] = (krecipasm(hplc)<<2); hplc += hinc; }
+        
 		for(i=smostwallcnt-1;i>=0;i--)
 		{
 			j = smostwall[i];
-
+            
 			if ((xb1[j] > xb2[MAXWALLSB-1]) || (xb2[j] < xb1[MAXWALLSB-1])) continue;
-
+            
 			dalx2 = xb1[j]; darx2 = xb2[j];
 			if (max(yb1[MAXWALLSB-1],yb2[MAXWALLSB-1]) > min(yb1[j],yb2[j]))
 			{
@@ -4519,7 +4519,7 @@
 				{
 					x = thewall[j]; xp1 = wall[x].x; yp1 = wall[x].y;
 					x = wall[x].point2; xp2 = wall[x].x; yp2 = wall[x].y;
-
+                    
 					z1 = (xp2-xp1)*(y1-yp1) - (yp2-yp1)*(x1-xp1);
 					z2 = (xp2-xp1)*(y2-yp1) - (yp2-yp1)*(x2-xp1);
 					if ((z1^z2) >= 0)
@@ -4528,7 +4528,7 @@
 					{
 						z1 = (x2-x1)*(yp1-y1) - (y2-y1)*(xp1-x1);
 						z2 = (x2-x1)*(yp2-y1) - (y2-y1)*(xp2-x1);
-
+                        
 						if ((z1^z2) >= 0)
 							x = -(z1+z2);
 						else
@@ -4544,19 +4544,19 @@
 							{     /* INTERSECTION! */
 								x = (xp1-globalposx) + scale(xp2-xp1,z1,z1-z2);
 								y = (yp1-globalposy) + scale(yp2-yp1,z1,z1-z2);
-
+                                
 								yp1 = dmulscale14(x,cosglobalang,y,singlobalang);
 								if (yp1 > 0)
 								{
 									xp1 = dmulscale14(y,cosglobalang,-x,singlobalang);
-
+                                    
 									x = halfxdimen + scale(xp1,halfxdimen,yp1);
 									if (xp1 >= 0) x++;   /* Fix for SIGNED divide */
-
+                                    
 									if (z1 < 0)
-										{ if (dalx2 < x) dalx2 = x; }
+                                    { if (dalx2 < x) dalx2 = x; }
 									else
-										{ if (darx2 > x) darx2 = x; }
+                                    { if (darx2 > x) darx2 = x; }
 									x = 0x80000001;
 								}
 								else
@@ -4592,8 +4592,8 @@
 				}
 			}
 		}
-
-			/* sprite */
+        
+        /* sprite */
 		if ((searchit >= 1) && (searchx >= xb1[MAXWALLSB-1]) && (searchx <= xb2[MAXWALLSB-1]))
 			if ((searchy >= uwall[searchx]) && (searchy <= dwall[searchx]))
 			{
@@ -4600,7 +4600,7 @@
 				searchsector = sectnum; searchwall = spritenum;
 				searchstat = 3; searchit = 1;
 			}
-
+        
 		if ((cstat&2) == 0)
 			maskwallscan(xb1[MAXWALLSB-1],xb2[MAXWALLSB-1],uwall,dwall,swall,lwall);
 		else
@@ -4611,19 +4611,19 @@
 		if ((cstat&64) != 0)
 			if ((globalposz > tspr->z) == ((cstat&8)==0))
 				return;
-
+        
 		if ((cstat&4) > 0) xoff = -xoff;
 		if ((cstat&8) > 0) yoff = -yoff;
 		xspan = tilesizx[tilenum];
 		yspan = tilesizy[tilenum];
-
-			/* Rotate center point */
+        
+        /* Rotate center point */
 		dax = tspr->x-globalposx;
 		day = tspr->y-globalposy;
 		rzi[0] = dmulscale10(cosglobalang,dax,singlobalang,day);
 		rxi[0] = dmulscale10(cosglobalang,day,-singlobalang,dax);
-
-			/* Get top-left corner */
+        
+        /* Get top-left corner */
 		i = ((tspr->ang+2048-globalang)&2047);
 		cosang = sintable[(i+512)&2047]; sinang = sintable[i];
 		dax = ((xspan>>1)+xoff)*tspr->xrepeat;
@@ -4630,8 +4630,8 @@
 		day = ((yspan>>1)+yoff)*tspr->yrepeat;
 		rzi[0] += dmulscale12(sinang,dax,cosang,day);
 		rxi[0] += dmulscale12(sinang,day,-cosang,dax);
-
-			/* Get other 3 corners */
+        
+        /* Get other 3 corners */
 		dax = xspan*tspr->xrepeat;
 		day = yspan*tspr->yrepeat;
 		rzi[1] = rzi[0]-mulscale12(sinang,dax);
@@ -4640,50 +4640,50 @@
 		day = -mulscale12(sinang,day);
 		rzi[2] = rzi[1]+dax; rxi[2] = rxi[1]+day;
 		rzi[3] = rzi[0]+dax; rxi[3] = rxi[0]+day;
-
-			/* Put all points on same z */
+        
+        /* Put all points on same z */
 		ryi[0] = scale((tspr->z-globalposz),yxaspect,320<<8);
 		if (ryi[0] == 0) return;
 		ryi[1] = ryi[2] = ryi[3] = ryi[0];
-
+        
 		if ((cstat&4) == 0)
-			{ z = 0; z1 = 1; z2 = 3; }
+        { z = 0; z1 = 1; z2 = 3; }
 		else
-			{ z = 1; z1 = 0; z2 = 2; }
-
+        { z = 1; z1 = 0; z2 = 2; }
+        
 		dax = rzi[z1]-rzi[z]; day = rxi[z1]-rxi[z];
 		bot = dmulscale8(dax,dax,day,day);
 		if (((klabs(dax)>>13) >= bot) || ((klabs(day)>>13) >= bot)) return;
 		globalx1 = divscale18(dax,bot);
 		globalx2 = divscale18(day,bot);
-
+        
 		dax = rzi[z2]-rzi[z]; day = rxi[z2]-rxi[z];
 		bot = dmulscale8(dax,dax,day,day);
 		if (((klabs(dax)>>13) >= bot) || ((klabs(day)>>13) >= bot)) return;
 		globaly1 = divscale18(dax,bot);
 		globaly2 = divscale18(day,bot);
-
-			/* Calculate globals for hline texture mapping function */
+        
+        /* Calculate globals for hline texture mapping function */
 		globalxpanning = (rxi[z]<<12);
 		globalypanning = (rzi[z]<<12);
 		globalzd = (ryi[z]<<12);
-
+        
 		rzi[0] = mulscale16(rzi[0],viewingrange);
 		rzi[1] = mulscale16(rzi[1],viewingrange);
 		rzi[2] = mulscale16(rzi[2],viewingrange);
 		rzi[3] = mulscale16(rzi[3],viewingrange);
-
+        
 		if (ryi[0] < 0)   /* If ceilsprite is above you, reverse order of points */
 		{
 			i = rxi[1]; rxi[1] = rxi[3]; rxi[3] = i;
 			i = rzi[1]; rzi[1] = rzi[3]; rzi[3] = i;
 		}
-
-
-			/* Clip polygon in 3-space */
+        
+        
+        /* Clip polygon in 3-space */
 		npoints = 4;
-
-			/* Clip edge 1 */
+        
+        /* Clip edge 1 */
 		npoints2 = 0;
 		zzsgn = rxi[0]+rzi[0];
 		for(z=0;z<npoints;z++)
@@ -4705,8 +4705,8 @@
 			}
 		}
 		if (npoints2 <= 2) return;
-
-			/* Clip edge 2 */
+        
+        /* Clip edge 2 */
 		npoints = 0;
 		zzsgn = rxi2[0]-rzi2[0];
 		for(z=0;z<npoints2;z++)
@@ -4728,8 +4728,8 @@
 			}
 		}
 		if (npoints <= 2) return;
-
-			/* Clip edge 3 */
+        
+        /* Clip edge 3 */
 		npoints2 = 0;
 		zzsgn = ryi[0]*halfxdimen + (rzi[0]*(globalhoriz-0));
 		for(z=0;z<npoints;z++)
@@ -4753,8 +4753,8 @@
 			}
 		}
 		if (npoints2 <= 2) return;
-
-			/* Clip edge 4 */
+        
+        /* Clip edge 4 */
 		npoints = 0;
 		zzsgn = ryi2[0]*halfxdimen + (rzi2[0]*(globalhoriz-ydimen));
 		for(z=0;z<npoints2;z++)
@@ -4778,8 +4778,8 @@
 			}
 		}
 		if (npoints <= 2) return;
-
-			/* Project onto screen */
+        
+        /* Project onto screen */
 		lpoint = -1; lmax = 0x7fffffff;
 		rpoint = -1; rmax = 0x80000000;
 		for(z=0;z<npoints;z++)
@@ -4793,12 +4793,12 @@
 			if (xsi[z] < lmax) lmax = xsi[z], lpoint = z;
 			if (xsi[z] > rmax) rmax = xsi[z], rpoint = z;
 		}
-
-			/* Get uwall arrays */
+        
+        /* Get uwall arrays */
 		for(z=lpoint;z!=rpoint;z=zz)
 		{
 			zz = z+1; if (zz == npoints) zz = 0;
-
+            
 			dax1 = ((xsi[z]+65535)>>16);
 			dax2 = ((xsi[zz]+65535)>>16);
 			if (dax2 > dax1)
@@ -4808,12 +4808,12 @@
 				qinterpolatedown16short((int32_t *)(&uwall[dax1]),dax2-dax1,y,yinc);
 			}
 		}
-
-			/* Get dwall arrays */
+        
+        /* Get dwall arrays */
 		for(;z!=lpoint;z=zz)
 		{
 			zz = z+1; if (zz == npoints) zz = 0;
-
+            
 			dax1 = ((xsi[zz]+65535)>>16);
 			dax2 = ((xsi[z]+65535)>>16);
 			if (dax2 > dax1)
@@ -4823,8 +4823,8 @@
 				qinterpolatedown16short((int32_t *)(&dwall[dax1]),dax2-dax1,y,yinc);
 			}
 		}
-
-
+        
+        
 		lx = ((lmax+65535)>>16);
 		rx = ((rmax+65535)>>16);
 		for(x=lx;x<=rx;x++)
@@ -4832,23 +4832,23 @@
 			uwall[x] = max(uwall[x],startumost[x+windowx1]-windowy1);
 			dwall[x] = min(dwall[x],startdmost[x+windowx1]-windowy1);
 		}
-
-			/* Additional uwall/dwall clipping goes here */
+        
+        /* Additional uwall/dwall clipping goes here */
 		for(i=smostwallcnt-1;i>=0;i--)
 		{
 			j = smostwall[i];
 			if ((xb1[j] > rx) || (xb2[j] < lx)) continue;
 			if ((yp <= yb1[j]) && (yp <= yb2[j])) continue;
-
-				/* if (spritewallfront(tspr,thewall[j]) == 0) */
+            
+            /* if (spritewallfront(tspr,thewall[j]) == 0) */
 			x = thewall[j]; xp1 = wall[x].x; yp1 = wall[x].y;
 			x = wall[x].point2; xp2 = wall[x].x; yp2 = wall[x].y;
 			x = (xp2-xp1)*(tspr->y-yp1)-(tspr->x-xp1)*(yp2-yp1);
 			if ((yp > yb1[j]) && (yp > yb2[j])) x = -1;
 			if ((x >= 0) && ((x != 0) || (wall[thewall[j]].nextsector != tspr->sectnum))) continue;
-
+            
 			dalx2 = max(xb1[j],lx); darx2 = min(xb2[j],rx);
-
+            
 			switch(smostwalltype[i])
 			{
 				case 0:
@@ -4870,8 +4870,8 @@
 					break;
 			}
 		}
-
-			/* sprite */
+        
+        /* sprite */
 		if ((searchit >= 1) && (searchx >= lx) && (searchx <= rx))
 			if ((searchy >= uwall[searchx]) && (searchy <= dwall[searchx]))
 			{
@@ -4878,19 +4878,19 @@
 				searchsector = sectnum; searchwall = spritenum;
 				searchstat = 3; searchit = 1;
 			}
-
+        
 		globalorientation = cstat;
 		globalpicnum = tilenum;
 		if ((unsigned)globalpicnum >= (unsigned)MAXTILES) globalpicnum = 0;
 		/* if (picanm[globalpicnum]&192) globalpicnum += animateoffs((short)globalpicnum,spritenum+32768); */
-
+        
 		if (waloff[globalpicnum] == 0) loadtile(globalpicnum);
 		setgotpic(globalpicnum);
 		globalbufplc = waloff[globalpicnum];
-
+        
 		globvis = mulscale16(globalhisibility,viewingrange);
 		if (sec->visibility != 0) globvis = mulscale4(globvis,(long)((uint8_t )(sec->visibility+16)));
-
+        
 		x = picsiz[globalpicnum]; y = ((x>>4)&15); x &= 15;
 		if (pow2long[x] != xspan)
 		{
@@ -4898,27 +4898,27 @@
 			globalx1 = mulscale(globalx1,xspan,x);
 			globalx2 = mulscale(globalx2,xspan,x);
 		}
-
+        
 		dax = globalxpanning; day = globalypanning;
 		globalxpanning = -dmulscale6(globalx1,day,globalx2,dax);
 		globalypanning = -dmulscale6(globaly1,day,globaly2,dax);
-
+        
 		globalx2 = mulscale16(globalx2,viewingrange);
 		globaly2 = mulscale16(globaly2,viewingrange);
 		globalzd = mulscale16(globalzd,viewingrangerecip);
-
+        
 		globalx1 = (globalx1-globalx2)*halfxdimen;
 		globaly1 = (globaly1-globaly2)*halfxdimen;
-
+        
 		if ((cstat&2) == 0)
 			msethlineshift(x,y);
 		else
 			tsethlineshift(x,y);
-
-			/* Draw it! */
+        
+        /* Draw it! */
 		ceilspritescan(lx,rx-1);
 	}
-
+    
 	if (automapping == 1) show2dsprite[spritenum>>3] |= pow2char[spritenum&7];
 }
 
@@ -4927,7 +4927,7 @@
 {
 	int32_t i, j, k, l, gap, xs, ys, xp, yp, yoff, yspan;
 	/* int32_t zs, zp; */
-
+    
 	for(i=spritesortcnt-1;i>=0;i--) tspriteptr[i] = &tsprite[i];
 	for(i=spritesortcnt-1;i>=0;i--)
 	{
@@ -4951,7 +4951,7 @@
 		}
 		spritesy[i] = yp;
 	}
-
+    
 	gap = 1; while (gap < spritesortcnt) gap = (gap<<1)+1;
 	for(gap>>=1;gap>0;gap>>=1)      /* Sort sprite list */
 		for(i=0;i<spritesortcnt-gap;i++)
@@ -4962,10 +4962,10 @@
 				swaplong(&spritesx[l],&spritesx[l+gap]);
 				swaplong(&spritesy[l],&spritesy[l+gap]);
 			}
-
+    
 	if (spritesortcnt > 0)
 		spritesy[spritesortcnt] = (spritesy[spritesortcnt-1]^1);
-
+    
 	ys = spritesy[0]; i = 0;
 	for(j=1;j<=spritesortcnt;j++)
 	{
@@ -5005,7 +5005,7 @@
 		}
 		i = j;
 	}
-
+    
 	while ((spritesortcnt > 0) && (maskwallcnt > 0))  /* While BOTH > 0 */
 	{
 		j = maskwall[maskwallcnt-1];
@@ -5013,7 +5013,7 @@
 			drawsprite(--spritesortcnt);
 		else
 		{
-				/* Check to see if any sprites behind the masked wall... */
+            /* Check to see if any sprites behind the masked wall... */
 			k = -1;
 			gap = 0;
 			for(i=spritesortcnt-2;i>=0;i--)
@@ -5040,8 +5040,8 @@
 					}
 				spritesortcnt -= gap;
 			}
-
-				/* finally safe to draw the masked wall */
+            
+            /* finally safe to draw the masked wall */
 			drawmaskwall(--maskwallcnt);
 		}
 	}
@@ -5053,11 +5053,11 @@
 int setsprite(short spritenum, int32_t newx, int32_t newy, int32_t newz)
 {
 	short tempsectnum;
-
+    
 	sprite[spritenum].x = newx;
 	sprite[spritenum].y = newy;
 	sprite[spritenum].z = newz;
-
+    
 	tempsectnum = sprite[spritenum].sectnum;
 	updatesector(newx,newy,&tempsectnum);
 	if (tempsectnum < 0)
@@ -5064,7 +5064,7 @@
 		return(-1);
 	if (tempsectnum != sprite[spritenum].sectnum)
 		changespritesect(spritenum,tempsectnum);
-
+    
 	return(0);
 }
 
@@ -5072,7 +5072,7 @@
 void initspritelists(void)
 {
 	int32_t i;
-
+    
 	for (i=0;i<MAXSECTORS;i++)     /* Init doubly-linked sprite sector lists */
 		headspritesect[i] = -1;
 	headspritesect[MAXSECTORS] = 0;
@@ -5084,8 +5084,8 @@
 	}
 	prevspritesect[0] = -1;
 	nextspritesect[MAXSPRITES-1] = -1;
-
-
+    
+    
 	for(i=0;i<MAXSTATUS;i++)      /* Init doubly-linked sprite status lists */
 		headspritestat[i] = -1;
 	headspritestat[MAXSTATUS] = 0;
@@ -5110,24 +5110,24 @@
 int insertspritesect(short sectnum)
 {
 	short blanktouse;
-
+    
 	if ((sectnum >= MAXSECTORS) || (headspritesect[MAXSECTORS] == -1))
 		return(-1);  /* list full */
-
+    
 	blanktouse = headspritesect[MAXSECTORS];
-
+    
 	headspritesect[MAXSECTORS] = nextspritesect[blanktouse];
 	if (headspritesect[MAXSECTORS] >= 0)
 		prevspritesect[headspritesect[MAXSECTORS]] = -1;
-
+    
 	prevspritesect[blanktouse] = -1;
 	nextspritesect[blanktouse] = headspritesect[sectnum];
 	if (headspritesect[sectnum] >= 0)
 		prevspritesect[headspritesect[sectnum]] = blanktouse;
 	headspritesect[sectnum] = blanktouse;
-
+    
 	sprite[blanktouse].sectnum = sectnum;
-
+    
 	return(blanktouse);
 }
 
@@ -5135,24 +5135,24 @@
 int insertspritestat(short statnum)
 {
 	short blanktouse;
-
+    
 	if ((statnum >= MAXSTATUS) || (headspritestat[MAXSTATUS] == -1))
 		return(-1);  /* list full */
-
+    
 	blanktouse = headspritestat[MAXSTATUS];
-
+    
 	headspritestat[MAXSTATUS] = nextspritestat[blanktouse];
 	if (headspritestat[MAXSTATUS] >= 0)
 		prevspritestat[headspritestat[MAXSTATUS]] = -1;
-
+    
 	prevspritestat[blanktouse] = -1;
 	nextspritestat[blanktouse] = headspritestat[statnum];
 	if (headspritestat[statnum] >= 0)
 		prevspritestat[headspritestat[statnum]] = blanktouse;
 	headspritestat[statnum] = blanktouse;
-
+    
 	sprite[blanktouse].statnum = statnum;
-
+    
 	return(blanktouse);
 }
 
@@ -5168,18 +5168,18 @@
 {
 	if (sprite[deleteme].sectnum == MAXSECTORS)
 		return(-1);
-
+    
 	if (headspritesect[sprite[deleteme].sectnum] == deleteme)
 		headspritesect[sprite[deleteme].sectnum] = nextspritesect[deleteme];
-
+    
 	if (prevspritesect[deleteme] >= 0) nextspritesect[prevspritesect[deleteme]] = nextspritesect[deleteme];
 	if (nextspritesect[deleteme] >= 0) prevspritesect[nextspritesect[deleteme]] = prevspritesect[deleteme];
-
+    
 	if (headspritesect[MAXSECTORS] >= 0) prevspritesect[headspritesect[MAXSECTORS]] = deleteme;
 	prevspritesect[deleteme] = -1;
 	nextspritesect[deleteme] = headspritesect[MAXSECTORS];
 	headspritesect[MAXSECTORS] = deleteme;
-
+    
 	sprite[deleteme].sectnum = MAXSECTORS;
 	return(0);
 }
@@ -5189,18 +5189,18 @@
 {
 	if (sprite[deleteme].statnum == MAXSTATUS)
 		return(-1);
-
+    
 	if (headspritestat[sprite[deleteme].statnum] == deleteme)
 		headspritestat[sprite[deleteme].statnum] = nextspritestat[deleteme];
-
+    
 	if (prevspritestat[deleteme] >= 0) nextspritestat[prevspritestat[deleteme]] = nextspritestat[deleteme];
 	if (nextspritestat[deleteme] >= 0) prevspritestat[nextspritestat[deleteme]] = prevspritestat[deleteme];
-
+    
 	if (headspritestat[MAXSTATUS] >= 0) prevspritestat[headspritestat[MAXSTATUS]] = deleteme;
 	prevspritestat[deleteme] = -1;
 	nextspritestat[deleteme] = headspritestat[MAXSTATUS];
 	headspritestat[MAXSTATUS] = deleteme;
-
+    
 	sprite[deleteme].statnum = MAXSTATUS;
 	return(0);
 }
@@ -5234,11 +5234,11 @@
 	walltype *wal;
 	int32_t i, testz, nextz;
 	short sectortouse;
-
+    
 	if (direction == 1) nextz = 0x7fffffff; else nextz = 0x80000000;
-
+    
 	sectortouse = -1;
-
+    
 	wal = &wall[sector[sectnum].wallptr];
 	i = sector[sectnum].wallnum;
 	do
@@ -5289,23 +5289,23 @@
 		wal++;
 		i--;
 	} while (i != 0);
-
+    
 	return(sectortouse);
 }
 
 
 int cansee(int32_t x1, int32_t y1, int32_t z1, short sect1,
-            int32_t x2, int32_t y2, int32_t z2, short sect2)
+           int32_t x2, int32_t y2, int32_t z2, short sect2)
 {
 	sectortype *sec;
 	walltype *wal, *wal2;
 	int32_t i, cnt, nexts, x, y, z, cz, fz, dasectnum, dacnt, danum;
 	int32_t x21, y21, z21, x31, y31, x34, y34, bot, t;
-
+    
 	if ((x1 == x2) && (y1 == y2)) return(sect1 == sect2);
-
+    
 	x21 = x2-x1; y21 = y2-y1; z21 = z2-z1;
-
+    
 	clipsectorlist[0] = sect1; danum = 1;
 	for(dacnt=0;dacnt<danum;dacnt++)
 	{
@@ -5315,24 +5315,24 @@
 			wal2 = &wall[wal->point2];
 			x31 = wal->x-x1; x34 = wal->x-wal2->x;
 			y31 = wal->y-y1; y34 = wal->y-wal2->y;
-
+            
 			bot = y21*x34-x21*y34; if (bot <= 0) continue;
 			t = y21*x31-x21*y31; if ((unsigned)t >= (unsigned)bot) continue;
 			t = y31*x34-x31*y34; if ((unsigned)t >= (unsigned)bot) continue;
-
+            
 			nexts = wal->nextsector;
 			if ((nexts < 0) || (wal->cstat&32)) return(0);
-
+            
 			t = divscale24(t,bot);
 			x = x1 + mulscale24(x21,t);
 			y = y1 + mulscale24(y21,t);
 			z = z1 + mulscale24(z21,t);
-
+            
 			getzsofslope((short)dasectnum,x,y,&cz,&fz);
 			if ((z <= cz) || (z >= fz)) return(0);
 			getzsofslope((short)nexts,x,y,&cz,&fz);
 			if ((z <= cz) || (z >= fz)) return(0);
-
+            
 			for(i=danum-1;i>=0;i--) if (clipsectorlist[i] == nexts) break;
 			if (i < 0) clipsectorlist[danum++] = nexts;
 		}
@@ -5347,7 +5347,7 @@
                int32_t *inty, int32_t *intz)
 {     /* p1 to p2 is a line segment */
 	int32_t x21, y21, x34, y34, x31, y31, bot, topt, topu, t;
-
+    
 	x21 = x2-x1; x34 = x3-x4;
 	y21 = y2-y1; y34 = y3-y4;
 	bot = x21*y34 - y21*x34;
@@ -5377,7 +5377,7 @@
                int32_t *inty, int32_t *intz)
 {     /* p1 towards p2 is a ray */
 	int32_t x34, y34, x31, y31, bot, topt, topu, t;
-
+    
 	x34 = x3-x4; y34 = y3-y4;
 	bot = vx*y34 - vy*x34;
 	if (bot >= 0)
@@ -5417,21 +5417,21 @@
 	short tempshortcnt, tempshortnum, dasector, startwall, endwall;
 	short nextsector;
 	uint8_t  clipyou;
-
+    
 	*hitsect = -1; *hitwall = -1; *hitsprite = -1;
 	if (sectnum < 0) return(-1);
-
+    
 	*hitx = hitscangoalx; *hity = hitscangoaly;
-
+    
 	dawalclipmask = (cliptype&65535);
 	dasprclipmask = (cliptype>>16);
-
+    
 	clipsectorlist[0] = sectnum;
 	tempshortcnt = 0; tempshortnum = 1;
 	do
 	{
 		dasector = clipsectorlist[tempshortcnt]; sec = &sector[dasector];
-
+        
 		x1 = 0x7fffffff;
 		if (sec->ceilingstat&2)
 		{
@@ -5440,7 +5440,7 @@
 			i = nsqrtasm(dax*dax+day*day); if (i == 0) continue;
 			i = divscale15(sec->ceilingheinum,i);
 			dax *= i; day *= i;
-
+            
 			j = (vz<<8)-dmulscale15(dax,vy,-day,vx);
 			if (j != 0)
 			{
@@ -5470,7 +5470,7 @@
 				*hitsect = dasector; *hitwall = -1; *hitsprite = -1;
 				*hitx = x1; *hity = y1; *hitz = z1;
 			}
-
+        
 		x1 = 0x7fffffff;
 		if (sec->floorstat&2)
 		{
@@ -5479,7 +5479,7 @@
 			i = nsqrtasm(dax*dax+day*day); if (i == 0) continue;
 			i = divscale15(sec->floorheinum,i);
 			dax *= i; day *= i;
-
+            
 			j = (vz<<8)-dmulscale15(dax,vy,-day,vx);
 			if (j != 0)
 			{
@@ -5509,18 +5509,18 @@
 				*hitsect = dasector; *hitwall = -1; *hitsprite = -1;
 				*hitx = x1; *hity = y1; *hitz = z1;
 			}
-
+        
 		startwall = sec->wallptr; endwall = startwall + sec->wallnum;
 		for(z=startwall,wal=&wall[startwall];z<endwall;z++,wal++)
 		{
 			wal2 = &wall[wal->point2];
 			x1 = wal->x; y1 = wal->y; x2 = wal2->x; y2 = wal2->y;
-
+            
 			if ((x1-xs)*(y2-ys) < (x2-xs)*(y1-ys)) continue;
 			if (rintersect(xs,ys,zs,vx,vy,vz,x1,y1,x2,y2,&intx,&inty,&intz) == 0) continue;
-
+            
 			if (klabs(intx-xs)+klabs(inty-ys) >= klabs((*hitx)-xs)+klabs((*hity)-ys)) continue;
-
+            
 			nextsector = wal->nextsector;
 			if ((nextsector < 0) || (wal->cstat&dawalclipmask))
 			{
@@ -5535,18 +5535,18 @@
 				*hitx = intx; *hity = inty; *hitz = intz;
 				continue;
 			}
-
+            
 			for(zz=tempshortnum-1;zz>=0;zz--)
 				if (clipsectorlist[zz] == nextsector) break;
 			if (zz < 0) clipsectorlist[tempshortnum++] = nextsector;
 		}
-
+        
 		for(z=headspritesect[dasector];z>=0;z=nextspritesect[z])
 		{
 			spr = &sprite[z];
 			cstat = spr->cstat;
 			if ((cstat&dasprclipmask) == 0) continue;
-
+            
 			x1 = spr->x; y1 = spr->y; z1 = spr->z;
 			switch(cstat&48)
 			{
@@ -5553,15 +5553,15 @@
 				case 0:
 					topt = vx*(x1-xs) + vy*(y1-ys); if (topt <= 0) continue;
 					bot = vx*vx + vy*vy; if (bot == 0) continue;
-
+                    
 					intz = zs+scale(vz,topt,bot);
-
+                    
 					i = (tilesizy[spr->picnum]*spr->yrepeat<<2);
 					if (cstat&128) z1 += (i>>1);
 					if (picanm[spr->picnum]&0x00ff0000) z1 -= ((long)((int8_t )((picanm[spr->picnum]>>16)&255))*spr->yrepeat<<2);
 					if ((intz > z1) || (intz < z1-i)) continue;
 					topu = vx*(y1-ys) - vy*(x1-xs);
-
+                    
 					offx = scale(vx,topu,bot);
 					offy = scale(vy,topu,bot);
 					dist = offx*offx + offy*offy;
@@ -5569,17 +5569,17 @@
 					if (dist > (i>>7)) continue;
 					intx = xs + scale(vx,topt,bot);
 					inty = ys + scale(vy,topt,bot);
-
+                    
 					if (klabs(intx-xs)+klabs(inty-ys) > klabs((*hitx)-xs)+klabs((*hity)-ys)) continue;
-
+                    
 					*hitsect = dasector; *hitwall = -1; *hitsprite = z;
 					*hitx = intx; *hity = inty; *hitz = intz;
 					break;
 				case 16:
-						/*
-						 * These lines get the 2 points of the rotated sprite
-						 * Given: (x1, y1) starts out as the center point
-						 */
+                    /*
+                     * These lines get the 2 points of the rotated sprite
+                     * Given: (x1, y1) starts out as the center point
+                     */
 					tilenum = spr->picnum;
 					xoff = (long)((int8_t )((picanm[tilenum]>>8)&255))+((long)spr->xoffset);
 					if ((cstat&4) > 0) xoff = -xoff;
@@ -5588,14 +5588,14 @@
 					l = tilesizx[tilenum]; k = (l>>1)+xoff;
 					x1 -= mulscale16(dax,k); x2 = x1+mulscale16(dax,l);
 					y1 -= mulscale16(day,k); y2 = y1+mulscale16(day,l);
-
+                    
 					if ((cstat&64) != 0)   /* back side of 1-way sprite */
 						if ((x1-xs)*(y2-ys) < (x2-xs)*(y1-ys)) continue;
-
+                    
 					if (rintersect(xs,ys,zs,vx,vy,vz,x1,y1,x2,y2,&intx,&inty,&intz) == 0) continue;
-
+                    
 					if (klabs(intx-xs)+klabs(inty-ys) > klabs((*hitx)-xs)+klabs((*hity)-ys)) continue;
-
+                    
 					k = ((tilesizy[spr->picnum]*spr->yrepeat)<<2);
 					if (cstat&128) daz = spr->z+(k>>1); else daz = spr->z;
 					if (picanm[spr->picnum]&0x00ff0000) daz -= ((long)((int8_t  )((picanm[spr->picnum]>>16)&255))*spr->yrepeat<<2);
@@ -5611,23 +5611,23 @@
 					if (((intz-zs)^vz) < 0) continue;
 					if ((cstat&64) != 0)
 						if ((zs > intz) == ((cstat&8)==0)) continue;
-
+                    
 					intx = xs+scale(intz-zs,vx,vz);
 					inty = ys+scale(intz-zs,vy,vz);
-
+                    
 					if (klabs(intx-xs)+klabs(inty-ys) > klabs((*hitx)-xs)+klabs((*hity)-ys)) continue;
-
+                    
 					tilenum = spr->picnum;
 					xoff = (long)((int8_t )((picanm[tilenum]>>8)&255))+((long)spr->xoffset);
 					yoff = (long)((int8_t )((picanm[tilenum]>>16)&255))+((long)spr->yoffset);
 					if ((cstat&4) > 0) xoff = -xoff;
 					if ((cstat&8) > 0) yoff = -yoff;
-
+                    
 					ang = spr->ang;
 					cosang = sintable[(ang+512)&2047]; sinang = sintable[ang];
 					xspan = tilesizx[tilenum]; xrepeat = spr->xrepeat;
 					yspan = tilesizy[tilenum]; yrepeat = spr->yrepeat;
-
+                    
 					dax = ((xspan>>1)+xoff)*xrepeat; day = ((yspan>>1)+yoff)*yrepeat;
 					x1 += dmulscale16(sinang,dax,cosang,day)-intx;
 					y1 += dmulscale16(sinang,day,-cosang,dax)-inty;
@@ -5637,7 +5637,7 @@
 					l = yspan*yrepeat;
 					k = -mulscale16(cosang,l); x3 = x2+k; x4 = x1+k;
 					k = -mulscale16(sinang,l); y3 = y2+k; y4 = y1+k;
-
+                    
 					clipyou = 0;
 					if ((y1^y2) < 0)
 					{
@@ -5659,7 +5659,7 @@
 						if ((x4^x1) < 0) clipyou ^= (x4*y1<x1*y4)^(y4<y1);
 						else if (x4 >= 0) clipyou ^= 1;
 					}
-
+                    
 					if (clipyou != 0)
 					{
 						*hitsect = dasector; *hitwall = -1; *hitsprite = z;
@@ -5684,24 +5684,24 @@
 	int32_t topt, topu, bot, dist, offx, offy, vx, vy, vz;
 	short tempshortcnt, tempshortnum, dasector, startwall, endwall;
 	short nextsector, good;
-
+    
 	*neartagsector = -1; *neartagwall = -1; *neartagsprite = -1;
 	*neartaghitdist = 0;
-
+    
 	if (sectnum < 0) return(0);
 	if ((tagsearch < 1) || (tagsearch > 3)) return(0);
-
+    
 	vx = mulscale14(sintable[(ange+2560)&2047],neartagrange); xe = xs+vx;
 	vy = mulscale14(sintable[(ange+2048)&2047],neartagrange); ye = ys+vy;
 	vz = 0; ze = 0;
-
+    
 	clipsectorlist[0] = sectnum;
 	tempshortcnt = 0; tempshortnum = 1;
-
+    
 	do
 	{
 		dasector = clipsectorlist[tempshortcnt];
-
+        
 		startwall = sector[dasector].wallptr;
 		endwall = startwall + sector[dasector].wallnum - 1;
 		for(z=startwall,wal=&wall[startwall];z<=endwall;z++,wal++)
@@ -5708,9 +5708,9 @@
 		{
 			wal2 = &wall[wal->point2];
 			x1 = wal->x; y1 = wal->y; x2 = wal2->x; y2 = wal2->y;
-
+            
 			nextsector = wal->nextsector;
-
+            
 			good = 0;
 			if (nextsector >= 0)
 			{
@@ -5719,10 +5719,10 @@
 			}
 			if ((tagsearch&1) && wal->lotag) good |= 2;
 			if ((tagsearch&2) && wal->hitag) good |= 2;
-
+            
 			if ((good == 0) && (nextsector < 0)) continue;
 			if ((x1-xs)*(y2-ys) < (x2-xs)*(y1-ys)) continue;
-
+            
 			if (lintersect(xs,ys,zs,xe,ye,ze,x1,y1,x2,y2,&intx,&inty,&intz) == 1)
 			{
 				if (good != 0)
@@ -5740,11 +5740,11 @@
 				}
 			}
 		}
-
+        
 		for(z=headspritesect[dasector];z>=0;z=nextspritesect[z])
 		{
 			spr = &sprite[z];
-
+            
 			good = 0;
 			if ((tagsearch&1) && spr->lotag) good |= 1;
 			if ((tagsearch&2) && spr->hitag) good |= 1;
@@ -5751,7 +5751,7 @@
 			if (good != 0)
 			{
 				x1 = spr->x; y1 = spr->y; z1 = spr->z;
-
+                
 				topt = vx*(x1-xs) + vy*(y1-ys);
 				if (topt > 0)
 				{
@@ -5765,7 +5765,7 @@
 						if ((intz <= z1) && (intz >= z1-(i<<2)))
 						{
 							topu = vx*(y1-ys) - vy*(x1-xs);
-
+                            
 							offx = scale(vx,topu,bot);
 							offy = scale(vy,topu,bot);
 							dist = offx*offx + offy*offy;
@@ -5788,7 +5788,7 @@
 				}
 			}
 		}
-
+        
 		tempshortcnt++;
 	} while (tempshortcnt < tempshortnum);
 	return(0);
@@ -5798,10 +5798,10 @@
 void dragpoint(short pointhighlight, int32_t dax, int32_t day)
 {
 	short cnt, tempshort;
-
+    
 	wall[pointhighlight].x = dax;
 	wall[pointhighlight].y = day;
-
+    
 	cnt = MAXWALLS;
 	tempshort = pointhighlight;    /* search points CCW */
 	do
@@ -5841,7 +5841,7 @@
 int lastwall(short point)
 {
 	int32_t i, j, cnt;
-
+    
 	if ((point > 0) && (wall[point-1].point2 == point)) return(point-1);
 	i = point;
 	cnt = MAXWALLS;
@@ -5857,10 +5857,10 @@
 
 #define addclipline(dax1, day1, dax2, day2, daoval)      \
 {                                                        \
-	clipit[clipnum].x1 = dax1; clipit[clipnum].y1 = day1; \
-	clipit[clipnum].x2 = dax2; clipit[clipnum].y2 = day2; \
-	clipobjectval[clipnum] = daoval;                      \
-	clipnum++;                                            \
+clipit[clipnum].x1 = dax1; clipit[clipnum].y1 = day1; \
+clipit[clipnum].x2 = dax2; clipit[clipnum].y2 = day2; \
+clipobjectval[clipnum] = daoval;                      \
+clipnum++;                                            \
 }                                                        \
 
 
@@ -5868,7 +5868,7 @@
 {
 	int32_t dx, dy, ox, oy, x1, y1;
 	uint8_t  first;
-
+    
 	x1 = clipit[w].x1; dx = clipit[w].x2-x1;
 	y1 = clipit[w].y1; dy = clipit[w].y2-y1;
 	ox = ksgn(-dy); oy = ksgn(dx);
@@ -5886,13 +5886,13 @@
 {
 	int32_t x1, y1, x2, y2, bot, topu, nintx, ninty, cnt, z, hitwall;
 	int32_t x21, y21, x43, y43;
-
+    
 	hitwall = -1;
 	for(z=clipnum-1;z>=0;z--)
 	{
 		x1 = clipit[z].x1; x2 = clipit[z].x2; x21 = x2-x1;
 		y1 = clipit[z].y1; y2 = clipit[z].y2; y21 = y2-y1;
-
+        
 		topu = x21*(y3-y1) - (x3-x1)*y21; if (topu <= 0) continue;
 		if (x21*(*y4-y1) > (*x4-x1)*y21) continue;
 		x43 = *x4-x3; y43 = *y4-y3;
@@ -5899,7 +5899,7 @@
 		if (x43*(y1-y3) > (x1-x3)*y43) continue;
 		if (x43*(y2-y3) <= (x2-x3)*y43) continue;
 		bot = x43*y21 - x21*y43; if (bot == 0) continue;
-
+        
 		cnt = 256;
 		do
 		{
@@ -5908,9 +5908,9 @@
 			ninty = y3 + scale(y43,topu,bot);
 			topu--;
 		} while (x21*(ninty-y1) <= (nintx-x1)*y21);
-
+        
 		if (klabs(x3-nintx)+klabs(y3-ninty) < klabs(x3-*x4)+klabs(y3-*y4))
-			{ *x4 = nintx; *y4 = ninty; hitwall = z; }
+        { *x4 = nintx; *y4 = ninty; hitwall = z; }
 	}
 	return(hitwall);
 }
@@ -5932,30 +5932,30 @@
 	int32_t bsz, dax, day, xoff, yoff, xspan, yspan, cosang, sinang, tilenum;
 	int32_t xrepeat, yrepeat, gx, gy, dx, dy, dasprclipmask, dawalclipmask;
 	int32_t hitwall, cnt, clipyou;
-
+    
 	if (((xvect|yvect) == 0) || (*sectnum < 0)) return(0);
 	retval = 0;
-
+    
 	oxvect = xvect;
 	oyvect = yvect;
-
+    
 	goalx = (*x) + (xvect>>14);
 	goaly = (*y) + (yvect>>14);
-
-
+    
+    
 	clipnum = 0;
-
+    
 	cx = (((*x)+goalx)>>1);
 	cy = (((*y)+goaly)>>1);
-		/* Extra walldist for sprites on sector lines */
+    /* Extra walldist for sprites on sector lines */
 	gx = goalx-(*x); gy = goaly-(*y);
 	rad = nsqrtasm(gx*gx + gy*gy) + MAXCLIPDIST+walldist + 8;
 	xmin = cx-rad; ymin = cy-rad;
 	xmax = cx+rad; ymax = cy+rad;
-
+    
 	dawalclipmask = (cliptype&65535);        /* CLIPMASK0 = 0x00010001 */
 	dasprclipmask = (cliptype>>16);          /* CLIPMASK1 = 0x01000040 */
-
+    
 	clipsectorlist[0] = (*sectnum);
 	clipsectcnt = 0; clipsectnum = 1;
 	do
@@ -5970,16 +5970,16 @@
 			if ((wal->x > xmax) && (wal2->x > xmax)) continue;
 			if ((wal->y < ymin) && (wal2->y < ymin)) continue;
 			if ((wal->y > ymax) && (wal2->y > ymax)) continue;
-
+            
 			x1 = wal->x; y1 = wal->y; x2 = wal2->x; y2 = wal2->y;
-
+            
 			dx = x2-x1; dy = y2-y1;
 			if (dx*((*y)-y1) < ((*x)-x1)*dy) continue;  /* If wall's not facing you */
-
+            
 			if (dx > 0) dax = dx*(ymin-y1); else dax = dx*(ymax-y1);
 			if (dy > 0) day = dy*(xmax-x1); else day = dy*(xmin-x1);
 			if (dax >= day) continue;
-
+            
 			clipyou = 0;
 			if ((wal->nextsector < 0) || (wal->cstat&dawalclipmask)) clipyou = 1;
 			else if (editstatus == 0)
@@ -5988,7 +5988,7 @@
 					dax = *x, day = *y;
 				daz = getflorzofslope((short)dasect,dax,day);
 				daz2 = getflorzofslope(wal->nextsector,dax,day);
-
+                
 				sec2 = &sector[wal->nextsector];
 				if (daz2 < daz-(1<<8))
 					if ((sec2->floorstat&1) == 0)
@@ -6002,10 +6002,10 @@
 							if ((*z) <= daz2+(ceildist-1)) clipyou = 1;
 				}
 			}
-
+            
 			if (clipyou)
 			{
-					/* Add 2 boxes at endpoints */
+                /* Add 2 boxes at endpoints */
 				bsz = walldist; if (gx < 0) bsz = -bsz;
 				addclipline(x1-bsz,y1-bsz,x1-bsz,y1+bsz,(short)j+32768);
 				addclipline(x2-bsz,y2-bsz,x2-bsz,y2+bsz,(short)j+32768);
@@ -6012,7 +6012,7 @@
 				bsz = walldist; if (gy < 0) bsz = -bsz;
 				addclipline(x1+bsz,y1-bsz,x1-bsz,y1-bsz,(short)j+32768);
 				addclipline(x2+bsz,y2-bsz,x2-bsz,y2-bsz,(short)j+32768);
-
+                
 				dax = walldist; if (dy > 0) dax = -dax;
 				day = walldist; if (dx < 0) day = -day;
 				addclipline(x1+dax,y1+day,x2+dax,y2+day,(short)j+32768);
@@ -6024,7 +6024,7 @@
 				if (i < 0) clipsectorlist[clipsectnum++] = wal->nextsector;
 			}
 		}
-
+        
 		for(j=headspritesect[dasect];j>=0;j=nextspritesect[j])
 		{
 			spr = &sprite[j];
@@ -6056,10 +6056,10 @@
 					daz += ceildist; daz2 -= flordist;
 					if (((*z) < daz) && ((*z) > daz2))
 					{
-							/* 
-							 * These lines get the 2 points of the rotated sprite
-							 * Given: (x1, y1) starts out as the center point
-                             */
+                        /*
+                         * These lines get the 2 points of the rotated sprite
+                         * Given: (x1, y1) starts out as the center point
+                         */
                         tilenum = spr->picnum;
 						xoff = (long)((int8_t  )((picanm[tilenum]>>8)&255))+((long)spr->xoffset);
 						if ((cstat&4) > 0) xoff = -xoff;
@@ -6072,7 +6072,7 @@
 						{
 							dax = mulscale14(sintable[(spr->ang+256+512)&2047],walldist);
 							day = mulscale14(sintable[(spr->ang+256)&2047],walldist);
-
+                            
 							if ((x1-(*x))*(y2-(*y)) >= (x2-(*x))*(y1-(*y)))   /* Front */
 							{
 								addclipline(x1+dax,y1+day,x2+day,y2-dax,(short)j+49152);
@@ -6082,12 +6082,12 @@
 								if ((cstat&64) != 0) continue;
 								addclipline(x2-dax,y2-day,x1-day,y1+dax,(short)j+49152);
 							}
-
-								/* Side blocker */
+                            
+                            /* Side blocker */
 							if ((x2-x1)*((*x)-x1) + (y2-y1)*((*y)-y1) < 0)
-								{ addclipline(x1-day,y1+dax,x1+dax,y1+day,(short)j+49152); }
+                            { addclipline(x1-day,y1+dax,x1+dax,y1+day,(short)j+49152); }
 							else if ((x1-x2)*((*x)-x2) + (y1-y2)*((*y)-y2) < 0)
-								{ addclipline(x2+day,y2-dax,x2-dax,y2-day,(short)j+49152); }
+                            { addclipline(x2+day,y2-dax,x2-dax,y2-day,(short)j+49152); }
 						}
 					}
 					break;
@@ -6098,18 +6098,18 @@
 					{
 						if ((cstat&64) != 0)
 							if (((*z) > spr->z) == ((cstat&8)==0)) continue;
-
+                        
 						tilenum = spr->picnum;
 						xoff = (long)((int8_t  )((picanm[tilenum]>>8)&255))+((long)spr->xoffset);
 						yoff = (long)((int8_t  )((picanm[tilenum]>>16)&255))+((long)spr->yoffset);
 						if ((cstat&4) > 0) xoff = -xoff;
 						if ((cstat&8) > 0) yoff = -yoff;
-
+                        
 						k = spr->ang;
 						cosang = sintable[(k+512)&2047]; sinang = sintable[k];
 						xspan = tilesizx[tilenum]; xrepeat = spr->xrepeat;
 						yspan = tilesizy[tilenum]; yrepeat = spr->yrepeat;
-
+                        
 						dax = ((xspan>>1)+xoff)*xrepeat; day = ((yspan>>1)+yoff)*yrepeat;
 						rxi[0] = x1 + dmulscale16(sinang,dax,cosang,day);
 						ryi[0] = y1 + dmulscale16(sinang,day,-cosang,dax);
@@ -6119,10 +6119,10 @@
 						l = yspan*yrepeat;
 						k = -mulscale16(cosang,l); rxi[2] = rxi[1]+k; rxi[3] = rxi[0]+k;
 						k = -mulscale16(sinang,l); ryi[2] = ryi[1]+k; ryi[3] = ryi[0]+k;
-
+                        
 						dax = mulscale14(sintable[(spr->ang-256+512)&2047],walldist);
 						day = mulscale14(sintable[(spr->ang-256)&2047],walldist);
-
+                        
 						if ((rxi[0]-(*x))*(ryi[1]-(*y)) < (rxi[1]-(*x))*(ryi[0]-(*y)))
 						{
 							if (clipinsideboxline(cx,cy,rxi[1],ryi[1],rxi[0],ryi[0],rad) != 0)
@@ -6133,7 +6133,7 @@
 							if (clipinsideboxline(cx,cy,rxi[3],ryi[3],rxi[2],ryi[2],rad) != 0)
 								addclipline(rxi[3]+day,ryi[3]-dax,rxi[2]-dax,ryi[2]-day,(short)j+49152);
 						}
-
+                        
 						if ((rxi[1]-(*x))*(ryi[2]-(*y)) < (rxi[2]-(*x))*(ryi[1]-(*y)))
 						{
 							if (clipinsideboxline(cx,cy,rxi[2],ryi[2],rxi[1],ryi[1],rad) != 0)
@@ -6149,8 +6149,8 @@
 			}
 		}
 	} while (clipsectcnt < clipsectnum);
-
-
+    
+    
 	hitwall = 0;
 	cnt = clipmoveboxtracenum;
 	do
@@ -6164,7 +6164,7 @@
 			if (templong2 > 0)
 			{
 				templong1 = (goalx-intx)*lx + (goaly-inty)*ly;
-
+                
 				if ((klabs(templong1)>>11) < templong2)
 					i = divscale20(templong1,templong2);
 				else
@@ -6172,7 +6172,7 @@
 				goalx = mulscale20(lx,i)+intx;
 				goaly = mulscale20(ly,i)+inty;
 			}
-
+            
 			templong1 = dmulscale6(lx,oxvect,ly,oyvect);
 			for(i=cnt+1;i<=clipmoveboxtracenum;i++)
 			{
@@ -6184,20 +6184,20 @@
 					return(retval);
 				}
 			}
-
+            
 			keepaway(&goalx, &goaly, hitwall);
 			xvect = ((goalx-intx)<<14);
 			yvect = ((goaly-inty)<<14);
-
+            
 			if (cnt == clipmoveboxtracenum) retval = clipobjectval[hitwall];
 			hitwalls[cnt] = hitwall;
 		}
 		cnt--;
-
+        
 		*x = intx;
 		*y = inty;
 	} while (((xvect|yvect) != 0) && (hitwall >= 0) && (cnt > 0));
-
+    
 	for(j=0;j<clipsectnum;j++)
 		if (inside(*x,*y,clipsectorlist[j]) == 1)
 		{
@@ -6204,7 +6204,7 @@
 			*sectnum = clipsectorlist[j];
 			return(retval);
 		}
-
+    
 	*sectnum = -1; templong1 = 0x7fffffff;
 	for(j=numsectors-1;j>=0;j--)
 		if (inside(*x,*y,j) == 1)
@@ -6213,11 +6213,11 @@
 				templong2 = (getceilzofslope((short)j,*x,*y)-(*z));
 			else
 				templong2 = (sector[j].ceilingz-(*z));
-
+            
 			if (templong2 > 0)
 			{
 				if (templong2 < templong1)
-					{ *sectnum = j; templong1 = templong2; }
+                { *sectnum = j; templong1 = templong2; }
 			}
 			else
 			{
@@ -6225,7 +6225,7 @@
 					templong2 = ((*z)-getflorzofslope((short)j,*x,*y));
 				else
 					templong2 = ((*z)-sector[j].floorz);
-
+                
 				if (templong2 <= 0)
 				{
 					*sectnum = j;
@@ -6232,10 +6232,10 @@
 					return(retval);
 				}
 				if (templong2 < templong1)
-					{ *sectnum = j; templong1 = templong2; }
+                { *sectnum = j; templong1 = templong2; }
 			}
 		}
-
+    
 	return(retval);
 }
 
@@ -6250,18 +6250,18 @@
 	int32_t dasprclipmask, dawalclipmask;
 	short startwall, endwall, clipsectcnt;
 	uint8_t  bad2;
-
+    
 	if ((*sectnum) < 0) return(-1);
-
+    
 	dawalclipmask = (cliptype&65535);
 	dasprclipmask = (cliptype>>16);
-
+    
 	k = 32;
 	dir = 1;
 	do
 	{
 		bad = 0;
-
+        
 		clipsectorlist[0] = *sectnum;
 		clipsectcnt = 0; clipsectnum = 1;
 		do
@@ -6271,7 +6271,7 @@
 				startwall = sec->wallptr, endwall = startwall + sec->wallnum;
 			else
 				endwall = sec->wallptr, startwall = endwall + sec->wallnum;
-
+            
 			for(i=startwall,wal=&wall[startwall];i!=endwall;i+=dir,wal+=dir)
 				if (clipinsidebox(*x,*y,i,walldist-4) == 1)
 				{
@@ -6281,9 +6281,9 @@
 					if (j == 0)
 					{
 						sec2 = &sector[wal->nextsector];
-
-
-							/* Find closest point on wall (dax, day) to (*x, *y) */
+                        
+                        
+                        /* Find closest point on wall (dax, day) to (*x, *y) */
 						dax = wall[wal->point2].x-wal->x;
 						day = wall[wal->point2].y-wal->y;
 						daz = dax*((*x)-wal->x) + day*((*y)-wal->y);
@@ -6296,13 +6296,13 @@
 						}
 						dax = wal->x + mulscale30(dax,t);
 						day = wal->y + mulscale30(day,t);
-
-
+                        
+                        
 						daz = getflorzofslope(clipsectorlist[clipsectcnt],dax,day);
 						daz2 = getflorzofslope(wal->nextsector,dax,day);
 						if ((daz2 < daz-(1<<8)) && ((sec2->floorstat&1) == 0))
 							if (*z >= daz2-(flordist-1)) j = 1;
-
+                        
 						daz = getceilzofslope(clipsectorlist[clipsectcnt],dax,day);
 						daz2 = getceilzofslope(wal->nextsector,dax,day);
 						if ((daz2 > daz+(1<<8)) && ((sec2->ceilingstat&1) == 0))
@@ -6330,39 +6330,39 @@
 						if (j < 0) clipsectorlist[clipsectnum++] = wal->nextsector;
 					}
 				}
-
+            
 			clipsectcnt++;
 		} while (clipsectcnt < clipsectnum);
 		dir = -dir;
 	} while (bad != 0);
-
+    
 	return(bad);
 }
 
 /*
-   FCS:  x and y are the new position of the entity that has just moved:
-         lastKnownSector is an hint (the last known sectorID of the entity).
+ FCS:  x and y are the new position of the entity that has just moved:
+ lastKnownSector is an hint (the last known sectorID of the entity).
  
-   Thanks to the "hint", the algorithm check:
-   1. Is (x,y) inside sectors[sectnum].
-   2. Flood in sectnum portal and check again if (x,y) is inside.
-   3. Do a linear search on sectors[sectnum] from 0 to numSectors.
-  
-   Note: Inside uses cross_product and return as soon as the point switch
-         from one side to the other.
+ Thanks to the "hint", the algorithm check:
+ 1. Is (x,y) inside sectors[sectnum].
+ 2. Flood in sectnum portal and check again if (x,y) is inside.
+ 3. Do a linear search on sectors[sectnum] from 0 to numSectors.
+ 
+ Note: Inside uses cross_product and return as soon as the point switch
+ from one side to the other.
  */
 void updatesector(int32_t x, int32_t y, short *lastKnownSector)
 {
 	walltype *wal;
 	int32_t i, j;
-
+    
 	//First check the last sector where (old_x,old_y) was before being updated to (x,y)
-	if (inside(x,y,*lastKnownSector) ) 
+	if (inside(x,y,*lastKnownSector) )
 	{
 		//We found it and (x,y) is still in the same sector: nothing to update !
 		return;
 	}
-
+    
 	// Seems (x,y) moved into an other sector....hopefully one connected via a portal. Let's flood in each portal.
 	if ((*lastKnownSector >= 0) && (*lastKnownSector < numsectors))
 	{
@@ -6381,7 +6381,7 @@
 			j--;
 		} while (j != 0);
 	}
-
+    
 	//Damn that is a BIG move, still cannot find which sector (x,y) belongs to. Let's search via linear search.
 	for(i=numsectors-1;i>=0;i--)
 	{
@@ -6399,7 +6399,7 @@
 void rotatepoint(int32_t xpivot, int32_t ypivot, int32_t x, int32_t y, short daang, int32_t *x2, int32_t *y2)
 {
 	int32_t dacos, dasin;
-
+    
 	dacos = sintable[(daang+2560)&2047];
 	dasin = sintable[(daang+2048)&2047];
 	x -= xpivot;
@@ -6426,7 +6426,7 @@
 {
 	int32_t i, xp1, yp1, xp2=0, yp2, tempy, tempint;
 	uint8_t  mask;
-
+    
 	if (gride > 0)
 	{
 		yp1 = 200-mulscale14(posye+131072,zoome);
@@ -6433,39 +6433,39 @@
 		if (yp1 < 0) yp1 = 0;
 		yp2 = 200-mulscale14(posye-131072,zoome);
 		if (yp2 >= ydim16) yp2 = ydim16-1;
-
+        
 		if ((yp1 < ydim16) && (yp2 >= 0) && (yp2 >= yp1))
 		{
 			setcolor16(8);
-                        #ifdef PLATFORM_DOS
+#ifdef PLATFORM_DOS
 			koutp(0x3ce,0x8);
-                        #endif
-                        tempint = ((yp1*640+pageoffset)>>3)+(int32_t)_getVideoBase();
+#endif
+            tempint = ((yp1*640+pageoffset)>>3)+(int32_t)_getVideoBase();
 			tempy = yp2-yp1+1;
 			mask = 0;
 			xp1 = 320-mulscale14(posxe+131072,zoome);
-
+            
 			for(i=-131072;i<=131072;i+=(2048>>gride))
 			{
 				xp2 = xp1;
 				xp1 = 320-mulscale14(posxe-i,zoome);
-
+                
 				if (xp1 >= 640) break;
 				if (xp1 >= 0)
 				{
-
-                    #if (defined PLATFORM_DOS)
-	    				if ((xp1|7) != (xp2|7))
-    					{
-		    				koutp(0x3cf,mask);
-			    			if (((xp2>>3) >= 0) && ((xp2>>3) < 80))
-				    			vlin16first(templong+(xp2>>3),tempy);
-					    	mask = 0;
-    					}
-    					mask |= pow2char[(xp1&7)^7];
-                    #else
-                        drawline16(xp1, 0, xp1, tempy, 8);
-                    #endif
+                    
+#if (defined PLATFORM_DOS)
+                    if ((xp1|7) != (xp2|7))
+                    {
+                        koutp(0x3cf,mask);
+                        if (((xp2>>3) >= 0) && ((xp2>>3) < 80))
+                            vlin16first(templong+(xp2>>3),tempy);
+                        mask = 0;
+                    }
+                    mask |= pow2char[(xp1&7)^7];
+#else
+                    drawline16(xp1, 0, xp1, tempy, 8);
+#endif
 				}
 			}
 			if ((i >= 131072) && (xp1 < 640))
@@ -6481,7 +6481,7 @@
 #endif
 			}
 		}
-
+        
 		xp1 = mulscale14(posxe+131072,zoome);
 		xp2 = mulscale14(posxe-131072,zoome);
 		tempy = 0x80000000;
@@ -6505,18 +6505,18 @@
 	walltype *wal;
 	int32_t i, j, xp1, yp1, xp2, yp2, tempint;
 	uint8_t  col;
-
+    
 	if (qsetmode == 200) return;
-
+    
 	if (editstatus == 0)
 	{
 		faketimerhandler();
 		clear2dscreen();
-
+        
 		faketimerhandler();
 		draw2dgrid(posxe,posye,ange,zoome,gride);
 	}
-
+    
 	faketimerhandler();
 	for(i=numwalls-1,wal=&wall[i];i>=0;i--,wal--)
 	{
@@ -6532,7 +6532,7 @@
 			j = wal->nextwall;
 			if ((j >= 0) && (i > j)) continue;
 		}
-
+        
 		if (j < 0)
 		{
 			col = 7;
@@ -6545,12 +6545,12 @@
 			if ((i == linehighlight) || ((linehighlight >= 0) && (i == wall[linehighlight].nextwall)))
 				col += ((numframes&2)<<2);
 		}
-
+        
 		xp1 = mulscale14(wal->x-posxe,zoome);
 		yp1 = mulscale14(wal->y-posye,zoome);
 		xp2 = mulscale14(wall[wal->point2].x-posxe,zoome);
 		yp2 = mulscale14(wall[wal->point2].y-posye,zoome);
-
+        
 		if ((wal->cstat&64) > 0)
 		{
 			if (klabs(xp2-xp1) >= klabs(yp2-yp1))
@@ -6566,7 +6566,7 @@
 			col += 8;
 		}
 		drawline16(320+xp1,200+yp1,320+xp2,200+yp2,col);
-
+        
 		if ((zoome >= 256) && (editstatus == 1))
 			if (((320+xp1) >= 2) && ((320+xp1) <= 637))
 				if (((200+yp1) >= 2) && ((200+yp1) <= ydim16-3))
@@ -6578,28 +6578,28 @@
 						if (show2dwall[i>>3]&pow2char[i&7])
 							col += ((numframes&2)<<2);
 					}
-
-
+                    
+                    
 					tempint = (mul5(200+yp1)<<7)+(320+xp1);
-
+                    
 					setcolor16((long)col);
-
+                    
 					drawpixel16(tempint-2-1280);
 					drawpixel16(tempint-1-1280);
 					drawpixel16(tempint+0-1280);
 					drawpixel16(tempint+1-1280);
 					drawpixel16(tempint+2-1280);
-
+                    
 					drawpixel16(tempint-2+1280);
 					drawpixel16(tempint-1+1280);
 					drawpixel16(tempint+0+1280);
 					drawpixel16(tempint+1+1280);
 					drawpixel16(tempint+2+1280);
-
+                    
 					drawpixel16(tempint-2-640);
 					drawpixel16(tempint-2+0);
 					drawpixel16(tempint-2+640);
-
+                    
 					drawpixel16(tempint+2-640);
 					drawpixel16(tempint+2+0);
 					drawpixel16(tempint+2+640);
@@ -6606,7 +6606,7 @@
 				}
 	}
 	faketimerhandler();
-
+    
 	if ((zoome >= 256) || (editstatus == 0))
 		for(i=0;i<numsectors;i++)
 			for(j=headspritesect[i];j>=0;j=nextspritesect[j])
@@ -6624,41 +6624,41 @@
 								col += ((numframes&2)<<2);
 						}
 					}
-
+                    
 					xp1 = mulscale14(sprite[j].x-posxe,zoome);
 					yp1 = mulscale14(sprite[j].y-posye,zoome);
 					if (((320+xp1) >= 2) && ((320+xp1) <= 637))
 						if (((200+yp1) >= 2) && ((200+yp1) <= ydim16-3))
 						{
-
+                            
 							tempint = (mul5(200+yp1)<<7)+(320+xp1);
-
-
+                            
+                            
 							setcolor16((long)col);
 							drawpixel16(tempint-1-1280);
 							drawpixel16(tempint+0-1280);
 							drawpixel16(tempint+1-1280);
-
+                            
 							drawpixel16(tempint-1+1280);
 							drawpixel16(tempint+0+1280);
 							drawpixel16(tempint+1+1280);
-
+                            
 							drawpixel16(tempint-2-640);
 							drawpixel16(tempint-2+0);
 							drawpixel16(tempint-2+640);
-
+                            
        						drawpixel16(tempint+2-640);
 							drawpixel16(tempint+2+0);
 							drawpixel16(tempint+2+640);
-
+                            
 							drawpixel16(tempint+1+640);
 							drawpixel16(tempint-1+640);
 							drawpixel16(tempint+1-640);
 							drawpixel16(tempint-1-640);
-
+                            
 							xp2 = mulscale11(sintable[(sprite[j].ang+2560)&2047],zoome) / 768;
 							yp2 = mulscale11(sintable[(sprite[j].ang+2048)&2047],zoome) / 768;
-
+                            
 							if ((sprite[j].cstat&256) > 0)
 							{
 								if (((sprite[j].ang+256)&512) == 0)
@@ -6676,7 +6676,7 @@
 							drawline16(320+xp1,200+yp1,320+xp1+xp2,200+yp1+yp2,col);
 						}
 				}
-
+    
 	faketimerhandler();
 	xp1 = mulscale11(sintable[(ange+2560)&2047],zoome) / 768; /* Draw white arrow */
 	yp1 = mulscale11(sintable[(ange+2048)&2047],zoome) / 768;
@@ -6700,12 +6700,12 @@
 {
 	int32_t stx, i, x, y, charxsiz;
 	uint8_t  *fontptr, *letptr, *ptr;
-
+    
 	stx = xpos;
-
+    
 	if (fontsize) { fontptr = smalltextfont; charxsiz = 4; }
-				else { fontptr = textfont; charxsiz = 8; }
-
+    else { fontptr = textfont; charxsiz = 8; }
+    
 	for(i=0;name[i];i++)
 	{
 		letptr = &fontptr[name[i]<<3];
@@ -6723,7 +6723,7 @@
 		}
 		stx += charxsiz;
 	}
-
+    
     if (should_update)
         _updateScreenRect(xpos, ypos, charxsiz * i, 8);
 }
@@ -6748,1414 +6748,1414 @@
 	uint8_t  filename[2048];
 	FILE *pFile;
 #else
-int krand()
-{
+    int krand()
+    {
 #endif
-
-	randomseed = (randomseed*27584621)+1;
-
+        
+        randomseed = (randomseed*27584621)+1;
+        
 #ifdef  DBGRECORD
-	for(i=0; file[i]; i++)
-	{
-		if(file[i]=='\\')
-		{
-			i++;
-			k = 0;
-		}
-		filename[k++]=(file[i]=='.')?0:file[i];
-	}
-	// printf("%-5d %-8s %-8x\n", line, filename, randomseed);
-	pFile = fopen("c:\\temp\\krand.txt","a");
-	fprintf(pFile,"%-4d %-5s %-6x\n", line, filename, randomseed);
-	fclose(pFile);
+        for(i=0; file[i]; i++)
+        {
+            if(file[i]=='\\')
+            {
+                i++;
+                k = 0;
+            }
+            filename[k++]=(file[i]=='.')?0:file[i];
+        }
+        // printf("%-5d %-8s %-8x\n", line, filename, randomseed);
+        pFile = fopen("c:\\temp\\krand.txt","a");
+        fprintf(pFile,"%-4d %-5s %-6x\n", line, filename, randomseed);
+        fclose(pFile);
 #endif
-
-	return(((uint32_t )randomseed)>>16);
-}
-
-
-void getzrange(int32_t x, int32_t y, int32_t z, short sectnum,
-               int32_t *ceilz, int32_t *ceilhit, int32_t *florz, int32_t *florhit,
-               int32_t walldist, uint32_t  cliptype)
-{
-	sectortype *sec;
-	walltype *wal, *wal2;
-	spritetype *spr;
-	int32_t clipsectcnt, startwall, endwall, tilenum, xoff, yoff, dax, day;
-	int32_t xmin, ymin, xmax, ymax, i, j, k, l, daz, daz2, dx, dy;
-	int32_t x1, y1, x2, y2, x3, y3, x4, y4, ang, cosang, sinang;
-	int32_t xspan, yspan, xrepeat, yrepeat, dasprclipmask, dawalclipmask;
-	short cstat;
-	uint8_t  clipyou;
-
-	if (sectnum < 0)
-	{
-		*ceilz = 0x80000000; *ceilhit = -1;
-		*florz = 0x7fffffff; *florhit = -1;
-		return;
-	}
-
+        
+        return(((uint32_t )randomseed)>>16);
+    }
+    
+    
+    void getzrange(int32_t x, int32_t y, int32_t z, short sectnum,
+                   int32_t *ceilz, int32_t *ceilhit, int32_t *florz, int32_t *florhit,
+                   int32_t walldist, uint32_t  cliptype)
+    {
+        sectortype *sec;
+        walltype *wal, *wal2;
+        spritetype *spr;
+        int32_t clipsectcnt, startwall, endwall, tilenum, xoff, yoff, dax, day;
+        int32_t xmin, ymin, xmax, ymax, i, j, k, l, daz, daz2, dx, dy;
+        int32_t x1, y1, x2, y2, x3, y3, x4, y4, ang, cosang, sinang;
+        int32_t xspan, yspan, xrepeat, yrepeat, dasprclipmask, dawalclipmask;
+        short cstat;
+        uint8_t  clipyou;
+        
+        if (sectnum < 0)
+        {
+            *ceilz = 0x80000000; *ceilhit = -1;
+            *florz = 0x7fffffff; *florhit = -1;
+            return;
+        }
+        
 		/* Extra walldist for sprites on sector lines */
-	i = walldist+MAXCLIPDIST+1;
-	xmin = x-i; ymin = y-i;
-	xmax = x+i; ymax = y+i;
-
-	getzsofslope(sectnum,x,y,ceilz,florz);
-	*ceilhit = sectnum+16384; *florhit = sectnum+16384;
-
-	dawalclipmask = (cliptype&65535);
-	dasprclipmask = (cliptype>>16);
-
-	clipsectorlist[0] = sectnum;
-	clipsectcnt = 0; clipsectnum = 1;
-
-	do  /* Collect sectors inside your square first */
-	{
-		sec = &sector[clipsectorlist[clipsectcnt]];
-		startwall = sec->wallptr; endwall = startwall + sec->wallnum;
-		for(j=startwall,wal=&wall[startwall];j<endwall;j++,wal++)
-		{
-			k = wal->nextsector;
-			if (k >= 0)
-			{
-				wal2 = &wall[wal->point2];
-				x1 = wal->x; x2 = wal2->x;
-				if ((x1 < xmin) && (x2 < xmin)) continue;
-				if ((x1 > xmax) && (x2 > xmax)) continue;
-				y1 = wal->y; y2 = wal2->y;
-				if ((y1 < ymin) && (y2 < ymin)) continue;
-				if ((y1 > ymax) && (y2 > ymax)) continue;
-
-				dx = x2-x1; dy = y2-y1;
-				if (dx*(y-y1) < (x-x1)*dy) continue; /* back */
-				if (dx > 0) dax = dx*(ymin-y1); else dax = dx*(ymax-y1);
-				if (dy > 0) day = dy*(xmax-x1); else day = dy*(xmin-x1);
-				if (dax >= day) continue;
-
-				if (wal->cstat&dawalclipmask) continue;
-				sec = &sector[k];
-				if (editstatus == 0)
-				{
-					if (((sec->ceilingstat&1) == 0) && (z <= sec->ceilingz+(3<<8))) continue;
-					if (((sec->floorstat&1) == 0) && (z >= sec->floorz-(3<<8))) continue;
-				}
-
-				for(i=clipsectnum-1;i>=0;i--) if (clipsectorlist[i] == k) break;
-				if (i < 0) clipsectorlist[clipsectnum++] = k;
-
-				if ((x1 < xmin+MAXCLIPDIST) && (x2 < xmin+MAXCLIPDIST)) continue;
-				if ((x1 > xmax-MAXCLIPDIST) && (x2 > xmax-MAXCLIPDIST)) continue;
-				if ((y1 < ymin+MAXCLIPDIST) && (y2 < ymin+MAXCLIPDIST)) continue;
-				if ((y1 > ymax-MAXCLIPDIST) && (y2 > ymax-MAXCLIPDIST)) continue;
-				if (dx > 0) dax += dx*MAXCLIPDIST; else dax -= dx*MAXCLIPDIST;
-				if (dy > 0) day -= dy*MAXCLIPDIST; else day += dy*MAXCLIPDIST;
-				if (dax >= day) continue;
-
+        i = walldist+MAXCLIPDIST+1;
+        xmin = x-i; ymin = y-i;
+        xmax = x+i; ymax = y+i;
+        
+        getzsofslope(sectnum,x,y,ceilz,florz);
+        *ceilhit = sectnum+16384; *florhit = sectnum+16384;
+        
+        dawalclipmask = (cliptype&65535);
+        dasprclipmask = (cliptype>>16);
+        
+        clipsectorlist[0] = sectnum;
+        clipsectcnt = 0; clipsectnum = 1;
+        
+        do  /* Collect sectors inside your square first */
+        {
+            sec = &sector[clipsectorlist[clipsectcnt]];
+            startwall = sec->wallptr; endwall = startwall + sec->wallnum;
+            for(j=startwall,wal=&wall[startwall];j<endwall;j++,wal++)
+            {
+                k = wal->nextsector;
+                if (k >= 0)
+                {
+                    wal2 = &wall[wal->point2];
+                    x1 = wal->x; x2 = wal2->x;
+                    if ((x1 < xmin) && (x2 < xmin)) continue;
+                    if ((x1 > xmax) && (x2 > xmax)) continue;
+                    y1 = wal->y; y2 = wal2->y;
+                    if ((y1 < ymin) && (y2 < ymin)) continue;
+                    if ((y1 > ymax) && (y2 > ymax)) continue;
+                    
+                    dx = x2-x1; dy = y2-y1;
+                    if (dx*(y-y1) < (x-x1)*dy) continue; /* back */
+                    if (dx > 0) dax = dx*(ymin-y1); else dax = dx*(ymax-y1);
+                    if (dy > 0) day = dy*(xmax-x1); else day = dy*(xmin-x1);
+                    if (dax >= day) continue;
+                    
+                    if (wal->cstat&dawalclipmask) continue;
+                    sec = &sector[k];
+                    if (editstatus == 0)
+                    {
+                        if (((sec->ceilingstat&1) == 0) && (z <= sec->ceilingz+(3<<8))) continue;
+                        if (((sec->floorstat&1) == 0) && (z >= sec->floorz-(3<<8))) continue;
+                    }
+                    
+                    for(i=clipsectnum-1;i>=0;i--) if (clipsectorlist[i] == k) break;
+                    if (i < 0) clipsectorlist[clipsectnum++] = k;
+                    
+                    if ((x1 < xmin+MAXCLIPDIST) && (x2 < xmin+MAXCLIPDIST)) continue;
+                    if ((x1 > xmax-MAXCLIPDIST) && (x2 > xmax-MAXCLIPDIST)) continue;
+                    if ((y1 < ymin+MAXCLIPDIST) && (y2 < ymin+MAXCLIPDIST)) continue;
+                    if ((y1 > ymax-MAXCLIPDIST) && (y2 > ymax-MAXCLIPDIST)) continue;
+                    if (dx > 0) dax += dx*MAXCLIPDIST; else dax -= dx*MAXCLIPDIST;
+                    if (dy > 0) day -= dy*MAXCLIPDIST; else day += dy*MAXCLIPDIST;
+                    if (dax >= day) continue;
+                    
 					/* It actually got here, through all the continue's! */
-				getzsofslope((short)k,x,y,&daz,&daz2);
-				if (daz > *ceilz) { *ceilz = daz; *ceilhit = k+16384; }
-				if (daz2 < *florz) { *florz = daz2; *florhit = k+16384; }
-			}
-		}
-		clipsectcnt++;
-	} while (clipsectcnt < clipsectnum);
-
-	for(i=0;i<clipsectnum;i++)
-	{
-		for(j=headspritesect[clipsectorlist[i]];j>=0;j=nextspritesect[j])
-		{
-			spr = &sprite[j];
-			cstat = spr->cstat;
-			if (cstat&dasprclipmask)
-			{
-				x1 = spr->x; y1 = spr->y;
-
-				clipyou = 0;
-				switch(cstat&48)
-				{
-					case 0:
-						k = walldist+(spr->clipdist<<2)+1;
-						if ((klabs(x1-x) <= k) && (klabs(y1-y) <= k))
-						{
-							daz = spr->z;
-							k = ((tilesizy[spr->picnum]*spr->yrepeat)<<1);
-							if (cstat&128) daz += k;
-							if (picanm[spr->picnum]&0x00ff0000) daz -= ((long)((int8_t  )((picanm[spr->picnum]>>16)&255))*spr->yrepeat<<2);
-							daz2 = daz - (k<<1);
-							clipyou = 1;
-						}
-						break;
-					case 16:
-						tilenum = spr->picnum;
-						xoff = (long)((int8_t  )((picanm[tilenum]>>8)&255))+((long)spr->xoffset);
-						if ((cstat&4) > 0) xoff = -xoff;
-						k = spr->ang; l = spr->xrepeat;
-						dax = sintable[k&2047]*l; day = sintable[(k+1536)&2047]*l;
-						l = tilesizx[tilenum]; k = (l>>1)+xoff;
-						x1 -= mulscale16(dax,k); x2 = x1+mulscale16(dax,l);
-						y1 -= mulscale16(day,k); y2 = y1+mulscale16(day,l);
-						if (clipinsideboxline(x,y,x1,y1,x2,y2,walldist+1) != 0)
-						{
-							daz = spr->z; k = ((tilesizy[spr->picnum]*spr->yrepeat)<<1);
-							if (cstat&128) daz += k;
-							if (picanm[spr->picnum]&0x00ff0000) daz -= ((long)((int8_t  )((picanm[spr->picnum]>>16)&255))*spr->yrepeat<<2);
-							daz2 = daz-(k<<1);
-							clipyou = 1;
-						}
-						break;
-					case 32:
-						daz = spr->z; daz2 = daz;
-
-						if ((cstat&64) != 0)
-							if ((z > daz) == ((cstat&8)==0)) continue;
-
-						tilenum = spr->picnum;
-						xoff = (long)((int8_t  )((picanm[tilenum]>>8)&255))+((long)spr->xoffset);
-						yoff = (long)((int8_t  )((picanm[tilenum]>>16)&255))+((long)spr->yoffset);
-						if ((cstat&4) > 0) xoff = -xoff;
-						if ((cstat&8) > 0) yoff = -yoff;
-
-						ang = spr->ang;
-						cosang = sintable[(ang+512)&2047]; sinang = sintable[ang];
-						xspan = tilesizx[tilenum]; xrepeat = spr->xrepeat;
-						yspan = tilesizy[tilenum]; yrepeat = spr->yrepeat;
-
-						dax = ((xspan>>1)+xoff)*xrepeat; day = ((yspan>>1)+yoff)*yrepeat;
-						x1 += dmulscale16(sinang,dax,cosang,day)-x;
-						y1 += dmulscale16(sinang,day,-cosang,dax)-y;
-						l = xspan*xrepeat;
-						x2 = x1 - mulscale16(sinang,l);
-						y2 = y1 + mulscale16(cosang,l);
-						l = yspan*yrepeat;
-						k = -mulscale16(cosang,l); x3 = x2+k; x4 = x1+k;
-						k = -mulscale16(sinang,l); y3 = y2+k; y4 = y1+k;
-
-						dax = mulscale14(sintable[(spr->ang-256+512)&2047],walldist+4);
-						day = mulscale14(sintable[(spr->ang-256)&2047],walldist+4);
-						x1 += dax; x2 -= day; x3 -= dax; x4 += day;
-						y1 += day; y2 += dax; y3 -= day; y4 -= dax;
-
-						if ((y1^y2) < 0)
-						{
-							if ((x1^x2) < 0) clipyou ^= (x1*y2<x2*y1)^(y1<y2);
-							else if (x1 >= 0) clipyou ^= 1;
-						}
-						if ((y2^y3) < 0)
-						{
-							if ((x2^x3) < 0) clipyou ^= (x2*y3<x3*y2)^(y2<y3);
-							else if (x2 >= 0) clipyou ^= 1;
-						}
-						if ((y3^y4) < 0)
-						{
-							if ((x3^x4) < 0) clipyou ^= (x3*y4<x4*y3)^(y3<y4);
-							else if (x3 >= 0) clipyou ^= 1;
-						}
-						if ((y4^y1) < 0)
-						{
-							if ((x4^x1) < 0) clipyou ^= (x4*y1<x1*y4)^(y4<y1);
-							else if (x4 >= 0) clipyou ^= 1;
-						}
-						break;
-				}
-
-				if (clipyou != 0)
-				{
-					if ((z > daz) && (daz > *ceilz)) { *ceilz = daz; *ceilhit = j+49152; }
-					if ((z < daz2) && (daz2 < *florz)) { *florz = daz2; *florhit = j+49152; }
-				}
-			}
-		}
-	}
-}
-
-
-void setview(int32_t x1, int32_t y1, int32_t x2, int32_t y2)
-{
-	int32_t i;
-
-	windowx1 = x1; wx1 = (x1<<12);
-	windowy1 = y1; wy1 = (y1<<12);
-	windowx2 = x2; wx2 = ((x2+1)<<12);
-	windowy2 = y2; wy2 = ((y2+1)<<12);
-
-	xdimen = (x2-x1)+1; halfxdimen = (xdimen>>1);
-	xdimenrecip = divscale32(1L,xdimen);
-	ydimen = (y2-y1)+1;
-
-	setaspect(65536L,(long)divscale16(ydim*320L,xdim*200L));
-
-	for(i=0;i<windowx1;i++) { startumost[i] = 1, startdmost[i] = 0; }
-	for(i=windowx1;i<=windowx2;i++)
+                    getzsofslope((short)k,x,y,&daz,&daz2);
+                    if (daz > *ceilz) { *ceilz = daz; *ceilhit = k+16384; }
+                    if (daz2 < *florz) { *florz = daz2; *florhit = k+16384; }
+                }
+            }
+            clipsectcnt++;
+        } while (clipsectcnt < clipsectnum);
+        
+        for(i=0;i<clipsectnum;i++)
+        {
+            for(j=headspritesect[clipsectorlist[i]];j>=0;j=nextspritesect[j])
+            {
+                spr = &sprite[j];
+                cstat = spr->cstat;
+                if (cstat&dasprclipmask)
+                {
+                    x1 = spr->x; y1 = spr->y;
+                    
+                    clipyou = 0;
+                    switch(cstat&48)
+                    {
+                        case 0:
+                            k = walldist+(spr->clipdist<<2)+1;
+                            if ((klabs(x1-x) <= k) && (klabs(y1-y) <= k))
+                            {
+                                daz = spr->z;
+                                k = ((tilesizy[spr->picnum]*spr->yrepeat)<<1);
+                                if (cstat&128) daz += k;
+                                if (picanm[spr->picnum]&0x00ff0000) daz -= ((long)((int8_t  )((picanm[spr->picnum]>>16)&255))*spr->yrepeat<<2);
+                                daz2 = daz - (k<<1);
+                                clipyou = 1;
+                            }
+                            break;
+                        case 16:
+                            tilenum = spr->picnum;
+                            xoff = (long)((int8_t  )((picanm[tilenum]>>8)&255))+((long)spr->xoffset);
+                            if ((cstat&4) > 0) xoff = -xoff;
+                            k = spr->ang; l = spr->xrepeat;
+                            dax = sintable[k&2047]*l; day = sintable[(k+1536)&2047]*l;
+                            l = tilesizx[tilenum]; k = (l>>1)+xoff;
+                            x1 -= mulscale16(dax,k); x2 = x1+mulscale16(dax,l);
+                            y1 -= mulscale16(day,k); y2 = y1+mulscale16(day,l);
+                            if (clipinsideboxline(x,y,x1,y1,x2,y2,walldist+1) != 0)
+                            {
+                                daz = spr->z; k = ((tilesizy[spr->picnum]*spr->yrepeat)<<1);
+                                if (cstat&128) daz += k;
+                                if (picanm[spr->picnum]&0x00ff0000) daz -= ((long)((int8_t  )((picanm[spr->picnum]>>16)&255))*spr->yrepeat<<2);
+                                daz2 = daz-(k<<1);
+                                clipyou = 1;
+                            }
+                            break;
+                        case 32:
+                            daz = spr->z; daz2 = daz;
+                            
+                            if ((cstat&64) != 0)
+                                if ((z > daz) == ((cstat&8)==0)) continue;
+                            
+                            tilenum = spr->picnum;
+                            xoff = (long)((int8_t  )((picanm[tilenum]>>8)&255))+((long)spr->xoffset);
+                            yoff = (long)((int8_t  )((picanm[tilenum]>>16)&255))+((long)spr->yoffset);
+                            if ((cstat&4) > 0) xoff = -xoff;
+                            if ((cstat&8) > 0) yoff = -yoff;
+                            
+                            ang = spr->ang;
+                            cosang = sintable[(ang+512)&2047]; sinang = sintable[ang];
+                            xspan = tilesizx[tilenum]; xrepeat = spr->xrepeat;
+                            yspan = tilesizy[tilenum]; yrepeat = spr->yrepeat;
+                            
+                            dax = ((xspan>>1)+xoff)*xrepeat; day = ((yspan>>1)+yoff)*yrepeat;
+                            x1 += dmulscale16(sinang,dax,cosang,day)-x;
+                            y1 += dmulscale16(sinang,day,-cosang,dax)-y;
+                            l = xspan*xrepeat;
+                            x2 = x1 - mulscale16(sinang,l);
+                            y2 = y1 + mulscale16(cosang,l);
+                            l = yspan*yrepeat;
+                            k = -mulscale16(cosang,l); x3 = x2+k; x4 = x1+k;
+                            k = -mulscale16(sinang,l); y3 = y2+k; y4 = y1+k;
+                            
+                            dax = mulscale14(sintable[(spr->ang-256+512)&2047],walldist+4);
+                            day = mulscale14(sintable[(spr->ang-256)&2047],walldist+4);
+                            x1 += dax; x2 -= day; x3 -= dax; x4 += day;
+                            y1 += day; y2 += dax; y3 -= day; y4 -= dax;
+                            
+                            if ((y1^y2) < 0)
+                            {
+                                if ((x1^x2) < 0) clipyou ^= (x1*y2<x2*y1)^(y1<y2);
+                                else if (x1 >= 0) clipyou ^= 1;
+                            }
+                            if ((y2^y3) < 0)
+                            {
+                                if ((x2^x3) < 0) clipyou ^= (x2*y3<x3*y2)^(y2<y3);
+                                else if (x2 >= 0) clipyou ^= 1;
+                            }
+                            if ((y3^y4) < 0)
+                            {
+                                if ((x3^x4) < 0) clipyou ^= (x3*y4<x4*y3)^(y3<y4);
+                                else if (x3 >= 0) clipyou ^= 1;
+                            }
+                            if ((y4^y1) < 0)
+                            {
+                                if ((x4^x1) < 0) clipyou ^= (x4*y1<x1*y4)^(y4<y1);
+                                else if (x4 >= 0) clipyou ^= 1;
+                            }
+                            break;
+                    }
+                    
+                    if (clipyou != 0)
+                    {
+                        if ((z > daz) && (daz > *ceilz)) { *ceilz = daz; *ceilhit = j+49152; }
+                        if ((z < daz2) && (daz2 < *florz)) { *florz = daz2; *florhit = j+49152; }
+                    }
+                }
+            }
+        }
+    }
+    
+    
+    void setview(int32_t x1, int32_t y1, int32_t x2, int32_t y2)
+    {
+        int32_t i;
+        
+        windowx1 = x1; wx1 = (x1<<12);
+        windowy1 = y1; wy1 = (y1<<12);
+        windowx2 = x2; wx2 = ((x2+1)<<12);
+        windowy2 = y2; wy2 = ((y2+1)<<12);
+        
+        xdimen = (x2-x1)+1; halfxdimen = (xdimen>>1);
+        xdimenrecip = divscale32(1L,xdimen);
+        ydimen = (y2-y1)+1;
+        
+        setaspect(65536L,(long)divscale16(ydim*320L,xdim*200L));
+        
+        for(i=0;i<windowx1;i++) { startumost[i] = 1, startdmost[i] = 0; }
+        for(i=windowx1;i<=windowx2;i++)
 		{ startumost[i] = windowy1, startdmost[i] = windowy2+1; }
-	for(i=windowx2+1;i<xdim;i++) { startumost[i] = 1, startdmost[i] = 0; }
-
-	viewoffset = windowy1*bytesperline + windowx1;
-
-	if ((stereomode) || (vidoption == 6))
-	{
-		ostereopixelwidth = stereopixelwidth;
-		xdimen = (windowx2-windowx1+1)+(stereopixelwidth<<1); halfxdimen = (xdimen>>1);
-		xdimenrecip = divscale32(1L,xdimen);
-		setaspect((long)divscale16(xdimen,windowx2-windowx1+1),yxaspect);
-	}
-}
-
-
-void setaspect(int32_t daxrange, int32_t daaspect)
-{
-	viewingrange = daxrange;
-	viewingrangerecip = divscale32(1L,daxrange);
-
-	yxaspect = daaspect;
-	xyaspect = divscale32(1,yxaspect);
-	xdimenscale = scale(xdimen,yxaspect,320);
-	xdimscale = scale(320,xyaspect,xdimen);
-}
-
-
-void flushperms(void)
-{
-	permhead = permtail = 0;
-}
-
-// Render a sprite on screen. This is used by the Engine but also the Game module
-// when drawing the HUD or the Weapon held by the player !!!
-void rotatesprite(int32_t sx, int32_t sy, int32_t z, short a, short picnum,
-                  int8_t dashade, uint8_t  dapalnum, uint8_t  dastat,
-                  int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2)
-{
-	int32_t i;
-	permfifotype *per, *per2;
-
-	if ((cx1 > cx2) || (cy1 > cy2)) return;
-	if (z <= 16) return;
-	if (picanm[picnum]&192) picnum += animateoffs(picnum,(short)0xc000);
-	if ((tilesizx[picnum] <= 0) || (tilesizy[picnum] <= 0)) return;
-
-	if (((dastat&128) == 0) || (numpages < 2) || (beforedrawrooms != 0))
-		dorotatesprite(sx,sy,z,a,picnum,dashade,dapalnum,dastat,cx1,cy1,cx2,cy2);
-
-	if ((dastat&64) && (cx1 <= 0) && (cy1 <= 0) && (cx2 >= xdim-1) && (cy2 >= ydim-1) &&
-		 (sx == (160<<16)) && (sy == (100<<16)) && (z == 65536L) && (a == 0) && ((dastat&1) == 0))
-		permhead = permtail = 0;
-
-	if ((dastat&128) == 0) return;
-	if (numpages >= 2)
-	{
-		per = &permfifo[permhead];
-		per->sx = sx; per->sy = sy; per->z = z; per->a = a;
-		per->picnum = picnum;
-		per->dashade = dashade; per->dapalnum = dapalnum;
-		per->dastat = dastat;
-		per->pagesleft = numpages+((beforedrawrooms&1)<<7);
-		per->cx1 = cx1; per->cy1 = cy1; per->cx2 = cx2; per->cy2 = cy2;
-
-			/* Would be better to optimize out true bounding boxes */
-		if (dastat&64)  /* If non-masking write, checking for overlapping cases */
-		{
-			for(i=permtail;i!=permhead;i=((i+1)&(MAXPERMS-1)))
-			{
-				per2 = &permfifo[i];
-				if ((per2->pagesleft&127) == 0) continue;
-				if (per2->sx != per->sx) continue;
-				if (per2->sy != per->sy) continue;
-				if (per2->z != per->z) continue;
-				if (per2->a != per->a) continue;
-				if (tilesizx[per2->picnum] > tilesizx[per->picnum]) continue;
-				if (tilesizy[per2->picnum] > tilesizy[per->picnum]) continue;
-				if (per2->cx1 < per->cx1) continue;
-				if (per2->cy1 < per->cy1) continue;
-				if (per2->cx2 > per->cx2) continue;
-				if (per2->cy2 > per->cy2) continue;
-				per2->pagesleft = 0;
-			}
-			if ((per->z == 65536) && (per->a == 0))
-				for(i=permtail;i!=permhead;i=((i+1)&(MAXPERMS-1)))
-				{
-					per2 = &permfifo[i];
-					if ((per2->pagesleft&127) == 0) continue;
-					if (per2->z != 65536) continue;
-					if (per2->a != 0) continue;
-					if (per2->cx1 < per->cx1) continue;
-					if (per2->cy1 < per->cy1) continue;
-					if (per2->cx2 > per->cx2) continue;
-					if (per2->cy2 > per->cy2) continue;
-					if ((per2->sx>>16) < (per->sx>>16)) continue;
-					if ((per2->sy>>16) < (per->sy>>16)) continue;
-					if ((per2->sx>>16)+tilesizx[per2->picnum] > (per->sx>>16)+tilesizx[per->picnum]) continue;
-					if ((per2->sy>>16)+tilesizy[per2->picnum] > (per->sy>>16)+tilesizy[per->picnum]) continue;
-					per2->pagesleft = 0;
-				}
-		}
-
-		permhead = ((permhead+1)&(MAXPERMS-1));
-	}
-}
-
-
-static int getclosestcol(int32_t r, int32_t g, int32_t b)
-{
-	int32_t i, j, k, dist, mindist, retcol;
-	uint8_t  *pal1;
-
-	j = (r>>3)*FASTPALGRIDSIZ*FASTPALGRIDSIZ+(g>>3)*FASTPALGRIDSIZ+(b>>3)+FASTPALGRIDSIZ*FASTPALGRIDSIZ+FASTPALGRIDSIZ+1;
-	mindist = min(rdist[coldist[r&7]+64+8],gdist[coldist[g&7]+64+8]);
-	mindist = min(mindist,bdist[coldist[b&7]+64+8]);
-	mindist++;
-
-	r = 64-r; g = 64-g; b = 64-b;
-
-	retcol = -1;
-	for(k=26;k>=0;k--)
-	{
-		i = colscan[k]+j; if ((colhere[i>>3]&pow2char[i&7]) == 0) continue;
-		i = colhead[i];
-		do
-		{
-			pal1 = (uint8_t  *)&palette[i*3];
-			dist = gdist[pal1[1]+g];
-			if (dist < mindist)
-			{
-				dist += rdist[pal1[0]+r];
-				if (dist < mindist)
-				{
-					dist += bdist[pal1[2]+b];
-					if (dist < mindist) { mindist = dist; retcol = i; }
-				}
-			}
-			i = colnext[i];
-		} while (i >= 0);
-	}
-	if (retcol >= 0) return(retcol);
-
-	mindist = 0x7fffffff;
-	pal1 = (uint8_t  *)&palette[768-3];
-	for(i=255;i>=0;i--,pal1-=3)
-	{
-		dist = gdist[pal1[1]+g]; if (dist >= mindist) continue;
-		dist += rdist[pal1[0]+r]; if (dist >= mindist) continue;
-		dist += bdist[pal1[2]+b]; if (dist >= mindist) continue;
-		mindist = dist; retcol = i;
-	}
-	return(retcol);
-}
-
-
-void makepalookup(int32_t palnum, uint8_t  *remapbuf, int8_t r,
-                  int8_t g, int8_t b, uint8_t  dastat)
-{
-	int32_t i, j, dist, palscale;
-	uint8_t  *ptr, *ptr2;
-
-	if (paletteloaded == 0) return;
-
-	if (palookup[palnum] == NULL)
-	{
-			/* Allocate palookup buffer */
-		if ((palookup[palnum] = (uint8_t  *)kkmalloc(numpalookups<<8)) == NULL)
-			allocache((int32_t *)&palookup[palnum],numpalookups<<8,&permanentlock);
-	}
-
-	if (dastat == 0) return;
-	if ((r|g|b|63) != 63) return;
-
-	if ((r|g|b) == 0)
-	{
-		for(i=0;i<256;i++)
-		{
-			ptr = (uint8_t  *)(FP_OFF(palookup[0])+remapbuf[i]);
-			ptr2 = (uint8_t  *)(FP_OFF(palookup[palnum])+i);
-			for(j=0;j<numpalookups;j++)
-				{ *ptr2 = *ptr; ptr += 256; ptr2 += 256; }
-		}
-	}
-	else
-	{
-		ptr2 = (uint8_t  *)FP_OFF(palookup[palnum]);
-		for(i=0;i<numpalookups;i++)
-		{
-			palscale = divscale16(i,numpalookups);
-			for(j=0;j<256;j++)
-			{
-				ptr = (uint8_t  *)&palette[remapbuf[j]*3];
-				*ptr2++ = getclosestcol((long)ptr[0]+mulscale16(r-ptr[0],palscale),
-												(long)ptr[1]+mulscale16(g-ptr[1],palscale),
-												(long)ptr[2]+mulscale16(b-ptr[2],palscale));
-			}
-		}
-	}
-
-	if ((vidoption == 6) && (qsetmode == 200))
-	{
-		for(i=0;i<256;i++)
-		{
-			dist = palette[i*3]*3+palette[i*3+1]*5+palette[i*3+2]*2;
-			ptr = (uint8_t  *)(FP_OFF(palookup[palnum])+i);
-			for(j=0;j<32;j++)
-				ptr[j<<8] = (uint8_t )min(max(mulscale10(dist,32-j),0),15);
-		}
-	}
-}
-
-
-void setbrightness(uint8_t  dabrightness, uint8_t  *dapal)
-{
-	int32_t i, j, k;
-
-	curbrightness = min(max((long)dabrightness,0),15);
-
-	k = 0;
-	if (vidoption == 6)
-	{
-		for(j=0;j<16;j++)
-			for(i=0;i<16;i++)
-			{
-				tempbuf[k++] = britable[curbrightness][j<<2];
-				tempbuf[k++] = 0;
-				tempbuf[k++] = britable[curbrightness][i<<2];
-				tempbuf[k++] = 0;
-			}
-	}
-	else
-	{
-		for(i=0;i<256;i++)
-		{
-			tempbuf[k++] = britable[curbrightness][dapal[i*3+2]];
-			tempbuf[k++] = britable[curbrightness][dapal[i*3+1]];
-			tempbuf[k++] = britable[curbrightness][dapal[i*3+0]];
-			tempbuf[k++] = 0;
-		}
-	}
-
-	VBE_setPalette(0, 256, (uint8_t  *) tempbuf);
-}
-
-//This is only used by drawmapview.
-static void fillpolygon(int32_t npoints)
-{
-	int32_t z, zz, x1, y1, x2, y2, miny, maxy, y, xinc, cnt;
-	int32_t ox, oy, bx, by, p, day1, day2;
-	short *ptr, *ptr2;
-
-	miny = 0x7fffffff; maxy = 0x80000000;
-	for(z=npoints-1;z>=0;z--)
-		{ y = ry1[z]; miny = min(miny,y); maxy = max(maxy,y); }
-	miny = (miny>>12); maxy = (maxy>>12);
-	if (miny < 0) miny = 0;
-	if (maxy >= ydim) maxy = ydim-1;
-	ptr = smost;    /* They're pointers! - watch how you optimize this thing */
-	for(y=miny;y<=maxy;y++)
-	{
-		dotp1[y] = ptr; dotp2[y] = ptr+(MAXNODESPERLINE>>1);
-		ptr += MAXNODESPERLINE;
-	}
-
-	for(z=npoints-1;z>=0;z--)
-	{
-		zz = xb1[z];
-		y1 = ry1[z]; day1 = (y1>>12);
-		y2 = ry1[zz]; day2 = (y2>>12);
-		if (day1 != day2)
-		{
-			x1 = rx1[z]; x2 = rx1[zz];
-			xinc = divscale12(x2-x1,y2-y1);
-			if (day2 > day1)
-			{
-				x1 += mulscale12((day1<<12)+4095-y1,xinc);
-				for(y=day1;y<day2;y++) { *dotp2[y]++ = (x1>>12); x1 += xinc; }
-			}
-			else
-			{
-				x2 += mulscale12((day2<<12)+4095-y2,xinc);
-				for(y=day2;y<day1;y++) { *dotp1[y]++ = (x2>>12); x2 += xinc; }
-			}
-		}
-	}
-
-	globalx1 = mulscale16(globalx1,xyaspect);
-	globaly2 = mulscale16(globaly2,xyaspect);
-
-	oy = miny+1-(ydim>>1);
-	globalposx += oy*globalx1;
-	globalposy += oy*globaly2;
-
-	setuphlineasm4(asm1,asm2);
-
-	ptr = smost;
-	for(y=miny;y<=maxy;y++)
-	{
-		cnt = dotp1[y]-ptr; ptr2 = ptr+(MAXNODESPERLINE>>1);
-		for(z=cnt-1;z>=0;z--)
-		{
-			day1 = 0; day2 = 0;
-			for(zz=z;zz>0;zz--)
-			{
-				if (ptr[zz] < ptr[day1]) day1 = zz;
-				if (ptr2[zz] < ptr2[day2]) day2 = zz;
-			}
-			x1 = ptr[day1]; ptr[day1] = ptr[z];
-			x2 = ptr2[day2]-1; ptr2[day2] = ptr2[z];
-			if (x1 > x2) continue;
-
-			if (globalpolytype < 1)
-			{
+        for(i=windowx2+1;i<xdim;i++) { startumost[i] = 1, startdmost[i] = 0; }
+        
+        viewoffset = windowy1*bytesperline + windowx1;
+        
+        if ((stereomode) || (vidoption == 6))
+        {
+            ostereopixelwidth = stereopixelwidth;
+            xdimen = (windowx2-windowx1+1)+(stereopixelwidth<<1); halfxdimen = (xdimen>>1);
+            xdimenrecip = divscale32(1L,xdimen);
+            setaspect((long)divscale16(xdimen,windowx2-windowx1+1),yxaspect);
+        }
+    }
+    
+    
+    void setaspect(int32_t daxrange, int32_t daaspect)
+    {
+        viewingrange = daxrange;
+        viewingrangerecip = divscale32(1L,daxrange);
+        
+        yxaspect = daaspect;
+        xyaspect = divscale32(1,yxaspect);
+        xdimenscale = scale(xdimen,yxaspect,320);
+        xdimscale = scale(320,xyaspect,xdimen);
+    }
+    
+    
+    void flushperms(void)
+    {
+        permhead = permtail = 0;
+    }
+    
+    // Render a sprite on screen. This is used by the Engine but also the Game module
+    // when drawing the HUD or the Weapon held by the player !!!
+    void rotatesprite(int32_t sx, int32_t sy, int32_t z, short a, short picnum,
+                      int8_t dashade, uint8_t  dapalnum, uint8_t  dastat,
+                      int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2)
+    {
+        int32_t i;
+        permfifotype *per, *per2;
+        
+        if ((cx1 > cx2) || (cy1 > cy2)) return;
+        if (z <= 16) return;
+        if (picanm[picnum]&192) picnum += animateoffs(picnum,(short)0xc000);
+        if ((tilesizx[picnum] <= 0) || (tilesizy[picnum] <= 0)) return;
+        
+        if (((dastat&128) == 0) || (numpages < 2) || (beforedrawrooms != 0))
+            dorotatesprite(sx,sy,z,a,picnum,dashade,dapalnum,dastat,cx1,cy1,cx2,cy2);
+        
+        if ((dastat&64) && (cx1 <= 0) && (cy1 <= 0) && (cx2 >= xdim-1) && (cy2 >= ydim-1) &&
+            (sx == (160<<16)) && (sy == (100<<16)) && (z == 65536L) && (a == 0) && ((dastat&1) == 0))
+            permhead = permtail = 0;
+        
+        if ((dastat&128) == 0) return;
+        if (numpages >= 2)
+        {
+            per = &permfifo[permhead];
+            per->sx = sx; per->sy = sy; per->z = z; per->a = a;
+            per->picnum = picnum;
+            per->dashade = dashade; per->dapalnum = dapalnum;
+            per->dastat = dastat;
+            per->pagesleft = numpages+((beforedrawrooms&1)<<7);
+            per->cx1 = cx1; per->cy1 = cy1; per->cx2 = cx2; per->cy2 = cy2;
+            
+			/* Would be better to optimize out true bounding boxes */
+            if (dastat&64)  /* If non-masking write, checking for overlapping cases */
+            {
+                for(i=permtail;i!=permhead;i=((i+1)&(MAXPERMS-1)))
+                {
+                    per2 = &permfifo[i];
+                    if ((per2->pagesleft&127) == 0) continue;
+                    if (per2->sx != per->sx) continue;
+                    if (per2->sy != per->sy) continue;
+                    if (per2->z != per->z) continue;
+                    if (per2->a != per->a) continue;
+                    if (tilesizx[per2->picnum] > tilesizx[per->picnum]) continue;
+                    if (tilesizy[per2->picnum] > tilesizy[per->picnum]) continue;
+                    if (per2->cx1 < per->cx1) continue;
+                    if (per2->cy1 < per->cy1) continue;
+                    if (per2->cx2 > per->cx2) continue;
+                    if (per2->cy2 > per->cy2) continue;
+                    per2->pagesleft = 0;
+                }
+                if ((per->z == 65536) && (per->a == 0))
+                    for(i=permtail;i!=permhead;i=((i+1)&(MAXPERMS-1)))
+                    {
+                        per2 = &permfifo[i];
+                        if ((per2->pagesleft&127) == 0) continue;
+                        if (per2->z != 65536) continue;
+                        if (per2->a != 0) continue;
+                        if (per2->cx1 < per->cx1) continue;
+                        if (per2->cy1 < per->cy1) continue;
+                        if (per2->cx2 > per->cx2) continue;
+                        if (per2->cy2 > per->cy2) continue;
+                        if ((per2->sx>>16) < (per->sx>>16)) continue;
+                        if ((per2->sy>>16) < (per->sy>>16)) continue;
+                        if ((per2->sx>>16)+tilesizx[per2->picnum] > (per->sx>>16)+tilesizx[per->picnum]) continue;
+                        if ((per2->sy>>16)+tilesizy[per2->picnum] > (per->sy>>16)+tilesizy[per->picnum]) continue;
+                        per2->pagesleft = 0;
+                    }
+            }
+            
+            permhead = ((permhead+1)&(MAXPERMS-1));
+        }
+    }
+    
+    
+    static int getclosestcol(int32_t r, int32_t g, int32_t b)
+    {
+        int32_t i, j, k, dist, mindist, retcol;
+        uint8_t  *pal1;
+        
+        j = (r>>3)*FASTPALGRIDSIZ*FASTPALGRIDSIZ+(g>>3)*FASTPALGRIDSIZ+(b>>3)+FASTPALGRIDSIZ*FASTPALGRIDSIZ+FASTPALGRIDSIZ+1;
+        mindist = min(rdist[coldist[r&7]+64+8],gdist[coldist[g&7]+64+8]);
+        mindist = min(mindist,bdist[coldist[b&7]+64+8]);
+        mindist++;
+        
+        r = 64-r; g = 64-g; b = 64-b;
+        
+        retcol = -1;
+        for(k=26;k>=0;k--)
+        {
+            i = colscan[k]+j; if ((colhere[i>>3]&pow2char[i&7]) == 0) continue;
+            i = colhead[i];
+            do
+            {
+                pal1 = (uint8_t  *)&palette[i*3];
+                dist = gdist[pal1[1]+g];
+                if (dist < mindist)
+                {
+                    dist += rdist[pal1[0]+r];
+                    if (dist < mindist)
+                    {
+                        dist += bdist[pal1[2]+b];
+                        if (dist < mindist) { mindist = dist; retcol = i; }
+                    }
+                }
+                i = colnext[i];
+            } while (i >= 0);
+        }
+        if (retcol >= 0) return(retcol);
+        
+        mindist = 0x7fffffff;
+        pal1 = (uint8_t  *)&palette[768-3];
+        for(i=255;i>=0;i--,pal1-=3)
+        {
+            dist = gdist[pal1[1]+g]; if (dist >= mindist) continue;
+            dist += rdist[pal1[0]+r]; if (dist >= mindist) continue;
+            dist += bdist[pal1[2]+b]; if (dist >= mindist) continue;
+            mindist = dist; retcol = i;
+        }
+        return(retcol);
+    }
+    
+    
+    void makepalookup(int32_t palnum, uint8_t  *remapbuf, int8_t r,
+                      int8_t g, int8_t b, uint8_t  dastat)
+    {
+        int32_t i, j, dist, palscale;
+        uint8_t  *ptr, *ptr2;
+        
+        if (paletteloaded == 0) return;
+        
+        if (palookup[palnum] == NULL)
+        {
+			/* Allocate palookup buffer */
+            if ((palookup[palnum] = (uint8_t  *)kkmalloc(numpalookups<<8)) == NULL)
+                allocache((int32_t *)&palookup[palnum],numpalookups<<8,&permanentlock);
+        }
+        
+        if (dastat == 0) return;
+        if ((r|g|b|63) != 63) return;
+        
+        if ((r|g|b) == 0)
+        {
+            for(i=0;i<256;i++)
+            {
+                ptr = (uint8_t  *)(FP_OFF(palookup[0])+remapbuf[i]);
+                ptr2 = (uint8_t  *)(FP_OFF(palookup[palnum])+i);
+                for(j=0;j<numpalookups;j++)
+				{ *ptr2 = *ptr; ptr += 256; ptr2 += 256; }
+            }
+        }
+        else
+        {
+            ptr2 = (uint8_t  *)FP_OFF(palookup[palnum]);
+            for(i=0;i<numpalookups;i++)
+            {
+                palscale = divscale16(i,numpalookups);
+                for(j=0;j<256;j++)
+                {
+                    ptr = (uint8_t  *)&palette[remapbuf[j]*3];
+                    *ptr2++ = getclosestcol((long)ptr[0]+mulscale16(r-ptr[0],palscale),
+                                            (long)ptr[1]+mulscale16(g-ptr[1],palscale),
+                                            (long)ptr[2]+mulscale16(b-ptr[2],palscale));
+                }
+            }
+        }
+        
+        if ((vidoption == 6) && (qsetmode == 200))
+        {
+            for(i=0;i<256;i++)
+            {
+                dist = palette[i*3]*3+palette[i*3+1]*5+palette[i*3+2]*2;
+                ptr = (uint8_t  *)(FP_OFF(palookup[palnum])+i);
+                for(j=0;j<32;j++)
+                    ptr[j<<8] = (uint8_t )min(max(mulscale10(dist,32-j),0),15);
+            }
+        }
+    }
+    
+    
+    void setbrightness(uint8_t  dabrightness, uint8_t  *dapal)
+    {
+        int32_t i, j, k;
+        
+        curbrightness = min(max((long)dabrightness,0),15);
+        
+        k = 0;
+        if (vidoption == 6)
+        {
+            for(j=0;j<16;j++)
+                for(i=0;i<16;i++)
+                {
+                    tempbuf[k++] = britable[curbrightness][j<<2];
+                    tempbuf[k++] = 0;
+                    tempbuf[k++] = britable[curbrightness][i<<2];
+                    tempbuf[k++] = 0;
+                }
+        }
+        else
+        {
+            for(i=0;i<256;i++)
+            {
+                tempbuf[k++] = britable[curbrightness][dapal[i*3+2]];
+                tempbuf[k++] = britable[curbrightness][dapal[i*3+1]];
+                tempbuf[k++] = britable[curbrightness][dapal[i*3+0]];
+                tempbuf[k++] = 0;
+            }
+        }
+        
+        VBE_setPalette(0, 256, (uint8_t  *) tempbuf);
+    }
+    
+    //This is only used by drawmapview.
+    static void fillpolygon(int32_t npoints)
+    {
+        int32_t z, zz, x1, y1, x2, y2, miny, maxy, y, xinc, cnt;
+        int32_t ox, oy, bx, by, p, day1, day2;
+        short *ptr, *ptr2;
+        
+        miny = 0x7fffffff; maxy = 0x80000000;
+        for(z=npoints-1;z>=0;z--)
+		{ y = ry1[z]; miny = min(miny,y); maxy = max(maxy,y); }
+        miny = (miny>>12); maxy = (maxy>>12);
+        if (miny < 0) miny = 0;
+        if (maxy >= ydim) maxy = ydim-1;
+        ptr = smost;    /* They're pointers! - watch how you optimize this thing */
+        for(y=miny;y<=maxy;y++)
+        {
+            dotp1[y] = ptr; dotp2[y] = ptr+(MAXNODESPERLINE>>1);
+            ptr += MAXNODESPERLINE;
+        }
+        
+        for(z=npoints-1;z>=0;z--)
+        {
+            zz = xb1[z];
+            y1 = ry1[z]; day1 = (y1>>12);
+            y2 = ry1[zz]; day2 = (y2>>12);
+            if (day1 != day2)
+            {
+                x1 = rx1[z]; x2 = rx1[zz];
+                xinc = divscale12(x2-x1,y2-y1);
+                if (day2 > day1)
+                {
+                    x1 += mulscale12((day1<<12)+4095-y1,xinc);
+                    for(y=day1;y<day2;y++) { *dotp2[y]++ = (x1>>12); x1 += xinc; }
+                }
+                else
+                {
+                    x2 += mulscale12((day2<<12)+4095-y2,xinc);
+                    for(y=day2;y<day1;y++) { *dotp1[y]++ = (x2>>12); x2 += xinc; }
+                }
+            }
+        }
+        
+        globalx1 = mulscale16(globalx1,xyaspect);
+        globaly2 = mulscale16(globaly2,xyaspect);
+        
+        oy = miny+1-(ydim>>1);
+        globalposx += oy*globalx1;
+        globalposy += oy*globaly2;
+        
+        setuphlineasm4(asm1,asm2);
+        
+        ptr = smost;
+        for(y=miny;y<=maxy;y++)
+        {
+            cnt = dotp1[y]-ptr; ptr2 = ptr+(MAXNODESPERLINE>>1);
+            for(z=cnt-1;z>=0;z--)
+            {
+                day1 = 0; day2 = 0;
+                for(zz=z;zz>0;zz--)
+                {
+                    if (ptr[zz] < ptr[day1]) day1 = zz;
+                    if (ptr2[zz] < ptr2[day2]) day2 = zz;
+                }
+                x1 = ptr[day1]; ptr[day1] = ptr[z];
+                x2 = ptr2[day2]-1; ptr2[day2] = ptr2[z];
+                if (x1 > x2) continue;
+                
+                if (globalpolytype < 1)
+                {
 					/* maphline */
-				ox = x2+1-(xdim>>1);
-				bx = ox*asm1 + globalposx;
-				by = ox*asm2 - globalposy;
-
-				p = ylookup[y]+x2+frameplace;
-				hlineasm4(x2-x1,-1L,globalshade<<8,by,bx,p);
-			}
-			else
-			{
+                    ox = x2+1-(xdim>>1);
+                    bx = ox*asm1 + globalposx;
+                    by = ox*asm2 - globalposy;
+                    
+                    p = ylookup[y]+x2+frameplace;
+                    hlineasm4(x2-x1,-1L,globalshade<<8,by,bx,p);
+                }
+                else
+                {
 					/* maphline */
-				ox = x1+1-(xdim>>1);
-				bx = ox*asm1 + globalposx;
-				by = ox*asm2 - globalposy;
-
-				p = ylookup[y]+x1+frameplace;
-				if (globalpolytype == 1)
-					mhline(globalbufplc,bx,(x2-x1)<<16,0L,by,p);
-				else
-				{
-					thline(globalbufplc,bx,(x2-x1)<<16,0L,by,p);
-					transarea += (x2-x1);
-				}
-			}
-		}
-		globalposx += globalx1;
-		globalposy += globaly2;
-		ptr += MAXNODESPERLINE;
-	}
-	faketimerhandler();
-}
-
-
-static int clippoly (int32_t npoints, int32_t clipstat)
-{
-	int32_t z, zz, s1, s2, t, npoints2, start2, z1, z2, z3, z4, splitcnt;
-	int32_t cx1, cy1, cx2, cy2;
-
-	cx1 = windowx1;
-	cy1 = windowy1;
-	cx2 = windowx2+1;
-	cy2 = windowy2+1;
-	cx1 <<= 12; cy1 <<= 12; cx2 <<= 12; cy2 <<= 12;
-
-	if (clipstat&0xa)   /* Need to clip top or left */
-	{
-		npoints2 = 0; start2 = 0; z = 0; splitcnt = 0;
-		do
-		{
-			s2 = cx1-rx1[z];
-			do
-			{
-				zz = xb1[z]; xb1[z] = -1;
-				s1 = s2; s2 = cx1-rx1[zz];
-				if (s1 < 0)
-				{
-					rx2[npoints2] = rx1[z]; ry2[npoints2] = ry1[z];
-					xb2[npoints2] = npoints2+1; npoints2++;
-				}
-				if ((s1^s2) < 0)
-				{
-					rx2[npoints2] = rx1[z]+scale(rx1[zz]-rx1[z],s1,s1-s2);
-					ry2[npoints2] = ry1[z]+scale(ry1[zz]-ry1[z],s1,s1-s2);
-					if (s1 < 0) p2[splitcnt++] = npoints2;
-					xb2[npoints2] = npoints2+1;
-					npoints2++;
-				}
-				z = zz;
-			} while (xb1[z] >= 0);
-
-			if (npoints2 >= start2+3)
-				xb2[npoints2-1] = start2, start2 = npoints2;
-			else
-				npoints2 = start2;
-
-			z = 1;
-			while ((z < npoints) && (xb1[z] < 0)) z++;
-		} while (z < npoints);
-		if (npoints2 <= 2) return(0);
-
-		for(z=1;z<splitcnt;z++)
-			for(zz=0;zz<z;zz++)
-			{
-				z1 = p2[z]; z2 = xb2[z1]; z3 = p2[zz]; z4 = xb2[z3];
-				s1  = klabs(rx2[z1]-rx2[z2])+klabs(ry2[z1]-ry2[z2]);
-				s1 += klabs(rx2[z3]-rx2[z4])+klabs(ry2[z3]-ry2[z4]);
-				s2  = klabs(rx2[z1]-rx2[z4])+klabs(ry2[z1]-ry2[z4]);
-				s2 += klabs(rx2[z3]-rx2[z2])+klabs(ry2[z3]-ry2[z2]);
-				if (s2 < s1)
+                    ox = x1+1-(xdim>>1);
+                    bx = ox*asm1 + globalposx;
+                    by = ox*asm2 - globalposy;
+                    
+                    p = ylookup[y]+x1+frameplace;
+                    if (globalpolytype == 1)
+                        mhline(globalbufplc,bx,(x2-x1)<<16,0L,by,p);
+                    else
+                    {
+                        thline(globalbufplc,bx,(x2-x1)<<16,0L,by,p);
+                        transarea += (x2-x1);
+                    }
+                }
+            }
+            globalposx += globalx1;
+            globalposy += globaly2;
+            ptr += MAXNODESPERLINE;
+        }
+        faketimerhandler();
+    }
+    
+    
+    static int clippoly (int32_t npoints, int32_t clipstat)
+    {
+        int32_t z, zz, s1, s2, t, npoints2, start2, z1, z2, z3, z4, splitcnt;
+        int32_t cx1, cy1, cx2, cy2;
+        
+        cx1 = windowx1;
+        cy1 = windowy1;
+        cx2 = windowx2+1;
+        cy2 = windowy2+1;
+        cx1 <<= 12; cy1 <<= 12; cx2 <<= 12; cy2 <<= 12;
+        
+        if (clipstat&0xa)   /* Need to clip top or left */
+        {
+            npoints2 = 0; start2 = 0; z = 0; splitcnt = 0;
+            do
+            {
+                s2 = cx1-rx1[z];
+                do
+                {
+                    zz = xb1[z]; xb1[z] = -1;
+                    s1 = s2; s2 = cx1-rx1[zz];
+                    if (s1 < 0)
+                    {
+                        rx2[npoints2] = rx1[z]; ry2[npoints2] = ry1[z];
+                        xb2[npoints2] = npoints2+1; npoints2++;
+                    }
+                    if ((s1^s2) < 0)
+                    {
+                        rx2[npoints2] = rx1[z]+scale(rx1[zz]-rx1[z],s1,s1-s2);
+                        ry2[npoints2] = ry1[z]+scale(ry1[zz]-ry1[z],s1,s1-s2);
+                        if (s1 < 0) p2[splitcnt++] = npoints2;
+                        xb2[npoints2] = npoints2+1;
+                        npoints2++;
+                    }
+                    z = zz;
+                } while (xb1[z] >= 0);
+                
+                if (npoints2 >= start2+3)
+                    xb2[npoints2-1] = start2, start2 = npoints2;
+                else
+                    npoints2 = start2;
+                
+                z = 1;
+                while ((z < npoints) && (xb1[z] < 0)) z++;
+            } while (z < npoints);
+            if (npoints2 <= 2) return(0);
+            
+            for(z=1;z<splitcnt;z++)
+                for(zz=0;zz<z;zz++)
+                {
+                    z1 = p2[z]; z2 = xb2[z1]; z3 = p2[zz]; z4 = xb2[z3];
+                    s1  = klabs(rx2[z1]-rx2[z2])+klabs(ry2[z1]-ry2[z2]);
+                    s1 += klabs(rx2[z3]-rx2[z4])+klabs(ry2[z3]-ry2[z4]);
+                    s2  = klabs(rx2[z1]-rx2[z4])+klabs(ry2[z1]-ry2[z4]);
+                    s2 += klabs(rx2[z3]-rx2[z2])+klabs(ry2[z3]-ry2[z2]);
+                    if (s2 < s1)
 					{ t = xb2[p2[z]]; xb2[p2[z]] = xb2[p2[zz]]; xb2[p2[zz]] = t; }
-			}
-
-
-		npoints = 0; start2 = 0; z = 0; splitcnt = 0;
-		do
-		{
-			s2 = cy1-ry2[z];
-			do
-			{
-				zz = xb2[z]; xb2[z] = -1;
-				s1 = s2; s2 = cy1-ry2[zz];
-				if (s1 < 0)
-				{
-					rx1[npoints] = rx2[z]; ry1[npoints] = ry2[z];
-					xb1[npoints] = npoints+1; npoints++;
-				}
-				if ((s1^s2) < 0)
-				{
-					rx1[npoints] = rx2[z]+scale(rx2[zz]-rx2[z],s1,s1-s2);
-					ry1[npoints] = ry2[z]+scale(ry2[zz]-ry2[z],s1,s1-s2);
-					if (s1 < 0) p2[splitcnt++] = npoints;
-					xb1[npoints] = npoints+1;
-					npoints++;
-				}
-				z = zz;
-			} while (xb2[z] >= 0);
-
-			if (npoints >= start2+3)
-				xb1[npoints-1] = start2, start2 = npoints;
-			else
-				npoints = start2;
-
-			z = 1;
-			while ((z < npoints2) && (xb2[z] < 0)) z++;
-		} while (z < npoints2);
-		if (npoints <= 2) return(0);
-
-		for(z=1;z<splitcnt;z++)
-			for(zz=0;zz<z;zz++)
-			{
-				z1 = p2[z]; z2 = xb1[z1]; z3 = p2[zz]; z4 = xb1[z3];
-				s1  = klabs(rx1[z1]-rx1[z2])+klabs(ry1[z1]-ry1[z2]);
-				s1 += klabs(rx1[z3]-rx1[z4])+klabs(ry1[z3]-ry1[z4]);
-				s2  = klabs(rx1[z1]-rx1[z4])+klabs(ry1[z1]-ry1[z4]);
-				s2 += klabs(rx1[z3]-rx1[z2])+klabs(ry1[z3]-ry1[z2]);
-				if (s2 < s1)
-					{ t = xb1[p2[z]]; xb1[p2[z]] = xb1[p2[zz]]; xb1[p2[zz]] = t; }
-			}
-	}
-	if (clipstat&0x5)   /* Need to clip bottom or right */
-	{
-		npoints2 = 0; start2 = 0; z = 0; splitcnt = 0;
-		do
-		{
-			s2 = rx1[z]-cx2;
-			do
-			{
-				zz = xb1[z]; xb1[z] = -1;
-				s1 = s2; s2 = rx1[zz]-cx2;
-				if (s1 < 0)
-				{
-					rx2[npoints2] = rx1[z]; ry2[npoints2] = ry1[z];
-					xb2[npoints2] = npoints2+1; npoints2++;
-				}
-				if ((s1^s2) < 0)
-				{
-					rx2[npoints2] = rx1[z]+scale(rx1[zz]-rx1[z],s1,s1-s2);
-					ry2[npoints2] = ry1[z]+scale(ry1[zz]-ry1[z],s1,s1-s2);
-					if (s1 < 0) p2[splitcnt++] = npoints2;
-					xb2[npoints2] = npoints2+1;
-					npoints2++;
-				}
-				z = zz;
-			} while (xb1[z] >= 0);
-
-			if (npoints2 >= start2+3)
-				xb2[npoints2-1] = start2, start2 = npoints2;
-			else
-				npoints2 = start2;
-
-			z = 1;
-			while ((z < npoints) && (xb1[z] < 0)) z++;
-		} while (z < npoints);
-		if (npoints2 <= 2) return(0);
-
-		for(z=1;z<splitcnt;z++)
-			for(zz=0;zz<z;zz++)
-			{
-				z1 = p2[z]; z2 = xb2[z1]; z3 = p2[zz]; z4 = xb2[z3];
-				s1  = klabs(rx2[z1]-rx2[z2])+klabs(ry2[z1]-ry2[z2]);
-				s1 += klabs(rx2[z3]-rx2[z4])+klabs(ry2[z3]-ry2[z4]);
-				s2  = klabs(rx2[z1]-rx2[z4])+klabs(ry2[z1]-ry2[z4]);
-				s2 += klabs(rx2[z3]-rx2[z2])+klabs(ry2[z3]-ry2[z2]);
-				if (s2 < s1)
-					{ t = xb2[p2[z]]; xb2[p2[z]] = xb2[p2[zz]]; xb2[p2[zz]] = t; }
-			}
-
-
-		npoints = 0; start2 = 0; z = 0; splitcnt = 0;
-		do
-		{
-			s2 = ry2[z]-cy2;
-			do
-			{
-				zz = xb2[z]; xb2[z] = -1;
-				s1 = s2; s2 = ry2[zz]-cy2;
-				if (s1 < 0)
-				{
-					rx1[npoints] = rx2[z]; ry1[npoints] = ry2[z];
-					xb1[npoints] = npoints+1; npoints++;
-				}
-				if ((s1^s2) < 0)
-				{
-					rx1[npoints] = rx2[z]+scale(rx2[zz]-rx2[z],s1,s1-s2);
-					ry1[npoints] = ry2[z]+scale(ry2[zz]-ry2[z],s1,s1-s2);
-					if (s1 < 0) p2[splitcnt++] = npoints;
-					xb1[npoints] = npoints+1;
-					npoints++;
-				}
-				z = zz;
-			} while (xb2[z] >= 0);
-
-			if (npoints >= start2+3)
-				xb1[npoints-1] = start2, start2 = npoints;
-			else
-				npoints = start2;
-
-			z = 1;
-			while ((z < npoints2) && (xb2[z] < 0)) z++;
-		} while (z < npoints2);
-		if (npoints <= 2) return(0);
-
-		for(z=1;z<splitcnt;z++)
-			for(zz=0;zz<z;zz++)
-			{
-				z1 = p2[z]; z2 = xb1[z1]; z3 = p2[zz]; z4 = xb1[z3];
-				s1  = klabs(rx1[z1]-rx1[z2])+klabs(ry1[z1]-ry1[z2]);
-				s1 += klabs(rx1[z3]-rx1[z4])+klabs(ry1[z3]-ry1[z4]);
-				s2  = klabs(rx1[z1]-rx1[z4])+klabs(ry1[z1]-ry1[z4]);
-				s2 += klabs(rx1[z3]-rx1[z2])+klabs(ry1[z3]-ry1[z2]);
-				if (s2 < s1)
-					{ t = xb1[p2[z]]; xb1[p2[z]] = xb1[p2[zz]]; xb1[p2[zz]] = t; }
-			}
-	}
-	return(npoints);
-}
-
-
-void drawmapview(int32_t dax, int32_t day, int32_t zoome, short ang)
-{
-	walltype *wal;
-	sectortype *sec;
-	spritetype *spr;
-	int32_t tilenum, xoff, yoff, i, j, k, l, cosang, sinang, xspan, yspan;
-	int32_t xrepeat, yrepeat, x, y, x1, y1, x2, y2, x3, y3, x4, y4, bakx1, baky1;
-	int32_t s, w, ox, oy, startwall, cx1, cy1, cx2, cy2;
-	int32_t bakgxvect, bakgyvect, sortnum, gap, npoints;
-	int32_t xvect, yvect, xvect2, yvect2, daslope;
-
-	beforedrawrooms = 0;
-	totalarea += (windowx2+1-windowx1)*(windowy2+1-windowy1);
-
-	clearbuf(&gotsector[0],(long)((numsectors+31)>>5),0L);
-
-	cx1 = (windowx1<<12); cy1 = (windowy1<<12);
-	cx2 = ((windowx2+1)<<12)-1; cy2 = ((windowy2+1)<<12)-1;
-	zoome <<= 8;
-	bakgxvect = divscale28(sintable[(1536-ang)&2047],zoome);
-	bakgyvect = divscale28(sintable[(2048-ang)&2047],zoome);
-	xvect = mulscale8(sintable[(2048-ang)&2047],zoome);
-	yvect = mulscale8(sintable[(1536-ang)&2047],zoome);
-	xvect2 = mulscale16(xvect,yxaspect);
-	yvect2 = mulscale16(yvect,yxaspect);
-
-	sortnum = 0;
-	for(s=0,sec=&sector[s];s<numsectors;s++,sec++)
-		if (show2dsector[s>>3]&pow2char[s&7])
-		{
-			npoints = 0; i = 0;
-			startwall = sec->wallptr;
-			for(w=sec->wallnum,wal=&wall[startwall];w>0;w--,wal++)
-			{
-				ox = wal->x - dax; oy = wal->y - day;
-				x = dmulscale16(ox,xvect,-oy,yvect) + (xdim<<11);
-				y = dmulscale16(oy,xvect2,ox,yvect2) + (ydim<<11);
-				i |= getclipmask(x-cx1,cx2-x,y-cy1,cy2-y);
-				rx1[npoints] = x;
-				ry1[npoints] = y;
-				xb1[npoints] = wal->point2 - startwall;
-				npoints++;
-			}
-			if ((i&0xf0) != 0xf0) continue;
-			bakx1 = rx1[0]; baky1 = mulscale16(ry1[0]-(ydim<<11),xyaspect)+(ydim<<11);
-			if (i&0x0f)
-			{
-				npoints = clippoly(npoints,i);
-				if (npoints < 3) continue;
-			}
-
-				/* Collect floor sprites to draw */
-			for(i=headspritesect[s];i>=0;i=nextspritesect[i])
-				if ((sprite[i].cstat&48) == 32)
-				{
-					if ((sprite[i].cstat&(64+8)) == (64+8)) continue;
-					tsprite[sortnum++].owner = i;
-				}
-
-			gotsector[s>>3] |= pow2char[s&7];
-
-			globalorientation = (long)sec->floorstat;
-			if ((globalorientation&1) != 0) continue;
-
-			if (palookup[sec->floorpal] != globalpalwritten)
-			{
-				globalpalwritten = palookup[sec->floorpal];
-				setpalookupaddress(globalpalwritten);
-			}
-			globalpicnum = sec->floorpicnum;
-			if ((unsigned)globalpicnum >= (unsigned)MAXTILES) globalpicnum = 0;
-			setgotpic(globalpicnum);
-			if ((tilesizx[globalpicnum] <= 0) || (tilesizy[globalpicnum] <= 0)) continue;
-			if ((picanm[globalpicnum]&192) != 0) globalpicnum += animateoffs((short)globalpicnum,s);
-			if (waloff[globalpicnum] == 0) loadtile(globalpicnum);
-			globalbufplc = waloff[globalpicnum];
-			globalshade = max(min(sec->floorshade,numpalookups-1),0);
-			globvis = globalhisibility;
-			if (sec->visibility != 0) globvis = mulscale4(globvis,(long)((uint8_t )(sec->visibility+16)));
-			globalpolytype = 0;
-			if ((globalorientation&64) == 0)
-			{
-				globalposx = dax; globalx1 = bakgxvect; globaly1 = bakgyvect;
-				globalposy = day; globalx2 = bakgxvect; globaly2 = bakgyvect;
-			}
-			else
-			{
-				ox = wall[wall[startwall].point2].x - wall[startwall].x;
-				oy = wall[wall[startwall].point2].y - wall[startwall].y;
-				i = nsqrtasm(ox*ox+oy*oy); if (i == 0) continue;
-				i = 1048576/i;
-				globalx1 = mulscale10(dmulscale10(ox,bakgxvect,oy,bakgyvect),i);
-				globaly1 = mulscale10(dmulscale10(ox,bakgyvect,-oy,bakgxvect),i);
-				ox = (bakx1>>4)-(xdim<<7); oy = (baky1>>4)-(ydim<<7);
-				globalposx = dmulscale28(-oy,globalx1,-ox,globaly1);
-				globalposy = dmulscale28(-ox,globalx1,oy,globaly1);
-				globalx2 = -globalx1;
-				globaly2 = -globaly1;
-
-				daslope = sector[s].floorheinum;
-				i = nsqrtasm(daslope*daslope+16777216);
-				globalposy = mulscale12(globalposy,i);
-				globalx2 = mulscale12(globalx2,i);
-				globaly2 = mulscale12(globaly2,i);
-			}
-			globalxshift = (8-(picsiz[globalpicnum]&15));
-			globalyshift = (8-(picsiz[globalpicnum]>>4));
-			if (globalorientation&8) {globalxshift++; globalyshift++; }
-
-			sethlinesizes(picsiz[globalpicnum]&15,picsiz[globalpicnum]>>4,globalbufplc);
-
-			if ((globalorientation&0x4) > 0)
-			{
-				i = globalposx; globalposx = -globalposy; globalposy = -i;
-				i = globalx2; globalx2 = globaly1; globaly1 = i;
-				i = globalx1; globalx1 = -globaly2; globaly2 = -i;
-			}
-			if ((globalorientation&0x10) > 0) globalx1 = -globalx1, globaly1 = -globaly1, globalposx = -globalposx;
-			if ((globalorientation&0x20) > 0) globalx2 = -globalx2, globaly2 = -globaly2, globalposy = -globalposy;
-			asm1 = (globaly1<<globalxshift);
-			asm2 = (globalx2<<globalyshift);
-			globalx1 <<= globalxshift;
-			globaly2 <<= globalyshift;
-			globalposx = (globalposx<<(20+globalxshift))+(((long)sec->floorxpanning)<<24);
-			globalposy = (globalposy<<(20+globalyshift))-(((long)sec->floorypanning)<<24);
-
-			fillpolygon(npoints);
-		}
-
-		/* Sort sprite list */
-	gap = 1; while (gap < sortnum) gap = (gap<<1)+1;
-	for(gap>>=1;gap>0;gap>>=1)
-		for(i=0;i<sortnum-gap;i++)
-			for(j=i;j>=0;j-=gap)
-			{
-				if (sprite[tsprite[j].owner].z <= sprite[tsprite[j+gap].owner].z) break;
-				swapshort(&tsprite[j].owner,&tsprite[j+gap].owner);
-			}
-
-	for(s=sortnum-1;s>=0;s--)
-	{
-		spr = &sprite[tsprite[s].owner];
-		if ((spr->cstat&48) == 32)
-		{
-			npoints = 0;
-
-			tilenum = spr->picnum;
-			xoff = (long)((int8_t  )((picanm[tilenum]>>8)&255))+((long)spr->xoffset);
-			yoff = (long)((int8_t  )((picanm[tilenum]>>16)&255))+((long)spr->yoffset);
-			if ((spr->cstat&4) > 0) xoff = -xoff;
-			if ((spr->cstat&8) > 0) yoff = -yoff;
-
-			k = spr->ang;
-			cosang = sintable[(k+512)&2047]; sinang = sintable[k];
-			xspan = tilesizx[tilenum]; xrepeat = spr->xrepeat;
-			yspan = tilesizy[tilenum]; yrepeat = spr->yrepeat;
-
-			ox = ((xspan>>1)+xoff)*xrepeat; oy = ((yspan>>1)+yoff)*yrepeat;
-			x1 = spr->x + mulscale(sinang,ox,16) + mulscale(cosang,oy,16);
-			y1 = spr->y + mulscale(sinang,oy,16) - mulscale(cosang,ox,16);
-			l = xspan*xrepeat;
-			x2 = x1 - mulscale(sinang,l,16);
-			y2 = y1 + mulscale(cosang,l,16);
-			l = yspan*yrepeat;
-			k = -mulscale(cosang,l,16); x3 = x2+k; x4 = x1+k;
-			k = -mulscale(sinang,l,16); y3 = y2+k; y4 = y1+k;
-
-			xb1[0] = 1; xb1[1] = 2; xb1[2] = 3; xb1[3] = 0;
-			npoints = 4;
-
-			i = 0;
-
-			ox = x1 - dax; oy = y1 - day;
-			x = dmulscale16(ox,xvect,-oy,yvect) + (xdim<<11);
-			y = dmulscale16(oy,xvect2,ox,yvect2) + (ydim<<11);
-			i |= getclipmask(x-cx1,cx2-x,y-cy1,cy2-y);
-			rx1[0] = x; ry1[0] = y;
-
-			ox = x2 - dax; oy = y2 - day;
-			x = dmulscale16(ox,xvect,-oy,yvect) + (xdim<<11);
-			y = dmulscale16(oy,xvect2,ox,yvect2) + (ydim<<11);
-			i |= getclipmask(x-cx1,cx2-x,y-cy1,cy2-y);
-			rx1[1] = x; ry1[1] = y;
-
-			ox = x3 - dax; oy = y3 - day;
-			x = dmulscale16(ox,xvect,-oy,yvect) + (xdim<<11);
-			y = dmulscale16(oy,xvect2,ox,yvect2) + (ydim<<11);
-			i |= getclipmask(x-cx1,cx2-x,y-cy1,cy2-y);
-			rx1[2] = x; ry1[2] = y;
-
-			x = rx1[0]+rx1[2]-rx1[1];
-			y = ry1[0]+ry1[2]-ry1[1];
-			i |= getclipmask(x-cx1,cx2-x,y-cy1,cy2-y);
-			rx1[3] = x; ry1[3] = y;
-
-			if ((i&0xf0) != 0xf0) continue;
-			bakx1 = rx1[0]; baky1 = mulscale16(ry1[0]-(ydim<<11),xyaspect)+(ydim<<11);
-			if (i&0x0f)
-			{
-				npoints = clippoly(npoints,i);
-				if (npoints < 3) continue;
-			}
-
-			globalpicnum = spr->picnum;
-			if ((unsigned)globalpicnum >= (unsigned)MAXTILES) globalpicnum = 0;
-			setgotpic(globalpicnum);
-			if ((tilesizx[globalpicnum] <= 0) || (tilesizy[globalpicnum] <= 0)) continue;
-			if ((picanm[globalpicnum]&192) != 0) globalpicnum += animateoffs((short)globalpicnum,s);
-			if (waloff[globalpicnum] == 0) loadtile(globalpicnum);
-			globalbufplc = waloff[globalpicnum];
-			if ((sector[spr->sectnum].ceilingstat&1) > 0)
-				globalshade = ((long)sector[spr->sectnum].ceilingshade);
-			else
-				globalshade = ((long)sector[spr->sectnum].floorshade);
-			globalshade = max(min(globalshade+spr->shade+6,numpalookups-1),0);
-			asm3 = (long) FP_OFF(palookup[spr->pal]+(globalshade<<8));
-			globvis = globalhisibility;
-			if (sec->visibility != 0) globvis = mulscale4(globvis,(long)((uint8_t )(sec->visibility+16)));
-			globalpolytype = ((spr->cstat&2)>>1)+1;
-
-				/* relative alignment stuff */
-			ox = x2-x1; oy = y2-y1;
-			i = ox*ox+oy*oy; if (i == 0) continue; i = (65536*16384)/i;
-			globalx1 = mulscale10(dmulscale10(ox,bakgxvect,oy,bakgyvect),i);
-			globaly1 = mulscale10(dmulscale10(ox,bakgyvect,-oy,bakgxvect),i);
-			ox = y1-y4; oy = x4-x1;
-			i = ox*ox+oy*oy; if (i == 0) continue; i = (65536*16384)/i;
-			globalx2 = mulscale10(dmulscale10(ox,bakgxvect,oy,bakgyvect),i);
-			globaly2 = mulscale10(dmulscale10(ox,bakgyvect,-oy,bakgxvect),i);
-
-			ox = picsiz[globalpicnum]; oy = ((ox>>4)&15); ox &= 15;
-			if (pow2long[ox] != xspan)
-			{
-				ox++;
-				globalx1 = mulscale(globalx1,xspan,ox);
-				globaly1 = mulscale(globaly1,xspan,ox);
-			}
-
-			bakx1 = (bakx1>>4)-(xdim<<7); baky1 = (baky1>>4)-(ydim<<7);
-			globalposx = dmulscale28(-baky1,globalx1,-bakx1,globaly1);
-			globalposy = dmulscale28(bakx1,globalx2,-baky1,globaly2);
-
-			if ((spr->cstat&2) == 0)
-				msethlineshift(ox,oy);
-			else
-				tsethlineshift(ox,oy);
-
-			if ((spr->cstat&0x4) > 0) globalx1 = -globalx1, globaly1 = -globaly1, globalposx = -globalposx;
-			asm1 = (globaly1<<2); globalx1 <<= 2; globalposx <<= (20+2);
-			asm2 = (globalx2<<2); globaly2 <<= 2; globalposy <<= (20+2);
-
-			fillpolygon(npoints);
-		}
-	}
-}
-
-
-void clearview(int32_t dacol)
-{
-	int32_t p, y, dx;
-
-	if (qsetmode != 200) return;
-
-	dx = windowx2-windowx1+1;
-	dacol += (dacol<<8); dacol += (dacol<<16);
-	if (vidoption == 6)
-	{
-		p = (long) FP_OFF(screen)+ylookup[windowy1]+windowx1;
-		for(y=windowy1;y<=windowy2;y++)
-		{
-			clearbufbyte((void *)p,dx,dacol);
-                        clearbufbyte((void *)(p+65536),dx,dacol);
-			p += ylookup[1];
-		}
-		faketimerhandler();
-		return;
-	}
-	p = frameplace+ylookup[windowy1]+windowx1;
-	for(y=windowy1;y<=windowy2;y++)
-		{ clearbufbyte((void *)p,dx,dacol); p += ylookup[1]; }
-	faketimerhandler();
-}
-
-
-void clearallviews(int32_t dacol)
-{
-	int32_t i;
-
-	if (qsetmode != 200) return;
-	dacol += (dacol<<8); dacol += (dacol<<16);
-
-	switch(vidoption)
-	{
-		case 1:
-			for(i=0;i<numpages;i++)
-			{
-				setactivepage(i);
-				clearbufbyte((void *)frameplace,imageSize,0L);
-			}
-			setactivepage(activepage);
-		case 2:
-			clearbuf((void *)frameplace,(xdim*ydim)>>2,0L);
-			break;
-		case 6:
-			clearbuf(screen,128000L>>2,dacol);
-			break;
-	}
-	faketimerhandler();
-}
-
-
-void plotpixel(int32_t x, int32_t y, uint8_t  col)
-{
-	drawpixel(ylookup[y]+x+frameplace,(long)col);
-}
-
-
-uint8_t  getpixel(int32_t x, int32_t y)
-{
-	return(readpixel(ylookup[y]+x+frameplace));
-}
-
-	/* MUST USE RESTOREFORDRAWROOMS AFTER DRAWING */
-static int32_t setviewcnt = 0;
-static int32_t bakvidoption[4];
-static int32_t bakframeplace[4], bakxsiz[4], bakysiz[4];
-static int32_t bakwindowx1[4], bakwindowy1[4];
-static int32_t bakwindowx2[4], bakwindowy2[4];
-
-
-void setviewtotile(short tilenume, int32_t xsiz, int32_t ysiz)
-{
-	int32_t i, j;
-
-		/* DRAWROOMS TO TILE BACKUP&SET CODE */
-	tilesizx[tilenume] = xsiz; tilesizy[tilenume] = ysiz;
-	bakxsiz[setviewcnt] = xsiz; bakysiz[setviewcnt] = ysiz;
-	bakvidoption[setviewcnt] = vidoption;
-    vidoption = 2;
-	bakframeplace[setviewcnt] = frameplace; frameplace = waloff[tilenume];
-	bakwindowx1[setviewcnt] = windowx1; bakwindowy1[setviewcnt] = windowy1;
-	bakwindowx2[setviewcnt] = windowx2; bakwindowy2[setviewcnt] = windowy2;
-	copybufbyte(&startumost[windowx1],&bakumost[windowx1],(windowx2-windowx1+1)*sizeof(bakumost[0]));
-	copybufbyte(&startdmost[windowx1],&bakdmost[windowx1],(windowx2-windowx1+1)*sizeof(bakdmost[0]));
-	setview(0,0,ysiz-1,xsiz-1);
-	setaspect(65536,65536);
-	j = 0; for(i=0;i<=xsiz;i++) { ylookup[i] = j, j += ysiz; }
-	setvlinebpl(ysiz);
-	setviewcnt++;
-}
-
-
-void setviewback(void)
-{
-	int32_t i, j, k;
-
-	if (setviewcnt <= 0) return;
-	setviewcnt--;
-
-	setview(bakwindowx1[setviewcnt],bakwindowy1[setviewcnt],
-			  bakwindowx2[setviewcnt],bakwindowy2[setviewcnt]);
-	copybufbyte(&bakumost[windowx1],&startumost[windowx1],(windowx2-windowx1+1)*sizeof(startumost[0]));
-	copybufbyte(&bakdmost[windowx1],&startdmost[windowx1],(windowx2-windowx1+1)*sizeof(startdmost[0]));
-	vidoption = bakvidoption[setviewcnt];
-	frameplace = bakframeplace[setviewcnt];
-	if (setviewcnt == 0)
-		k = bakxsiz[0];
-	else
-		k = max(bakxsiz[setviewcnt-1],bakxsiz[setviewcnt]);
-	j = 0; for(i=0;i<=k;i++) ylookup[i] = j, j += bytesperline;
-	setvlinebpl(bytesperline);
-}
-
-
-void squarerotatetile(short tilenume)
-{
-	int32_t i, j, k, xsiz, ysiz;
-	uint8_t  *ptr1, *ptr2;
-
-	xsiz = tilesizx[tilenume]; ysiz = tilesizy[tilenume];
-
-		/* supports square tiles only for rotation part */
-	if (xsiz == ysiz)
-	{
-		k = (xsiz<<1);
-		for(i=xsiz-1;i>=0;i--)
-		{
-			ptr1 = (uint8_t  *) (waloff[tilenume]+i*(xsiz+1));
-            ptr2 = ptr1;
-			if ((i&1) != 0) { ptr1--; ptr2 -= xsiz; swapchar(ptr1,ptr2); }
-			for(j=(i>>1)-1;j>=0;j--)
-				{ ptr1 -= 2; ptr2 -= k; swapchar2(ptr1,ptr2,xsiz); }
-		}
-	}
-}
-
-
-void preparemirror(int32_t dax, int32_t day, int32_t daz,
-                   short daang, int32_t dahoriz, short dawall,
-                   short dasector, int32_t *tposx, int32_t *tposy,
-                   short *tang)
-{
-	int32_t i, j, x, y, dx, dy;
-
-	x = wall[dawall].x; dx = wall[wall[dawall].point2].x-x;
-	y = wall[dawall].y; dy = wall[wall[dawall].point2].y-y;
-	j = dx*dx + dy*dy; if (j == 0) return;
-	i = (((dax-x)*dx + (day-y)*dy)<<1);
-	*tposx = (x<<1) + scale(dx,i,j) - dax;
-	*tposy = (y<<1) + scale(dy,i,j) - day;
-	*tang = (((getangle(dx,dy)<<1)-daang)&2047);
-
-	inpreparemirror = 1;
-}
-
-
-void completemirror(void)
-{
-	int32_t i, dy, p;
-
-		/* Can't reverse with uninitialized data */
-	if (inpreparemirror) { inpreparemirror = 0; return; }
-	if (mirrorsx1 > 0) mirrorsx1--;
-	if (mirrorsx2 < windowx2-windowx1-1) mirrorsx2++;
-	if (mirrorsx2 < mirrorsx1) return;
-
-	transarea += (mirrorsx2-mirrorsx1)*(windowy2-windowy1);
-
-	p = frameplace+ylookup[windowy1+mirrorsy1]+windowx1+mirrorsx1;
-	i = windowx2-windowx1-mirrorsx2-mirrorsx1; mirrorsx2 -= mirrorsx1;
-	// FIX_00085: Optimized Video driver. FPS increases by +20%.
-	for(dy=mirrorsy2-mirrorsy1-1;dy>=0;dy--)
-	{
-                copybufbyte((void *)(p),tempbuf,mirrorsx2+1);
-		tempbuf[mirrorsx2] = tempbuf[mirrorsx2-1];
-                copybufreverse(&tempbuf[mirrorsx2],(void *)(p+i),mirrorsx2+1);
-		p += ylookup[1];
-		faketimerhandler();
-	}
-}
-
-
-int sectorofwall(short theline)
-{
-	int32_t i, gap;
-
-	if ((theline < 0) || (theline >= numwalls)) return(-1);
-	i = wall[theline].nextwall; if (i >= 0) return(wall[i].nextsector);
-
-	gap = (numsectors>>1); i = gap;
-	while (gap > 1)
-	{
-		gap >>= 1;
-		if (sector[i].wallptr < theline) i += gap; else i -= gap;
-	}
-	while (sector[i].wallptr > theline) i--;
-	while (sector[i].wallptr+sector[i].wallnum <= theline) i++;
-	return(i);
-}
-
-
-int getceilzofslope(short sectnum, int32_t dax, int32_t day)
-{
-	int32_t dx, dy, i, j;
-	walltype *wal;
-
-	if (!(sector[sectnum].ceilingstat&2)) return(sector[sectnum].ceilingz);
-	wal = &wall[sector[sectnum].wallptr];
-	dx = wall[wal->point2].x-wal->x; dy = wall[wal->point2].y-wal->y;
-	i = (nsqrtasm(dx*dx+dy*dy)<<5); if (i == 0) return(sector[sectnum].ceilingz);
-	j = dmulscale3(dx,day-wal->y,-dy,dax-wal->x);
-	return(sector[sectnum].ceilingz+scale(sector[sectnum].ceilingheinum,j,i));
-}
-
-
-int getflorzofslope(short sectnum, int32_t dax, int32_t day)
-{
-	int32_t dx, dy, i, j;
-	walltype *wal;
-
-	if (!(sector[sectnum].floorstat&2)) return(sector[sectnum].floorz);
-	wal = &wall[sector[sectnum].wallptr];
-	dx = wall[wal->point2].x-wal->x; dy = wall[wal->point2].y-wal->y;
-	i = (nsqrtasm(dx*dx+dy*dy)<<5); if (i == 0) return(sector[sectnum].floorz);
-	j = dmulscale3(dx,day-wal->y,-dy,dax-wal->x);
-	return(sector[sectnum].floorz+scale(sector[sectnum].floorheinum,j,i));
-}
-
-
-void getzsofslope(short sectnum, int32_t dax, int32_t day, int32_t *ceilz, int32_t *florz)
-{
-	int32_t dx, dy, i, j;
-	walltype *wal, *wal2;
-	sectortype *sec;
-
-	sec = &sector[sectnum];
-	*ceilz = sec->ceilingz; *florz = sec->floorz;
-	if ((sec->ceilingstat|sec->floorstat)&2)
-	{
-		wal = &wall[sec->wallptr]; wal2 = &wall[wal->point2];
-		dx = wal2->x-wal->x; dy = wal2->y-wal->y;
-		i = (nsqrtasm(dx*dx+dy*dy)<<5); if (i == 0) return;
-		j = dmulscale3(dx,day-wal->y,-dy,dax-wal->x);
-		if (sec->ceilingstat&2) *ceilz = (*ceilz)+scale(sec->ceilingheinum,j,i);
-		if (sec->floorstat&2) *florz = (*florz)+scale(sec->floorheinum,j,i);
-	}
-}
-
-
-void alignceilslope(short dasect, int32_t x, int32_t y, int32_t z)
-{
-	int32_t i, dax, day;
-	walltype *wal;
-
-	wal = &wall[sector[dasect].wallptr];
-	dax = wall[wal->point2].x-wal->x;
-	day = wall[wal->point2].y-wal->y;
-
-	i = (y-wal->y)*dax - (x-wal->x)*day; if (i == 0) return;
-	sector[dasect].ceilingheinum = scale((z-sector[dasect].ceilingz)<<8,
-													 nsqrtasm(dax*dax+day*day),i);
-
-	if (sector[dasect].ceilingheinum == 0) sector[dasect].ceilingstat &= ~2;
-												 else sector[dasect].ceilingstat |= 2;
-}
-
-
-void alignflorslope(short dasect, int32_t x, int32_t y, int32_t z)
-{
-	int32_t i, dax, day;
-	walltype *wal;
-
-	wal = &wall[sector[dasect].wallptr];
-	dax = wall[wal->point2].x-wal->x;
-	day = wall[wal->point2].y-wal->y;
-
-	i = (y-wal->y)*dax - (x-wal->x)*day; if (i == 0) return;
-	sector[dasect].floorheinum = scale((z-sector[dasect].floorz)<<8,
-												  nsqrtasm(dax*dax+day*day),i);
-
-	if (sector[dasect].floorheinum == 0) sector[dasect].floorstat &= ~2;
-											  else sector[dasect].floorstat |= 2;
-}
-
-
-int loopnumofsector(short sectnum, short wallnum)
-{
-	int32_t i, numloops, startwall, endwall;
-
-	numloops = 0;
-	startwall = sector[sectnum].wallptr;
-	endwall = startwall + sector[sectnum].wallnum;
-	for(i=startwall;i<endwall;i++)
-	{
-		if (i == wallnum) return(numloops);
-		if (wall[i].point2 < i) numloops++;
-	}
-	return(-1);
-}
-
-
-void setfirstwall(short sectnum, short newfirstwall)
-{
-	int32_t i, j, k, numwallsofloop;
-	int32_t startwall, endwall, danumwalls, dagoalloop;
-
-	startwall = sector[sectnum].wallptr;
-	danumwalls = sector[sectnum].wallnum;
-	endwall = startwall+danumwalls;
-	if ((newfirstwall < startwall) || (newfirstwall >= startwall+danumwalls)) return;
-	for(i=0;i<danumwalls;i++)
-		memcpy(&wall[i+numwalls],&wall[i+startwall],sizeof(walltype));
-
-	numwallsofloop = 0;
-	i = newfirstwall;
-	do
-	{
-		numwallsofloop++;
-		i = wall[i].point2;
-	} while (i != newfirstwall);
-
+                }
+            
+            
+            npoints = 0; start2 = 0; z = 0; splitcnt = 0;
+            do
+            {
+                s2 = cy1-ry2[z];
+                do
+                {
+                    zz = xb2[z]; xb2[z] = -1;
+                    s1 = s2; s2 = cy1-ry2[zz];
+                    if (s1 < 0)
+                    {
+                        rx1[npoints] = rx2[z]; ry1[npoints] = ry2[z];
+                        xb1[npoints] = npoints+1; npoints++;
+                    }
+                    if ((s1^s2) < 0)
+                    {
+                        rx1[npoints] = rx2[z]+scale(rx2[zz]-rx2[z],s1,s1-s2);
+                        ry1[npoints] = ry2[z]+scale(ry2[zz]-ry2[z],s1,s1-s2);
+                        if (s1 < 0) p2[splitcnt++] = npoints;
+                        xb1[npoints] = npoints+1;
+                        npoints++;
+                    }
+                    z = zz;
+                } while (xb2[z] >= 0);
+                
+                if (npoints >= start2+3)
+                    xb1[npoints-1] = start2, start2 = npoints;
+                else
+                    npoints = start2;
+                
+                z = 1;
+                while ((z < npoints2) && (xb2[z] < 0)) z++;
+            } while (z < npoints2);
+            if (npoints <= 2) return(0);
+            
+            for(z=1;z<splitcnt;z++)
+                for(zz=0;zz<z;zz++)
+                {
+                    z1 = p2[z]; z2 = xb1[z1]; z3 = p2[zz]; z4 = xb1[z3];
+                    s1  = klabs(rx1[z1]-rx1[z2])+klabs(ry1[z1]-ry1[z2]);
+                    s1 += klabs(rx1[z3]-rx1[z4])+klabs(ry1[z3]-ry1[z4]);
+                    s2  = klabs(rx1[z1]-rx1[z4])+klabs(ry1[z1]-ry1[z4]);
+                    s2 += klabs(rx1[z3]-rx1[z2])+klabs(ry1[z3]-ry1[z2]);
+                    if (s2 < s1)
+					{ t = xb1[p2[z]]; xb1[p2[z]] = xb1[p2[zz]]; xb1[p2[zz]] = t; }
+                }
+        }
+        if (clipstat&0x5)   /* Need to clip bottom or right */
+        {
+            npoints2 = 0; start2 = 0; z = 0; splitcnt = 0;
+            do
+            {
+                s2 = rx1[z]-cx2;
+                do
+                {
+                    zz = xb1[z]; xb1[z] = -1;
+                    s1 = s2; s2 = rx1[zz]-cx2;
+                    if (s1 < 0)
+                    {
+                        rx2[npoints2] = rx1[z]; ry2[npoints2] = ry1[z];
+                        xb2[npoints2] = npoints2+1; npoints2++;
+                    }
+                    if ((s1^s2) < 0)
+                    {
+                        rx2[npoints2] = rx1[z]+scale(rx1[zz]-rx1[z],s1,s1-s2);
+                        ry2[npoints2] = ry1[z]+scale(ry1[zz]-ry1[z],s1,s1-s2);
+                        if (s1 < 0) p2[splitcnt++] = npoints2;
+                        xb2[npoints2] = npoints2+1;
+                        npoints2++;
+                    }
+                    z = zz;
+                } while (xb1[z] >= 0);
+                
+                if (npoints2 >= start2+3)
+                    xb2[npoints2-1] = start2, start2 = npoints2;
+                else
+                    npoints2 = start2;
+                
+                z = 1;
+                while ((z < npoints) && (xb1[z] < 0)) z++;
+            } while (z < npoints);
+            if (npoints2 <= 2) return(0);
+            
+            for(z=1;z<splitcnt;z++)
+                for(zz=0;zz<z;zz++)
+                {
+                    z1 = p2[z]; z2 = xb2[z1]; z3 = p2[zz]; z4 = xb2[z3];
+                    s1  = klabs(rx2[z1]-rx2[z2])+klabs(ry2[z1]-ry2[z2]);
+                    s1 += klabs(rx2[z3]-rx2[z4])+klabs(ry2[z3]-ry2[z4]);
+                    s2  = klabs(rx2[z1]-rx2[z4])+klabs(ry2[z1]-ry2[z4]);
+                    s2 += klabs(rx2[z3]-rx2[z2])+klabs(ry2[z3]-ry2[z2]);
+                    if (s2 < s1)
+					{ t = xb2[p2[z]]; xb2[p2[z]] = xb2[p2[zz]]; xb2[p2[zz]] = t; }
+                }
+            
+            
+            npoints = 0; start2 = 0; z = 0; splitcnt = 0;
+            do
+            {
+                s2 = ry2[z]-cy2;
+                do
+                {
+                    zz = xb2[z]; xb2[z] = -1;
+                    s1 = s2; s2 = ry2[zz]-cy2;
+                    if (s1 < 0)
+                    {
+                        rx1[npoints] = rx2[z]; ry1[npoints] = ry2[z];
+                        xb1[npoints] = npoints+1; npoints++;
+                    }
+                    if ((s1^s2) < 0)
+                    {
+                        rx1[npoints] = rx2[z]+scale(rx2[zz]-rx2[z],s1,s1-s2);
+                        ry1[npoints] = ry2[z]+scale(ry2[zz]-ry2[z],s1,s1-s2);
+                        if (s1 < 0) p2[splitcnt++] = npoints;
+                        xb1[npoints] = npoints+1;
+                        npoints++;
+                    }
+                    z = zz;
+                } while (xb2[z] >= 0);
+                
+                if (npoints >= start2+3)
+                    xb1[npoints-1] = start2, start2 = npoints;
+                else
+                    npoints = start2;
+                
+                z = 1;
+                while ((z < npoints2) && (xb2[z] < 0)) z++;
+            } while (z < npoints2);
+            if (npoints <= 2) return(0);
+            
+            for(z=1;z<splitcnt;z++)
+                for(zz=0;zz<z;zz++)
+                {
+                    z1 = p2[z]; z2 = xb1[z1]; z3 = p2[zz]; z4 = xb1[z3];
+                    s1  = klabs(rx1[z1]-rx1[z2])+klabs(ry1[z1]-ry1[z2]);
+                    s1 += klabs(rx1[z3]-rx1[z4])+klabs(ry1[z3]-ry1[z4]);
+                    s2  = klabs(rx1[z1]-rx1[z4])+klabs(ry1[z1]-ry1[z4]);
+                    s2 += klabs(rx1[z3]-rx1[z2])+klabs(ry1[z3]-ry1[z2]);
+                    if (s2 < s1)
+					{ t = xb1[p2[z]]; xb1[p2[z]] = xb1[p2[zz]]; xb1[p2[zz]] = t; }
+                }
+        }
+        return(npoints);
+    }
+    
+    
+    void drawmapview(int32_t dax, int32_t day, int32_t zoome, short ang)
+    {
+        walltype *wal;
+        sectortype *sec;
+        spritetype *spr;
+        int32_t tilenum, xoff, yoff, i, j, k, l, cosang, sinang, xspan, yspan;
+        int32_t xrepeat, yrepeat, x, y, x1, y1, x2, y2, x3, y3, x4, y4, bakx1, baky1;
+        int32_t s, w, ox, oy, startwall, cx1, cy1, cx2, cy2;
+        int32_t bakgxvect, bakgyvect, sortnum, gap, npoints;
+        int32_t xvect, yvect, xvect2, yvect2, daslope;
+        
+        beforedrawrooms = 0;
+        totalarea += (windowx2+1-windowx1)*(windowy2+1-windowy1);
+        
+        clearbuf(&gotsector[0],(long)((numsectors+31)>>5),0L);
+        
+        cx1 = (windowx1<<12); cy1 = (windowy1<<12);
+        cx2 = ((windowx2+1)<<12)-1; cy2 = ((windowy2+1)<<12)-1;
+        zoome <<= 8;
+        bakgxvect = divscale28(sintable[(1536-ang)&2047],zoome);
+        bakgyvect = divscale28(sintable[(2048-ang)&2047],zoome);
+        xvect = mulscale8(sintable[(2048-ang)&2047],zoome);
+        yvect = mulscale8(sintable[(1536-ang)&2047],zoome);
+        xvect2 = mulscale16(xvect,yxaspect);
+        yvect2 = mulscale16(yvect,yxaspect);
+        
+        sortnum = 0;
+        for(s=0,sec=&sector[s];s<numsectors;s++,sec++)
+            if (show2dsector[s>>3]&pow2char[s&7])
+            {
+                npoints = 0; i = 0;
+                startwall = sec->wallptr;
+                for(w=sec->wallnum,wal=&wall[startwall];w>0;w--,wal++)
+                {
+                    ox = wal->x - dax; oy = wal->y - day;
+                    x = dmulscale16(ox,xvect,-oy,yvect) + (xdim<<11);
+                    y = dmulscale16(oy,xvect2,ox,yvect2) + (ydim<<11);
+                    i |= getclipmask(x-cx1,cx2-x,y-cy1,cy2-y);
+                    rx1[npoints] = x;
+                    ry1[npoints] = y;
+                    xb1[npoints] = wal->point2 - startwall;
+                    npoints++;
+                }
+                if ((i&0xf0) != 0xf0) continue;
+                bakx1 = rx1[0]; baky1 = mulscale16(ry1[0]-(ydim<<11),xyaspect)+(ydim<<11);
+                if (i&0x0f)
+                {
+                    npoints = clippoly(npoints,i);
+                    if (npoints < 3) continue;
+                }
+                
+				/* Collect floor sprites to draw */
+                for(i=headspritesect[s];i>=0;i=nextspritesect[i])
+                    if ((sprite[i].cstat&48) == 32)
+                    {
+                        if ((sprite[i].cstat&(64+8)) == (64+8)) continue;
+                        tsprite[sortnum++].owner = i;
+                    }
+                
+                gotsector[s>>3] |= pow2char[s&7];
+                
+                globalorientation = (long)sec->floorstat;
+                if ((globalorientation&1) != 0) continue;
+                
+                if (palookup[sec->floorpal] != globalpalwritten)
+                {
+                    globalpalwritten = palookup[sec->floorpal];
+                    setpalookupaddress(globalpalwritten);
+                }
+                globalpicnum = sec->floorpicnum;
+                if ((unsigned)globalpicnum >= (unsigned)MAXTILES) globalpicnum = 0;
+                setgotpic(globalpicnum);
+                if ((tilesizx[globalpicnum] <= 0) || (tilesizy[globalpicnum] <= 0)) continue;
+                if ((picanm[globalpicnum]&192) != 0) globalpicnum += animateoffs((short)globalpicnum,s);
+                if (waloff[globalpicnum] == 0) loadtile(globalpicnum);
+                globalbufplc = waloff[globalpicnum];
+                globalshade = max(min(sec->floorshade,numpalookups-1),0);
+                globvis = globalhisibility;
+                if (sec->visibility != 0) globvis = mulscale4(globvis,(long)((uint8_t )(sec->visibility+16)));
+                globalpolytype = 0;
+                if ((globalorientation&64) == 0)
+                {
+                    globalposx = dax; globalx1 = bakgxvect; globaly1 = bakgyvect;
+                    globalposy = day; globalx2 = bakgxvect; globaly2 = bakgyvect;
+                }
+                else
+                {
+                    ox = wall[wall[startwall].point2].x - wall[startwall].x;
+                    oy = wall[wall[startwall].point2].y - wall[startwall].y;
+                    i = nsqrtasm(ox*ox+oy*oy); if (i == 0) continue;
+                    i = 1048576/i;
+                    globalx1 = mulscale10(dmulscale10(ox,bakgxvect,oy,bakgyvect),i);
+                    globaly1 = mulscale10(dmulscale10(ox,bakgyvect,-oy,bakgxvect),i);
+                    ox = (bakx1>>4)-(xdim<<7); oy = (baky1>>4)-(ydim<<7);
+                    globalposx = dmulscale28(-oy,globalx1,-ox,globaly1);
+                    globalposy = dmulscale28(-ox,globalx1,oy,globaly1);
+                    globalx2 = -globalx1;
+                    globaly2 = -globaly1;
+                    
+                    daslope = sector[s].floorheinum;
+                    i = nsqrtasm(daslope*daslope+16777216);
+                    globalposy = mulscale12(globalposy,i);
+                    globalx2 = mulscale12(globalx2,i);
+                    globaly2 = mulscale12(globaly2,i);
+                }
+                globalxshift = (8-(picsiz[globalpicnum]&15));
+                globalyshift = (8-(picsiz[globalpicnum]>>4));
+                if (globalorientation&8) {globalxshift++; globalyshift++; }
+                
+                sethlinesizes(picsiz[globalpicnum]&15,picsiz[globalpicnum]>>4,globalbufplc);
+                
+                if ((globalorientation&0x4) > 0)
+                {
+                    i = globalposx; globalposx = -globalposy; globalposy = -i;
+                    i = globalx2; globalx2 = globaly1; globaly1 = i;
+                    i = globalx1; globalx1 = -globaly2; globaly2 = -i;
+                }
+                if ((globalorientation&0x10) > 0) globalx1 = -globalx1, globaly1 = -globaly1, globalposx = -globalposx;
+                if ((globalorientation&0x20) > 0) globalx2 = -globalx2, globaly2 = -globaly2, globalposy = -globalposy;
+                asm1 = (globaly1<<globalxshift);
+                asm2 = (globalx2<<globalyshift);
+                globalx1 <<= globalxshift;
+                globaly2 <<= globalyshift;
+                globalposx = (globalposx<<(20+globalxshift))+(((long)sec->floorxpanning)<<24);
+                globalposy = (globalposy<<(20+globalyshift))-(((long)sec->floorypanning)<<24);
+                
+                fillpolygon(npoints);
+            }
+        
+		/* Sort sprite list */
+        gap = 1; while (gap < sortnum) gap = (gap<<1)+1;
+        for(gap>>=1;gap>0;gap>>=1)
+            for(i=0;i<sortnum-gap;i++)
+                for(j=i;j>=0;j-=gap)
+                {
+                    if (sprite[tsprite[j].owner].z <= sprite[tsprite[j+gap].owner].z) break;
+                    swapshort(&tsprite[j].owner,&tsprite[j+gap].owner);
+                }
+        
+        for(s=sortnum-1;s>=0;s--)
+        {
+            spr = &sprite[tsprite[s].owner];
+            if ((spr->cstat&48) == 32)
+            {
+                npoints = 0;
+                
+                tilenum = spr->picnum;
+                xoff = (long)((int8_t  )((picanm[tilenum]>>8)&255))+((long)spr->xoffset);
+                yoff = (long)((int8_t  )((picanm[tilenum]>>16)&255))+((long)spr->yoffset);
+                if ((spr->cstat&4) > 0) xoff = -xoff;
+                if ((spr->cstat&8) > 0) yoff = -yoff;
+                
+                k = spr->ang;
+                cosang = sintable[(k+512)&2047]; sinang = sintable[k];
+                xspan = tilesizx[tilenum]; xrepeat = spr->xrepeat;
+                yspan = tilesizy[tilenum]; yrepeat = spr->yrepeat;
+                
+                ox = ((xspan>>1)+xoff)*xrepeat; oy = ((yspan>>1)+yoff)*yrepeat;
+                x1 = spr->x + mulscale(sinang,ox,16) + mulscale(cosang,oy,16);
+                y1 = spr->y + mulscale(sinang,oy,16) - mulscale(cosang,ox,16);
+                l = xspan*xrepeat;
+                x2 = x1 - mulscale(sinang,l,16);
+                y2 = y1 + mulscale(cosang,l,16);
+                l = yspan*yrepeat;
+                k = -mulscale(cosang,l,16); x3 = x2+k; x4 = x1+k;
+                k = -mulscale(sinang,l,16); y3 = y2+k; y4 = y1+k;
+                
+                xb1[0] = 1; xb1[1] = 2; xb1[2] = 3; xb1[3] = 0;
+                npoints = 4;
+                
+                i = 0;
+                
+                ox = x1 - dax; oy = y1 - day;
+                x = dmulscale16(ox,xvect,-oy,yvect) + (xdim<<11);
+                y = dmulscale16(oy,xvect2,ox,yvect2) + (ydim<<11);
+                i |= getclipmask(x-cx1,cx2-x,y-cy1,cy2-y);
+                rx1[0] = x; ry1[0] = y;
+                
+                ox = x2 - dax; oy = y2 - day;
+                x = dmulscale16(ox,xvect,-oy,yvect) + (xdim<<11);
+                y = dmulscale16(oy,xvect2,ox,yvect2) + (ydim<<11);
+                i |= getclipmask(x-cx1,cx2-x,y-cy1,cy2-y);
+                rx1[1] = x; ry1[1] = y;
+                
+                ox = x3 - dax; oy = y3 - day;
+                x = dmulscale16(ox,xvect,-oy,yvect) + (xdim<<11);
+                y = dmulscale16(oy,xvect2,ox,yvect2) + (ydim<<11);
+                i |= getclipmask(x-cx1,cx2-x,y-cy1,cy2-y);
+                rx1[2] = x; ry1[2] = y;
+                
+                x = rx1[0]+rx1[2]-rx1[1];
+                y = ry1[0]+ry1[2]-ry1[1];
+                i |= getclipmask(x-cx1,cx2-x,y-cy1,cy2-y);
+                rx1[3] = x; ry1[3] = y;
+                
+                if ((i&0xf0) != 0xf0) continue;
+                bakx1 = rx1[0]; baky1 = mulscale16(ry1[0]-(ydim<<11),xyaspect)+(ydim<<11);
+                if (i&0x0f)
+                {
+                    npoints = clippoly(npoints,i);
+                    if (npoints < 3) continue;
+                }
+                
+                globalpicnum = spr->picnum;
+                if ((unsigned)globalpicnum >= (unsigned)MAXTILES) globalpicnum = 0;
+                setgotpic(globalpicnum);
+                if ((tilesizx[globalpicnum] <= 0) || (tilesizy[globalpicnum] <= 0)) continue;
+                if ((picanm[globalpicnum]&192) != 0) globalpicnum += animateoffs((short)globalpicnum,s);
+                if (waloff[globalpicnum] == 0) loadtile(globalpicnum);
+                globalbufplc = waloff[globalpicnum];
+                if ((sector[spr->sectnum].ceilingstat&1) > 0)
+                    globalshade = ((long)sector[spr->sectnum].ceilingshade);
+                else
+                    globalshade = ((long)sector[spr->sectnum].floorshade);
+                globalshade = max(min(globalshade+spr->shade+6,numpalookups-1),0);
+                asm3 = (long) FP_OFF(palookup[spr->pal]+(globalshade<<8));
+                globvis = globalhisibility;
+                if (sec->visibility != 0) globvis = mulscale4(globvis,(long)((uint8_t )(sec->visibility+16)));
+                globalpolytype = ((spr->cstat&2)>>1)+1;
+                
+				/* relative alignment stuff */
+                ox = x2-x1; oy = y2-y1;
+                i = ox*ox+oy*oy; if (i == 0) continue; i = (65536*16384)/i;
+                globalx1 = mulscale10(dmulscale10(ox,bakgxvect,oy,bakgyvect),i);
+                globaly1 = mulscale10(dmulscale10(ox,bakgyvect,-oy,bakgxvect),i);
+                ox = y1-y4; oy = x4-x1;
+                i = ox*ox+oy*oy; if (i == 0) continue; i = (65536*16384)/i;
+                globalx2 = mulscale10(dmulscale10(ox,bakgxvect,oy,bakgyvect),i);
+                globaly2 = mulscale10(dmulscale10(ox,bakgyvect,-oy,bakgxvect),i);
+                
+                ox = picsiz[globalpicnum]; oy = ((ox>>4)&15); ox &= 15;
+                if (pow2long[ox] != xspan)
+                {
+                    ox++;
+                    globalx1 = mulscale(globalx1,xspan,ox);
+                    globaly1 = mulscale(globaly1,xspan,ox);
+                }
+                
+                bakx1 = (bakx1>>4)-(xdim<<7); baky1 = (baky1>>4)-(ydim<<7);
+                globalposx = dmulscale28(-baky1,globalx1,-bakx1,globaly1);
+                globalposy = dmulscale28(bakx1,globalx2,-baky1,globaly2);
+                
+                if ((spr->cstat&2) == 0)
+                    msethlineshift(ox,oy);
+                else
+                    tsethlineshift(ox,oy);
+                
+                if ((spr->cstat&0x4) > 0) globalx1 = -globalx1, globaly1 = -globaly1, globalposx = -globalposx;
+                asm1 = (globaly1<<2); globalx1 <<= 2; globalposx <<= (20+2);
+                asm2 = (globalx2<<2); globaly2 <<= 2; globalposy <<= (20+2);
+                
+                fillpolygon(npoints);
+            }
+        }
+    }
+    
+    
+    void clearview(int32_t dacol)
+    {
+        int32_t p, y, dx;
+        
+        if (qsetmode != 200) return;
+        
+        dx = windowx2-windowx1+1;
+        dacol += (dacol<<8); dacol += (dacol<<16);
+        if (vidoption == 6)
+        {
+            p = (long) FP_OFF(screen)+ylookup[windowy1]+windowx1;
+            for(y=windowy1;y<=windowy2;y++)
+            {
+                clearbufbyte((void *)p,dx,dacol);
+                clearbufbyte((void *)(p+65536),dx,dacol);
+                p += ylookup[1];
+            }
+            faketimerhandler();
+            return;
+        }
+        p = frameplace+ylookup[windowy1]+windowx1;
+        for(y=windowy1;y<=windowy2;y++)
+		{ clearbufbyte((void *)p,dx,dacol); p += ylookup[1]; }
+        faketimerhandler();
+    }
+    
+    
+    void clearallviews(int32_t dacol)
+    {
+        int32_t i;
+        
+        if (qsetmode != 200) return;
+        dacol += (dacol<<8); dacol += (dacol<<16);
+        
+        switch(vidoption)
+        {
+            case 1:
+                for(i=0;i<numpages;i++)
+                {
+                    setactivepage(i);
+                    clearbufbyte((void *)frameplace,imageSize,0L);
+                }
+                setactivepage(activepage);
+            case 2:
+                clearbuf((void *)frameplace,(xdim*ydim)>>2,0L);
+                break;
+            case 6:
+                clearbuf(screen,128000L>>2,dacol);
+                break;
+        }
+        faketimerhandler();
+    }
+    
+    
+    void plotpixel(int32_t x, int32_t y, uint8_t  col)
+    {
+        drawpixel(ylookup[y]+x+frameplace,(long)col);
+    }
+    
+    
+    uint8_t  getpixel(int32_t x, int32_t y)
+    {
+        return(readpixel(ylookup[y]+x+frameplace));
+    }
+    
+	/* MUST USE RESTOREFORDRAWROOMS AFTER DRAWING */
+    static int32_t setviewcnt = 0;
+    static int32_t bakvidoption[4];
+    static int32_t bakframeplace[4], bakxsiz[4], bakysiz[4];
+    static int32_t bakwindowx1[4], bakwindowy1[4];
+    static int32_t bakwindowx2[4], bakwindowy2[4];
+    
+    
+    void setviewtotile(short tilenume, int32_t xsiz, int32_t ysiz)
+    {
+        int32_t i, j;
+        
+		/* DRAWROOMS TO TILE BACKUP&SET CODE */
+        tilesizx[tilenume] = xsiz; tilesizy[tilenume] = ysiz;
+        bakxsiz[setviewcnt] = xsiz; bakysiz[setviewcnt] = ysiz;
+        bakvidoption[setviewcnt] = vidoption;
+        vidoption = 2;
+        bakframeplace[setviewcnt] = frameplace; frameplace = waloff[tilenume];
+        bakwindowx1[setviewcnt] = windowx1; bakwindowy1[setviewcnt] = windowy1;
+        bakwindowx2[setviewcnt] = windowx2; bakwindowy2[setviewcnt] = windowy2;
+        copybufbyte(&startumost[windowx1],&bakumost[windowx1],(windowx2-windowx1+1)*sizeof(bakumost[0]));
+        copybufbyte(&startdmost[windowx1],&bakdmost[windowx1],(windowx2-windowx1+1)*sizeof(bakdmost[0]));
+        setview(0,0,ysiz-1,xsiz-1);
+        setaspect(65536,65536);
+        j = 0; for(i=0;i<=xsiz;i++) { ylookup[i] = j, j += ysiz; }
+        setvlinebpl(ysiz);
+        setviewcnt++;
+    }
+    
+    
+    void setviewback(void)
+    {
+        int32_t i, j, k;
+        
+        if (setviewcnt <= 0) return;
+        setviewcnt--;
+        
+        setview(bakwindowx1[setviewcnt],bakwindowy1[setviewcnt],
+                bakwindowx2[setviewcnt],bakwindowy2[setviewcnt]);
+        copybufbyte(&bakumost[windowx1],&startumost[windowx1],(windowx2-windowx1+1)*sizeof(startumost[0]));
+        copybufbyte(&bakdmost[windowx1],&startdmost[windowx1],(windowx2-windowx1+1)*sizeof(startdmost[0]));
+        vidoption = bakvidoption[setviewcnt];
+        frameplace = bakframeplace[setviewcnt];
+        if (setviewcnt == 0)
+            k = bakxsiz[0];
+        else
+            k = max(bakxsiz[setviewcnt-1],bakxsiz[setviewcnt]);
+        j = 0; for(i=0;i<=k;i++) ylookup[i] = j, j += bytesperline;
+        setvlinebpl(bytesperline);
+    }
+    
+    
+    void squarerotatetile(short tilenume)
+    {
+        int32_t i, j, k, xsiz, ysiz;
+        uint8_t  *ptr1, *ptr2;
+        
+        xsiz = tilesizx[tilenume]; ysiz = tilesizy[tilenume];
+        
+		/* supports square tiles only for rotation part */
+        if (xsiz == ysiz)
+        {
+            k = (xsiz<<1);
+            for(i=xsiz-1;i>=0;i--)
+            {
+                ptr1 = (uint8_t  *) (waloff[tilenume]+i*(xsiz+1));
+                ptr2 = ptr1;
+                if ((i&1) != 0) { ptr1--; ptr2 -= xsiz; swapchar(ptr1,ptr2); }
+                for(j=(i>>1)-1;j>=0;j--)
+				{ ptr1 -= 2; ptr2 -= k; swapchar2(ptr1,ptr2,xsiz); }
+            }
+        }
+    }
+    
+    
+    void preparemirror(int32_t dax, int32_t day, int32_t daz,
+                       short daang, int32_t dahoriz, short dawall,
+                       short dasector, int32_t *tposx, int32_t *tposy,
+                       short *tang)
+    {
+        int32_t i, j, x, y, dx, dy;
+        
+        x = wall[dawall].x; dx = wall[wall[dawall].point2].x-x;
+        y = wall[dawall].y; dy = wall[wall[dawall].point2].y-y;
+        j = dx*dx + dy*dy; if (j == 0) return;
+        i = (((dax-x)*dx + (day-y)*dy)<<1);
+        *tposx = (x<<1) + scale(dx,i,j) - dax;
+        *tposy = (y<<1) + scale(dy,i,j) - day;
+        *tang = (((getangle(dx,dy)<<1)-daang)&2047);
+        
+        inpreparemirror = 1;
+    }
+    
+    
+    void completemirror(void)
+    {
+        int32_t i, dy, p;
+        
+		/* Can't reverse with uninitialized data */
+        if (inpreparemirror) { inpreparemirror = 0; return; }
+        if (mirrorsx1 > 0) mirrorsx1--;
+        if (mirrorsx2 < windowx2-windowx1-1) mirrorsx2++;
+        if (mirrorsx2 < mirrorsx1) return;
+        
+        transarea += (mirrorsx2-mirrorsx1)*(windowy2-windowy1);
+        
+        p = frameplace+ylookup[windowy1+mirrorsy1]+windowx1+mirrorsx1;
+        i = windowx2-windowx1-mirrorsx2-mirrorsx1; mirrorsx2 -= mirrorsx1;
+        // FIX_00085: Optimized Video driver. FPS increases by +20%.
+        for(dy=mirrorsy2-mirrorsy1-1;dy>=0;dy--)
+        {
+            copybufbyte((void *)(p),tempbuf,mirrorsx2+1);
+            tempbuf[mirrorsx2] = tempbuf[mirrorsx2-1];
+            copybufreverse(&tempbuf[mirrorsx2],(void *)(p+i),mirrorsx2+1);
+            p += ylookup[1];
+            faketimerhandler();
+        }
+    }
+    
+    
+    int sectorofwall(short theline)
+    {
+        int32_t i, gap;
+        
+        if ((theline < 0) || (theline >= numwalls)) return(-1);
+        i = wall[theline].nextwall; if (i >= 0) return(wall[i].nextsector);
+        
+        gap = (numsectors>>1); i = gap;
+        while (gap > 1)
+        {
+            gap >>= 1;
+            if (sector[i].wallptr < theline) i += gap; else i -= gap;
+        }
+        while (sector[i].wallptr > theline) i--;
+        while (sector[i].wallptr+sector[i].wallnum <= theline) i++;
+        return(i);
+    }
+    
+    
+    int getceilzofslope(short sectnum, int32_t dax, int32_t day)
+    {
+        int32_t dx, dy, i, j;
+        walltype *wal;
+        
+        if (!(sector[sectnum].ceilingstat&2)) return(sector[sectnum].ceilingz);
+        wal = &wall[sector[sectnum].wallptr];
+        dx = wall[wal->point2].x-wal->x; dy = wall[wal->point2].y-wal->y;
+        i = (nsqrtasm(dx*dx+dy*dy)<<5); if (i == 0) return(sector[sectnum].ceilingz);
+        j = dmulscale3(dx,day-wal->y,-dy,dax-wal->x);
+        return(sector[sectnum].ceilingz+scale(sector[sectnum].ceilingheinum,j,i));
+    }
+    
+    
+    int getflorzofslope(short sectnum, int32_t dax, int32_t day)
+    {
+        int32_t dx, dy, i, j;
+        walltype *wal;
+        
+        if (!(sector[sectnum].floorstat&2)) return(sector[sectnum].floorz);
+        wal = &wall[sector[sectnum].wallptr];
+        dx = wall[wal->point2].x-wal->x; dy = wall[wal->point2].y-wal->y;
+        i = (nsqrtasm(dx*dx+dy*dy)<<5); if (i == 0) return(sector[sectnum].floorz);
+        j = dmulscale3(dx,day-wal->y,-dy,dax-wal->x);
+        return(sector[sectnum].floorz+scale(sector[sectnum].floorheinum,j,i));
+    }
+    
+    
+    void getzsofslope(short sectnum, int32_t dax, int32_t day, int32_t *ceilz, int32_t *florz)
+    {
+        int32_t dx, dy, i, j;
+        walltype *wal, *wal2;
+        sectortype *sec;
+        
+        sec = &sector[sectnum];
+        *ceilz = sec->ceilingz; *florz = sec->floorz;
+        if ((sec->ceilingstat|sec->floorstat)&2)
+        {
+            wal = &wall[sec->wallptr]; wal2 = &wall[wal->point2];
+            dx = wal2->x-wal->x; dy = wal2->y-wal->y;
+            i = (nsqrtasm(dx*dx+dy*dy)<<5); if (i == 0) return;
+            j = dmulscale3(dx,day-wal->y,-dy,dax-wal->x);
+            if (sec->ceilingstat&2) *ceilz = (*ceilz)+scale(sec->ceilingheinum,j,i);
+            if (sec->floorstat&2) *florz = (*florz)+scale(sec->floorheinum,j,i);
+        }
+    }
+    
+    
+    void alignceilslope(short dasect, int32_t x, int32_t y, int32_t z)
+    {
+        int32_t i, dax, day;
+        walltype *wal;
+        
+        wal = &wall[sector[dasect].wallptr];
+        dax = wall[wal->point2].x-wal->x;
+        day = wall[wal->point2].y-wal->y;
+        
+        i = (y-wal->y)*dax - (x-wal->x)*day; if (i == 0) return;
+        sector[dasect].ceilingheinum = scale((z-sector[dasect].ceilingz)<<8,
+                                             nsqrtasm(dax*dax+day*day),i);
+        
+        if (sector[dasect].ceilingheinum == 0) sector[dasect].ceilingstat &= ~2;
+        else sector[dasect].ceilingstat |= 2;
+    }
+    
+    
+    void alignflorslope(short dasect, int32_t x, int32_t y, int32_t z)
+    {
+        int32_t i, dax, day;
+        walltype *wal;
+        
+        wal = &wall[sector[dasect].wallptr];
+        dax = wall[wal->point2].x-wal->x;
+        day = wall[wal->point2].y-wal->y;
+        
+        i = (y-wal->y)*dax - (x-wal->x)*day; if (i == 0) return;
+        sector[dasect].floorheinum = scale((z-sector[dasect].floorz)<<8,
+                                           nsqrtasm(dax*dax+day*day),i);
+        
+        if (sector[dasect].floorheinum == 0) sector[dasect].floorstat &= ~2;
+        else sector[dasect].floorstat |= 2;
+    }
+    
+    
+    int loopnumofsector(short sectnum, short wallnum)
+    {
+        int32_t i, numloops, startwall, endwall;
+        
+        numloops = 0;
+        startwall = sector[sectnum].wallptr;
+        endwall = startwall + sector[sectnum].wallnum;
+        for(i=startwall;i<endwall;i++)
+        {
+            if (i == wallnum) return(numloops);
+            if (wall[i].point2 < i) numloops++;
+        }
+        return(-1);
+    }
+    
+    
+    void setfirstwall(short sectnum, short newfirstwall)
+    {
+        int32_t i, j, k, numwallsofloop;
+        int32_t startwall, endwall, danumwalls, dagoalloop;
+        
+        startwall = sector[sectnum].wallptr;
+        danumwalls = sector[sectnum].wallnum;
+        endwall = startwall+danumwalls;
+        if ((newfirstwall < startwall) || (newfirstwall >= startwall+danumwalls)) return;
+        for(i=0;i<danumwalls;i++)
+            memcpy(&wall[i+numwalls],&wall[i+startwall],sizeof(walltype));
+        
+        numwallsofloop = 0;
+        i = newfirstwall;
+        do
+        {
+            numwallsofloop++;
+            i = wall[i].point2;
+        } while (i != newfirstwall);
+        
 		/* Put correct loop at beginning */
-	dagoalloop = loopnumofsector(sectnum,newfirstwall);
-	if (dagoalloop > 0)
-	{
-		j = 0;
-		while (loopnumofsector(sectnum,j+startwall) != dagoalloop) j++;
-		for(i=0;i<danumwalls;i++)
-		{
-			k = i+j; if (k >= danumwalls) k -= danumwalls;
-			memcpy(&wall[startwall+i],&wall[numwalls+k],sizeof(walltype));
-
-			wall[startwall+i].point2 += danumwalls-startwall-j;
-			if (wall[startwall+i].point2 >= danumwalls)
-				wall[startwall+i].point2 -= danumwalls;
-			wall[startwall+i].point2 += startwall;
-		}
-		newfirstwall += danumwalls-j;
-		if (newfirstwall >= startwall+danumwalls) newfirstwall -= danumwalls;
-	}
-
-	for(i=0;i<numwallsofloop;i++)
-		memcpy(&wall[i+numwalls],&wall[i+startwall],sizeof(walltype));
-	for(i=0;i<numwallsofloop;i++)
-	{
-		k = i+newfirstwall-startwall;
-		if (k >= numwallsofloop) k -= numwallsofloop;
-		memcpy(&wall[startwall+i],&wall[numwalls+k],sizeof(walltype));
-
-		wall[startwall+i].point2 += numwallsofloop-newfirstwall;
-		if (wall[startwall+i].point2 >= numwallsofloop)
-			wall[startwall+i].point2 -= numwallsofloop;
-		wall[startwall+i].point2 += startwall;
-	}
-
-	for(i=startwall;i<endwall;i++)
-		if (wall[i].nextwall >= 0) wall[wall[i].nextwall].nextwall = i;
-}
-
-/* end of engine.c ... */
-
-
+        dagoalloop = loopnumofsector(sectnum,newfirstwall);
+        if (dagoalloop > 0)
+        {
+            j = 0;
+            while (loopnumofsector(sectnum,j+startwall) != dagoalloop) j++;
+            for(i=0;i<danumwalls;i++)
+            {
+                k = i+j; if (k >= danumwalls) k -= danumwalls;
+                memcpy(&wall[startwall+i],&wall[numwalls+k],sizeof(walltype));
+                
+                wall[startwall+i].point2 += danumwalls-startwall-j;
+                if (wall[startwall+i].point2 >= danumwalls)
+                    wall[startwall+i].point2 -= danumwalls;
+                wall[startwall+i].point2 += startwall;
+            }
+            newfirstwall += danumwalls-j;
+            if (newfirstwall >= startwall+danumwalls) newfirstwall -= danumwalls;
+        }
+        
+        for(i=0;i<numwallsofloop;i++)
+            memcpy(&wall[i+numwalls],&wall[i+startwall],sizeof(walltype));
+        for(i=0;i<numwallsofloop;i++)
+        {
+            k = i+newfirstwall-startwall;
+            if (k >= numwallsofloop) k -= numwallsofloop;
+            memcpy(&wall[startwall+i],&wall[numwalls+k],sizeof(walltype));
+            
+            wall[startwall+i].point2 += numwallsofloop-newfirstwall;
+            if (wall[startwall+i].point2 >= numwallsofloop)
+                wall[startwall+i].point2 -= numwallsofloop;
+            wall[startwall+i].point2 += startwall;
+        }
+        
+        for(i=startwall;i<endwall;i++)
+            if (wall[i].nextwall >= 0) wall[wall[i].nextwall].nextwall = i;
+    }
+    
+    /* end of engine.c ... */
+    
+