home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / KERNEL-S / V1.0 / LINUX-1.0 / LINUX-1 / linux / drivers / sound / configure.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-14  |  15.3 KB  |  551 lines

  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.     int            default_answ;
  69.   }
  70.  
  71. hw_entry;
  72.  
  73.  
  74. /*
  75.  * The rule table for the driver options. The first field defines a set of
  76.  * options which must be selected before this entry can be selected. The
  77.  * second field is a set of options which are not allowed with this one. If
  78.  * the fourth field is zero, the option is selected without asking
  79.  * confirmation from the user.
  80.  * 
  81.  * With this version of the rule table it is possible to select just one type of
  82.  * hardware.
  83.  * 
  84.  * NOTE!    Keep the following table and the questions array in sync with the
  85.  * option numbering!
  86.  */
  87.  
  88. hw_entry        hw_table[] =
  89. {
  90. /* 0 */
  91.   {0, 0, "PAS", 1, 0, 0},
  92.   {0, 0, "SB", 1, 0, 0},
  93.   {0, B (OPT_PAS) | B (OPT_SB), "ADLIB", 1, 0, 0},
  94.  
  95. /* 3 */
  96.   {0, 0, "GUS", 1, 0, 0},
  97.   {0, 0, "MPU401", 1, 0, 0},
  98.   {B (OPT_SB), B (OPT_PAS), "SBPRO", 1, 0, 1},
  99.   {B (OPT_SB) | B (OPT_SBPRO), B (OPT_PAS), "SB16", 1, 0, 1},
  100.   {B (OPT_SB) | B (OPT_PAS) | B (OPT_GUS), 0, "AUDIO", 1, 0, 1},
  101.   {B (OPT_MPU401), 0, "MIDI_AUTO", 0, OPT_MIDI, 0},
  102.   {B (OPT_SB) | B (OPT_PAS) | B (OPT_MPU401) | B (OPT_GUS), 0, "MIDI", 1, 0, 1},
  103.   {B (OPT_ADLIB), 0, "YM3812_AUTO", 0, OPT_YM3812, 0},
  104.   {B (OPT_SB) | B (OPT_PAS) | B (OPT_ADLIB), B (OPT_YM3812_AUTO), "YM3812", 1, 0, 1},
  105. /* 10 */
  106.   {B (OPT_MIDI) | B (OPT_YM3812) | B (OPT_YM3812_AUTO) | B (OPT_GUS), 0, "SEQUENCER", 0, 0, 1},
  107.   {0, 0, "CHIP_MIDI", 1, 0, 0}
  108. };
  109.  
  110. char           *questions[] =
  111. {
  112.   "ProAudioSpectrum 16 support",
  113.   "SoundBlaster support",
  114.   "AdLib support",
  115.   "Gravis Ultrasound support",
  116.   "MPU-401 support (NOT for SB16)",
  117.  
  118.   "SoundBlaster Pro support",
  119.   "SoundBlaster 16 support",
  120.   "digitized voice support",
  121.   "This should not be asked",
  122.   "MIDI interface support",
  123.   "This should not be asked",
  124.   "FM synthesizer (YM3812/OPL-3) support",
  125.   "/dev/sequencer support",
  126.   "MIDI on CHIP support"
  127. };
  128.  
  129. unsigned long   selected_options = 0;
  130. int sb_dma = 0;
  131.  
  132. int
  133. can_select_option (int nr)
  134. {
  135.   switch (nr)
  136.     {
  137.     case 0:
  138.       fprintf (stderr, "The SoundBlaster, AdLib and ProAudioSpectrum\n"
  139.            "cards cannot be installed at the same time\n");
  140.       fprintf (stderr, "\nSelect at most one of them:\n");
  141.       fprintf (stderr, "    - ProAudioSpectrum 16\n");
  142.       fprintf (stderr, "    - SoundBlaster / SB Pro\n");
  143.       fprintf (stderr, "          (Could be selected with PAS16 also\n"
  144.            "      since there is a SB emulation on it)\n");
  145.       fprintf (stderr, "    - AdLib\n");
  146.       fprintf (stderr, "\nDon't enable SoundBlaster if you have GUS at 0x220!\n\n");
  147.       break;
  148.  
  149.     case OPT_LAST_MUTUAL + 1:
  150.       fprintf (stderr, "\nThe following cards should work with any other cards.\n"
  151.            "CAUTION! Don't enable MPU-401 if you don't have it.\n");
  152.       break;
  153.  
  154.     case OPT_HIGHLEVEL:
  155.       fprintf (stderr, "\nSelect one or more of the following options\n");
  156.       break;
  157.  
  158.  
  159.     }
  160.  
  161.   if (hw_table[nr].conditions)
  162.     if (!(hw_table[nr].conditions & selected_options))
  163.       return 0;
  164.  
  165.   if (hw_table[nr].exclusive_options)
  166.     if (hw_table[nr].exclusive_options & selected_options)
  167.       return 0;
  168.  
  169.   return 1;
  170. }
  171.  
  172. int
  173. think_positively (int def_answ)
  174. {
  175.   char            answ[512];
  176.   int             len;
  177.  
  178.   if ((len = read (0, &answ, sizeof (answ))) < 1)
  179.     {
  180.       fprintf (stderr, "\n\nERROR! Cannot read stdin\n");
  181.  
  182.       perror ("stdin");
  183.       printf ("#undef CONFIGURE_SOUNDCARD\n");
  184.       printf ("#undef KERNEL_SOUNDCARD\n");
  185.       exit (-1);
  186.     }
  187.  
  188.   if (len < 2)            /* There is an additional LF at the end */
  189.     return def_answ;
  190.  
  191.   answ[len - 1] = 0;
  192.  
  193.   if (!strcmp (answ, "y") || !strcmp (answ, "Y"))
  194.     return 1;
  195.  
  196.   return 0;
  197. }
  198.  
  199. int
  200. ask_value (char *format, int default_answer)
  201. {
  202.   char            answ[512];
  203.   int             len, num;
  204.  
  205. play_it_again_Sam:
  206.  
  207.   if ((len = read (0, &answ, sizeof (answ))) < 1)
  208.     {
  209.       fprintf (stderr, "\n\nERROR! Cannot read stdin\n");
  210.  
  211.       perror ("stdin");
  212.       printf ("#undef CONFIGURE_SOUNDCARD\n");
  213.       printf ("#undef KERNEL_SOUNDCARD\n");
  214.       exit (-1);
  215.     }
  216.  
  217.   if (len < 2)            /* There is an additional LF at the end */
  218.     return default_answer;
  219.  
  220.   answ[len - 1] = 0;
  221.  
  222.   if (sscanf (answ, format, &num) != 1)
  223.     {
  224.       fprintf (stderr, "Illegal format. Try again: ");
  225.       goto play_it_again_Sam;
  226.     }
  227.  
  228.   return num;
  229. }
  230.  
  231. int
  232. main (int argc, char *argv[])
  233. {
  234.   int             i, num, def_size, full_driver = 1;
  235.   char            answ[10];
  236.  
  237.   printf ("/*\tGenerated by configure. Don't edit!!!!\t*/\n\n");
  238.  
  239.   fprintf (stderr, "\nConfiguring the sound support\n\n");
  240.  
  241.   fprintf (stderr, "Do you want to include full version of the sound driver (n/y) ? ");
  242.  
  243.   if (think_positively (0))
  244.     {
  245.       selected_options = 0xffffffff & ~B (OPT_MPU401);
  246.       fprintf (stderr, "Note! MPU-401 driver was not enabled\n");
  247.       full_driver = 1;
  248.     }
  249.   else
  250.     {
  251.       fprintf (stderr, "Do you want to DISABLE the Sound Driver (n/y) ?");
  252.       if (think_positively (0))
  253.     {
  254.       printf ("#undef CONFIGURE_SOUNDCARD\n");
  255.       printf ("#undef KERNEL_SOUNDCARD\n");
  256.       exit (0);
  257.     }
  258.       /* Partial driver */
  259.  
  260.       full_driver = 0;
  261.  
  262.       for (i = 0; i <= OPT_LAST; i++)
  263.     if (can_select_option (i))
  264.       {
  265.         if (!(selected_options & B (i)))    /* Not selected yet */
  266.           if (!hw_table[i].verify)
  267.         {
  268.           if (hw_table[i].alias)
  269.             selected_options |= B (hw_table[i].alias);
  270.           else
  271.             selected_options |= B (i);
  272.         }
  273.           else
  274.         {
  275.           int def_answ = hw_table[i].default_answ;
  276.  
  277.           fprintf (stderr, 
  278.              def_answ ? "  %s (y/n) ? " : "  %s (n/y) ? ", 
  279.              questions[i]);
  280.           if (think_positively (def_answ))
  281.             if (hw_table[i].alias)
  282.               selected_options |= B (hw_table[i].alias);
  283.             else
  284.               selected_options |= B (i);
  285.         }
  286.       }
  287.     }
  288.  
  289.   if (selected_options & B(OPT_SB16))
  290.      selected_options |= B(OPT_SBPRO);
  291.  
  292.   if (!(selected_options & ANY_DEVS))
  293.     {
  294.       printf ("#undef CONFIGURE_SOUNDCARD\n");
  295.       printf ("#undef KERNEL_SOUNDCARD\n");
  296.       fprintf (stderr, "\n*** This combination is useless. Sound driver disabled!!! ***\n\n");
  297.       exit (0);
  298.     }
  299.   else
  300.     printf ("#define KERNEL_SOUNDCARD\n");
  301.  
  302.   for (i = 0; i <= OPT_LAST; i++)
  303.     if (!hw_table[i].alias)
  304.       if (selected_options & B (i))
  305.     printf ("#undef  EXCLUDE_%s\n", hw_table[i].macro);
  306.       else
  307.     printf ("#define EXCLUDE_%s\n", hw_table[i].macro);
  308.  
  309.  
  310.   printf ("#define EXCLUDE_PRO_MIDI\n");
  311.   printf ("#define EXCLUDE_CHIP_MIDI\n");
  312.  
  313.   /*
  314.    * IRQ and DMA settings
  315.    */
  316.   printf ("\n");
  317.  
  318. #if defined(linux)
  319.   if (selected_options & B (OPT_SB) && selected_options & (B (OPT_AUDIO) | B (OPT_MIDI)))
  320.     {
  321.       fprintf (stderr, "\nIRQ number for SoundBlaster?\n"
  322.            "The IRQ adress is defined by the jumpers on your card and\n"
  323.            "7 is the factory default. Valid values are 9, 5, 7 and 10.\n"
  324.            "Enter the value: ");
  325.  
  326.       num = ask_value ("%d", 7);
  327.       if (num != 9 && num != 5 && num != 7 && num != 10)
  328.     {
  329.  
  330.       fprintf (stderr, "*** Illegal input! ***\n");
  331.       num = 7;
  332.     }
  333.       fprintf (stderr, "SoundBlaster IRQ set to %d\n", num);
  334.       printf ("#define SBC_IRQ %d\n", num);
  335.  
  336.       if (selected_options & B (OPT_SBPRO))
  337.     {
  338.  
  339.       fprintf (stderr, "\nDMA channel for SoundBlaster?\n"
  340.            "For SB 1.0, 1.5 and 2.0 this MUST be 1\n"
  341.            "SB Pro supports DMA channels 0, 1 and 3 (jumper)\n"
  342.            "For SB16 give the 8 bit DMA# here\n"
  343.            "The default value is 1\n"
  344.            "Enter the value: ");
  345.  
  346.       num = ask_value ("%d", 1);
  347.       if (num < 0 || num > 3)
  348.         {
  349.  
  350.           fprintf (stderr, "*** Illegal input! ***\n");
  351.           num = 1;
  352.         }
  353.       fprintf (stderr, "SoundBlaster DMA set to %d\n", num);
  354.       printf ("#define SBC_DMA %d\n", num);
  355.       sb_dma = num;
  356.     }
  357.  
  358.       if (selected_options & B (OPT_SB16))
  359.     {
  360.  
  361.       fprintf (stderr, "\n16 bit DMA channel for SoundBlaster 16?\n"
  362.              "Possible values are 5, 6 or 7\n"
  363.            "The default value is 6\n"
  364.            "Enter the value: ");
  365.  
  366.       num = ask_value ("%d", 6);
  367.       if ((num < 5 || num > 7) && (num != sb_dma))
  368.         {
  369.  
  370.           fprintf (stderr, "*** Illegal input! ***\n");
  371.           num = 6;
  372.         }
  373.       fprintf (stderr, "SoundBlaster DMA set to %d\n", num);
  374.       printf ("#define SB16_DMA %d\n", num);
  375.  
  376.           fprintf (stderr, "\nI/O base for SB16 Midi?\n"
  377.            "Possible values are 300 and 330\n"
  378.            "The factory default is 330\n"
  379.            "Enter the SB16 Midi I/O base: ");
  380.  
  381.           num = ask_value ("%x", 0x330);
  382.           fprintf (stderr, "SB16 Midi I/O base set to %03x\n", num);
  383.           printf ("#define SB16MIDI_BASE 0x%03x\n", num);
  384.     }
  385.     }
  386.  
  387.   if (selected_options & B (OPT_PAS))
  388.     {
  389.       if (selected_options & (B (OPT_AUDIO) | B (OPT_MIDI)))
  390.     {
  391.       fprintf (stderr, "\nIRQ number for ProAudioSpectrum?\n"
  392.            "The recommended value is the IRQ used under DOS.\n"
  393.            "Please refer to the ProAudioSpectrum User's Guide.\n"
  394.            "The default value is 10.\n"
  395.            "Enter the value: ");
  396.  
  397.       num = ask_value ("%d", 10);
  398.       if (num == 6 || num < 3 || num > 15 || num == 2)    /* Illegal */
  399.         {
  400.  
  401.           fprintf (stderr, "*** Illegal input! ***\n");
  402.           num = 10;
  403.         }
  404.       fprintf (stderr, "ProAudioSpectrum IRQ set to %d\n", num);
  405.       printf ("#define PAS_IRQ %d\n", num);
  406.     }
  407.  
  408.       if (selected_options & B (OPT_AUDIO))
  409.     {
  410.       fprintf (stderr, "\nDMA number for ProAudioSpectrum?\n"
  411.            "The recommended value is the DMA channel under DOS.\n"
  412.            "Please refer to the ProAudioSpectrum User's Guide.\n"
  413.            "The default value is 3\n"
  414.            "Enter the value: ");
  415.  
  416.       num = ask_value ("%d", 3);
  417.       if (num == 4 || num < 0 || num > 7)
  418.         {
  419.  
  420.           fprintf (stderr, "*** Illegal input! ***\n");
  421.           num = 3;
  422.         }
  423.       fprintf (stderr, "\nProAudioSpectrum DMA set to %d\n", num);
  424.       printf ("#define PAS_DMA %d\n", num);
  425.     }
  426.     }
  427.  
  428.   if (selected_options & B (OPT_GUS))
  429.     {
  430.       fprintf (stderr, "\nI/O base for Gravis Ultrasound?\n"
  431.            "Valid choises are 210, 220, 230, 240, 250 or 260\n"
  432.            "The factory default is 220\n"
  433.            "Enter the GUS I/O base: ");
  434.  
  435.       num = ask_value ("%x", 0x220);
  436.       if ((num > 0x260) || ((num & 0xf0f) != 0x200) || ((num & 0x0f0) > 0x060))
  437.     {
  438.  
  439.       fprintf (stderr, "*** Illegal input! ***\n");
  440.       num = 0x220;
  441.     }
  442.  
  443.       if ((selected_options & B (OPT_SB)) && (num == 0x220))
  444.     {
  445.       fprintf (stderr, "FATAL ERROR!!!!!!!!!!!!!!\n"
  446.            "\t0x220 cannot be used if SoundBlaster is enabled.\n"
  447.            "\tRun the config again.\n");
  448.       printf ("#undef CONFIGURE_SOUNDCARD\n");
  449.       printf ("#undef KERNEL_SOUNDCARD\n");
  450.       exit (-1);
  451.     }
  452.       fprintf (stderr, "GUS I/O base set to %03x\n", num);
  453.       printf ("#define GUS_BASE 0x%03x\n", num);
  454.  
  455.       fprintf (stderr, "\nIRQ number for Gravis UltraSound?\n"
  456.            "The recommended value is the IRQ used under DOS.\n"
  457.            "Please refer to the Gravis Ultrasound User's Guide.\n"
  458.            "The default value is 15.\n"
  459.            "Enter the value: ");
  460.  
  461.       num = ask_value ("%d", 15);
  462.       if (num == 6 || num < 3 || num > 15 || num == 2)    /* Invalid */
  463.     {
  464.  
  465.       fprintf (stderr, "*** Illegal input! ***\n");
  466.       num = 15;
  467.     }
  468.       fprintf (stderr, "Gravis UltraSound IRQ set to %d\n", num);
  469.       printf ("#define GUS_IRQ %d\n", num);
  470.  
  471.       fprintf (stderr, "\nDMA number for Gravis UltraSound?\n"
  472.            "The recommended value is the DMA channel under DOS.\n"
  473.            "Please refer to the Gravis Ultrasound User's Guide.\n"
  474.            "The default value is 6\n"
  475.            "Enter the value: ");
  476.  
  477.       num = ask_value ("%d", 6);
  478.       if (num == 4 || num < 0 || num > 7)
  479.     {
  480.       fprintf (stderr, "*** Illegal input! ***\n");
  481.       num = 6;
  482.     }
  483.       fprintf (stderr, "\nGravis UltraSound DMA set to %d\n", num);
  484.       printf ("#define GUS_DMA %d\n", num);
  485.     }
  486.  
  487.   if (selected_options & B (OPT_MPU401))
  488.     {
  489.       fprintf (stderr, "\nI/O base for MPU-401?\n"
  490.            "The factory default is 330\n"
  491.            "Enter the MPU-401 I/O base: ");
  492.  
  493.       num = ask_value ("%x", 0x330);
  494.       fprintf (stderr, "MPU-401 I/O base set to %03x\n", num);
  495.       printf ("#define MPU_BASE 0x%03x\n", num);
  496.  
  497.       fprintf (stderr, "\nIRQ number for MPU-401?\n"
  498.            "Valid numbers are: 3, 4, 5, 7 and 9(=2).\n"
  499.            "The default value is 5.\n"
  500.            "Enter the value: ");
  501.  
  502.       num = ask_value ("%d", 5);
  503.       if (num == 6 || num < 3 || num > 15)    /* Used for floppy */
  504.     {
  505.  
  506.       fprintf (stderr, "*** Illegal input! ***\n");
  507.       num = 5;
  508.     }
  509.       fprintf (stderr, "MPU-401 IRQ set to %d\n", num);
  510.       printf ("#define MPU_IRQ %d\n", num);
  511.     }
  512. #endif
  513.  
  514.   if (selected_options & B (OPT_AUDIO))
  515.     {
  516.       def_size = 16384;
  517.  
  518.       if (selected_options & (B (OPT_SBPRO) | B (OPT_PAS) | B(OPT_SB16)))
  519.     def_size = 32768;
  520.  
  521. #ifndef __386BSD__
  522.       if (((selected_options & B (OPT_PAS)) || (selected_options & B (OPT_SB16))) && 
  523.           !full_driver)
  524.     def_size = 65536;    /* PAS16 or SB16 */
  525. #endif
  526.  
  527.       fprintf (stderr, "\nSelect the DMA buffer size (4096, 16384, 32768 or 65536 bytes)\n"
  528.            "%d is recommended value for this configuration.\n"
  529.            "Enter the value: ", def_size);
  530.  
  531.       num = ask_value ("%d", def_size);
  532.       if (num != 4096 && num != 16384 && num != 32768 && num != 65536)
  533.     {
  534.  
  535.       fprintf (stderr, "*** Illegal input! ***\n");
  536.       num = def_size;
  537.     }
  538.       fprintf (stderr, "The DMA buffer size set to %d\n", num);
  539.       printf ("#define DSP_BUFFSIZE %d\n", num);
  540.     }
  541.  
  542.   printf ("#define SELECTED_SOUND_OPTIONS\t0x%08x\n", selected_options);
  543.   fprintf (stderr, "The sound driver is now configured.\n");
  544.  
  545. #if defined(SCO) || defined(ISC) || defined(SYSV)
  546.     fprintf(stderr, "Rember to update the System file\n");
  547. #endif
  548.  
  549.   exit (0);
  550. }
  551.