rnd-20030404-4-src
[rocksndiamonds.git] / src / libgame / msdos.c
index c6c51db6b65912ce03a3aba80d29a877ea9bd4b7..ec19ef6389c7d639c99f9106ef17826ff53de950 100644 (file)
@@ -1,7 +1,7 @@
 /***********************************************************
 * Artsoft Retro-Game Library                               *
 *----------------------------------------------------------*
-* (c) 1994-2001 Artsoft Entertainment                      *
+* (c) 1994-2002 Artsoft Entertainment                      *
 *               Holger Schemel                             *
 *               Detmolder Strasse 189                      *
 *               33604 Bielefeld                            *
@@ -17,7 +17,9 @@
 #if defined(PLATFORM_MSDOS)
 
 #include "sound.h"
+#include "joystick.h"
 #include "misc.h"
+#include "setup.h"
 #include "pcx.h"
 
 #define AllegroDefaultScreen() (display->screens[display->default_screen])
@@ -52,12 +54,6 @@ static int global_colormap_entries_used = 0;
 
 boolean wait_for_vsync;
 
-/*
-extern int playing_sounds;
-extern struct SoundControl playlist[MAX_SOUNDS_PLAYING];
-extern struct SoundControl emptySoundControl;
-*/
-
 static BITMAP *Read_PCX_to_AllegroBitmap(char *);
 
 static void allegro_init_drivers()
@@ -90,7 +86,7 @@ static void allegro_init_drivers()
 
 static boolean allegro_init_audio()
 {
-  reserve_voices(MAX_SOUNDS_PLAYING, 0);
+  reserve_voices(NUM_MIXER_CHANNELS, 0);
 
   if (install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL) == -1)
     if (install_sound(DIGI_SB, MIDI_NONE, NULL) == -1)
@@ -301,9 +297,9 @@ Display *XOpenDisplay(char *display_name)
   Screen *screen;
   Display *display;
   BITMAP *mouse_bitmap = NULL;
+  char *mouse_filename = getCustomImageFilename(program.msdos_cursor_filename);
 
-  mouse_bitmap = Read_PCX_to_AllegroBitmap(program.msdos_pointer_filename);
-  if (mouse_bitmap == NULL)
+  if ((mouse_bitmap = Read_PCX_to_AllegroBitmap(mouse_filename)) == NULL)
     return NULL;
 
   screen = malloc(sizeof(Screen));
@@ -921,6 +917,14 @@ Pixel AllegroGetPixel(Drawable d, int x, int y)
   return getpixel((BITMAP *)d, x, y);
 }
 
+void AllegroZoomBitmap(Drawable src, Drawable dst,
+                      int src_width, int src_height,
+                      int dst_width, int dst_height)
+{
+  stretch_blit((BITMAP *)src, (BITMAP *)dst,
+              0, 0, src_width, src_height, 0, 0, dst_width, dst_height);
+}
+
 void MSDOSOpenAudio(void)
 {
   if (allegro_init_audio())
@@ -929,9 +933,13 @@ void MSDOSOpenAudio(void)
     audio.music_available = TRUE;
     audio.loops_available = TRUE;
     audio.sound_enabled = TRUE;
-  }
 
-  InitPlaylist();
+    audio.num_channels = NUM_MIXER_CHANNELS;
+    audio.music_channel = MUSIC_CHANNEL;
+    audio.first_sound_channel = FIRST_SOUND_CHANNEL;
+
+    Mixer_InitChannels();
+  }
 }
 
 void MSDOSCloseAudio(void)
@@ -944,4 +952,57 @@ void NetworkServer(int port, int serveronly)
   Error(ERR_WARN, "networking not supported in DOS version");
 }
 
+
+/* ========================================================================= */
+/* joystick functions                                                        */
+/* ========================================================================= */
+
+void MSDOSInitJoysticks()
+{
+  int i;
+
+  /* start from scratch */
+  remove_joystick();
+
+  /* try to access two joysticks; if that fails, try to access just one */
+  if (install_joystick(JOY_TYPE_2PADS) == 0 ||
+      install_joystick(JOY_TYPE_AUTODETECT) == 0)
+    joystick.status = JOYSTICK_ACTIVATED;
+
+  for (i=0; i<MAX_PLAYERS; i++)
+  {
+    char *device_name = setup.input[i].joy.device_name;
+    int joystick_nr = getJoystickNrFromDeviceName(device_name);
+
+    if (joystick_nr >= num_joysticks)
+      joystick_nr = -1;
+
+    /* misuse joystick file descriptor variable to store joystick number */
+    joystick.fd[i] = joystick_nr;
+  }
+}
+
+boolean MSDOSReadJoystick(int nr, int *x, int *y, boolean *b1, boolean *b2)
+{
+  /* the allegro global variable 'num_joysticks' contains the number
+     of joysticks found at initialization under MS-DOS / Windows */
+
+  if (nr < 0 || nr >= num_joysticks)
+    return FALSE;
+
+  poll_joystick();
+
+  if (x != NULL)
+    *x = joy[nr].stick[0].axis[0].pos;
+  if (y != NULL)
+    *y = joy[nr].stick[0].axis[1].pos;
+
+  if (b1 != NULL)
+    *b1 = joy[nr].button[0].b;
+  if (b2 != NULL)
+    *b2 = joy[nr].button[1].b;
+
+  return TRUE;
+}
+
 #endif /* PLATFORM_MSDOS */