home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / config.c < prev    next >
Text File  |  1998-06-08  |  13KB  |  393 lines

  1. /*
  2. THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
  3. SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
  4. END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
  5. ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
  6. IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
  7. SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
  8. FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
  9. CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
  10. AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
  11. COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  12. */
  13. /*
  14.  * $Source: f:/miner/source/main/rcs/config.c $
  15.  * $Revision: 2.2 $
  16.  * $Author: john $
  17.  * $Date: 1995/03/27 09:42:59 $
  18.  * 
  19.  * contains routine(s) to read in the configuration file which contains
  20.  * game configuration stuff like detail level, sound card, etc
  21.  * 
  22.  * $Log: config.c $
  23.  * Revision 2.2  1995/03/27  09:42:59  john
  24.  * Added VR Settings in config file.
  25.  * 
  26.  * Revision 2.1  1995/03/16  11:20:40  john
  27.  * Put in support for Crystal Lake soundcard.
  28.  * 
  29.  * Revision 2.0  1995/02/27  11:30:13  john
  30.  * New version 2.0, which has no anonymous unions, builds with
  31.  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
  32.  * 
  33.  * Revision 1.14  1995/02/11  16:19:36  john
  34.  * Added code to make the default mission be the one last played.
  35.  * 
  36.  * Revision 1.13  1995/01/18  13:23:24  matt
  37.  * Made curtom detail level vars initialize properly at load
  38.  * 
  39.  * Revision 1.12  1995/01/04  22:15:36  matt
  40.  * Fixed stupid bug using scanf() to read bytes
  41.  * 
  42.  * Revision 1.11  1995/01/04  13:14:21  matt
  43.  * Made custom detail level settings save in config file
  44.  * 
  45.  * Revision 1.10  1994/12/12  21:35:09  john
  46.  * *** empty log message ***
  47.  * 
  48.  * Revision 1.9  1994/12/12  21:31:51  john
  49.  * Made volume work better by making sure volumes are valid
  50.  * and set correctly at program startup.
  51.  * 
  52.  * Revision 1.8  1994/12/12  13:58:01  john
  53.  * MAde -nomusic work.
  54.  * Fixed GUS hang at exit by deinitializing digi before midi.
  55.  * 
  56.  * Revision 1.7  1994/12/08  10:01:33  john
  57.  * Changed the way the player callsign stuff works.
  58.  * 
  59.  * Revision 1.6  1994/12/01  11:24:07  john
  60.  * Made volume/gamma/joystick sliders all be the same length.  0-->8.
  61.  * 
  62.  * Revision 1.5  1994/11/29  02:01:07  john
  63.  * Added code to look at -volume command line arg.
  64.  * 
  65.  * Revision 1.4  1994/11/14  20:14:11  john
  66.  * Fixed some warnings.
  67.  * 
  68.  * Revision 1.3  1994/11/14  19:51:01  john
  69.  * Added joystick cal values to descent.cfg.
  70.  * 
  71.  * Revision 1.2  1994/11/14  17:53:09  allender
  72.  * read and write descent.cfg file
  73.  * 
  74.  * Revision 1.1  1994/11/14  16:28:08  allender
  75.  * Initial revision
  76.  * 
  77.  * 
  78.  */
  79.  
  80. #include <stdio.h>
  81. #include <stdlib.h>
  82. #include <string.h>
  83. #include <ctype.h>
  84. #include <conio.h>
  85. #include <dos.h>
  86.  
  87. #include "types.h"
  88. #include "game.h"
  89. #include "digi.h"
  90. #include "kconfig.h"
  91. #include "palette.h"
  92. #include "joy.h"
  93. #include "args.h"
  94. #include "player.h"
  95. #include "mission.h"
  96.  
  97. #pragma pack (4);                        // Use 32-bit packing!
  98. #pragma off (check_stack);            // No stack checking!
  99. //#include "sos.h"//These sos headers are part of a commercial library, and aren't included-KRB
  100. //#include "sosm.h"
  101.  
  102. #pragma off (unreferenced)
  103. static char rcsid[] = "$Id: config.c 2.2 1995/03/27 09:42:59 john Exp $";
  104. #pragma on (unreferenced)
  105.  
  106. static char *digi_dev_str = "DigiDeviceID";
  107. static char *digi_port_str = "DigiPort";
  108. static char *digi_irq_str = "DigiIrq";
  109. static char *digi_dma_str = "DigiDma";
  110. static char *digi_volume_str = "DigiVolume";
  111. static char *midi_volume_str = "MidiVolume";
  112. static char *midi_dev_str = "MidiDeviceID";
  113. static char *midi_port_str = "MidiPort";
  114. static char *detail_level_str = "DetailLevel";
  115. static char *gamma_level_str = "GammaLevel";
  116. static char *stereo_rev_str = "StereoReverse";
  117. static char *joystick_min_str = "JoystickMin";
  118. static char *joystick_max_str = "JoystickMax";
  119. static char *joystick_cen_str = "JoystickCen";
  120. static char *last_player_str = "LastPlayer";
  121. static char *last_mission_str = "LastMission";
  122. static char *config_vr_type_str = "VR_type";
  123. static char *config_vr_tracking_str = "VR_tracking";
  124.  
  125.  
  126. char config_last_player[CALLSIGN_LEN+1] = "";
  127. char config_last_mission[MISSION_NAME_LEN+1] = "";
  128.  
  129. int Config_digi_type = 0;
  130. int Config_midi_type = 0;
  131.  
  132. int Config_vr_type = 0;
  133. int Config_vr_tracking = 0;
  134.  
  135. extern byte    Object_complexity, Object_detail, Wall_detail, Wall_render_depth, Debris_amount, SoundChannels;
  136.  
  137. void set_custom_detail_vars(void);
  138.  
  139.  
  140. #define CL_MC0 0xF8F
  141. #define CL_MC1 0xF8D
  142.  
  143. void CrystalLakeWriteMCP( ushort mc_addr, ubyte mc_data )
  144. {
  145.     _disable();
  146.     outp( CL_MC0, 0xE2 );                // Write password
  147.     outp( mc_addr, mc_data );        // Write data
  148.     _enable();
  149. }
  150.  
  151. ubyte CrystalLakeReadMCP( ushort mc_addr )
  152. {
  153.     ubyte value;
  154.     _disable();
  155.     outp( CL_MC0, 0xE2 );        // Write password
  156.     value = inp( mc_addr );        // Read data
  157.     _enable();
  158.     return value;
  159. }
  160.  
  161. void CrystalLakeSetSB()
  162. {
  163.     ubyte tmp;
  164.     tmp = CrystalLakeReadMCP( CL_MC1 );
  165.     tmp &= 0x7F;
  166.     CrystalLakeWriteMCP( CL_MC1, tmp );
  167. }
  168.  
  169. void CrystalLakeSetWSS()
  170. {
  171.     ubyte tmp;
  172.     tmp = CrystalLakeReadMCP( CL_MC1 );
  173.     tmp |= 0x80;
  174.     CrystalLakeWriteMCP( CL_MC1, tmp );
  175. }
  176.  
  177. int ReadConfigFile()
  178. {
  179.     FILE *infile;
  180.     char line[80], *token, *value, *ptr;
  181.     ubyte gamma;
  182.     int joy_axis_min[4];
  183.     int joy_axis_center[4];
  184.     int joy_axis_max[4];
  185.     int i;
  186.  
  187.     strcpy( config_last_player, "" );
  188.  
  189.     joy_axis_min[0] = joy_axis_min[1] = joy_axis_min[2] = joy_axis_min[3] = 0;
  190.     joy_axis_max[0] = joy_axis_max[1] = joy_axis_max[2] = joy_axis_max[3] = 0;
  191.     joy_axis_center[0] = joy_axis_center[1] = joy_axis_center[2] = joy_axis_center[3] = 0;
  192.     joy_set_cal_vals(joy_axis_min, joy_axis_center, joy_axis_max);
  193.  
  194.     digi_driver_board = 0;
  195.     digi_driver_port = 0;
  196.     digi_driver_irq = 0;
  197.     digi_driver_dma = 0;
  198.  
  199.     digi_midi_type = 0;
  200.     digi_midi_port = 0;
  201.  
  202.     Config_digi_volume = 4;
  203.     Config_midi_volume = 4;
  204.     Config_control_type = 0;
  205.     Config_channels_reversed = 0;
  206.  
  207.     infile = fopen("descent.cfg", "rt");
  208.     if (infile == NULL) {
  209.         return 1;
  210.     }
  211.     while (!feof(infile)) {
  212.         memset(line, 0, 80);
  213.         fgets(line, 80, infile);
  214.         ptr = &(line[0]);
  215.         while (isspace(*ptr))
  216.             ptr++;
  217.         if (*ptr != '\0') {
  218.             token = strtok(ptr, "=");
  219.             value = strtok(NULL, "=");
  220.             if (!strcmp(token, digi_dev_str))
  221.                 digi_driver_board = strtol(value, NULL, 16);
  222.             else if (!strcmp(token, digi_port_str))
  223.                 digi_driver_port = strtol(value, NULL, 16);
  224.             else if (!strcmp(token, digi_irq_str))
  225.                 digi_driver_irq = strtol(value, NULL, 10);
  226.             else if (!strcmp(token, digi_dma_str))
  227.                 digi_driver_dma = strtol(value, NULL, 10);
  228.             else if (!strcmp(token, digi_volume_str))
  229.                 Config_digi_volume = strtol(value, NULL, 10);
  230.             else if (!strcmp(token, midi_dev_str))
  231.                 digi_midi_type = strtol(value, NULL, 16);
  232.             else if (!strcmp(token, midi_port_str))
  233.                 digi_midi_port = strtol(value, NULL, 16);
  234.             else if (!strcmp(token, midi_volume_str))
  235.                 Config_midi_volume = strtol(value, NULL, 10);
  236.             else if (!strcmp(token, stereo_rev_str))
  237.                 Config_channels_reversed = strtol(value, NULL, 10);
  238.             else if (!strcmp(token, gamma_level_str)) {
  239.                 gamma = strtol(value, NULL, 10);
  240.                 gr_palette_set_gamma( gamma );
  241.             }
  242.             else if (!strcmp(token, detail_level_str)) {
  243.                 Detail_level = strtol(value, NULL, 10);
  244.                 if (Detail_level == NUM_DETAIL_LEVELS-1) {
  245.                     int count,dummy,oc,od,wd,wrd,da,sc;
  246.  
  247.                     count = sscanf (value, "%d,%d,%d,%d,%d,%d,%d\n",&dummy,&oc,&od,&wd,&wrd,&da,&sc);
  248.  
  249.                     if (count == 7) {
  250.                         Object_complexity = oc;
  251.                         Object_detail = od;
  252.                         Wall_detail = wd;
  253.                         Wall_render_depth = wrd;
  254.                         Debris_amount = da;
  255.                         SoundChannels = sc;
  256.                         set_custom_detail_vars();
  257.                     }
  258.                 }
  259.             }
  260.             else if (!strcmp(token, joystick_min_str))    {
  261.                 sscanf( value, "%d,%d,%d,%d", &joy_axis_min[0], &joy_axis_min[1], &joy_axis_min[2], &joy_axis_min[3] );
  262.             } 
  263.             else if (!strcmp(token, joystick_max_str))    {
  264.                 sscanf( value, "%d,%d,%d,%d", &joy_axis_max[0], &joy_axis_max[1], &joy_axis_max[2], &joy_axis_max[3] );
  265.             }
  266.             else if (!strcmp(token, joystick_cen_str))    {
  267.                 sscanf( value, "%d,%d,%d,%d", &joy_axis_center[0], &joy_axis_center[1], &joy_axis_center[2], &joy_axis_center[3] );
  268.             }
  269.             else if (!strcmp(token, last_player_str))    {
  270.                 char * p;
  271.                 strncpy( config_last_player, value, CALLSIGN_LEN );
  272.                 p = strchr( config_last_player, '\n');
  273.                 if ( p ) *p = 0;
  274.             }
  275.             else if (!strcmp(token, last_mission_str))    {
  276.                 char * p;
  277.                 strncpy( config_last_mission, value, MISSION_NAME_LEN );
  278.                 p = strchr( config_last_mission, '\n');
  279.                 if ( p ) *p = 0;
  280.             } else if (!strcmp(token, config_vr_type_str)) {
  281.                 Config_vr_type = strtol(value, NULL, 10);
  282.             } else if (!strcmp(token, config_vr_tracking_str)) {
  283.                 Config_vr_tracking = strtol(value, NULL, 10);
  284.             }
  285.         }
  286.     }
  287.  
  288.     fclose(infile);
  289.  
  290.     i = FindArg( "-volume" );
  291.     
  292.     if ( i > 0 )    {
  293.         i = atoi( Args[i+1] );
  294.         if ( i < 0 ) i = 0;
  295.         if ( i > 100 ) i = 100;
  296.         Config_digi_volume = (i*8)/100;
  297.         Config_midi_volume = (i*8)/100;
  298.     }
  299.  
  300.     if ( Config_digi_volume > 8 ) Config_digi_volume = 8;
  301.  
  302.     if ( Config_midi_volume > 8 ) Config_midi_volume = 8;
  303.  
  304.     joy_set_cal_vals(joy_axis_min, joy_axis_center, joy_axis_max);
  305.     digi_set_volume( (Config_digi_volume*32768)/8, (Config_midi_volume*128)/8 );
  306. /*
  307.     printf( "DigiDeviceID: 0x%x\n", digi_driver_board );
  308.     printf( "DigiPort: 0x%x\n", digi_driver_port        );
  309.     printf( "DigiIrq: 0x%x\n",  digi_driver_irq        );
  310.     printf( "DigiDma: 0x%x\n",    digi_driver_dma    );
  311.     printf( "MidiDeviceID: 0x%x\n", digi_midi_type    );
  312.     printf( "MidiPort: 0x%x\n", digi_midi_port        );
  313.       key_getch();
  314. */
  315.  
  316.     Config_midi_type = digi_midi_type;
  317.     Config_digi_type = digi_driver_board;
  318.  
  319.     // HACK!!! 
  320.     //Hack to make the Crytal Lake look like Microsoft Sound System
  321.     if ( digi_driver_board == 0xe200 )    {
  322.         ubyte tmp;
  323.         tmp = CrystalLakeReadMCP( CL_MC1 );
  324.         if ( !(tmp & 0x80) )
  325.             atexit( CrystalLakeSetSB );        // Restore to SB when done.
  326.          CrystalLakeSetWSS();
  327.         digi_driver_board = 0;//_MICROSOFT_8_ST;<was this microsoft thing, but its irrelevant, because we have no sound here yet,being that its also undefined, I set it to 0 -KRB
  328.     }
  329.  
  330.     return 0;
  331. }
  332.  
  333. int WriteConfigFile()
  334. {
  335.     FILE *infile;
  336.     char str[256];
  337.     int joy_axis_min[4];
  338.     int joy_axis_center[4];
  339.     int joy_axis_max[4];
  340.     ubyte gamma = gr_palette_get_gamma();
  341.     
  342.     joy_get_cal_vals(joy_axis_min, joy_axis_center, joy_axis_max);
  343.  
  344.     infile = fopen("descent.cfg", "wt");
  345.     if (infile == NULL) {
  346.         return 1;
  347.     }
  348.     sprintf (str, "%s=0x%x\n", digi_dev_str, Config_digi_type);
  349.     fputs(str, infile);
  350.     sprintf (str, "%s=0x%x\n", digi_port_str, digi_driver_port);
  351.     fputs(str, infile);
  352.     sprintf (str, "%s=%d\n", digi_irq_str, digi_driver_irq);
  353.     fputs(str, infile);
  354.     sprintf (str, "%s=%d\n", digi_dma_str, digi_driver_dma);
  355.     fputs(str, infile);
  356.     sprintf (str, "%s=%d\n", digi_volume_str, Config_digi_volume);
  357.     fputs(str, infile);
  358.     sprintf (str, "%s=0x%x\n", midi_dev_str, Config_midi_type);
  359.     fputs(str, infile);
  360.     sprintf (str, "%s=0x%x\n", midi_port_str, digi_midi_port);
  361.     fputs(str, infile);
  362.     sprintf (str, "%s=%d\n", midi_volume_str, Config_midi_volume);
  363.     fputs(str, infile);
  364.     sprintf (str, "%s=%d\n", stereo_rev_str, Config_channels_reversed);
  365.     fputs(str, infile);
  366.     sprintf (str, "%s=%d\n", gamma_level_str, gamma);
  367.     fputs(str, infile);
  368.     if (Detail_level == NUM_DETAIL_LEVELS-1)
  369.         sprintf (str, "%s=%d,%d,%d,%d,%d,%d,%d\n", detail_level_str, Detail_level,
  370.                 Object_complexity,Object_detail,Wall_detail,Wall_render_depth,Debris_amount,SoundChannels);
  371.     else
  372.         sprintf (str, "%s=%d\n", detail_level_str, Detail_level);
  373.     fputs(str, infile);
  374.     sprintf (str, "%s=%d,%d,%d,%d\n", joystick_min_str, joy_axis_min[0], joy_axis_min[1], joy_axis_min[2], joy_axis_min[3] );
  375.     fputs(str, infile);
  376.     sprintf (str, "%s=%d,%d,%d,%d\n", joystick_cen_str, joy_axis_center[0], joy_axis_center[1], joy_axis_center[2], joy_axis_center[3] );
  377.     fputs(str, infile);
  378.     sprintf (str, "%s=%d,%d,%d,%d\n", joystick_max_str, joy_axis_max[0], joy_axis_max[1], joy_axis_max[2], joy_axis_max[3] );
  379.     fputs(str, infile);
  380.     sprintf (str, "%s=%s\n", last_player_str, Players[Player_num].callsign );
  381.     fputs(str, infile);
  382.     sprintf (str, "%s=%s\n", last_mission_str, config_last_mission );
  383.     fputs(str, infile);
  384.     sprintf (str, "%s=%d\n", config_vr_type_str, Config_vr_type );
  385.     fputs(str, infile);
  386.     sprintf (str, "%s=%d\n", config_vr_tracking_str, Config_vr_tracking );
  387.     fputs(str, infile);
  388.     fclose(infile);
  389.     return 0;
  390. }        
  391.  
  392. 
  393.