root/drivers/sound/configure.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. can_select_option
  2. think_positively
  3. ask_value
  4. main

   1 /*
   2  * sound/configure.c    - Configuration program for the Linux Sound Driver
   3  * 
   4  * Copyright by Hannu Savolainen 1993
   5  * 
   6  * Redistribution and use in source and binary forms, with or without
   7  * modification, are permitted provided that the following conditions are
   8  * met: 1. Redistributions of source code must retain the above copyright
   9  * notice, this list of conditions and the following disclaimer. 2.
  10  * Redistributions in binary form must reproduce the above copyright notice,
  11  * this list of conditions and the following disclaimer in the documentation
  12  * and/or other materials provided with the distribution.
  13  * 
  14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
  15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
  18  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  20  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  21  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  24  * SUCH DAMAGE.
  25  * 
  26  */
  27 
  28 #include <stdio.h>
  29 
  30 #define B(x)    (1 << (x))
  31 
  32 /*
  33  * Option numbers
  34  */
  35 
  36 #define OPT_PAS         0
  37 #define OPT_SB          1
  38 #define OPT_ADLIB       2
  39 #define OPT_LAST_MUTUAL 2
  40 
  41 #define OPT_GUS         3
  42 #define OPT_MPU401      4
  43 
  44 #define OPT_HIGHLEVEL   5
  45 #define OPT_SBPRO       5
  46 #define OPT_SB16        6
  47 #define OPT_AUDIO       7
  48 #define OPT_MIDI_AUTO   8
  49 #define OPT_MIDI        9
  50 #define OPT_YM3812_AUTO 10      /* Select this automaticly if user selects
  51                                  * MIDI or AdLib driver */
  52 #define OPT_YM3812      11      /* Select this if the previous one was not
  53                                  * selected */
  54 #define OPT_SEQUENCER   12
  55 #define OPT_CHIP_MIDI   13      /* New support added at UW - Milwauklee UW -
  56                                  * Milwauklee */
  57 #define OPT_LAST        12
  58 
  59 #define ANY_DEVS (B(OPT_AUDIO)|B(OPT_MIDI)|B(OPT_SEQUENCER)|B(OPT_GUS)|B(OPT_MPU401))
  60 
  61 typedef struct
  62   {
  63     unsigned long   conditions;
  64     unsigned long   exclusive_options;
  65     char            macro[20];
  66     int             verify;
  67     int             alias;
  68   }
  69 
  70 hw_entry;
  71 
  72 
  73 /*
  74  * The rule table for the driver options. The first field defines a set of
  75  * options which must be selected before this entry can be selected. The
  76  * second field is a set of options which are not allowed with this one. If
  77  * the fourth field is zero, the option is selected without asking
  78  * confirmation from the user.
  79  * 
  80  * With this version of the rule table it is possible to select just one type of
  81  * hardware.
  82  * 
  83  * NOTE!        Keep the following table and the questions array in sync with the
  84  * option numbering!
  85  */
  86 
  87 hw_entry        hw_table[] =
  88 {
  89 /* 0 */
  90   {0, 0, "PAS", 1, 0},
  91   {0, 0, "SB", 1, 0},
  92   {0, B (OPT_PAS) | B (OPT_SB), "ADLIB", 1, 0},
  93 
  94 /* 3 */
  95   {0, 0, "GUS", 1, 0},
  96   {0, 0, "MPU401", 1, 0},
  97   {B (OPT_SB), B (OPT_PAS), "SBPRO", 1, 0},
  98   {B (OPT_SB) | B (OPT_SBPRO), B (OPT_PAS), "SB16", 1, 0},
  99   {B (OPT_SB) | B (OPT_PAS) | B (OPT_GUS), 0, "AUDIO", 1, 0},
 100   {B (OPT_MPU401), 0, "MIDI_AUTO", 0, OPT_MIDI},
 101   {B (OPT_SB) | B (OPT_PAS) | B (OPT_MPU401) | B (OPT_GUS), 0, "MIDI", 1, 0},
 102   {B (OPT_ADLIB), 0, "YM3812_AUTO", 0, OPT_YM3812},
 103   {B (OPT_SB) | B (OPT_PAS) | B (OPT_ADLIB), B (OPT_YM3812_AUTO), "YM3812", 1, 0},
 104 /* 10 */
 105   {B (OPT_MIDI) | B (OPT_YM3812) | B (OPT_YM3812_AUTO) | B (OPT_GUS), 0, "SEQUENCER", 0, 0},
 106   {0, 0, "CHIP_MIDI", 1, 0}
 107 };
 108 
 109 char           *questions[] =
 110 {
 111   "ProAudioSpectrum 16 support",
 112   "SoundBlaster support",
 113   "AdLib support",
 114   "Gravis Ultrasound support",
 115   "MPU-401 support",
 116 
 117   "SoundBlaster Pro support (required for SB16 also)",
 118   "SoundBlaster 16 support",
 119   "digitized voice support",
 120   "This should not be asked",
 121   "MIDI interface support",
 122   "This should not be asked",
 123   "Internal synthesizer (FM/GUS) support",
 124   "/dev/sequencer support",
 125   "MIDI on CHIP support"
 126 };
 127 
 128 unsigned long   selected_options = 0;
 129 
 130 int
 131 can_select_option (int nr)
     /* [previous][next][first][last][top][bottom][index][help] */
 132 {
 133   switch (nr)
 134     {
 135     case 0:
 136       fprintf (stderr, "The SoundBlaster, AdLib and ProAudioSpectrum\n"
 137                "cards cannot be installed at the same time\n");
 138       fprintf (stderr, "\nSelect at most one of them:\n");
 139       fprintf (stderr, "        - ProAudioSpectrum 16\n");
 140       fprintf (stderr, "        - SoundBlaster / SB Pro\n");
 141       fprintf (stderr, "          (Could be selected with PAS16 also\n"
 142                "          since there is a SB emulation on it)\n");
 143       fprintf (stderr, "        - AdLib\n");
 144       fprintf (stderr, "\nDon't enable SoundBlaster if you have GUS at 0x220!\n\n");
 145       break;
 146 
 147     case OPT_LAST_MUTUAL + 1:
 148       fprintf (stderr, "\nThe following cards should work with any other cards.\n"
 149                "CAUTION! Don't enable MPU-401 if you don't have it.\n");
 150       break;
 151 
 152     case OPT_HIGHLEVEL:
 153       fprintf (stderr, "\nSelect one or more of the following options\n");
 154       break;
 155 
 156 
 157     }
 158 
 159   if (hw_table[nr].conditions)
 160     if (!(hw_table[nr].conditions & selected_options))
 161       return 0;
 162 
 163   if (hw_table[nr].exclusive_options)
 164     if (hw_table[nr].exclusive_options & selected_options)
 165       return 0;
 166 
 167   return 1;
 168 }
 169 
 170 int
 171 think_positively (void)
     /* [previous][next][first][last][top][bottom][index][help] */
 172 {
 173   char            answ[512];
 174   int             len;
 175 
 176   if ((len = read (0, &answ, sizeof (answ))) < 1)
 177     {
 178       fprintf (stderr, "\n\nERROR! Cannot read stdin\n");
 179 
 180       perror ("stdin");
 181       printf ("#undef CONFIGURE_SOUNDCARD\n");
 182       printf ("#undef KERNEL_SOUNDCARD\n");
 183       exit (-1);
 184     }
 185 
 186   if (len < 2)                  /* There is an additional LF at the end */
 187     return 0;
 188 
 189   answ[len - 1] = 0;
 190 
 191   if (!strcmp (answ, "y") || !strcmp (answ, "Y"))
 192     return 1;
 193 
 194   return 0;
 195 }
 196 
 197 int
 198 ask_value (char *format, int default_answer)
     /* [previous][next][first][last][top][bottom][index][help] */
 199 {
 200   char            answ[512];
 201   int             len, num;
 202 
 203 play_it_again_Sam:
 204 
 205   if ((len = read (0, &answ, sizeof (answ))) < 1)
 206     {
 207       fprintf (stderr, "\n\nERROR! Cannot read stdin\n");
 208 
 209       perror ("stdin");
 210       printf ("#undef CONFIGURE_SOUNDCARD\n");
 211       printf ("#undef KERNEL_SOUNDCARD\n");
 212       exit (-1);
 213     }
 214 
 215   if (len < 2)                  /* There is an additional LF at the end */
 216     return default_answer;
 217 
 218   answ[len - 1] = 0;
 219 
 220   if (sscanf (answ, format, &num) != 1)
 221     {
 222       fprintf (stderr, "Illegal format. Try again: ");
 223       goto play_it_again_Sam;
 224     }
 225 
 226   return num;
 227 }
 228 
 229 int
 230 main (int argc, char *argv[])
     /* [previous][next][first][last][top][bottom][index][help] */
 231 {
 232   int             i, num, def_size, full_driver = 1;
 233   char            answ[10];
 234 
 235   printf ("/*\tGenerated by configure. Don't edit!!!!\t*/\n\n");
 236 
 237   fprintf (stderr, "\nConfiguring the sound support\n\n");
 238 
 239   fprintf (stderr, "Do you want to include full version of the sound driver (n/y) ? ");
 240 
 241   if (think_positively ())
 242     {
 243       selected_options = 0xffffffff & ~B (OPT_MPU401);
 244       fprintf (stderr, "Note! MPU-401 driver was not enabled\n");
 245       full_driver = 1;
 246     }
 247   else
 248     {
 249       fprintf (stderr, "Do you want to DISABLE the Sound Driver (n/y) ?");
 250       if (think_positively ())
 251         {
 252           printf ("#undef CONFIGURE_SOUNDCARD\n");
 253           printf ("#undef KERNEL_SOUNDCARD\n");
 254           exit (0);
 255         }
 256       /* Partial driver */
 257 
 258       full_driver = 0;
 259 
 260       for (i = 0; i <= OPT_LAST; i++)
 261         if (can_select_option (i))
 262           {
 263             if (!(selected_options & B (i)))    /* Not selected yet */
 264               if (!hw_table[i].verify)
 265                 {
 266                   if (hw_table[i].alias)
 267                     selected_options |= B (hw_table[i].alias);
 268                   else
 269                     selected_options |= B (i);
 270                 }
 271               else
 272                 {
 273                   fprintf (stderr, "  %s (n/y) ? ", questions[i]);
 274                   if (think_positively ())
 275                     if (hw_table[i].alias)
 276                       selected_options |= B (hw_table[i].alias);
 277                     else
 278                       selected_options |= B (i);
 279                 }
 280           }
 281     }
 282 
 283   if (!(selected_options & ANY_DEVS))
 284     {
 285       printf ("#undef CONFIGURE_SOUNDCARD\n");
 286       printf ("#undef KERNEL_SOUNDCARD\n");
 287       fprintf (stderr, "\n*** This combination is useless. Sound driver disabled!!! ***\n\n");
 288       exit (0);
 289     }
 290   else
 291     printf ("#define KERNEL_SOUNDCARD\n");
 292 
 293   for (i = 0; i <= OPT_LAST; i++)
 294     if (!hw_table[i].alias)
 295       if (selected_options & B (i))
 296         printf ("#undef  EXCLUDE_%s\n", hw_table[i].macro);
 297       else
 298         printf ("#define EXCLUDE_%s\n", hw_table[i].macro);
 299 
 300 
 301   printf ("#define EXCLUDE_PRO_MIDI\n");
 302   printf ("#define EXCLUDE_CHIP_MIDI\n");
 303 
 304   /*
 305    * IRQ and DMA settings
 306    */
 307   printf ("\n");
 308 
 309 #ifdef linux
 310   if (selected_options & B (OPT_SB) && selected_options & (B (OPT_AUDIO) | B (OPT_MIDI)))
 311     {
 312       fprintf (stderr, "\nIRQ number for SoundBlaster?\n"
 313                "The IRQ adress is defined by the jumpers on your card and\n"
 314                "7 is the factory default. Valid values are 9, 5, 7 and 10.\n"
 315                "Enter the value: ");
 316 
 317       num = ask_value ("%d", 7);
 318       if (num != 9 && num != 5 && num != 7 && num != 10)
 319         {
 320 
 321           fprintf (stderr, "*** Illegal input! ***\n");
 322           num = 7;
 323         }
 324       fprintf (stderr, "SoundBlaster IRQ set to %d\n", num);
 325       printf ("#define SBC_IRQ %d\n", num);
 326 
 327       if (selected_options & B (OPT_SBPRO))
 328         {
 329 
 330           fprintf (stderr, "\nDMA channel for SoundBlaster?\n"
 331                    "For SB 1.0, 1.5 and 2.0 this MUST be 1\n"
 332                    "SB Pro supports DMA channels 0, 1 and 3 (jumper)\n"
 333                    "For SB16 give the 8 bit DMA# here\n"
 334                    "The default value is 1\n"
 335                    "Enter the value: ");
 336 
 337           num = ask_value ("%d", 1);
 338           if (num < 0 || num > 3)
 339             {
 340 
 341               fprintf (stderr, "*** Illegal input! ***\n");
 342               num = 1;
 343             }
 344           fprintf (stderr, "SoundBlaster DMA set to %d\n", num);
 345           printf ("#define SBC_DMA %d\n", num);
 346         }
 347 
 348       if (selected_options & B (OPT_SB16))
 349         {
 350 
 351           fprintf (stderr, "\n16 bit DMA channel for SoundBlaster 16?\n"
 352                    "Possible values are 5, 6 or 7\n"
 353                    "The default value is 6\n"
 354                    "Enter the value: ");
 355 
 356           num = ask_value ("%d", 6);
 357           if (num < 5 || num > 7)
 358             {
 359 
 360               fprintf (stderr, "*** Illegal input! ***\n");
 361               num = 6;
 362             }
 363           fprintf (stderr, "SoundBlaster DMA set to %d\n", num);
 364           printf ("#define SB16_DMA %d\n", num);
 365         }
 366     }
 367 
 368   if (selected_options & B (OPT_PAS))
 369     {
 370       if (selected_options & (B (OPT_AUDIO) | B (OPT_MIDI)))
 371         {
 372           fprintf (stderr, "\nIRQ number for ProAudioSpectrum?\n"
 373                    "The recommended value is the IRQ used under DOS.\n"
 374                    "Please refer to the ProAudioSpectrum User's Guide.\n"
 375                    "The default value is 10.\n"
 376                    "Enter the value: ");
 377 
 378           num = ask_value ("%d", 10);
 379           if (num == 6 || num < 3 || num > 15 || num == 2)      /* Illegal */
 380             {
 381 
 382               fprintf (stderr, "*** Illegal input! ***\n");
 383               num = 10;
 384             }
 385           fprintf (stderr, "ProAudioSpectrum IRQ set to %d\n", num);
 386           printf ("#define PAS_IRQ %d\n", num);
 387         }
 388 
 389       if (selected_options & B (OPT_AUDIO))
 390         {
 391           fprintf (stderr, "\nDMA number for ProAudioSpectrum?\n"
 392                    "The recommended value is the DMA channel under DOS.\n"
 393                    "Please refer to the ProAudioSpectrum User's Guide.\n"
 394                    "The default value is 3\n"
 395                    "Enter the value: ");
 396 
 397           num = ask_value ("%d", 3);
 398           if (num == 4 || num < 0 || num > 7)
 399             {
 400 
 401               fprintf (stderr, "*** Illegal input! ***\n");
 402               num = 3;
 403             }
 404           fprintf (stderr, "\nProAudioSpectrum DMA set to %d\n", num);
 405           printf ("#define PAS_DMA %d\n", num);
 406         }
 407     }
 408 
 409   if (selected_options & B (OPT_GUS))
 410     {
 411       fprintf (stderr, "\nI/O base for Gravis Ultrasound?\n"
 412                "Valid choises are 210, 220, 230, 240, 250 or 260\n"
 413                "The factory default is 220\n"
 414                "Enter the GUS I/O base: ");
 415 
 416       num = ask_value ("%x", 0x220);
 417       if ((num > 0x260) || ((num & 0xf0f) != 0x200) || ((num & 0x0f0) > 0x060))
 418         {
 419 
 420           fprintf (stderr, "*** Illegal input! ***\n");
 421           num = 0x220;
 422         }
 423 
 424       if ((selected_options & B (OPT_SB)) && (num == 0x220))
 425         {
 426           fprintf (stderr, "FATAL ERROR!!!!!!!!!!!!!!\n"
 427                    "\t0x220 cannot be used if SoundBlaster is enabled.\n"
 428                    "\tRun the config again.\n");
 429           printf ("#undef CONFIGURE_SOUNDCARD\n");
 430           printf ("#undef KERNEL_SOUNDCARD\n");
 431           exit (-1);
 432         }
 433       fprintf (stderr, "GUS I/O base set to %03x\n", num);
 434       printf ("#define GUS_BASE 0x%03x\n", num);
 435 
 436       fprintf (stderr, "\nIRQ number for Gravis UltraSound?\n"
 437                "The recommended value is the IRQ used under DOS.\n"
 438                "Please refer to the Gravis Ultrasound User's Guide.\n"
 439                "The default value is 15.\n"
 440                "Enter the value: ");
 441 
 442       num = ask_value ("%d", 15);
 443       if (num == 6 || num < 3 || num > 15 || num == 2)  /* Invalid */
 444         {
 445 
 446           fprintf (stderr, "*** Illegal input! ***\n");
 447           num = 15;
 448         }
 449       fprintf (stderr, "Gravis UltraSound IRQ set to %d\n", num);
 450       printf ("#define GUS_IRQ %d\n", num);
 451 
 452       fprintf (stderr, "\nDMA number for Gravis UltraSound?\n"
 453                "The recommended value is the DMA channel under DOS.\n"
 454                "Please refer to the Gravis Ultrasound User's Guide.\n"
 455                "The default value is 6\n"
 456                "Enter the value: ");
 457 
 458       num = ask_value ("%d", 6);
 459       if (num == 4 || num < 0 || num > 7)
 460         {
 461           fprintf (stderr, "*** Illegal input! ***\n");
 462           num = 6;
 463         }
 464       fprintf (stderr, "\nGravis UltraSound DMA set to %d\n", num);
 465       printf ("#define GUS_DMA %d\n", num);
 466     }
 467 
 468   if (selected_options & B (OPT_MPU401))
 469     {
 470       fprintf (stderr, "\nI/O base for MPU-401?\n"
 471                "The factory default is 330\n"
 472                "Enter the MPU-401 I/O base: ");
 473 
 474       num = ask_value ("%x", 0x330);
 475       fprintf (stderr, "MPU-401 I/O base set to %03x\n", num);
 476       printf ("#define MPU_BASE 0x%03x\n", num);
 477 
 478       fprintf (stderr, "\nIRQ number for MPU-401?\n"
 479                "Valid numbers are: 3, 4, 5, 7 and 9.\n"
 480                "The default value is 5.\n"
 481                "Enter the value: ");
 482 
 483       num = ask_value ("%d", 5);
 484       if (num == 6 || num < 3 || num > 15)      /* Used for floppy */
 485         {
 486 
 487           fprintf (stderr, "*** Illegal input! ***\n");
 488           num = 5;
 489         }
 490       fprintf (stderr, "MPU-401 IRQ set to %d\n", num);
 491       printf ("#define MPU_IRQ %d\n", num);
 492     }
 493 #endif
 494 
 495   if (selected_options & B (OPT_AUDIO))
 496     {
 497       def_size = 16384;
 498 
 499       if (selected_options & (B (OPT_SBPRO) | B (OPT_PAS)))
 500         def_size = 32768;
 501       if ((selected_options & B (OPT_PAS)) && !full_driver)
 502         def_size = 65536;       /* PAS16 alone */
 503 
 504       fprintf (stderr, "\nSelect the DMA buffer size (4096, 16384, 32768 or 65536 bytes)\n"
 505                "%d is recommended value for this configuration.\n"
 506                "Enter the value: ", def_size);
 507 
 508       num = ask_value ("%d", def_size);
 509       if (num != 4096 && num != 16384 && num != 32768 && num != 65536)
 510         {
 511 
 512           fprintf (stderr, "*** Illegal input! ***\n");
 513           num = def_size;
 514         }
 515       fprintf (stderr, "The DMA buffer size set to %d\n", num);
 516       printf ("#define DSP_BUFFSIZE %d\n", num);
 517     }
 518 
 519   printf ("#define SELECTED_SOUND_OPTIONS\t0x%08x\n", selected_options);
 520   fprintf (stderr, "The sound driver is now configured.\n");
 521 
 522   exit (0);
 523 }

/* [previous][next][first][last][top][bottom][index][help] */