stratagus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Stratagus-CVS] stratagus/src clone/clone.c clone/mainloop.c cl...


From: Nehal Mistry
Subject: [Stratagus-CVS] stratagus/src clone/clone.c clone/mainloop.c cl...
Date: Mon, 17 Nov 2003 14:14:52 -0500

CVSROOT:        /cvsroot/stratagus
Module name:    stratagus
Branch:         
Changes by:     Nehal Mistry <address@hidden>   03/11/17 14:14:48

Modified files:
        src/clone      : clone.c mainloop.c player.c unit_draw.c 
        src/editor     : editloop.c 
        src/game       : game.c intro.c loadgame.c 
        src/include    : cursor.h map.h player.h ui.h unit.h unittype.h 
                         video.h 
        src/map        : map.c map_draw.c map_fog.c minimap.c tileset.c 
        src/movie      : movie.c 
        src/ui         : ccl_ui.c icons.c mainscr.c menu_proc.c menus.c 
                         ui.c 
        src/unit       : ccl_unittype.c unittype.c 
        src/video      : cursor.c font.c graphic.c linedraw.c png.c 
                         sdl.c sprite.c video.c 

Log message:
        Added prelimenary SDL_Surface support using -DUSE_SDL_SUPPORT

Patches:
Index: stratagus/src/clone/clone.c
diff -u stratagus/src/clone/clone.c:1.225 stratagus/src/clone/clone.c:1.226
--- stratagus/src/clone/clone.c:1.225   Sun Nov 16 01:49:25 2003
+++ stratagus/src/clone/clone.c Mon Nov 17 14:14:28 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: clone.c,v 1.225 2003/11/16 06:49:25 mr-russ Exp $
+//     $Id: clone.c,v 1.226 2003/11/17 19:14:28 nehalmistry Exp $
 
 //@{
 
@@ -642,8 +642,9 @@
 {
 }
 
-#else
+#endif
 
+#ifndef USE_SDL_SURFACE
 local void VideoEffect0(int frame,
     const EventCallback* callbacks __attribute__((unused)))
 {
@@ -957,18 +958,24 @@
        WaitEventsOneFrame(&callbacks);
     }
 #else
+//#ifndef USE_SDL_SURFACE
     timeout *= CYCLES_PER_SECOND;
     while (timeout-- && WaitNoEvent) {
        // FIXME: make this configurable
+
+#ifndef USE_SDL_SURFACE
        if (0) {
            VideoEffect0(timeout, &callbacks);
        }
+#endif
        WaitEventsOneFrame(&callbacks);
     }
+#ifndef USE_SDL_SURFACE
     if (0) {
        VideoEffect0(-1, &callbacks);
     }
 #endif
+#endif
 
     VideoLockScreen();
     VideoClearScreen();
@@ -999,7 +1006,13 @@
                *s = ' ';
            }
        }
+#ifdef USE_SDL_SURFACE
+       SDL_Color color = { 0, 0, 0, 0 };
+
+       VideoFillRectangle(color, 5, VideoHeight - 18, VideoWidth - 10, 18);
+#else
        VideoFillRectangle(ColorBlack, 5, VideoHeight - 18, VideoWidth - 10, 
18);
+#endif
        VideoDrawTextCentered(VideoWidth / 2, VideoHeight - 16, GameFont, temp);
        VideoUnlockScreen();
        InvalidateArea(5, VideoHeight - 18, VideoWidth - 10, 18);
@@ -1024,11 +1037,19 @@
     // FIXME: must search tileset by identifier or use a gui palette?
     TheMap.TerrainName = Tilesets[0]->Ident;
     LoadTileset();
+#ifdef USE_SDL_SURFACE
+    LoadRGB(&GlobalPalette, s = strdcat3(StratagusLibPath,
+       "/graphics/", Tilesets[0]->PaletteFile));
+    TheMap.TerrainName = NULL;
+    free(s);
+    VideoCreatePalette(&GlobalPalette);
+#else
     LoadRGB(GlobalPalette, s = strdcat3(StratagusLibPath,
        "/graphics/", Tilesets[0]->PaletteFile));
     TheMap.TerrainName = NULL;
     free(s);
     VideoCreatePalette(GlobalPalette);
+#endif
     SetDefaultTextColors(FontYellow, FontWhite);
 
     LoadFonts();
Index: stratagus/src/clone/mainloop.c
diff -u stratagus/src/clone/mainloop.c:1.159 
stratagus/src/clone/mainloop.c:1.160
--- stratagus/src/clone/mainloop.c:1.159        Sat Nov  8 21:42:05 2003
+++ stratagus/src/clone/mainloop.c      Mon Nov 17 14:14:28 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: mainloop.c,v 1.159 2003/11/09 02:42:05 n0body Exp $
+//     $Id: mainloop.c,v 1.160 2003/11/17 19:14:28 nehalmistry Exp $
 
 //@{
 
@@ -517,7 +517,11 @@
     // Separate the viewports and mark the active viewport.
     //
     for (vp = TheUI.Viewports; vp < evp; ++vp) {
+#ifdef USE_SDL_SURFACE
+       SDL_Color color;
+#else
        VMemType color;
+#endif
 
        if (vp == TheUI.SelectedViewport) {
            color = ColorOrange;
@@ -546,7 +550,9 @@
 {
     MustRedraw &= EnableRedraw;                // Don't redraw disabled parts
 
+#ifndef USE_SDL_SURFACE
     VideoLockScreen();                 // prepare video write
+#endif
 
     HideAnyCursor();                   // remove cursor (when available)
 
@@ -621,7 +627,9 @@
 
     DrawAnyCursor();
 
+#ifndef USE_SDL_SURFACE
     VideoUnlockScreen();               // End write access
+#endif
 
     //
     // Update changes to display.
Index: stratagus/src/clone/player.c
diff -u stratagus/src/clone/player.c:1.98 stratagus/src/clone/player.c:1.99
--- stratagus/src/clone/player.c:1.98   Sun Nov 16 01:49:26 2003
+++ stratagus/src/clone/player.c        Mon Nov 17 14:14:28 2003
@@ -10,7 +10,7 @@
 //
 /address@hidden player.c       -       The players. */
 //
-//     (c) Copyright 1998-2003 by Lutz Sammer and Jimmy Salmon
+//     (c) Copyright 1998-2003 by Lutz Sammer, Jimmy Salmon, Nehal Mistry
 //
 //      This program is free software; you can redistribute it and/or modify
 //      it under the terms of the GNU General Public License as published by
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: player.c,v 1.98 2003/11/16 06:49:26 mr-russ Exp $
+//     $Id: player.c,v 1.99 2003/11/17 19:14:28 nehalmistry Exp $
 
 //@{
 
@@ -66,8 +66,13 @@
 /**
 **     Colors used for minimap.        FIXME: make this configurable
 */
+#ifdef USE_SDL_SURFACE
+global SDL_Color PlayerColorsRGB[PlayerMax];
+global SDL_Color PlayerColors[PlayerMax];
+#else
 global VMemType PlayerColorsRGB[PlayerMax];
 global VMemType PlayerColors[PlayerMax];
+#endif
 
 global char* PlayerColorNames[PlayerMax] = {
     "red",
@@ -142,19 +147,32 @@
     };
 
     // FIXME: remove this
+#ifdef USE_SDL_SURFACE
+    for (p = 0; p < PlayerMax; ++p) {
+       PlayerColorsRGB[p].r = PColors[p].R;
+       PlayerColorsRGB[p].g = PColors[p].G;
+       PlayerColorsRGB[p].b = PColors[p].B;
+    }
+#else
     for (p = 0; p < PlayerMax; ++p) {
        PlayerColorsRGB[p].D24.a = PColors[p].R;
        PlayerColorsRGB[p].D24.b = PColors[p].G;
        PlayerColorsRGB[p].D24.c = PColors[p].B;
     }
+#endif
 
     for (p = 0; p < PlayerMax; ++p) {
        Players[p].Player = p;
        if (!Players[p].Type) {
            Players[p].Type = PlayerNobody;
        }
+#ifdef USE_SDL_SURFACE
+       PlayerColors[p] = VideoMapRGB(PlayerColorsRGB[p].r,
+           PlayerColorsRGB[p].g, PlayerColorsRGB[p].b);
+#else
        PlayerColors[p] = VideoMapRGB(PlayerColorsRGB[p].D24.a,
            PlayerColorsRGB[p].D24.b, PlayerColorsRGB[p].D24.c);
+#endif
     }
 }
 
@@ -202,7 +220,7 @@
     int j;
 
     CLprintf(file, "\n;;; -----------------------------------------\n");
-    CLprintf(file, ";;; MODULE: players $Id: player.c,v 1.98 2003/11/16 
06:49:26 mr-russ Exp $\n\n");
+    CLprintf(file, ";;; MODULE: players $Id: player.c,v 1.99 2003/11/17 
19:14:28 nehalmistry Exp $\n\n");
 
     //
     // Dump table wc2 race numbers -> internal symbol.
@@ -861,6 +879,10 @@
 */
 global void GraphicPlayerPixels(const Player* player, const Graphic* sprite)
 {
+#ifdef USE_SDL_SURFACE
+    memcpy(&sprite->Palette->colors[208], player->UnitColors.Colors, 
+       sizeof(Pixels) * 4);
+#else
     switch (VideoBpp) {
        case 8:
            *((struct __4pixel8__*)(((VMemType8*)sprite->Pixels) + 208)) =
@@ -880,6 +902,7 @@
                player->UnitColors.Depth32;
            break;
     }
+#endif
 }
 
 /**
@@ -889,6 +912,10 @@
 */
 global void PlayerPixels(const Player* player)
 {
+#ifdef USE_SDL_SURFACE
+    memcpy(&GlobalPalette.colors[208], player->UnitColors.Colors, 
+       sizeof(Pixels) * 4);
+#else
     // FIXME: use function pointer
     switch (VideoBpp) {
        case 8:
@@ -905,6 +932,7 @@
            *((struct __4pixel32__*)(Pixels32 + 208)) = 
player->UnitColors.Depth32;
            break;
     }
+#endif
 }
 
 /**
@@ -919,8 +947,33 @@
     int i;
     int o;
 
+//    Pixels->colors = calloc(256, sizeof(SDL_Color));
+
     //o = rand() & 0x7;                        // FIXME: random colors didn't 
work
     o = 0;
+#ifdef USE_SDL_SURFACE
+    for (i = 0; i < 7; ++i) {
+       Players[o].UnitColors.Colors[0] = GlobalPalette.colors[208];
+       Players[o].UnitColors.Colors[1] = GlobalPalette.colors[209];
+       Players[o].UnitColors.Colors[2] = GlobalPalette.colors[210];
+       Players[o].UnitColors.Colors[3] = GlobalPalette.colors[211];
+
+       Players[o + 8].UnitColors.Colors[0] = GlobalPalette.colors[208];
+       Players[o + 8].UnitColors.Colors[1] = GlobalPalette.colors[209];
+       Players[o + 8].UnitColors.Colors[2] = GlobalPalette.colors[210];
+       Players[o + 8].UnitColors.Colors[3] = GlobalPalette.colors[211];
+       o = (o + 1) & 0x7;
+    }
+
+    Players[o].UnitColors.Colors[0] = GlobalPalette.colors[12];
+    Players[o].UnitColors.Colors[1] = GlobalPalette.colors[13];
+    Players[o].UnitColors.Colors[2] = GlobalPalette.colors[14];
+    Players[o].UnitColors.Colors[3] = GlobalPalette.colors[15];
+    Players[o+8].UnitColors.Colors[0] = GlobalPalette.colors[12];
+    Players[o+8].UnitColors.Colors[1] = GlobalPalette.colors[13];
+    Players[o+8].UnitColors.Colors[2] = GlobalPalette.colors[14];
+    Players[o+8].UnitColors.Colors[3] = GlobalPalette.colors[15];
+#else
     switch (VideoBpp) {
     case 8:
        // New player colors setup
@@ -1045,6 +1098,7 @@
 
        break;
     }
+#endif
 }
 
 /**
Index: stratagus/src/clone/unit_draw.c
diff -u stratagus/src/clone/unit_draw.c:1.182 
stratagus/src/clone/unit_draw.c:1.183
--- stratagus/src/clone/unit_draw.c:1.182       Fri Nov 14 14:57:29 2003
+++ stratagus/src/clone/unit_draw.c     Mon Nov 17 14:14:29 2003
@@ -10,7 +10,7 @@
 //
 /address@hidden unit_draw.c    -       The draw routines for units. */
 //
-//     (c) Copyright 1998-2003 by Lutz Sammer and Jimmy Salmon
+//     (c) Copyright 1998-2003 by Lutz Sammer, Jimmy Salmon, Nehal Mistry
 //
 //      This program is free software; you can redistribute it and/or modify
 //      it under the terms of the GNU General Public License as published by
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: unit_draw.c,v 1.182 2003/11/14 19:57:29 jsalmon3 Exp $
+//     $Id: unit_draw.c,v 1.183 2003/11/17 19:14:29 nehalmistry Exp $
 
 //@{
 
@@ -92,8 +92,13 @@
 **     @param x1,y1    Coordinates of the top left corner. 
 **     @param x2,y2    Coordinates of the bottom right corner. 
 */
+#ifdef USE_SDL_SURFACE
+global void (*DrawSelection)(SDL_Color color, int x1, int y1,
+    int x2, int y2) = DrawSelectionNone;
+#else
 global void (*DrawSelection)(VMemType color, int x1, int y1,
     int x2, int y2) = DrawSelectionNone;
+#endif
 
 /*----------------------------------------------------------------------------
 --     Functions
@@ -113,6 +118,47 @@
 **
 **     @return         Color for selection, or NULL if not selected.
 */
+#ifdef USE_SDL_SURFACE
+local SDL_Color* SelectionColor(const Unit* unit)
+{
+    SDL_Color *color;
+
+    color = malloc(sizeof(SDL_Color));
+
+    // FIXME: make these colors customizable via CVS
+
+    if (EditorRunning && unit==UnitUnderCursor &&
+           EditorState == EditorSelecting) {
+       *color = ColorWhite;
+       return color;
+    }
+
+    if (unit->Selected || (unit->Blink & 1)) {
+       if (unit->Player->Player == PlayerNumNeutral) {
+           *color = ColorYellow;
+           return color;
+       }
+       // FIXME: better allied?
+       if (unit->Player == ThisPlayer) {
+           *color = ColorGreen;
+           return color;
+       }
+       if (IsEnemy(ThisPlayer, unit)) {
+           *color = ColorRed;
+           return color;
+       }
+       return &unit->Player->Color;
+    }
+
+    // If building mark all own buildings
+    if (CursorBuilding && unit->Type->Building &&
+           unit->Player == ThisPlayer) {
+       *color = ColorGray;     
+       return color;
+    }
+    return NULL;
+}
+#else
 local VMemType* SelectionColor(const Unit* unit)
 {
     if (EditorRunning && unit==UnitUnderCursor &&
@@ -141,6 +187,7 @@
     }
     return NULL;
 }
+#endif
 
 /**
 **     Show selection marker around an unit.
@@ -149,7 +196,11 @@
 */
 global void DrawUnitSelection(const Unit* unit)
 {
+#ifdef USE_SDL_SURFACE
+    SDL_Color* color;
+#else
     VMemType* color;
+#endif
     int x;
     int y;
     UnitType* type;
@@ -176,10 +227,17 @@
 **     @param x1,y1    Coordinates of the top left corner. 
 **     @param x2,y2    Coordinates of the bottom right corner. 
 */
+#ifdef USE_SDL_SURFACE
+global void DrawSelectionNone(SDL_Color color, int x1, int y1,
+    int x2, int y2)
+{
+}
+#else
 global void DrawSelectionNone(VMemType color, int x1, int y1,
     int x2, int y2)
 {
 }
+#endif
 
 /**
 **     Show selected units with circle.
@@ -188,8 +246,13 @@
 **     @param x1,y1    Coordinates of the top left corner. 
 **     @param x2,y2    Coordinates of the bottom right corner. 
 */
+#ifdef USE_SDL_SURFACE
+global void DrawSelectionCircle(SDL_Color color, int x1, int x2,
+    int y1, int y2)
+#else
 global void DrawSelectionCircle(VMemType color, int x1, int x2,
     int y1, int y2)
+#endif
 {
     VideoDrawCircleClip(color, (x1 + x2) / 2, (y1 + y2) / 2,
        min((x2 - x1) / 2, (y2 - y1) / 2));
@@ -204,11 +267,21 @@
 **     @param x1,y1    Coordinates of the top left corner. 
 **     @param x2,y2    Coordinates of the bottom right corner. 
 */
+#ifdef USE_SDL_SURFACE
+global void DrawSelectionCircleWithTrans(SDL_Color color, int x1, int y1,
+    int x2, int y2)
+#else
 global void DrawSelectionCircleWithTrans(VMemType color, int x1, int y1,
     int x2, int y2)
+#endif
 {
+#ifdef USE_SDL_SURFACE
+    VideoFillTransCircleClip(color, (x1 + x2) / 2, (y1 + y2) / 2,
+       min((x2 - x1) / 2, (y2 - y1) / 2) - 2, 75);
+#else
     VideoFill75TransCircleClip(color, (x1 + x2) / 2, (y1 + y2) / 2,
        min((x2 - x1) / 2, (y2 - y1) / 2) - 2);
+#endif
     VideoDrawCircleClip(color, (x1 + x2) / 2, (y1 + y2) / 2,
        min((x2 - x1) / 2, (y2 - y1) / 2));
 }
@@ -220,8 +293,13 @@
 **     @param x1,y1    Coordinates of the top left corner. 
 **     @param x2,y2    Coordinates of the bottom right corner. 
 */
+#ifdef USE_SDL_SURFACE
+global void DrawSelectionRectangle(SDL_Color color, int x1, int y1,
+    int x2, int y2)
+#else
 global void DrawSelectionRectangle(VMemType color, int x1, int y1,
     int x2, int y2)
+#endif
 {
     VideoDrawRectangleClip(color, x1, y1, x2 - x1, y2 - y1);
 }
@@ -233,12 +311,22 @@
 **     @param x1,y1    Coordinates of the top left corner. 
 **     @param x2,y2    Coordinates of the bottom right corner. 
 */
+#ifdef USE_SDL_SURFACE
+global void DrawSelectionRectangleWithTrans(SDL_Color color, int x1, int y1,
+    int x2, int y2)
+#else
 global void DrawSelectionRectangleWithTrans(VMemType color, int x1, int y1,
     int x2, int y2)
+#endif
 {
     VideoDrawRectangleClip(color, x1, y1, x2 - x1, y2 - y1);
+#ifdef USE_SDL_SURFACE
+    VideoFillTransRectangleClip(color, x1 + 1, y1 + 1,
+       x2 - x1 - 2, y2 - y1 - 2, 75);
+#else
     VideoFill75TransRectangleClip(color, x1 + 1, y1 + 1,
        x2 - x1 - 2, y2 - y1 - 2);
+#endif
 }
 
 /**
@@ -248,8 +336,13 @@
 **     @param x1,y1    Coordinates of the top left corner. 
 **     @param x2,y2    Coordinates of the bottom right corner. 
 */
+#ifdef USE_SDL_SURFACE
+global void DrawSelectionCorners(SDL_Color color, int x1, int y1,
+    int x2, int y2)
+#else
 global void DrawSelectionCorners(VMemType color, int x1, int y1,
     int x2, int y2)
+#endif
 {
 #define CORNER_PIXELS 6
 
@@ -854,7 +947,7 @@
 global void SaveDecorations(CLFile* file)
 {
     CLprintf(file, "\n;;; -----------------------------------------\n");
-    CLprintf(file, ";;; MODULE: decorations $Id: unit_draw.c,v 1.182 
2003/11/14 19:57:29 jsalmon3 Exp $\n\n");
+    CLprintf(file, ";;; MODULE: decorations $Id: unit_draw.c,v 1.183 
2003/11/17 19:14:29 nehalmistry Exp $\n\n");
 
     CLprintf(file, "(mana-sprite \"%s\"  %d %d  %d %d)\n",
        ManaSprite.File, ManaSprite.HotX, ManaSprite.HotY,
@@ -1026,6 +1119,7 @@
                    type->BoxHeight + 5,
                (f * type->BoxHeight) / 100, 4);
        }
+
         w = (f * type->BoxHeight) / 100 - 1;
         if (w > 0) { // Prevents -1 turning into unsigned int
            VideoFillRectangleClip(ColorBlue,
@@ -1048,7 +1142,11 @@
 local void DrawDecoration(const Unit* unit, const UnitType* type, int x, int y)
 {
     int f;
+#ifdef USE_SDL_SURFACE
+    SDL_Color color;
+#else
     VMemType color;
+#endif
     int w;
     int x1;
     int y1;
@@ -1653,8 +1751,13 @@
 {
     int x2;
     int y2;
+#ifdef USE_SDL_SURFACE
+    SDL_Color color;
+    SDL_Color e_color;
+#else
     VMemType color;
     VMemType e_color;
+#endif
     int dest;
 
     GetOrderPosition(unit, order, &x2, &y2);
@@ -1835,6 +1938,20 @@
     //
     if (NumSelected == 1 && unit->Selected) {
        if (ShowSightRange) {
+#ifdef USE_SDL_SURFACE
+           if (ShowSightRange == 1) {
+               VideoFillTransRectangleClip(ColorGreen,
+                   x + type->TileWidth * TileSizeX / 2 - stats->SightRange * 
TileSizeX,
+                   y + type->TileHeight * TileSizeY / 2 - stats->SightRange * 
TileSizeY,
+                   stats->SightRange * TileSizeX * 2,
+                   stats->SightRange * TileSizeY * 2, 75);
+           } else if (ShowSightRange == 2) {
+               VideoFillTransCircleClip(ColorGreen,
+                   x + type->TileWidth * TileSizeX / 2,
+                   y + type->TileHeight * TileSizeY / 2,
+                   min((stats->SightRange + (type->TileWidth - 1) / 2) * 
TileSizeX,
+                   (stats->SightRange + (type->TileHeight - 1) / 2) * 
TileSizeY), 75);
+#else
            if (ShowSightRange == 1) {
                VideoFill75TransRectangleClip(ColorGreen,
                    x + type->TileWidth * TileSizeX / 2 - stats->SightRange * 
TileSizeX,
@@ -1847,6 +1964,7 @@
                    y + type->TileHeight * TileSizeY / 2,
                    min((stats->SightRange + (type->TileWidth - 1) / 2) * 
TileSizeX,
                    (stats->SightRange + (type->TileHeight - 1) / 2) * 
TileSizeY));
+#endif
            } else {
                VideoDrawCircleClip(ColorGreen,
                    x + type->TileWidth * TileSizeX / 2,
@@ -1890,6 +2008,10 @@
 */
 local void GraphicUnitPixels(const Unit* unit, const Graphic* sprite)
 {
+#ifdef USE_SDL_SURFACE
+    memcpy(&sprite->Palette->colors[208], unit->Colors->Colors, 
+       sizeof(SDL_Color) * 4);
+#else
     switch (VideoBpp) {
        case 8:
            *((struct __4pixel8__*)(((VMemType8*)sprite->Pixels) + 208)) =
@@ -1909,6 +2031,7 @@
                unit->Colors->Depth32;
            break;
     }
+#endif
 }
 
 #ifdef USE_OPENGL
Index: stratagus/src/editor/editloop.c
diff -u stratagus/src/editor/editloop.c:1.142 
stratagus/src/editor/editloop.c:1.143
--- stratagus/src/editor/editloop.c:1.142       Fri Nov 14 02:50:34 2003
+++ stratagus/src/editor/editloop.c     Mon Nov 17 14:14:30 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: editloop.c,v 1.142 2003/11/14 07:50:34 mr-russ Exp $
+//     $Id: editloop.c,v 1.143 2003/11/17 19:14:30 nehalmistry Exp $
 
 //@{
 
@@ -413,7 +413,9 @@
 */
 local void DrawTileIcons(void)
 {
+#ifndef USE_SDL_SURFACE
     unsigned char** tiles;
+#endif
     int x;
     int y;
     int i;
@@ -452,7 +454,9 @@
        MBUTTON_GEM_SQUARE + (TileToolDecoration ? 2 : 0), x + 40, y - 3);
     y += 20;
 
+#ifndef USE_SDL_SURFACE
     tiles = TheMap.Tiles;
+#endif
 
     y = TheUI.ButtonPanelY + 4;
     i = 0;
@@ -467,8 +471,12 @@
 #ifdef USE_OPENGL
            MapDrawTile(TheMap.Tileset->Table[0x10 + i * 16], x, y);
 #else
+#ifdef USE_SDL_SURFACE
+           VideoDrawTile(TheMap.Tileset->Table[0x10 + i * 16], x, y);
+#else
            VideoDrawTile(tiles[TheMap.Tileset->Table[0x10 + i * 16]], x, y);
 #endif
+#endif
            VideoDrawRectangle(ColorGray, x, y, TileSizeX, TileSizeY);
            if (TileCursor == i) {
                VideoDrawRectangle(ColorGreen, x + 1, y + 1, TileSizeX-2, 
TileSizeY-2);
@@ -657,7 +665,11 @@
 */
 local void DrawTileIcon(unsigned tilenum,unsigned x,unsigned y,unsigned flags)
 {
+#ifdef USE_SDL_SURFACE
+    SDL_Color color;
+#else
     VMemType color;
+#endif
 
     color = (flags & IconActive) ? ColorGray : ColorBlack;
 
@@ -685,8 +697,12 @@
 #ifdef USE_OPENGL
     MapDrawTile(TheMap.Tileset->Table[tilenum], x, y);
 #else
+#ifdef USE_SDL_SURFACE
+    VideoDrawTile(TheMap.Tileset->Table[tilenum], x, y);
+#else
     VideoDrawTile(TheMap.Tiles[TheMap.Tileset->Table[tilenum]], x, y);
 #endif
+#endif
 
     if (flags & IconSelected) {
        VideoDrawRectangleClip(ColorGreen, x, y, TileSizeX, TileSizeY);
@@ -776,8 +792,13 @@
 #ifdef USE_OPENGL
                    MapDrawTile(TheMap.Tileset->Table[0x10 + TileCursor * 16], 
tx, ty);
 #else
+#ifdef USE_SDL_SURFACE
+                   VideoDrawTile(TheMap.Tileset->Table[0x10 +
+                       TileCursor * 16], tx, ty);
+#else
                    VideoDrawTile(TheMap.Tiles[TheMap.Tileset->Table[0x10 +
                        TileCursor * 16]], tx, ty);
+#endif
 #endif
                }
            }
Index: stratagus/src/game/game.c
diff -u stratagus/src/game/game.c:1.112 stratagus/src/game/game.c:1.113
--- stratagus/src/game/game.c:1.112     Thu Nov 13 08:54:04 2003
+++ stratagus/src/game/game.c   Mon Nov 17 14:14:31 2003
@@ -27,7 +27,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: game.c,v 1.112 2003/11/13 13:54:04 pludov Exp $
+//     $Id: game.c,v 1.113 2003/11/17 19:14:31 nehalmistry Exp $
 
 //@{
 
@@ -395,11 +395,19 @@
     //
     // Graphic part
     //
+#ifdef USE_SDL_SURFACE
+    LoadRGB(&GlobalPalette,
+           s = strdcat3(StratagusLibPath, "/graphics/",
+               TheMap.Tileset->PaletteFile));
+    free(s);
+    VideoCreatePalette(&GlobalPalette);
+#else
     LoadRGB(GlobalPalette,
            s = strdcat3(StratagusLibPath, "/graphics/",
                TheMap.Tileset->PaletteFile));
     free(s);
     VideoCreatePalette(GlobalPalette);
+#endif
     InitIcons();
     LoadIcons();
 
Index: stratagus/src/game/intro.c
diff -u stratagus/src/game/intro.c:1.104 stratagus/src/game/intro.c:1.105
--- stratagus/src/game/intro.c:1.104    Sat Nov 15 15:53:42 2003
+++ stratagus/src/game/intro.c  Mon Nov 17 14:14:31 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: intro.c,v 1.104 2003/11/15 20:53:42 jsalmon3 Exp $
+//     $Id: intro.c,v 1.105 2003/11/17 19:14:31 nehalmistry Exp $
 
 //@{
 
@@ -876,7 +876,11 @@
 /**
 **     Draw a box with the text inside
 */
+#ifdef USE_SDL_SURFACE
+local void DrawStatBox(int x, int y, char* text, SDL_Color color, int percent)
+#else
 local void DrawStatBox(int x, int y, char* text, VMemType color, int percent)
+#endif
 {
     VideoFillRectangleClip(ColorBlack, x, y, 80, 24);
     VideoDrawRectangleClip(ColorYellow, x + 1, y + 1, 78, 22);
Index: stratagus/src/game/loadgame.c
diff -u stratagus/src/game/loadgame.c:1.69 stratagus/src/game/loadgame.c:1.70
--- stratagus/src/game/loadgame.c:1.69  Fri Nov 14 11:51:17 2003
+++ stratagus/src/game/loadgame.c       Mon Nov 17 14:14:31 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: loadgame.c,v 1.69 2003/11/14 16:51:17 pludov Exp $
+//     $Id: loadgame.c,v 1.70 2003/11/17 19:14:31 nehalmistry Exp $
 
 //@{
 
@@ -200,11 +200,19 @@
     }
 #endif
 
+#ifdef USE_SDL_SURFACE
+    LoadRGB(&GlobalPalette,
+           s = strdcat3(StratagusLibPath, "/graphics/",
+               TheMap.Tileset->PaletteFile));
+    free(s);
+    VideoCreatePalette(&GlobalPalette);
+#else
     LoadRGB(GlobalPalette,
            s = strdcat3(StratagusLibPath, "/graphics/",
                TheMap.Tileset->PaletteFile));
     free(s);
     VideoCreatePalette(GlobalPalette);
+#endif
     CreateMinimap();
 
     SetDefaultTextColors(TheUI.NormalFontColor, TheUI.ReverseFontColor);
Index: stratagus/src/include/cursor.h
diff -u stratagus/src/include/cursor.h:1.36 stratagus/src/include/cursor.h:1.37
--- stratagus/src/include/cursor.h:1.36 Tue Oct  7 08:03:40 2003
+++ stratagus/src/include/cursor.h      Mon Nov 17 14:14:32 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: cursor.h,v 1.36 2003/10/07 12:03:40 martinxyz Exp $
+//     $Id: cursor.h,v 1.37 2003/11/17 19:14:32 nehalmistry Exp $
 
 #ifndef __CURSOR_H__
 #define __CURSOR_H__
@@ -154,7 +154,11 @@
 
 // --- FILLED UP ---
 
+#ifdef USE_SDL_SURFACE
     Graphic*   Sprite;                 /// Cursor sprite image
+#else
+    Graphic*   Sprite;                 /// Cursor sprite image
+#endif
 };
 
     /// Cursor config reference
@@ -211,9 +215,13 @@
 
     /// Save/load rectangle region from/to screen
     /// Note: this is made extern for minimap only
+#ifdef USE_SDL_SURFACE
+extern void SaveCursorRectangle(void *buffer,int x,int y,int w,int h);
+extern void LoadCursorRectangle(void *buffer,int x,int y,int w,int h);
+#else
 extern void (*SaveCursorRectangle)(void *buffer,int x,int y,int w,int h);
 extern void (*LoadCursorRectangle)(void *buffer,int x,int y,int w,int h);
-
+#endif
 
     /// Invalidate given area and check if cursor won't need any
 extern void InvalidateAreaAndCheckCursor( int x, int y, int w, int h );
Index: stratagus/src/include/map.h
diff -u stratagus/src/include/map.h:1.101 stratagus/src/include/map.h:1.102
--- stratagus/src/include/map.h:1.101   Wed Oct 29 22:46:02 2003
+++ stratagus/src/include/map.h Mon Nov 17 14:14:32 2003
@@ -27,7 +27,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: map.h,v 1.101 2003/10/30 03:46:02 n0body Exp $
+//     $Id: map.h,v 1.102 2003/11/17 19:14:32 nehalmistry Exp $
 
 #ifndef __MAP_H__
 #define __MAP_H__
@@ -317,9 +317,15 @@
     int                        Terrain;        /// terrain type 
(summer,winter,...)
     Tileset*           Tileset;        /// tileset data
 
+#ifdef USE_SDL_SURFACE
+    unsigned int       TileCount;      /// how many tiles, 
+                                       /// == TileGraphic->NFrames
+    Graphic*           TileGraphic;    /// graphic for all the tiles
+#else
     unsigned           TileCount;      /// how many tiles are available
     unsigned char**    Tiles;          /// pointer to tile data
     Graphic*           TileData;       /// tiles graphic for map
+#endif
 
     char               Description[32];/// map description short
 
@@ -336,10 +342,17 @@
 extern char MustRedrawTile[MAXMAP_W*MAXMAP_H]; /// Flags must redraw tile
 
     /// Fast draw tile, display and video mode independ
+#ifdef USE_SDL_SURFACE
+extern void VideoDrawTile(int,int,int);
+#else
 extern void (*VideoDrawTile)(const unsigned char*,int,int);
+#endif
     /// Draws tiles display and video mode independ
+#ifdef USE_SDL_SURFACE
+extern void MapDrawTile(int,int,int);
+#else
 extern void (*MapDrawTile)(int,int,int);
-
+#endif
     /// Vision Table to see where to locate goals and vision
 extern unsigned char *VisionTable[3];
     /// Companion table for fast lookups
Index: stratagus/src/include/player.h
diff -u stratagus/src/include/player.h:1.77 stratagus/src/include/player.h:1.78
--- stratagus/src/include/player.h:1.77 Sun Nov 16 01:49:26 2003
+++ stratagus/src/include/player.h      Mon Nov 17 14:14:32 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: player.h,v 1.77 2003/11/16 06:49:26 mr-russ Exp $
+//     $Id: player.h,v 1.78 2003/11/17 19:14:32 nehalmistry Exp $
 
 #ifndef __PLAYER_H__
 #define __PLAYER_H__
@@ -343,7 +343,11 @@
     int                TotalKills;             /// How many unit killed
 
 // Display video
+#ifdef USE_SDL_SURFACE
+    SDL_Color  Color;                  /// color of units on minimap
+#else
     VMemType   Color;                  /// color of units on minimap
+#endif
 
     UnitColors UnitColors;             /// Unit colors for new units
 
@@ -453,7 +457,11 @@
 extern Player Players[PlayerMax];      /// All players
 extern Player* ThisPlayer;             /// Player on local computer
 extern int NoRescueCheck;              /// Disable rescue check
+#ifdef USE_SDL_SURFACE
+extern SDL_Color PlayerColors[PlayerMax];
+#else
 extern VMemType PlayerColors[PlayerMax];       /// Player colors
+#endif
 extern char* PlayerColorNames[PlayerMax];      /// Player color names
 
 extern PlayerRace PlayerRaces;         /// Player races
Index: stratagus/src/include/ui.h
diff -u stratagus/src/include/ui.h:1.77 stratagus/src/include/ui.h:1.78
--- stratagus/src/include/ui.h:1.77     Sat Nov  8 12:29:55 2003
+++ stratagus/src/include/ui.h  Mon Nov 17 14:14:33 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: ui.h,v 1.77 2003/11/08 17:29:55 jsalmon3 Exp $
+//     $Id: ui.h,v 1.78 2003/11/17 19:14:33 nehalmistry Exp $
 
 #ifndef __UI_H__
 #define __UI_H__
@@ -231,8 +231,13 @@
     int                TransportingTextY;
 
     // Completed bar
+#ifdef USE_SDL_SURFACE
+    SDL_Color  CompletedBarColorRGB;   /// color for completed bar
+    SDL_Color  CompletedBarColor;      /// color for completed bar
+#else
     VMemType   CompletedBarColorRGB;   /// color for completed bar
     VMemType   CompletedBarColor;      /// color for completed bar
+#endif
     int                CompletedBarX;          /// completed bar X position
     int                CompletedBarY;          /// completed bar Y position
     int                CompletedBarW;          /// completed bar width
@@ -284,7 +289,11 @@
     int                MinimapPosX;            /// minimap screen X position
     int                MinimapPosY;            /// minimap screen Y position
     int                MinimapTransparent;     /// unexplored areas are 
transparent
+#ifdef USE_SDL_SURFACE
+    SDL_Color  ViewportCursorColor;    /// minimap cursor color
+#else
     VMemType   ViewportCursorColor;    /// minimap cursor color
+#endif
 
     // The status line
     GraphicConfig StatusLine;          /// Status line background
Index: stratagus/src/include/unit.h
diff -u stratagus/src/include/unit.h:1.235 stratagus/src/include/unit.h:1.236
--- stratagus/src/include/unit.h:1.235  Tue Nov 11 04:24:02 2003
+++ stratagus/src/include/unit.h        Mon Nov 17 14:14:33 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: unit.h,v 1.235 2003/11/11 09:24:02 n0body Exp $
+//     $Id: unit.h,v 1.236 2003/11/17 19:14:33 nehalmistry Exp $
 
 #ifndef __UNIT_H__
 #define __UNIT_H__
@@ -378,6 +378,10 @@
 #include "upgrade.h"
 #include "construct.h"
 
+#ifdef USE_SDL_SURFACE
+#include "SDL.h"
+#endif
+
 #ifdef NEW_DECODRAW
 #include "deco.h"
 #endif
@@ -725,8 +729,11 @@
 extern char RevealAttacker;            /// Config: reveal attacker enabled
 extern const Viewport* CurrentViewport; /// CurrentViewport
 extern void DrawUnitSelection(const Unit*);
+#ifdef USE_SDL_SURFACE
+extern void (*DrawSelection)(SDL_Color, int, int, int, int);
+#else
 extern void (*DrawSelection)(VMemType, int, int, int, int);
-
+#endif
 extern int MaxSelectable;              /// How many units could be selected
 
 extern Unit** Selected;                        /// currently selected units
@@ -916,6 +923,20 @@
 
 //     in unit_draw.c
 //--------------------
+#ifdef USE_SDL_SURFACE
+    /// Draw nothing around unit
+extern void DrawSelectionNone(SDL_Color, int, int, int, int);
+    /// Draw circle around unit
+extern void DrawSelectionCircle(SDL_Color, int, int, int, int);
+    /// Draw circle filled with alpha around unit
+extern void DrawSelectionCircleWithTrans(SDL_Color, int, int, int, int);
+    /// Draw rectangle around unit
+extern void DrawSelectionRectangle(SDL_Color, int, int, int, int);
+    /// Draw rectangle filled with alpha around unit
+extern void DrawSelectionRectangleWithTrans(SDL_Color, int, int, int, int);
+    /// Draw corners around unit
+extern void DrawSelectionCorners(SDL_Color, int, int, int, int);
+#else
     /// Draw nothing around unit
 extern void DrawSelectionNone(VMemType, int, int, int, int);
     /// Draw circle around unit
@@ -928,6 +949,7 @@
 extern void DrawSelectionRectangleWithTrans(VMemType, int, int, int, int);
     /// Draw corners around unit
 extern void DrawSelectionCorners(VMemType, int, int, int, int);
+#endif
 
     /// Register CCL decorations features
 extern void DecorationCclRegister(void);
Index: stratagus/src/include/unittype.h
diff -u stratagus/src/include/unittype.h:1.129 
stratagus/src/include/unittype.h:1.130
--- stratagus/src/include/unittype.h:1.129      Sun Nov  9 17:13:58 2003
+++ stratagus/src/include/unittype.h    Mon Nov 17 14:14:33 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: unittype.h,v 1.129 2003/11/09 22:13:58 n0body Exp $
+//     $Id: unittype.h,v 1.130 2003/11/17 19:14:33 nehalmistry Exp $
 
 #ifndef __UNITTYPE_H__
 #define __UNITTYPE_H__
@@ -754,8 +754,11 @@
     int                MaxWorkers;             /// Maximum number of workers.
     ResourceInfo* ResInfo[MaxCosts];   /// Resource information.
     UnitType*  MustBuildOnTop;         /// Must be built on top of something.
+#ifdef USE_SDL_SURFACE
+    SDL_Color  NeutralMinimapColorRGB; /// Minimap Color for Neutral Units.
+#else
     VMemType   NeutralMinimapColorRGB; /// Minimap Color for Neutral Units.
-
+#endif
 
     UnitSound Sound;                   /// Sounds for events
     // FIXME: temporary solution
Index: stratagus/src/include/video.h
diff -u stratagus/src/include/video.h:1.95 stratagus/src/include/video.h:1.96
--- stratagus/src/include/video.h:1.95  Sat Nov  8 05:23:04 2003
+++ stratagus/src/include/video.h       Mon Nov 17 14:14:33 2003
@@ -10,7 +10,7 @@
 //
 /address@hidden video.h        -       The video headerfile. */
 //
-//     (c) Copyright 1999-2003 by Lutz Sammer
+//     (c) Copyright 1999-2003 by Lutz Sammer and Nehal Mistry
 //
 //      This program is free software; you can redistribute it and/or modify
 //      it under the terms of the GNU General Public License as published by
@@ -26,13 +26,524 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: video.h,v 1.95 2003/11/08 10:23:04 martinxyz Exp $
+//     $Id: video.h,v 1.96 2003/11/17 19:14:33 nehalmistry Exp $
 
 #ifndef __VIDEO_H__
 #define __VIDEO_H__
 
 //@{
 
+#ifdef USE_SDL_SURFACE
+
+#include "SDL.h"
+
+typedef struct _graphic_
+{
+    SDL_Surface *Surface;
+    SDL_Surface *SurfaceFlip;
+    SDL_Palette *Palette;
+    int Width;
+    int Height;
+    int NumFrames;
+} Graphic;
+
+typedef struct _unit_colors_
+{
+    SDL_Color Colors[4];
+} UnitColors;
+
+#ifdef DEBUG
+extern unsigned AllocatedGraphicMemory;        /// Allocated memory for objects
+extern unsigned CompressedGraphicMemory;/// memory for compressed objects
+#endif
+
+/**
+**     Event call back.
+**
+**     This is placed in the video part, because it depends on the video
+**     hardware driver.
+*/
+typedef struct _event_callback_ {
+
+       /// Callback for mouse button press
+    void (*ButtonPressed)(unsigned buttons);
+       /// Callback for mouse button release
+    void (*ButtonReleased)(unsigned buttons);
+       /// Callback for mouse move
+    void (*MouseMoved)(int x, int y);
+       /// Callback for mouse exit of game window
+    void (*MouseExit)(void);
+
+       /// Callback for key press
+    void (*KeyPressed)(unsigned keycode, unsigned keychar);
+       /// Callback for key release
+    void (*KeyReleased)(unsigned keycode, unsigned keychar);
+       /// Callback for key repeated
+    void (*KeyRepeated)(unsigned keycode, unsigned keychar);
+
+       /// Callback for network event
+    void (*NetworkEvent)(void);
+       /// Callback for sound output ready
+    void (*SoundReady)(void);
+
+} EventCallback;
+
+    ///        Graphic reference used during config/setup
+typedef struct _graphic_config_ {
+    char*      File;                   /// config graphic name or file
+    Graphic*   Graphic;                /// graphic pointer to use to run time
+} GraphicConfig;
+
+/**
+**     General graphic object type.
+*/
+typedef struct _graphic_type_ {
+       ///     Draw the object unclipped.
+    void (*Draw)(const Graphic* o, unsigned f, int x, int y);
+       ///     Draw the object unclipped and flipped in X direction.
+    void (*DrawX)(const Graphic* o, unsigned f, int x, int y);
+       ///     Draw the object clipped to the current clipping.
+    void (*DrawClip)(const Graphic* o, unsigned f, int x, int y);
+       ///     Draw the object clipped and flipped in X direction.
+    void (*DrawClipX)(const Graphic* o, unsigned f, int x, int y);
+       ///     Draw the shadow object clipped to the current clipping.
+    void (*DrawShadowClip)(const Graphic* o, unsigned f, int x, int y);
+       ///     Draw the shadow object clipped and flipped in X direction.
+    void (*DrawShadowClipX)(const Graphic* o, unsigned f, int x, int y);
+       ///     Draw part of the object unclipped.
+    void (*DrawSub)(const Graphic* o, int gx, int gy,
+       int w, int h, int x, int y);
+       ///     Draw part of the object unclipped and flipped in X direction.
+    void (*DrawSubX)(const Graphic* o, int gx, int gy,
+       int w, int h, int x, int y);
+       ///     Draw part of the object clipped to the current clipping.
+    void (*DrawSubClip)(const Graphic* o, int gx, int gy,
+       int w, int h, int x, int y);
+       ///     Draw part of the object clipped and flipped in X direction.
+    void (*DrawSubClipX)(const Graphic* o, int gx, int gy,
+       int w, int h, int x, int y);
+
+       ///     Draw the object unclipped and zoomed.
+    void (*DrawZoom)(const Graphic* o, unsigned f, int x, int y, int z);
+
+    // FIXME: add zooming functions.
+
+       ///     Free the object.
+    void (*Free)(Graphic* o);
+} GraphicType;
+
+    ///        Creates a shared hardware palette from an independent Palette 
struct.
+extern SDL_Palette* VideoCreateSharedPalette(const SDL_Palette* palette);
+
+    ///        Free a shared hardware palette.
+extern void VideoFreeSharedPalette(SDL_Palette* palette);
+
+extern int ColorCycleAll;              /// Flag color cycle palettes
+
+/**
+**     Typedef for palette links.
+*/
+typedef struct _palette_link_ PaletteLink;
+
+/**
+**     Links all palettes together to join the same palettes.
+*/
+struct _palette_link_ {
+    PaletteLink*       Next;           /// Next palette
+    SDL_Palette*       Palette;        /// Palette in hardware format
+    long               Checksum;       /// Checksum for quick lookup
+    int                        RefCount;       /// Reference counter
+};
+
+    /**
+    ** Video synchronization speed. Synchronization time in percent.
+    ** If =0, video framerate is not synchronized. 100 is exact
+    ** CYCLES_PER_SECOND (30). Game will try to redraw screen within
+    ** intervals of VideoSyncSpeed, not more, not less.
+    ** @see CYCLES_PER_SECOND @see VideoInterrupts
+    */
+extern int VideoSyncSpeed;
+
+extern volatile int VideoInterrupts;
+
+    // 1 if mouse cursor is inside main window, else 0
+extern int InMainWindow;
+
+    ///        Wanted videomode, fullscreen or windowed.
+extern char VideoFullScreen;
+
+    ///        Initialize Pixels[] for all players.
+    ///        (bring Players[] in sync with Pixels[])
+extern void SetPlayersPalette(void);
+
+    ///        Lock the screen for display
+extern void VideoLockScreen(void);
+
+    ///        Unlock the screen for display
+extern void VideoUnlockScreen(void);
+
+    // 1 if mouse cursor is inside main window, else 0
+extern int InMainWindow;
+
+    ///        Wanted videomode, fullscreen or windowed.
+extern char VideoFullScreen;
+
+    /**
+    ** Architecture-dependant video depth. Set by InitVideoXXX, if 0.
+    ** (8,15,16,24,32)
+    ** @see InitVideo @see InitVideoSdl
+    ** @see main
+    */
+extern int VideoDepth;
+
+    /**
+    ** Architecture-dependant video bpp (bits pro pixel).
+    ** Set by InitVideoXXX. (8,16,24,32)
+    ** @see InitVideo @see InitVideoSdl
+    ** @see main
+    */
+extern int VideoBpp;
+
+    /**
+    ** Architecture-dependant videomemory. Set by InitVideoXXX.
+    ** FIXME: need a new function to set it, see #ifdef SDL code
+    ** @see InitVideo @see InitVideoSdl
+    ** @see VMemType
+    */
+extern SDL_Surface* TheScreen;
+
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+#define RMASK 0xff000000
+#define GMASK 0x00ff0000
+#define BMASK 0x0000ff00
+#define AMASK 0x000000ff
+#else
+#define RMASK 0x000000ff
+#define GMASK 0x0000ff00
+#define BMASK 0x00ff0000
+#define AMASK 0xff000000
+#endif
+
+extern SDL_Palette *Pixels;
+
+    ///        Loaded system palette. 256-entries long, active system palette.
+// FIXME: use SDL_Palette
+extern SDL_Palette GlobalPalette;
+
+typedef unsigned char GraphicData;     /// generic graphic data type
+
+    /// initialize the video part
+extern void InitVideo(void);
+
+extern void RealizeScreen(void);
+
+    /// Resize a graphic
+extern void ResizeGraphic(Graphic* g, int w, int h);
+
+    ///        Load graphic from PNG file
+extern Graphic* LoadGraphicPNG(const char* name);
+
+    /// Load graphic
+extern Graphic* LoadGraphic(const char* file);
+
+    /// New graphic
+extern Graphic* NewGraphic(unsigned d, int w, int h);
+
+    ///        Initializes video synchronization.
+extern void SetVideoSync(void);
+
+    ///        Clear video screen
+extern void VideoClearScreen(void);
+
+    /// Make graphic
+extern Graphic* MakeGraphic(unsigned, int, int, void*, unsigned);
+
+    ///        Load a picture and display it on the screen (full screen),
+    ///        changing the colormap and so on..
+extern void DisplayPicture(const char *name);
+
+    /// Init graphic
+extern void InitGraphic(void);
+
+    /// Init sprite
+extern void InitSprite(void);
+
+    /// Init line draw
+extern void InitLineDraw(void);
+
+    /// Simply invalidates whole window or screen.
+extern void Invalidate(void);
+
+    ///        Invalidates selected area on window or screen. Use for accurate
+    ///        redrawing. in so
+extern void InvalidateArea(int x, int y, int w, int h);
+
+    ///        Set clipping for nearly all vector primitives. Functions which 
support
+    ///        clipping will be marked Clip. Set the system-wide clipping 
rectangle.
+extern void SetClipping(int left, int top, int right, int bottom);
+
+    ///        Realize video memory.
+extern void RealizeVideoMemory(void);
+
+    ///        Load palette from resource. Just loads palette, to set it use
+    ///        VideoCreatePalette, which sets system palette.
+// FIXME: use SDL_Palette
+extern void LoadRGB(SDL_Palette* pal,const char* name);
+
+    ///        Set the system hardware palette from an independant Palette 
struct.
+extern void VideoCreatePalette(const SDL_Palette* palette);
+
+    /// Load sprite
+extern Graphic* LoadSprite(const char* file, int w, int h);
+
+    ///        Draw part of a graphic clipped and faded.
+extern void VideoDrawSubClipFaded(Graphic* graphic, int gx, int gy,
+    int w, int h, int x, int y, unsigned char fade);
+
+    ///        Save a screenshot to a PNG file
+extern void SaveScreenshotPNG(const char* name);
+
+    ///        Creates a hardware palette from an independent Palette struct.
+extern SDL_Palette* VideoCreateNewPalette(const SDL_Palette* palette);
+
+    /// Prints warning if video is too slow..
+extern void CheckVideoInterrupts(void);
+
+    ///        Process all system events. Returns if the time for a frame is 
over
+extern void WaitEventsOneFrame(const EventCallback* callbacks);
+
+    /// Toggle full screen mode
+extern void ToggleFullScreen(void);
+
+    ///        Push current clipping.
+extern void PushClipping(void);
+
+    ///        Pop current clipping.
+extern void PopClipping(void);
+
+    /// Returns the ticks in ms since start
+extern unsigned long GetTicks(void);
+
+    /// Toggle mouse grab mode
+extern void ToggleGrabMouse(int mode);
+
+extern EventCallback* Callbacks;       /// Current callbacks
+extern EventCallback GameCallbacks;    /// Game callbacks
+extern EventCallback MenuCallbacks;    /// Menu callbacks
+
+    ///        Maps RGB to a hardware dependent pixel.
+extern SDL_Color VideoMapRGB(int r, int g, int b);
+
+extern SDL_Color ColorBlack;
+extern SDL_Color ColorDarkGreen;
+extern SDL_Color ColorBlue;
+extern SDL_Color ColorOrange;
+extern SDL_Color ColorWhite;
+extern SDL_Color ColorGray;
+extern SDL_Color ColorRed;
+extern SDL_Color ColorGreen;
+extern SDL_Color ColorYellow;
+
+extern int ColorWaterCycleStart;       /// color # start for color cycling
+extern int ColorWaterCycleEnd;         /// color # end   for color cycling
+extern int ColorIconCycleStart;                /// color # start for color 
cycling
+extern int ColorIconCycleEnd;          /// color # end   for color cycling
+extern int ColorBuildingCycleStart;    /// color # start for color cycling
+extern int ColorBuildingCycleEnd;      /// color # end   for color cycling
+
+// FIXME: check these out, clean up if we can
+// FIXME: check these out, clean up if we can
+// FIXME: check these out, clean up if we can
+    ///        Draw pixel unclipped.
+extern void VideoDrawPixel(SDL_Color color, int x, int y);
+
+    ///        Draw translucent pixel unclipped.
+extern void VideoDrawTransPixel(SDL_Color color, int x, int y,
+    unsigned char alpha);
+
+    ///        Draw pixel clipped to current clip setting.
+extern void VideoDrawPixelClip(SDL_Color color, int x, int y);
+
+    ///        Draw translucent pixel clipped to current clip setting.
+extern void VideoDrawTransPixelClip(SDL_Color color, int x, int y,
+    unsigned char alpha);
+
+    ///        Draw vertical line unclipped.
+extern void VideoDrawVLine(SDL_Color color, int x, int y,
+    int height);
+
+    ///        Draw translucent vertical line unclipped.
+extern void VideoDrawTransVLine(SDL_Color color, int x, int y,
+    int height, unsigned char alpha);
+
+    ///        Draw vertical line clipped to current clip setting
+extern void VideoDrawVLineClip(SDL_Color color, int x, int y,
+    int height);
+
+    ///        Draw translucent vertical line clipped to current clip setting
+extern void VideoDrawTransVLineClip(SDL_Color color, int x, int y,
+    int height, unsigned char alpha);
+
+    ///        Draw horizontal line unclipped.
+extern void VideoDrawHLine(SDL_Color color, int x, int y,
+    int width);
+
+    ///        Draw translucent horizontal line unclipped.
+extern void VideoDrawTransHLine(SDL_Color color, int x, int y,
+    int width, unsigned char alpha);
+
+    ///        Draw horizontal line clipped to current clip setting
+extern void VideoDrawHLineClip(SDL_Color color, int x, int y,
+    int width);
+
+    ///        Draw translucent horizontal line clipped to current clip setting
+extern void VideoDrawTransHLineClip(SDL_Color color, int x, int y,
+    int width, unsigned char alpha);
+
+    ///        Draw line unclipped.
+extern void VideoDrawLine(SDL_Color color, int sx, int sy, int dx, int dy);
+
+    ///        Draw translucent line unclipped.
+extern void VideoDrawTransLine(SDL_Color color, int sx, int sy, int dx, int dy,
+    unsigned char alpha);
+
+    ///        Draw line clipped to current clip setting
+extern void VideoDrawLineClip(SDL_Color color, int sx, int sy, int dx, int dy);
+
+    ///        Draw translucent line clipped to current clip setting
+extern void VideoDrawTransLineClip(SDL_Color color, int sx, int sy,
+    int dx, int dy, unsigned char alpha);
+
+    ///        Draw rectangle.
+extern void VideoDrawRectangle(SDL_Color color, int x, int y,
+    int w, int h);
+
+    ///        Draw translucent rectangle.
+extern void VideoDrawTransRectangle(SDL_Color color, int x, int y,
+    int w, int h, unsigned char alpha);
+
+    ///        Draw rectangle clipped.
+extern void VideoDrawRectangleClip(SDL_Color color, int x, int y,
+    int w, int h);
+
+    ///        Draw translucent rectangle clipped.
+extern void VideoDrawTransRectangleClip(SDL_Color color, int x, int y,
+    int w, int h, unsigned char alpha);
+
+    ///        Draw 8bit raw graphic data clipped, using given pixel pallette
+extern void VideoDrawRawClip(SDL_Surface *surface, int x, int y, int w, int h);
+
+    /// Does ColorCycling..
+extern void ColorCycle(void);
+
+    ///        Draw part of a graphic clipped and faded.
+extern void VideoDrawSubClipFaded(Graphic* graphic, int gx, int gy,
+    int w, int h, int x, int y, unsigned char fade);
+
+    ///        Draw circle.
+extern void VideoDrawCircle(SDL_Color color, int x, int y, int r);
+
+    ///        Draw translucent circle.
+extern void VideoDrawTransCircle(SDL_Color color, int x, int y, int r,
+    unsigned char alpha);
+
+    ///        Draw circle clipped.
+extern void VideoDrawCircleClip(SDL_Color color, int x, int y, int r);
+
+    ///        Draw translucent circle clipped.
+extern void VideoDrawTransCircleClip(SDL_Color color, int x, int y, int r,
+    unsigned char alpha);
+
+    ///        Fill rectangle.
+extern void VideoFillRectangle(SDL_Color color, int x, int y,
+    int w, int h);
+
+    ///        Fill translucent rectangle.
+extern void VideoFillTransRectangle(SDL_Color color, int x, int y,
+    int w, int h, unsigned char alpha);
+
+    ///        Fill rectangle clipped.
+extern void VideoFillRectangleClip(SDL_Color color, int x, int y,
+    int w, int h);
+
+    ///        Fill translucent rectangle clipped.
+extern void VideoFillTransRectangleClip(SDL_Color color, int x, int y,
+    int w, int h, unsigned char alpha);
+
+    ///        Fill circle.
+extern void VideoFillCircle(SDL_Color color, int x, int y, int r);
+
+    ///        Fill translucent circle.
+extern void VideoFillTransCircle(SDL_Color color, int x, int y, int r,
+    unsigned char alpha);
+
+    ///        Fill circle clipped.
+extern void VideoFillCircleClip(SDL_Color color, int x, int y, int r);
+
+    ///        Fill translucent circle clipped.
+extern void VideoFillTransCircleClip(SDL_Color color, int x, int y, int r,
+    unsigned char alpha);
+
+    ///        Draw a graphic object unclipped.
+extern void VideoDraw(const Graphic*, unsigned, int, int);
+
+    ///        Draw a graphic object clipped to the current clipping.
+extern void VideoDrawSub(const Graphic*, int, int, int, int, int, int);
+
+    ///        Draw a graphic object clipped to the current clipping.
+extern void VideoDrawClip(const Graphic*, unsigned frame, int x, int y);
+
+    ///        Draw a graphic object clipped to the current clipping.
+extern void VideoDrawSubClip(const Graphic*, int ix, int iy, int w, 
+    int h, int x, int y);
+
+// FIXME FIXME FIXME: need to implement all of this
+    ///        Draw a graphic object unclipped.
+//#define VideoDraw(o, f, x, y)        //((o)->Type->Draw)((o), (f), (x), (y))
+    ///        Draw a graphic object unclipped and flipped in X direction.
+#define VideoDrawX(o, f, x, y) //((o)->Type->DrawX)((o), (f), (x), (y))
+    ///        Free a graphic object.
+#define VideoFree(o)   //((o)->Type->Free)((o))
+    ///        Save (NULL) free a graphic object.
+#define VideoSaveFree(o) // do { if ((o)) ((o)->Type->Free)((o)); } while(0)
+//#define VideoDrawSub(a,b,c,d,e,f,g)
+    ///        Draw a graphic object clipped to the current clipping.
+//#define VideoDrawSubClip(o, ix, iy, w, h, x, y)
+    ///        Draw a graphic object clipped and flipped in X direction.
+#define VideoDrawClipX(o, f, x, y)     //((o)->Type->DrawClipX)((o), (f), (x), 
(y))
+    ///        Draw a shadow graphic object clipped to the current clipping.
+#define VideoDrawShadowClip(o, f, x, y)        
//((o)->Type->DrawShadowClip)((o),(f),(x),(y))
+    ///        Draw a shadow graphic object clipped and flipped in X direction.
+#define VideoDrawShadowClipX(o, f, x, y)    
//((o)->Type->DrawShadowClipX)((o),(f),(x),(y))
+
+    /// Get the width of a single frame of a graphic object
+#define VideoGraphicWidth(o)   ((o)->Width)
+    /// Get the height of a single frame of a graphic object
+#define VideoGraphicHeight(o)  ((o)->Height)
+#define VideoGraphicFrames(o) ((o)->NumFrames)
+//    ((o)->Type->DrawSubClip)((o), (ix), (iy), (w), (h), (x), (y))
+
+
+    /// MACRO defines speed of colorcycling FIXME: should be made configurable
+#define COLOR_CYCLE_SPEED      (CYCLES_PER_SECOND/4)
+
+extern SDL_Surface* MainSurface;
+
+/*
+#define VideoMemory8   (&VideoMemory->D8)      /// video memory  8bpp
+#define VideoMemory16  (&VideoMemory->D16)     /// video memory 16bpp
+#define VideoMemory24  (&VideoMemory->D24)     /// video memory 24bpp
+#define VideoMemory32  (&VideoMemory->D32)     /// video memory 32bpp
+*/
+
+
+#else
+
+// OOOOOOOOOLLLLLLLLDDDDDDDD VIDEO MODE *********************************
+// OOOOOOOOOLLLLLLLLDDDDDDDD VIDEO MODE *********************************
+// OOOOOOOOOLLLLLLLLDDDDDDDD VIDEO MODE *********************************
+// OOOOOOOOOLLLLLLLLDDDDDDDD VIDEO MODE *********************************
+
 /*----------------------------------------------------------------------------
 --     Documentation
 ----------------------------------------------------------------------------*/
@@ -900,6 +1411,8 @@
 
     /// Returns the ticks in ms since start
 extern unsigned long GetTicks(void);
+
+#endif
 
 //@}
 
Index: stratagus/src/map/map.c
diff -u stratagus/src/map/map.c:1.64 stratagus/src/map/map.c:1.65
--- stratagus/src/map/map.c:1.64        Fri Nov 14 23:38:51 2003
+++ stratagus/src/map/map.c     Mon Nov 17 14:14:34 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: map.c,v 1.64 2003/11/15 04:38:51 mr-russ Exp $
+//     $Id: map.c,v 1.65 2003/11/17 19:14:34 nehalmistry Exp $
 
 //@{
 
@@ -643,8 +643,11 @@
 {
     free(TheMap.Fields);
     free(TheMap.TerrainName);
+#ifndef USE_SDL_SURFACE
+// FIXME: merge
     free(TheMap.TileData);
     free(TheMap.Tiles);
+#endif
     free(TheMap.Visible[0]);
 
     // Tileset freeed by Tileset?
Index: stratagus/src/map/map_draw.c
diff -u stratagus/src/map/map_draw.c:1.53 stratagus/src/map/map_draw.c:1.54
--- stratagus/src/map/map_draw.c:1.53   Sat Nov  8 19:13:11 2003
+++ stratagus/src/map/map_draw.c        Mon Nov 17 14:14:35 2003
@@ -29,7 +29,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: map_draw.c,v 1.53 2003/11/09 00:13:11 n0body Exp $
+//     $Id: map_draw.c,v 1.54 2003/11/17 19:14:35 nehalmistry Exp $
 
 //@{
 
@@ -182,14 +182,22 @@
 **
 **     Draws tiles display and video mode independ
 */
+#ifdef USE_SDL_SURFACE
+global void VideoDrawTile(const int, int, int);
+#else
 global void (*VideoDrawTile)(const GraphicData*, int, int);
+#endif
 
 /**
 **     Fast draw tile function pointer with cache support.
 **
 **     Draws tiles display and video mode independ
 */
+#ifdef USE_SDL_SURFACE
+global void MapDrawTile(int, int, int);
+#else
 global void (*MapDrawTile)(int, int, int);
+#endif
 
 #ifdef NEW_DECODRAW
 /**
@@ -272,6 +280,39 @@
 --     Draw tile
 ----------------------------------------------------------------------------*/
 
+#ifdef USE_SDL_SURFACE
+/**
+**     Fast draw tile.
+**
+**     @param tile     pointer to tile graphic data
+**     @param x        X position into video memory
+**     @param y        Y position into video memory
+**
+**     @note This is a hot spot in the program.
+**     (50% cpu time was needed for this, now only 32%)
+**
+**     @see GRID
+*/
+global void VideoDrawTile(const int tile, int x, int y)
+{
+    int tilepitch;
+    SDL_Rect srect;
+    SDL_Rect drect;
+
+    tilepitch = TheMap.TileGraphic->Width / TileSizeX;
+
+    srect.x = TileSizeX * (tile % tilepitch);
+    srect.y = TileSizeY * (tile / tilepitch);
+
+    drect.x = x;
+    drect.y = y;
+
+    SDL_LockSurface(TheScreen);
+    SDL_BlitSurface(TheMap.TileGraphic->Surface, &srect, 
+       TheScreen, &drect);
+    SDL_UnlockSurface(TheScreen);
+}
+#else
 /**
 **     Fast draw 16x16 tile for 8 bpp video modes.
 **
@@ -673,6 +714,7 @@
     }
 #endif
 }
+#endif // ifdef USE_SDL_SURFACE
 
 #ifdef NEW_DECODRAW
 /**
@@ -1870,6 +1912,7 @@
 
 #ifdef USE_SMART_TILECACHE     // {
 
+#ifndef USE_SDL_SURFACE
 /**
 **     Fast draw 16x16 tile for 8 bpp from cache.
 **
@@ -2171,9 +2214,17 @@
        dp += da;
     }
 }
+#endif // ifndef USE_SDL_SURFACE
 
 // ---------------------------------------------------------------------------
 
+#ifdef USE_SDL_SURFACE
+local void MapDrawTile(int tile, int x, int y)
+{
+    VideoDrawTile(tile, x, y);
+}
+#else
+
 /**
 **     Draw 16x16 tile for 8 bpp video modes with cache support.
 **
@@ -2311,6 +2362,7 @@
        TileCached[tile] = VideoMemory32 + x + y * VideoWidth;
     }
 }
+#endif
 
 /**
 **     Draw tile.
@@ -2495,6 +2547,10 @@
     }
 #endif
 
+#ifdef USE_SDL_SURFACE
+    // FIXME: what to do?
+    i = 0;
+#else
     if (VideoBpp == 15 || VideoBpp == 16) {
        //
        //      Convert 16 bit pixel table into two 32 bit tables.
@@ -2504,6 +2560,7 @@
            PixelsHigh[i] = (((VMemType16*)TheMap.TileData->Pixels)[i] & 
0xFFFF) << 16;
        }
     }
+#endif
 }
 
 /**
@@ -2853,6 +2910,7 @@
     DebugCheck(!MapDecoration);
 
 #else
+#ifndef USE_SDL_SURFACE
     if (TileSizeX == 16 && TileSizeY == 16) {
        switch (VideoBpp) {
            case  8:
@@ -2923,6 +2981,7 @@
        printf("Tile size not supported: (%dx%d)\n", TileSizeX, TileSizeY);
        exit(1);
     }
+#endif // ifdef USE_SDL_SURFACE
 #endif // NEW_DECODRAW
 
 #endif // USE_OPENGL
Index: stratagus/src/map/map_fog.c
diff -u stratagus/src/map/map_fog.c:1.113 stratagus/src/map/map_fog.c:1.114
--- stratagus/src/map/map_fog.c:1.113   Tue Nov 11 04:24:03 2003
+++ stratagus/src/map/map_fog.c Mon Nov 17 14:14:36 2003
@@ -27,7 +27,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: map_fog.c,v 1.113 2003/11/11 09:24:03 n0body Exp $
+//     $Id: map_fog.c,v 1.114 2003/11/17 19:14:36 nehalmistry Exp $
 
 //@{
 
@@ -120,6 +120,12 @@
 
 global unsigned char* VisionTable[3];
 global int* VisionLookup;
+
+#ifdef USE_SDL_SURFACE
+local void (*VideoDrawUnexplored)(const int, int, int);
+local void (*VideoDrawFog)(const int, int, int);
+local void (*VideoDrawOnlyFog)(const int, int x, int y);
+#else
 /**
 **     Draw unexplored area function pointer. (display and video mode independ)
 */
@@ -134,6 +140,7 @@
 **     Draw only fog of war function pointer. (display and video mode independ)
 */
 local void (*VideoDrawOnlyFog)(const GraphicData*, int x, int y);
+#endif
 
 /**
 **     Precalculated fog of war alpha table.
@@ -486,6 +493,38 @@
 --     Draw fog solid
 ----------------------------------------------------------------------------*/
 
+#ifdef USE_SDL_SURFACE
+/**
+**     Fast draw solid fog of war 16x16 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 VideoDrawFogSolid(const int tile, int x, int y)
+{
+    int tilepitch;
+    SDL_Rect srect;
+    SDL_Rect drect;
+
+    tilepitch = TheMap.TileGraphic->Width / TileSizeX;
+
+    srect.x = TileSizeX * (tile % tilepitch);
+    srect.y = TileSizeY * (tile / tilepitch);
+
+    drect.x = x;
+    drect.y = y;
+
+    SDL_LockSurface(TheScreen);
+    SDL_BlitSurface(TheMap.TileGraphic->Surface, &srect, TheScreen, &drect);
+    SDL_UnlockSurface(TheScreen);
+}
+
+global void VideoDrawUnexploredSolid(const int tile, int x, int y)
+{
+
+}
+#else
 // Routines for 8 bit displays .. --------------------------------------------
 
 /**
@@ -1471,6 +1510,7 @@
        dp += da;
     }
 }
+#endif
 
 /**
 **     Fast draw solid unexplored tile.
@@ -1491,6 +1531,27 @@
 --     Draw real fog :-)
 ----------------------------------------------------------------------------*/
 
+#ifdef USE_SDL_SURFACE
+global void VideoDrawFogAlpha(const int tile, int x, int y)
+{
+    int tilepitch;
+    SDL_Rect srect;
+    SDL_Rect drect;
+
+    tilepitch = TheMap.TileGraphic->Width / TileSizeX;
+
+    srect.x = TileSizeX * (tile % tilepitch);
+    srect.y = TileSizeY * (tile / tilepitch);
+
+    drect.x = x;
+    drect.y = y;
+
+    SDL_LockSurface(TheScreen);
+    SDL_BlitSurface(TheMap.TileGraphic->Surface, &srect, TheScreen, &drect);
+    SDL_UnlockSurface(TheScreen);
+}
+
+#else
 // Routines for 8 bit displays .. --------------------------------------------
 
 /**
@@ -2424,6 +2485,7 @@
        dp += da;
     }
 }
+#endif
 
 // Routines for OpenGL .. -------------------------------------------
 
@@ -2590,7 +2652,11 @@
     }
 
     if (tile2) {
+#ifdef USE_SDL_SURFACE
+       VideoDrawUnexplored(tile2, dx, dy);
+#else
        VideoDrawUnexplored(TheMap.Tiles[tile2], dx, dy);
+#endif
        if (tile2 == tile) {            // no same fog over unexplored
 //         if (tile != 0xf) {
 //             TheMap.Fields[sx].VisibleLastFrame |= MapFieldPartiallyVisible;
@@ -2600,13 +2666,21 @@
     }
     if (IsMapFieldVisible(ThisPlayer, x, y) || ReplayRevealMap) {
        if (tile) {
+#ifdef USE_SDL_SURFACE
+           VideoDrawFog(tile, dx, dy);
+#else
            VideoDrawFog(TheMap.Tiles[tile], dx, dy);
+#endif
 //         TheMap.Fields[sx].VisibleLastFrame |= MapFieldPartiallyVisible;
 //     } else {
 //         TheMap.Fields[sx].VisibleLastFrame |= MapFieldCompletelyVisible;
        }
     } else {
+#ifdef USE_SDL_SURFACE
+       VideoDrawOnlyFog(UNEXPLORED_TILE, dx, dy);
+#else
        VideoDrawOnlyFog(TheMap.Tiles[UNEXPLORED_TILE], dx, dy);
+#endif
     }   
 }
 
@@ -2676,8 +2750,12 @@
 #ifdef USE_OPENGL
                        MapDrawTile(UNEXPLORED_TILE, dx, dy);
 #else
+#ifdef USE_SDL_SURFACE
+                       VideoDrawTile(UNEXPLORED_TILE, dx, dy);
+#else
                        VideoDrawTile(TheMap.Tiles[UNEXPLORED_TILE], dx, dy);
 #endif
+#endif
                    }
 #endif
 
@@ -2773,6 +2851,10 @@
     VideoDrawOnlyFog = VideoDrawOnlyFogAlphaOpenGL;
     VideoDrawUnexplored = VideoDrawUnexploredSolidOpenGL;
 #else
+
+#ifdef USE_SDL_SURFACE
+
+#else
     if (!OriginalFogOfWar) {
        int i;
        int n;
@@ -2782,7 +2864,6 @@
        int rshft, gshft, bshft;
        int rloss, gloss, bloss;
 
-
        switch (VideoDepth) {
            case 8:
                n = 1 << (sizeof(VMemType8) * 8);
@@ -3036,6 +3117,7 @@
            exit(1);
        }
     }
+#endif
 #endif
 }
 
Index: stratagus/src/map/minimap.c
diff -u stratagus/src/map/minimap.c:1.73 stratagus/src/map/minimap.c:1.74
--- stratagus/src/map/minimap.c:1.73    Sat Nov  1 06:33:09 2003
+++ stratagus/src/map/minimap.c Mon Nov 17 14:14:36 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: minimap.c,v 1.73 2003/11/01 11:33:09 pludov Exp $
+//     $Id: minimap.c,v 1.74 2003/11/17 19:14:36 nehalmistry Exp $
 
 //@{
 
@@ -53,7 +53,11 @@
 ----------------------------------------------------------------------------*/
 
 local Graphic* MinimapTerrainGraphic;  /// generated minimap terrain
+#ifdef USE_SDL_SURFACE
+local SDL_Surface* MinimapGraphic;     /// generated minimap
+#else
 local VMemType* MinimapGraphic;                /// generated minimap
+#endif
 local int* Minimap2MapX;               /// fast conversion table
 local int* Minimap2MapY;               /// fast conversion table
 local int Map2MinimapX[MaxMapWidth];   /// fast conversion table
@@ -136,8 +140,13 @@
            }
 
            tile = TheMap.Fields[x + y].Tile;
+
+#ifdef USE_SDL_SURFACE
+           // FIXME: todod
+#else
            ((unsigned char*)MinimapTerrainGraphic->Frames)[mx + my * 
TheUI.MinimapW] =
                TheMap.Tiles[tile][7 + (mx % scalex) * 8 + (6 + (my % scaley) * 
8) * TileSizeX];
+#endif
        }
     }
 }
@@ -171,8 +180,13 @@
            int tile;
 
            tile = TheMap.Fields[Minimap2MapX[mx] + Minimap2MapY[my]].Tile;
+
+#ifdef USE_SDL_SURFACE
+           // FIXME: todo
+#else
            ((unsigned char*)MinimapTerrainGraphic->Frames)[mx + my * 
TheUI.MinimapW] =
                TheMap.Tiles[tile][7 + (mx % scalex) * 8 + (6 + (my % scaley) * 
8) * TileSizeX];
+#endif
        }
     }
 }
@@ -227,12 +241,48 @@
     }
 
     MinimapTerrainGraphic = NewGraphic(8, TheUI.MinimapW, TheUI.MinimapH);
+
+#ifdef USE_SDL_SURFACE
+    Uint32 rmask, gmask, bmask, amask;
+// FIXME: use defines for this?
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+    rmask = 0xff000000;
+    gmask = 0x00ff0000;
+    bmask = 0x0000ff00;
+    amask = 0x000000ff;
+#else
+    rmask = 0x000000ff;
+    gmask = 0x0000ff00;
+    bmask = 0x00ff0000;
+    amask = 0xff000000;
+#endif
+    // FIXME: does NewGraphic do this for MinimapTerrainGraphic??
+    // FIXME: what depth?
+    MinimapGraphic = SDL_CreateRGBSurface(SDL_SWSURFACE, TheUI.MinimapW,
+       TheUI.MinimapH, 8, rmask, gmask, bmask, amask);
+#else
     memset(MinimapTerrainGraphic->Frames, 0, TheUI.MinimapW * TheUI.MinimapH);
     MinimapGraphic = calloc(TheUI.MinimapW * TheUI.MinimapH, sizeof(VMemType));
+#endif
 
     // FIXME: looks too complicated
     for (y = 0; y < TheUI.MinimapH; ++y) {
        for (x = 0; x < TheUI.MinimapW; ++x) {
+#ifdef USE_SDL_SURFACE
+           SDL_Color c;
+           int b;
+
+           c = TheUI.MinimapPanel.Graphic->Surface->format->palette->colors[
+               x + (TheUI.MinimapPosX - TheUI.MinimapPanelX) + (y + 
TheUI.MinimapPosY - 
+               TheUI.MinimapPanelY) * TheUI.MinimapPanel.Graphic->Width];
+
+           b = MinimapGraphic->format->BytesPerPixel;
+
+           // FIXME: rgb: todo: ack
+
+//         ((char*)MinimapGraphic->pixels)[x * b + y * TheUI.MinimapW * b] = 
+//             VideoMapRGB(c.r, c.g, c.b);
+#else
            Palette p;
            // this only copies the panel background... honest.
            p = GlobalPalette[
@@ -241,13 +291,19 @@
                    (y + TheUI.MinimapPosY - TheUI.MinimapPanelY) *
                    TheUI.MinimapPanel.Graphic->Width]];
            MinimapGraphic[x + y * TheUI.MinimapW] = VideoMapRGB(p.r, p.g, p.b);
+#endif
        }
     }
     if (!TheUI.MinimapTransparent) {
        // make only the inner part which is going to be used black
        for (y = MinimapY; y < TheUI.MinimapH - MinimapY; ++y) {
            for (x = MinimapX; x < TheUI.MinimapW - MinimapX; ++x) {
+#ifdef USE_SDL_SURFACE
+               // FIXME: todo
+//             ((char*)MinimapGraphic->pixels)[x + y * TheUI.MinimapW] = 
ColorBlack;
+#else
                MinimapGraphic[x + y * TheUI.MinimapW] = ColorBlack;
+#endif
            }
        }
     }
@@ -305,6 +361,9 @@
            } else {
                visiontype = IsTileVisible(ThisPlayer, Minimap2MapX[mx], 
Minimap2MapY[my] / TheMap.Width);
            }
+#ifdef USE_SDL_SURFACE
+           // FIXME: todo
+#else
            if (MinimapWithTerrain && (visiontype > 1 || (visiontype == 1 && 
((mx & 1) == (my & 1))))) {
                Palette p;
                p = GlobalPalette[
@@ -313,6 +372,7 @@
            } else if (visiontype > 0) {
                MinimapGraphic[mx + my * TheUI.MinimapW] = ColorBlack;
            }
+#endif
        }
     }
 
@@ -325,6 +385,11 @@
 
     // Draw Destroyed Buildings On Map
     table = &DestroyedBuildings;
+
+#ifdef USE_SDL_SURFACE
+    // FIXME: todo
+    (int)type = (int)unit = w = h = h0 = 0;
+#else
     while (*table) {
        VMemType color;
 
@@ -418,6 +483,7 @@
        }
 
     }
+#endif
 }
 
 /**
@@ -429,6 +495,9 @@
 global void DrawMinimap(int vx __attribute__((unused)),
        int vy __attribute__((unused)))
 {
+#ifdef USE_SDL_SURFACE
+    // FIXME: todo
+#else
     int i;
     int j;
 
@@ -483,6 +552,7 @@
            break;
        }
     }
+#endif
 }
 
 /**
@@ -521,7 +591,11 @@
        (TheUI.SelectedViewport->MapWidth * MinimapScaleX) / MINIMAP_FAC;
     OldMinimapCursorH = h =
        (TheUI.SelectedViewport->MapHeight * MinimapScaleY) / MINIMAP_FAC;
+#ifdef USE_SDL_SURFACE
+    i = (w + 1 + h) * 2 * TheScreen->format->BytesPerPixel;
+#else
     i = (w + 1 + h) * 2 * VideoTypeSize;
+#endif
     if (OldMinimapCursorSize < i) {
        if (OldMinimapCursorImage) {
            OldMinimapCursorImage = realloc(OldMinimapCursorImage, i);
@@ -534,7 +608,11 @@
     SaveCursorRectangle(OldMinimapCursorImage, x, y, w, h);
 
     // Draw cursor as rectangle (Note: unclipped, as it is always visible)
+#ifdef USE_SDL_SURFACE
+    VideoDrawTransRectangle(TheUI.ViewportCursorColor, x, y, w, h, 50);
+#else
     VideoDraw50TransRectangle(TheUI.ViewportCursorColor, x, y, w, h);
+#endif
 }
 
 /**
Index: stratagus/src/map/tileset.c
diff -u stratagus/src/map/tileset.c:1.56 stratagus/src/map/tileset.c:1.57
--- stratagus/src/map/tileset.c:1.56    Fri Nov 14 23:38:51 2003
+++ stratagus/src/map/tileset.c Mon Nov 17 14:14:36 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: tileset.c,v 1.56 2003/11/15 04:38:51 mr-russ Exp $
+//     $Id: tileset.c,v 1.57 2003/11/17 19:14:36 nehalmistry Exp $
 
 //@{
 
@@ -129,7 +129,11 @@
     buf = alloca(strlen(Tilesets[i]->ImageFile) + 9 + 1);
     strcat(strcpy(buf, "graphics/"), Tilesets[i]->ImageFile);
     ShowLoadProgress("Tileset `%s'", Tilesets[i]->ImageFile);
+#ifdef USE_SDL_SURFACE
+    TheMap.TileGraphic = LoadGraphic(buf);
+#else
     TheMap.TileData = LoadGraphic(buf);
+#endif
 #ifdef USE_OPENGL
     MakeTexture(TheMap.TileData, TheMap.TileData->Width, 
TheMap.TileData->Height);
 #endif
@@ -140,10 +144,17 @@
     //
     //  Calculate number of tiles in graphic tile
     //
+#ifdef USE_SDL_SURFACE
+    tiles_per_row = TheMap.TileGraphic->Width / TileSizeX;
+
+    TheMap.TileCount = n =
+       tiles_per_row * (TheMap.TileGraphic->Height / TileSizeY);
+#else
     tiles_per_row = TheMap.TileData->Width / TileSizeX;
+
     TheMap.TileCount = n =
        tiles_per_row * (TheMap.TileData->Height / TileSizeY);
-
+#endif
     DebugLevel2Fn(" %d Tiles in file %s, %d per row\n" _C_ TheMap.
        TileCount _C_ TheMap.Tileset->ImageFile _C_ tiles_per_row);
 
@@ -157,7 +168,9 @@
     //  Precalculate the graphic starts of the tiles
     //
     data = malloc(n * TileSizeX * TileSizeY);
+#ifndef USE_SDL_SURFACE
     TheMap.Tiles = malloc(n * sizeof(*TheMap.Tiles));
+
     for (i = 0; i < n; ++i) {
        TheMap.Tiles[i] = data + i * TileSizeX * TileSizeY;
     }
@@ -180,13 +193,23 @@
            s += TheMap.TileData->Width;
        }
     }
+#endif
 
 #ifndef USE_OPENGL
+#ifdef USE_SDL_SURFACE
+/*
+    free(TheMap.TileGraphic->Frames);  // release old memory
+    TheMap.TileGraphic->Frames = data;
+    TheMap.TileGraphic->Width = TileSizeX;
+    TheMap.TileGraphic->Height = TileSizeY * n;
+*/
+#else
     free(TheMap.TileData->Frames);     // release old memory
     TheMap.TileData->Frames = data;
     TheMap.TileData->Width = TileSizeX;
     TheMap.TileData->Height = TileSizeY * n;
 #endif
+#endif
 
     //
     //  Build the TileTypeTable
@@ -726,7 +749,7 @@
     char** sp;
 
     CLprintf(file, "\n;;; -----------------------------------------\n");
-    CLprintf(file, ";;; MODULE: tileset $Id: tileset.c,v 1.56 2003/11/15 
04:38:51 mr-russ Exp $\n\n");
+    CLprintf(file, ";;; MODULE: tileset $Id: tileset.c,v 1.57 2003/11/17 
19:14:36 nehalmistry Exp $\n\n");
 
     //  Original number to internal tileset name
 
@@ -786,10 +809,15 @@
     //
     // Should this be done by the map?
     //
+#ifdef USE_SDL_SURFACE
+    VideoSaveFree(TheMap.TileGraphic);
+    TheMap.TileGraphic = NULL;
+#else
     VideoSaveFree(TheMap.TileData);
     TheMap.TileData = NULL;
     free(TheMap.Tiles);
     TheMap.Tiles = NULL;
+#endif
 
     //
     // Mapping the original tileset numbers in puds to our internal strings
Index: stratagus/src/movie/movie.c
diff -u stratagus/src/movie/movie.c:1.17 stratagus/src/movie/movie.c:1.18
--- stratagus/src/movie/movie.c:1.17    Fri Nov  7 12:37:30 2003
+++ stratagus/src/movie/movie.c Mon Nov 17 14:14:37 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: movie.c,v 1.17 2003/11/07 17:37:30 jsalmon3 Exp $
+//     $Id: movie.c,v 1.18 2003/11/17 19:14:37 nehalmistry Exp $
 
 //@{
 
@@ -57,7 +57,11 @@
 
 #ifdef USE_SDL                         /// Only supported with SDL for now
 
-extern SDL_Surface* Screen;            /// internal screen
+#ifdef USE_SDL_SURFACE
+extern SDL_Surface* TheScreen; /// internal screen
+#else
+extern SDL_Surface* Screen;    /// internal screen
+#endif
 
 /*----------------------------------------------------------------------------
 --     Defines
@@ -246,8 +250,13 @@
     if (flags & PlayMovieFullScreen) {
        DebugLevel0Fn("FIXME: full screen switch not supported\n");
     }
+#ifdef USE_SDL_SURFACE
+    overlay = SDL_CreateYUVOverlay(avi->Width, avi->Height,
+       SDL_YV12_OVERLAY, TheScreen);
+#else
     overlay = SDL_CreateYUVOverlay(avi->Width, avi->Height,
        SDL_YV12_OVERLAY, Screen);
+#endif
     if (!overlay) {
        fprintf(stderr, "Couldn't create overlay: %s\n", SDL_GetError());
        exit(1);
Index: stratagus/src/ui/ccl_ui.c
diff -u stratagus/src/ui/ccl_ui.c:1.152 stratagus/src/ui/ccl_ui.c:1.153
--- stratagus/src/ui/ccl_ui.c:1.152     Mon Nov 17 13:48:10 2003
+++ stratagus/src/ui/ccl_ui.c   Mon Nov 17 14:14:37 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: ccl_ui.c,v 1.152 2003/11/17 18:48:10 jsalmon3 Exp $
+//     $Id: ccl_ui.c,v 1.153 2003/11/17 19:14:37 nehalmistry Exp $
 
 //@{
 
@@ -297,7 +297,11 @@
        i = 100;
     }
     TheUI.Contrast = i;
+#ifdef USE_SDL_SURFACE
+    VideoCreatePalette(&GlobalPalette);        // rebuild palette
+#else
     VideoCreatePalette(GlobalPalette); // rebuild palette
+#endif
     MustRedraw = RedrawEverything;
 
     return old;
@@ -347,7 +351,11 @@
        i = 0;
     }
     TheUI.Brightness = i;
+#ifdef USE_SDL_SURFACE
+    VideoCreatePalette(&GlobalPalette);        // rebuild palette
+#else
     VideoCreatePalette(GlobalPalette); // rebuild palette
+#endif
     MustRedraw = RedrawEverything;
 
     return old;
@@ -397,7 +405,11 @@
        i = 0;
     }
     TheUI.Saturation = i;
+#ifdef USE_SDL_SURFACE
+    VideoCreatePalette(&GlobalPalette);        // rebuild palette
+#else
     VideoCreatePalette(GlobalPalette); // rebuild palette
+#endif
     MustRedraw = RedrawEverything;
 
     return old;
@@ -2389,9 +2401,15 @@
                        if (gh_eq_p(value, gh_symbol2scm("color"))) {
                            value = gh_car(slist);
                            slist = gh_cdr(slist);
+#ifdef USE_SDL_SURFACE
+                           ui->CompletedBarColorRGB.r = 
gh_scm2int(gh_car(value));
+                           ui->CompletedBarColorRGB.g = 
gh_scm2int(gh_car(gh_cdr(value)));
+                           ui->CompletedBarColorRGB.b = 
gh_scm2int(gh_car(gh_cdr(gh_cdr(value))));
+#else
                            ui->CompletedBarColorRGB.D24.a = 
gh_scm2int(gh_car(value));
                            ui->CompletedBarColorRGB.D24.b = 
gh_scm2int(gh_car(gh_cdr(value)));
                            ui->CompletedBarColorRGB.D24.c = 
gh_scm2int(gh_car(gh_cdr(gh_cdr(value))));
+#endif
                        } else if (gh_eq_p(value, gh_symbol2scm("pos"))) {
                            value = gh_car(slist);
                            slist = gh_cdr(slist);
Index: stratagus/src/ui/icons.c
diff -u stratagus/src/ui/icons.c:1.54 stratagus/src/ui/icons.c:1.55
--- stratagus/src/ui/icons.c:1.54       Wed Nov 12 15:29:31 2003
+++ stratagus/src/ui/icons.c    Mon Nov 17 14:14:39 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: icons.c,v 1.54 2003/11/12 20:29:31 jsalmon3 Exp $
+//     $Id: icons.c,v 1.55 2003/11/17 19:14:39 nehalmistry Exp $
 
 //@{
 
@@ -370,7 +370,11 @@
 global void DrawUnitIcon(const Player* player, Icon* icon, unsigned flags,
     int x, int y)
 {
+#ifdef USE_SDL_SURFACE
+    SDL_Color color;
+#else
     VMemType color;
+#endif
     int width;
     int height;
 
@@ -428,7 +432,7 @@
     int i;
 
     CLprintf(file, "\n;;; -----------------------------------------\n");
-    CLprintf(file, ";;; MODULE: icons $Id: icons.c,v 1.54 2003/11/12 20:29:31 
jsalmon3 Exp $\n\n");
+    CLprintf(file, ";;; MODULE: icons $Id: icons.c,v 1.55 2003/11/17 19:14:39 
nehalmistry Exp $\n\n");
 
     //
     //  Mapping the original icon numbers in puds to our internal strings
Index: stratagus/src/ui/mainscr.c
diff -u stratagus/src/ui/mainscr.c:1.143 stratagus/src/ui/mainscr.c:1.144
--- stratagus/src/ui/mainscr.c:1.143    Sun Nov 16 01:49:28 2003
+++ stratagus/src/ui/mainscr.c  Mon Nov 17 14:14:39 2003
@@ -27,7 +27,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: mainscr.c,v 1.143 2003/11/16 06:49:28 mr-russ Exp $
+//     $Id: mainscr.c,v 1.144 2003/11/17 19:14:39 nehalmistry Exp $
 
 //@{
 
@@ -80,7 +80,11 @@
 local void UiDrawLifeBar(const Unit* unit, int x, int y)
 {
     int f;
+#ifdef USE_SDL_SURFACE
+    SDL_Color color;
+#else
     VMemType color;
+#endif
 
     y += unit->Type->Icon.Icon->Height + 7;
     VideoFillRectangleClip(ColorBlack, x, y,
Index: stratagus/src/ui/menu_proc.c
diff -u stratagus/src/ui/menu_proc.c:1.110 stratagus/src/ui/menu_proc.c:1.111
--- stratagus/src/ui/menu_proc.c:1.110  Fri Nov  7 17:41:29 2003
+++ stratagus/src/ui/menu_proc.c        Mon Nov 17 14:14:40 2003
@@ -10,7 +10,7 @@
 //
 /address@hidden menu_proc.c    -       The menu processing code. */
 //
-//     (c) Copyright 1999-2003 by Andreas Arens and Jimmy Salmon
+//     (c) Copyright 1999-2003 by Andreas Arens, Jimmy Salmon, Nehal Mistry
 //
 //      This program is free software; you can redistribute it and/or modify
 //      it under the terms of the GNU General Public License as published by
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: menu_proc.c,v 1.110 2003/11/07 22:41:29 jsalmon3 Exp $
+//     $Id: menu_proc.c,v 1.111 2003/11/17 19:14:40 nehalmistry Exp $
 
 //@{
 
@@ -986,7 +986,12 @@
 
     if (menu->Panel && !strcmp(menu->Panel, ScPanel)) {
        // Background
+#ifdef USE_SDL_SURFACE
+       VideoFillTransRectangle(ColorBlack, MenuRedrawX + 1, 
+               MenuRedrawY + 1, MenuRedrawW - 2, MenuRedrawH - 2, 50);
+#else
        VideoFill50TransRectangle(ColorBlack, MenuRedrawX + 1, MenuRedrawY + 1, 
MenuRedrawW - 2, MenuRedrawH - 2);
+#endif
        VideoDrawHLineClip(ColorBlue, MenuRedrawX + 3, MenuRedrawY, MenuRedrawW 
- 6);
        VideoDrawHLineClip(ColorBlue, MenuRedrawX + 3, MenuRedrawY + 
MenuRedrawH - 1, MenuRedrawW - 6);
        VideoDrawVLineClip(ColorBlue, MenuRedrawX, MenuRedrawY + 3, MenuRedrawH 
- 6);
Index: stratagus/src/ui/menus.c
diff -u stratagus/src/ui/menus.c:1.587 stratagus/src/ui/menus.c:1.588
--- stratagus/src/ui/menus.c:1.587      Fri Nov 14 16:57:45 2003
+++ stratagus/src/ui/menus.c    Mon Nov 17 14:14:42 2003
@@ -10,7 +10,7 @@
 //
 /address@hidden menus.c        -       The menu function code. */
 //
-//     (c) Copyright 1999-2003 by Andreas Arens and Jimmy Salmon
+//     (c) Copyright 1999-2003 by Andreas Arens, Jimmy Salmon, Nehal Mistry
 //
 //      This program is free software; you can redistribute it and/or modify
 //      it under the terms of the GNU General Public License as published by
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: menus.c,v 1.587 2003/11/14 21:57:45 mr-russ Exp $
+//     $Id: menus.c,v 1.588 2003/11/17 19:14:42 nehalmistry Exp $
 
 //@{
 
@@ -5694,11 +5694,19 @@
 
        LoadTileset();
        ChangeTilesetPud(old, &TheMap);
+#ifdef USE_SDL_SURFACE
+       LoadRGB(&GlobalPalette,
+               s=strdcat3(StratagusLibPath,"/graphics/",
+                   TheMap.Tileset->PaletteFile));
+       free(s);
+       VideoCreatePalette(&GlobalPalette);
+#else
        LoadRGB(GlobalPalette,
                s=strdcat3(StratagusLibPath,"/graphics/",
                    TheMap.Tileset->PaletteFile));
        free(s);
        VideoCreatePalette(GlobalPalette);
+#endif
        PreprocessMap();
        LoadConstructions();
        LoadUnitTypes();
Index: stratagus/src/ui/ui.c
diff -u stratagus/src/ui/ui.c:1.88 stratagus/src/ui/ui.c:1.89
--- stratagus/src/ui/ui.c:1.88  Fri Nov 14 23:38:51 2003
+++ stratagus/src/ui/ui.c       Mon Nov 17 14:14:42 2003
@@ -27,7 +27,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: ui.c,v 1.88 2003/11/15 04:38:51 mr-russ Exp $
+//     $Id: ui.c,v 1.89 2003/11/17 19:14:42 nehalmistry Exp $
 
 //@{
 
@@ -154,9 +154,15 @@
        SetViewportMode(VIEWPORT_SINGLE);
     }
 
+#ifdef USE_SDL_SURFACE
+    TheUI.CompletedBarColor = VideoMapRGB(TheUI.CompletedBarColorRGB.r,
+       TheUI.CompletedBarColorRGB.g, TheUI.CompletedBarColorRGB.b);
+    TheUI.ViewportCursorColor = ColorWhite;
+#else
     TheUI.CompletedBarColor = VideoMapRGB(TheUI.CompletedBarColorRGB.D24.a,
        TheUI.CompletedBarColorRGB.D24.b, TheUI.CompletedBarColorRGB.D24.c);
     TheUI.ViewportCursorColor = ColorWhite;
+#endif
 }
 
 /**
@@ -476,8 +482,13 @@
     CLprintf(file, ")");
 
     CLprintf(file, "\n    'completed-bar (list");
+#ifdef USE_SDL_SURFACE
+    CLprintf(file, "\n      'color '(%d %d %d)", ui->CompletedBarColorRGB.r,
+       ui->CompletedBarColorRGB.g, ui->CompletedBarColorRGB.b);
+#else
     CLprintf(file, "\n      'color '(%d %d %d)", 
ui->CompletedBarColorRGB.D24.a,
        ui->CompletedBarColorRGB.D24.b, ui->CompletedBarColorRGB.D24.c);
+#endif
     CLprintf(file, "\n      'pos '(%d %d)", ui->CompletedBarX, 
ui->CompletedBarY);
     CLprintf(file, "\n      'size '(%d %d)", ui->CompletedBarW, 
ui->CompletedBarH);
     CLprintf(file, "\n      'text (list", ui->CompletedBarText);
@@ -644,7 +655,7 @@
     int i;
 
     CLprintf(file, "\n;;; -----------------------------------------\n");
-    CLprintf(file, ";;; MODULE: ui $Id: ui.c,v 1.88 2003/11/15 04:38:51 
mr-russ Exp $\n\n");
+    CLprintf(file, ";;; MODULE: ui $Id: ui.c,v 1.89 2003/11/17 19:14:42 
nehalmistry Exp $\n\n");
 
     // Contrast, Brightness, Saturation
     CLprintf(file, "(set-contrast! %d)\n", TheUI.Contrast);
Index: stratagus/src/unit/ccl_unittype.c
diff -u stratagus/src/unit/ccl_unittype.c:1.112 
stratagus/src/unit/ccl_unittype.c:1.113
--- stratagus/src/unit/ccl_unittype.c:1.112     Wed Nov 12 15:31:17 2003
+++ stratagus/src/unit/ccl_unittype.c   Mon Nov 17 14:14:43 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: ccl_unittype.c,v 1.112 2003/11/12 20:31:17 jsalmon3 Exp $
+//     $Id: ccl_unittype.c,v 1.113 2003/11/17 19:14:43 nehalmistry Exp $
 
 //@{
 
@@ -305,9 +305,15 @@
        } else if (gh_eq_p(value, gh_symbol2scm("neutral-minimap-color"))) {
            sublist = gh_car(list);
            list = gh_cdr(list);
+#ifdef USE_SDL_SURFACE
+           type->NeutralMinimapColorRGB.r = gh_scm2int(gh_car(sublist));
+           type->NeutralMinimapColorRGB.g = 
gh_scm2int(gh_car(gh_cdr(sublist)));
+           type->NeutralMinimapColorRGB.b = 
gh_scm2int(gh_car(gh_cdr(gh_cdr(sublist))));
+#else
            type->NeutralMinimapColorRGB.D24.a = gh_scm2int(gh_car(sublist));
            type->NeutralMinimapColorRGB.D24.b = 
gh_scm2int(gh_car(gh_cdr(sublist)));
            type->NeutralMinimapColorRGB.D24.c = 
gh_scm2int(gh_car(gh_cdr(gh_cdr(sublist))));
+#endif
        } else if (gh_eq_p(value, gh_symbol2scm("box-size"))) {
            sublist = gh_car(list);
            list = gh_cdr(list);
Index: stratagus/src/unit/unittype.c
diff -u stratagus/src/unit/unittype.c:1.126 stratagus/src/unit/unittype.c:1.127
--- stratagus/src/unit/unittype.c:1.126 Wed Nov 12 15:31:17 2003
+++ stratagus/src/unit/unittype.c       Mon Nov 17 14:14:44 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: unittype.c,v 1.126 2003/11/12 20:31:17 jsalmon3 Exp $
+//     $Id: unittype.c,v 1.127 2003/11/17 19:14:44 nehalmistry Exp $
 
 //@{
 
@@ -781,9 +781,15 @@
        CLprintf(file, "  'not-selectable\n");
     }
 
+#ifdef USE_SDL_SURFACE
+    CLprintf(file, "  'neutral-minimap-color '(%d %d %d)\n",
+       type->NeutralMinimapColorRGB.r,type->NeutralMinimapColorRGB.g,
+       type->NeutralMinimapColorRGB.b);
+#else
     CLprintf(file, "  'neutral-minimap-color '(%d %d %d)\n",
        type->NeutralMinimapColorRGB.D24.a,type->NeutralMinimapColorRGB.D24.b,
        type->NeutralMinimapColorRGB.D24.c);
+#endif
 
     CLprintf(file, "  'sight-range %d", type->_SightRange);
     if (all || type->ReactRangeComputer) {
@@ -1191,7 +1197,7 @@
     char** sp;
 
     CLprintf(file, "\n;;; -----------------------------------------\n");
-    CLprintf(file, ";;; MODULE: unittypes $Id: unittype.c,v 1.126 2003/11/12 
20:31:17 jsalmon3 Exp $\n\n");
+    CLprintf(file, ";;; MODULE: unittypes $Id: unittype.c,v 1.127 2003/11/17 
19:14:44 nehalmistry Exp $\n\n");
 
     // Original number to internal unit-type name.
 
Index: stratagus/src/video/cursor.c
diff -u stratagus/src/video/cursor.c:1.76 stratagus/src/video/cursor.c:1.77
--- stratagus/src/video/cursor.c:1.76   Sun Nov  9 14:37:59 2003
+++ stratagus/src/video/cursor.c        Mon Nov 17 14:14:44 2003
@@ -10,7 +10,7 @@
 //
 /address@hidden cursor.c       -       The cursors. */
 //
-//     (c) Copyright 1998,2000-2002 by Lutz Sammer
+//     (c) Copyright 1998,2000-2002 by Lutz Sammer and Nehal Mistry
 //
 //      This program is free software; you can redistribute it and/or modify
 //      it under the terms of the GNU General Public License as published by
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: cursor.c,v 1.76 2003/11/09 19:37:59 jsalmon3 Exp $
+//     $Id: cursor.c,v 1.77 2003/11/17 19:14:44 nehalmistry Exp $
 
 //@{
 
@@ -126,7 +126,11 @@
 
         /// Memory re-use, so can be defined although no save present!
 local int OldCursorSize;       /// size of saved cursor image
+#ifdef USE_SDL_SURFACE
+local SDL_Surface* OldCursorImage;             /// background saved behind 
cursor
+#else
 local void* OldCursorImage;            /// background saved behind cursor
+#endif
 
     /**
     ** Function pointer: Save 2D image behind sprite cursor
@@ -136,13 +140,19 @@
     ** @param w        Width in pixels for image starting at left-top.
     ** @param h        Height in pixels for image starting at left-top.
     **
-    ** @note the complete image should be in Screen (no clipping) and
+    ** @note the complete image should be in TheScreen (no clipping) and
     ** non-empty
     **     (x >= 0, y >= 0, w > 0, h > 0, (x + w - 1) <= VideoWidth, (y + h - 
1) <= VideoHeight)
     */
+#ifdef USE_SDL_SURFACE
+local void SaveCursorBackground(int x, int y, int w, int h);
+    /// Function pointer: Load background behind cursor
+local void LoadCursorBackground(int x, int y, int w, int h);
+#else
 local void (*SaveCursorBackground)(int x, int y, int w, int h);
     /// Function pointer: Load background behind cursor
 local void (*LoadCursorBackground)(int x, int y, int w, int h);
+#endif
 
 /*--- DRAW RECTANGLE CURSOR ------------------------------------------------*/
        // Saved area after draw rectangle, needed later to hide it again
@@ -152,7 +162,11 @@
 local int OldCursorRectangleY;         /// saved cursor position on screen Y
 local int OldCursorRectangleW;         /// saved cursor width in pixel
 local int OldCursorRectangleH;         /// saved cursor height in pixel
+#ifdef USE_SDL_SURFACE
+local SDL_Surface* OldCursorRectangle;         /// background saved behind 
rectangle
+#else
 local void* OldCursorRectangle;                /// background saved behind 
rectangle
+#endif
 
        // Area which is already hidden, but needed for invalidate
        // (HiddenCursorRectangleW != 0 denotes it's defined)
@@ -170,11 +184,15 @@
 **     @param w        Width in pixels for rectangle starting at left-top.
 **     @param h        Height in pixels for rectangle starting at left-top.
 **
-**     @note the complete rectangle should be in Screen (no clipping) and
+**     @note the complete rectangle should be in TheScreen (no clipping) and
 **     non-empty
 **     (x >= 0, y >= 0, w > 0, h > 0, (x + w - 1) <= VideoWidth, (y + h - 1) 
<= VideoHeight)
 */
+#ifdef USE_SDL_SURFACE
+global void SaveCursorRectangle(void* buffer, int x, int y, int w, int h);
+#else
 global void (*SaveCursorRectangle)(void* buffer, int x, int y, int w, int h);
+#endif
 
 /**
 **     Function pointer: Load rectangle behind cursor
@@ -187,7 +205,11 @@
 **
 **     @note rectangle previously saved with SaveCursorRectangle(x,y,w,h)
 */
+#ifdef USE_SDL_SURFACE
+global void LoadCursorRectangle(void* buffer, int x, int y, int w, int h);
+#else
 global void (*LoadCursorRectangle)(void* buffer, int x, int y, int w, int h);
+#endif
 
 /*----------------------------------------------------------------------------
 --     Functions
@@ -229,8 +251,13 @@
            buf = alloca(strlen(file) + 9 + 1);
            file = strcat(strcpy(buf,"graphics/"), file);
            ShowLoadProgress("Cursor %s", file);
+#ifdef USE_SDL_SURFACE
+           Cursors[i].Sprite = LoadSprite(file,
+               Cursors[i].Width, Cursors[i].Height);
+#else
            Cursors[i].Sprite = LoadSprite(file,
                Cursors[i].Width, Cursors[i].Height);
+#endif
        }
     }
 }
@@ -252,7 +279,11 @@
        if (strcmp(cursortype->Ident, ident)) {
            continue;
        }
+#ifdef USE_SDL_SURFACE
+       if (!cursortype->Race || cursortype->Sprite) {
+#else
        if (!cursortype->Race || cursortype->Sprite) {
+#endif
            return cursortype;
        }
     }
@@ -263,6 +294,32 @@
 /*----------------------------------------------------------------------------
 --     DRAW RECTANGLE CURSOR
 ----------------------------------------------------------------------------*/
+
+#ifdef USE_SDL_SURFACE
+global void LoadCursorRectangle(void* buffer, int x, int y, int w, int h)
+{
+    // FIXME: todo
+    int i;
+
+    SDL_LockSurface(TheScreen);
+    for (i = 0; i < h; ++i) {
+       memcpy(&((char*)TheScreen->pixels)[x + (h + i) * VideoWidth], buffer, 
w);
+    }
+    SDL_UnlockSurface(TheScreen);
+}
+
+global void SaveCursorRectangle(void* buffer, int x, int y, int w, int h)
+{
+    int i;
+
+    SDL_LockSurface(TheScreen);
+    for (i = 0; i < h; ++i) {
+       memcpy(buffer, &((char*)TheScreen->pixels)[x + (h + i) * VideoWidth], 
w);
+    }
+    SDL_UnlockSurface(TheScreen);
+    // FIXME: todo
+}
+#else
 /**
 **     Puts stored 'image' from SAVECURSORRECTANGLE back on the screen.
 **      Note w and h are both > 0
@@ -394,6 +451,7 @@
 {
     SAVECURSORRECTANGLE(buffer, VideoMemory32, VMemType32, x, y, w, h);
 }
+#endif
 
 /**
 **     Draw rectangle cursor when visible, defined by
@@ -452,6 +510,39 @@
 /*----------------------------------------------------------------------------
 --     DRAW SPRITE CURSOR
 ----------------------------------------------------------------------------*/
+#ifdef USE_SDL_SURFACE
+local void LoadCursorBackground(int x, int y, int w, int h)
+{
+    SDL_Rect drect;
+    SDL_Rect srect;
+
+    srect.x = 0;
+    srect.y = 0;
+    srect.w = w;
+    srect.h = h;
+
+    drect.x = x;
+    drect.y = y;
+
+    SDL_BlitSurface(OldCursorImage, NULL, TheScreen, &drect);
+}
+
+local void SaveCursorBackground(int x, int y, int w, int h)
+{
+    SDL_Rect srect;
+    SDL_Rect drect;
+
+    srect.x = 0;
+    srect.y = 0;
+    srect.w = w;
+    srect.h = h;
+
+    drect.x = x;
+    drect.y = y;
+
+    SDL_BlitSurface(TheScreen, &srect, OldCursorImage, NULL);
+}
+#else
 /**
 **     Restore cursor background for 8bpp frame buffer.
 **
@@ -627,6 +718,7 @@
        sp += VideoWidth;
     }
 }
+#endif
 
 /**
 **     Destroy image behind cursor.
@@ -664,10 +756,22 @@
     //
     spritex = (x -= type->HotX);
     spritey = (y -= type->HotY);
+#ifdef USE_SDL_SURFACE
+    w = VideoGraphicWidth(type->Sprite);
+    h = VideoGraphicHeight(type->Sprite);
+#else
     w = VideoGraphicWidth(type->Sprite);
     h = VideoGraphicHeight(type->Sprite);
+#endif
 
     //Reserve enough memory for background of sprite (also for future calls)
+#ifdef USE_SDL_SURFACE
+    size = w * h;
+    if (OldCursorSize < size) {
+       OldCursorImage = malloc(sizeof(SDL_Surface));
+       OldCursorSize = size;
+    }
+#else
     size = w * h * MemSize;
     if (OldCursorSize < size) {
        if (OldCursorImage) {
@@ -677,14 +781,18 @@
        }
        OldCursorSize = size;
     }
-
+#endif
     //Save (seen) area behind sprite
     CLIP_RECTANGLE(x, y, w, h);
     SaveCursorBackground(OldCursorX = x, OldCursorY = y,
        OldCursorW = w, OldCursorH = h);
 
     //Draw sprite (using its own clipping)  FIXME: prevent clipping twice
+#ifdef USE_SDL_SURFACE
+    VideoDrawClip(type->Sprite, frame, spritex, spritey);
+#else
     VideoDrawClip(type->Sprite, frame, spritex, spritey);
+#endif
     OldCursorInvalidate = 1;
 }
 
@@ -702,7 +810,11 @@
     int y1;
     int mx;
     int my;
+#ifdef USE_SDL_SURFACE
+    SDL_Color color;
+#else
     VMemType color;
+#endif
     int f;
     int w;
     int w0;
@@ -907,7 +1019,11 @@
        last = ticks + GameCursor->FrameRate;
        GameCursor->SpriteFrame++;
        if ((GameCursor->SpriteFrame & 127) >=
+#ifdef USE_SDL_SURFACE
                VideoGraphicFrames(GameCursor->Sprite)) {
+#else
+               VideoGraphicFrames(GameCursor->Sprite)) {
+#endif
            GameCursor->SpriteFrame = 0;
        }
        MustRedraw |= RedrawCursor;
@@ -1072,6 +1188,10 @@
        OldCursorRectangle = 0;
     }
 
+#ifdef USE_SDL_SURFACE
+    OldCursorImage = SDL_CreateRGBSurface(SDL_SWSURFACE, 40, 40, 8, 0, 0, 0, 
0);
+    OldCursorRectangle = SDL_CreateRGBSurface(SDL_SWSURFACE, 40, 40, 8, 0, 0, 
0, 0);
+#else
     switch (VideoBpp) {
        case 8:
            SaveCursorBackground = SaveCursorBackground8;
@@ -1107,6 +1227,7 @@
            abort();
     }
     OldCursorRectangle = malloc((2 * VideoWidth + 2 * (VideoHeight - 2)) * 
MemSize);
+#endif // ifdef USE_SDL_SURFACE
 #endif
 
     CursorX = VideoWidth / 2;
@@ -1121,7 +1242,7 @@
     int i;
 
     CLprintf(file, "\n;;; -----------------------------------------\n");
-    CLprintf(file, ";;; MODULE: cursors $Id: cursor.c,v 1.76 2003/11/09 
19:37:59 jsalmon3 Exp $\n\n");
+    CLprintf(file, ";;; MODULE: cursors $Id: cursor.c,v 1.77 2003/11/17 
19:14:44 nehalmistry Exp $\n\n");
 
     for (i = 0; Cursors[i].OType; ++i) {
        CLprintf(file, "(define-cursor '%s '%s\n",
Index: stratagus/src/video/font.c
diff -u stratagus/src/video/font.c:1.59 stratagus/src/video/font.c:1.60
--- stratagus/src/video/font.c:1.59     Wed Nov 12 15:33:42 2003
+++ stratagus/src/video/font.c  Mon Nov 17 14:14:45 2003
@@ -10,7 +10,7 @@
 //
 /address@hidden font.c         -       The color fonts. */
 //
-//     (c) Copyright 1998-2003 by Lutz Sammer and Jimmy Salmon
+//     (c) Copyright 1998-2003 by Lutz Sammer, Jimmy Salmon, Nehal Mistry
 //
 //      This program is free software; you can redistribute it and/or modify
 //      it under the terms of the GNU General Public License as published by
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: font.c,v 1.59 2003/11/12 20:33:42 jsalmon3 Exp $
+//     $Id: font.c,v 1.60 2003/11/17 19:14:45 nehalmistry Exp $
 
 //@{
 
@@ -51,6 +51,17 @@
 
 #define NumFontColors 7
 
+#ifdef USE_SDL_SURFACE
+    /// Font color mapping
+typedef struct _font_color_mapping_ {
+    char* ColorName;                   /// Font color name
+
+    SDL_Color Color[NumFontColors];    /// Array of hardware dependent pixels
+    struct _font_color_mapping_* Next; /// Next pointer
+} FontColorMapping;
+
+local FontColorMapping* FontColor;
+#else
     /// Font color mapping
 typedef struct _font_color_mapping_ {
     char* Color;                       /// Font color
@@ -69,6 +80,8 @@
 #define FontPixels24   (&FontPixels->D24)      /// font pixels 24bpp
 #define FontPixels32   (&FontPixels->D32)      /// font pixels 32bpp
 
+#endif
+
     /// Font color mappings
 local FontColorMapping* FontColorMappings;
 
@@ -79,6 +92,18 @@
 */
 local ColorFont Fonts[MaxFonts];
 
+#ifdef USE_SDL_SURFACE
+    /// Last text color
+local FontColorMapping* LastTextColor;
+    /// Default text color
+local FontColorMapping* DefaultTextColor;
+    /// Reverse text color
+local FontColorMapping* ReverseTextColor;
+    /// Default normal color index
+local char* DefaultNormalColorIndex;
+    /// Default reverse color index
+local char* DefaultReverseColorIndex;
+#else
     /// Last text color
 local const VMemType* LastTextColor;
     /// Default text color
@@ -89,9 +114,14 @@
 local char* DefaultNormalColorIndex;
     /// Default reverse color index
 local char* DefaultReverseColorIndex;
+#endif
 
     /// Draw character with current video depth.
+#ifdef USE_SDL_SURFACE
+local void VideoDrawChar(const Graphic*, int, int, int, int, int, int);
+#else
 local void (*VideoDrawChar)(const Graphic*, int, int, int, int, int, int);
+#endif
 
 #ifdef USE_OPENGL
     /// Font bitmaps
@@ -124,6 +154,31 @@
 
 // FIXME: should use RLE encoded fonts, not color key fonts.
 
+#ifdef USE_SDL_SURFACE
+local void VideoDrawChar(const Graphic* sprite,
+    int gx, int gy, int w, int h, int x, int y)
+{
+    SDL_Rect srect;
+    SDL_Rect drect;
+
+    srect.x = gx;
+    srect.y = gy;
+    srect.w = w;
+    srect.h = h;
+
+    drect.x = x;
+    drect.y = y;
+
+    SDL_SetColors(sprite->Surface, FontColor->Color, 0, NumFontColors);
+
+    SDL_BlitSurface(sprite->Surface, &srect, TheScreen, &drect);
+
+    SDL_UpdateRect(TheScreen, x, y, w, h);
+    InvalidateArea(x, y, w, h);
+}
+
+#else
+
 /**
 **     Draw character with current color into 8bit video memory.
 **
@@ -343,6 +398,7 @@
     }
 #undef UNROLL
 }
+#endif
 
 #ifdef USE_OPENGL
 /**
@@ -378,6 +434,23 @@
 }
 #endif
 
+#ifdef USE_SDL_SURFACE
+local FontColorMapping* GetFontColorMapping(char* color)
+{
+    FontColorMapping *fcm;
+
+    fcm = FontColorMappings;
+    while (fcm) {
+       if (!strcmp(fcm->ColorName, color)) {
+           return fcm;
+       }
+       fcm = fcm->Next;
+    }
+    fprintf(stderr, "Font mapping not found: '%s'\n", color);
+    ExitFatal(1);
+    return NULL;
+}
+#else
 /**
 **     FIXME: docu
 */
@@ -396,6 +469,7 @@
     ExitFatal(1);
     return NULL;
 }
+#endif
 
 /**
 **     Set the default text colors.
@@ -407,7 +481,11 @@
 {
     DefaultNormalColorIndex = normal;
     DefaultReverseColorIndex = reverse;
+#ifdef USE_SDL_SURFACE
+    LastTextColor = DefaultTextColor = FontColor = GetFontColorMapping(normal);
+#else
     LastTextColor = DefaultTextColor = FontPixels = 
GetFontColorMapping(normal);
+#endif
     ReverseTextColor = GetFontColorMapping(reverse);
 }
 
@@ -509,7 +587,11 @@
     int height;
     int widths;
     const ColorFont* fp;
+#ifdef USE_SDL_SURFACE
+    FontColorMapping* rev;
+#else
     const VMemType* rev;
+#endif
     char* color;
     const unsigned char* p;
     void (*DrawChar)(const Graphic*, int, int, int, int, int, int);
@@ -535,18 +617,34 @@
                case '~':
                    break;
                case '!':
+#ifdef USE_SDL_SURFACE
+                   rev = FontColor;
+                   FontColor = ReverseTextColor;
+#else
                    rev = FontPixels;
                    FontPixels = ReverseTextColor;
+#endif
+                   
                    ++text;
                    break;
                case '<':
+#ifdef USE_SDL_SURFACE
+                   LastTextColor = FontColor;
+                   FontColor = ReverseTextColor;
+#else
                    LastTextColor = FontPixels;
                    FontPixels = ReverseTextColor;
+#endif
                    continue;
                case '>':
                    rev = LastTextColor;        // swap last and current color
+#ifdef USE_SDL_SURFACE
+                   LastTextColor = FontColor;
+                   FontColor = rev;
+#else
                    LastTextColor = FontPixels;
                    FontPixels = rev;
+#endif
                    continue;
 
                default:
@@ -562,12 +660,21 @@
                    memcpy(color, text, p - text);
                    color[p - text] = '\0';
                    text = p;
+#ifdef USE_SDL_SURFACE
+                   printf("NBNNNNNNNNNNNNNNNNNNNNNN\n");
+                   LastTextColor = FontColor;
+                   FontColor = GetFontColorMapping(color);
+#else
                    LastTextColor = FontPixels;
                    FontPixels = GetFontColorMapping(color);
+#endif
                    free(color);
                    continue;
            }
        }
+#ifdef USE_SDL_SURFACE
+
+#endif
 
        DebugCheck(*text < 32);
 
@@ -580,7 +687,11 @@
        }
        widths += w + 1;
        if (rev) {
+#ifdef USE_SDL_SURFACE
+           FontColor = rev;
+#else
            FontPixels = rev;
+#endif
            rev = NULL;
        }
     }
@@ -641,9 +752,15 @@
 {
     int w;
 
+#ifdef USE_SDL_SURFACE
+    FontColor = ReverseTextColor;
+    w = VideoDrawText(x, y, font, text);
+    FontColor = DefaultTextColor;
+#else
     FontPixels = ReverseTextColor;
     w = VideoDrawText(x, y, font, text);
     FontPixels = DefaultTextColor;
+#endif
 
     return w;
 }
@@ -737,6 +854,45 @@
     return VideoDrawReverseText(x, y, font, buf);
 }
 
+#ifdef USE_SDL_SURFACE
+local void FontMeasureWidths(ColorFont* fp)
+{
+    // FIXME: todo.. can this be optimized?
+    int y;
+    const unsigned char* sp;
+    const unsigned char* lp;
+    const unsigned char* gp;
+
+    for (y = 1; y < 207; ++y) {
+       fp->CharWidth[y] = 0;
+    }
+
+    fp->CharWidth[0] = fp->Width / 2;  // a reasonable value for SPACE
+
+    for (y = 1; y < 207; ++y) {
+       sp = (const unsigned char *)fp->Graphic->Surface->pixels +
+           y * fp->Height * fp->Graphic->Width - 1;
+       gp = sp + fp->Graphic->Width * fp->Height;
+       // Bail out if no letters left
+       if (gp >= ((const unsigned char *)fp->Graphic->Surface->pixels +
+               fp->Graphic->Width * fp->Graphic->Height)) {
+           break;
+       }
+       while (sp < gp) {
+           lp = sp + fp->Graphic->Width - 1;
+           for (; sp < lp; --lp) {
+               if (*lp != 255) {
+                   if (lp - sp > fp->CharWidth[y]) {   // max width
+                       fp->CharWidth[y] = lp - sp;
+                   }
+               }
+           }
+           sp += fp->Graphic->Width;
+       }
+
+    }    
+}
+#else
 /**
 **     Calculate widths table for a font.
 **
@@ -777,6 +933,7 @@
     }
     fp->CharWidth[0] = fp->Width / 2;  // a reasonable value for SPACE
 }
+#endif
 
 /**
 **     Make font bitmap.
@@ -837,7 +994,11 @@
 {
     unsigned i;
     FontColorMapping* fcm;
+#ifdef USE_SDL_SURFACE
+    SDL_Color* color;
+#else
     void* pixels;
+#endif
 
     //
     // First select the font drawing procedure.
@@ -845,6 +1006,8 @@
 #ifdef USE_OPENGL
     VideoDrawChar = VideoDrawCharOpenGL;
 #else
+#ifdef USE_SDL_SURFACE
+#else
     switch (VideoBpp) {
        case 8:
            VideoDrawChar = VideoDrawChar8;
@@ -868,6 +1031,7 @@
            abort();
     }
 #endif
+#endif
 
     for (i = 0; i<sizeof(Fonts) / sizeof(*Fonts); ++i) {
        if (Fonts[i].File) {
@@ -881,6 +1045,22 @@
     }
 
     fcm = FontColorMappings;
+#ifdef USE_SDL_SURFACE
+
+    while (fcm) {
+       color = fcm->Color;
+       for (i = 0; i < NumFontColors; ++i) {
+           SDL_Color c;
+           // FIXME: todo
+//         c = VideoMapRGB(fcm->RGB[i].R, fcm->RGB[i].G, fcm->RGB[i].B);
+           c = VideoMapRGB(fcm->Color[i].r, fcm->Color[i].g, fcm->Color[i].b);
+
+           color[i] = VideoMapRGB(c.r, c.g, c.b);
+       }
+       fcm = fcm->Next;
+    }
+
+#else
     while (fcm) {
        pixels = fcm->Pixels;
        for (i = 0; i < NumFontColors; ++i) {
@@ -906,6 +1086,7 @@
        }
        fcm = fcm->Next;
     }
+#endif
 }
 
 /*----------------------------------------------------------------------------
@@ -1048,18 +1229,31 @@
     } else {
        fcmp = &FontColorMappings;
        while (*fcmp) {
+#ifdef USE_SDL_SURFACE
+           if (!strcmp((*fcmp)->ColorName, color)) {
+               fprintf(stderr, "Warning: Redefining color '%s'\n", color);
+               free((*fcmp)->ColorName);
+               fcm = *fcmp;
+               break;
+           }
+#else
            if (!strcmp((*fcmp)->Color, color)) {
                fprintf(stderr, "Warning: Redefining color '%s'\n", color);
                free((*fcmp)->Color);
                fcm = *fcmp;
                break;
            }
+#endif
            fcmp = &(*fcmp)->Next;
        }
        *fcmp = calloc(sizeof(*FontColorMappings), 1);
        fcm = *fcmp;
     }
+#ifdef USE_SDL_SURFACE
+    fcm->ColorName = color;
+#else
     fcm->Color = color;
+#endif
     fcm->Next = NULL;
 
     value = gh_car(list);
@@ -1069,9 +1263,15 @@
        fprintf(stderr, "Wrong vector length\n");
     }
     for (i = 0; i < NumFontColors; ++i) {
+#ifdef USE_SDL_SURFACE
+       fcm->Color[i].r = gh_scm2int(gh_vector_ref(value, gh_int2scm(i * 3 + 
0)));
+       fcm->Color[i].g = gh_scm2int(gh_vector_ref(value, gh_int2scm(i * 3 + 
1)));
+       fcm->Color[i].b = gh_scm2int(gh_vector_ref(value, gh_int2scm(i * 3 + 
2)));
+#else
        fcm->RGB[i].R = gh_scm2int(gh_vector_ref(value, gh_int2scm(i * 3 + 0)));
        fcm->RGB[i].G = gh_scm2int(gh_vector_ref(value, gh_int2scm(i * 3 + 1)));
        fcm->RGB[i].B = gh_scm2int(gh_vector_ref(value, gh_int2scm(i * 3 + 2)));
+#endif
     }
 
     return SCM_UNSPECIFIED;
Index: stratagus/src/video/graphic.c
diff -u stratagus/src/video/graphic.c:1.46 stratagus/src/video/graphic.c:1.47
--- stratagus/src/video/graphic.c:1.46  Mon Sep 29 17:07:37 2003
+++ stratagus/src/video/graphic.c       Mon Nov 17 14:14:46 2003
@@ -10,7 +10,7 @@
 //
 /address@hidden graphic.c      -       The general graphic functions. */
 //
-//     (c) Copyright 1999-2002 by Lutz Sammer
+//     (c) Copyright 1999-2002 by Lutz Sammer and Nehal Mistry
 //
 //      This program is free software; you can redistribute it and/or modify
 //      it under the terms of the GNU General Public License as published by
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: graphic.c,v 1.46 2003/09/29 21:07:37 jsalmon3 Exp $
+//     $Id: graphic.c,v 1.47 2003/11/17 19:14:46 nehalmistry Exp $
 
 //@{
 
@@ -42,6 +42,10 @@
 #include "iolib.h"
 #include "intern_video.h"
 
+#ifdef USE_SDL_SURFACE
+#include <string.h>
+#endif
+
 /*----------------------------------------------------------------------------
 --     Declarations
 ----------------------------------------------------------------------------*/
@@ -52,13 +56,60 @@
 --     Variables
 ----------------------------------------------------------------------------*/
 
+#ifdef USE_SDL_SURFACE
+local GraphicType GraphicImage;
+#else
 local GraphicType GraphicImage8Type;   /// image type 8bit palette
 local GraphicType GraphicImage16Type;  /// image type 16bit palette
+#endif
 
 /*----------------------------------------------------------------------------
 --     Local functions
 ----------------------------------------------------------------------------*/
 
+#ifdef USE_SDL_SURFACE
+global void VideoDrawSub(const Graphic* graphic, int gx, int gy,
+    int w, int h, int x, int y)
+{
+    SDL_Rect srect;
+    SDL_Rect drect;
+
+    srect.x = gx;
+    srect.y = gy;
+    srect.w = w;
+    srect.h = h;
+
+    drect.x = x;
+    drect.y = y;
+
+    CLIP_RECTANGLE(gx, gy, w, h);
+
+    SDL_BlitSurface(graphic->Surface, &srect, TheScreen, &drect);
+//    InvalidateArea(x, y, w, h);
+}
+
+global void VideoDrawSubClip(const Graphic* graphic, int gx, int gy,
+    int w, int h, int x, int y)
+{
+    SDL_Rect srect;
+    SDL_Rect drect;
+
+    srect.x = gx;
+    srect.y = gy;
+    srect.w = w;
+    srect.h = h;
+
+    drect.x = x;
+    drect.y = y;
+
+    CLIP_RECTANGLE(gx, gy, w, h);
+
+    SDL_BlitSurface(graphic->Surface, &srect, TheScreen, &drect);
+//    InvalidateArea(x, y, w, h);
+//    Invalidate();
+}
+
+#else
 /**
 **     Video draw part of 8bit graphic into 8 bit framebuffer.
 **
@@ -232,6 +283,7 @@
        dp += da;
     }
 }
+#endif
 
 /**
 **     Video draw part of graphic.
@@ -281,6 +333,16 @@
 }
 #endif
 
+#ifdef USE_SDL_SURFACE
+/*
+local void VideoDrawSub(const Graphic* graphic, int gx, int gy,
+    int w, int h, int x, int y)
+{
+    CLIP_RECTANGLE(x, y, w, h);
+    VideoDrawSub(graphic, gx, gy, w, h, x, y);
+}
+*/
+#else
 /**
 **     Video draw part of 8bit graphic clipped into 8 bit framebuffer.
 **
@@ -352,6 +414,7 @@
     CLIP_RECTANGLE(x, y, w, h);
     VideoDrawSub8to32(graphic, gx, gy, w, h, x, y);
 }
+#endif
 
 /**
 **     Video draw part of graphic clipped.
@@ -379,9 +442,13 @@
 local void FreeGraphic8(Graphic* graphic)
 {
 #ifdef DEBUG
+#ifdef USE_SDL_SURFACE
+    // FIXME: todo
+#else
     AllocatedGraphicMemory -= graphic->Size;
     AllocatedGraphicMemory -= sizeof(Graphic);
 #endif
+#endif
 
 #ifdef USE_OPENGL
     if (graphic->NumTextureNames) {
@@ -389,12 +456,17 @@
        free(graphic->TextureNames);
     }
 #endif
+
+#ifdef USE_SDL_SURFACE
+    SDL_FreeSurface(graphic->Surface);
+#else
     VideoFreeSharedPalette(graphic->Pixels);
     if (graphic->Palette) {
        free(graphic->Palette);
     }
     free(graphic->Frames);
     free(graphic);
+#endif
 }
 
 // FIXME: need frame version
@@ -452,6 +524,8 @@
        fprintf(stderr, "Out of memory\n");
        ExitFatal(-1);
     }
+#ifdef USE_SDL_SURFACE
+#else
     if (depth == 8) {
        graphic->Type = &GraphicImage8Type;
     } else if (depth == 16) {
@@ -460,15 +534,29 @@
        fprintf(stderr, "Unsported image depth\n");
        ExitFatal(-1);
     }
+#endif
     graphic->Width = width;
     graphic->Height = height;
 
+#ifdef USE_SDL_SURFACE
+    // FIXME: endian
+
+//    graphic->Surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 
depth, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
+    graphic->Surface = SDL_CreateRGBSurfaceFrom(data, width, height, depth, 
width * depth / 8, 
+//     0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
+       0, 0, 0, 0);
+//     depth * width);//, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
+
+    graphic->NumFrames = 0;
+#else
     graphic->Pixels = NULL;
     graphic->Palette = NULL;
 
     graphic->NumFrames = 0;
     graphic->Frames = data;
     graphic->Size = size;
+#endif
+
 #ifdef USE_OPENGL
     graphic->NumTextureNames = 0;
 #endif
@@ -677,7 +765,15 @@
     unsigned char* data;
     int x;
 
+#ifdef USE_SDL_SURFACE
+    return;
+
+    int bps;
+
+    bps = g->Surface->format->BytesPerPixel;
+#else
     DebugCheck(g->Type != &GraphicImage8Type);
+#endif
 
     if (g->Width == w && g->Height == h) {
        return;
@@ -691,12 +787,25 @@
 
     for (i = 0; i < h; ++i) {
        for (j = 0; j < w; ++j) {
+#ifdef USE_SDL_SURFACE
+           memcpy(&data[x * g->Surface->format->BytesPerPixel],
+               &((char*)g->Surface->pixels)[(i * g->Height / h) * g->Width * 
bps
+                   + bps * j * g->Width / w], bps);
+#else
            data[x] = ((unsigned char*)g->Frames)[
                (i * g->Height / h) * g->Width + j * g->Width / w];
+#endif
            ++x;
        }
     }
 
+#ifdef USE_SDL_SURFACE
+    // FIXME: todo
+    SDL_FreeSurface(g->Surface);
+    g->Surface = SDL_CreateRGBSurfaceFrom(data, w, h, bps, w * bps, 0, 0, 0, 
0);
+    g->Width = w;
+    g->Height = h;
+#else
     free(g->Frames);
 #ifdef DEBUG
     AllocatedGraphicMemory -= g->Width * g->Height;
@@ -704,6 +813,7 @@
     g->Frames = data;
     g->Width = w;
     g->Height = h;
+#endif
 }
 
 /**
@@ -727,9 +837,16 @@
        ExitFatal(-1);
     }
 
+#ifdef USE_SDL_SURFACE
+//    Pixels = graphic->Surface->format->palette;
+//    graphic->Surface->format->palette = 
+//     VideoCreateSharedPalette(graphic->Surface->format->palette);
+    graphic->NumFrames = 1;
+#else
     graphic->Pixels = VideoCreateSharedPalette(graphic->Palette);
     //free(graphic->Palette);
     //graphic->Palette = NULL;         // JOHNS: why should we free this?
+#endif
 
     return graphic;
 }
@@ -739,10 +856,18 @@
 */
 global void InitGraphic(void)
 {
+#ifdef USE_SDL_SURFACE
+//    GlobalPalletPixels->ncolors = 256;
+//    GlobalPalette.colors = (SDL_Color*)calloc(256, sizeof(SDL_Color));
+//    GlobalPalette.ncolors = 256;
+//    GlobalPalette.colors = (SDL_Color*)calloc(256, sizeof(SDL_Color));
+#else
+
 #ifdef USE_OPENGL
     GraphicImage8Type.DrawSub = VideoDrawSubOpenGL;
     GraphicImage8Type.DrawSubClip = VideoDrawSubOpenGLClip;
 #else
+
     switch( VideoBpp ) {
        case 8:
            GraphicImage8Type.DrawSub = VideoDrawSub8to8;
@@ -771,6 +896,7 @@
     }
 #endif
     GraphicImage8Type.Free = FreeGraphic8;
+#endif
 }
 
 //@}
Index: stratagus/src/video/linedraw.c
diff -u stratagus/src/video/linedraw.c:1.39 stratagus/src/video/linedraw.c:1.40
--- stratagus/src/video/linedraw.c:1.39 Tue Oct  7 20:06:43 2003
+++ stratagus/src/video/linedraw.c      Mon Nov 17 14:14:46 2003
@@ -10,7 +10,8 @@
 //
 /address@hidden linedraw.c     -       The general linedraw functions. */
 //
-//     (c) Copyright 2000-2003 by Lutz Sammer, Stephan Rasenberg, Jimmy Salmon
+//     (c) Copyright 2000-2003 by Lutz Sammer, Stephan Rasenberg, 
+//     Jimmy Salmon, Nehal Mistry
 //
 //      This program is free software; you can redistribute it and/or modify
 //      it under the terms of the GNU General Public License as published by
@@ -26,7 +27,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: linedraw.c,v 1.39 2003/10/08 00:06:43 jsalmon3 Exp $
+//     $Id: linedraw.c,v 1.40 2003/11/17 19:14:46 nehalmistry Exp $
 
 //@{
 
@@ -62,6 +63,33 @@
 --     Variables
 ----------------------------------------------------------------------------*/
 
+#ifdef USE_SDL_SURFACE
+// FIXME: comments
+global void VideoDrawPixel(SDL_Color color, int x, int y);
+global void VideoDrawTransPixel(SDL_Color color, int x, int y, unsigned char 
alpha);
+global void VideoDrawPixelClip(SDL_Color color, int x, int y);
+global void VideoDrawVLine(SDL_Color color, int x, int y, int width);
+global void VideoDrawVLineClip(SDL_Color color, int x, int y, int width);
+global void VideoDrawTransVLine(SDL_Color color, int x, int y,
+    int height, unsigned char alpha);
+global void VideoDrawHLine(SDL_Color color, int x, int y, int width);
+global void VideoDrawHLineClip(SDL_Color color, int x, int y, int width);
+global void VideoDrawTransHLine(SDL_Color color, int x, int y,
+    int width, unsigned char alpha);
+global void VideoDrawLine(SDL_Color color, int sx, int sy, int dx, int dy);
+global void VideoDrawTransLine(SDL_Color color, int sx, int sy,
+    int dx, int dy, unsigned char alpha);
+global void VideoDrawRectangle(SDL_Color color, int x, int y,
+    int w, int h);
+global void VideoDrawRectangleClip(SDL_Color color, int x, int y,
+    int w, int h);
+global void VideoDrawTransRectangle(SDL_Color color, int x, int y,
+    int w, int h, unsigned char alpha);
+global void VideoFillRectangle(SDL_Color color, int x, int y,
+    int w, int h);
+global void VideoFillTransRectangle(SDL_Color color, int x, int y,
+    int w, int h, unsigned char alpha);
+#else
 /**
 **     Draw pixel unclipped.
 **
@@ -410,12 +438,206 @@
 */
 global void (*VideoFillTransRectangle)(VMemType color, int x, int y,
     int w, int h, unsigned char alpha);
-
+#endif
 
 // ===========================================================================
 //     Pixel
 // ===========================================================================
 
+#ifdef USE_SDL_SURFACE
+    // FIXME: BIG todo
+global void InitLineDraw()
+{
+}
+
+global void VideoDrawPixel(SDL_Color color, int x, int y)
+{
+    DebugCheck(1);
+}
+global void VideoDrawTransPixel(SDL_Color color, int x, int y, unsigned char 
alpha)
+{
+    DebugCheck(1);
+}
+global void VideoDrawPixelClip(SDL_Color color, int x, int y)
+{
+    DebugCheck(1);
+}
+global void VideoDrawVLine(SDL_Color color, int x, int y, int width)
+{
+    DebugCheck(1);
+}
+global void VideoDrawTransVLine(SDL_Color color, int x, int y,
+    int height, unsigned char alpha)
+{
+    DebugCheck(1);
+}
+global void VideoDrawVLineClip(SDL_Color color, int x, int y, int width)
+{
+    DebugCheck(1);
+}
+
+global void VideoDrawHLine(SDL_Color color, int x, int y, int width)
+{
+    DebugCheck(1);
+}
+global void VideoDrawHLineClip(SDL_Color color, int x, int y, int width)
+{
+    DebugCheck(1);
+}
+
+global void VideoDrawTransHLine(SDL_Color color, int x, int y,
+    int width, unsigned char alpha)
+{
+    DebugCheck(1);
+}
+global void VideoDrawLine(SDL_Color color, int sx, int sy, int dx, int dy)
+{
+    DebugCheck(1);
+}
+
+global void VideoDrawLineClip(SDL_Color color, int sx, int sy, int dx, int dy)
+{
+    DebugCheck(1);
+}
+
+global void VideoDrawTransLine(SDL_Color color, int sx, int sy,
+    int dx, int dy, unsigned char alpha)
+{
+    DebugCheck(1);
+}
+global void VideoDrawRectangle(SDL_Color color, int x, int y,
+    int w, int h)
+{
+    DebugCheck(1);
+}
+global void VideoDrawRectangleClip(SDL_Color color, int x, int y,
+    int w, int h)
+{
+/*
+    int i;
+//    int j;
+//    int bpp;
+    Uint32 c;
+    SDL_Rect drect;
+
+    SDL_Surface* rec;
+
+    rec = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, RMASK, GMASK, BMASK, 
AMASK);
+    c = SDL_MapRGB(TheScreen->format, color.r, color.g, color.b);
+
+    SDL_LockSurface(rec);
+    for (i = 0; i < w; ++i) {
+//     ((Uint32*)(rec->pixels))[(x + i)] = c;
+//     ((Uint32*)(rec->pixels))[(x + i) + (y) * rec->w] = c;
+    }
+    SDL_UnlockSurface(rec);
+
+    drect.x = x;
+    drect.y = y;
+
+    SDL_BlitSurface(rec, NULL, TheScreen, &drect);
+//    SDL_FreeSurface(rec);
+*/
+/*
+    c = SDL_MapRGB(TheScreen->format, color.r, color.g, color.b);
+    bpp = TheScreen->format->BytesPerPixel;
+*/
+/*
+    for (i = 0; i < h; ++i) {
+       // FIXME: why w*2?
+       for (j = 0; j < w*2; ++j) {
+           ((char*)(TheScreen->pixels))[(x + j) + (y + i) * TheScreen->pitch] 
= 
+               c;
+       }
+    }
+*/
+//    Invalidate();
+}
+
+global void VideoDrawTransRectangle(SDL_Color color, int x, int y,
+    int w, int h, unsigned char alpha)
+{
+    DebugCheck(1);
+}
+
+global void VideoFillRectangle(SDL_Color color, int x, int y,
+    int w, int h)
+{
+//    int i;
+//    int j;
+    SDL_Rect drect;
+    Uint32 c = SDL_MapRGB(TheScreen->format, color.r, color.g, color.b);
+
+    drect.x = x;
+    drect.y = y;
+    drect.w = w;
+    drect.h = h;
+
+    SDL_FillRect(TheScreen, &drect, c);
+/*
+    VideoLockScreen();
+
+    for (i = 0; i < h; ++i) {
+       // FIXME: why w*2?
+       for (j = 0; j < w*2; ++j) {
+           ((char*)(TheScreen->pixels))[(x + j) + (y + i) * TheScreen->pitch] 
= 
+               c;
+//c = 0;
+       }
+    }
+
+    VideoUnlockScreen();
+    Invalidate();
+*/
+}
+
+global void VideoFillTransRectangle(SDL_Color color, int x, int y,
+    int w, int h, unsigned char alpha)
+{
+    DebugCheck(1);
+}
+
+global void VideoFillRectangleClip(SDL_Color color, int x, int y,
+    int w, int h)
+{
+    DebugCheck(1);
+}
+
+global void VideoFillTransRectangleClip(SDL_Color color, int x, int y,
+    int w, int h, unsigned char alpha)
+{
+    DebugCheck(1);
+}
+
+global void VideoDrawCircleClip(SDL_Color color, int x, int y,
+    int w)
+{
+    DebugCheck(1);
+}
+
+global void VideoDrawTransCircleClip(SDL_Color color, int x, int y,
+    int w, unsigned char alpha)
+{
+    DebugCheck(1);
+}
+
+global void VideoFillCircleClip(SDL_Color color, int x, int y,
+    int w)
+{
+    DebugCheck(1);
+}
+
+global void VideoFillTransCircleClip(SDL_Color color, int x, int y,
+    int w, unsigned char alpha)
+{
+    DebugCheck(1);
+}
+
+global void DebugTestDisplayLines(void)
+{
+    DebugCheck(1);
+}
+#else
 /**
 **     Draw pixel unclipped into 8bit framebuffer.
 **
@@ -881,7 +1103,11 @@
     glEnable(GL_TEXTURE_2D);
 }
 #endif
+#endif // ifdef USE_SDL_SURFACE
+
+#ifdef USE_SDL_SURFACE
 
+#else
 /**
 **     Draw translucent pixel unclipped into 8bit framebuffer.
 **
@@ -7209,7 +7435,7 @@
     int i;
     int j;
 
-    /* ClearScreen */
+    /* ClearTheScreen */
     for (y = 0; y < VideoHeight; ++y) {
        for (x = 0; x < VideoWidth; ++x) {
            VideoDrawPixel(ColorBlack, x, y);
@@ -7256,6 +7482,7 @@
        }
     }
 }
+#endif // ifdef USE_SDL_SURFACE
 
 #endif // } DEBUG
 
Index: stratagus/src/video/png.c
diff -u stratagus/src/video/png.c:1.24 stratagus/src/video/png.c:1.25
--- stratagus/src/video/png.c:1.24      Sat Sep 27 17:54:10 2003
+++ stratagus/src/video/png.c   Mon Nov 17 14:14:48 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: png.c,v 1.24 2003/09/27 21:54:10 jsalmon3 Exp $
+//     $Id: png.c,v 1.25 2003/11/17 19:14:48 nehalmistry Exp $
 
 //@{
 
@@ -80,7 +80,14 @@
 global Graphic* LoadGraphicPNG(const char* name)
 {
     Graphic* graphic;
+#ifdef USE_SDL_SURFACE
+//    SDL_Palette* palette;
+    SDL_Color* palettecolors;
+int ckey;
+    ckey = -1;
+#else
     Palette* palette;
+#endif
     CLFile* fp;
     png_structp png_ptr;
     png_infop info_ptr;
@@ -126,13 +133,53 @@
        info_ptr->width * info_ptr->height);
     DebugLevel3("%s: %s" _C_ name _C_
        png_get_valid(png_ptr, info_ptr, PNG_INFO_PLTE) ? "palette" : "");
+#ifdef USE_SDL_SURFACE
+
+    // FIXME: need to get the correct color
+    /*
+    if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
+       Exit(-1);
+       Uint8 *trans;
+       int num_trans;
+
+       int t = -1;
+       png_color_16 *transv;
+       png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, &transv);
+       printf("num_trans = %d\n", num_trans);
+           for (i = 0; i < num_trans; ++i) {
+               if(trans[i] == 0) {
+                   if (t >= 0) {
+                       break;
+                   }
+                   t = i;
+               } else if (trans[i] != 255) {
+                   break;
+               }
+           }
+           if (i == num_trans) {
+               // exactly one transparent index
+               ckey = t;
+           } else {
+               // more than one transparent index, or translucency
+               png_set_expand(png_ptr);
+           }
+
+    }
+*/
+#else
     DebugLevel3(" %s" _C_
        png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) ? "transparent" : "");
+#endif
+
     DebugLevel3(" depth %d\n" _C_ info_ptr->bit_depth);
 
     // Setup translators:
 
+#ifdef USE_SDL_SURFACE
+    palettecolors = (SDL_Color*)calloc(256, sizeof(SDL_Color));
+#else
     palette = (Palette*)calloc(256, sizeof(Palette));
+#endif
 
     if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
        DebugLevel3("Color palette\n");
@@ -142,12 +189,22 @@
                abort();
            }
            for (i = 0; i < info_ptr->num_palette; ++i) {
+#ifdef USE_SDL_SURFACE
+               palettecolors[i].r = info_ptr->palette[i].red;
+               palettecolors[i].g = info_ptr->palette[i].green;
+               palettecolors[i].b = info_ptr->palette[i].blue;
+#else
                palette[i].r = info_ptr->palette[i].red;
                palette[i].g = info_ptr->palette[i].green;
                palette[i].b = info_ptr->palette[i].blue;
+#endif
            }
            for(; i < 256; ++i) {
+#ifdef USE_SDL_SURFACE
+               palettecolors[i].r = palettecolors[i].g = palettecolors[i].b = 
0;
+#else
                palette[i].r = palette[i].g = palette[i].b = 0;
+#endif
            }
        }
     }
@@ -211,7 +268,20 @@
     CLclose(fp);
 
     graphic = MakeGraphic(8, w, h, data, w * h);       // data freed by make 
graphic
+#ifdef USE_SDL_SURFACE
+    SDL_SetPalette(graphic->Surface, SDL_LOGPAL|SDL_PHYSPAL, palettecolors, 0, 
256);
+//    SDL_SetColorKey(graphic->Surface, SDL_SRCCOLORKEY|SDL_RLEACCEL, ckey);
+
+    // FIXME: need to find correct color
+    SDL_SetColorKey(graphic->Surface, SDL_SRCCOLORKEY|SDL_RLEACCEL, 
+       SDL_MapRGB(graphic->Surface->format, 255, 255, 255));
+
+//     SDL_MapRGB(graphic->Surface->format, 255, 255, 255));
+//    SDL_SetPalette(graphic->Surface, 0, palettecolors, 0, 256);
+//    SDL_SetPalette(TheScreen, SDL_LOGPAL|SDL_PHYSPAL, palettecolors, 0, 256);
+#else
     graphic->Palette = palette;  //FIXME: should this be part of MakeGraphic
+#endif
 
     return graphic;
 }
@@ -223,6 +293,8 @@
 */
 global void SaveScreenshotPNG(const char* name)
 {
+#ifdef USE_SDL_SURFACE
+#else
     FILE* fp;
     png_structp png_ptr;
     png_infop info_ptr;
@@ -322,6 +394,7 @@
     free(row);
 
     fclose(fp);
+#endif
 }
 
 //@}
Index: stratagus/src/video/sdl.c
diff -u stratagus/src/video/sdl.c:1.102 stratagus/src/video/sdl.c:1.103
--- stratagus/src/video/sdl.c:1.102     Thu Oct 23 14:38:36 2003
+++ stratagus/src/video/sdl.c   Mon Nov 17 14:14:48 2003
@@ -10,7 +10,7 @@
 //
 /address@hidden sdl.c          -       SDL video support. */
 //
-//     (c) Copyright 1999-2003 by Lutz Sammer and Jimmy Salmon
+//     (c) Copyright 1999-2003 by Lutz Sammer, Jimmy Salmon, Nehal Mistry
 //
 //      This program is free software; you can redistribute it and/or modify
 //      it under the terms of the GNU General Public License as published by
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: sdl.c,v 1.102 2003/10/23 18:38:36 n0body Exp $
+//     $Id: sdl.c,v 1.103 2003/11/17 19:14:48 nehalmistry Exp $
 
 //@{
 
@@ -82,7 +82,11 @@
 --     Variables
 ----------------------------------------------------------------------------*/
 
+#ifdef USE_SDL_SURFACE
+global SDL_Surface* TheScreen;         /// Internal screen
+#else
 global SDL_Surface* Screen;            /// Internal screen
+#endif
 global int InMainWindow = 1;           /// Cursor inside stratagus window
 
 local int FrameTicks;                  /// Frame length in ms
@@ -158,6 +162,7 @@
 
     // Initialize the SDL library
 
+
     if (SDL_WasInit(SDL_INIT_VIDEO) == 0) {
 
        if (SDL_Init(
@@ -201,6 +206,10 @@
 #ifdef USE_OPENGL
     flags |= SDL_OPENGL;
 #endif
+
+#ifdef USE_SDL_SURFACE
+    TheScreen = SDL_SetVideoMode(VideoWidth, VideoHeight, VideoDepth, flags);
+#else
     Screen = SDL_SetVideoMode(VideoWidth, VideoHeight, VideoDepth, flags);
 
     if (Screen == NULL) {
@@ -208,24 +217,45 @@
            VideoWidth, VideoHeight, VideoDepth, SDL_GetError());
        exit(1);
     }
+#endif
+
+#ifdef USE_SDL_SURFACE
+//    TheScreen = TheScreen;
+    if (VideoDepth == 8)
+    TheScreen->format->palette = &GlobalPalette;
+#endif
 
 #ifdef DEBUG
+#ifdef USE_SDL_SURFACE
+    if (SDL_MUSTLOCK(TheScreen)) {
+       DebugLevel0Fn("Must locksurface!\n");
+    }
+#else
     if (SDL_MUSTLOCK(Screen)) {
        DebugLevel0Fn("Must locksurface!\n");
     }
 #endif
+#endif
 
     // Turn cursor off, we use our own.
     SDL_ShowCursor(0);
 
+#ifdef USE_SDL_SURFACE
+    VideoBpp = TheScreen->format->BitsPerPixel;
+    VideoFullScreen = (TheScreen->flags & SDL_FULLSCREEN) ? 1 : 0;
+#else
     VideoBpp = Screen->format->BitsPerPixel;
     VideoFullScreen = (Screen->flags & SDL_FULLSCREEN) ? 1 : 0;
+#endif
 
     //
     // I need the used bits per pixel.
     // You see it's better making all self, than using wired libaries :)
     //  And with the win32 version this also doesn't work
     //
+#ifdef USE_SDL_SURFACE
+    VideoDepth = TheScreen->format->BitsPerPixel;
+#else
     if (!VideoDepth) {
        int i;
        int j;
@@ -246,6 +276,7 @@
            VideoDepth = Screen->format->BitsPerPixel;
        }
     }
+#endif
 
     // Make default character translation easier
     SDL_EnableUNICODE(1);
@@ -259,7 +290,6 @@
     ColorBlue = VideoMapRGB(0, 0, 252);
     ColorOrange = VideoMapRGB(248, 140, 20);
     ColorWhite = VideoMapRGB(252, 248, 240);
-    ColorNPC = VideoMapRGB(160, 160, 164);
     ColorGray = VideoMapRGB(128, 128, 128);
     ColorRed = VideoMapRGB(252, 0, 0);
     ColorGreen = VideoMapRGB(0, 252, 0);
@@ -280,6 +310,9 @@
 */
 global void InvalidateArea(int x, int y, int w, int h)
 {
+#ifdef USE_SDL_SURFACE
+    SDL_UpdateRect(TheScreen, x, y, w, h);
+#else
 #ifndef USE_OPENGL
     // FIXME: This checks should be done at higher level
     // FIXME: did SDL version >1.1, check this now also?
@@ -305,6 +338,7 @@
     }
     SDL_UpdateRect(Screen, x, y, w, h);
 #endif
+#endif
 }
 
 /**
@@ -313,8 +347,12 @@
 global void Invalidate(void)
 {
 #ifndef USE_OPENGL
+#ifdef USE_SDL_SURFACE
+    SDL_UpdateRect(TheScreen, 0, 0, VideoWidth, VideoHeight);
+#else
     SDL_UpdateRect(Screen, 0, 0, VideoWidth, VideoHeight);
 #endif
+#endif
 }
 
 /**
@@ -773,6 +811,18 @@
 #endif
 }
 
+#ifdef USE_SDL_SURFACE
+global SDL_Color VideoMapRGB(int r, int g, int b)
+{
+    SDL_Color c;
+
+    c.r = r;
+    c.g = g;
+    c.b = b;
+
+    return c;
+}
+#else
 /**
 **     Maps RGB to a hardware dependent pixel.
 **
@@ -787,13 +837,29 @@
     VMemType c;
     unsigned long map;
 
+#ifdef USE_SDL_SURFACE
+    DebugCheck(!TheScreen);
+    map = SDL_MapRGB(TheScreen->format, r, g, b);
+#else
     DebugCheck(!Screen);
-
     map = SDL_MapRGB(Screen->format, r, g, b);
+#endif
+
     memcpy(&c, &map, sizeof(c));
     return c;
 }
+#endif
 
+#ifdef USE_SDL_SURFACE
+// FIXME: todo
+/*
+global SDL_Palette* VideoCreateNewPalette(const SDL_Palette* palette)
+{
+    SDL_Palette *s;
+    return s;
+}
+*/
+#else
 /**
 **     Create a new hardware dependent palette palette.
 **
@@ -887,6 +953,7 @@
 
     return pixels;
 }
+#endif
 
 /**
 **     Check video interrupt.
@@ -915,9 +982,13 @@
 global void SdlLockScreen(void)
 {
 #ifndef USE_OPENGL
+#ifdef USE_SDL_SURFACE
+    SDL_LockSurface(TheScreen);
+#else
     SDL_LockSurface(Screen);
     VideoMemory = Screen->pixels;
 #endif
+#endif
 }
 
 /**
@@ -926,6 +997,9 @@
 global void SdlUnlockScreen(void)
 {
 #ifndef USE_OPENGL
+#ifdef USE_SDL_SURFACE
+    SDL_UnlockSurface(TheScreen);
+#else
     SDL_UnlockSurface(Screen);
 #ifdef DEBUG
     VideoMemory = NULL;                        // Catch errors!
@@ -933,6 +1007,7 @@
     VideoMemory = Screen->pixels;      // Be kind
 #endif
 #endif
+#endif
 }
 
 /**
@@ -975,32 +1050,69 @@
     int ncolors;
 #endif
 
+#ifdef USE_SDL_SURFACE
+    if (!TheScreen) {                  // don't bother if there's no surface.
+       return;
+    }
+#else
     if (!Screen) {                     // don't bother if there's no surface.
        return;
     }
+#endif
 
+#ifdef USE_SDL_SURFACE
+    flags = TheScreen->flags;
+    w = TheScreen->w;
+    h = TheScreen->h;
+    bpp = TheScreen->format->BitsPerPixel;
+
+    SDL_GetClipRect(TheScreen, &clip);
+#else
     flags = Screen->flags;
     w = Screen->w;
     h = Screen->h;
     bpp = Screen->format->BitsPerPixel;
 
     SDL_GetClipRect(Screen, &clip);
+#endif
 
     // save the contents of the screen.
+#ifdef USE_SDL_SURFACE
     framesize = w * h * Screen->format->BytesPerPixel;
+#else
+    framesize = w * h * TheScreen->format->BytesPerPixel;
+#endif
 
 #ifndef USE_OPENGL
     if (!(pixels = malloc(framesize))) {       // out of memory
        return;
     }
+#ifdef USE_SDL_SURFACE
+    SDL_LockSurface(TheScreen);
+    memcpy(pixels, TheScreen->pixels, framesize);
+#else
     SDL_LockSurface(Screen);
     memcpy(pixels, Screen->pixels, framesize);
+#endif
+#else
 
 #ifdef DEBUG
     // shut up compiler
     palette = NULL;
     ncolors=0;
 #endif
+#ifdef USE_SDL_SURFACE
+    if (TheScreen->format->palette) {
+       ncolors = TheScreen->format->palette->ncolors;
+       if (!(palette = malloc(ncolors * sizeof(SDL_Color)))) {
+           free(pixels);
+           return;
+       }
+       memcpy(palette, TheScreen->format->palette->colors,
+           ncolors * sizeof(SDL_Color));
+    }
+    SDL_UnlockSurface(TheScreen);
+#else
     if (Screen->format->palette) {
        ncolors = Screen->format->palette->ncolors;
        if (!(palette = malloc(ncolors * sizeof(SDL_Color)))) {
@@ -1012,7 +1124,24 @@
     }
     SDL_UnlockSurface(Screen);
 #endif
+#endif
 
+#ifdef USE_SDL_SURFACE
+    TheScreen = SDL_SetVideoMode(w, h, bpp, flags ^ SDL_FULLSCREEN);
+    if (!TheScreen) {
+       TheScreen = SDL_SetVideoMode(w, h, bpp, flags);
+       if (!TheScreen) {               // completely screwed.
+#ifndef USE_OPENGL
+           free(pixels);
+           if (TheScreen->format->palette) {
+               free(palette);
+           }
+#endif
+           fprintf(stderr, "Toggle to fullscreen, crashed all\n");
+           Exit(-1);
+       }
+    }
+#else
     Screen = SDL_SetVideoMode(w, h, bpp, flags ^ SDL_FULLSCREEN);
     if (!Screen) {
        Screen = SDL_SetVideoMode(w, h, bpp, flags);
@@ -1027,6 +1156,7 @@
            Exit(-1);
        }
     }
+#endif
 
     // Windows shows the SDL cursor when starting in fullscreen mode
     // then switching to window mode.  This hides the cursor again.
@@ -1036,6 +1166,18 @@
 #ifdef USE_OPENGL
     InitOpenGL();
 #else
+#ifdef USE_SDL_SURFACE
+    SDL_LockSurface(TheScreen);
+    memcpy(TheScreen->pixels, pixels, framesize);
+    free(pixels);
+
+    if (TheScreen->format->palette) {
+       // !!! FIXME : No idea if that flags param is right.
+       SDL_SetPalette(TheScreen, SDL_LOGPAL, palette, 0, ncolors);
+       free(palette);
+    }
+    SDL_UnlockSurface(TheScreen);
+#else
     SDL_LockSurface(Screen);
     memcpy(Screen->pixels, pixels, framesize);
     free(pixels);
@@ -1047,14 +1189,30 @@
     }
     SDL_UnlockSurface(Screen);
 #endif
+#endif
 
+#ifdef USE_SDL_SURFACE
+    SDL_SetClipRect(TheScreen, &clip);
+#else
     SDL_SetClipRect(Screen, &clip);
+#endif
 
     Invalidate();                      // Update display
 #else
+#ifdef USE_SDL_SURFACE
+    SDL_WM_ToggleFullScreen(TheScreen);
+#else
     SDL_WM_ToggleFullScreen(Screen);
 #endif
+
+#endif
+#ifdef USE_SDL_SURFACE
+    VideoFullScreen = (TheScreen->flags & SDL_FULLSCREEN) ? 1 : 0;
+#else
     VideoFullScreen = (Screen->flags & SDL_FULLSCREEN) ? 1 : 0;
+#endif
+
+
 }
 
 #endif // } USE_SDL
Index: stratagus/src/video/sprite.c
diff -u stratagus/src/video/sprite.c:1.38 stratagus/src/video/sprite.c:1.39
--- stratagus/src/video/sprite.c:1.38   Wed Nov 12 15:33:42 2003
+++ stratagus/src/video/sprite.c        Mon Nov 17 14:14:48 2003
@@ -10,7 +10,8 @@
 //
 /address@hidden sprite.c       -       The general sprite functions. */
 //
-//     (c) Copyright 2000-2002 by Lutz Sammer, Stephan Rasenberg
+//     (c) Copyright 2000-2002 by Lutz Sammer, Stephan Rasenberg, 
+//     Nehal Mistry
 //
 //      This program is free software; you can redistribute it and/or modify
 //      it under the terms of the GNU General Public License as published by
@@ -26,7 +27,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: sprite.c,v 1.38 2003/11/12 20:33:42 jsalmon3 Exp $
+//     $Id: sprite.c,v 1.39 2003/11/17 19:14:48 nehalmistry Exp $
 
 //@{
 
@@ -54,8 +55,13 @@
 local GraphicType GraphicSprite8Type;  /// sprite type 8bit palette
 local GraphicType GraphicSprite16Type; /// sprite type 16bit palette
 
+#ifdef USE_SDL_SURFACE
+global void VideoDrawRawClip(SDL_Surface *surface,
+    int x, int y, int w, int h);
+#else
 global void (*VideoDrawRawClip)(VMemType *pixels, const unsigned char *data,
     int x, int y, int w, int h);
+#endif
 
 /*----------------------------------------------------------------------------
 --     Local functions
@@ -65,6 +71,23 @@
 --     RLE Sprites
 ----------------------------------------------------------------------------*/
 
+#ifdef USE_SDL_SURFACE
+local void VideoDraw(const Graphic* sprite, unsigned frame, int x, int y)
+{
+    SDL_Rect srect;
+    SDL_Rect drect;
+
+    srect.x = (frame % (sprite->Surface->w / sprite->Width)) * sprite->Width;
+    srect.y = (frame / (sprite->Surface->w / sprite->Width)) * sprite->Height;
+    srect.w = sprite->Width;
+    srect.h = sprite->Height;
+
+    drect.x = x;
+    drect.y = y;
+
+    SDL_BlitSurface(sprite->Surface, &srect, TheScreen, &drect);
+}
+#else
 //
 //     The current implementation uses RLE encoded sprites.
 //     If you know something better, write it.
@@ -183,6 +206,7 @@
 {
     RLE_BLIT(32, sprite, frame, x, y);
 }
+#endif
 
 /**
 **     Draw graphic object unclipped.
@@ -219,6 +243,21 @@
 }
 #endif
 
+#ifdef USE_SDL_SURFACE
+local void VideoDrawXFlip(const Graphic* sprite, unsigned frame, int x, int y)
+{
+
+    int sbpp;
+    int dbpp;
+
+    sbpp = sprite->Surface->format->BytesPerPixel;
+    dbpp = TheScreen->format->BytesPerPixel;
+
+
+    // FIXME: todo
+//    SDL_BlitSurface(, &srect, temp, &drect);
+}
+#else
 /**
 **     Draw 8bit graphic object unclipped and flipped in X direction
 **     into 8 bit framebuffer.
@@ -393,6 +432,7 @@
        dp += da;
     } while (dp < ep);                 // all lines
 }
+#endif
 
 /**
 **     Draw graphic object unclipped and flipped in X direction.
@@ -429,6 +469,36 @@
 }
 #endif
 
+#ifdef USE_SDL_SURFACE
+global void VideoDrawClip(const Graphic* sprite, unsigned frame, int x, int y)
+{
+    SDL_Rect srect;
+    SDL_Rect drect;
+
+    srect.x = (frame % (sprite->Surface->w / sprite->Width)) * sprite->Width;
+    srect.y = (frame / (sprite->Surface->w / sprite->Width)) * sprite->Height;
+    srect.w = sprite->Width;
+    srect.h = sprite->Height;
+
+    if (x + srect.w > ClipX2) {
+       drect.w = ClipX2 - x;
+    }
+    if (y + srect.h > ClipY2) {
+       drect.h = ClipY2 - y;
+    }
+    if (x < ClipX1) {
+       x = ClipX1;
+    }
+    if (y < ClipY1) {
+       y = ClipY1;
+    }
+
+    drect.x = x;
+    drect.y = y;
+
+    SDL_BlitSurface(sprite->Surface, &srect, TheScreen, &drect);
+}
+#else
 /**
 **     Draw 8bit graphic object clipped into 8 bit framebuffer.
 **
@@ -973,6 +1043,7 @@
 
     }
 }
+#endif
 
 /**
 **     Draw graphic object clipped.
@@ -1027,6 +1098,9 @@
 }
 #endif
 
+#ifdef USE_SDL_SURFACE
+
+#else
 /**
 **     Draw 8bit graphic object clipped and flipped in X direction
 **     into 8 bit framebuffer.
@@ -1578,6 +1652,7 @@
        }
     }
 }
+#endif
 
 /**
 **     Draw graphic object clipped and flipped in X direction.
@@ -1640,6 +1715,9 @@
 }
 #endif
 
+#ifdef USE_SDL_SURFACE
+
+#else
 /**
 **     Draw 8bit shadow graphic object clipped into 8 bit framebuffer.
 **
@@ -2248,7 +2326,11 @@
 
     }
 }
+#endif
 
+#ifdef USE_SDL_SURFACE
+    // FIXME: todo
+#else
 /**
 **     Draw 8bit shadow graphic object clipped and flipped in X direction
 **     into 8bit framebuffer.
@@ -2911,7 +2993,11 @@
        dest += nextline;
     } while (--h > 0);
 }
+#endif
 
+#ifdef USE_SDL_SURFACE
+    // FIXME: todo
+#else
 /**
 **     Draw 8bit raw graphic data clipped, using given pixel pallette
 **     into 8bit framebuffer.
@@ -2979,7 +3065,21 @@
 {
     VideoDrawRawXXClip((char*)pixels, data, x, y, w, h, sizeof(VMemType32));
 }
+#endif
 
+#ifdef USE_SDL_SURFACE
+local void FreeSprite(Graphic* graphic)
+{
+    int i;
+#ifdef DEBUG_TODO
+    AllocatedGraphicMemory -= graphic->Size;
+    AllocatedGraphicMemory -= sizeof(Graphic);
+#endif
+    for (i = 0; i < graphic->NumFrames; ++i) {
+       SDL_FreeSurface(&graphic->Surface[i]);
+    }
+}
+#else
 /**
 **     Free graphic object.
 */
@@ -3000,6 +3100,7 @@
     free(graphic->Frames);
     free(graphic);
 }
+#endif
 
 // FIXME: need 16 bit palette version
 // FIXME: need alpha blending version
@@ -3024,6 +3125,20 @@
 */
 global Graphic* LoadSprite(const char* name, int width, int height)
 {
+#ifdef USE_SDL_SURFACE
+    Graphic * g;
+    int nframes;
+
+    g = LoadGraphic(name);
+
+    nframes = g->Width / width * g->Height / height;
+
+    g->NumFrames = nframes;
+    g->Width = width;
+    g->Height = height;
+
+    return g;
+#else
     Graphic* graphic;
 #ifndef USE_OPENGL
     Graphic* sprite;
@@ -3106,6 +3221,7 @@
        fprintf(stderr, "Unsported image depth\n");
        ExitFatal(-1);
     }
+
     sprite->Width = width;
     sprite->Height = height;
 
@@ -3117,7 +3233,6 @@
     sprite->Size = 0;
     sprite->Frames = NULL;
 
-
     // Worst case is alternating opaque and transparent pixels
     data = malloc(n * sizeof(unsigned char*) + 
        (graphic->Width / 2 + 1) * 3 * graphic->Height);
@@ -3197,6 +3312,7 @@
 
     return sprite;
 #endif
+#endif
 }
 
 /**
@@ -3204,6 +3320,10 @@
 */
 global void InitSprite(void)
 {
+#ifdef USE_SDL_SURFACE
+
+#else
+
 #ifdef USE_OPENGL
     GraphicSprite8Type.Draw = VideoDrawOpenGL;
     GraphicSprite8Type.DrawClip = VideoDrawClipOpenGL;
@@ -3213,6 +3333,7 @@
     GraphicSprite8Type.DrawShadowClipX = VideoDraw8to32ShadowClipX;
     VideoDrawRawClip = VideoDrawRaw32Clip;
 #else
+
     switch (VideoBpp) {
        case 8:
            GraphicSprite8Type.Draw = VideoDraw8to8;
@@ -3262,6 +3383,7 @@
 #endif
 
     GraphicSprite8Type.Free = FreeSprite8;
+#endif
 }
 
 //@}
Index: stratagus/src/video/video.c
diff -u stratagus/src/video/video.c:1.70 stratagus/src/video/video.c:1.71
--- stratagus/src/video/video.c:1.70    Fri Nov  7 15:02:10 2003
+++ stratagus/src/video/video.c Mon Nov 17 14:14:48 2003
@@ -10,7 +10,7 @@
 //
 /address@hidden video.c        -       The universal video functions. */
 //
-//     (c) Copyright 1999-2002 by Lutz Sammer
+//     (c) Copyright 1999-2002 by Lutz Sammer and Nehal Mistry
 //
 //      This program is free software; you can redistribute it and/or modify
 //      it under the terms of the GNU General Public License as published by
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: video.c,v 1.70 2003/11/07 20:02:10 n0body Exp $
+//     $Id: video.c,v 1.71 2003/11/17 19:14:48 nehalmistry Exp $
 
 //@{
 
@@ -190,7 +190,11 @@
     ** @see InitVideo @see InitVideoSdl
     ** @see VMemType
     */
+#ifdef USE_SDL_SURFACE
+global SDL_Surface* TheScreen;
+#else
 global VMemType* VideoMemory;
+#endif
 
     /**
     ** Architecture-dependant system palette. Applies as conversion between
@@ -198,14 +202,21 @@
     ** Set by VideoCreatePalette or VideoSetPalette.
     ** @see VideoCreatePalette @see VideoSetPalette
     */
+#ifdef USE_SDL_SURFACE
+global SDL_Palette* Pixels;
+#else
 global VMemType* Pixels;
+#endif
 
 global int VideoSyncSpeed = 100;       /// 0 disable interrupts
 global volatile int VideoInterrupts;   /// be happy, were are quicker
 
     /// Loaded system palette. 256-entries long, active system palette.
+#ifdef USE_SDL_SURFACE
+global SDL_Palette GlobalPalette;
+#else
 global Palette GlobalPalette[256];
-
+#endif
     /**
     ** FIXME: this docu is added only to the first variable!
     **
@@ -236,6 +247,20 @@
     **  VideoAllocPalette8:
     **  Funcytion to let hardware independent palette be converted (when set).
     */
+#ifdef USE_SDL_SURFACE
+global SDL_Palette* commonpalette;
+    // FIXME: docu
+//global unsigned long commonpalette_defined[8];
+    // FIXME: docu
+global SDL_Color* colorcube8;
+    // FIXME: docu
+global SDL_Color* lookup25trans8;
+    // FIXME: docu
+global SDL_Color* lookup50trans8;
+    // FIXME: docu
+global void VideoAllocPalette(SDL_Palette* palette, SDL_Palette* 
+    syspalette);
+#else
 global Palette* commonpalette;
     // FIXME: docu
 global unsigned long commonpalette_defined[8];
@@ -248,6 +273,7 @@
     // FIXME: docu
 global void (*VideoAllocPalette8)(Palette* palette, Palette* syspalette,
     unsigned long syspalette_defined[8]) = NULL;
+#endif
 
 global int ColorWaterCycleStart;
 global int ColorWaterCycleEnd;
@@ -257,6 +283,19 @@
 global int ColorBuildingCycleEnd;
 
     /// Does ColorCycling..
+#ifdef USE_SDL_SURFACE
+global void ColorCycle(void);
+
+SDL_Color ColorBlack;
+SDL_Color ColorDarkGreen;
+SDL_Color ColorBlue;
+SDL_Color ColorOrange;
+SDL_Color ColorWhite;
+SDL_Color ColorGray;
+SDL_Color ColorRed;
+SDL_Color ColorGreen;
+SDL_Color ColorYellow;
+#else
 global void (*ColorCycle)(void);
 
 VMemType ColorBlack;
@@ -269,6 +308,7 @@
 VMemType ColorRed;
 VMemType ColorGreen;
 VMemType ColorYellow;
+#endif
 
 
 /*----------------------------------------------------------------------------
@@ -426,6 +466,22 @@
 **
 **     @return         Calculated hash/checksum.
 */
+#ifdef USE_SDL_SURFACE
+local long GetPaletteChecksum(const SDL_Palette* palette)
+{
+    long retVal;
+    int i;
+
+    for (retVal = i = 0; i < palette->ncolors; ++i){
+       //This is designed to return different values if
+       // the pixels are in a different order.
+       retVal = ((palette->colors[i].r + i) & 0xff) + retVal;
+       retVal = ((palette->colors[i].g + i) & 0xff) + retVal;
+       retVal = ((palette->colors[i].b + i) & 0xff) + retVal;
+    }
+    return retVal;
+}
+#else
 local long GetPaletteChecksum(const Palette* palette)
 {
     long retVal;
@@ -440,6 +496,7 @@
     }
     return retVal;
 }
+#endif
 
 /**
 **     Creates a shared hardware palette from an independend Palette struct.
@@ -448,6 +505,9 @@
 **
 **     @return         A palette in hardware  dependend format.
 */
+#ifdef USE_SDL_SURFACE
+
+#else
 global VMemType* VideoCreateSharedPalette(const Palette* palette)
 {
     PaletteLink* current_link;
@@ -518,6 +578,7 @@
        }
     }
 }
+#endif
 
 /**
 **     Load a picture and display it on the screen (full screen),
@@ -535,12 +596,25 @@
     MakeTexture(picture, picture->Width, picture->Height);
 #endif
 
-    VideoLockScreen();
+#ifdef USE_SDL_SURFACE
+    SDL_Rect srect;
+    SDL_Rect drect;
+
+    srect.x = 0;
+    srect.y = 0;
+    srect.w = picture->Width;
+    srect.h = picture->Height;
+
+    drect.x = 0;
+    drect.y = 0;
 
+    SDL_BlitSurface(picture->Surface, &srect, TheScreen, &drect);
+#else
+    VideoLockScreen();
     VideoDrawSubClip(picture, 0, 0, picture->Width, picture->Height,
        (VideoWidth - picture->Width) / 2, (VideoHeight - picture->Height) / 2);
-
     VideoUnlockScreen();
+#endif
 
     VideoFree(picture);
 }
@@ -554,6 +628,35 @@
 **
 **     @see VideoCreatePalette
 */
+#ifdef USE_SDL_SURFACE
+global void LoadRGB(SDL_Palette* pal, const char* name)
+{
+    CLFile* fp;
+    int i;
+    unsigned char* p;
+    unsigned char buffer[256 * 3];
+
+    if (!(fp = CLopen(name, CL_OPEN_READ)) || CLread(fp, buffer, 256 * 3) != 
256 * 3) {
+       fprintf(stderr, "Can't load palette %s\n", name);
+       ExitFatal(-1);
+    }
+
+    // FIXME: malloc somewhere else ?!?!
+    pal = malloc(sizeof(SDL_Palette));
+    pal->colors = calloc(256, sizeof(SDL_Color));
+
+    pal->ncolors = 256;
+
+    p = buffer;
+    for (i = 0; i < 256; ++i) {
+       pal->colors[i].r = (*p++);
+       pal->colors[i].g = (*p++);
+       pal->colors[i].b = (*p++);
+    }
+
+    CLclose(fp);
+}
+#else
 global void LoadRGB(Palette* pal, const char* name)
 {
     CLFile* fp;
@@ -575,6 +678,7 @@
 
     CLclose(fp);
 }
+#endif
 
 // FIXME: this isn't 100% correct
 // Color cycling info - forest:
@@ -610,6 +714,12 @@
 **     FIXME: Also icons and some units use color cycling.
 **     FIXME: must be configured by the tileset or global.
 */
+#ifdef USE_SDL_SURFACE
+local void ColorCycle(void)
+{
+    // FIXME: todo
+}
+#else
 local void ColorCycle8(void)
 {
     int i;
@@ -903,6 +1013,7 @@
     MapColorCycle();           // FIXME: could be little more informative
     MustRedraw |= RedrawColorCycle;
 }
+#endif
 
 /*===========================================================================
 Following functions support a single common palette for 8bpp
@@ -920,6 +1031,9 @@
 **      FIXME: Use TheUI settings (brightness, contrast and saturation) and
 **      visual color range knowledge to reduce the ammount of colors needed.
 */
+#ifdef USE_SDL_SURFACE
+    // FIXME: todo
+#else
 local void VideoFillCommonPalette8(Palette* palette)
 {
 #ifdef BPP8_WINSAFE
@@ -1049,7 +1163,7 @@
 #endif
 #endif
 }
-
+#endif
 
 /**
 **      Fill a colorcube to get from a RGB (5x5x5 bit) to a system 8bpp color
@@ -1064,6 +1178,9 @@
 **      @param cube     Array of 32768 (32*32*32) bytes with RGB value (each in
 **                      range 0..31) as index, delivers color index.
 */
+#ifdef USE_SDL_SURFACE
+    // FIXME: todo
+#else
 local void VideoFillColorcube8(const Palette* palette,
     const unsigned long pal_def[8], VMemType8* cube)
 {
@@ -1110,6 +1227,7 @@
        }
     }
 }
+#endif
 
 /**
 **      Find a new hardware dependend palette, re-using the colors as set in
@@ -1122,6 +1240,9 @@
 **      @return         A hardware dependend 8bpp pixel table.
 **
 */
+#ifdef USE_SDL_SURFACE
+    // FIXME: todo2
+#else
 global VMemType8* VideoFindNewPalette8(const VMemType8* cube,
     const Palette* palette)
 {
@@ -1201,13 +1322,18 @@
        }
     }
 }
-
+#endif
 /**
 **      Initialize globals based on a single common palette of 256 colors.
 **      Only needed for 8bpp, which hasn't RGB encoded in its system color.
 **      FIXME: should be called again when it gets dependent of TheUI settings
 **             then call VideoFreePalette first to prevent "can not allocate"
 */
+#ifdef USE_SDL_SURFACE
+local void InitSingleCommonPalette(void)
+{
+}
+#else
 local void InitSingleCommonPalette8(void)
 {
     Palette* tmp;
@@ -1256,6 +1382,7 @@
        exit(-1);
     }
 }
+#endif
 
 /*===========================================================================*/
 
@@ -1267,6 +1394,17 @@
 **
 **     @see SetPlayersPalette
 */
+#ifdef USE_SDL_SURFACE
+global void VideoSetPalette(const SDL_Palette* palette)
+{
+    if (!GlobalPalette.colors) {
+//    GlobalPalette = (SDL_Palette*)malloc(sizeof(SDL_Palette));
+        GlobalPalette.colors = calloc(256, sizeof(SDL_Color));
+    }
+//    TheScreen->format->palette = (SDL_Palette*)palette;
+    SetPlayersPalette();
+}
+#else
 global void VideoSetPalette(const VMemType* palette)
 {
     DebugLevel2Fn("Palette %x used\n" _C_ (unsigned)palette);
@@ -1277,6 +1415,7 @@
     Pixels = (VMemType*)palette;
     SetPlayersPalette();
 }
+#endif
 
 /*----------------------------------------------------------------------------
 --     Functions
@@ -1287,6 +1426,15 @@
 **
 **     @param palette  System independ palette structure.
 */
+#ifdef USE_SDL_SURFACE
+global void VideoCreatePalette(const SDL_Palette* palette)
+{
+//    SDL_SetPalette(
+//    SDL_Palette* temp;
+//    temp = VideoCreateNewPalette(palette);
+    VideoSetPalette(palette);
+}
+#else
 global void VideoCreatePalette(const Palette* palette)
 {
     VMemType* temp;
@@ -1295,6 +1443,7 @@
 
     VideoSetPalette(temp);
 }
+#endif
 
 /**
 **     Lock the screen for write access.
@@ -1358,6 +1507,8 @@
     //
     // General (video) modules and settings
     //
+#ifdef USE_SDL_SURFACE
+#else
     switch (VideoBpp) {
        case  8: ColorCycle = ColorCycle8; break;
        case 15:
@@ -1367,6 +1518,7 @@
         default: DebugLevel0Fn("Video %d bpp unsupported\n" _C_ VideoBpp);
     }
     VideoTypeSize = VideoBpp / 8;
+#endif
 
     //
     // Init video sub modules




reply via email to

[Prev in Thread] Current Thread [Next in Thread]