home *** CD-ROM | disk | FTP | other *** search
/ Amiga ACS 1998 #6 / amigaacscoverdisc1998-061998.iso / games / descent / source / main / inferno.c < prev    next >
Text File  |  1998-06-08  |  55KB  |  1,895 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. /* $Source: f:/miner/source/main/rcs/inferno.c $
  14.  * $Revision: 2.36 $
  15.  * $Author: john $
  16.  * $Date: 1996/01/05 16:52:16 $
  17.  *
  18.  * main() for Inferno  
  19.  *
  20.  * $Log: inferno.c $
  21.  * Revision 2.36  1996/01/05  16:52:16  john
  22.  * Improved 3d stuff.
  23.  * 
  24.  * Revision 2.35  1995/10/07  13:20:06  john
  25.  * Added new modes for LCDBIOS, also added support for -JoyNice,
  26.  * and added Shift+F1-F4 to controls various stereoscopic params.
  27.  * 
  28.  * Revision 2.34  1995/06/26  11:30:57  john
  29.  * Made registration/copyright screen go away after 5 minutes.
  30.  * 
  31.  * Revision 2.33  1995/05/31  14:26:55  unknown
  32.  * Fixed ugly spacing.
  33.  * 
  34.  * Revision 2.32  1995/05/26  16:15:28  john
  35.  * Split SATURN into define's for requiring cd, using cd, etc.
  36.  * Also started adding all the Rockwell stuff.
  37.  * 
  38.  * Revision 2.31  1995/05/11  13:30:01  john
  39.  * Changed 3dbios detection to work like Didde Kim wanted it to.
  40.  * 
  41.  * Revision 2.30  1995/05/08  13:53:50  john
  42.  * Added code to read vipport environemnt variable.
  43.  * 
  44.  * Revision 2.29  1995/05/08  11:26:18  john
  45.  * Reversed eyes in 3dmax mode.
  46.  * 
  47.  * Revision 2.28  1995/05/08  11:24:06  john
  48.  * Made 3dmax work like Kasan wants it to.
  49.  * 
  50.  * Revision 2.27  1995/04/23  16:06:25  john
  51.  * Moved rinvul into modem/null modem menu.
  52.  * 
  53.  * Revision 2.26  1995/04/12  13:39:26  john
  54.  * Fixed bug with -lowmem not working.
  55.  * 
  56.  * Revision 2.25  1995/04/09  14:43:00  john
  57.  * Made Dynamic sockets not print Msockets for help.
  58.  * 
  59.  * Revision 2.24  1995/04/07  16:11:33  john
  60.  * Fixed problem with VFX display when using setup.
  61.  * 
  62.  * Revision 2.23  1995/04/06  15:40:51  john
  63.  * Synced VFX with setup #'s.
  64.  * 
  65.  * Revision 2.22  1995/04/06  12:12:53  john
  66.  * Fixed some bugs with 3dmax.
  67.  * 
  68.  * Revision 2.21  1995/03/30  16:36:51  mike
  69.  * text localization.
  70.  * 
  71.  * Revision 2.20  1995/03/29  15:33:52  john
  72.  * Added code to parse descent.net file.
  73.  * 
  74.  * Revision 2.19  1995/03/28  20:08:21  john
  75.  * Took away alternate server thing.
  76.  * 
  77.  * Revision 2.18  1995/03/27  09:43:08  john
  78.  * Added VR Settings in config file.
  79.  * 
  80.  * Revision 2.17  1995/03/23  19:02:21  john
  81.  * Added descent.net file use.
  82.  * 
  83.  * Revision 2.16  1995/03/23  12:25:11  john
  84.  * Moved IPX stuff into BIOS lib.
  85.  * 
  86.  * Revision 2.15  1995/03/21  16:52:34  john
  87.  * Added 320x100.
  88.  * 
  89.  * Revision 2.14  1995/03/21  14:40:33  john
  90.  * Ifdef'd out the NETWORK code.
  91.  * 
  92.  * Revision 2.13  1995/03/16  23:13:35  john
  93.  * Fixed bug with piggy paging in bitmap not checking for disk
  94.  * error, hence bogifying textures if you pull the CD out.
  95.  * 
  96.  * Revision 2.12  1995/03/16  21:45:22  john
  97.  * Made all paged modes have incompatible menus!
  98.  * 
  99.  * Revision 2.11  1995/03/15  15:19:34  john
  100.  * Took out code that changes to exe dir.
  101.  * 
  102.  * Revision 2.10  1995/03/15  14:33:37  john
  103.  * Added code to force the Descent CD-rom in the drive.
  104.  * 
  105.  * Revision 2.9  1995/03/15  11:41:27  john
  106.  * Better Saturn CD-ROM support.
  107.  * 
  108.  * Revision 2.8  1995/03/14  18:24:46  john
  109.  * Force Destination Saturn to use CD-ROM drive.
  110.  * 
  111.  * Revision 2.7  1995/03/14  16:22:35  john
  112.  * Added cdrom alternate directory stuff.
  113.  * 
  114.  * Revision 2.6  1995/03/13  15:17:19  john
  115.  * Added alternate hogfile directory.
  116.  * 
  117.  * Revision 2.5  1995/03/10  13:05:35  john
  118.  * Added code so that palette is correct for VFX1 helmets.
  119.  * 
  120.  * Revision 2.4  1995/03/07  15:12:43  john
  121.  * Fixed VFX,3dmax support.
  122.  * 
  123.  * Revision 2.3  1995/03/07  14:19:35  mike
  124.  * More destination saturn stuff.
  125.  * 
  126.  * Revision 2.2  1995/03/06  16:47:34  mike
  127.  * destination saturn
  128.  * 
  129.  * Revision 2.1  1995/03/06  15:24:06  john
  130.  * New screen techniques.
  131.  * 
  132.  * Revision 2.0  1995/02/27  11:31:29  john
  133.  * New version 2.0, which has no anonymous unions, builds with
  134.  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
  135.  * 
  136.  * Revision 1.295  1995/02/23  12:02:14  john
  137.  * Made mono  windows smaller.
  138.  * 
  139.  * Revision 1.294  1995/02/16  17:35:00  john
  140.  * Added code to allow dynamic socket changing.
  141.  * 
  142.  * Revision 1.293  1995/02/14  19:29:29  john
  143.  * Locked down critical error handler.
  144.  * 
  145.  * Revision 1.292  1995/02/14  15:29:20  john
  146.  * Added CR-LF to last line of menu help text.
  147.  * 
  148.  * Revision 1.291  1995/02/14  11:39:01  john
  149.  * Added polled/bios joystick readers.
  150.  * 
  151.  * Revision 1.290  1995/02/13  20:35:03  john
  152.  * Lintized
  153.  * 
  154.  * Revision 1.289  1995/02/11  16:20:02  john
  155.  * Added code to make the default mission be the one last played.
  156.  * 
  157.  * Revision 1.288  1995/02/11  15:54:13  rob
  158.  * changed cinvul to rinvul.
  159.  * 
  160.  * Revision 1.287  1995/02/11  14:48:43  rob
  161.  * Added max of 314 seconds to control invul. times
  162.  * 
  163.  * Revision 1.286  1995/02/11  12:42:01  john
  164.  * Added new song method, with FM bank switching..
  165.  * 
  166.  * Revision 1.285  1995/02/11  11:36:11  rob
  167.  * Added cinvul option.
  168.  * 
  169.  * Revision 1.284  1995/02/10  16:07:45  matt
  170.  * Took 'registered' out of printed info at startup
  171.  * 
  172.  * Revision 1.283  1995/02/09  22:00:59  john
  173.  * Added i-glasses tracking.
  174.  * 
  175.  * Revision 1.282  1995/02/02  11:11:27  john
  176.  * Added -nocyberman switch.
  177.  * 
  178.  * Revision 1.281  1995/02/01  16:35:14  john
  179.  * Linted.
  180.  * 
  181.  * Revision 1.280  1995/01/31  02:04:25  matt
  182.  * Fixed up cmdline help
  183.  * 
  184.  * Revision 1.279  1995/01/30  16:25:55  john
  185.  * Put back in graphical screen at program end.
  186.  * 
  187.  * Revision 1.278  1995/01/28  17:05:50  matt
  188.  * Changed imbedded copyright to use comma instead of hyphen
  189.  * 
  190.  * Revision 1.277  1995/01/28  15:57:26  john
  191.  * Made joystick calibration be only when wrong detected in
  192.  * menu or joystick axis changed.
  193.  * 
  194.  * Revision 1.276  1995/01/25  14:37:49  john
  195.  * Made joystick only prompt for calibration once...
  196.  * 
  197.  * Revision 1.275  1995/01/24  18:21:00  john
  198.  * Added Adam's text warning.
  199.  * 
  200.  * Revision 1.274  1995/01/22  15:57:20  john
  201.  * Took out code that printed warning out as game exited.
  202.  * 
  203.  * Revision 1.273  1995/01/22  13:31:35  matt
  204.  * Added load of mission 0, so there's always a default mission
  205.  * 
  206.  * Revision 1.272  1995/01/19  17:00:41  john
  207.  * Made save game work between levels.
  208.  * 
  209.  * Revision 1.271  1995/01/18  11:47:57  adam
  210.  * changed copyright notice
  211.  * 
  212.  * Revision 1.270  1995/01/15  13:42:42  john
  213.  * Moved low_mem cutoff higher.
  214.  * 
  215.  * Revision 1.269  1995/01/12  18:53:50  john
  216.  * Put ifdef EDITOR around the code that checked for 
  217.  * a 800x600 mode, because this trashed some people's
  218.  * computers (maybe) causing the mem allocation error in
  219.  * mouse.c that many users reported.
  220.  * 
  221.  * Revision 1.268  1995/01/12  11:41:42  john
  222.  * Added external control reading.
  223.  * 
  224.  * Revision 1.267  1995/01/06  10:26:55  john
  225.  * Added -nodoscheck command line switch.
  226.  * 
  227.  * Revision 1.266  1995/01/05  16:59:30  yuan
  228.  * Don't show orderform in editor version.
  229.  * 
  230.  * Revision 1.265  1994/12/28  15:33:51  john
  231.  * Added -slowjoy option.
  232.  * 
  233.  * Revision 1.264  1994/12/15  16:44:15  matt
  234.  * Added trademark notice
  235.  * 
  236.  * Revision 1.263  1994/12/14  20:13:59  john
  237.  * Reduced physical mem requments to 2 MB.
  238.  * 
  239.  * Revision 1.262  1994/12/14  19:06:17  john
  240.  * Lowered physical memory requments to 2 MB.
  241.  * 
  242.  * Revision 1.261  1994/12/14  09:41:29  allender
  243.  * change to drive and directory (if needed) of command line invocation
  244.  * so descent can be started from anywhere
  245.  * 
  246.  * Revision 1.260  1994/12/13  19:08:59  john
  247.  * Updated memory requirements.
  248.  * 
  249.  * Revision 1.259  1994/12/13  17:30:33  john
  250.  * Made the timer rate be changed right after initializing it.
  251.  * 
  252.  * Revision 1.258  1994/12/13  02:46:25  matt
  253.  * Added imbedded copyright
  254.  * 
  255.  * Revision 1.257  1994/12/13  02:06:46  john
  256.  * Added code to check stack used by descent... initial
  257.  * check showed stack used 35k/50k, so we decided it wasn't
  258.  * worth pursuing any more.
  259.  * 
  260.  * Revision 1.256  1994/12/11  23:17:54  john
  261.  * Added -nomusic.
  262.  * Added RealFrameTime.
  263.  * Put in a pause when sound initialization error.
  264.  * Made controlcen countdown and framerate use RealFrameTime.
  265.  * 
  266.  * Revision 1.255  1994/12/10  00:56:51  matt
  267.  * Added -nomusic to command-line help
  268.  * 
  269.  * Revision 1.254  1994/12/08  11:55:11  john
  270.  * Took out low memory print.
  271.  * 
  272.  * Revision 1.253  1994/12/08  11:51:00  john
  273.  * Made strcpy only copy corect number of chars,.
  274.  * 
  275.  * Revision 1.252  1994/12/08  00:38:29  matt
  276.  * Cleaned up banner messages
  277.  * 
  278.  * Revision 1.251  1994/12/07  19:14:52  matt
  279.  * Cleaned up command-line options and command-line help message
  280.  * 
  281.  * Revision 1.250  1994/12/06  19:33:28  john
  282.  * Fixed text of message to make more sense.
  283.  * 
  284.  * Revision 1.249  1994/12/06  16:30:55  john
  285.  * Neatend mem message,..
  286.  * 
  287.  * Revision 1.248  1994/12/06  16:17:35  john
  288.  * Added better mem checking/printing.
  289.  * 
  290.  * Revision 1.247  1994/12/06  14:14:37  john
  291.  * Added code to set low mem based on memory.
  292.  * 
  293.  * Revision 1.246  1994/12/05  12:29:09  allender
  294.  * removed ifdefs around -norun option
  295.  * 
  296.  * Revision 1.245  1994/12/05  00:03:30  matt
  297.  * Added -norun option to exit after writing pig
  298.  * 
  299.  * Revision 1.244  1994/12/04  14:47:01  john
  300.  * MAde the intro and menu be the same song.
  301.  * 
  302.  * Revision 1.243  1994/12/04  14:36:42  john
  303.  * Added menu music.
  304.  * 
  305.  * Revision 1.242  1994/12/02  13:50:17  yuan
  306.  * Localization.
  307.  * 
  308.  * Revision 1.241  1994/12/01  17:28:30  adam
  309.  * added end-shareware stuff
  310.  * 
  311.  * Revision 1.240  1994/11/30  12:10:57  adam
  312.  * added support for PCX titles/brief screens
  313.  * 
  314.  * Revision 1.239  1994/11/29  15:47:33  matt
  315.  * Moved error_init to start of game, so error message prints last
  316.  * 
  317.  * Revision 1.238  1994/11/29  14:19:22  jasen
  318.  * reduced dos mem requirments.
  319.  * 
  320.  * Revision 1.237  1994/11/29  03:46:35  john
  321.  * Added joystick sensitivity; Added sound channels to detail menu.  Removed -maxchannels
  322.  * command line arg.
  323.  * 
  324.  * Revision 1.236  1994/11/29  02:50:18  john
  325.  * Increased the amount a joystick has to be off before
  326.  * asking if they want to recalibrate their joystick.
  327.  * 
  328.  * Revision 1.235  1994/11/29  02:01:29  john
  329.  * Corrected some of the Descent command line help items.
  330.  * 
  331.  * Revision 1.234  1994/11/29  01:39:56  john
  332.  * Fixed minor bug with vfx_light help not wrapping correctly.
  333.  * 
  334.  * Revision 1.233  1994/11/28  21:34:17  john
  335.  * Reduced dos mem rqment to 70k.
  336.  * 
  337.  * Revision 1.232  1994/11/28  21:20:38  john
  338.  * First version with memory checking.
  339.  * 
  340.  * Revision 1.231  1994/11/28  20:06:21  rob
  341.  * Removed old serial param command line options.
  342.  * Added -noserial and -nonetwork to help listing.
  343.  * 
  344.  * Revision 1.230  1994/11/27  23:15:24  matt
  345.  * Made changes for new mprintf calling convention
  346.  * 
  347.  * Revision 1.229  1994/11/27  20:50:51  matt
  348.  * Don't set mem stuff if no debug
  349.  * 
  350.  * Revision 1.228  1994/11/27  18:46:21  matt
  351.  * Cleaned up command-line switches a little
  352.  * 
  353.  * Revision 1.227  1994/11/21  17:48:00  matt
  354.  * Added text to specifiy whether shareware or registered version
  355.  * 
  356.  * Revision 1.226  1994/11/21  14:44:20  john
  357.  * Fixed some bugs with setting volumes even when -nosound was used. Duh!
  358.  * 
  359.  * Revision 1.225  1994/11/21  13:53:42  matt
  360.  * Took out dos extender copyright
  361.  * 
  362.  * Revision 1.224  1994/11/21  09:46:54  john
  363.  * Added -showmeminfo parameter.
  364.  * 
  365.  * Revision 1.223  1994/11/20  22:12:05  mike
  366.  * Make some stuff dependent on SHAREWARE.
  367.  * 
  368.  * Revision 1.222  1994/11/20  21:14:09  john
  369.  * Changed -serial to -noserial.  MAde a 1 sec delay 
  370.  * before leaving title screen.  Clear keyboard buffer
  371.  * before asking for player name.
  372.  * 
  373.  * Revision 1.221  1994/11/19  15:20:20  mike
  374.  * rip out unused code and data
  375.  * 
  376.  * Revision 1.220  1994/11/17  19:14:29  adam
  377.  * prevented order screen from coming up when -notitles is used
  378.  * 
  379.  * Revision 1.219  1994/11/16  11:34:39  john
  380.  * Added -nottitle switch.
  381.  * 
  382.  * Revision 1.218  1994/11/16  10:05:53  john
  383.  * Added verbose messages.
  384.  * 
  385.  * Revision 1.217  1994/11/15  20:12:34  john
  386.  * Added back in inferno and parallax screens.
  387.  * 
  388.  * Revision 1.216  1994/11/15  18:35:30  john
  389.  * Added verbose setting.
  390.  * 
  391.  * Revision 1.215  1994/11/15  17:47:44  john
  392.  * Added ordering info screen.
  393.  * 
  394.  * Revision 1.214  1994/11/15  08:57:44  john
  395.  * Added MS-DOS version checking and -nonetwork option.
  396.  * 
  397.  * Revision 1.213  1994/11/15  08:34:32  john
  398.  * Added better error messages for IPX init.
  399.  * 
  400.  * Revision 1.212  1994/11/14  20:14:18  john
  401.  * Fixed some warnings.
  402.  * 
  403.  * Revision 1.211  1994/11/14  19:50:49  john
  404.  * Added joystick cal values to descent.cfg.
  405.  * 
  406.  * Revision 1.210  1994/11/14  17:56:44  allender
  407.  * make call to ReadConfigFile at startup
  408.  * 
  409.  * Revision 1.209  1994/11/14  11:41:55  john
  410.  * Fixed bug with editor/game sequencing.
  411.  * 
  412.  * Revision 1.208  1994/11/13  17:05:11  john
  413.  * Made the callsign entry be a list box and gave the ability
  414.  * to delete players.
  415.  * 
  416.  * Revision 1.207  1994/11/13  15:39:22  john
  417.  * Added critical error handler to game.  Took out -editor command line
  418.  * option because it didn't work anymore and wasn't worth fixing.  Made scores
  419.  * not use MINER enviroment variable on release version, and made scores
  420.  * not print an error if there is no descent.hi.
  421.  * 
  422.  * Revision 1.206  1994/11/10  20:53:29  john
  423.  * Used new sound install parameters.
  424.  * 
  425.  * Revision 1.205  1994/11/10  11:07:52  mike
  426.  * Set default detail level.
  427.  * 
  428.  * Revision 1.204  1994/11/09  13:45:43  matt
  429.  * Made -? work again for help
  430.  * 
  431.  * Revision 1.203  1994/11/09  10:55:58  matt
  432.  * Cleaned up initialization for editor -> game transitions
  433.  * 
  434.  * Revision 1.202  1994/11/07  21:35:47  matt
  435.  * Use new function iff_read_into_bitmap()
  436.  * 
  437.  * Revision 1.201  1994/11/05  17:22:16  john
  438.  * Fixed lots of sequencing problems with newdemo stuff.
  439.  * 
  440.  * Revision 1.200  1994/11/05  14:05:44  john
  441.  * Fixed fade transitions between all screens by making gr_palette_fade_in and out keep
  442.  * track of whether the palette is faded in or not.  Then, wherever the code needs to fade out,
  443.  * it just calls gr_palette_fade_out and it will fade out if it isn't already.  The same with fade_in.
  444.  * This eliminates the need for all the flags like Menu_fade_out, game_fade_in palette, etc.
  445.  * 
  446.  * Revision 1.199  1994/11/04  14:36:30  allender
  447.  * change Auto_demo meaning to mean autostart from menu only.  Use
  448.  * FindArgs when searching for AutoDemo from command line.  also,
  449.  * set N_Players to 1 when starting in editor mode.
  450.  * 
  451.  * Revision 1.198  1994/11/02  11:59:49  john
  452.  * Moved menu out of game into inferno main loop.
  453.  * 
  454.  * Revision 1.197  1994/11/01  17:57:39  mike
  455.  * -noscreens option to bypass all screens.
  456.  * 
  457.  * Revision 1.196  1994/10/28  15:42:34  allender
  458.  * don't register player if Autodemo is on
  459.  * 
  460.  * Revision 1.195  1994/10/28  10:58:01  matt
  461.  * Added copyright notice for DOS4GW
  462.  * 
  463.  * Revision 1.194  1994/10/20  21:26:48  matt
  464.  * Took out old serial name/number code, and put up message if this
  465.  * is a marked version.
  466.  * 
  467.  * Revision 1.193  1994/10/19  09:52:14  allender
  468.  * Print out who descent.exe belongs to if descent.exe is stamped.
  469.  * 
  470.  * Revision 1.192  1994/10/18  16:43:05  allender
  471.  * Added check for identifier stamp and time after which descent will
  472.  * no longer run.
  473.  * 
  474.  * Revision 1.191  1994/10/17  13:07:17  john
  475.  * Moved the descent.cfg info into the player config file.
  476.  * 
  477.  * Revision 1.190  1994/10/04  10:26:31  matt
  478.  * Support new menu fade in
  479.  * 
  480.  * Revision 1.189  1994/10/03  22:58:46  matt
  481.  * Changed some values of game_mode
  482.  * 
  483.  * Revision 1.188  1994/10/03  18:55:39  rob
  484.  * Changed defaults for com port settings.
  485.  * 
  486.  * Revision 1.187  1994/10/03  13:34:47  matt
  487.  * Added new (and hopefully better) game sequencing functions
  488.  * 
  489.  * Revision 1.186  1994/09/30  12:37:28  john
  490.  * Added midi,digi volume to configuration.
  491.  * 
  492.  * Revision 1.185  1994/09/30  10:08:48  john
  493.  * Changed sound stuff... made it so the reseting card doesn't hang, 
  494.  * made volume change only if sound is installed.
  495.  * 
  496.  * Revision 1.184  1994/09/28  17:25:00  matt
  497.  * Added first draft of game save/load system
  498.  * 
  499.  * Revision 1.183  1994/09/28  16:18:23  john
  500.  * Added capability to play midi song.
  501.  * 
  502.  * Revision 1.182  1994/09/28  11:31:18  john
  503.  * Made text output unbuffered.
  504.  * 
  505.  * Revision 1.181  1994/09/27  19:23:44  john
  506.  * Added -nojoystick and -nomouse
  507.  * 
  508.  * Revision 1.180  1994/09/24  16:55:29  rob
  509.  * No longer open COM port immediately upon program start.
  510.  * No longer set Network_active is serial_active is set.
  511.  * 
  512.  * Revision 1.179  1994/09/24  14:16:30  mike
  513.  * Support new game mode constants.
  514.  * 
  515.  * Revision 1.178  1994/09/22  17:52:31  rob
  516.  * Added Findargs hooks for -serial, -speed, and -com.
  517.  * 
  518.  * Revision 1.177  1994/09/22  16:14:11  john
  519.  * Redid intro sequecing.
  520.  * 
  521.  * Revision 1.176  1994/09/21  16:32:58  john
  522.  * Made mouse and keyboard init after bm_init. Why?
  523.  * Because it seems to work better under virtual 
  524.  * memory.
  525.  * 
  526.  * Revision 1.175  1994/09/21  16:27:52  john
  527.  * Added mouse_init
  528.  * 
  529.  * Revision 1.174  1994/09/20  15:14:10  matt
  530.  * New message for new VFX switches
  531.  * 
  532.  * Revision 1.173  1994/09/16  16:14:27  john
  533.  * Added acrade sequencing.
  534.  * 
  535.  * Revision 1.172  1994/09/16  11:49:52  john
  536.  * Added first version of arcade joystick support;
  537.  * Also fixed some bugs in kconfig.c, such as reading non-present
  538.  * joysticks, which killed frame rate, and not reading key_down_time
  539.  * when in slide mode or bank mode.
  540.  * 
  541.  * Revision 1.171  1994/09/15  16:11:35  john
  542.  * Added support for VFX1 head tracking. Fixed bug with memory over-
  543.  * write when using stereo mode.
  544.  * 
  545.  * Revision 1.170  1994/09/12  19:38:23  john
  546.  * Made some stuff that prints to the DOS screen go to the
  547.  * mono instead, since it really is debugging info.
  548.  * 
  549.  * Revision 1.169  1994/08/29  21:18:28  john
  550.  * First version of new keyboard/oystick remapping stuff.
  551.  * 
  552.  * Revision 1.168  1994/08/26  13:02:00  john
  553.  * Put high score system in.
  554.  * 
  555.  * Revision 1.167  1994/08/24  19:00:23  john
  556.  * Changed key_down_time to return fixed seconds instead of
  557.  * milliseconds.
  558.  * 
  559.  * Revision 1.166  1994/08/18  16:24:20  john
  560.  * changed socket to channel in text.
  561.  * 
  562.  * Revision 1.165  1994/08/18  16:16:51  john
  563.  * Added support for different sockets.
  564.  * 
  565.  * Revision 1.164  1994/08/18  10:47:53  john
  566.  * *** empty log message ***
  567.  * 
  568.  * Revision 1.163  1994/08/12  09:15:54  john
  569.  * *** empty log message ***
  570.  * 
  571.  * Revision 1.162  1994/08/12  03:11:19  john
  572.  * Made network be default off; Moved network options into
  573.  * main menu.  Made starting net game check that mines are the
  574.  * same.
  575.  * 
  576.  * Revision 1.161  1994/08/10  19:57:05  john
  577.  * Changed font stuff; Took out old menu; messed up lots of
  578.  * other stuff like game sequencing messages, etc.
  579.  * 
  580.  * Revision 1.160  1994/08/05  16:30:23  john
  581.  * Added capability to turn off network.
  582.  * 
  583.  * Revision 1.159  1994/08/04  19:42:51  matt
  584.  * Moved serial number & name (and version name) from inferno.c to inferno.ini
  585.  * 
  586.  * Revision 1.158  1994/08/03  10:30:23  matt
  587.  * Change cybermaxx switches, updated command-line help, and added serial number system
  588.  * 
  589.  * Revision 1.157  1994/07/29  18:30:10  matt
  590.  * New parms (lack of parms, actually) for g3_init()
  591.  * 
  592.  * Revision 1.156  1994/07/24  00:39:25  matt
  593.  * Added more text to TEX file; make NewGame() take a start level; made game
  594.  * load/save menus use open/close window funcs.
  595.  * 
  596.  * Revision 1.155  1994/07/21  21:31:27  john
  597.  * First cheapo version of VictorMaxx tracking.
  598.  * 
  599.  * Revision 1.154  1994/07/21  18:15:34  matt
  600.  * Ripped out a bunch of unused stuff
  601.  * 
  602.  * Revision 1.153  1994/07/21  17:59:10  matt
  603.  * Cleaned up initial mode game/editor code
  604.  * 
  605.  * Revision 1.152  1994/07/21  13:11:19  matt
  606.  * Ripped out remants of old demo system, and added demo only system that
  607.  * disables object movement and game options from menu.
  608.  * 
  609.  * Revision 1.151  1994/07/20  15:58:27  john
  610.  * First installment of ipx stuff.
  611.  * 
  612.  * Revision 1.150  1994/07/15  16:04:24  matt
  613.  * Changed comment for milestone 3 version
  614.  * 
  615.  * Revision 1.149  1994/07/15  13:59:24  matt
  616.  * Fixed stupid mistake I make in the last revision
  617.  * 
  618.  * Revision 1.148  1994/07/15  13:20:15  matt
  619.  * Updated comand-line help
  620.  * 
  621.  * Revision 1.147  1994/07/14  23:29:43  matt
  622.  * Open two mono debug messages, one for errors & one for spew
  623.  * 
  624.  * Revision 1.146  1994/07/09  22:48:05  matt
  625.  * Added localizable text
  626.  * 
  627.  * Revision 1.145  1994/07/02  13:49:47  matt
  628.  * Cleaned up includes
  629.  * 
  630.  * Revision 1.144  1994/06/30  20:04:43  john
  631.  * Added -joydef support.
  632.  * 
  633.  * Revision 1.143  1994/06/24  17:01:44  john
  634.  * Add VFX support; Took Game Sequencing, like EndGame and stuff and
  635.  * took it out of game.c and into gameseq.c
  636.  * 
  637.  */
  638.  
  639. #pragma off (unreferenced)
  640. static char rcsid[] = "$Id: inferno.c 2.36 1996/01/05 16:52:16 john Exp $";
  641. static char copyright[] = "DESCENT   COPYRIGHT (C) 1994,1995 PARALLAX SOFTWARE CORPORATION";
  642. #pragma on (unreferenced)
  643.  
  644. #include <io.h>
  645. #include <dos.h>
  646. #include <stdio.h>
  647. #include <malloc.h>
  648. #include <stdlib.h>
  649. #include <string.h>
  650. #include <conio.h>
  651. #include <time.h>
  652. #include <dos.h>
  653. #include <direct.h>
  654.  
  655. #include "gr.h"
  656. #include "ui.h"
  657. #include "mono.h"
  658. #include "key.h"
  659. #include "timer.h"
  660. #include "3d.h"
  661. #include "bm.h"
  662. #include "inferno.h"
  663. #include "error.h"
  664. #include "cflib.h"
  665. #include "div0.h"
  666. #include "game.h"
  667. #include "segment.h"        //for Side_to_verts
  668. #include "mem.h"
  669. #include "textures.h"
  670. #include "segpoint.h"
  671. #include "screens.h"
  672. #include "texmap.h"
  673. #include "texmerge.h"
  674. #include "menu.h"
  675. #include "wall.h"
  676. #include "switch.h"
  677. #include "polyobj.h"
  678. #include "effects.h"
  679. #include "digi.h"
  680. #include "iff.h"
  681. #include "pcx.h"
  682. #include "palette.h"
  683. #include "args.h"
  684. #include "sounds.h"
  685. #include "titles.h"
  686. #include "player.h"
  687. #include "text.h"
  688. #include "ipx.h"
  689. #include "newdemo.h"
  690. #include "victor.h"
  691. #include "network.h"
  692. #include "modem.h"
  693. #include "gamefont.h"
  694. #include "kconfig.h"
  695. #include "arcade.h"
  696. #include "coindev.h"
  697. #include "mouse.h"
  698. #include "joy.h"
  699. #include "dpmi.h"
  700. #include "newmenu.h"
  701. #include "desc_id.h"
  702. #include "config.h"
  703. #include "joydefs.h"
  704. #include "multi.h"
  705. #include "iglasses.h"
  706. #include "songs.h"
  707. #include "cfile.h"
  708. #include "cdrom.h"
  709. #include "gameseq.h"
  710.  
  711. #ifdef EDITOR
  712. #include "editor\editor.h"
  713. #include "editor\kdefs.h"
  714. #endif
  715.  
  716. #include "vers_id.h"
  717.  
  718. extern int Game_simuleyes_flag;
  719.  
  720. static const char desc_id_checksum_str[] = DESC_ID_CHKSUM;
  721. char desc_id_exit_num = 0;
  722.  
  723. int Function_mode=FMODE_MENU;        //game or editor?
  724. int Screen_mode=-1;                    //game screen or editor screen?
  725.  
  726. //--unused-- grs_bitmap Inferno_bitmap_title;
  727.  
  728. int WVIDEO_running=0;        //debugger can set to 1 if running
  729.  
  730. #ifdef EDITOR
  731. int Inferno_is_800x600_available = 0;
  732. #endif
  733.  
  734. //--unused-- int Cyberman_installed=0;            // SWIFT device present
  735.  
  736. void install_int3_handler(void);
  737.  
  738. int __far descent_critical_error_handler( unsigned deverr, unsigned errcode, unsigned far * devhdr );
  739.  
  740. #ifndef NDEBUG
  741. do_heap_check()
  742. {
  743.     int heap_status;
  744.  
  745.     heap_status = _heapset( 0xFF );
  746.     switch( heap_status )
  747.     {
  748.     case _HEAPBADBEGIN:
  749.         mprintf((1, "ERROR - heap is damaged\n"));
  750.         Int3();
  751.         break;
  752.     case _HEAPBADNODE:
  753.         mprintf((1, "ERROR - bad node in heap\n" ));
  754.         Int3();
  755.         break;
  756.     }
  757. }
  758. #endif
  759.  
  760. int registered_copy=0;
  761. char name_copy[sizeof(DESC_ID_STR)];
  762.  
  763. void
  764. check_id_checksum_and_date()
  765. {
  766.     const char name[] = DESC_ID_STR;
  767.     char time_str[] = DESC_DEAD_TIME;
  768.     int i, found;
  769.     unsigned long *checksum, test_checksum;
  770.     time_t current_time, saved_time;
  771.  
  772.     saved_time = (time_t)strtol(&(time_str[strlen(time_str) - 10]), NULL, 16);
  773.     if (saved_time == (time_t)0)
  774.         return;
  775.  
  776.     strcpy(name_copy,name);
  777.     registered_copy = 1;
  778.  
  779.     current_time = time(NULL);
  780.     if (current_time >= saved_time)
  781.         desc_id_exit_num = 1;
  782.  
  783.     test_checksum = 0;
  784.     for (i = 0; i < strlen(name); i++) {
  785.         found = 0;      
  786.         test_checksum += name[i];
  787.         if (((test_checksum / 2) * 2) != test_checksum)
  788.             found = 1;
  789.         test_checksum = test_checksum >> 1;
  790.         if (found)
  791.             test_checksum |= 0x80000000;
  792.     }
  793.     checksum = (unsigned long *)&(desc_id_checksum_str[0]);
  794.     if (test_checksum != *checksum)
  795.         desc_id_exit_num = 2;
  796.  
  797.     printf ("%s %s\n", TXT_REGISTRATION, name);
  798. }
  799.  
  800. int is_3dbios_installed()
  801. {
  802.     dpmi_real_regs rregs;
  803.     memset(&rregs,0,sizeof(dpmi_real_regs));
  804.     rregs.eax = 0x4ed0;
  805.     //rregs.ebx = 0x3d10;    
  806.     dpmi_real_int386x( 0x10, &rregs );
  807.     if ( (rregs.edx & 0xFFFF) != 0x3344 )
  808.         return 0;
  809.     else
  810.         return 1;
  811.  
  812. }
  813.  
  814.  
  815. int init_graphics()
  816. {
  817.     int result;
  818.  
  819.     result=gr_check_mode(SM_320x200C);
  820. #ifdef EDITOR
  821.     if ( result==0 )    
  822.         result=gr_check_mode(SM_800x600V);
  823. #endif
  824.  
  825.     switch( result )    {
  826.         case  0:        //Mode set OK
  827. #ifdef EDITOR
  828.                         Inferno_is_800x600_available = 1;
  829. #endif
  830.                         break;
  831.         case  1:        //No VGA adapter installed
  832.                         printf("%s\n", TXT_REQUIRES_VGA );
  833.                         return 1;
  834.         case 10:        //Error allocating selector for A0000h
  835.                         printf( "%s\n",TXT_ERROR_SELECTOR );
  836.                         return 1;
  837.         case 11:        //Not a valid mode support by gr.lib
  838.                         printf( "%s\n", TXT_ERROR_GRAPHICS );
  839.                         return 1;
  840. #ifdef EDITOR
  841.         case  3:        //Monitor doesn't support that VESA mode.
  842.         case  4:        //Video card doesn't support that VESA mode.
  843.  
  844.                         printf( "Your VESA driver or video hardware doesn't support 800x600 256-color mode.\n" );
  845.                         break;
  846.         case  5:        //No VESA driver found.
  847.                         printf( "No VESA driver detected.\n" );
  848.                         break;
  849.         case  2:        //Program doesn't support this VESA granularity
  850.         case  6:        //Bad Status after VESA call/
  851.         case  7:        //Not enough DOS memory to call VESA functions.
  852.         case  8:        //Error using DPMI.
  853.         case  9:        //Error setting logical line width.
  854.         default:
  855.                         printf( "Error %d using 800x600 256-color VESA mode.\n", result );
  856.                         break;
  857. #endif
  858.     }
  859.  
  860.     return 0;
  861. }
  862.  
  863. extern fix fixed_frametime;
  864.  
  865. // Returns 1 if ok, 0 if failed...
  866. int init_gameport()
  867. {
  868.     union REGS regs;
  869.  
  870.     memset(®s,0,sizeof(regs));
  871.     regs.x.eax = 0x8400;
  872.     regs.x.edx = 0xF0;
  873.    int386( 0x15, ®s, ®s );
  874.     if ( ( regs.x.eax & 0xFFFF ) == 'SG' )
  875.         return 1;
  876.     else
  877.         return 0;
  878. }
  879.  
  880. void check_dos_version()
  881. {
  882.     int major, minor;
  883.     union REGS regs;
  884.  
  885.     memset(®s,0,sizeof(regs));
  886.     regs.x.eax = 0x3000;                            // Get MS-DOS Version Number
  887.    int386( 0x21, ®s, ®s );
  888.  
  889.     major = regs.h.al;
  890.     minor = regs.h.ah;
  891.     
  892.     if ( major < 5 )    {
  893.         printf( "%s %d.d\n%s", TXT_DOS_VERSION_1, major, minor, TXT_DOS_VERSION_2);
  894.         exit(1);
  895.     }
  896.     //printf( "\nUsing MS-DOS %d.%d...\n", major, minor );
  897. }
  898.  
  899. void change_to_dir(char *cmd_line)
  900. {
  901.     char drive[_MAX_DRIVE], dir[_MAX_DIR], curdir[_MAX_DIR];
  902.     unsigned total, cur_drive;
  903.  
  904.     _splitpath(cmd_line, drive, dir, NULL, NULL);
  905.     dir[strlen(dir) - 1] = '\0';
  906.     if (drive[0] != '\0') {
  907.         _dos_getdrive(&cur_drive);
  908.         if (cur_drive != (drive[0] - 'A' + 1))
  909.             _dos_setdrive(drive[0] - 'A' + 1, &total);
  910.     }
  911.     getcwd(curdir, _MAX_DIR);
  912.     if (stricmp(&(curdir[2]), dir))
  913.         chdir(dir);
  914. }
  915.  
  916. void dos_check_file_handles(int num_required)
  917. {
  918.     int i, n;
  919.     FILE * fp[16];
  920.  
  921.     if ( num_required > 16 )
  922.         num_required = 16;
  923.  
  924.     n = 0;    
  925.     for (i=0; i<16; i++ )
  926.         fp[i] = NULL;
  927.     for (i=0; i<16; i++ )    {
  928.         fp[i] = fopen( "nul", "wb" );
  929.         if ( !fp[i] ) break;
  930.     }
  931.     n = i;
  932.     for (i=0; i<16; i++ )    {
  933.         if (fp[i])
  934.             fclose(fp[i]);
  935.     }
  936.     if ( n < num_required )    {
  937.         printf( "\n%s\n", TXT_NOT_ENOUGH_HANDLES );
  938.         printf( "------------------------\n" );
  939.         printf( "%d/%d %s\n", n, num_required, TXT_HANDLES_1 );
  940.         printf( "%s\n", TXT_HANDLES_2);
  941.         printf( "%s\n", TXT_HANDLES_3);
  942.         exit(1);
  943.     }
  944. }
  945.  
  946. #define NEEDED_DOS_MEMORY               ( 300*1024)        // 300 K
  947. #define NEEDED_LINEAR_MEMORY             (7680*1024)        // 7.5 MB
  948. #define LOW_PHYSICAL_MEMORY_CUTOFF    (5*1024*1024)    // 5.0 MB
  949. #define NEEDED_PHYSICAL_MEMORY        (2000*1024)        // 2000 KB
  950.  
  951. extern int piggy_low_memory;
  952.  
  953. void mem_int_to_string( int number, char *dest )
  954. {
  955.     int i,l,c;
  956.     char buffer[20],*p;
  957.  
  958.     sprintf( buffer, "%d", number );
  959.  
  960.     l = strlen(buffer);
  961.     if (l<=3) {
  962.         // Don't bother with less than 3 digits
  963.         sprintf( dest, "%d", number );
  964.         return;
  965.     }
  966.  
  967.     c = 0;
  968.     p=dest;
  969.     for (i=l-1; i>=0; i-- )    {
  970.         if (c==3) {
  971.             *p++=',';
  972.             c = 0;
  973.         }
  974.         c++;
  975.         *p++ = buffer[i];
  976.     }
  977.     *p++ = '\0';
  978.     strrev(dest);
  979. }
  980.  
  981. void check_memory()
  982. {
  983.     char text[32];
  984.  
  985.     printf( "\n%s\n", TXT_AVAILABLE_MEMORY);
  986.     printf( "----------------\n" );
  987.     mem_int_to_string( dpmi_dos_memory/1024, text );
  988.     printf( "Conventional: %7s KB\n", text );
  989.     mem_int_to_string( dpmi_physical_memory/1024, text );
  990.     printf( "Extended:     %7s KB\n", text );
  991.     if ( dpmi_available_memory > dpmi_physical_memory )    {
  992.         mem_int_to_string( (dpmi_available_memory-dpmi_physical_memory)/1024, text );
  993.     } else {
  994.         mem_int_to_string( 0, text );
  995.     }
  996.     printf( "Virtual:      %7s KB\n", text );
  997.     printf( "\n" );
  998.  
  999.     if ( dpmi_dos_memory < NEEDED_DOS_MEMORY )    {
  1000.         printf( "%d %s\n", NEEDED_DOS_MEMORY - dpmi_dos_memory, TXT_MEMORY_CONFIG );
  1001.         exit(1);
  1002.     }
  1003.  
  1004.     if ( dpmi_available_memory < NEEDED_LINEAR_MEMORY )    {
  1005.         if ( dpmi_virtual_memory )    {
  1006.             printf( "%d %s\n", NEEDED_LINEAR_MEMORY - dpmi_available_memory, TXT_RECONFIGURE_VMM );
  1007.         } else {
  1008.             printf( "%d %s\n", NEEDED_LINEAR_MEMORY - dpmi_available_memory, TXT_MORE_MEMORY );
  1009.             printf( "%s\n", TXT_MORE_MEMORY_2);
  1010.         }
  1011.         exit(1);
  1012.     }
  1013.  
  1014.     if ( dpmi_physical_memory < NEEDED_PHYSICAL_MEMORY )    {
  1015.         printf( "%d %s\n", NEEDED_PHYSICAL_MEMORY - dpmi_physical_memory, TXT_PHYSICAL_MEMORY );
  1016.         if ( dpmi_virtual_memory )    {    
  1017.             printf( "%s\n", TXT_PHYSICAL_MEMORY_2);
  1018.         }
  1019.         exit(1);
  1020.     }
  1021.  
  1022.     if ( dpmi_physical_memory < LOW_PHYSICAL_MEMORY_CUTOFF )    {
  1023.         piggy_low_memory = 1;
  1024.     }
  1025.  
  1026. }
  1027.  
  1028.  
  1029. int Inferno_verbose = 0;
  1030.  
  1031. //NO_STACK_SIZE_CHECK uint * stack, *stack_ptr;
  1032. //NO_STACK_SIZE_CHECK int stack_size, unused_stack_space;
  1033. //NO_STACK_SIZE_CHECK int sil;
  1034. //NO_STACK_SIZE_CHECK 
  1035. //NO_STACK_SIZE_CHECK int main(int argc,char **argv)
  1036. //NO_STACK_SIZE_CHECK {
  1037. //NO_STACK_SIZE_CHECK     uint ret_value;
  1038. //NO_STACK_SIZE_CHECK     
  1039. //NO_STACK_SIZE_CHECK     unused_stack_space = 0;
  1040. //NO_STACK_SIZE_CHECK     stack = &ret_value;
  1041. //NO_STACK_SIZE_CHECK     stack_size = stackavail()/4;
  1042. //NO_STACK_SIZE_CHECK 
  1043. //NO_STACK_SIZE_CHECK     for ( sil=0; sil<stack_size; sil++ )    {
  1044. //NO_STACK_SIZE_CHECK         stack--;
  1045. //NO_STACK_SIZE_CHECK         *stack = 0xface0123;
  1046. //NO_STACK_SIZE_CHECK     }
  1047. //NO_STACK_SIZE_CHECK
  1048. //NO_STACK_SIZE_CHECK     ret_value = descent_main( argc, argv );        // Rename main to be descent_main
  1049. //NO_STACK_SIZE_CHECK 
  1050. //NO_STACK_SIZE_CHECK     for ( sil=0; sil<stack_size; sil++ )    {
  1051. //NO_STACK_SIZE_CHECK         if ( *stack == 0xface0123 )    
  1052. //NO_STACK_SIZE_CHECK             unused_stack_space++;
  1053. //NO_STACK_SIZE_CHECK         stack++;
  1054. //NO_STACK_SIZE_CHECK     }
  1055. //NO_STACK_SIZE_CHECK 
  1056. //NO_STACK_SIZE_CHECK     mprintf(( 0, "Program used %d/%d stack space\n", (stack_size - unused_stack_space)*4, stack_size*4 ));
  1057. //NO_STACK_SIZE_CHECK     key_getch();
  1058. //NO_STACK_SIZE_CHECK 
  1059. //NO_STACK_SIZE_CHECK     return ret_value;
  1060. //NO_STACK_SIZE_CHECK }
  1061.  
  1062. extern int digi_timer_rate;
  1063.  
  1064. int descent_critical_error = 0;
  1065. unsigned descent_critical_deverror = 0;
  1066. unsigned descent_critical_errcode = 0;
  1067.  
  1068.  
  1069.  
  1070. #pragma off (check_stack)
  1071. int __far descent_critical_error_handler(unsigned deverror, unsigned errcode, unsigned __far * devhdr )
  1072. {
  1073.     devhdr = devhdr;
  1074.     descent_critical_error++;
  1075.     descent_critical_deverror = deverror;
  1076.     descent_critical_errcode = errcode;
  1077.     return _HARDERR_FAIL;
  1078. }
  1079. void chandler_end (void)  // dummy functions
  1080. {
  1081. }
  1082. #pragma on (check_stack)
  1083.  
  1084. extern int Network_allow_socket_changes;
  1085.  
  1086. extern void vfx_set_palette_sub(ubyte *);
  1087.  
  1088. extern int Game_vfx_flag;
  1089. extern int Game_victor_flag;
  1090. extern int Game_vio_flag;
  1091. extern int Game_3dmax_flag;
  1092. extern int VR_low_res;
  1093. extern void vfx_init();
  1094.  
  1095. #ifdef USE_CD
  1096. char destsat_cdpath[128] = "";
  1097. int find_descent_cd();
  1098. #endif
  1099.  
  1100. extern int Config_vr_type;
  1101. extern int Config_vr_tracking;
  1102.  
  1103. int main(int argc,char **argv)
  1104. {
  1105.     int i,t;
  1106.     ubyte title_pal[768];
  1107.  
  1108.     error_init(NULL);
  1109.  
  1110.     setbuf(stdout, NULL);    // unbuffered output via printf
  1111.         
  1112.     InitArgs( argc,argv );
  1113.  
  1114.     if ( FindArg( "-verbose" ) )
  1115.         Inferno_verbose = 1;
  1116.  
  1117.     //change_to_dir(argv[0]);
  1118.  
  1119.     // Initialize DPMI before anything else!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1120.     // (To check memory size and availbabitliy and allocate some low DOS memory)
  1121.     if (Inferno_verbose) printf( "%s... ", TXT_INITIALIZING_DPMI);
  1122.     dpmi_init(Inferno_verbose);        // Before anything
  1123.     if (Inferno_verbose) printf( "\n" );
  1124.  
  1125.     if (Inferno_verbose) printf( "\n%s...", TXT_INITIALIZING_CRIT);
  1126.     if (!dpmi_lock_region((void near *)descent_critical_error_handler,(char *)chandler_end - (char near *)descent_critical_error_handler))    {
  1127.         Error( "Unable to lock critial error handler" );
  1128.     }
  1129.     if (!dpmi_lock_region(&descent_critical_error,sizeof(int)))    {
  1130.         Error( "Unable to lock critial error handler" );
  1131.     }
  1132.     if (!dpmi_lock_region(&descent_critical_deverror,sizeof(unsigned)))    {
  1133.         Error( "Unable to lock critial error handler" );
  1134.     }
  1135.     if (!dpmi_lock_region(&descent_critical_errcode,sizeof(unsigned)))    {
  1136.         Error( "Unable to lock critial error handler" );
  1137.     }
  1138.     _harderr((void *) descent_critical_error_handler );
  1139.     //Above line modified by KRB, added (void *) cast
  1140.     //for the compiler.
  1141.  
  1142. #ifdef USE_CD
  1143.     i=find_descent_cd();
  1144.     if ( i>0 )        {
  1145.         sprintf( destsat_cdpath, "%c:\\descent\\", i +'a' - 1  );
  1146.         cfile_use_alternate_hogdir( destsat_cdpath );
  1147.     } 
  1148. #ifdef REQUIRE_CD
  1149.     else {        // NOTE ABOVE LINK!!!!!!!!!!!!!!!!!!
  1150.         printf( "\n\n" );
  1151. #ifdef DEST_SAT
  1152.         printf("Couldn't find the 'Descent: Destination Saturn' CD-ROM.\n" );
  1153. #else
  1154.         printf("Couldn't find the Descent CD-ROM.\n" );
  1155. #endif
  1156.         printf("Please make sure that it is in your CD-ROM drive and\n" );
  1157.         printf("that your CD-ROM drivers are loaded correctly.\n" );
  1158.         exit(1);
  1159.     }
  1160. #endif
  1161. #endif
  1162.  
  1163.     load_text();
  1164.  
  1165. //    set_exit_message("\n\n%s", TXT_THANKS);
  1166.  
  1167.     printf("\nDESCENT   %s\n", VERSION_NAME);
  1168.     printf("%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);    
  1169.  
  1170.     check_id_checksum_and_date();
  1171.  
  1172.     if (FindArg( "-?" ) || FindArg( "-help" ) || FindArg( "?" ) )    {
  1173.  
  1174.         printf( "%s\n", TXT_COMMAND_LINE_0 );
  1175.  
  1176.         printf("  -SimulEyes     %s\n",
  1177.                 "Enables StereoGraphics SimulEyes VR stereo display" );
  1178.  
  1179.         printf("  -Iglasses      %s\n", TXT_IGLASSES );
  1180.         printf("  -VioTrack <n>  %s n\n",TXT_VIOTRACK );
  1181.         printf("  -3dmaxLo       %s\n",TXT_KASAN );
  1182.         printf("                 %s\n",TXT_KASAN_2 );
  1183.         printf("  -3dmaxHi       %s\n",TXT_3DMAX );
  1184.         printf( "%s\n", TXT_COMMAND_LINE_1 );
  1185.         printf( "%s\n", TXT_COMMAND_LINE_2 );
  1186.         printf( "%s\n", TXT_COMMAND_LINE_3 );
  1187.         printf( "%s\n", TXT_COMMAND_LINE_4 );
  1188.         printf( "%s\n", TXT_COMMAND_LINE_5 );
  1189. //        printf( "\n");
  1190.         printf( "%s\n", TXT_COMMAND_LINE_6 );
  1191.         printf( "%s\n", TXT_COMMAND_LINE_7 );
  1192.         printf( "%s\n", TXT_COMMAND_LINE_8 );
  1193. //        printf( "\n");
  1194.         printf( "\n%s\n",TXT_PRESS_ANY_KEY3);
  1195.         getch();
  1196.         printf( "\n" );
  1197.         printf( "%s\n", TXT_COMMAND_LINE_9);
  1198.         printf( "%s\n", TXT_COMMAND_LINE_10);
  1199.         printf( "%s\n", TXT_COMMAND_LINE_11);
  1200.         printf( "%s\n", TXT_COMMAND_LINE_12);
  1201.         printf( "%s\n", TXT_COMMAND_LINE_13);
  1202.         printf( "%s\n", TXT_COMMAND_LINE_14);
  1203.         printf( "%s\n", TXT_COMMAND_LINE_15);
  1204.         printf( "%s\n", TXT_COMMAND_LINE_16);
  1205.         printf( "%s\n", TXT_COMMAND_LINE_17);
  1206.         printf( "%s\n", TXT_COMMAND_LINE_18);
  1207.       printf( "  -DynamicSockets %s\n", TXT_SOCKET);
  1208.       printf( "  -NoFileCheck    %s\n", TXT_NOFILECHECK);
  1209.       printf( "  -GamePort       %s\n", "Use Colorado Spectrum's Notebook Gameport" );
  1210.         printf( "  -NoDoubleBuffer %s\n", "Use only one page of video memory" );
  1211.         printf( "  -LCDBios        %s\n", "Enables LCDBIOS for using LCD shutter glasses" );
  1212.         printf( "  -JoyNice        %s\n", "Joystick poller allows interrupts to occur" );
  1213.         set_exit_message("");
  1214.         return(0);
  1215.     }
  1216.  
  1217.     printf("\n%s\n", TXT_HELP);    
  1218.  
  1219.     #ifdef PASSWORD
  1220.     if ((t = FindArg("-pswd")) != 0) {
  1221.         int    n;
  1222.         byte    *pp = Side_to_verts;
  1223.         int ch;
  1224.         for (n=0; n<6; n++)
  1225.             for (ch=0; ch<strlen(Args[t+1]); ch++)
  1226.                 *pp++ ^= Args[t+1][ch];
  1227.     }
  1228.     else 
  1229.         Error("Invalid processor");        //missing password
  1230.     #endif
  1231.  
  1232.     if ( FindArg( "-autodemo" ))
  1233.         Auto_demo = 1;
  1234.  
  1235.     #ifndef RELEASE
  1236.     if ( FindArg( "-noscreens" ) )
  1237.         Skip_briefing_screens = 1;
  1238.     #endif
  1239.  
  1240.     Lighting_on = 1;
  1241.  
  1242.     if ( !FindArg( "-nodoscheck" ))
  1243.         check_dos_version();
  1244.     
  1245.     if ( !FindArg( "-nofilecheck" ))
  1246.         dos_check_file_handles(5);
  1247.  
  1248.     if ( !FindArg( "-nomemcheck" ))
  1249.         check_memory();
  1250.  
  1251.     strcpy(Menu_pcx_name, "menu.pcx");    //    Used to be menu2.pcx.
  1252.  
  1253.     if (init_graphics()) return 1;
  1254.  
  1255.     #ifdef EDITOR
  1256.     if (!Inferno_is_800x600_available)    {
  1257.         printf( "The editor will not be available, press any key to start game...\n" );
  1258.         Function_mode = FMODE_MENU;
  1259.         getch();
  1260.     }
  1261.     #endif
  1262.  
  1263.     #ifndef NDEBUG
  1264.         minit();
  1265.         mopen( 0, 9, 1, 78, 15, "Debug Spew");
  1266.         mopen( 1, 2, 1, 78,  5, "Errors & Serious Warnings");
  1267.     #endif
  1268.  
  1269.     if (!WVIDEO_running)
  1270.         mprintf((0,"WVIDEO_running = %d\n",WVIDEO_running));
  1271.  
  1272.     //if (!WVIDEO_running) install_int3_handler();
  1273.  
  1274.     //lib_init("INFERNO.DAT");
  1275.  
  1276.     if (Inferno_verbose) printf ("%s", TXT_VERBOSE_1);
  1277.     ReadConfigFile();
  1278.     if (Inferno_verbose) printf( "\n%s", TXT_VERBOSE_2);
  1279.  
  1280.     timer_init();
  1281.     timer_set_rate( digi_timer_rate );            // Tell our timer how fast to go (120 Hz)
  1282.     joy_set_timer_rate( digi_timer_rate );         // Tell joystick how fast timer is going
  1283.  
  1284.     if (Inferno_verbose) printf( "\n%s", TXT_VERBOSE_3);
  1285.     key_init();
  1286.     if (!FindArg( "-nomouse" ))    {
  1287.         if (Inferno_verbose) printf( "\n%s", TXT_VERBOSE_4);
  1288.         if (FindArg( "-nocyberman" ))
  1289.             mouse_init(0);
  1290.         else
  1291.             mouse_init(1);
  1292.     } else {
  1293.          if (Inferno_verbose) printf( "\n%s", TXT_VERBOSE_5);
  1294.     }
  1295.     if (!FindArg( "-nojoystick" ))    {
  1296.         if (Inferno_verbose) printf( "\n%s", TXT_VERBOSE_6);
  1297.         joy_init();
  1298.         if ( FindArg( "-joyslow" ))    {
  1299.             if (Inferno_verbose) printf( "\n%s", TXT_VERBOSE_7);
  1300.             joy_set_slow_reading(JOY_SLOW_READINGS);
  1301.         }
  1302.         if ( FindArg( "-joypolled" ))    {
  1303.             if (Inferno_verbose) printf( "\n%s", TXT_VERBOSE_8);
  1304.             joy_set_slow_reading(JOY_POLLED_READINGS);
  1305.         }
  1306.         if ( FindArg( "-joybios" ))    {
  1307.             if (Inferno_verbose) printf( "\n%s", TXT_VERBOSE_9);
  1308.             joy_set_slow_reading(JOY_BIOS_READINGS);
  1309.         }
  1310.         if ( FindArg( "-joynice" ))    {
  1311.             if (Inferno_verbose) printf( "\n%s", "Using nice joystick poller..." );
  1312.             joy_set_slow_reading(JOY_FRIENDLY_READINGS);
  1313.         }
  1314.         if ( FindArg( "-gameport" ))    {
  1315.             if ( init_gameport() )    {            
  1316.                 joy_set_slow_reading(JOY_BIOS_READINGS);
  1317.             } else {
  1318.                 Error( "\nCouldn't initialize the Notebook Gameport.\nMake sure the NG driver is loaded.\n" );
  1319.             }
  1320.         }
  1321.     } else {
  1322.         if (Inferno_verbose) printf( "\n%s", TXT_VERBOSE_10);
  1323.     }
  1324.     if (Inferno_verbose) printf( "\n%s", TXT_VERBOSE_11);
  1325.     div0_init(DM_ERROR);
  1326.  
  1327.     //------------ Init sound ---------------
  1328.     if (!FindArg( "-nosound" ))    {
  1329.         if (digi_init())    {
  1330.             printf( "\n%s\n", TXT_PRESS_ANY_KEY3);
  1331.             key_getch();
  1332.         }
  1333.     } else {
  1334.         if (Inferno_verbose) printf( "\n%s",TXT_SOUND_DISABLED );
  1335.     }
  1336.  
  1337. #ifdef NETWORK
  1338.     if (!FindArg( "-nonetwork" ))    {
  1339.         int socket=0, showaddress=0;
  1340.         int ipx_error;
  1341.         if (Inferno_verbose) printf( "\n%s ", TXT_INITIALIZING_NETWORK);
  1342.         if ((t=FindArg("-socket")))
  1343.             socket = atoi( Args[t+1] );
  1344.         if ( FindArg("-showaddress") ) showaddress=1;
  1345.         if ((ipx_error=ipx_init(IPX_DEFAULT_SOCKET+socket,showaddress))==0)    {
  1346.               if (Inferno_verbose) printf( "%s %d.\n", TXT_IPX_CHANNEL, socket );
  1347.             Network_active = 1;
  1348.         } else {
  1349.             switch( ipx_error )    {
  1350.             case 3:     if (Inferno_verbose) printf( "%s\n", TXT_NO_NETWORK); break;
  1351.             case -2: if (Inferno_verbose) printf( "%s 0x%x.\n", TXT_SOCKET_ERROR, IPX_DEFAULT_SOCKET+socket); break;
  1352.             case -4: if (Inferno_verbose) printf( "%s\n", TXT_MEMORY_IPX ); break;
  1353.             default:
  1354.                 if (Inferno_verbose) printf( "%s %d", TXT_ERROR_IPX, ipx_error );
  1355.             }
  1356.             if (Inferno_verbose) printf( "%s\n",TXT_NETWORK_DISABLED);
  1357.             Network_active = 0;        // Assume no network
  1358.         }
  1359.         ipx_read_user_file( "descent.usr" );
  1360.         ipx_read_network_file( "descent.net" );
  1361.         if ( FindArg( "-dynamicsockets" ))
  1362.             Network_allow_socket_changes = 1;
  1363.         else
  1364.             Network_allow_socket_changes = 0;
  1365.     } else {
  1366.         if (Inferno_verbose) printf( "%s\n", TXT_NETWORK_DISABLED);
  1367.         Network_active = 0;        // Assume no network
  1368.     }
  1369.  
  1370.     if (!FindArg("-noserial"))
  1371.     {
  1372.         serial_active = 1;
  1373.     }
  1374.     else 
  1375.     {
  1376.         serial_active = 0;
  1377.     }
  1378. #endif
  1379.  
  1380.     i = FindArg( "-vfxtrak" );
  1381.     if ( i > 0 )
  1382.         kconfig_sense_init();
  1383.     else if ((Config_vr_type==1)&&(Config_vr_tracking>0))
  1384.         kconfig_sense_init();
  1385.         
  1386.     i = FindArg( "-maxxtrak" );
  1387.     if ( i > 0)    
  1388.         victor_init_tracking( atoi(Args[i+1]) );
  1389.     else if ((Config_vr_type==2)&&(Config_vr_tracking>0))
  1390.         victor_init_tracking( Config_vr_tracking );
  1391.  
  1392.     i = FindArg( "-viotrack" );
  1393.     if ( i > 0 )
  1394.         iglasses_init_tracking( atoi(Args[i+1]) );
  1395.     else if ((Config_vr_type==3)&&(Config_vr_tracking>0))
  1396.         iglasses_init_tracking( Config_vr_tracking );
  1397.  
  1398.     if ( FindArg( "-vfx" ) || (Config_vr_type==1) )    {
  1399.         vfx_init();
  1400.         Game_vfx_flag = 1;
  1401.         game_init_render_buffers(SM_640x480V, 320, 240, 0, VR_AREA_DET, 0 );
  1402.         VR_low_res = 3;
  1403.     } else if ( FindArg( "-cybermaxx" ) || (Config_vr_type==2) )    {
  1404.         Game_victor_flag = 1;
  1405.         game_init_render_buffers(SM_320x200C, 320, 100, 0, VR_INTERLACED, 1 );
  1406.         VR_low_res = 0;
  1407.     } else if ( FindArg( "-iglasses" ) || (Config_vr_type==3) )    {
  1408.         Game_vio_flag = 1;
  1409.         game_init_render_buffers(SM_320x400U, 320, 200, 1, VR_INTERLACED, 0 );
  1410.         VR_low_res = 3;
  1411.     } else if ( FindArg( "-cybermax2" ) || (Config_vr_type==6) )    {
  1412.         game_init_render_buffers(SM_320x400U, 320, 200, 1, VR_INTERLACED, 0 );
  1413.         VR_low_res = 3;
  1414.     } else if ( FindArg( "-3dmaxlo" ) || (Config_vr_type==4) )    {
  1415.         if (!is_3dbios_installed())    {
  1416.             printf( "Error: Kasan 3DBIOS needs to be installed.\n" );
  1417.             exit(1);
  1418.         }
  1419.         Game_3dmax_flag = 1;
  1420.         game_init_render_buffers(SM_320x200C, 320, 100, 0, VR_INTERLACED, 0 );
  1421.         VR_low_res = 0;
  1422.         VR_switch_eyes = 0;
  1423.     } else if ( FindArg( "-3dmaxhi" ) || (Config_vr_type==5) )    {
  1424.         if (!is_3dbios_installed())    {
  1425.             printf( "Error: Kasan's 3DBIOS needs to be installed.\n" );
  1426.             exit(1);
  1427.         }
  1428.         Game_3dmax_flag = 2;
  1429.         game_init_render_buffers(22, 320, 200, 1, VR_INTERLACED, 0 );
  1430.         VR_switch_eyes = 0;
  1431.         VR_low_res = 0;
  1432.     } else {
  1433.         int screen_mode = SM_320x200C;
  1434.         int screen_width = 320;
  1435.         int screen_height = 200;
  1436.         int vr_mode = VR_NONE;
  1437.         int screen_compatible = 1;
  1438.         int use_double_buffer = 0;
  1439.  
  1440.         if ( FindArg( "-lcdbios" ) )    {
  1441.             if (!is_3dbios_installed())    {
  1442.                 printf( "Warning: LCDBIOS needs to be installed.\nPress Esc to continue anyway, any other key to exit.\n" );
  1443.                 if ( key_getch()!=KEY_ESC )
  1444.                     exit(1);
  1445.             }
  1446.  
  1447.             if (Inferno_verbose) printf( "Enabling LCDBIOS...\n" );
  1448.             Game_3dmax_flag = 3;
  1449.             screen_compatible = 0;
  1450.             VR_switch_eyes = 0;
  1451.             VR_low_res = 0;
  1452.             vr_mode = VR_INTERLACED;
  1453.         }
  1454.  
  1455.         if ( FindArg( "-simuleyes" ))  {
  1456.             Game_simuleyes_flag = 1;
  1457.         }
  1458.  
  1459.         if (Game_simuleyes_flag)  {  // default to 320x400 (x200 per eye)
  1460.             screen_mode = SM_320x400U;
  1461.             screen_width = 320;    
  1462.             screen_height = 400;
  1463.             screen_compatible = 0;
  1464.             use_double_buffer = 1;
  1465.  
  1466.             if ( FindArg( "-320x200" ))    {
  1467.                 if (Inferno_verbose) printf( "Using 320x200...\n" );
  1468.                 screen_mode = SM_320x200C;
  1469.                 screen_width = 320;
  1470.                 screen_height = 200;
  1471.                 use_double_buffer = 0;
  1472.             }
  1473.             else  {
  1474.                 if (Inferno_verbose) printf( "Using 320x400 ModeX...\n" );
  1475.             }
  1476.         }
  1477.  
  1478.         if ( FindArg( "-320x240" ))    {
  1479.             if (Inferno_verbose) printf( "Using 320x240 ModeX...\n" );
  1480.             screen_mode = SM_320x240U; 
  1481.             screen_width = 320;    
  1482.             screen_height = 240;
  1483.             screen_compatible = 0;
  1484.             use_double_buffer = 1;
  1485.         }
  1486.         if ( FindArg( "-320x400" ))    {
  1487.             if (Inferno_verbose) printf( "Using 320x400 ModeX...\n" );
  1488.             screen_mode = SM_320x400U; 
  1489.             screen_width = 320;    
  1490.             screen_height = 400;
  1491.             screen_compatible = 0;
  1492.             use_double_buffer = 1;
  1493.         }
  1494.  
  1495.         if (!Game_simuleyes_flag && FindArg( "-640x400" ))    {
  1496.             if (Inferno_verbose) printf( "Using 640x400 VESA...\n" );
  1497.             screen_mode = SM_640x400V; 
  1498.             screen_width = 640;    
  1499.             screen_height = 400;
  1500.             screen_compatible = 0;
  1501.             use_double_buffer = 1;
  1502.         }
  1503.  
  1504.         if (!Game_simuleyes_flag && FindArg( "-640x480" ))    {
  1505.             if (Inferno_verbose) printf( "Using 640x480 VESA...\n" );
  1506.             screen_mode = SM_640x480V; 
  1507.             screen_width = 640;    
  1508.             screen_height = 480;
  1509.             screen_compatible = 0;
  1510.             use_double_buffer = 1;
  1511.         }
  1512.         if ( FindArg( "-320x100" ))    {
  1513.             if (Inferno_verbose) printf( "Using 320x100 VGA...\n" );
  1514.             screen_mode = 19; 
  1515.             screen_width = 320;    
  1516.             screen_height = 100;
  1517.             screen_compatible = 0;
  1518.         }
  1519.  
  1520.         if ( FindArg( "-nodoublebuffer" ) )    {
  1521.             if (Inferno_verbose) printf( "Double-buffering disabled...\n" );
  1522.             use_double_buffer = 0;
  1523.         }
  1524.  
  1525.         if ( vr_mode == VR_INTERLACED ) 
  1526.             screen_height /= 2;
  1527.         game_init_render_buffers(screen_mode, screen_width, screen_height, use_double_buffer, vr_mode, screen_compatible );
  1528.     }
  1529.  
  1530.     if (Game_victor_flag) {
  1531.         char *vswitch = getenv( "CYBERMAXX" );
  1532.         if ( vswitch )    {
  1533.             char *p = strstr( vswitch, "/E:R" ); 
  1534.             if ( p )    {
  1535.                 VR_switch_eyes = 1;
  1536.             } else 
  1537.                 VR_switch_eyes = 0;
  1538.         } else {        
  1539.              VR_switch_eyes = 0;
  1540.         }
  1541.     }
  1542.  
  1543.  
  1544. #ifdef ARCADE
  1545.     i = FindArg( "-arcade" );
  1546.     if (i > 0 )    {
  1547.         arcade_init();
  1548.         coindev_init(0);
  1549.     }
  1550. #endif
  1551.  
  1552. #ifdef NETWORK
  1553. //    i = FindArg( "-rinvul" );
  1554. //    if (i > 0) {
  1555. //        int mins = atoi(Args[i+1]);
  1556. //        if (mins > 314)
  1557. //            mins = 314;
  1558. //     control_invul_time = mins/5;
  1559. //    }
  1560.     control_invul_time = 0;
  1561. #endif
  1562.  
  1563.     i = FindArg( "-xcontrol" );
  1564.     if ( i > 0 )    {
  1565.         kconfig_init_external_controls( strtol(Args[i+1], NULL, 0), strtol(Args[i+2], NULL, 0) );
  1566.     }
  1567.  
  1568.     if (Inferno_verbose) printf( "\n%s\n\n", TXT_INITIALIZING_GRAPHICS);
  1569.     if ((t=gr_init( SM_ORIGINAL ))!=0)
  1570.         Error(TXT_CANT_INIT_GFX,t);
  1571.     // Load the palette stuff. Returns non-zero if error.
  1572.     mprintf( (0, "Going into graphics mode..." ));
  1573.     gr_set_mode(SM_320x200C);
  1574.     mprintf( (0, "\nInitializing palette system..." ));
  1575.    gr_use_palette_table( "PALETTE.256" );
  1576.     mprintf( (0, "\nInitializing font system..." ));
  1577.     gamefont_init();    // must load after palette data loaded.
  1578.     songs_play_song( SONG_TITLE, 1 );
  1579.  
  1580.     #ifndef RELEASE
  1581.     if ( !FindArg( "-notitles" ) ) 
  1582.     #endif
  1583.     {    //NOTE LINK TO ABOVE!
  1584.         show_title_screen( "iplogo1.pcx", 1 );
  1585.         show_title_screen( "logo.pcx", 1 );
  1586.     }
  1587.  
  1588.     {
  1589.         //grs_bitmap title_bm;
  1590.         int pcx_error;
  1591.         char filename[14];
  1592.  
  1593.         strcpy(filename, "descent.pcx");
  1594.  
  1595.         if ((pcx_error=pcx_read_bitmap( filename, &grd_curcanv->cv_bitmap, grd_curcanv->cv_bitmap.bm_type, title_pal ))==PCX_ERROR_NONE)    {
  1596.             vfx_set_palette_sub( title_pal );
  1597.             gr_palette_clear();
  1598.             //gr_bitmap( 0, 0, &title_bm );
  1599.             gr_palette_fade_in( title_pal, 32, 0 );
  1600.             //free(title_bm.bm_data);
  1601.         } else {
  1602.             gr_close();
  1603.             Error( "Couldn't load pcx file '%s', PCX load error: %s\n",filename, pcx_errormsg(pcx_error));
  1604.         }
  1605.     }
  1606.  
  1607. #ifdef EDITOR
  1608.     if ( !FindArg("-nobm") )
  1609.         bm_init_use_tbl();
  1610.     else
  1611.         bm_init();
  1612. #else
  1613.         bm_init();
  1614. #endif
  1615.  
  1616.     if ( FindArg( "-norun" ) )
  1617.         return(0);
  1618.  
  1619.     mprintf( (0, "\nInitializing 3d system..." ));
  1620.     g3_init();
  1621.     mprintf( (0, "\nInitializing texture caching system..." ));
  1622.     texmerge_init( 10 );        // 10 cache bitmaps
  1623.     mprintf( (0, "\nRunning game...\n" ));
  1624.     set_screen_mode(SCREEN_MENU);
  1625.  
  1626.     init_game();
  1627.     set_detail_level_parameters(Detail_level);
  1628.  
  1629.     Players[Player_num].callsign[0] = '\0';
  1630.     if (!Auto_demo)     {
  1631.         key_flush();
  1632.         RegisterPlayer();        //get player's name
  1633.     }
  1634.  
  1635.     gr_palette_fade_out( title_pal, 32, 0 );
  1636.  
  1637.     //check for special stamped version
  1638.     if (registered_copy) {
  1639.         nm_messagebox("EVALUATION COPY",1,"Continue",
  1640.             "This special evaluation copy\n"
  1641.             "of DESCENT has been issued to:\n\n"
  1642.             "%s\n"
  1643.             "\n\n    NOT FOR DISTRIBUTION",
  1644.             name_copy);
  1645.  
  1646.         gr_palette_fade_out( gr_palette, 32, 0 );
  1647.     }
  1648.  
  1649.     //kconfig_load_all();
  1650.  
  1651.     Game_mode = GM_GAME_OVER;
  1652.  
  1653.     if (Auto_demo)    {
  1654.         newdemo_start_playback("DESCENT.DEM");        
  1655.         if (Newdemo_state == ND_STATE_PLAYBACK )
  1656.             Function_mode = FMODE_GAME;
  1657.     }
  1658.  
  1659.     build_mission_list(0);        // This also loads mission 0.
  1660.  
  1661.     while (Function_mode != FMODE_EXIT)
  1662.     {
  1663.         switch( Function_mode )    {
  1664.         case FMODE_MENU:
  1665.             if ( Auto_demo )    {
  1666.                 newdemo_start_playback(NULL);        // Randomly pick a file
  1667.                 if (Newdemo_state != ND_STATE_PLAYBACK)    
  1668.                     Error("No demo files were found for autodemo mode!");
  1669.             } else {
  1670.                 check_joystick_calibration();
  1671.                 DoMenu();                                         
  1672. #ifdef EDITOR
  1673.                 if ( Function_mode == FMODE_EDITOR )    {
  1674.                     create_new_mine();
  1675.                     SetPlayerFromCurseg();
  1676.                 }
  1677. #endif
  1678.             }
  1679.             break;
  1680.         case FMODE_GAME:
  1681.             #ifdef EDITOR
  1682.                 keyd_editor_mode = 0;
  1683.             #endif
  1684.             game();
  1685.             if ( Function_mode == FMODE_MENU )
  1686.                 songs_play_song( SONG_TITLE, 1 );
  1687.             break;
  1688.         #ifdef EDITOR
  1689.         case FMODE_EDITOR:
  1690.             keyd_editor_mode = 1;
  1691.             editor();
  1692.             _harderr( (void *)descent_critical_error_handler );        // Reinstall game error handler
  1693.             if ( Function_mode == FMODE_GAME ) {
  1694.                 Game_mode = GM_EDITOR;
  1695.                 editor_reset_stuff_on_level();
  1696.                 N_players = 1;
  1697.             }
  1698.             break;
  1699.         #endif
  1700.         default:
  1701.             Error("Invalid function mode %d",Function_mode);
  1702.         }
  1703.     }
  1704.  
  1705.     WriteConfigFile();
  1706.  
  1707. #ifndef ROCKWELL_CODE
  1708.     #ifndef RELEASE
  1709.     if (!FindArg( "-notitles" ))
  1710.     #endif
  1711.         //NOTE LINK TO ABOVE!!
  1712.     #ifndef EDITOR
  1713.         show_order_form();
  1714.     #endif
  1715. #endif
  1716.  
  1717.     #ifndef NDEBUG
  1718.     if ( FindArg( "-showmeminfo" ) )
  1719. //        show_mem_info = 1;        // Make memory statistics show
  1720.     #endif
  1721.  
  1722.     return(0);        //presumably successful exit
  1723. }
  1724.  
  1725.  
  1726. void check_joystick_calibration()    {
  1727.     int x1, y1, x2, y2, c;
  1728.     fix t1;
  1729.  
  1730.     if ( (Config_control_type!=CONTROL_JOYSTICK) &&
  1731.           (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) &&
  1732.           (Config_control_type!=CONTROL_THRUSTMASTER_FCS) &&
  1733.           (Config_control_type!=CONTROL_GRAVIS_GAMEPAD)
  1734.         ) return;
  1735.  
  1736.     joy_get_pos( &x1, &y1 );
  1737.  
  1738.     t1 = timer_get_fixed_seconds();
  1739.     while( timer_get_fixed_seconds() < t1 + F1_0/100 )
  1740.         ;
  1741.  
  1742.     joy_get_pos( &x2, &y2 );
  1743.  
  1744.     // If joystick hasn't moved...
  1745.     if ( (abs(x2-x1)<30) &&  (abs(y2-y1)<30) )    {
  1746.         if ( (abs(x1)>30) || (abs(x2)>30) ||  (abs(y1)>30) || (abs(y2)>30) )    {
  1747.             c = nm_messagebox( NULL, 2, TXT_CALIBRATE, TXT_SKIP, TXT_JOYSTICK_NOT_CEN );
  1748.             if ( c==0 )    {
  1749.                 joydefs_calibrate();
  1750.             }
  1751.         }
  1752.     }
  1753.  
  1754. }
  1755.  
  1756. void show_order_form()
  1757. {
  1758.     int pcx_error;
  1759.     char title_pal[768];
  1760.     char    exit_screen[16];
  1761.  
  1762.     gr_set_current_canvas( NULL );
  1763.     gr_palette_clear();
  1764.  
  1765.     key_flush();        
  1766.  
  1767. #ifdef SHAREWARE
  1768.     strcpy(exit_screen, "order01.pcx");
  1769. #else
  1770.     #ifdef DEST_SAT
  1771.         strcpy(exit_screen, "order01.pcx");
  1772.     #else
  1773.         strcpy(exit_screen, "warning.pcx");
  1774.     #endif
  1775. #endif
  1776.     if ((pcx_error=pcx_read_bitmap( exit_screen, &grd_curcanv->cv_bitmap, grd_curcanv->cv_bitmap.bm_type, title_pal ))==PCX_ERROR_NONE) {
  1777.         vfx_set_palette_sub( title_pal );
  1778.         gr_palette_fade_in( title_pal, 32, 0 );
  1779.         {
  1780.             int done=0;
  1781.             fix time_out_value = timer_get_approx_seconds()+i2f(60*5);
  1782.             while(!done)    {
  1783.                 if ( timer_get_approx_seconds() > time_out_value ) done = 1;
  1784.                 if (key_inkey()) done = 1;
  1785.             }
  1786.         }
  1787.         gr_palette_fade_out( title_pal, 32, 0 );        
  1788.     }
  1789.     key_flush();        
  1790. }
  1791.  
  1792.  
  1793. #ifdef USE_CD
  1794.  
  1795. #include <dos.h>
  1796. #include <stdio.h>
  1797. #include <stdlib.h>
  1798. #include <string.h>
  1799.  
  1800. #include "dpmi.h"
  1801.  
  1802. typedef struct {
  1803.     char unit;
  1804.     ushort dev_offset;
  1805.     ushort dev_segment;
  1806. } dev_list;
  1807.  
  1808. typedef struct _Dev_Hdr {
  1809.     unsigned int dev_next;
  1810.     unsigned short dev_att;
  1811.     ushort dev_stat;
  1812.     ushort dev_int;
  1813.     char dev_name[8];
  1814.     short dev_resv;
  1815.     char dev_letr;
  1816.     char dev_units;
  1817. } dev_header;
  1818.  
  1819. int find_descent_cd()
  1820. {
  1821.     dpmi_real_regs rregs;
  1822.         
  1823.     // Get dos memory for call...
  1824.     dev_list * buf;
  1825.     dev_header *device;
  1826.     int num_drives, i;
  1827.     unsigned cdrive, cur_drive, cdrom_drive;
  1828.  
  1829.     memset(&rregs,0,sizeof(dpmi_real_regs));
  1830.     rregs.eax = 0x1500;
  1831.     rregs.ebx = 0;
  1832.     dpmi_real_int386x( 0x2f, &rregs );
  1833.     if ((rregs.ebx & 0xffff) == 0) {
  1834.         return -1;            // No cdrom
  1835.     }
  1836.     num_drives = rregs.ebx;
  1837.  
  1838.     buf = (dev_list *)dpmi_get_temp_low_buffer( sizeof(dev_list)*26 );    
  1839.     if (buf==NULL) {
  1840.         return -2;            // Error getting memory!
  1841.     }
  1842.  
  1843.     memset(&rregs,0,sizeof(dpmi_real_regs));
  1844.     rregs.es = DPMI_real_segment(buf);
  1845.     rregs.ebx = DPMI_real_offset(buf);
  1846.     rregs.eax = 0x1501;
  1847.     dpmi_real_int386x( 0x2f, &rregs );
  1848.     cdrom_drive = 0;
  1849.     _dos_getdrive(&cdrive);
  1850.     for (i = 0; i < num_drives; i++) {
  1851.         device = (dev_header *)((buf[i].dev_segment<<4)+ buf[i].dev_offset);
  1852.         _dos_setdrive(device->dev_letr,&cur_drive);
  1853.         _dos_getdrive(&cur_drive);
  1854.         if (cur_drive == device->dev_letr) {
  1855.             if (!chdir("\\descent")) {
  1856.                 FILE * fp;
  1857. #ifdef DEST_SAT
  1858.                 fp = fopen( "saturn.hog", "rb" );    
  1859. #else
  1860.                 fp = fopen( "descent.hog", "rb" );    
  1861. #endif
  1862.                 if ( fp )    {
  1863.                     int write_failed = 1;
  1864.                     fclose(fp);
  1865.                     fp = fopen( "descent.tmp", "wb" );
  1866.                     if ( fp )    {
  1867.                         int temp = 0x15A90C23;
  1868.                         if ( fwrite( &temp, sizeof(int), 1, fp )==1 )    {
  1869.                             fp = fopen( "descent.tmp", "rb" );
  1870.                             if ( fp )    {
  1871.                                 temp = 0;
  1872.                                 if ( fread( &temp, sizeof(int), 1, fp )==1 )    {
  1873.                                     if ( temp == 0x15A90C23 ) 
  1874.                                         write_failed = 0;
  1875.                                 }
  1876.                                 fclose(fp);
  1877.                                 unlink( "descent.tmp" );
  1878.                             }
  1879.                         }
  1880.                         fclose(fp);
  1881.                     }
  1882.                     if ( write_failed )    {
  1883.                         cdrom_drive = device->dev_letr;
  1884.                         break;
  1885.                     }
  1886.                 }
  1887.             }
  1888.         }                
  1889.     }
  1890.     _dos_setdrive(cdrive,&cur_drive);
  1891.     return cdrom_drive;
  1892. }
  1893.  
  1894. #endif
  1895.