rnd-20010115-1-src
[rocksndiamonds.git] / src / libgame / msdos.c
index b3137b4a5bc7ecc98eb20e536503e1614b6f205b..2e0d278085cec4a689fd429ca03fd5efba081819 100644 (file)
@@ -1,21 +1,25 @@
 /***********************************************************
-*  Rocks'n'Diamonds -- McDuffin Strikes Back!              *
+* Artsoft Retro-Game Library                               *
 *----------------------------------------------------------*
-*  ©1995 Artsoft Development                               *
-*        Holger Schemel                                    *
-*        33659 Bielefeld-Senne                             *
-*        Telefon: (0521) 493245                            *
-*        eMail: aeglos@valinor.owl.de                      *
-*               aeglos@uni-paderborn.de                    *
-*               q99492@pbhrzx.uni-paderborn.de             *
+* (c) 1994-2001 Artsoft Entertainment                      *
+*               Holger Schemel                             *
+*               Detmolder Strasse 189                      *
+*               33604 Bielefeld                            *
+*               Germany                                    *
+*               e-mail: info@artsoft.org                   *
 *----------------------------------------------------------*
-*  msdos.c                                                 *
+* msdos.c                                                  *
 ***********************************************************/
 
-#include "libgame.h"
+#include "system.h"
+
 
 #if defined(PLATFORM_MSDOS)
 
+#include "sound.h"
+#include "misc.h"
+#include "pcx.h"
+
 #define AllegroDefaultScreen() (display->screens[display->default_screen])
 
 /* allegro driver declarations */
@@ -234,25 +238,7 @@ static KeySym ScancodeToKeySym(byte scancode)
   }
 }
 
-void XMapWindow(Display *display, Window window)
-{
-  int x, y;
-  unsigned int width, height;
-  boolean mouse_off;
-
-  x = AllegroDefaultScreen().x;
-  y = AllegroDefaultScreen().y;
-  width = AllegroDefaultScreen().width;
-  height = AllegroDefaultScreen().height;
-
-  mouse_off = hide_mouse(display, x, y, width, height);
-  blit((BITMAP *)window, video_bitmap, 0, 0, x, y, width, height);
-
-  if (mouse_off)
-    unhide_mouse(display);
-}
-
-static unsigned long AllocColorCell(int r, int g, int b)
+Pixel AllegroAllocColorCell(int r, int g, int b)
 {
   byte pixel_mapping = 0;
   int i;
@@ -278,16 +264,38 @@ static unsigned long AllocColorCell(int r, int g, int b)
     if (global_colormap_entries_used < MAX_COLORS)
       global_colormap_entries_used++;
 
+    i = global_colormap_entries_used - 1;
+
     global_colormap[i].r = r;
     global_colormap[i].g = g;
     global_colormap[i].b = b;
 
+    set_palette(global_colormap);
+
     pixel_mapping = i;
   }
 
   return pixel_mapping;
 }
 
+void XMapWindow(Display *display, Window window)
+{
+  int x, y;
+  unsigned int width, height;
+  boolean mouse_off;
+
+  x = AllegroDefaultScreen().x;
+  y = AllegroDefaultScreen().y;
+  width = AllegroDefaultScreen().width;
+  height = AllegroDefaultScreen().height;
+
+  mouse_off = hide_mouse(display, x, y, width, height);
+  blit((BITMAP *)window, video_bitmap, 0, 0, x, y, width, height);
+
+  if (mouse_off)
+    unhide_mouse(display);
+}
+
 Display *XOpenDisplay(char *display_name)
 {
   Screen *screen;
@@ -307,8 +315,8 @@ Display *XOpenDisplay(char *display_name)
   screen[0].white_pixel = 0xFF;
   screen[0].black_pixel = 0x00;
 #else
-  screen[0].white_pixel = AllocColorCell(0xFFFF, 0xFFFF, 0xFFFF);
-  screen[0].black_pixel = AllocColorCell(0x0000, 0x0000, 0x0000);
+  screen[0].white_pixel = AllegroAllocColorCell(0xFFFF, 0xFFFF, 0xFFFF);
+  screen[0].black_pixel = AllegroAllocColorCell(0x0000, 0x0000, 0x0000);
 #endif
   screen[0].video_bitmap = NULL;
 
@@ -558,9 +566,9 @@ static BITMAP *Image_to_AllegroBitmap(Image *image)
       pixel_mapping[i] = j;
     }
 #else
-    pixel_mapping[i] = AllocColorCell(image->rgb.red[i],
-                                     image->rgb.green[i],
-                                     image->rgb.blue[i]);
+    pixel_mapping[i] = AllegroAllocColorCell(image->rgb.red[i],
+                                            image->rgb.green[i],
+                                            image->rgb.blue[i]);
 #endif
 
   }
@@ -600,7 +608,17 @@ int Read_PCX_to_Pixmap(Display *display, Window window, GC gc, char *filename,
     return errno_pcx;
 
   *pixmap = (Pixmap)bitmap;
+#if 0
   *pixmap_mask = (Pixmap)bitmap;
+  /* !!! two pointers on same bitmap => second free() fails !!! */
+#else
+  /* pixmap_mask will never be used in Allegro (which uses masked_blit()),
+     so use non-NULL dummy pointer to empty Pixmap */
+  /*
+  *pixmap_mask = (Pixmap)checked_calloc(sizeof(Pixmap));
+  */
+  *pixmap_mask = (Pixmap)DUMMY_MASK;
+#endif
 
   return PCX_Success;
 }
@@ -915,9 +933,55 @@ void XAutoRepeatOff(Display *display)
   keyboard_auto_repeat = FALSE;
 }
 
-boolean MSDOSOpenAudio(void)
+void AllegroDrawLine(Drawable d, int from_x, int from_y, int to_x, int to_y,
+                    Pixel color)
 {
-  return allegro_init_audio();
+  boolean mouse_off = FALSE;
+
+  if ((BITMAP *)d == video_bitmap)
+  {
+    int dx = AllegroDefaultScreen().x;
+    int dy = AllegroDefaultScreen().y;
+    int x1, y1, x2, y2;
+
+    from_x += dx;
+    from_y += dy;
+    to_x += dx;
+    to_y += dy;
+
+    x1 = (from_x < to_x ? from_x : to_x);
+    y1 = (from_y < to_y ? from_y : to_y);
+    x2 = (from_x < to_x ? to_x : from_x);
+    y2 = (from_y < to_y ? to_y : from_y);
+
+    freeze_mouse_flag = TRUE;
+    mouse_off = hide_mouse(display, x1, y1, x2 - x1 + 1, y2 - y1 + 1);
+  }
+
+  line((BITMAP *)d, from_x, from_y, to_x, to_y, color);
+
+  if (mouse_off)
+    unhide_mouse(display);
+
+  freeze_mouse_flag = FALSE;
+}
+
+Pixel AllegroGetPixel(Drawable d, int x, int y)
+{
+  return getpixel((BITMAP *)d, x, y);
+}
+
+void MSDOSOpenAudio(void)
+{
+  if (allegro_init_audio())
+  {
+    audio.sound_available = TRUE;
+    audio.music_available = TRUE;
+    audio.loops_available = TRUE;
+    audio.sound_enabled = TRUE;
+  }
+
+  InitPlaylist();
 }
 
 void MSDOSCloseAudio(void)