rnd-19981202-1
authorHolger Schemel <info@artsoft.org>
Wed, 2 Dec 1998 13:28:53 +0000 (14:28 +0100)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 08:32:07 +0000 (10:32 +0200)
12 files changed:
src/Makefile
src/events.c
src/files.c
src/files.h
src/init.c
src/joystick.c
src/main.h
src/misc.c
src/misc.h
src/msdos.c
src/msdos.h
src/screens.c

index f57322d5d7bb1f1cafb5c6e4fe4dd8a72198f8ed..26739fb70a26a49c0f5f2a6e7902a33b3cc875d6 100644 (file)
@@ -95,7 +95,8 @@ SRCS =        main.c          \
        pcx.c           \
        image.c         \
        network.c       \
        pcx.c           \
        image.c         \
        network.c       \
-       netserv.c
+       netserv.c       \
+       msdos.c
 
 OBJS = main.o          \
        init.o          \
 
 OBJS = main.o          \
        init.o          \
@@ -115,7 +116,8 @@ OBJS =      main.o          \
        pcx.o           \
        image.o         \
        network.o       \
        pcx.o           \
        image.o         \
        network.o       \
-       netserv.o
+       netserv.o       \
+       msdos.o
 
 all:   $(PROGNAME)
 
 
 all:   $(PROGNAME)
 
@@ -126,7 +128,7 @@ $(PROGNAME):        $(OBJS)
        $(CC) $(CFLAGS) -c $*.c
 
 clean:
        $(CC) $(CFLAGS) -c $*.c
 
 clean:
-       $(RM) $(OBJS)
+       $(RM) *.o
        $(RM) $(PROGNAME)
 
 depend:
        $(RM) $(PROGNAME)
 
 depend:
index 8d1de10daab05453a25e881a39f478064d1b3681..7f71d4b790c68cf13fda22c0bb4dba5d4a6dfa30 100644 (file)
@@ -622,12 +622,19 @@ static int HandleJoystickForAllPlayers()
   {
     byte joy_action = 0;
 
   {
     byte joy_action = 0;
 
+    /*
     if (!setup.input[i].use_joystick)
       continue;
     if (!setup.input[i].use_joystick)
       continue;
+      */
 
     joy_action = Joystick(i);
     result |= joy_action;
 
 
     joy_action = Joystick(i);
     result |= joy_action;
 
+
+    if (!setup.input[i].use_joystick)
+      continue;
+
+
     stored_player[i].action = joy_action;
   }
 
     stored_player[i].action = joy_action;
   }
 
index daaaaa72dcef77d08db0378f12d236d9b90e75a7..2b089217ae9daba79e3c6d345ec153f5f8d9787e 100644 (file)
@@ -60,6 +60,7 @@
 #define LEVELFILE_EXTENSION    "lvl"
 #define TAPEFILE_EXTENSION     "rec"
 #define SCOREFILE_EXTENSION    "sco"
 #define LEVELFILE_EXTENSION    "lvl"
 #define TAPEFILE_EXTENSION     "rec"
 #define SCOREFILE_EXTENSION    "sco"
+#define ERROR_FILENAME         "error.out"
 #endif
 
 /* file permissions for newly written files */
 #endif
 
 /* file permissions for newly written files */
@@ -80,7 +81,7 @@ static char *getGlobalDataDir()
   return GAME_DIR;
 }
 
   return GAME_DIR;
 }
 
-static char *getUserDataDir()
+char *getUserDataDir()
 {
   static char *userdata_dir = NULL;
 
 {
   static char *userdata_dir = NULL;
 
@@ -1663,3 +1664,63 @@ void SaveLevelSetup()
 
   chmod(filename, SETUP_PERMS);
 }
 
   chmod(filename, SETUP_PERMS);
 }
+
+#ifdef MSDOS
+static boolean initErrorFile()
+{
+  char *filename;
+  FILE *error_file;
+
+  InitUserDataDirectory();
+
+  filename = getPath2(getUserDataDir(), ERROR_FILENAME);
+  error_file = fopen(filename, "w");
+  free(filename);
+
+  if (error_file == NULL)
+    return FALSE;
+
+  fclose(error_file);
+
+  return TRUE;
+}
+
+FILE *openErrorFile()
+{
+  static boolean first_access = TRUE;
+  char *filename;
+  FILE *error_file;
+
+  if (first_access)
+  {
+    if (!initErrorFile())
+      return NULL;
+
+    first_access = FALSE;
+  }
+
+  filename = getPath2(getUserDataDir(), ERROR_FILENAME);
+  error_file = fopen(filename, "a");
+  free(filename);
+
+  return error_file;
+}
+
+void dumpErrorFile()
+{
+  char *filename;
+  FILE *error_file;
+
+  filename = getPath2(getUserDataDir(), ERROR_FILENAME);
+  error_file = fopen(filename, "r");
+  free(filename);
+
+  if (error_file != NULL)
+  {
+    while (!feof(error_file))
+      fputc(fgetc(error_file), stderr);
+
+    fclose(error_file);
+  }
+}
+#endif
index 429fe63f6b3b84548ab92f64276deb335019df70..d95cce18fc76076f732c2ee7d3333e9684a45ab6 100644 (file)
@@ -33,4 +33,9 @@ void SaveSetup(void);
 void LoadLevelSetup(void);
 void SaveLevelSetup(void);
 
 void LoadLevelSetup(void);
 void SaveLevelSetup(void);
 
+#ifdef MSDOS
+FILE *openErrorFile();
+void dumpErrorFile();
+#endif
+
 #endif /* FILES_H */
 #endif /* FILES_H */
index ce89416c783e356126fcaebdbf1d12326543843d..25cc7e043c72b7d9ad00635cf2c8241b61485e38 100644 (file)
@@ -72,19 +72,10 @@ void OpenAll(int argc, char *argv[])
   InitDisplay();
   InitWindow(argc, argv);
 
   InitDisplay();
   InitWindow(argc, argv);
 
-  print_debug("now map window");
-
   XMapWindow(display, window);
   XFlush(display);
 
   XMapWindow(display, window);
   XFlush(display);
 
-  print_debug("window mapped");
-
-  print_debug("now init gfx");
-
   InitGfx();
   InitGfx();
-
-  print_debug("gfx initialized");
-
   InitElementProperties();
 
   DrawMainMenu();
   InitElementProperties();
 
   DrawMainMenu();
@@ -227,9 +218,7 @@ void InitSoundServer()
 
 void InitJoysticks()
 {
 
 void InitJoysticks()
 {
-#ifndef MSDOS
   int i;
   int i;
-#endif
 
   if (global_joystick_status == JOYSTICK_OFF)
     return;
 
   if (global_joystick_status == JOYSTICK_OFF)
     return;
@@ -266,7 +255,27 @@ void InitJoysticks()
     joystick_status = JOYSTICK_AVAILABLE;
   }
 #else
     joystick_status = JOYSTICK_AVAILABLE;
   }
 #else
-  joystick_status = JOYSTICK_AVAILABLE;
+
+  /* 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_AVAILABLE;
+
+  /*
+  load_joystick_data(JOYSTICK_FILENAME);
+  */
+
+  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 */
+    stored_player[i].joystick_fd = joystick_nr;
+  }
 #endif
 }
 
 #endif
 }
 
@@ -430,10 +439,6 @@ void InitWindow(int argc, char *argv[])
   gc_values.background = pen_bg;
   gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground;
   gc = XCreateGC(display, window, gc_valuemask, &gc_values);
   gc_values.background = pen_bg;
   gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground;
   gc = XCreateGC(display, window, gc_valuemask, &gc_values);
-
-
-
-  print_debug("OpenWindow finished");
 }
 
 void DrawInitText(char *text, int ypos, int color)
 }
 
 void DrawInitText(char *text, int ypos, int color)
@@ -662,10 +667,6 @@ void LoadGfx(int pos, struct PictureFileInfo *pic)
 
 #endif
 
 
 #endif
 
-
-  print_debug("now load pic:");
-
-
   /* Grafik laden */
   if (pic->picture_filename)
   {
   /* Grafik laden */
   if (pic->picture_filename)
   {
@@ -709,46 +710,26 @@ void LoadGfx(int pos, struct PictureFileInfo *pic)
 
 #else /* !USE_XPM_LIBRARY */
 
 
 #else /* !USE_XPM_LIBRARY */
 
-
-
-    print_debug(filename);
-
-
-
     pcx_err = Read_PCX_to_Pixmap(display, window, gc, filename,
                                 &pix[pos], &clipmask[pos]);
     pcx_err = Read_PCX_to_Pixmap(display, window, gc, filename,
                                 &pix[pos], &clipmask[pos]);
-
-
-    print_debug("ok-1");
-
-
     switch(pcx_err)
     {
       case PCX_Success:
     switch(pcx_err)
     {
       case PCX_Success:
-       print_debug("Success");
         break;
       case PCX_OpenFailed:
         break;
       case PCX_OpenFailed:
-       print_debug("OpenFailed");
         Error(ERR_EXIT, "cannot open PCX file '%s'", filename);
       case PCX_ReadFailed:
         Error(ERR_EXIT, "cannot open PCX file '%s'", filename);
       case PCX_ReadFailed:
-       print_debug("ReadFailed");
         Error(ERR_EXIT, "cannot read PCX file '%s'", filename);
       case PCX_FileInvalid:
         Error(ERR_EXIT, "cannot read PCX file '%s'", filename);
       case PCX_FileInvalid:
-       print_debug("FileInvalid");
        Error(ERR_EXIT, "invalid PCX file '%s'", filename);
       case PCX_NoMemory:
        Error(ERR_EXIT, "invalid PCX file '%s'", filename);
       case PCX_NoMemory:
-       print_debug("NoMemory");
        Error(ERR_EXIT, "not enough memory for PCX file '%s'", filename);
       case PCX_ColorFailed:
        Error(ERR_EXIT, "not enough memory for PCX file '%s'", filename);
       case PCX_ColorFailed:
-       print_debug("ColorFailed");
        Error(ERR_EXIT, "cannot get colors for PCX file '%s'", filename);
       default:
        Error(ERR_EXIT, "cannot get colors for PCX file '%s'", filename);
       default:
-       print_debug("default");
        break;
     }
 
        break;
     }
 
-    print_debug("ok-2");
-
 #if DEBUG_TIMING
     printf("SUMMARY LOADING PCX FILE %s:", filename);
     debug_print_timestamp(1, "");
 #if DEBUG_TIMING
     printf("SUMMARY LOADING PCX FILE %s:", filename);
     debug_print_timestamp(1, "");
@@ -756,16 +737,8 @@ void LoadGfx(int pos, struct PictureFileInfo *pic)
 
 #endif /* !USE_XPM_LIBRARY */
 
 
 #endif /* !USE_XPM_LIBRARY */
 
-
-    print_debug("-> 1");
-
-
-
     if (!pix[pos])
       Error(ERR_EXIT, "cannot get graphics for '%s'", pic->picture_filename);
     if (!pix[pos])
       Error(ERR_EXIT, "cannot get graphics for '%s'", pic->picture_filename);
-
-
-    print_debug("-> 2");
   }
 
   /* zugehörige Maske laden (wenn vorhanden) */
   }
 
   /* zugehörige Maske laden (wenn vorhanden) */
@@ -806,16 +779,9 @@ void LoadGfx(int pos, struct PictureFileInfo *pic)
 
 #endif /* USE_XPM_LIBRARY */
 
 
 #endif /* USE_XPM_LIBRARY */
 
-
-    if (!clipmask[pos])
-      print_debug("Oops -- no clipmask");
-
     if (!clipmask[pos])
       Error(ERR_EXIT, "cannot get clipmask for '%s'", pic->picture_filename);
   }
     if (!clipmask[pos])
       Error(ERR_EXIT, "cannot get clipmask for '%s'", pic->picture_filename);
   }
-
-
-  print_debug("LoadGfx done");
 }
 
 void InitElementProperties()
 }
 
 void InitElementProperties()
@@ -1412,5 +1378,9 @@ void CloseAllAndExit(int exit_value)
     XCloseDisplay(display);
   }
 
     XCloseDisplay(display);
   }
 
+#ifdef MSDOS
+  dumpErrorFile();
+#endif
+
   exit(exit_value);
 }
   exit(exit_value);
 }
index 7240e88cf6bfaac94f88b681b74581cacc3f9086..3982e0a1f74c05d219fc562981c712e43f33ef62 100644 (file)
@@ -64,9 +64,9 @@ static int JoystickPosition(int middle, int margin, int actual)
 }
 #endif
 
 }
 #endif
 
+#ifndef MSDOS
 int Joystick(int player_nr)
 {
 int Joystick(int player_nr)
 {
-#ifndef MSDOS
 #ifdef __FreeBSD__
   struct joystick joy_ctrl;
 #else
 #ifdef __FreeBSD__
   struct joystick joy_ctrl;
 #else
@@ -76,24 +76,22 @@ int Joystick(int player_nr)
     int x;
     int y;
   } joy_ctrl;
     int x;
     int y;
   } joy_ctrl;
-#endif
 #endif
 
   int joystick_fd = stored_player[player_nr].joystick_fd;
 #endif
 
   int joystick_fd = stored_player[player_nr].joystick_fd;
-
-#ifndef MSDOS
   int js_x,js_y, js_b1,js_b2;
   int left, right, up, down;
   int result = 0;
   int js_x,js_y, js_b1,js_b2;
   int left, right, up, down;
   int result = 0;
-#endif
 
   if (joystick_status == JOYSTICK_OFF)
     return 0;
 
 
   if (joystick_status == JOYSTICK_OFF)
     return 0;
 
-  if (!setup.input[player_nr].use_joystick || joystick_fd < 0)
+  if (game_status == SETUPINPUT)
+    return 0;
+
+  if (joystick_fd < 0 || !setup.input[player_nr].use_joystick)
     return 0;
 
     return 0;
 
-#ifndef MSDOS
   if (read(joystick_fd, &joy_ctrl, sizeof(joy_ctrl)) != sizeof(joy_ctrl))
   {
     Error(ERR_WARN, "cannot read joystick device '%s'",
   if (read(joystick_fd, &joy_ctrl, sizeof(joy_ctrl)) != sizeof(joy_ctrl))
   {
     Error(ERR_WARN, "cannot read joystick device '%s'",
@@ -137,33 +135,89 @@ int Joystick(int player_nr)
     result |= JOY_BUTTON_2;
 
   return result;
     result |= JOY_BUTTON_2;
 
   return result;
+}
+
+#else /* MSDOS */
+
+/* allegro global variables for joystick control */
+extern int num_joysticks;
+extern JOYSTICK_INFO joy[];
+
+int Joystick(int player_nr)
+{
+  int joystick_nr = stored_player[player_nr].joystick_fd;
+  int result = 0;
+
+  if (joystick_status == JOYSTICK_OFF)
+    return 0;
+
+  if (game_status == SETUPINPUT)
+    return 0;
+
+  if (joystick_nr < 0)
+    return 0;
+
+  /* the allegro global variable ĂŻnum_joysticksĂŻ contains the number
+     of joysticks found at initialization under MSDOS / Windows */
+
+#if 0
+  if (joystick_nr >= num_joysticks || !setup.input[player_nr].use_joystick)
+    return 0;
+#else
+
+#if 1
+  if (joystick_nr >= num_joysticks ||
+      (game_status == PLAYING && !setup.input[player_nr].use_joystick))
+    return 0;
 #else
 #else
-  return 0;
+  if (joystick_nr >= num_joysticks)
+    return 0;
+#endif
+
 #endif
 #endif
+
+  poll_joystick();
+
+  if (joy[joystick_nr].stick[0].axis[0].d1)
+    result |= JOY_LEFT;
+  else if (joy[joystick_nr].stick[0].axis[0].d2)
+    result |= JOY_RIGHT;
+  if (joy[joystick_nr].stick[0].axis[1].d1)
+    result |= JOY_UP;
+  else if (joy[joystick_nr].stick[0].axis[1].d2)
+    result |= JOY_DOWN;
+
+  if (joy[joystick_nr].button[0].b)
+    result |= JOY_BUTTON_1;
+  if (joy[joystick_nr].button[1].b)
+    result |= JOY_BUTTON_2;
+
+  return result;
 }
 }
+#endif /* MSDOS */
 
 int JoystickButton(int player_nr)
 {
 
 int JoystickButton(int player_nr)
 {
-  static int last_joy_button = 0;
+  static int last_joy_button[MAX_PLAYERS] = { 0, 0, 0, 0 };
   int joy_button = (Joystick(player_nr) & JOY_BUTTON);
   int result;
 
   if (joy_button)
   {
   int joy_button = (Joystick(player_nr) & JOY_BUTTON);
   int result;
 
   if (joy_button)
   {
-    if (last_joy_button)
+    if (last_joy_button[player_nr])
       result = JOY_BUTTON_PRESSED;
     else
       result = JOY_BUTTON_NEW_PRESSED;
   }
   else
   {
       result = JOY_BUTTON_PRESSED;
     else
       result = JOY_BUTTON_NEW_PRESSED;
   }
   else
   {
-    if (last_joy_button)
+    if (last_joy_button[player_nr])
       result = JOY_BUTTON_NEW_RELEASED;
     else
       result = JOY_BUTTON_NOT_PRESSED;
   }
 
       result = JOY_BUTTON_NEW_RELEASED;
     else
       result = JOY_BUTTON_NOT_PRESSED;
   }
 
-  last_joy_button = joy_button;
+  last_joy_button[player_nr] = joy_button;
   return result;
 }
 
   return result;
 }
 
@@ -174,8 +228,12 @@ int AnyJoystick()
 
   for (i=0; i<MAX_PLAYERS; i++)
   {
 
   for (i=0; i<MAX_PLAYERS; i++)
   {
+
+    /*
     if (!setup.input[i].use_joystick)
       continue;
     if (!setup.input[i].use_joystick)
       continue;
+      */
+
 
     result |= Joystick(i);
   }
 
     result |= Joystick(i);
   }
@@ -186,14 +244,23 @@ int AnyJoystick()
 int AnyJoystickButton()
 {
   int i;
 int AnyJoystickButton()
 {
   int i;
-  int result = 0;
+  int result;
 
   for (i=0; i<MAX_PLAYERS; i++)
   {
 
   for (i=0; i<MAX_PLAYERS; i++)
   {
+
+    /*
     if (!setup.input[i].use_joystick)
       continue;
     if (!setup.input[i].use_joystick)
       continue;
+      */
 
 
+    /*
     result |= JoystickButton(i);
     result |= JoystickButton(i);
+    */
+
+    result = JoystickButton(i);
+    if (result != JOY_BUTTON_NOT_PRESSED)
+      break;
   }
 
   return result;
   }
 
   return result;
index 719be55bad4f97fbe1037a1e88e23c7fe9f6cad9..4dc5883b60e36dea7af94eca4275150c9ac543a5 100644 (file)
@@ -1035,16 +1035,17 @@ extern int              num_bg_loops;
 #define FC_SPECIAL2            5
 
 /* values for game_status */
 #define FC_SPECIAL2            5
 
 /* values for game_status */
-#define MAINMENU               0
-#define PLAYING                        1
-#define LEVELED                        2
-#define HELPSCREEN             3
-#define CHOOSELEVEL            4
-#define TYPENAME               5
-#define HALLOFFAME             6
-#define SETUP                  7
-#define SETUPINPUT             8
-#define EXITGAME               9
+#define EXITGAME               0
+#define MAINMENU               1
+#define PLAYING                        2
+#define LEVELED                        3
+#define HELPSCREEN             4
+#define CHOOSELEVEL            5
+#define TYPENAME               6
+#define HALLOFFAME             7
+#define SETUP                  8
+#define SETUPINPUT             9
+#define CALIBRATION            10
 
 #ifndef GAME_DIR
 #define GAME_DIR               "."
 
 #ifndef GAME_DIR
 #define GAME_DIR               "."
index 19c90ac508010a6cc72d3b5c9a30e104294bceda..2d7e7f1f6c106e8ce6971fb2eb9ddacb409d6c8e 100644 (file)
@@ -26,7 +26,7 @@
 #include "sound.h"
 #include "random.h"
 #include "joystick.h"
 #include "sound.h"
 #include "random.h"
 #include "joystick.h"
-
+#include "files.h"
 
 #ifdef MSDOS
 volatile unsigned long counter = 0;
 
 #ifdef MSDOS
 volatile unsigned long counter = 0;
@@ -457,6 +457,15 @@ void GetOptions(char *argv[])
 void Error(int mode, char *format, ...)
 {
   char *process_name = "";
 void Error(int mode, char *format, ...)
 {
   char *process_name = "";
+  FILE *error = stderr;
+
+#ifdef MSDOS
+  if ((error = openErrorFile()) == NULL)
+  {
+    printf("Cannot write to error output file!\n");
+    CloseAllAndExit(1);
+  }
+#endif
 
   if (mode & ERR_SOUND_SERVER)
     process_name = " sound server";
 
   if (mode & ERR_SOUND_SERVER)
     process_name = " sound server";
@@ -469,26 +478,30 @@ void Error(int mode, char *format, ...)
   {
     va_list ap;
 
   {
     va_list ap;
 
-    fprintf(stderr, "%s%s: ", program_name, process_name);
+    fprintf(error, "%s%s: ", program_name, process_name);
 
     if (mode & ERR_WARN)
 
     if (mode & ERR_WARN)
-      fprintf(stderr, "warning: ");
+      fprintf(error, "warning: ");
 
     va_start(ap, format);
 
     va_start(ap, format);
-    vfprintf(stderr, format, ap);
+    vfprintf(error, format, ap);
     va_end(ap);
   
     va_end(ap);
   
-    fprintf(stderr, "\n");
+    fprintf(error, "\n");
   }
   
   if (mode & ERR_HELP)
   }
   
   if (mode & ERR_HELP)
-    fprintf(stderr, "%s: Try option '--help' for more information.\n",
+    fprintf(error, "%s: Try option '--help' for more information.\n",
            program_name);
 
   if (mode & ERR_EXIT)
            program_name);
 
   if (mode & ERR_EXIT)
-  {
-    fprintf(stderr, "%s%s: aborting\n", program_name, process_name);
+    fprintf(error, "%s%s: aborting\n", program_name, process_name);
+
+  if (error != stderr)
+    fclose(error);
 
 
+  if (mode & ERR_EXIT)
+  {
     if (mode & ERR_FROM_SERVER)
       exit(1);                         /* child process: normal exit */
     else
     if (mode & ERR_FROM_SERVER)
       exit(1);                         /* child process: normal exit */
     else
@@ -587,9 +600,15 @@ void translate_keyname(KeySym *keysym, char **x11name, char **name, int mode)
     { XK_apostrophe,   "XK_apostrophe",        "'" },
     { XK_plus,         "XK_plus",              "+" },
     { XK_minus,                "XK_minus",             "-" },
     { XK_apostrophe,   "XK_apostrophe",        "'" },
     { XK_plus,         "XK_plus",              "+" },
     { XK_minus,                "XK_minus",             "-" },
+    { XK_equal,                "XK_equal",             "equal" },
     { XK_comma,                "XK_comma",             "," },
     { XK_period,       "XK_period",            "." },
     { XK_comma,                "XK_comma",             "," },
     { XK_period,       "XK_period",            "." },
+    { XK_colon,                "XK_colon",             ";" },
+    { XK_slash,                "XK_slash",             "/" },
     { XK_numbersign,   "XK_numbersign",        "#" },
     { XK_numbersign,   "XK_numbersign",        "#" },
+    { XK_backslash,    "XK_backslash",         "backslash" },
+    { XK_braceleft,    "XK_braceleft",         "brace left" },
+    { XK_braceright,   "XK_braceright",        "brace right" },
     { XK_less,         "XK_less",              "less" },
     { XK_greater,      "XK_greater",           "greater" },
     { XK_asciicircum,  "XK_asciicircum",       "circumflex" },
     { XK_less,         "XK_less",              "less" },
     { XK_greater,      "XK_greater",           "greater" },
     { XK_asciicircum,  "XK_asciicircum",       "circumflex" },
@@ -849,7 +868,29 @@ int getJoySymbolFromJoyName(char *name)
   return joysymbol;
 }
 
   return joysymbol;
 }
 
+int getJoystickNrFromDeviceName(char *device_name)
+{
+  char c;
+  int joystick_nr = 0;
+
+  if (device_name == NULL || device_name[0] == '\0')
+    return 0;
+
+  c = device_name[strlen(device_name) - 1];
+
+  if (c >= '0' && c <= '9')
+    joystick_nr = (int)(c - '0');
+
+  if (joystick_nr < 0 || joystick_nr >= MAX_PLAYERS)
+    joystick_nr = 0;
+
+  return joystick_nr;
+}
+
+/* ----------------------------------------------------------------- */
 /* the following is only for debugging purpose and normally not used */
 /* the following is only for debugging purpose and normally not used */
+/* ----------------------------------------------------------------- */
+
 #define DEBUG_NUM_TIMESTAMPS   3
 
 void debug_print_timestamp(int counter_nr, char *message)
 #define DEBUG_NUM_TIMESTAMPS   3
 
 void debug_print_timestamp(int counter_nr, char *message)
@@ -867,28 +908,3 @@ void debug_print_timestamp(int counter_nr, char *message)
 
   counter[counter_nr][1] = Counter();
 }
 
   counter[counter_nr][1] = Counter();
 }
-
-void print_debug(char *s)
-{
-  FILE *f;
-
-  if (!s)
-  {
-    if ((f = fopen("debug.asc", "w")) == NULL)
-    {
-      printf("Cannot write to debug file!\n");
-      exit(1);
-    }
-    fclose(f);
-    return;
-  }
-
-  if ((f = fopen("debug.asc", "a")) == NULL)
-  {
-    printf("Cannot append to debug file!\n");
-    exit(1);
-  }
-
-  fprintf(f, "%s\r\n", s);
-  fclose(f);
-}
index 1477f85d76c4a5984434ef643ce15a1a4c385a8a..ae8ae79e9ad85e266d8778c503a43e25d735d5d7 100644 (file)
@@ -60,8 +60,9 @@ char *getX11KeyNameFromKeySym(KeySym);
 KeySym getKeySymFromX11KeyName(char *);
 char *getJoyNameFromJoySymbol(int);
 int getJoySymbolFromJoyName(char *);
 KeySym getKeySymFromX11KeyName(char *);
 char *getJoyNameFromJoySymbol(int);
 int getJoySymbolFromJoyName(char *);
-void debug_print_timestamp(int, char *);
+int getJoystickNrFromDeviceName(char *);
 
 
+void debug_print_timestamp(int, char *);
 void print_debug(char *);
 
 #endif /* MISC_H */
 void print_debug(char *);
 
 #endif /* MISC_H */
index f1dcfa473686ba19765dfae70497bd6021a702b9..6c6c525ca7c42949fea52af7a4a435c403a5303a 100644 (file)
 #ifdef MSDOS
 
 #include "main.h"
 #ifdef MSDOS
 
 #include "main.h"
+#include "misc.h"
 #include "tools.h"
 #include "sound.h"
 #include "files.h"
 #include "joystick.h"
 #include "image.h"
 
 #include "tools.h"
 #include "sound.h"
 #include "files.h"
 #include "joystick.h"
 #include "image.h"
 
+/* allegro driver declarations */
 DECLARE_GFX_DRIVER_LIST(GFX_DRIVER_VBEAF GFX_DRIVER_VESA2L GFX_DRIVER_VESA1)
 DECLARE_COLOR_DEPTH_LIST(COLOR_DEPTH_8)
 DECLARE_DIGI_DRIVER_LIST(DIGI_DRIVER_SB)
 DECLARE_MIDI_DRIVER_LIST()
 DECLARE_JOYSTICK_DRIVER_LIST(JOYSTICK_DRIVER_STANDARD)
 
 DECLARE_GFX_DRIVER_LIST(GFX_DRIVER_VBEAF GFX_DRIVER_VESA2L GFX_DRIVER_VESA1)
 DECLARE_COLOR_DEPTH_LIST(COLOR_DEPTH_8)
 DECLARE_DIGI_DRIVER_LIST(DIGI_DRIVER_SB)
 DECLARE_MIDI_DRIVER_LIST()
 DECLARE_JOYSTICK_DRIVER_LIST(JOYSTICK_DRIVER_STANDARD)
 
-static int key_buffer[OSD_MAX_KEY];
+/* allegro global variables */
+extern volatile int key_shifts;
+extern int num_joysticks;
+extern JOYSTICK_INFO joy[];
+extern int i_love_bill;
+
+/* internal variables of msdos.c */
+static int key_press_state[MAX_SCANCODES];
 static XEvent event_buffer[MAX_EVENT_BUFFER];
 static int pending_events;
 static boolean joystick_event;
 static XEvent event_buffer[MAX_EVENT_BUFFER];
 static int pending_events;
 static boolean joystick_event;
@@ -54,22 +63,24 @@ static void allegro_drivers()
 
   for (i=0; i<MAX_EVENT_BUFFER; i++)
     event_buffer[i].type = 0;
 
   for (i=0; i<MAX_EVENT_BUFFER; i++)
     event_buffer[i].type = 0;
-  for(i=0; i<OSD_MAX_KEY; i++)
-    key_buffer[i] = KeyReleaseMask;
+
+  for (i=0; i<MAX_SCANCODES; i++)
+    key_press_state[i] = KeyReleaseMask;
+
   last_mouse_pos = mouse_pos;
   last_mouse_b = 0;
 
   pending_events = 0;
   clear_keybuf();
 
   last_mouse_pos = mouse_pos;
   last_mouse_b = 0;
 
   pending_events = 0;
   clear_keybuf();
 
+  /* enable Windows friendly timer mode (already default under Windows) */
   i_love_bill = TRUE;
   i_love_bill = TRUE;
+
   install_keyboard();
   install_timer();
   if (install_mouse() > 0)
     mouse_installed = TRUE;
   install_keyboard();
   install_timer();
   if (install_mouse() > 0)
     mouse_installed = TRUE;
-  install_joystick(JOY_TYPE_2PADS);
 
 
-  load_joystick_data(JOYSTICK_FILENAME);
   last_joystick_state = 0;
   joystick_event = FALSE;
 
   last_joystick_state = 0;
   joystick_event = FALSE;
 
@@ -98,131 +109,124 @@ static void unhide_mouse(Display *display)
     show_mouse(video_bitmap);
 }
 
     show_mouse(video_bitmap);
 }
 
-static int get_joystick_state()
+static KeySym ScancodeToKeySym(byte scancode)
 {
 {
-  int state = 0;
-
-  /*!!!*/
-  int joystick_nr = 0; /* CHANGE THIS! */
-  /*!!!*/
-
-  poll_joystick();
-
-  if (joy[joystick_nr].stick[0].axis[0].d1)
-    state |= JOY_LEFT;
-  if (joy[joystick_nr].stick[0].axis[0].d2)
-    state |= JOY_RIGHT;
-  if (joy[joystick_nr].stick[0].axis[1].d1)
-    state |= JOY_UP;
-  if (joy[joystick_nr].stick[0].axis[1].d2)
-    state |= JOY_DOWN;
-  if (joy[joystick_nr].button[0].b)
-    state |= JOY_BUTTON_1;
-
-  switch (state)
+  switch(scancode)
   {
   {
-    case (JOY_DOWN | JOY_LEFT):
-      state = XK_KP_1;
-      break;
-    case (JOY_DOWN):
-      state = XK_KP_2;
-      break;
-    case (JOY_DOWN | JOY_RIGHT):
-      state = XK_KP_3;
-      break;
-    case (JOY_LEFT):
-      state = XK_KP_4;
-      break;
-    case (JOY_RIGHT):
-      state = XK_KP_6;
-      break;
-    case (JOY_UP | JOY_LEFT):
-      state = XK_KP_7;
-      break;
-    case (JOY_UP):
-      state = XK_KP_8;
-      break;
-    case (JOY_UP | JOY_RIGHT):
-      state = XK_KP_9;
-      break;
-
-    case (JOY_DOWN | JOY_BUTTON_1):
-      state = XK_X;
-      break;
-    case (JOY_LEFT | JOY_BUTTON_1):
-      state = XK_S;
-      break;
-    case (JOY_RIGHT | JOY_BUTTON_1):
-      state = XK_D;
-      break;
-    case (JOY_UP | JOY_BUTTON_1):
-      state = XK_E;
-      break;
-   default:
-     state = 0;
+    case KEY_ESC:              return XK_Escape;
+    case KEY_1:                        return XK_1;
+    case KEY_2:                        return XK_2;
+    case KEY_3:                        return XK_3;
+    case KEY_4:                        return XK_4;
+    case KEY_5:                        return XK_5;
+    case KEY_6:                        return XK_6;
+    case KEY_7:                        return XK_7;
+    case KEY_8:                        return XK_8;
+    case KEY_9:                        return XK_9;
+    case KEY_0:                        return XK_0;
+    case KEY_MINUS:            return XK_minus;
+    case KEY_EQUALS:           return XK_equal;
+    case KEY_BACKSPACE:                return XK_BackSpace;
+    case KEY_TAB:              return XK_Tab;
+    case KEY_Q:                        return XK_q;
+    case KEY_W:                        return XK_w;
+    case KEY_E:                        return XK_e;
+    case KEY_R:                        return XK_r;
+    case KEY_T:                        return XK_t;
+    case KEY_Y:                        return XK_y;
+    case KEY_U:                        return XK_u;
+    case KEY_I:                        return XK_i;
+    case KEY_O:                        return XK_o;
+    case KEY_P:                        return XK_p;
+    case KEY_OPENBRACE:                return XK_braceleft;
+    case KEY_CLOSEBRACE:       return XK_braceright;
+    case KEY_ENTER:            return XK_Return;
+    case KEY_LCONTROL:         return XK_Control_L;
+    case KEY_A:                        return XK_a;
+    case KEY_S:                        return XK_s;
+    case KEY_D:                        return XK_d;
+    case KEY_F:                        return XK_f;
+    case KEY_G:                        return XK_g;
+    case KEY_H:                        return XK_h;
+    case KEY_J:                        return XK_j;
+    case KEY_K:                        return XK_k;
+    case KEY_L:                        return XK_l;
+    case KEY_COLON:            return XK_colon;
+    case KEY_QUOTE:            return XK_apostrophe;
+    case KEY_TILDE:            return XK_asciitilde;
+    case KEY_LSHIFT:           return XK_Shift_L;
+    case KEY_BACKSLASH:                return XK_backslash;
+    case KEY_Z:                        return XK_z;
+    case KEY_X:                        return XK_x;
+    case KEY_C:                        return XK_c;
+    case KEY_V:                        return XK_v;
+    case KEY_B:                        return XK_b;
+    case KEY_N:                        return XK_n;
+    case KEY_M:                        return XK_m;
+    case KEY_COMMA:            return XK_comma;
+    case KEY_STOP:             return XK_period;
+    case KEY_SLASH:            return XK_slash;
+    case KEY_RSHIFT:           return XK_Shift_R;
+    case KEY_ASTERISK:         return XK_KP_Multiply;
+    case KEY_ALT:              return XK_Alt_L;
+    case KEY_SPACE:            return XK_space;
+    case KEY_CAPSLOCK:         return XK_Caps_Lock;
+    case KEY_F1:               return XK_F1;
+    case KEY_F2:               return XK_F2;
+    case KEY_F3:               return XK_F3;
+    case KEY_F4:               return XK_F4;
+    case KEY_F5:               return XK_F5;
+    case KEY_F6:               return XK_F6;
+    case KEY_F7:               return XK_F7;
+    case KEY_F8:               return XK_F8;
+    case KEY_F9:               return XK_F9;
+    case KEY_F10:              return XK_F10;
+    case KEY_NUMLOCK:          return XK_Num_Lock;
+    case KEY_SCRLOCK:          return XK_Scroll_Lock;
+    case KEY_HOME:             return XK_Home;
+    case KEY_UP:               return XK_Up;
+    case KEY_PGUP:             return XK_Page_Up;
+    case KEY_MINUS_PAD:                return XK_KP_Subtract;
+    case KEY_LEFT:             return XK_Left;
+    case KEY_5_PAD:            return XK_KP_5;
+    case KEY_RIGHT:            return XK_Right;
+    case KEY_PLUS_PAD:         return XK_KP_Add;
+    case KEY_END:              return XK_End;
+    case KEY_DOWN:             return XK_Down;
+    case KEY_PGDN:             return XK_Page_Down;
+    case KEY_INSERT:           return XK_Insert;
+    case KEY_DEL:              return XK_Delete;
+    case KEY_PRTSCR:           return XK_Print;
+    case KEY_F11:              return XK_F11;
+    case KEY_F12:              return XK_F12;
+    case KEY_LWIN:             return XK_Meta_L;
+    case KEY_RWIN:             return XK_Meta_R;
+    case KEY_MENU:             return XK_Menu;
+    case KEY_PAD:              return XK_VoidSymbol;
+    case KEY_RCONTROL:         return XK_Control_R;
+    case KEY_ALTGR:            return XK_Alt_R;
+    case KEY_SLASH2:           return XK_KP_Divide;
+    case KEY_PAUSE:            return XK_Pause;
+
+    case NEW_KEY_BACKSLASH:    return XK_backslash;
+    case NEW_KEY_1_PAD:                return XK_KP_1;
+    case NEW_KEY_2_PAD:                return XK_KP_2;
+    case NEW_KEY_3_PAD:                return XK_KP_3;
+    case NEW_KEY_4_PAD:                return XK_KP_4;
+    case NEW_KEY_5_PAD:                return XK_KP_5;
+    case NEW_KEY_6_PAD:                return XK_KP_6;
+    case NEW_KEY_7_PAD:                return XK_KP_7;
+    case NEW_KEY_8_PAD:                return XK_KP_8;
+    case NEW_KEY_9_PAD:                return XK_KP_9;
+    case NEW_KEY_0_PAD:                return XK_KP_0;
+    case NEW_KEY_STOP_PAD:     return XK_KP_Separator;
+    case NEW_KEY_EQUALS_PAD:   return XK_KP_Equal;
+    case NEW_KEY_SLASH_PAD:    return XK_KP_Divide;
+    case NEW_KEY_ASTERISK_PAD: return XK_KP_Multiply;
+    case NEW_KEY_ENTER_PAD:    return XK_KP_Enter;
+
+    default:                   return XK_VoidSymbol;
   }
   }
-
-  return state;
-}
-
-unsigned char get_ascii(KeySym key)
-{
-  switch(key)
-  {
-    case OSD_KEY_Q: return 'Q';
-    case OSD_KEY_W: return 'W';
-    case OSD_KEY_E: return 'E';
-    case OSD_KEY_R: return 'R';
-    case OSD_KEY_T: return 'T';
-    case OSD_KEY_Y: return 'Y';
-    case OSD_KEY_U: return 'U';
-    case OSD_KEY_I: return 'I';
-    case OSD_KEY_O: return 'O';
-    case OSD_KEY_P: return 'P';
-    case OSD_KEY_A: return 'A';
-    case OSD_KEY_S: return 'S';
-    case OSD_KEY_D: return 'D';
-    case OSD_KEY_F: return 'F';
-    case OSD_KEY_G: return 'G';
-    case OSD_KEY_H: return 'H';
-    case OSD_KEY_J: return 'J';
-    case OSD_KEY_K: return 'K';
-    case OSD_KEY_L: return 'L';
-    case OSD_KEY_Z: return 'Z';
-    case OSD_KEY_X: return 'X';
-    case OSD_KEY_C: return 'C';
-    case OSD_KEY_V: return 'V';
-    case OSD_KEY_B: return 'B';
-    case OSD_KEY_N: return 'N';
-    case OSD_KEY_M: return 'M';
-    case OSD_KEY_1: return '1';
-    case OSD_KEY_2: return '2';
-    case OSD_KEY_3: return '3';
-    case OSD_KEY_4: return '4';
-    case OSD_KEY_5: return '5';
-    case OSD_KEY_6: return '6';
-    case OSD_KEY_7: return '7';
-    case OSD_KEY_8: return '8';
-    case OSD_KEY_9: return '9';
-    case OSD_KEY_0: return '0';
-    case OSD_KEY_SPACE: return ' ';
-  }
-
-  return 0;
-}
-
-static long osd_key_pressed(int keycode)
-{
-  if (keycode == OSD_KEY_RCONTROL)
-    keycode = KEY_RCONTROL;
-  if (keycode == OSD_KEY_ALTGR)
-    keycode = KEY_ALTGR;
-
-  if (key[keycode])
-    return KeyPressMask;
-  else
-    return KeyReleaseMask;
 }
 
 void XMapWindow(Display *display, Window window)
 }
 
 void XMapWindow(Display *display, Window window)
@@ -248,13 +252,20 @@ Display *XOpenDisplay(char *display_name)
   Screen *screen;
   Display *display;
   BITMAP *mouse_bitmap = NULL;
   Screen *screen;
   Display *display;
   BITMAP *mouse_bitmap = NULL;
+  char *filename;
 
 
-  screen = malloc(sizeof(Screen));
-  display = malloc(sizeof(Display));
+  filename = getPath3(options.base_directory, GRAPHICS_DIRECTORY,
+                     MOUSE_FILENAME);
+
+  mouse_bitmap = Read_PCX_to_AllegroBitmap(filename);
+  free(filename);
 
 
-  if ((mouse_bitmap = Read_PCX_to_AllegroBitmap(MOUSE_PCX_FILENAME)) == NULL)
+  if (mouse_bitmap == NULL)
     return NULL;
 
     return NULL;
 
+  screen = malloc(sizeof(Screen));
+  display = malloc(sizeof(Display));
+
   screen[0].cmap = 0;
   screen[0].root = 0;
   screen[0].white_pixel = 0xFF;
   screen[0].cmap = 0;
   screen[0].root = 0;
   screen[0].white_pixel = 0xFF;
@@ -292,6 +303,7 @@ Window XCreateSimpleWindow(Display *display, Window parent, int x, int y,
   display->screens[display->default_screen].height = YRES;
 
   set_mouse_sprite(display->mouse_ptr);
   display->screens[display->default_screen].height = YRES;
 
   set_mouse_sprite(display->mouse_ptr);
+  set_mouse_speed(1, 1);
   set_mouse_range(display->screens[display->default_screen].x + 1,
                  display->screens[display->default_screen].y + 1,
                  display->screens[display->default_screen].x + WIN_XSIZE + 1,
   set_mouse_range(display->screens[display->default_screen].x + 1,
                  display->screens[display->default_screen].y + 1,
                  display->screens[display->default_screen].x + WIN_XSIZE + 1,
@@ -585,10 +597,15 @@ void XCloseDisplay(Display *display)
 
   if (is_screen_bitmap(bitmap))
     destroy_bitmap(bitmap);
 
   if (is_screen_bitmap(bitmap))
     destroy_bitmap(bitmap);
+
   if (display->screens)
     free(display->screens);
   if (display->screens)
     free(display->screens);
+
   if (display)
     free(display);
   if (display)
     free(display);
+
+  /* return to text mode (or DOS box on Windows screen) */
+  set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
 }
 
 void XNextEvent(Display *display, XEvent *event_return)
 }
 
 void XNextEvent(Display *display, XEvent *event_return)
@@ -600,77 +617,115 @@ void XNextEvent(Display *display, XEvent *event_return)
   pending_events--;
 }
 
   pending_events--;
 }
 
-int XPending(Display *display)
+static void NewKeyEvent(int key_press_state, KeySym keysym)
 {
 {
-  int i, state;
-  static boolean joy_button_2 = FALSE;
+  XKeyEvent *xkey;
 
 
-  /*!!!*/
-  int joystick_nr = 0; /* CHANGE THIS! */
-  /*!!!*/
+  if (pending_events >= MAX_EVENT_BUFFER)
+    return;
 
 
-  XKeyEvent *xkey;
-  XButtonEvent *xbutton;
-  XMotionEvent *xmotion;
+  pending_events++;
+  xkey = (XKeyEvent *)&event_buffer[pending_events];
+  xkey->type = key_press_state;
+  xkey->state = (unsigned int)keysym;
+}
 
 
-  /* joystick event (simulating keyboard event) */
+#define HANDLE_RAW_KB_ALL_KEYS         0
+#define HANDLE_RAW_KB_MODIFIER_KEYS_ONLY       1
 
 
-  state = get_joystick_state();
+static int modifier_scancode[] =
+{
+  KEY_LSHIFT,
+  KEY_RSHIFT,
+  KEY_LCONTROL,
+  KEY_RCONTROL,
+  KEY_ALT,
+  KEY_ALTGR,
+  KEY_LWIN,
+  KEY_RWIN,
+  KEY_CAPSLOCK,
+  KEY_NUMLOCK,
+  KEY_SCRLOCK,
+  -1
+};
+
+static void HandleKeyboardRaw(int mode)
+{
+  int i;
 
 
-  if (joy[joystick_nr].button[1].b && !joy_button_2)
-  {
-    pending_events++;
-    xkey = (XKeyEvent *)&event_buffer[pending_events];
-    xkey->type = KeyPress;
-    xkey->state = XK_B;
-    joy_button_2 = TRUE;
-  }
-  else if (!joy[joystick_nr].button[1].b && joy_button_2)
+  for (i=0; i<MAX_SCANCODES; i++)
   {
   {
-    pending_events++;
-    xkey = (XKeyEvent *)&event_buffer[pending_events];
-    xkey->type = KeyRelease;
-    xkey->state = XK_B;
-    joy_button_2 = FALSE;
-  }
+    int scancode, new_state, event_type;
+    char key_pressed;
 
 
-  if (state && !joystick_event)
-  {
-    pending_events++;
-    xkey = (XKeyEvent *)&event_buffer[pending_events];
-    xkey->type = KeyPress;
-    xkey->state = state;
-    joystick_event = TRUE;
-    last_joystick_state = state;
-  }
-  else if ((state != last_joystick_state) && joystick_event)
-  {
-    pending_events++;
-    xkey = (XKeyEvent *)&event_buffer[pending_events];
-    xkey->type = KeyRelease;
-    xkey->state = last_joystick_state;
-    joystick_event = FALSE;
-  }
+    if (mode == HANDLE_RAW_KB_MODIFIER_KEYS_ONLY)
+    {
+      if ((scancode = modifier_scancode[i]) == -1)
+       return;
+    }
+    else
+      scancode = i;
 
 
-  /* keyboard event */
+    key_pressed = key[scancode];
+    new_state = (key_pressed ? KeyPressMask : KeyReleaseMask);
+    event_type = (key_pressed ? KeyPress : KeyRelease);
+
+    if (key_press_state[i] == new_state)       /* state not changed */
+      continue;
+
+    key_press_state[i] = new_state;
 
 
-  for(i=0; i<OSD_MAX_KEY+1 && pending_events<MAX_EVENT_BUFFER; i++)
+    NewKeyEvent(event_type, ScancodeToKeySym(scancode));
+  }
+}
+
+static void HandleKeyboardEvent()
+{
+  if (keypressed())
   {
   {
-    state = osd_key_pressed(i);
+    int key_info = readkey();
+    int scancode = (key_info >> 8);
+    int ascii = (key_info & 0xff);
+    KeySym keysym = ScancodeToKeySym(scancode);
 
 
-    if (state != key_buffer[i])
+    if (scancode == KEY_PAD)
     {
     {
-      key_buffer[i] = state;
-      pending_events++;
-      xkey = (XKeyEvent *)&event_buffer[pending_events];
-      xkey->type = (state & KeyPressMask ? KeyPress : KeyRelease);
-      xkey->state = i;
+      /* keys on the numeric keypad return just scancode 'KEY_PAD'
+        for some reason, so we must handle them separately */
+
+      if (ascii >= '0' && ascii <= '9')
+       keysym = XK_KP_0 + (KeySym)(ascii - '0');
+      else if (ascii == '.')
+       keysym = XK_KP_Separator;
     }
     }
+
+    NewKeyEvent(KeyPress, keysym);
   }
   }
+  else if (key_shifts & (KB_SHIFT_FLAG | KB_CTRL_FLAG | KB_ALT_FLAG))
+  {
+    /* the allegro function keypressed() does not give us single pressed
+       modifier keys, so we must detect them with the internal global
+       allegro variable 'key_shifts' and then handle them separately */
 
 
-  /* mouse motion event */
+    HandleKeyboardRaw(HANDLE_RAW_KB_MODIFIER_KEYS_ONLY);
+  }
+}
+
+int XPending(Display *display)
+{
+  XButtonEvent *xbutton;
+  XMotionEvent *xmotion;
+  int i;
 
 
-  if (mouse_pos != last_mouse_pos && mouse_b != last_mouse_b)
+  /* keyboard event */
+  if (game_status == PLAYING)
+    HandleKeyboardRaw(HANDLE_RAW_KB_ALL_KEYS);
+  else
+    HandleKeyboardEvent();
+
+  /* mouse motion event */
+  /* generate mouse motion event only if any mouse buttons are pressed */
+  if (mouse_pos != last_mouse_pos && mouse_b)
   {
     last_mouse_pos = mouse_pos;
     pending_events++;
   {
     last_mouse_pos = mouse_pos;
     pending_events++;
@@ -678,19 +733,12 @@ int XPending(Display *display)
     xmotion->type = MotionNotify;
     xmotion->x = mouse_x - display->screens[display->default_screen].x;
     xmotion->y = mouse_y - display->screens[display->default_screen].y;
     xmotion->type = MotionNotify;
     xmotion->x = mouse_x - display->screens[display->default_screen].x;
     xmotion->y = mouse_y - display->screens[display->default_screen].y;
-
-
-    /*
-    return;
-    */
-
   }
 
   /* mouse button event */
   }
 
   /* mouse button event */
-
   if (mouse_b != last_mouse_b)
   {
   if (mouse_b != last_mouse_b)
   {
-    for(i=1; i<4; i<<=1)
+    for (i=1; i<4; i<<=1)
     {
       if ((last_mouse_b & i) != (mouse_b & i))
       {
     {
       if ((last_mouse_b & i) != (mouse_b & i))
       {
@@ -722,7 +770,7 @@ void sound_handler(struct SoundControl snd_ctrl)
     if (!playing_sounds)
       return;
 
     if (!playing_sounds)
       return;
 
-    for(i=0; i<MAX_SOUNDS_PLAYING; i++)
+    for (i=0; i<MAX_SOUNDS_PLAYING; i++)
       if ((snd_ctrl.stop_all_sounds || playlist[i].nr == snd_ctrl.nr) &&
          !playlist[i].fade_sound)
       {
       if ((snd_ctrl.stop_all_sounds || playlist[i].nr == snd_ctrl.nr) &&
          !playlist[i].fade_sound)
       {
@@ -745,7 +793,7 @@ void sound_handler(struct SoundControl snd_ctrl)
     SoundServer_StopSound(snd_ctrl.nr);
   }
 
     SoundServer_StopSound(snd_ctrl.nr);
   }
 
-  for(i=0; i<MAX_SOUNDS_PLAYING; i++)
+  for (i=0; i<MAX_SOUNDS_PLAYING; i++)
   {
     if (!playlist[i].active || playlist[i].loop)
       continue;
   {
     if (!playlist[i].active || playlist[i].loop)
       continue;
@@ -766,7 +814,7 @@ void sound_handler(struct SoundControl snd_ctrl)
 
 void NetworkServer(int port, int serveronly)
 {
 
 void NetworkServer(int port, int serveronly)
 {
-  printf("Sorry, networking not supported in DOS version.\n");
+  Error(ERR_WARN, "networking not supported in DOS version");
 }
 
 #endif /* MSDOS */
 }
 
 #endif /* MSDOS */
index 4db6cf8b28961610a0529ac0af927eae2d946296..c344414ed379eeeffb461de91d0d437e2016fbbc 100644 (file)
 #include <allegro.h>
 #include <time.h>
 
 #include <allegro.h>
 #include <time.h>
 
+/* allegro defines TRUE as -1 */
+#ifdef TRUE
+#undef TRUE
+#undef FALSE
+#endif
+
+#define TRUE   1
+#define FALSE  0
+
 #define XRES   800
 #define YRES   600
 
 #define XRES   800
 #define YRES   600
 
-/* Allegro keyboard mapping */
-
-#define OSD_KEY_ESC         1        /* keyboard scan codes */
-#define OSD_KEY_1           2        /* (courtesy of allegro.h) */
-#define OSD_KEY_2           3
-#define OSD_KEY_3           4
-#define OSD_KEY_4           5
-#define OSD_KEY_5           6
-#define OSD_KEY_6           7
-#define OSD_KEY_7           8
-#define OSD_KEY_8           9
-#define OSD_KEY_9           10
-#define OSD_KEY_0           11
-#define OSD_KEY_MINUS       12
-#define OSD_KEY_EQUALS      13
-#define OSD_KEY_BACKSPACE   14
-#define OSD_KEY_TAB         15
-#define OSD_KEY_Q           16
-#define OSD_KEY_W           17
-#define OSD_KEY_E           18
-#define OSD_KEY_R           19
-#define OSD_KEY_T           20
-#define OSD_KEY_Y           21
-#define OSD_KEY_U           22
-#define OSD_KEY_I           23
-#define OSD_KEY_O           24
-#define OSD_KEY_P           25
-#define OSD_KEY_OPENBRACE   26
-#define OSD_KEY_CLOSEBRACE  27
-#define OSD_KEY_ENTER       28
-#define OSD_KEY_LCONTROL    29
-#define OSD_KEY_A           30
-#define OSD_KEY_S           31
-#define OSD_KEY_D           32
-#define OSD_KEY_F           33
-#define OSD_KEY_G           34
-#define OSD_KEY_H           35
-#define OSD_KEY_J           36
-#define OSD_KEY_K           37
-#define OSD_KEY_L           38
-#define OSD_KEY_COLON       39
-#define OSD_KEY_QUOTE       40
-#define OSD_KEY_TILDE       41
-#define OSD_KEY_LSHIFT      42
-/* 43 */
-#define OSD_KEY_Z           44
-#define OSD_KEY_X           45
-#define OSD_KEY_C           46
-#define OSD_KEY_V           47
-#define OSD_KEY_B           48
-#define OSD_KEY_N           49
-#define OSD_KEY_M           50
-#define OSD_KEY_COMMA       51
-#define OSD_KEY_STOP        52
-#define OSD_KEY_SLASH       53
-#define OSD_KEY_RSHIFT      54
-#define OSD_KEY_ASTERISK    55
-#define OSD_KEY_ALT         56
-#define OSD_KEY_SPACE       57
-#define OSD_KEY_CAPSLOCK    58
-#define OSD_KEY_F1          59
-#define OSD_KEY_F2          60
-#define OSD_KEY_F3          61
-#define OSD_KEY_F4          62
-#define OSD_KEY_F5          63
-#define OSD_KEY_F6          64
-#define OSD_KEY_F7          65
-#define OSD_KEY_F8          66
-#define OSD_KEY_F9          67
-#define OSD_KEY_F10         68
-#define OSD_KEY_NUMLOCK     69
-#define OSD_KEY_SCRLOCK     70
-#define OSD_KEY_HOME        71
-#define OSD_KEY_UP          72
-#define OSD_KEY_PGUP        73
-#define OSD_KEY_MINUS_PAD   74
-#define OSD_KEY_LEFT        75
-#define OSD_KEY_5_PAD       76
-#define OSD_KEY_RIGHT       77
-#define OSD_KEY_PLUS_PAD    78
-#define OSD_KEY_END         79
-#define OSD_KEY_DOWN        80
-#define OSD_KEY_PGDN        81
-#define OSD_KEY_INSERT      82
-#define OSD_KEY_DEL         83
-#define OSD_KEY_RCONTROL    84  /* different from Allegro */
-#define OSD_KEY_ALTGR       85  /* different from Allegro */
-/* 86 */
-#define OSD_KEY_F11         87
-#define OSD_KEY_F12         88
-#define OSD_KEY_COMMAND     89
-#define OSD_KEY_OPTION      90
-/* 91 - 100 */
+/* additional Allegro keyboard mapping */
+
 /* The following are all undefined in Allegro */
 /* The following are all undefined in Allegro */
-#define OSD_KEY_1_PAD          101
-#define OSD_KEY_2_PAD          102
-#define OSD_KEY_3_PAD          103
-#define OSD_KEY_4_PAD          104
-/* 105 */
-#define OSD_KEY_6_PAD          106
-#define OSD_KEY_7_PAD          107
-#define OSD_KEY_8_PAD          108
-#define OSD_KEY_9_PAD          109
-#define OSD_KEY_0_PAD          110
-#define OSD_KEY_STOP_PAD       111
-#define OSD_KEY_EQUALS_PAD     112
-#define OSD_KEY_SLASH_PAD      113
-#define OSD_KEY_ASTER_PAD      114
-#define OSD_KEY_ENTER_PAD      115
-
-#define OSD_MAX_KEY         115
-
-/* X11 keyboard mapping */
-
-#define XK_KP_Enter    OSD_KEY_ENTER_PAD
-#define XK_KP_0                OSD_KEY_0_PAD
-#define XK_KP_1                OSD_KEY_1_PAD
-#define XK_KP_2                OSD_KEY_2_PAD
-#define XK_KP_3                OSD_KEY_3_PAD
-#define XK_KP_4                OSD_KEY_4_PAD
-#define XK_KP_6                OSD_KEY_6_PAD
-#define XK_KP_7                OSD_KEY_7_PAD
-#define XK_KP_8                OSD_KEY_8_PAD
-#define XK_KP_9                OSD_KEY_9_PAD
+#define NEW_KEY_BACKSLASH      86
+#define NEW_KEY_1_PAD          101
+#define NEW_KEY_2_PAD          102
+#define NEW_KEY_3_PAD          103
+#define NEW_KEY_4_PAD          104
+#define NEW_KEY_5_PAD          105
+#define NEW_KEY_6_PAD          106
+#define NEW_KEY_7_PAD          107
+#define NEW_KEY_8_PAD          108
+#define NEW_KEY_9_PAD          109
+#define NEW_KEY_0_PAD          110
+#define NEW_KEY_STOP_PAD       111
+#define NEW_KEY_EQUALS_PAD     112
+#define NEW_KEY_SLASH_PAD      113
+#define NEW_KEY_ASTERISK_PAD   114
+#define NEW_KEY_ENTER_PAD      115
+
+/* X11 keyboard mapping (from 'keysymdef.h') */
+
+#define XK_VoidSymbol          0xFFFFFF        /* void symbol */
+
 /*
 /*
-#define XK_KP_Home     OSD_KEY_7_PAD
-#define XK_KP_Page_Up  OSD_KEY_9_PAD
-#define XK_KP_Page_Down        OSD_KEY_3_PAD
-#define XK_KP_End      OSD_KEY_1_PAD
-#define XK_KP_Left     OSD_KEY_4_PAD   
-#define XK_KP_Up       OSD_KEY_8_PAD
-#define XK_KP_Right    OSD_KEY_6_PAD
-#define XK_KP_Down     OSD_KEY_2_PAD
-*/
-#define XK_0           OSD_KEY_1
-#define XK_1           OSD_KEY_2
-#define XK_2           OSD_KEY_3
-#define XK_3           OSD_KEY_4
-#define XK_4           OSD_KEY_5
-#define XK_5           OSD_KEY_6
-#define XK_6           OSD_KEY_7
-#define XK_7           OSD_KEY_8
-#define XK_8           OSD_KEY_9
-#define XK_9           OSD_KEY_0
-#define XK_A           OSD_KEY_A
-#define XK_B           OSD_KEY_B
-#define XK_C           OSD_KEY_C
-#define XK_D           OSD_KEY_D
-#define XK_E           OSD_KEY_E
-#define XK_F           OSD_KEY_F
-#define XK_G           OSD_KEY_G
-#define XK_H           OSD_KEY_H
-#define XK_I           OSD_KEY_I
-#define XK_J           OSD_KEY_J
-#define XK_K           OSD_KEY_K
-#define XK_L           OSD_KEY_L
-#define XK_M           OSD_KEY_M
-#define XK_N           OSD_KEY_N
-#define XK_O           OSD_KEY_O
-#define XK_P           OSD_KEY_P
-#define XK_Q           OSD_KEY_Q
-#define XK_R           OSD_KEY_R
-#define XK_S           OSD_KEY_S
-#define XK_T           OSD_KEY_T
-#define XK_U           OSD_KEY_U
-#define XK_V           OSD_KEY_V
-#define XK_W           OSD_KEY_W
-#define XK_X           OSD_KEY_X
-#define XK_Y           OSD_KEY_Y
-#define XK_Z           OSD_KEY_Z
-#define XK_a           OSD_KEY_A
-#define XK_b           OSD_KEY_B
-#define XK_c           OSD_KEY_C
-#define XK_d           OSD_KEY_D
-#define XK_e           OSD_KEY_E
-#define XK_f           OSD_KEY_F
-#define XK_g           OSD_KEY_G
-#define XK_h           OSD_KEY_H
-#define XK_i           OSD_KEY_I
-#define XK_j           OSD_KEY_J
-#define XK_k           OSD_KEY_K
-#define XK_l           OSD_KEY_L
-#define XK_m           OSD_KEY_M
-#define XK_n           OSD_KEY_N
-#define XK_o           OSD_KEY_O
-#define XK_p           OSD_KEY_P
-#define XK_q           OSD_KEY_Q
-#define XK_r           OSD_KEY_R
-#define XK_s           OSD_KEY_S
-#define XK_t           OSD_KEY_T
-#define XK_u           OSD_KEY_U
-#define XK_v           OSD_KEY_V
-#define XK_w           OSD_KEY_W
-#define XK_x           OSD_KEY_X
-#define XK_y           OSD_KEY_Y
-#define XK_z           OSD_KEY_Z
-#define XK_Return      OSD_KEY_ENTER
-#define XK_Escape      OSD_KEY_ESC
-#define XK_Shift_L     OSD_KEY_LSHIFT
-#define XK_Shift_R     OSD_KEY_RSHIFT
-#define XK_Left                OSD_KEY_LEFT    
-#define XK_Up          OSD_KEY_UP
-#define XK_Right       OSD_KEY_RIGHT
-#define XK_Down                OSD_KEY_DOWN
-#define XK_BackSpace   OSD_KEY_BACKSPACE
-#define XK_Delete      OSD_KEY_DEL
-#define XK_Space       OSD_KEY_SPACE
-#define XK_F12         OSD_KEY_F12
-#define XK_F11         OSD_KEY_F11
-#define XK_F10         OSD_KEY_F10
-
-
-/*!!!*/
-#define XK_KP_Add      OSD_KEY_PLUS_PAD
-#define XK_KP_Subtract OSD_KEY_MINUS_PAD
-#define XK_KP_Multiply OSD_KEY_ASTER_PAD
-#define XK_KP_Divide   OSD_KEY_SLASH_PAD
-#define XK_KP_Separator        OSD_KEY_STOP_PAD
-#define XK_Control_L   OSD_KEY_LCONTROL
-#define XK_Control_R   OSD_KEY_RCONTROL
-#define XK_Meta_L      OSD_KEY_ALT
-#define XK_Meta_R      OSD_KEY_ALTGR
-#define XK_Alt_L       OSD_KEY_ALT
-#define XK_Alt_R       OSD_KEY_ALTGR
-#define XK_Mode_switch 0                       /* unknown in allegro */
-#define XK_Multi_key   0                       /* unknown in allegro */
-#define XK_Insert      OSD_KEY_INSERT
-#define XK_Tab         OSD_KEY_TAB
-#define XK_Home                OSD_KEY_HOME
-#define XK_End         OSD_KEY_END
-#define XK_Page_Up     OSD_KEY_PGUP
-#define XK_Page_Down   OSD_KEY_PGDN
-#define XK_space       OSD_KEY_SPACE
-#define XK_adiaeresis  0                       /* unknown in allegro */
-#define XK_odiaeresis  0                       /* unknown in allegro */
-#define XK_udiaeresis  0                       /* unknown in allegro */
-#define XK_apostrophe  0                       /* unknown in allegro */
-#define XK_plus                0                       /* unknown in allegro */
-#define XK_minus       OSD_KEY_MINUS
-#define XK_comma       OSD_KEY_COMMA
-#define XK_period      OSD_KEY_STOP
-#define XK_numbersign  0                       /* unknown in allegro */
-#define XK_less                0                       /* unknown in allegro */
-#define XK_greater     0                       /* unknown in allegro */
-#define XK_asciicircum 0                       /* unknown in allegro */
-#define XK_ssharp      0                       /* unknown in allegro */
-#define XK_F1          0                       /* unknown in allegro */
-#define XK_F24         0                       /* unknown in allegro */
-#define XK_VoidSymbol  0                       /* unknown in allegro */
-/*!!!*/
-
-
-#define MOUSE_GIF_FILENAME     "graphics\\mouse.gif"
-#define MOUSE_PCX_FILENAME     "graphics\\mouse.gif"
+ * TTY Functions, cleverly chosen to map to ascii, for convenience of
+ * programming, but could have been arbitrary (at the cost of lookup
+ * tables in client code.
+ */
+
+#define XK_BackSpace           0xFF08  /* back space, back char */
+#define XK_Tab                 0xFF09
+#define XK_Linefeed            0xFF0A  /* Linefeed, LF */
+#define XK_Clear               0xFF0B
+#define XK_Return              0xFF0D  /* Return, enter */
+#define XK_Pause               0xFF13  /* Pause, hold */
+#define XK_Scroll_Lock         0xFF14
+#define XK_Sys_Req             0xFF15
+#define XK_Escape              0xFF1B
+#define XK_Delete              0xFFFF  /* Delete, rubout */
+
+/* International & multi-key character composition */
+
+#define XK_Multi_key           0xFF20  /* Multi-key character compose */
+#define XK_SingleCandidate     0xFF3C
+#define XK_MultipleCandidate   0xFF3D
+#define XK_PreviousCandidate   0xFF3E
+
+/* Cursor control & motion */
+
+#define XK_Home                        0xFF50
+#define XK_Left                        0xFF51  /* Move left, left arrow */
+#define XK_Up                  0xFF52  /* Move up, up arrow */
+#define XK_Right               0xFF53  /* Move right, right arrow */
+#define XK_Down                        0xFF54  /* Move down, down arrow */
+#define XK_Prior               0xFF55  /* Prior, previous */
+#define XK_Page_Up             0xFF55
+#define XK_Next                        0xFF56  /* Next */
+#define XK_Page_Down           0xFF56
+#define XK_End                 0xFF57  /* EOL */
+#define XK_Begin               0xFF58  /* BOL */
+
+/* Misc Functions */
+
+#define XK_Select              0xFF60  /* Select, mark */
+#define XK_Print               0xFF61
+#define XK_Execute             0xFF62  /* Execute, run, do */
+#define XK_Insert              0xFF63  /* Insert, insert here */
+#define XK_Undo                        0xFF65  /* Undo, oops */
+#define XK_Redo                        0xFF66  /* redo, again */
+#define XK_Menu                        0xFF67
+#define XK_Find                        0xFF68  /* Find, search */
+#define XK_Cancel              0xFF69  /* Cancel, stop, abort, exit */
+#define XK_Help                        0xFF6A  /* Help */
+#define XK_Break               0xFF6B
+#define XK_Mode_switch         0xFF7E  /* Character set switch */
+#define XK_script_switch        0xFF7E  /* Alias for mode_switch */
+#define XK_Num_Lock            0xFF7F
+
+/* Keypad Functions, keypad numbers cleverly chosen to map to ascii */
+
+#define XK_KP_Space            0xFF80  /* space */
+#define XK_KP_Tab              0xFF89
+#define XK_KP_Enter            0xFF8D  /* enter */
+#define XK_KP_F1               0xFF91  /* PF1, KP_A, ... */
+#define XK_KP_F2               0xFF92
+#define XK_KP_F3               0xFF93
+#define XK_KP_F4               0xFF94
+#define XK_KP_Home             0xFF95
+#define XK_KP_Left             0xFF96
+#define XK_KP_Up               0xFF97
+#define XK_KP_Right            0xFF98
+#define XK_KP_Down             0xFF99
+#define XK_KP_Prior            0xFF9A
+#define XK_KP_Page_Up          0xFF9A
+#define XK_KP_Next             0xFF9B
+#define XK_KP_Page_Down                0xFF9B
+#define XK_KP_End              0xFF9C
+#define XK_KP_Begin            0xFF9D
+#define XK_KP_Insert           0xFF9E
+#define XK_KP_Delete           0xFF9F
+#define XK_KP_Equal            0xFFBD  /* equals */
+#define XK_KP_Multiply         0xFFAA
+#define XK_KP_Add              0xFFAB
+#define XK_KP_Separator                0xFFAC  /* separator, often comma */
+#define XK_KP_Subtract         0xFFAD
+#define XK_KP_Decimal          0xFFAE
+#define XK_KP_Divide           0xFFAF
+
+#define XK_KP_0                        0xFFB0
+#define XK_KP_1                        0xFFB1
+#define XK_KP_2                        0xFFB2
+#define XK_KP_3                        0xFFB3
+#define XK_KP_4                        0xFFB4
+#define XK_KP_5                        0xFFB5
+#define XK_KP_6                        0xFFB6
+#define XK_KP_7                        0xFFB7
+#define XK_KP_8                        0xFFB8
+#define XK_KP_9                        0xFFB9
+
+/*
+ * Auxilliary Functions; note the duplicate definitions for left and right
+ * function keys;  Sun keyboards and a few other manufactures have such
+ * function key groups on the left and/or right sides of the keyboard.
+ * We've not found a keyboard with more than 35 function keys total.
+ */
+
+#define XK_F1                  0xFFBE
+#define XK_F2                  0xFFBF
+#define XK_F3                  0xFFC0
+#define XK_F4                  0xFFC1
+#define XK_F5                  0xFFC2
+#define XK_F6                  0xFFC3
+#define XK_F7                  0xFFC4
+#define XK_F8                  0xFFC5
+#define XK_F9                  0xFFC6
+#define XK_F10                 0xFFC7
+#define XK_F11                 0xFFC8
+#define XK_L1                  0xFFC8
+#define XK_F12                 0xFFC9
+#define XK_L2                  0xFFC9
+#define XK_F13                 0xFFCA
+#define XK_L3                  0xFFCA
+#define XK_F14                 0xFFCB
+#define XK_L4                  0xFFCB
+#define XK_F15                 0xFFCC
+#define XK_L5                  0xFFCC
+#define XK_F16                 0xFFCD
+#define XK_L6                  0xFFCD
+#define XK_F17                 0xFFCE
+#define XK_L7                  0xFFCE
+#define XK_F18                 0xFFCF
+#define XK_L8                  0xFFCF
+#define XK_F19                 0xFFD0
+#define XK_L9                  0xFFD0
+#define XK_F20                 0xFFD1
+#define XK_L10                 0xFFD1
+#define XK_F21                 0xFFD2
+#define XK_R1                  0xFFD2
+#define XK_F22                 0xFFD3
+#define XK_R2                  0xFFD3
+#define XK_F23                 0xFFD4
+#define XK_R3                  0xFFD4
+#define XK_F24                 0xFFD5
+#define XK_R4                  0xFFD5
+#define XK_F25                 0xFFD6
+#define XK_R5                  0xFFD6
+#define XK_F26                 0xFFD7
+#define XK_R6                  0xFFD7
+#define XK_F27                 0xFFD8
+#define XK_R7                  0xFFD8
+#define XK_F28                 0xFFD9
+#define XK_R8                  0xFFD9
+#define XK_F29                 0xFFDA
+#define XK_R9                  0xFFDA
+#define XK_F30                 0xFFDB
+#define XK_R10                 0xFFDB
+#define XK_F31                 0xFFDC
+#define XK_R11                 0xFFDC
+#define XK_F32                 0xFFDD
+#define XK_R12                 0xFFDD
+#define XK_F33                 0xFFDE
+#define XK_R13                 0xFFDE
+#define XK_F34                 0xFFDF
+#define XK_R14                 0xFFDF
+#define XK_F35                 0xFFE0
+#define XK_R15                 0xFFE0
+
+/* Modifiers */
+
+#define XK_Shift_L             0xFFE1  /* Left shift */
+#define XK_Shift_R             0xFFE2  /* Right shift */
+#define XK_Control_L           0xFFE3  /* Left control */
+#define XK_Control_R           0xFFE4  /* Right control */
+#define XK_Caps_Lock           0xFFE5  /* Caps lock */
+#define XK_Shift_Lock          0xFFE6  /* Shift lock */
+
+#define XK_Meta_L              0xFFE7  /* Left meta */
+#define XK_Meta_R              0xFFE8  /* Right meta */
+#define XK_Alt_L               0xFFE9  /* Left alt */
+#define XK_Alt_R               0xFFEA  /* Right alt */
+#define XK_Super_L             0xFFEB  /* Left super */
+#define XK_Super_R             0xFFEC  /* Right super */
+#define XK_Hyper_L             0xFFED  /* Left hyper */
+#define XK_Hyper_R             0xFFEE  /* Right hyper */
+
+/*
+ *  Latin 1
+ *  Byte 3 = 0
+ */
+
+#define XK_space               0x020
+#define XK_exclam              0x021
+#define XK_quotedbl            0x022
+#define XK_numbersign          0x023
+#define XK_dollar              0x024
+#define XK_percent             0x025
+#define XK_ampersand           0x026
+#define XK_apostrophe          0x027
+#define XK_quoteright          0x027   /* deprecated */
+#define XK_parenleft           0x028
+#define XK_parenright          0x029
+#define XK_asterisk            0x02a
+#define XK_plus                0x02b
+#define XK_comma               0x02c
+#define XK_minus               0x02d
+#define XK_period              0x02e
+#define XK_slash               0x02f
+#define XK_0                   0x030
+#define XK_1                   0x031
+#define XK_2                   0x032
+#define XK_3                   0x033
+#define XK_4                   0x034
+#define XK_5                   0x035
+#define XK_6                   0x036
+#define XK_7                   0x037
+#define XK_8                   0x038
+#define XK_9                   0x039
+#define XK_colon               0x03a
+#define XK_semicolon           0x03b
+#define XK_less                0x03c
+#define XK_equal               0x03d
+#define XK_greater             0x03e
+#define XK_question            0x03f
+#define XK_at                  0x040
+#define XK_A                   0x041
+#define XK_B                   0x042
+#define XK_C                   0x043
+#define XK_D                   0x044
+#define XK_E                   0x045
+#define XK_F                   0x046
+#define XK_G                   0x047
+#define XK_H                   0x048
+#define XK_I                   0x049
+#define XK_J                   0x04a
+#define XK_K                   0x04b
+#define XK_L                   0x04c
+#define XK_M                   0x04d
+#define XK_N                   0x04e
+#define XK_O                   0x04f
+#define XK_P                   0x050
+#define XK_Q                   0x051
+#define XK_R                   0x052
+#define XK_S                   0x053
+#define XK_T                   0x054
+#define XK_U                   0x055
+#define XK_V                   0x056
+#define XK_W                   0x057
+#define XK_X                   0x058
+#define XK_Y                   0x059
+#define XK_Z                   0x05a
+#define XK_bracketleft         0x05b
+#define XK_backslash           0x05c
+#define XK_bracketright        0x05d
+#define XK_asciicircum         0x05e
+#define XK_underscore          0x05f
+#define XK_grave               0x060
+#define XK_quoteleft           0x060   /* deprecated */
+#define XK_a                   0x061
+#define XK_b                   0x062
+#define XK_c                   0x063
+#define XK_d                   0x064
+#define XK_e                   0x065
+#define XK_f                   0x066
+#define XK_g                   0x067
+#define XK_h                   0x068
+#define XK_i                   0x069
+#define XK_j                   0x06a
+#define XK_k                   0x06b
+#define XK_l                   0x06c
+#define XK_m                   0x06d
+#define XK_n                   0x06e
+#define XK_o                   0x06f
+#define XK_p                   0x070
+#define XK_q                   0x071
+#define XK_r                   0x072
+#define XK_s                   0x073
+#define XK_t                   0x074
+#define XK_u                   0x075
+#define XK_v                   0x076
+#define XK_w                   0x077
+#define XK_x                   0x078
+#define XK_y                   0x079
+#define XK_z                   0x07a
+#define XK_braceleft           0x07b
+#define XK_bar                 0x07c
+#define XK_braceright          0x07d
+#define XK_asciitilde          0x07e
+
+#define XK_nobreakspace        0x0a0
+#define XK_exclamdown          0x0a1
+#define XK_cent                       0x0a2
+#define XK_sterling            0x0a3
+#define XK_currency            0x0a4
+#define XK_yen                 0x0a5
+#define XK_brokenbar           0x0a6
+#define XK_section             0x0a7
+#define XK_diaeresis           0x0a8
+#define XK_copyright           0x0a9
+#define XK_ordfeminine         0x0aa
+#define XK_guillemotleft       0x0ab   /* left angle quotation mark */
+#define XK_notsign             0x0ac
+#define XK_hyphen              0x0ad
+#define XK_registered          0x0ae
+#define XK_macron              0x0af
+#define XK_degree              0x0b0
+#define XK_plusminus           0x0b1
+#define XK_twosuperior         0x0b2
+#define XK_threesuperior       0x0b3
+#define XK_acute               0x0b4
+#define XK_mu                  0x0b5
+#define XK_paragraph           0x0b6
+#define XK_periodcentered      0x0b7
+#define XK_cedilla             0x0b8
+#define XK_onesuperior         0x0b9
+#define XK_masculine           0x0ba
+#define XK_guillemotright      0x0bb   /* right angle quotation mark */
+#define XK_onequarter          0x0bc
+#define XK_onehalf             0x0bd
+#define XK_threequarters       0x0be
+#define XK_questiondown        0x0bf
+#define XK_Agrave              0x0c0
+#define XK_Aacute              0x0c1
+#define XK_Acircumflex         0x0c2
+#define XK_Atilde              0x0c3
+#define XK_Adiaeresis          0x0c4
+#define XK_Aring               0x0c5
+#define XK_AE                  0x0c6
+#define XK_Ccedilla            0x0c7
+#define XK_Egrave              0x0c8
+#define XK_Eacute              0x0c9
+#define XK_Ecircumflex         0x0ca
+#define XK_Ediaeresis          0x0cb
+#define XK_Igrave              0x0cc
+#define XK_Iacute              0x0cd
+#define XK_Icircumflex         0x0ce
+#define XK_Idiaeresis          0x0cf
+#define XK_ETH                 0x0d0
+#define XK_Eth                 0x0d0   /* deprecated */
+#define XK_Ntilde              0x0d1
+#define XK_Ograve              0x0d2
+#define XK_Oacute              0x0d3
+#define XK_Ocircumflex         0x0d4
+#define XK_Otilde              0x0d5
+#define XK_Odiaeresis          0x0d6
+#define XK_multiply            0x0d7
+#define XK_Ooblique            0x0d8
+#define XK_Ugrave              0x0d9
+#define XK_Uacute              0x0da
+#define XK_Ucircumflex         0x0db
+#define XK_Udiaeresis          0x0dc
+#define XK_Yacute              0x0dd
+#define XK_THORN               0x0de
+#define XK_Thorn               0x0de   /* deprecated */
+#define XK_ssharp              0x0df
+#define XK_agrave              0x0e0
+#define XK_aacute              0x0e1
+#define XK_acircumflex         0x0e2
+#define XK_atilde              0x0e3
+#define XK_adiaeresis          0x0e4
+#define XK_aring               0x0e5
+#define XK_ae                  0x0e6
+#define XK_ccedilla            0x0e7
+#define XK_egrave              0x0e8
+#define XK_eacute              0x0e9
+#define XK_ecircumflex         0x0ea
+#define XK_ediaeresis          0x0eb
+#define XK_igrave              0x0ec
+#define XK_iacute              0x0ed
+#define XK_icircumflex         0x0ee
+#define XK_idiaeresis          0x0ef
+#define XK_eth                 0x0f0
+#define XK_ntilde              0x0f1
+#define XK_ograve              0x0f2
+#define XK_oacute              0x0f3
+#define XK_ocircumflex         0x0f4
+#define XK_otilde              0x0f5
+#define XK_odiaeresis          0x0f6
+#define XK_division            0x0f7
+#define XK_oslash              0x0f8
+#define XK_ugrave              0x0f9
+#define XK_uacute              0x0fa
+#define XK_ucircumflex         0x0fb
+#define XK_udiaeresis          0x0fc
+#define XK_yacute              0x0fd
+#define XK_thorn               0x0fe
+#define XK_ydiaeresis          0x0ff
+
+/* end of X11 keyboard mapping */
+
+#define MOUSE_FILENAME         "mouse.pcx"
 #define JOYSTICK_FILENAME      "joystick.cnf"
 #define JOYSTICK_FILENAME      "joystick.cnf"
+
 #define screen myscreen
 
 #define XFlush(a)
 #define screen myscreen
 
 #define XFlush(a)
 #define XSetWMProperties(a,b,c,d,e,f,g,h,i)
 
 #define MAX_EVENT_BUFFER       256
 #define XSetWMProperties(a,b,c,d,e,f,g,h,i)
 
 #define MAX_EVENT_BUFFER       256
+#define MAX_SCANCODES          128
 
 #define True                   1
 #define False                  0
 
 #define True                   1
 #define False                  0
index 48f42a35ca745a65b1b39c7f1202a17c366d2c56..f2076dce3518fe3f447e08ff04066f710eb90daf 100644 (file)
@@ -715,53 +715,39 @@ void HandleTypeName(int newxpos, KeySym key)
   if (newxpos)
   {
     xpos = newxpos;
   if (newxpos)
   {
     xpos = newxpos;
-    DrawText(SX+6*32, SY+ypos*32, setup.player_name, FS_BIG, FC_YELLOW);
-    DrawGraphic(xpos+6,ypos,GFX_KUGEL_ROT);
+    DrawText(SX + 6*32, SY + ypos*32, setup.player_name, FS_BIG, FC_YELLOW);
+    DrawGraphic(xpos + 6, ypos, GFX_KUGEL_ROT);
     return;
   }
 
     return;
   }
 
-#ifndef MSDOS
-  if ((key>=XK_A && key<=XK_Z) || (key>=XK_a && key<=XK_z && 
-      xpos<MAX_NAMELEN-1))
+  if (((key >= XK_A && key <= XK_Z) || (key >= XK_a && key <= XK_z)) && 
+      xpos < MAX_NAMELEN - 1)
   {
   {
-    if (key>=XK_A && key<=XK_Z)
-      ascii = 'A'+(char)(key-XK_A);
-    if (key>=XK_a && key<=XK_z)
-      ascii = 'a'+(char)(key-XK_a);
+    if (key >= XK_A && key <= XK_Z)
+      ascii = 'A' + (char)(key - XK_A);
+    if (key >= XK_a && key <= XK_z)
+      ascii = 'a' + (char)(key - XK_a);
 
     setup.player_name[xpos] = ascii;
 
     setup.player_name[xpos] = ascii;
-    setup.player_name[xpos+1] = 0;
+    setup.player_name[xpos + 1] = 0;
     xpos++;
     xpos++;
-    DrawTextExt(drawto,gc,SX+6*32,SY+ypos*32,
-               setup.player_name,FS_BIG,FC_YELLOW);
-    DrawTextExt(window,gc,SX+6*32,SY+ypos*32,
-               setup.player_name,FS_BIG,FC_YELLOW);
-    DrawGraphic(xpos+6,ypos,GFX_KUGEL_ROT);
+    DrawTextExt(drawto, gc, SX + 6*32, SY + ypos*32,
+               setup.player_name, FS_BIG, FC_YELLOW);
+    DrawTextExt(window, gc, SX + 6*32, SY + ypos*32,
+               setup.player_name, FS_BIG, FC_YELLOW);
+    DrawGraphic(xpos + 6, ypos, GFX_KUGEL_ROT);
   }
   }
-#else
-  if ((ascii = get_ascii(key)) && xpos<MAX_NAMELEN-1)
-  {
-    setup.player_name[xpos] = ascii;
-    setup.player_name[xpos+1] = 0;
-    xpos++;
-    DrawTextExt(drawto,gc,SX+6*32,SY+ypos*32,
-               setup.player_name,FS_BIG,FC_YELLOW);
-    DrawTextExt(window,gc,SX+6*32,SY+ypos*32,
-               setup.player_name,FS_BIG,FC_YELLOW);
-    DrawGraphic(xpos+6,ypos,GFX_KUGEL_ROT);
-  }
-#endif
-  else if ((key==XK_Delete || key==XK_BackSpace) && xpos>0)
+  else if ((key == XK_Delete || key == XK_BackSpace) && xpos > 0)
   {
     xpos--;
     setup.player_name[xpos] = 0;
   {
     xpos--;
     setup.player_name[xpos] = 0;
-    DrawGraphic(xpos+6,ypos,GFX_KUGEL_ROT);
-    DrawGraphic(xpos+7,ypos,GFX_LEERRAUM);
+    DrawGraphic(xpos + 6, ypos, GFX_KUGEL_ROT);
+    DrawGraphic(xpos + 7, ypos, GFX_LEERRAUM);
   }
   }
-  else if (key==XK_Return && xpos>0)
+  else if (key == XK_Return && xpos > 0)
   {
   {
-    DrawText(SX+6*32,SY+ypos*32,setup.player_name,FS_BIG,FC_RED);
-    DrawGraphic(xpos+6,ypos,GFX_LEERRAUM);
+    DrawText(SX + 6*32, SY + ypos*32, setup.player_name, FS_BIG, FC_RED);
+    DrawGraphic(xpos + 6, ypos, GFX_LEERRAUM);
 
     SaveSetup();
     game_status = MAINMENU;
 
     SaveSetup();
     game_status = MAINMENU;
@@ -1239,28 +1225,12 @@ void DrawSetupInputScreen()
   DrawText(SX+32, SY+3*32, "Device:", FS_BIG, FC_GREEN);
   DrawText(SX+32, SY+15*32, "Exit", FS_BIG, FC_GREEN);
 
   DrawText(SX+32, SY+3*32, "Device:", FS_BIG, FC_GREEN);
   DrawText(SX+32, SY+15*32, "Exit", FS_BIG, FC_GREEN);
 
+  DrawTextFCentered(SYSIZE - 20, FC_BLUE,
+                   "Joysticks deactivated on this screen");
+
+  HandleSetupInputScreen(0,0, 0,0, MB_MENU_INITIALIZE);
   FadeToFront();
   InitAnimation();
   FadeToFront();
   InitAnimation();
-  HandleSetupInputScreen(0,0,0,0,MB_MENU_INITIALIZE);
-}
-
-static int getJoystickNrFromDeviceName(char *device_name)
-{
-  char c;
-  int joystick_nr = 0;
-
-  if (device_name == NULL || device_name[0] == '\0')
-    return 0;
-
-  c = device_name[strlen(device_name) - 1];
-
-  if (c >= '0' && c <= '9')
-    joystick_nr = (int)(c - '0');
-
-  if (joystick_nr < 0 || joystick_nr >= MAX_PLAYERS)
-    joystick_nr = 0;
-
-  return joystick_nr;
 }
 
 static void setJoystickDeviceToNr(char *device_name, int device_nr)
 }
 
 static void setJoystickDeviceToNr(char *device_name, int device_nr)
@@ -1494,7 +1464,9 @@ void HandleSetupInputScreen(int mx, int my, int dx, int dy, int button)
        if (setup.input[player_nr].use_joystick)
        {
          InitJoysticks();
        if (setup.input[player_nr].use_joystick)
        {
          InitJoysticks();
+         game_status = CALIBRATION;
          CalibrateJoystick(player_nr);
          CalibrateJoystick(player_nr);
+         game_status = SETUPINPUT;
        }
        else
          CustomizeKeyboard(player_nr);
        }
        else
          CustomizeKeyboard(player_nr);
@@ -1659,34 +1631,43 @@ void CalibrateJoystick(int player_nr)
   } joy_ctrl;
 #endif
 
   } joy_ctrl;
 #endif
 
-#ifdef MSDOS
-  /*
-  char joy_nr[4];
-  */
-#endif
-
-  int joystick_fd = stored_player[player_nr].joystick_fd;
+#ifndef MSDOS
   int new_joystick_xleft = 128, new_joystick_xright = 128;
   int new_joystick_yupper = 128, new_joystick_ylower = 128;
   int new_joystick_xmiddle, new_joystick_ymiddle;
   int new_joystick_xleft = 128, new_joystick_xright = 128;
   int new_joystick_yupper = 128, new_joystick_ylower = 128;
   int new_joystick_xmiddle, new_joystick_ymiddle;
+#else
+  int calibration_step = 1;
+#endif
+
+  int joystick_fd = stored_player[player_nr].joystick_fd;
   int x, y, last_x, last_y, xpos = 8, ypos = 3;
   boolean check[3][3];
   int x, y, last_x, last_y, xpos = 8, ypos = 3;
   boolean check[3][3];
-  int check_remaining = 3 * 3;
-  int joy;
+  int check_remaining;
+  int joy_value;
   int result = -1;
 
   int result = -1;
 
-  if (joystick_status == JOYSTICK_OFF)
-    return;
-
-  if (!setup.input[player_nr].use_joystick || joystick_fd < 0)
-    return;
+  if (joystick_status == JOYSTICK_OFF ||
+      joystick_fd < 0 ||
+      !setup.input[player_nr].use_joystick)
+    goto error_out;
 
   ClearWindow();
 
   ClearWindow();
-  DrawText(SX,      SY +  6*32, " ROTATE JOYSTICK ",FS_BIG,FC_YELLOW);
-  DrawText(SX,      SY +  7*32, "IN ALL DIRECTIONS",FS_BIG,FC_YELLOW);
-  DrawText(SX + 16, SY +  9*32, "  IF ALL BALLS  ",FS_BIG,FC_YELLOW);
-  DrawText(SX,      SY + 10*32, "   ARE YELLOW,   ",FS_BIG,FC_YELLOW);
-  DrawText(SX,      SY + 11*32, "  PRESS BUTTON!  ",FS_BIG,FC_YELLOW);
+
+#ifndef MSDOS
+  DrawText(SX,      SY +  6*32, " ROTATE JOYSTICK ", FS_BIG, FC_YELLOW);
+  DrawText(SX,      SY +  7*32, "IN ALL DIRECTIONS", FS_BIG, FC_YELLOW);
+  DrawText(SX + 16, SY +  9*32, "  IF ALL BALLS  ",  FS_BIG, FC_YELLOW);
+  DrawText(SX,      SY + 10*32, "   ARE YELLOW,   ", FS_BIG, FC_YELLOW);
+  DrawText(SX,      SY + 11*32, "PRESS ANY BUTTON!", FS_BIG, FC_YELLOW);
+  check_remaining = 3 * 3;
+#else
+  DrawText(SX,      SY +  7*32, "  MOVE JOYSTICK  ", FS_BIG, FC_YELLOW);
+  DrawText(SX + 16, SY +  8*32, "       TO       ",  FS_BIG, FC_YELLOW);
+  DrawText(SX,      SY +  9*32, " CENTER POSITION ",  FS_BIG, FC_YELLOW);
+  DrawText(SX,      SY + 10*32, "       AND       ", FS_BIG, FC_YELLOW);
+  DrawText(SX,      SY + 11*32, "PRESS ANY BUTTON!", FS_BIG, FC_YELLOW);
+  check_remaining = 0;
+#endif
 
   for(y=0; y<3; y++)
   {
 
   for(y=0; y<3; y++)
   {
@@ -1697,9 +1678,9 @@ void CalibrateJoystick(int player_nr)
     }
   }
 
     }
   }
 
-  joy = Joystick(player_nr);
-  last_x = (joy & JOY_LEFT ? -1 : joy & JOY_RIGHT ? +1 : 0);
-  last_y = (joy & JOY_UP   ? -1 : joy & JOY_DOWN  ? +1 : 0);
+  joy_value = Joystick(player_nr);
+  last_x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
+  last_y = (joy_value & JOY_UP   ? -1 : joy_value & JOY_DOWN  ? +1 : 0);
   DrawGraphic(xpos + last_x, ypos + last_y, GFX_KUGEL_ROT);
 
   BackToFront();
   DrawGraphic(xpos + last_x, ypos + last_y, GFX_KUGEL_ROT);
 
   BackToFront();
@@ -1758,7 +1739,6 @@ void CalibrateJoystick(int player_nr)
       joystick_status = JOYSTICK_OFF;
       goto error_out;
     }
       joystick_status = JOYSTICK_OFF;
       goto error_out;
     }
-#endif
 
     new_joystick_xleft  = MIN(new_joystick_xleft,  joy_ctrl.x);
     new_joystick_xright = MAX(new_joystick_xright, joy_ctrl.x);
 
     new_joystick_xleft  = MIN(new_joystick_xleft,  joy_ctrl.x);
     new_joystick_xright = MAX(new_joystick_xright, joy_ctrl.x);
@@ -1778,18 +1758,60 @@ void CalibrateJoystick(int player_nr)
     setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
 
     CheckJoystickData();
     setup.input[player_nr].joy.ymiddle = new_joystick_ymiddle;
 
     CheckJoystickData();
+#endif
 
 
-    joy = Joystick(player_nr);
+    joy_value = Joystick(player_nr);
 
 
-    if (joy & JOY_BUTTON && check_remaining == 0)
+    if (joy_value & JOY_BUTTON && check_remaining == 0)
+    {
       result = 1;
 
       result = 1;
 
-    x = (joy & JOY_LEFT ? -1 : joy & JOY_RIGHT ? +1 : 0);
-    y = (joy & JOY_UP   ? -1 : joy & JOY_DOWN  ? +1 : 0);
+#ifdef MSDOS
+      if (calibration_step == 1)
+      {
+       remove_joystick();
+       InitJoysticks();
+      }
+      else if (calibrate_joystick(joystick_fd) != 0)
+      {
+       joystick_status = JOYSTICK_OFF;
+       goto error_out;
+      }
+
+      if (joy[joystick_fd].flags & JOYFLAG_CALIBRATE)
+      {
+       calibration_step++;
+       result = -1;
+
+       DrawText(SX,      SY +  7*32, "  MOVE JOYSTICK  ", FS_BIG, FC_YELLOW);
+       DrawText(SX + 16, SY +  8*32, "       TO       ",  FS_BIG, FC_YELLOW);
+
+       if (calibration_step == 2)
+         DrawText(SX + 16, SY + 9*32," THE UPPER LEFT ",  FS_BIG, FC_YELLOW);
+       else
+         DrawText(SX,      SY + 9*32," THE LOWER RIGHT ", FS_BIG, FC_YELLOW);
+
+       DrawText(SX,      SY + 10*32, "       AND       ", FS_BIG, FC_YELLOW);
+       DrawText(SX,      SY + 11*32, "PRESS ANY BUTTON!", FS_BIG, FC_YELLOW);
+
+       BackToFront();
+
+       while(Joystick(player_nr) & JOY_BUTTON)
+         DoAnimation();
+      }
+#endif
+    }
+
+    x = (joy_value & JOY_LEFT ? -1 : joy_value & JOY_RIGHT ? +1 : 0);
+    y = (joy_value & JOY_UP   ? -1 : joy_value & JOY_DOWN  ? +1 : 0);
 
     if (x != last_x || y != last_y)
     {
 
     if (x != last_x || y != last_y)
     {
+#ifndef MSDOS
       DrawGraphic(xpos + last_x, ypos + last_y, GFX_KUGEL_GELB);
       DrawGraphic(xpos + last_x, ypos + last_y, GFX_KUGEL_GELB);
+#else
+      DrawGraphic(xpos + last_x, ypos + last_y, GFX_KUGEL_BLAU);
+#endif
       DrawGraphic(xpos + x,      ypos + y,      GFX_KUGEL_ROT);
 
       last_x = x;
       DrawGraphic(xpos + x,      ypos + y,      GFX_KUGEL_ROT);
 
       last_x = x;
@@ -1811,6 +1833,7 @@ void CalibrateJoystick(int player_nr)
             setup.input[player_nr].joy.ymiddle,
             setup.input[player_nr].joy.ylower);
 #endif
             setup.input[player_nr].joy.ymiddle,
             setup.input[player_nr].joy.ylower);
 #endif
+
     }
 
     BackToFront();
     }
 
     BackToFront();
@@ -1826,15 +1849,13 @@ void CalibrateJoystick(int player_nr)
   while(Joystick(player_nr) & JOY_BUTTON);
   return;
 
   while(Joystick(player_nr) & JOY_BUTTON);
   return;
 
-#ifndef MSDOS
   error_out:
   error_out:
-#endif
 
   ClearWindow();
 
   ClearWindow();
-  DrawText(SX+16, SY+16, "NO JOYSTICK",FS_BIG,FC_YELLOW);
-  DrawText(SX+16, SY+48, " AVAILABLE ",FS_BIG,FC_YELLOW);
+  DrawText(SX + 16, SY + 6*32, "  JOYSTICK NOT  ", FS_BIG, FC_YELLOW);
+  DrawText(SX,      SY + 7*32, "    AVAILABLE    ", FS_BIG, FC_YELLOW);
   BackToFront();
   BackToFront();
-  Delay(3000);
+  Delay(2000);
   DrawSetupInputScreen();
 }
 
   DrawSetupInputScreen();
 }