From 036750d1a444d370034ddc93068a0fb02d2c29a1 Mon Sep 17 00:00:00 2001
From: johns <>
Date: Sat, 27 May 2000 19:49:33 +0000
Subject: [PATCH] More video cleanup.

---
 doc/ChangeLog.html          |   4 +-
 src/include/new_video.h     |  10 +
 src/include/player.h        |   6 +-
 src/map/map_draw.cpp        | 740 ++++++++++++++++++++++++------------
 src/map/map_fog.cpp         | 630 ++++++++++++++++++++++++------
 src/network/new_network.cpp |   4 +-
 src/stratagus/player.cpp    |  64 ++--
 src/video/X11.cpp           |   2 +
 src/video/new_video.cpp     |  57 ++-
 src/video/sdl.cpp           |   4 +
 src/video/svgalib.cpp       |   4 +
 11 files changed, 1121 insertions(+), 404 deletions(-)

diff --git a/doc/ChangeLog.html b/doc/ChangeLog.html
index 0c280d9f8..dd1c97ce3 100644
--- a/doc/ChangeLog.html
+++ b/doc/ChangeLog.html
@@ -483,7 +483,7 @@
     <LI>Fixed bug: can't upgrade axe-thrower to berserker.
     <LI>Heading code rewritten.
     <LI>Missile code rewritten.
-    <LI>Fixed bug: Building are not buring correct.
+    <LI>Fixed bug: Building are not burning correct.
     <LI>Burning buildings now play burning sound if selected.
     <LI>'Q' is now the quit key, 'q' works no longer.
     <LI>Fixed bug: Attack ground didn't work.
@@ -494,6 +494,8 @@
     <LI>Fixed bug: cancel gives back more than the unit/upgrade has cost.
     <LI>Network code finished, most bugs found, works now with firewalls.
     <LI>Fixed bug: Placement and removement of oil patch from David Slimp.
+    <LI>Cleanup of video code.
+    <LI>Fixed bug: Now starts if compiled without sound and with CCl. 
     <LI>+++
     </UL>
 
diff --git a/src/include/new_video.h b/src/include/new_video.h
index 36752336d..ef63c1951 100644
--- a/src/include/new_video.h
+++ b/src/include/new_video.h
@@ -495,6 +495,16 @@ extern void VideoFillRectangle(SysColors color,int x,int y
     */
 extern void SetClipping(int left,int top,int right,int bottom);
 
+    /**
+    **	Push current clipping.
+    */
+extern void PushClipping(void);
+
+    /**
+    **	Pop current clipping.
+    */
+extern void PopClipping(void);
+
     /**
     **	Load a picture and display it on the screen (full screen),
     **	changing the colormap and so on..
diff --git a/src/include/player.h b/src/include/player.h
index 723bec0f8..b2d6c6a80 100644
--- a/src/include/player.h
+++ b/src/include/player.h
@@ -196,13 +196,17 @@ extern void PlayersEachFrame(void);
     /// FIXME: write short docu
 extern void PlayersEachSecond(void);
 
+#ifdef NEW_VIDEO
     /// Change current color set to new player.
 extern void PlayerPixels(const Player* player);
 
     /// Change current color set to new player of the sprite
-#ifdef NEW_VIDEO
 extern void GraphicPlayerPixels(const Player* player, const Graphic * sprite);
 #else
+    /// Change current color set to new player.
+extern void PlayerPixels(const Player* player);
+
+    /// Change current color set to new player of the sprite
 extern void RLEPlayerPixels(const Player* player, const RleSprite * sprite);
 #endif
 
diff --git a/src/map/map_draw.cpp b/src/map/map_draw.cpp
index 406352aab..dd0926801 100644
--- a/src/map/map_draw.cpp
+++ b/src/map/map_draw.cpp
@@ -142,7 +142,7 @@ global void (*MapDrawTile)(int,int,int);
 #define GRID_SUB	0
 #endif
 
-// FIXME: Johns: More to come: scaling, 64x64 tiles...
+// FIXME: Johns: More to come: zooming, scaling, 64x64 tiles...
 
 /**
 **	Do unroll 8x
@@ -160,6 +160,14 @@ global void (*MapDrawTile)(int,int,int);
     UNROLL8((x)+ 0);	\
     UNROLL8((x)+ 8)
 
+/**
+**	Do unroll 24x
+*/
+#define UNROLL24(x)	\
+    UNROLL8((x)+ 0);	\
+    UNROLL8((x)+ 8);	\
+    UNROLL8((x)+16)
+
 /**
 **	Do unroll 32x
 */
@@ -174,8 +182,9 @@ global void (*MapDrawTile)(int,int,int);
 ----------------------------------------------------------------------------*/
 
 /**
-**	Fast draw 32x32 tile for 32 bpp video modes.
+**	Fast draw 32x32 tile for 8 bpp video modes.
 **
+**	@param graphic	Graphic structure for the tile
 **	@param data	pointer to tile graphic data
 **	@param x	X position into video memory
 **	@param y	Y position into video memory
@@ -185,27 +194,27 @@ global void (*MapDrawTile)(int,int,int);
 **
 **	@see GRID
 */
-global void VideoDraw32Tile32(const unsigned char* data,int x,int y)
+global void VideoDraw8Tile32(const unsigned char* data,int x,int y)
 {
     const unsigned char* sp;
     const unsigned char* ep;
-    VMemType32* dp;
+    VMemType8* dp;
     int da;
 
     sp=data;
     ep=sp+TileSizeY*TileSizeX-GRID_SUB;
     da=VideoWidth;
-    dp=VideoMemory32+x+y*VideoWidth;
+    dp=VideoMemory8+x+y*VideoWidth;
 
     while( sp<ep ) {			// loop unrolled
 #undef UNROLL2
 #define UNROLL2(x)		\
-	dp[x+0]=((VMemType32*)TheMap.TileData->Pixels)[sp[x+0]];	\
-	dp[x+1]=((VMemType32*)TheMap.TileData->Pixels)[sp[x+1]]
+	dp[x+0]=((VMemType8*)TheMap.TileData->Pixels)[sp[x+0]];	\
+	dp[x+1]=((VMemType8*)TheMap.TileData->Pixels)[sp[x+1]]
 
 	UNROLL32(0);
 #if GRID==1
-	dp[31]=((VMemType32*)TheMap.TileData->Pixels)[0];
+	dp[31]=((VMemType8*)TheMap.TileData->Pixels)[0];
 #endif
 	sp+=TileSizeX;
 	dp+=da;
@@ -213,7 +222,7 @@ global void VideoDraw32Tile32(const unsigned char* data,int x,int y)
 
 #if GRID==1
     for( da=TileSizeX; da--; ) {	// with grid no need to be fast
-	dp[da]=((VMemType32*)TheMap.TileData->Pixels)[0];
+	dp[da]=((VMemType8*)TheMap.TileData->Pixels)[0];
     }
 #endif
 }
@@ -273,7 +282,7 @@ global void VideoDraw16Tile32(const unsigned char* data,int x,int y)
 }
 
 /**
-**	Fast draw 32x32 tile for 8 bpp video modes.
+**	Fast draw 32x32 tile for 24 bpp video modes.
 **
 **	@param graphic	Graphic structure for the tile
 **	@param data	pointer to tile graphic data
@@ -285,66 +294,22 @@ global void VideoDraw16Tile32(const unsigned char* data,int x,int y)
 **
 **	@see GRID
 */
-global void VideoDraw8Tile32(const unsigned char* data,int x,int y)
+global void VideoDraw24Tile32(const unsigned char* data,int x,int y)
 {
     const unsigned char* sp;
     const unsigned char* ep;
-    VMemType8* dp;
+    VMemType24* dp;
     int da;
 
     sp=data;
     ep=sp+TileSizeY*TileSizeX-GRID_SUB;
     da=VideoWidth;
-    dp=VideoMemory8+x+y*VideoWidth;
-
-    while( sp<ep ) {			// loop unrolled
-#undef UNROLL2
-#define UNROLL2(x)		\
-	dp[x+0]=((VMemType8*)TheMap.TileData->Pixels)[sp[x+0]];	\
-	dp[x+1]=((VMemType8*)TheMap.TileData->Pixels)[sp[x+1]]
-
-	UNROLL32(0);
-#if GRID==1
-	dp[31]=((VMemType8*)TheMap.TileData->Pixels)[0];
-#endif
-	sp+=TileSizeX;
-	dp+=da;
-    }
-
-#if GRID==1
-    for( da=TileSizeX; da--; ) {	// with grid no need to be fast
-	dp[da]=((VMemType8*)TheMap.TileData->Pixels)[0];
-    }
-#endif
-}
-
-/*----------------------------------------------------------------------------
---	Draw tile with zoom
-----------------------------------------------------------------------------*/
-
-/**
-**	Fast draw 32x32 tile for 16 bpp video modes.
-**
-**	@param graphic	Graphic structure for the tile
-**	@param data	pointer to tile graphic data
-**	@param x	X position into video memory
-**	@param y	Y position into video memory
-**
-**	@see GRID
-*/
-global void VideoDraw16Tile32Zoom(const unsigned char* data,int x,int y)
-{
-    const unsigned char* sp;
-    const unsigned char* ep;
-    VMemType16* dp;
-    int da;
-
-    sp=data;
-    ep=sp+TileSizeY*TileSizeX-GRID_SUB;
-    da=VideoWidth;
-    dp=VideoMemory16+x+y*VideoWidth;
+    dp=VideoMemory24+x+y*VideoWidth;
 
     IfDebug( 
+	if( ((long)sp)&1 ) {
+	    DebugLevel0("Not aligned memory\n");
+	}
 	if( ((long)dp)&3 ) {
 	    DebugLevel0("Not aligned memory\n");
 	}
@@ -353,7 +318,8 @@ global void VideoDraw16Tile32Zoom(const unsigned char* data,int x,int y)
     while( sp<ep ) {			// loop unrolled
 #undef UNROLL2
 #define UNROLL2(x)		\
-	*(unsigned int*)(dp+x+0)=PixelsLow[sp[x+0]]|PixelsHigh[sp[x+1]]
+	dp[x+0]=((VMemType24*)TheMap.TileData->Pixels)[sp[x+0]];	\
+	dp[x+1]=((VMemType24*)TheMap.TileData->Pixels)[sp[x+1]]
 
 	UNROLL32(0);
 #if GRID==1
@@ -370,73 +336,65 @@ global void VideoDraw16Tile32Zoom(const unsigned char* data,int x,int y)
 #endif
 }
 
-/*----------------------------------------------------------------------------
---	Cache
-----------------------------------------------------------------------------*/
-
-#ifdef USE_TILECACHE
-
-#if 0
-// This function is currently unused.
-
 /**
-**	Draw 32x32 tile for 16 bpp video modes into cache.
+**	Fast draw 32x32 tile for 32 bpp video modes.
 **
-**	@param graphic	Graphic structure for the tile
-**	@param cache	Cache to fill with tile
+**	@param data	pointer to tile graphic data
+**	@param x	X position into video memory
+**	@param y	Y position into video memory
 **
 **	This is a hot spot in the program.
+**	(50% cpu time was needed for this, now only 32%)
 **
 **	@see GRID
 */
-local void FillCache16WithTile32(const unsigned char* data,VMemType16* cache)
+global void VideoDraw32Tile32(const unsigned char* data,int x,int y)
 {
     const unsigned char* sp;
     const unsigned char* ep;
-    VMemType16* dp;
+    VMemType32* dp;
+    int da;
 
     sp=data;
     ep=sp+TileSizeY*TileSizeX-GRID_SUB;
-    dp=cache;
-
-    IfDebug( 
-	if( ((long)sp)&1 ) {
-	    DebugLevel0("Not aligned memory\n");
-	}
-
-	if( ((long)dp)&3 ) {
-	    DebugLevel0("Not aligned memory\n");
-	}
-    );
+    da=VideoWidth;
+    dp=VideoMemory32+x+y*VideoWidth;
 
     while( sp<ep ) {			// loop unrolled
 #undef UNROLL2
 #define UNROLL2(x)		\
-	*(unsigned int*)(dp+x+0)=PixelsLow[sp[x+0]]|PixelsHigh[sp[x+1]]
+	dp[x+0]=((VMemType32*)TheMap.TileData->Pixels)[sp[x+0]];	\
+	dp[x+1]=((VMemType32*)TheMap.TileData->Pixels)[sp[x+1]]
 
 	UNROLL32(0);
 #if GRID==1
-	dp[31]=Pixels[0];
+	dp[31]=((VMemType32*)TheMap.TileData->Pixels)[0];
 #endif
 	sp+=TileSizeX;
-	dp+=TileSizeX;
+	dp+=da;
     }
 
 #if GRID==1
-    if( 1 ) {
-	int i;
-
-	for( i=TileSizeX; i--; ) {	// no need to be fast with grid
-	    dp[i]=Pixels[0];
-	}
+    for( da=TileSizeX; da--; ) {	// with grid no need to be fast
+	dp[da]=((VMemType32*)TheMap.TileData->Pixels)[0];
     }
 #endif
 }
 
-#endif
+/*----------------------------------------------------------------------------
+--	Draw tile with zoom
+----------------------------------------------------------------------------*/
+
+// FIXME: write this
+
+/*----------------------------------------------------------------------------
+--	Cache
+----------------------------------------------------------------------------*/
+
+#ifdef USE_TILECACHE	// {
 
 /**
-**	Draw 32x32 tile for 32 bpp video modes into cache and video memory.
+**	Draw 32x32 tile for 8 bpp video modes into cache and video memory.
 **
 **	@param graphic	Graphic structure for the tile
 **	@param cache	Cache to fill with tile
@@ -447,22 +405,22 @@ local void FillCache16WithTile32(const unsigned char* data,VMemType16* cache)
 **
 **	@see GRID
 */
-local void FillCache32AndDraw32(const unsigned char* data,VMemType32* cache
+local void FillCache8AndDraw32(const unsigned char* data,VMemType8* cache
 	,int x,int y)
 {
     const unsigned char* sp;
     const unsigned char* ep;
     int va;
-    VMemType32* dp;
-    VMemType32* vp;
+    VMemType8* dp;
+    VMemType8* vp;
 
     sp=data;
     ep=sp+TileSizeY*TileSizeX-GRID_SUB;
     dp=cache;
     va=VideoWidth;
-    vp=VideoMemory32+x+y*VideoWidth;
+    vp=VideoMemory8+x+y*VideoWidth;
 
-    IfDebug( 
+    IfDebug(
 	if( ((long)sp)&1 ) {
 	    DebugLevel0("Not aligned memory\n");
 	}
@@ -477,12 +435,12 @@ local void FillCache32AndDraw32(const unsigned char* data,VMemType32* cache
     while( sp<ep ) {			// loop unrolled
 #undef UNROLL2
 #define UNROLL2(x)	\
-	vp[x+0]=dp[x+0]=((VMemType32*)TheMap.TileData->Pixels)[sp[x+0]];	\
-	vp[x+0]=dp[x+1]=((VMemType32*)TheMap.TileData->Pixels)[sp[x+1]]
+	vp[x+0]=dp[x+0]=((VMemType8*)TheMap.TileData->Pixels)[sp[x+0]];	\
+	vp[x+0]=dp[x+1]=((VMemType8*)TheMap.TileData->Pixels)[sp[x+1]]
 
 	UNROLL32(0);
 #if GRID==1
-	vp[31]=dp[31]=((VMemType32*)TheMap.TileData->Pixels)[0];
+	vp[31]=dp[31]=((VMemType8*)TheMap.TileData->Pixels)[0];
 #endif
 	vp+=va;
 	sp+=TileSizeX;
@@ -491,7 +449,7 @@ local void FillCache32AndDraw32(const unsigned char* data,VMemType32* cache
 
 #if GRID==1
     for( va=TileSizeX; va--; ) {	// no need to be fast with grid
-	vp[va]=dp[va]=((VMemType32*)TheMap.TileData->Pixels)[0];
+	vp[va]=dp[va]=((VMemType8*)TheMap.TileData->Pixels)[0];
     }
 #endif
 }
@@ -558,7 +516,7 @@ local void FillCache16AndDraw32(const unsigned char* data,VMemType16* cache
 }
 
 /**
-**	Draw 32x32 tile for 8 bpp video modes into cache and video memory.
+**	Draw 32x32 tile for 24 bpp video modes into cache and video memory.
 **
 **	@param graphic	Graphic structure for the tile
 **	@param cache	Cache to fill with tile
@@ -569,22 +527,22 @@ local void FillCache16AndDraw32(const unsigned char* data,VMemType16* cache
 **
 **	@see GRID
 */
-local void FillCache8AndDraw32(const unsigned char* data,VMemType8* cache
+local void FillCache24AndDraw32(const unsigned char* data,VMemType24* cache
 	,int x,int y)
 {
     const unsigned char* sp;
     const unsigned char* ep;
     int va;
-    VMemType8* dp;
-    VMemType8* vp;
+    VMemType24* dp;
+    VMemType24* vp;
 
     sp=data;
     ep=sp+TileSizeY*TileSizeX-GRID_SUB;
     dp=cache;
     va=VideoWidth;
-    vp=VideoMemory8+x+y*VideoWidth;
+    vp=VideoMemory24+x+y*VideoWidth;
 
-    IfDebug(
+    IfDebug( 
 	if( ((long)sp)&1 ) {
 	    DebugLevel0("Not aligned memory\n");
 	}
@@ -599,12 +557,12 @@ local void FillCache8AndDraw32(const unsigned char* data,VMemType8* cache
     while( sp<ep ) {			// loop unrolled
 #undef UNROLL2
 #define UNROLL2(x)	\
-	vp[x+0]=dp[x+0]=((VMemType8*)TheMap.TileData->Pixels)[sp[x+0]];	\
-	vp[x+0]=dp[x+1]=((VMemType8*)TheMap.TileData->Pixels)[sp[x+1]]
+	vp[x+0]=dp[x+0]=((VMemType24*)TheMap.TileData->Pixels)[sp[x+0]]; \
+	vp[x+0]=dp[x+1]=((VMemType24*)TheMap.TileData->Pixels)[sp[x+1]]
 
 	UNROLL32(0);
 #if GRID==1
-	vp[31]=dp[31]=((VMemType8*)TheMap.TileData->Pixels)[0];
+	vp[31]=dp[31]=((VMemType24*)TheMap.TileData->Pixels)[0];
 #endif
 	vp+=va;
 	sp+=TileSizeX;
@@ -613,11 +571,198 @@ local void FillCache8AndDraw32(const unsigned char* data,VMemType8* cache
 
 #if GRID==1
     for( va=TileSizeX; va--; ) {	// no need to be fast with grid
-	vp[va]=dp[va]=((VMemType8*)TheMap.TileData->Pixels)[0];
+	vp[va]=dp[va]=((VMemType24*)TheMap.TileData->Pixels)[0];
     }
 #endif
 }
 
+/**
+**	Draw 32x32 tile for 32 bpp video modes into cache and video memory.
+**
+**	@param graphic	Graphic structure for the tile
+**	@param cache	Cache to fill with tile
+**	@param x	X position into video memory
+**	@param y	Y position into video memory
+**
+**	This is a hot spot in the program.
+**
+**	@see GRID
+*/
+local void FillCache32AndDraw32(const unsigned char* data,VMemType32* cache
+	,int x,int y)
+{
+    const unsigned char* sp;
+    const unsigned char* ep;
+    int va;
+    VMemType32* dp;
+    VMemType32* vp;
+
+    sp=data;
+    ep=sp+TileSizeY*TileSizeX-GRID_SUB;
+    dp=cache;
+    va=VideoWidth;
+    vp=VideoMemory32+x+y*VideoWidth;
+
+    IfDebug( 
+	if( ((long)sp)&1 ) {
+	    DebugLevel0("Not aligned memory\n");
+	}
+	if( ((long)dp)&3 ) {
+	    DebugLevel0("Not aligned memory\n");
+	}
+	if( ((long)vp)&3 ) {
+	    DebugLevel0("Not aligned video memory\n");
+	}
+    );
+
+    while( sp<ep ) {			// loop unrolled
+#undef UNROLL2
+#define UNROLL2(x)	\
+	vp[x+0]=dp[x+0]=((VMemType32*)TheMap.TileData->Pixels)[sp[x+0]]; \
+	vp[x+0]=dp[x+1]=((VMemType32*)TheMap.TileData->Pixels)[sp[x+1]]
+
+	UNROLL32(0);
+#if GRID==1
+	vp[31]=dp[31]=((VMemType32*)TheMap.TileData->Pixels)[0];
+#endif
+	vp+=va;
+	sp+=TileSizeX;
+	dp+=TileSizeX;
+    }
+
+#if GRID==1
+    for( va=TileSizeX; va--; ) {	// no need to be fast with grid
+	vp[va]=dp[va]=((VMemType32*)TheMap.TileData->Pixels)[0];
+    }
+#endif
+}
+
+// ---------------------------------------------------------------------------
+
+/**
+**	Fast draw 32x32 tile from cache for 8bpp.
+**
+**	@param graphic	Pointer to cached tile graphic
+**	@param x	X position into video memory
+**	@param y	Y position into video memory
+**
+**	@see GRID
+*/
+local void VideoDraw8Tile32FromCache(const VMemType8* graphic,int x,int y)
+{
+    const VMemType8* sp;
+    const VMemType8* ep;
+    VMemType8* dp;
+    int da;
+
+    sp=graphic;
+    ep=sp+TileSizeY*TileSizeX;
+    da=VideoWidth;
+    dp=VideoMemory8+x+y*VideoWidth;
+
+    IfDebug(
+	if( ((long)dp)&3 ) {
+	    DebugLevel0("Not aligned memory\n");
+	}
+	if( ((long)sp)&3 ) {
+	    DebugLevel0("Not aligned memory\n");
+	}
+    );
+
+    while( sp<ep ) {			// loop unrolled
+#undef UNROLL2
+#define UNROLL2(x)		\
+	*(unsigned long*)(dp+x)=*(unsigned long*)(sp+x)
+
+	UNROLL16(0);
+	sp+=TileSizeX;
+	dp+=da;
+    }
+}
+
+/**
+**	Fast draw 32x32 tile from cache for 16bpp.
+**
+**	@param graphic	Pointer to cached tile graphic
+**	@param x	X position into video memory
+**	@param y	Y position into video memory
+**
+**	@see GRID
+*/
+local void VideoDraw16Tile32FromCache(const VMemType16* graphic,int x,int y)
+{
+    const VMemType16* sp;
+    const VMemType16* ep;
+    VMemType16* dp;
+    int da;
+
+    sp=graphic;
+    ep=sp+TileSizeY*TileSizeX;
+    da=VideoWidth;
+    dp=VideoMemory16+x+y*VideoWidth;
+
+    IfDebug(
+	if( ((long)dp)&3 ) {
+	    DebugLevel0("Not aligned memory\n");
+	}
+	if( ((long)sp)&3 ) {
+	    DebugLevel0("Not aligned memory\n");
+	}
+    );
+
+    while( sp<ep ) {			// loop unrolled
+#undef UNROLL2
+#define UNROLL2(x)		\
+	*(unsigned long*)(dp+x)=*(unsigned long*)(sp+x)
+
+	UNROLL32(0);
+	sp+=TileSizeX;
+	dp+=da;
+    }
+}
+
+/**
+**	Fast draw 32x32 tile from cache for 24bpp.
+**
+**	@param graphic	Pointer to cached tile graphic
+**	@param x	X position into video memory
+**	@param y	Y position into video memory
+**
+**	@see GRID
+*/
+local void VideoDraw24Tile32FromCache(const VMemType24* graphic,int x,int y)
+{
+    const VMemType24* sp;
+    const VMemType24* ep;
+    VMemType24* dp;
+    int da;
+
+    sp=graphic;
+    ep=sp+TileSizeY*TileSizeX;
+    da=VideoWidth;
+    dp=VideoMemory24+x+y*VideoWidth;
+
+    IfDebug(
+	if( ((long)dp)&3 ) {
+	    DebugLevel0("Not aligned memory\n");
+	}
+	if( ((long)sp)&3 ) {
+	    DebugLevel0("Not aligned memory\n");
+	}
+    );
+
+    while( sp<ep ) {			// loop unrolled
+#undef UNROLL2
+#define UNROLL2(x)		\
+	*(unsigned long*)(dp+x*2+0)=*(unsigned long*)(sp+x*2+0);	\
+	*(unsigned long*)(dp+x*2+1)=*(unsigned long*)(sp+x*2+1)
+
+	UNROLL24(0);
+	sp+=TileSizeX;
+	dp+=da;
+    }
+}
+
 /**
 **	Fast draw 32x32 tile from cache.
 **
@@ -660,96 +805,16 @@ local void VideoDraw32Tile32FromCache(const VMemType32* graphic,int x,int y)
     }
 }
 
-/**
-**	Fast draw 32x32 tile from cache.
-**
-**	@param graphic	Pointer to cached tile graphic
-**	@param x	X position into video memory
-**	@param y	Y position into video memory
-**
-**	@see GRID
-*/
-local void VideoDraw16Tile32FromCache(const VMemType16* graphic,int x,int y)
-{
-    const VMemType16* sp;
-    const VMemType16* ep;
-    VMemType16* dp;
-    int da;
-
-    sp=graphic;
-    ep=sp+TileSizeY*TileSizeX;
-    da=VideoWidth;
-    dp=VideoMemory16+x+y*VideoWidth;
-
-    IfDebug(
-	if( ((long)dp)&3 ) {
-	    DebugLevel0("Not aligned memory\n");
-	}
-	if( ((long)sp)&3 ) {
-	    DebugLevel0("Not aligned memory\n");
-	}
-    );
-
-    while( sp<ep ) {			// loop unrolled
-#undef UNROLL2
-#define UNROLL2(x)		\
-	*(unsigned long*)(dp+x)=*(unsigned long*)(sp+x)
-
-	UNROLL32(0);
-	sp+=TileSizeX;
-	dp+=da;
-    }
-}
+// ---------------------------------------------------------------------------
 
 /**
-**	Fast draw 32x32 tile from cache.
-**
-**	@param graphic	Pointer to cached tile graphic
-**	@param x	X position into video memory
-**	@param y	Y position into video memory
-**
-**	@see GRID
-*/
-local void VideoDraw8Tile32FromCache(const VMemType8* graphic,int x,int y)
-{
-    const VMemType8* sp;
-    const VMemType8* ep;
-    VMemType8* dp;
-    int da;
-
-    sp=graphic;
-    ep=sp+TileSizeY*TileSizeX;
-    da=VideoWidth;
-    dp=VideoMemory8+x+y*VideoWidth;
-
-    IfDebug(
-	if( ((long)dp)&3 ) {
-	    DebugLevel0("Not aligned memory\n");
-	}
-	if( ((long)sp)&3 ) {
-	    DebugLevel0("Not aligned memory\n");
-	}
-    );
-
-    while( sp<ep ) {			// loop unrolled
-#undef UNROLL2
-#define UNROLL2(x)		\
-	*(unsigned long*)(dp+x)=*(unsigned long*)(sp+x)
-
-	UNROLL16(0);
-	sp+=TileSizeX;
-	dp+=da;
-    }
-}
-
-/**
-**	Draw 32x32 tile for 32 bpp video modes with cache support.
+**	Draw 32x32 tile for 8 bpp video modes with cache support.
 **
 **	@param tile	Tile number to draw.
 **	@param x	X position into video memory
 **	@param y	Y position into video memory
 */
-local void MapDraw32Tile32(int tile,int x,int y)
+local void MapDraw8Tile32(int tile,int x,int y)
 {
     TileCache* cache;
 
@@ -761,7 +826,7 @@ local void MapDraw32Tile32(int tile,int x,int y)
 	    --TileCacheSize;
 	    cache=malloc(
 		    sizeof(TileCache)-sizeof(unsigned char)+
-		    TileSizeX*TileSizeY*sizeof(VMemType32));
+		    TileSizeX*TileSizeY*sizeof(VMemType16));
 	} else {
 	    cache=(void*)TileCacheLRU->last;
 	    if( cache->Tile ) {
@@ -774,9 +839,9 @@ local void MapDraw32Tile32(int tile,int x,int y)
 	cache->Tile=tile;
 	dl_insert_first(TileCacheLRU,&cache->DlNode);
 
-	FillCache32AndDraw32(TheMap.Tiles[tile],(void*)&cache->Buffer,x,y);
+	FillCache8AndDraw32(TheMap.Tiles[tile],(void*)&cache->Buffer,x,y);
     } else {
-	VideoDraw32Tile32FromCache((void*)&cache->Buffer,x,y);
+	VideoDraw8Tile32FromCache((void*)&cache->Buffer,x,y);
     }
 }
 
@@ -819,13 +884,13 @@ local void MapDraw16Tile32(int tile,int x,int y)
 }
 
 /**
-**	Draw 32x32 tile for 8 bpp video modes with cache support.
+**	Draw 32x32 tile for 24 bpp video modes with cache support.
 **
 **	@param tile	Tile number to draw.
 **	@param x	X position into video memory
 **	@param y	Y position into video memory
 */
-local void MapDraw8Tile32(int tile,int x,int y)
+local void MapDraw24Tile32(int tile,int x,int y)
 {
     TileCache* cache;
 
@@ -837,7 +902,7 @@ local void MapDraw8Tile32(int tile,int x,int y)
 	    --TileCacheSize;
 	    cache=malloc(
 		    sizeof(TileCache)-sizeof(unsigned char)+
-		    TileSizeX*TileSizeY*sizeof(VMemType16));
+		    TileSizeX*TileSizeY*sizeof(VMemType24));
 	} else {
 	    cache=(void*)TileCacheLRU->last;
 	    if( cache->Tile ) {
@@ -850,13 +915,51 @@ local void MapDraw8Tile32(int tile,int x,int y)
 	cache->Tile=tile;
 	dl_insert_first(TileCacheLRU,&cache->DlNode);
 
-	FillCache8AndDraw32(TheMap.Tiles[tile],(void*)&cache->Buffer,x,y);
+	FillCache24AndDraw32(TheMap.Tiles[tile],(void*)&cache->Buffer,x,y);
     } else {
-	VideoDraw8Tile32FromCache((void*)&cache->Buffer,x,y);
+	VideoDraw24Tile32FromCache((void*)&cache->Buffer,x,y);
     }
 }
 
-#endif
+/**
+**	Draw 32x32 tile for 32 bpp video modes with cache support.
+**
+**	@param tile	Tile number to draw.
+**	@param x	X position into video memory
+**	@param y	Y position into video memory
+*/
+local void MapDraw32Tile32(int tile,int x,int y)
+{
+    TileCache* cache;
+
+    if( !(cache=TileCached[tile]) ) {
+	//
+	//	Not cached
+	//
+	if( TileCacheSize ) {		// enough cache buffers?
+	    --TileCacheSize;
+	    cache=malloc(
+		    sizeof(TileCache)-sizeof(unsigned char)+
+		    TileSizeX*TileSizeY*sizeof(VMemType32));
+	} else {
+	    cache=(void*)TileCacheLRU->last;
+	    if( cache->Tile ) {
+		TileCached[cache->Tile]=NULL;	// now not cached
+	    }
+	    dl_remove_last(TileCacheLRU);
+	    DebugLevel3("EMPTY CACHE\n");
+	}
+	TileCached[tile]=cache;
+	cache->Tile=tile;
+	dl_insert_first(TileCacheLRU,&cache->DlNode);
+
+	FillCache32AndDraw32(TheMap.Tiles[tile],(void*)&cache->Buffer,x,y);
+    } else {
+	VideoDraw32Tile32FromCache((void*)&cache->Buffer,x,y);
+    }
+}
+
+#endif	// } USE_TILECACHE
 
 /*----------------------------------------------------------------------------
 --	Smart Cache
@@ -865,7 +968,7 @@ local void MapDraw8Tile32(int tile,int x,int y)
 #ifdef USE_SMART_TILECACHE	// {
 
 /**
-**	Fast draw 32x32 tile for 32 bpp from cache.
+**	Fast draw 32x32 tile for 8 bpp from cache.
 **
 **	@param graphic	Pointer to cached tile graphic
 **	@param x	X position into video memory
@@ -873,30 +976,34 @@ local void MapDraw8Tile32(int tile,int x,int y)
 **
 **	@see GRID
 */
-local void VideoDraw32Tile32Cached(const VMemType32* graphic,int x,int y)
+local void VideoDraw8Tile32Cached(const VMemType8* graphic,int x,int y)
 {
-    const VMemType32* sp;
-    const VMemType32* ep;
-    VMemType32* dp;
+    const VMemType8* sp;
+    const VMemType8* ep;
+    VMemType8* dp;
     int da;
 
     sp=graphic;
     da=VideoWidth;
     ep=sp+TileSizeX+TileSizeY*da;
-    dp=VideoMemory32+x+y*da;
+    dp=VideoMemory8+x+y*da;
 
     while( sp<ep ) {			// loop unrolled
 #undef UNROLL2
 #define UNROLL2(x)		\
-	*(unsigned long*)(dp+x)=*(unsigned long*)(sp+x)
+	((unsigned long*)dp)[x+0]=((unsigned long*)sp)[x+0]; \
+	((unsigned long*)dp)[x+1]=((unsigned long*)sp)[x+1]
 
-	UNROLL32(0);
+	UNROLL8(0);
+	sp+=da;
+	dp+=da;
+
+	UNROLL8(0);
 	sp+=da;
 	dp+=da;
     }
 }
 
-
 /**
 **	Fast draw 32x32 tile for 16 bpp from cache.
 **
@@ -926,11 +1033,15 @@ local void VideoDraw16Tile32Cached(const VMemType16* graphic,int x,int y)
 	UNROLL32(0);
 	sp+=da;
 	dp+=da;
+
+	UNROLL32(0);
+	sp+=da;
+	dp+=da;
     }
 }
 
 /**
-**	Fast draw 32x32 tile for 8 bpp from cache.
+**	Fast draw 32x32 tile for 24 bpp from cache.
 **
 **	@param graphic	Pointer to cached tile graphic
 **	@param x	X position into video memory
@@ -938,43 +1049,87 @@ local void VideoDraw16Tile32Cached(const VMemType16* graphic,int x,int y)
 **
 **	@see GRID
 */
-local void VideoDraw8Tile32Cached(const VMemType8* graphic,int x,int y)
+local void VideoDraw24Tile32Cached(const VMemType24* graphic,int x,int y)
 {
-    const VMemType8* sp;
-    const VMemType8* ep;
-    VMemType8* dp;
+    const VMemType24* sp;
+    const VMemType24* ep;
+    VMemType24* dp;
     int da;
 
     sp=graphic;
     da=VideoWidth;
     ep=sp+TileSizeX+TileSizeY*da;
-    dp=VideoMemory8+x+y*da;
+    dp=VideoMemory24+x+y*da;
 
     while( sp<ep ) {			// loop unrolled
 #undef UNROLL2
 #define UNROLL2(x)		\
-	*(unsigned long*)(dp+x)=*(unsigned long*)(sp+x)
+	*((unsigned long*)dp+x+0)=*((unsigned long*)sp+x+0);	\
+	*((unsigned long*)dp+x+1)=*((unsigned long*)sp+x+1)
 
-	UNROLL16(0);
+	UNROLL24(0);
+	sp+=da;
+	dp+=da;
+
+	UNROLL24(0);
 	sp+=da;
 	dp+=da;
     }
 }
 
 /**
-**	Draw 32x32 tile for 32 bpp video modes with cache support.
+**	Fast draw 32x32 tile for 32 bpp from cache.
+**
+**	@param graphic	Pointer to cached tile graphic
+**	@param x	X position into video memory
+**	@param y	Y position into video memory
+**
+**	@see GRID
+*/
+local void VideoDraw32Tile32Cached(const VMemType32* graphic,int x,int y)
+{
+    const VMemType32* sp;
+    const VMemType32* ep;
+    VMemType32* dp;
+    int da;
+
+    sp=graphic;
+    da=VideoWidth;
+    ep=sp+TileSizeX+TileSizeY*da;
+    dp=VideoMemory32+x+y*da;
+
+    while( sp<ep ) {			// loop unrolled
+#undef UNROLL2
+#define UNROLL2(x)		\
+	*(dp+x*2+0)=*(sp+x*2+0);	\
+	*(dp+x*2+1)=*(sp+x*2+1)
+
+	UNROLL32(0);
+	sp+=da;
+	dp+=da;
+
+	UNROLL32(0);
+	sp+=da;
+	dp+=da;
+    }
+}
+
+// ---------------------------------------------------------------------------
+
+/**
+**	Draw 32x32 tile for 8 bpp video modes with cache support.
 **
 **	@param tile	Tile number to draw.
 **	@param x	X position into video memory
 **	@param y	Y position into video memory
 */
-local void MapDraw32Tile32(int tile,int x,int y)
+local void MapDraw8Tile32(int tile,int x,int y)
 {
-    if( 0 && TileCached[tile] ) {
-	VideoDraw32Tile32Cached(TileCached[tile],x,y);
+    if( TileCached[tile] ) {
+	VideoDraw8Tile32Cached(TileCached[tile],x,y);
     } else {
-	VideoDraw32Tile32(TheMap.Tiles[tile],x,y);
-	TileCached[tile]=VideoMemory32+x+y*VideoWidth;
+	VideoDraw8Tile32(TheMap.Tiles[tile],x,y);
+	TileCached[tile]=VideoMemory8+x+y*VideoWidth;
     }
 }
 
@@ -995,6 +1150,49 @@ local void MapDraw16Tile32(int tile,int x,int y)
     }
 }
 
+/**
+**	Draw 32x32 tile for 24 bpp video modes with cache support.
+**
+**	@param tile	Tile number to draw.
+**	@param x	X position into video memory
+**	@param y	Y position into video memory
+*/
+local void MapDraw24Tile32(int tile,int x,int y)
+{
+    if( TileCached[tile] ) {
+	VideoDraw24Tile32Cached(TileCached[tile],x,y);
+    } else {
+	VideoDraw24Tile32(TheMap.Tiles[tile],x,y);
+	TileCached[tile]=VideoMemory24+x+y*VideoWidth;
+    }
+}
+
+/**
+**	Draw 32x32 tile for 32 bpp video modes with cache support.
+**
+**	@param tile	Tile number to draw.
+**	@param x	X position into video memory
+**	@param y	Y position into video memory
+*/
+local void MapDraw32Tile32(int tile,int x,int y)
+{
+    // FIXME: (johns) Why turned off?
+    if( 0 && TileCached[tile] ) {
+	VideoDraw32Tile32Cached(TileCached[tile],x,y);
+    } else {
+	VideoDraw32Tile32(TheMap.Tiles[tile],x,y);
+	TileCached[tile]=VideoMemory32+x+y*VideoWidth;
+    }
+}
+
+#endif	// } USE_SMART_TILECACHE
+
+/*----------------------------------------------------------------------------
+--	Without Cache
+----------------------------------------------------------------------------*/
+
+#if !defined(USE_TILECACHE) && !defined(USE_SMART_TILECACHE)	// {
+
 /**
 **	Draw 32x32 tile for 8 bpp video modes with cache support.
 **
@@ -1004,15 +1202,50 @@ local void MapDraw16Tile32(int tile,int x,int y)
 */
 local void MapDraw8Tile32(int tile,int x,int y)
 {
-    if( TileCached[tile] ) {
-	VideoDraw8Tile32Cached(TileCached[tile],x,y);
-    } else {
-	VideoDraw8Tile32(TheMap.Tiles[tile],x,y);
-	TileCached[tile]=VideoMemory8+x+y*VideoWidth;
-    }
+    VideoDraw8Tile32(TheMap.Tiles[tile],x,y);
 }
 
-#endif	// } USE_SMART_TILECACHE
+/**
+**	Draw 32x32 tile for 16 bpp video modes with cache support.
+**
+**	@param tile	Tile number to draw.
+**	@param x	X position into video memory
+**	@param y	Y position into video memory
+*/
+local void MapDraw16Tile32(int tile,int x,int y)
+{
+    VideoDraw16Tile32(TheMap.Tiles[tile],x,y);
+}
+
+/**
+**	Draw 32x32 tile for 24 bpp video modes with cache support.
+**
+**	@param tile	Tile number to draw.
+**	@param x	X position into video memory
+**	@param y	Y position into video memory
+*/
+local void MapDraw24Tile32(int tile,int x,int y)
+{
+    VideoDraw24Tile32(TheMap.Tiles[tile],x,y);
+}
+
+/**
+**	Draw 32x32 tile for 32 bpp video modes with cache support.
+**
+**	@param tile	Tile number to draw.
+**	@param x	X position into video memory
+**	@param y	Y position into video memory
+*/
+local void MapDraw32Tile32(int tile,int x,int y)
+{
+    VideoDraw32Tile32(TheMap.Tiles[tile],x,y);
+}
+
+#endif	// }  !defined(USE_TILECACHE) && !defined(USE_SMART_TILECACHE)
+
+/*----------------------------------------------------------------------------
+--	Global functions
+----------------------------------------------------------------------------*/
 
 /**
 **	Called if color cycled.
@@ -1090,16 +1323,8 @@ global void DrawMapBackground(int x,int y)
 		//	draw only tiles which must be drawn
 		//
 		if( *redraw_tile++) {
+		    // FIXME: unexplored fields could be drawn faster
 		    MapDrawTile(TheMap.Fields[sx].SeenTile,dx,dy);
-#if 0
-		    if (TheMap.Fields[sx].Flags&MapFieldExplored) {
-			MapDrawTile(TheMap.Fields[sx].SeenTile,dx,dy);
-		    } else {
-			// FIXME: costs speed makes only nice borders 
-			// FIXME: must write better code for this
-			MapDrawTile(TheMap.Fields[sx].Tile,dx,dy);
-		    }
-#endif
 		}
 		++sx;
 		dx+=TileSizeX;
@@ -1129,21 +1354,36 @@ global void DrawMapBackground(int x,int y)
 void InitMap(void)
 {
     switch( VideoDepth ) {
+	case  8:
+	    VideoDrawTile=VideoDraw8Tile32;
+#if !defined(USE_TILECACHE) && !defined(USE_SMART_TILECACHE)
+	    MapDrawTile=MapDraw8Tile32;
+#else
+	    MapDrawTile=MapDraw8Tile32;
+#endif
+	    break;
 	case 15:
 	case 16:
 	    VideoDrawTile=VideoDraw16Tile32;
 #if !defined(USE_TILECACHE) && !defined(USE_SMART_TILECACHE)
-	    MapDrawTile=MapDrawDumbTile;
+	    MapDrawTile=MapDraw16Tile32;
 #else
 	    MapDrawTile=MapDraw16Tile32;
 #endif
-
 	    break;
 	case 24:
+	    VideoDrawTile=VideoDraw24Tile32;
+#if !defined(USE_TILECACHE) && !defined(USE_SMART_TILECACHE)
+	    MapDrawTile=MapDraw24Tile32;
+#else
+	    MapDrawTile=MapDraw24Tile32;
+#endif
+	    // FIXME: real 24bpp mode break;
+
 	case 32:
 	    VideoDrawTile=VideoDraw32Tile32;
 #if !defined(USE_TILECACHE) && !defined(USE_SMART_TILECACHE)
-	    MapDrawTile=MapDrawDumbTile;
+	    MapDrawTile=MapDraw32Tile32;
 #else
 	    MapDrawTile=MapDraw32Tile32;
 #endif
diff --git a/src/map/map_fog.cpp b/src/map/map_fog.cpp
index 9f7a704ef..042fde9d2 100644
--- a/src/map/map_fog.cpp
+++ b/src/map/map_fog.cpp
@@ -73,7 +73,6 @@
 --	Variables
 ----------------------------------------------------------------------------*/
 
-
 global int OriginalFogOfWar;		/// Use original style fog of war
 global int FogOfWarContrast=50;		/// Contrast of fog of war
 global int FogOfWarBrightness=10;	/// Brightness of fog of war
@@ -109,7 +108,6 @@ local void (*VideoDrawOnlyFog)(const GraphicData*,int x,int y);
 */
 local void* FogOfWarAlphaTable;
 
-
 /*----------------------------------------------------------------------------
 --	Functions
 ----------------------------------------------------------------------------*/
@@ -358,6 +356,131 @@ global void MapUpdateVisible(void)
 --	Draw fog solid
 ----------------------------------------------------------------------------*/
 
+// Routines for 8 bit displays .. --------------------------------------------
+
+/**
+**	Fast draw solid fog of war 32x32 tile for 8 bpp video modes.
+**
+**	@param data	pointer to tile graphic data.
+**	@param x	X position into video memory.
+**	@param y	Y position into video memory.
+*/
+global void VideoDraw8Fog32Solid(const GraphicData* data,int x,int y)
+{
+    const unsigned char* sp;
+    const unsigned char* gp;
+    VMemType8* dp;
+    int da;
+
+    sp=data;
+    gp=sp+TileSizeY*TileSizeX;
+    dp=VideoMemory8+x+y*VideoWidth;
+    da=VideoWidth;
+
+    while( sp<gp ) {
+#undef UNROLL1
+#define UNROLL1(x)	\
+	if(COLOR_FOG_P(sp[x])) {		\
+	    dp[x]=((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];	\
+	}
+
+#undef UNROLL2
+#define UNROLL2(x)	\
+	UNROLL1(x+0);
+
+	UNROLL32(0);
+
+	sp+=TileSizeX;
+	dp+=da;
+
+#undef UNROLL2
+#define UNROLL2(x)	\
+	UNROLL1(x+1);
+
+	UNROLL32(0);
+
+	sp+=TileSizeX;
+	dp+=da;
+    }
+}
+
+/**
+**	Fast draw solid 100% fog of war 32x32 tile for 8 bpp video modes.
+**
+**	100% fog of war -- i.e. raster	10101.
+**					01010 etc...
+**
+**	@param data	pointer to tile graphic data.
+**	@param x	X position into video memory
+**	@param y	Y position into video memory
+*/
+global void VideoDraw8OnlyFog32Solid(const GraphicData* data,int x,int y)
+{
+    const VMemType8* gp;
+    VMemType8* dp;
+    int da;
+
+    dp=VideoMemory8+x+y*VideoWidth;
+    gp=dp+VideoWidth*TileSizeX;
+    da=VideoWidth;
+    while( dp<gp ) {
+#undef UNROLL2
+#define UNROLL2(x)		\
+	dp[x+0]=((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];
+	UNROLL32(0);
+	dp+=da;
+
+#undef UNROLL2
+#define UNROLL2(x)		\
+	dp[x+1]=((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];
+	UNROLL32(0);
+	dp+=da;
+    }
+}
+
+/**
+**	Fast draw solid unexplored 32x32 tile for 8 bpp video modes.
+**
+**	@param x	X position into video memory
+**	@param y	Y position into video memory
+*/
+global void VideoDraw8Unexplored32Solid(const GraphicData* data,int x,int y)
+{
+    const unsigned char* sp;
+    const unsigned char* gp;
+    VMemType8* dp;
+    int da;
+
+    sp=data;
+    gp=sp+TileSizeY*TileSizeX;
+    dp=VideoMemory8+x+y*VideoWidth;
+    da=VideoWidth;
+
+    while( sp<gp ) {
+#undef UNROLL1
+#define UNROLL1(x)	\
+	if(COLOR_FOG_P(sp[x]) ) {		\
+	    dp[x]=((VMemType8*)TheMap.TileData->Pixels)[COLOR_FOG];	\
+	}
+
+#undef UNROLL2
+#define UNROLL2(x)	\
+	UNROLL1(x+0);	\
+	UNROLL1(x+1);
+
+	UNROLL32(0);
+	sp+=TileSizeX;
+	dp+=da;
+
+	UNROLL32(0);
+	sp+=TileSizeX;
+	dp+=da;
+
+    }
+}
+
+// Routines for 16 bit displays .. -------------------------------------------
+
 /**
 **	Fast draw solid fog of war 32x32 tile for 16 bpp video modes.
 **
@@ -381,7 +504,7 @@ global void VideoDraw16Fog32Solid(const GraphicData* data,int x,int y)
 #undef UNROLL1
 #define UNROLL1(x)	\
 	if(COLOR_FOG_P(sp[x])) {		\
-	    dp[x]=((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];		\
+	    dp[x]=((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];	\
 	}
 
 #undef UNROLL2
@@ -460,7 +583,7 @@ global void VideoDraw16Unexplored32Solid(const GraphicData* data,int x,int y)
 #undef UNROLL1
 #define UNROLL1(x)	\
 	if(COLOR_FOG_P(sp[x]) ) {		\
-	    dp[x]=((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];		\
+	    dp[x]=((VMemType16*)TheMap.TileData->Pixels)[COLOR_FOG];	\
 	}
 
 #undef UNROLL2
@@ -471,11 +594,136 @@ global void VideoDraw16Unexplored32Solid(const GraphicData* data,int x,int y)
 	UNROLL32(0);
 	sp+=TileSizeX;
 	dp+=da;
+
+	UNROLL32(0);
+	sp+=TileSizeX;
+	dp+=da;
     }
 }
 
-/* Routines for 32 bit displays .. */
+// Routines for 24 bit displays .. -------------------------------------------
 
+/**
+**	Fast draw solid fog of war 32x32 tile for 24 bpp video modes.
+**
+**	@param data	pointer to tile graphic data.
+**	@param x	X position into video memory.
+**	@param y	Y position into video memory.
+*/
+global void VideoDraw24Fog32Solid(const GraphicData* data,int x,int y)
+{
+    const unsigned char* sp;
+    const unsigned char* gp;
+    VMemType24* dp;
+    int da;
+
+    sp=data;
+    gp=sp+TileSizeY*TileSizeX;
+    dp=VideoMemory24+x+y*VideoWidth;
+    da=VideoWidth;
+
+    while( sp<gp ) {
+#undef UNROLL1
+#define UNROLL1(x)	\
+	if(COLOR_FOG_P(sp[x])) {	\
+	    dp[x]=((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];	\
+	}
+
+#undef UNROLL2
+#define UNROLL2(x)	\
+	UNROLL1(x+0);
+
+	UNROLL32(0);
+
+	sp+=TileSizeX;
+	dp+=da;
+
+#undef UNROLL2
+#define UNROLL2(x)	\
+	UNROLL1(x+1);
+
+	UNROLL32(0);
+
+	sp+=TileSizeX;
+	dp+=da;
+    }
+}
+
+/**
+**	Fast draw solid 100% fog of war 32x32 tile for 24 bpp video modes.
+**
+**	100% fog of war -- i.e. raster	10101.
+**					01010 etc...
+**
+**	@param data	pointer to tile graphic data.
+**	@param x	X position into video memory
+**	@param y	Y position into video memory
+*/
+global void VideoDraw24OnlyFog32Solid(const GraphicData* data,int x,int y)
+{
+    const VMemType24* gp;
+    VMemType24* dp;
+    int da;
+
+    dp=VideoMemory24+x+y*VideoWidth;
+    gp=dp+VideoWidth*TileSizeX;
+    da=VideoWidth;
+    while( dp<gp ) {
+#undef UNROLL2
+#define UNROLL2(x)		\
+	dp[x+0]=((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];
+	UNROLL32(0);
+	dp+=da;
+
+#undef UNROLL2
+#define UNROLL2(x)		\
+	dp[x+1]=((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];
+	UNROLL32(0);
+	dp+=da;
+    }
+}
+
+/**
+**	Fast draw solid unexplored 32x32 tile for 24 bpp video modes.
+**
+**	@param x	X position into video memory
+**	@param y	Y position into video memory
+*/
+global void VideoDraw24Unexplored32Solid(const GraphicData* data,int x,int y)
+{
+    const unsigned char* sp;
+    const unsigned char* gp;
+    VMemType24* dp;
+    int da;
+
+    sp=data;
+    gp=sp+TileSizeY*TileSizeX;
+    dp=VideoMemory24+x+y*VideoWidth;
+    da=VideoWidth;
+
+    while( sp<gp ) {
+#undef UNROLL1
+#define UNROLL1(x)	\
+	if(COLOR_FOG_P(sp[x])) {		\
+	    dp[x]=((VMemType24*)TheMap.TileData->Pixels)[COLOR_FOG];	\
+	}
+
+#undef UNROLL2
+#define UNROLL2(x)	\
+	UNROLL1(x+0);	\
+	UNROLL1(x+1);
+
+	UNROLL32(0);
+	sp+=TileSizeX;
+	dp+=da;
+
+	UNROLL32(0);
+	sp+=TileSizeX;
+	dp+=da;
+    }
+}
+
+// Routines for 32 bit displays .. -------------------------------------------
 
 /**
 **	Fast draw solid fog of war 32x32 tile for 32 bpp video modes.
@@ -590,72 +838,55 @@ global void VideoDraw32Unexplored32Solid(const GraphicData* data,int x,int y)
 	UNROLL32(0);
 	sp+=TileSizeX;
 	dp+=da;
+
+	UNROLL32(0);
+	sp+=TileSizeX;
+	dp+=da;
     }
 }
 
-
 /*----------------------------------------------------------------------------
 --	Draw real fog :-)
 ----------------------------------------------------------------------------*/
 
-#if 0
-
-#define RMASK	(0x1F<< 0)
-#define GMASK	(0x1F<< 5)
-#define BMASK	(0x1F<<10)
-#define RSHFT	( 0)
-#define GSHFT	( 5)
-#define BSHFT   (10)
-#define RLOSS	( 3)
-#define GLOSS	( 3)
-#define BLOSS	( 3)
+// Routines for 8 bit displays .. --------------------------------------------
 
 /**
-**	Fast draw alpha fog of war 32x32 tile for 16 bpp video modes.
+**	Fast draw alpha fog of war 32x32 tile for 8 bpp video modes.
 **
 **	@param data	pointer to tile graphic data.
 **	@param x	X position into video memory
 **	@param y	Y position into video memory
+**
+**	The random effect is commented out
 */
-global void VideoDraw16Fog32Alpha(const GraphicData* data,int x,int y)
+global void VideoDraw8Fog32Alpha(const GraphicData* data,int x,int y)
 {
     const unsigned char* sp;
     const unsigned char* gp;
-    VMemType16* dp;
+    VMemType8* dp;
     int da;
-    int o;
-    int p;
-    int r;
-    int g;
-    int b;
-    int v;
 
     sp=data;
     gp=sp+TileSizeY*TileSizeX;
-    dp=VideoMemory16+x+y*VideoWidth;
+    dp=VideoMemory8+x+y*VideoWidth;
     da=VideoWidth;
 
     while( sp<gp ) {
-	o=rand();
 #undef UNROLL1
 #define UNROLL1(x)	\
-	if(COLOR_FOG_P(sp[x])) {		\
-	    p=dp[x];			\
-	    r=(p&RMASK)>>RSHFT<<RLOSS;	\
-	    g=(p&GMASK)>>GSHFT<<GLOSS;	\
-	    b=(p&BMASK)>>BSHFT<<BLOSS;	\
-	    v=(r+g+b)/4+((o&1)<<RLOSS);	\
-	    p=((v>>RLOSS)<<RSHFT)	\
-	      |((v>>GLOSS)<<GSHFT)	\
-	      |((v>>BLOSS)<<BSHFT);	\
-	    dp[x]=p;			\
-	    o>>=1;			\
+	if( COLOR_FOG_P(sp[x]) ) {	\
+	    dp[x]=((VMemType8*)FogOfWarAlphaTable)[dp[x]]; \
 	}
 
 #undef UNROLL2
 #define UNROLL2(x)	\
 	UNROLL1(x+0);	\
-	UNROLL1(x+1);
+	UNROLL1(x+1);	\
+
+	UNROLL32(0);
+	sp+=TileSizeX;
+	dp+=da;
 
 	UNROLL32(0);
 	sp+=TileSizeX;
@@ -664,7 +895,7 @@ global void VideoDraw16Fog32Alpha(const GraphicData* data,int x,int y)
 }
 
 /**
-**	Fast draw 100% fog of war 32x32 tile for 16 bpp video modes.
+**	Fast draw 100% fog of war 32x32 tile for 8 bpp video modes.
 **
 **	100% fog of war -- i.e. raster	10101.
 **					01010 etc...
@@ -672,48 +903,38 @@ global void VideoDraw16Fog32Alpha(const GraphicData* data,int x,int y)
 **	@param data	pointer to tile graphic data.
 **	@param x	X position into video memory
 **	@param y	Y position into video memory
+**
+**	The random effect is commented out
 */
-global void VideoDraw16OnlyFog32Alpha(const GraphicData* data,int x,int y)
+global void VideoDraw8OnlyFog32Alpha(const GraphicData* data,int x,int y)
 {
-    const VMemType16* gp;
-    VMemType16* dp;
+    const VMemType8* gp;
+    VMemType8* dp;
     int da;
-    int p;
-    int r;
-    int g;
-    int b;
-    int v;
-    int o;
 
-    dp=VideoMemory16+x+y*VideoWidth;
+    dp=VideoMemory8+x+y*VideoWidth;
     gp=dp+VideoWidth*TileSizeX;
     da=VideoWidth;
+
     while( dp<gp ) {
-	o=rand();
 #undef UNROLL1
 #define UNROLL1(x)	\
-	p=dp[x];			\
-	r=(p&RMASK)>>RSHFT<<RLOSS;	\
-	g=(p&GMASK)>>GSHFT<<GLOSS;	\
-	b=(p&BMASK)>>BSHFT<<BLOSS;	\
-	v=(r+g+b)/4+((o&1)<<RLOSS);	\
-	p=((v>>RLOSS)<<RSHFT)		\
-	  |((v>>GLOSS)<<GSHFT)		\
-	  |((v>>BLOSS)<<BSHFT);		\
-	dp[x]=p;			\
-	o>>=1;
+	dp[x]=((VMemType8*)FogOfWarAlphaTable)[dp[x]];	\
 
 #undef UNROLL2
 #define UNROLL2(x)	\
 	UNROLL1(x+0);	\
-	UNROLL1(x+1);
+	UNROLL1(x+1);	\
+
+	UNROLL32(0);
+	dp+=da;
 
 	UNROLL32(0);
 	dp+=da;
     }
 }
 
-#endif
+// Routines for 16 bit displays .. -------------------------------------------
 
 /**
 **	Fast draw alpha fog of war 32x32 tile for 16 bpp video modes.
@@ -803,13 +1024,131 @@ global void VideoDraw16OnlyFog32Alpha(const GraphicData* data,int x,int y)
     }
 }
 
+// Routines for 24 bit displays .. -------------------------------------------
+
+/**
+**	Fast draw alpha fog of war 32x32 tile for 24 bpp video modes.
+**
+**	@param data	pointer to tile graphic data.
+**	@param x	X position into video memory
+**	@param y	Y position into video memory
+*/
+global void VideoDraw24Fog32Alpha(const GraphicData* data,int x,int y)
+{
+    const unsigned char* sp;
+    const unsigned char* gp;
+    VMemType24* dp;
+    int da;
+    int r, g, b, v ;
+
+    sp=data;
+    gp=sp+TileSizeY*TileSizeX;
+    dp=VideoMemory24+x+y*VideoWidth;
+    da=VideoWidth;
+
+    while( sp<gp ) {
+#undef FOG_SCALE
+#define FOG_SCALE(x) \
+	    (((((x*3-v)*FogOfWarSaturation + v*100) \
+		*FogOfWarContrast) \
+		+FogOfWarBrightness*25600*3)/30000)
+
+#undef UNROLL1
+#define UNROLL1(x)      \
+	if (COLOR_FOG_P(sp[x])) { \
+	    r=dp[x].a & 0xff; \
+	    g=dp[x].b & 0xff; \
+	    b=dp[x].c & 0xff; \
+	    v=r+g+b; \
+\
+	    r = FOG_SCALE(r); \
+	    g = FOG_SCALE(g); \
+	    b = FOG_SCALE(b); \
+\
+	    r= r<0 ? 0 : r>255 ? 255 : r; \
+	    g= g<0 ? 0 : g>255 ? 255 : g; \
+	    b= b<0 ? 0 : b>255 ? 255 : b; \
+	    dp[x].a = r; \
+	    dp[x].b = g; \
+	    dp[x].c = b; \
+	} \
+
+#undef UNROLL2
+#define UNROLL2(x)	\
+	UNROLL1(x+0);	\
+	UNROLL1(x+1);	\
+
+	UNROLL32(0);
+	sp+=TileSizeX;
+	dp+=da;
+    }
+}
+
+/**
+**	Fast draw 100% fog of war 32x32 tile for 24 bpp video modes.
+**
+**	100% fog of war -- i.e. raster	10101.
+**					01010 etc...
+**
+**	@param data	pointer to tile graphic data.
+**	@param x	X position into video memory
+**	@param y	Y position into video memory
+*/
+global void VideoDraw24OnlyFog32Alpha(const GraphicData* data,int x,int y)
+{
+    const VMemType24* gp;
+    VMemType24* dp;
+    int da;
+    int r, g, b, v;
+
+    dp=VideoMemory24+x+y*VideoWidth;
+    gp=dp+VideoWidth*TileSizeX;
+    da=VideoWidth;
+
+    while( dp<gp ) {
+
+#undef FOG_SCALE
+#define FOG_SCALE(x) \
+	    (((((x*3-v)*FogOfWarSaturation + v*100) \
+		*FogOfWarContrast) \
+		+FogOfWarBrightness*25600*3)/30000)
+
+#undef UNROLL1
+#define UNROLL1(x)	\
+	r=dp[x].a & 0xff; \
+	g=dp[x].b & 0xff; \
+	b=dp[x].c & 0xff; \
+	v=r+g+b; \
+\
+	r = FOG_SCALE(r); \
+	g = FOG_SCALE(g); \
+	b = FOG_SCALE(b); \
+\
+	r= r<0 ? 0 : r>255 ? 255 : r; \
+	g= g<0 ? 0 : g>255 ? 255 : g; \
+	b= b<0 ? 0 : b>255 ? 255 : b; \
+	dp[x].a = r; \
+	dp[x].b = g; \
+	dp[x].c = b; \
+
+#undef UNROLL2
+#define UNROLL2(x)	\
+	UNROLL1(x+0);	\
+	UNROLL1(x+1);	\
+
+	UNROLL32(0);
+	dp+=da;
+    }
+}
+
+// Routines for 32 bit displays .. -------------------------------------------
+
 /**
 **	Fast draw alpha fog of war 32x32 tile for 32 bpp video modes.
 **
 **	@param data	pointer to tile graphic data.
 **	@param x	X position into video memory
 **	@param y	Y position into video memory
-	    o=(o>>1)^((o&1)<<30);					\
 */
 global void VideoDraw32Fog32Alpha(const GraphicData* data,int x,int y)
 {
@@ -817,52 +1156,45 @@ global void VideoDraw32Fog32Alpha(const GraphicData* data,int x,int y)
     const unsigned char* gp;
     VMemType32* dp;
     int da;
-    int o;
-
     int i, r, g, b, v ;
+
     sp=data;
     gp=sp+TileSizeY*TileSizeX;
     dp=VideoMemory32+x+y*VideoWidth;
     da=VideoWidth;
 
     while( sp<gp ) {
-	static int a=1234567;
-	//o=rand();
-
 #undef FOG_SCALE
 #define FOG_SCALE(x) \
-                    (((((x*3-v)*FogOfWarSaturation + v*100) \
-                        *FogOfWarContrast) \
-                        +FogOfWarBrightness*25600*3)/30000)
+	    (((((x*3-v)*FogOfWarSaturation + v*100) \
+		*FogOfWarContrast) \
+		+FogOfWarBrightness*25600*3)/30000)
 
 #undef UNROLL1
 #define UNROLL1(x)      \
-        o=a=a*(123456*4+1)+1; \
 	if (COLOR_FOG_P(sp[x])) { \
-        i = dp[x]; \
-        r=i       & 0xff; \
-        g=(i>>8 ) & 0xff; \
-        b=(i>>16) & 0xff; \
-	if (i) { \
-        v=r+g+b; \
+	    i = dp[x]; \
+	    if (i) { \
+		r=i       & 0xff; \
+		g=(i>>8 ) & 0xff; \
+		b=(i>>16) & 0xff; \
+		v=r+g+b; \
  \
-        r = FOG_SCALE(r); \
-        g = FOG_SCALE(g); \
-        b = FOG_SCALE(b); \
+		r = FOG_SCALE(r); \
+		g = FOG_SCALE(g); \
+		b = FOG_SCALE(b); \
  \
-        r= r<0 ? 0 : r>255 ? 255 : r; \
-        g= g<0 ? 0 : g>255 ? 255 : g; \
-        b= b<0 ? 0 : b>255 ? 255 : b; \
+		r= r<0 ? 0 : r>255 ? 255 : r; \
+		g= g<0 ? 0 : g>255 ? 255 : g; \
+		b= b<0 ? 0 : b>255 ? 255 : b; \
+		dp[x]= (r | (g << 8) | (b << 16)); \
+	    } \
 	} \
-        dp[x]= (r | (g << 8) | (b << 16)); \
-	} \
-
 
 #undef UNROLL2
 #define UNROLL2(x)	\
 	UNROLL1(x+0);	\
 	UNROLL1(x+1);	\
-	//o=(o>>1)|((o&1)<<31);
 
 	UNROLL32(0);
 	sp+=TileSizeX;
@@ -879,15 +1211,12 @@ global void VideoDraw32Fog32Alpha(const GraphicData* data,int x,int y)
 **	@param data	pointer to tile graphic data.
 **	@param x	X position into video memory
 **	@param y	Y position into video memory
-	o=(o>>1)|((o&1)<<30);
 */
 global void VideoDraw32OnlyFog32Alpha(const GraphicData* data,int x,int y)
 {
     const VMemType32* gp;
     VMemType32* dp;
     int da;
-    int o;
-
     int i, r, g, b, v;
 
     dp=VideoMemory32+x+y*VideoWidth;
@@ -895,41 +1224,36 @@ global void VideoDraw32OnlyFog32Alpha(const GraphicData* data,int x,int y)
     da=VideoWidth;
 
     while( dp<gp ) {
-	static int a=1234567;
-	//o=rand();
 
 #undef FOG_SCALE
 #define FOG_SCALE(x) \
-		    (((((x*3-v)*FogOfWarSaturation + v*100) \
-			*FogOfWarContrast) \
-			+FogOfWarBrightness*25600*3)/30000)
+	    (((((x*3-v)*FogOfWarSaturation + v*100) \
+		*FogOfWarContrast) \
+		+FogOfWarBrightness*25600*3)/30000)
 
 #undef UNROLL1
 #define UNROLL1(x)	\
-	o=a=a*(123456*4+1)+1; \
 	i = dp[x]; \
-	r=i       & 0xff; \
-	g=(i>>8 ) & 0xff; \
-	b=(i>>16) & 0xff; \
 	if (i) { \
-	v=r+g+b; \
+	    r=i       & 0xff; \
+	    g=(i>>8 ) & 0xff; \
+	    b=(i>>16) & 0xff; \
+	    v=r+g+b; \
  \
-	r = FOG_SCALE(r); \
-	g = FOG_SCALE(g); \
-	b = FOG_SCALE(b); \
+	    r = FOG_SCALE(r); \
+	    g = FOG_SCALE(g); \
+	    b = FOG_SCALE(b); \
  \
-	r= r<0 ? 0 : r>255 ? 255 : r; \
-	g= g<0 ? 0 : g>255 ? 255 : g; \
-	b= b<0 ? 0 : b>255 ? 255 : b; \
+	    r= r<0 ? 0 : r>255 ? 255 : r; \
+	    g= g<0 ? 0 : g>255 ? 255 : g; \
+	    b= b<0 ? 0 : b>255 ? 255 : b; \
+	    dp[x]= r | (g << 8) | (b << 16); \
 	} \
-	dp[x]= r | (g << 8) | (b << 16); \
-
 
 #undef UNROLL2
 #define UNROLL2(x)	\
 	UNROLL1(x+0);	\
 	UNROLL1(x+1);	\
-	//o=(o>>1)|((o&1)<<31);
 
 	UNROLL32(0);
 	dp+=da;
@@ -1160,6 +1484,65 @@ global void InitMapFogOfWar(void)
 	int rloss,gloss,bloss;
 
 	switch( VideoDepth ) {
+	    case 8:
+		n=1<<(sizeof(VMemType8)*8);
+		if( !FogOfWarAlphaTable ) {
+		    FogOfWarAlphaTable=malloc(n*sizeof(VMemType8));
+		}
+		for( i=0; i<n; ++i ) {
+		    int j;
+		    int l;
+		    int d;
+
+		    r=GlobalPalette[i].r;
+		    g=GlobalPalette[i].g;
+		    b=GlobalPalette[i].b;
+		    DebugLevel3("%d,%d,%d\n",r,g,b);
+		    v=r+g+b;
+
+		    r= ((((r*3-v)*FogOfWarSaturation + v*100)
+			*FogOfWarContrast)
+			+FogOfWarBrightness*25600*3)/30000;
+		    g= ((((g*3-v)*FogOfWarSaturation + v*100)
+			*FogOfWarContrast)
+			+FogOfWarBrightness*25600*3)/30000;
+		    b= ((((b*3-v)*FogOfWarSaturation + v*100)
+			*FogOfWarContrast)
+			+FogOfWarBrightness*25600*3)/30000;
+
+		    // Boundings
+		    r= r<0 ? 0 : r>255 ? 255 : r;
+		    g= g<0 ? 0 : g>255 ? 255 : g;
+		    b= b<0 ? 0 : b>255 ? 255 : b;
+
+		    //
+		    //	Find the best matching color
+		    //
+		    l=i;
+		    d=256;
+		    for( j=0; j<256; ++j ) {
+			v=abs(GlobalPalette[j].r-r)*1
+			    +abs(GlobalPalette[j].g-g)*1
+			    +abs(GlobalPalette[j].b-b)*1
+			    +abs(GlobalPalette[j].r
+				+GlobalPalette[j].g
+				+GlobalPalette[j].b-r-g-b)*2;
+			if( v<d ) {
+			    d=v;
+			    l=j;
+			}
+		    }
+		    DebugLevel3("%d,%d,%d -> %d,%d,%d\n",r,g,b
+			    ,GlobalPalette[l].r,GlobalPalette[l].g
+			    ,GlobalPalette[l].b);
+		    ((VMemType8*)FogOfWarAlphaTable)[i]=l;
+		}
+
+		VideoDrawFog=VideoDraw8Fog32Alpha;
+		VideoDrawOnlyFog=VideoDraw8OnlyFog32Alpha;
+		VideoDrawUnexplored=VideoDraw8Unexplored32Solid;
+		break;
+
 	    case 15:			// 15 bpp 555 video depth
 		rshft=( 0);
 		gshft=( 5);
@@ -1218,31 +1601,46 @@ build_table:
 		break;
 
 	    case 24:
+		VideoDrawFog=VideoDraw24Fog32Alpha;
+		VideoDrawOnlyFog=VideoDraw24OnlyFog32Alpha;
+		VideoDrawUnexplored=VideoDraw24Unexplored32Solid;
+		// FIXME: real 24 bpp mode break;
+
 	    case 32:
 		VideoDrawFog=VideoDraw32Fog32Alpha;
 		VideoDrawOnlyFog=VideoDraw32OnlyFog32Alpha;
 		VideoDrawUnexplored=VideoDraw32Unexplored32Solid;
 		break;
-	    // FIXME: support for 8 bpp modes
+
 	    default:
 		DebugLevel0(__FUNCTION__": Depth unsupported\n");
 		break;
 	}
     } else {
 	switch( VideoDepth ) {
+	    case  8:			//  8 bpp video depth
+		VideoDrawFog=VideoDraw8Fog32Solid;
+		VideoDrawOnlyFog=VideoDraw8OnlyFog32Solid;
+		VideoDrawUnexplored=VideoDraw8Unexplored32Solid;
+		break;
+
 	    case 15:			// 15 bpp video depth
 	    case 16:			// 16 bpp video depth
 		VideoDrawFog=VideoDraw16Fog32Solid;
 		VideoDrawOnlyFog=VideoDraw16OnlyFog32Solid;
 		VideoDrawUnexplored=VideoDraw16Unexplored32Solid;
 		break;
-	    case 24:
-	    case 32:
+	    case 24:			// 24 bpp video depth
+		VideoDrawFog=VideoDraw24Fog32Solid;
+		VideoDrawOnlyFog=VideoDraw24OnlyFog32Solid;
+		VideoDrawUnexplored=VideoDraw24Unexplored32Solid;
+		// FIXME: real 24bpp mode break;
+	    case 32:			// 32 bpp video depth
 		VideoDrawFog=VideoDraw32Fog32Solid;
 		VideoDrawOnlyFog=VideoDraw32OnlyFog32Solid;
 		VideoDrawUnexplored=VideoDraw32Unexplored32Solid;
 		break;
-	    // FIXME: support for 8/32 bpp modes
+
 	    default:
 		DebugLevel0(__FUNCTION__": Depth unsupported\n");
 		break;
diff --git a/src/network/new_network.cpp b/src/network/new_network.cpp
index 8a4c7063e..6f93da519 100644
--- a/src/network/new_network.cpp
+++ b/src/network/new_network.cpp
@@ -1518,14 +1518,14 @@ global void NetworkEvent(void)
     if( !NetworkInSync ) {
 	NetworkInSync=1;
 	n=((FrameCounter)/NetworkUpdates)*NetworkUpdates+NetworkUpdates;
-	DebugLevel3(__FUNCTION__": wait for %d - ",n);
+	DebugLevel2(__FUNCTION__": wait for %d - ",n);
 	for( player=0; player<HostsCount; ++player ) {
 	    if( NetworkIn[n&0xFF][NetPlyNr[player]].Time!=n ) {
 		NetworkInSync=0;
 		break;
 	    }
 	}
-	DebugLevel3("%d in sync %d\n",FrameCounter,NetworkInSync);
+	DebugLevel2("%d in sync %d\n",FrameCounter,NetworkInSync);
     }
 }
 
diff --git a/src/stratagus/player.cpp b/src/stratagus/player.cpp
index 527a1f06b..2c603708b 100644
--- a/src/stratagus/player.cpp
+++ b/src/stratagus/player.cpp
@@ -516,6 +516,7 @@ global void PlayersEachSecond(void)
 }
 
 #ifdef NEW_VIDEO
+
 /**
 **	Change current color set to new player.
 **
@@ -545,39 +546,6 @@ global void GraphicPlayerPixels(const Player* player,const Graphic* sprite)
 	    break;
     }
 }
-#else
-/**
-**	Change current color set to new player.
-**
-**	FIXME: use function pointer here.
-**
-**	@param player	Pointer to player.
-*/
-global void RLEPlayerPixels(const Player* player, const RleSprite * sprite)
-{
-    switch(VideoDepth){
-	case 8:
-	    *((struct __4pixel8__*)(((VMemType8*)sprite->Pixels)+208))
-		    =player->UnitColors.Depth8;
-	    break;
-	case 15:
-	case 16:
-	    *((struct __4pixel16__*)(((VMemType16*)sprite->Pixels)+208))
-		    =player->UnitColors.Depth16;
-	    break;
-	case 24:
-	    // FIXME: support for real 24 bpp mode
-	    //*((struct __4pixel24__*)(((VMemType24*)sprite->Pixels)+208))
-	    //	    =player->UnitColors.Depth24;
-	case 32:
-	    *((struct __4pixel32__*)(((VMemType32*)sprite->Pixels)+208))
-		    =player->UnitColors.Depth32;
-	break;
-    }
-}
-#endif
-
-#ifdef NEW_VIDEO
 
 /**
 **	Change current color set to new player.
@@ -740,6 +708,36 @@ global void SetPlayersPalette(void)
 
 #else
 
+/**
+**	Change current color set to new player.
+**
+**	FIXME: use function pointer here.
+**
+**	@param player	Pointer to player.
+*/
+global void RLEPlayerPixels(const Player* player, const RleSprite * sprite)
+{
+    switch(VideoDepth){
+	case 8:
+	    *((struct __4pixel8__*)(((VMemType8*)sprite->Pixels)+208))
+		    =player->UnitColors.Depth8;
+	    break;
+	case 15:
+	case 16:
+	    *((struct __4pixel16__*)(((VMemType16*)sprite->Pixels)+208))
+		    =player->UnitColors.Depth16;
+	    break;
+	case 24:
+	    // FIXME: support for real 24 bpp mode
+	    //*((struct __4pixel24__*)(((VMemType24*)sprite->Pixels)+208))
+	    //	    =player->UnitColors.Depth24;
+	case 32:
+	    *((struct __4pixel32__*)(((VMemType32*)sprite->Pixels)+208))
+		    =player->UnitColors.Depth32;
+	break;
+    }
+}
+
 /**
 **	Change current color set to new player.
 **
diff --git a/src/video/X11.cpp b/src/video/X11.cpp
index eb7b57a4e..31f40d399 100644
--- a/src/video/X11.cpp
+++ b/src/video/X11.cpp
@@ -94,8 +94,10 @@ local Atom WmDeleteWindowAtom;		/// Atom for WM_DELETE_WINDOW
 --	Sync
 ----------------------------------------------------------------------------*/
 
+#ifndef NEW_VIDEO
 global int VideoSyncSpeed=100;		// 0 disable interrupts
 volatile int VideoInterrupts;		// be happy, were are quicker
+#endif
 
 /**
 **	Called from SIGALRM.
diff --git a/src/video/new_video.cpp b/src/video/new_video.cpp
index 34f9d8117..993c6f052 100644
--- a/src/video/new_video.cpp
+++ b/src/video/new_video.cpp
@@ -69,6 +69,17 @@
 #define UseWin32	1
 #endif
 
+/**
+**	Structure of pushed clippings.
+*/
+typedef struct _clip_ {
+    struct _clip_*	Next;		/// next pushed clipping.
+    int			X1;		/// pushed clipping top left
+    int			Y1;		/// pushed clipping top left
+    int			X2;		/// pushed clipping bottom right
+    int			Y2;		/// pushed clipping bottom right
+} Clip;
+
 /*----------------------------------------------------------------------------
 --	Externals
 ----------------------------------------------------------------------------*/
@@ -91,6 +102,8 @@ global int ClipY1;			/// current clipping top left
 global int ClipX2;			/// current clipping bottom right
 global int ClipY2;			/// current clipping bottom right
 
+local Clip* Clips;			/// stack of all clips.
+
 #ifdef DEBUG
 global unsigned AllocatedGraphicMemory;	/// Allocated memory for objects
 global unsigned CompressedGraphicMemory;/// memory for compressed objects
@@ -120,6 +133,9 @@ global VMemType* VideoMemory;
     */
 global VMemType* Pixels;
 
+global int VideoSyncSpeed=100;		/// 0 disable interrupts
+global volatile int VideoInterrupts;	/// be happy, were are quicker
+
 #endif
 
     ///	Loaded system palette. 256-entries long, active system palette.
@@ -155,7 +171,7 @@ global void SetClipping(int left,int top,int right,int bottom)
 
     if( left>=VideoWidth )	left=VideoWidth-1;
     if( right>=VideoWidth )	right=VideoWidth-1;
-    if( bottom>=VideoHeight ) bottom=VideoHeight-1;
+    if( bottom>=VideoHeight )	bottom=VideoHeight-1;
     if( top>=VideoHeight )	top=VideoHeight-1;
     
     ClipX1=left;
@@ -163,6 +179,45 @@ global void SetClipping(int left,int top,int right,int bottom)
     ClipX2=right;
     ClipY2=bottom;
 }
+
+/**
+**	Push current clipping.
+*/
+global void PushClipping(void)
+{
+    Clip* clip;
+
+    clip=malloc(sizeof(Clip));
+    clip->Next=Clips;
+    clip->X1=ClipX1;
+    clip->Y1=ClipY1;
+    clip->X2=ClipX2;
+    clip->Y2=ClipY2;
+    Clips=clip;
+}
+
+/**
+**	Pop current clipping.
+*/
+global void PopClipping(void)
+{
+    Clip* clip;
+
+    clip=Clips;
+    if( clip ) {
+	Clips=clip->Next;
+	ClipX1=clip->X1;
+	ClipY1=clip->Y1;
+	ClipX2=clip->X2;
+	ClipY2=clip->Y2;
+    } else {
+	ClipX1=0;
+	ClipY1=0;
+	ClipX2=VideoWidth;
+	ClipY2=VideoHeight;
+    }
+}
+
 #endif
 
 /**
diff --git a/src/video/sdl.cpp b/src/video/sdl.cpp
index 54be3709f..66076ef4e 100644
--- a/src/video/sdl.cpp
+++ b/src/video/sdl.cpp
@@ -80,9 +80,13 @@ global VMemType32 * Pixels32;		/// 32 bpp palette
 --	Sync
 ----------------------------------------------------------------------------*/
 
+#ifndef NEW_VIDEO
+
 global int VideoSyncSpeed=100;		// 0 disable interrupts
 volatile int VideoInterrupts;		// be happy, were are quicker
 
+#endif
+
 /**
 **	Called from SIGALRM.
 */
diff --git a/src/video/svgalib.cpp b/src/video/svgalib.cpp
index c096f1e6e..8a2cbbac7 100644
--- a/src/video/svgalib.cpp
+++ b/src/video/svgalib.cpp
@@ -85,9 +85,13 @@ local void KeyboardEvent(int scancode,int press);
 --	Sync
 ----------------------------------------------------------------------------*/
 
+#ifndef NEW_VIDEO
+
 global int VideoSyncSpeed=100;		// 0 disable interrupts
 volatile int VideoInterrupts;		// be happy, were are quicker
 
+#endif
+
 /**
 **	Called from SIGALRM.
 */