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-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
15 * $Source: /cvs/cvsroot/d2x/main/inferno.c,v $
18 * $Date: 2001-10-25 09:12:16 $
20 * FIXME: put description here
22 * $Log: not supported by cvs2svn $
23 * Revision 1.10 2001/10/25 02:19:31 bradleyb
24 * conditionalize including multi.h and network.h, fix backslashes, fix compiler errors with EDITOR
26 * Revision 1.9 2001/10/19 08:08:50 bradleyb
27 * conditionalize conf.h
29 * Revision 1.8 2001/10/19 00:31:51 bradleyb
30 * Trying to get network working on win32
32 * Revision 1.7 2001/10/18 00:01:01 bradleyb
33 * RCS headers added/changed
42 char copyright[] = "DESCENT II COPYRIGHT (C) 1994-1996 PARALLAX SOFTWARE CORPORATION";
51 #include "pa_enabl.h" //$$POLY_ACC
63 #include "segment.h" //for Side_to_verts
105 // # include "3dfx_des.h"
107 #include "../texmap/scanline.h" //for select_tmap -MM
109 #if defined(POLY_ACC)
110 #include "poly_acc.h"
111 extern int Current_display_mode; //$$ there's got to be a better way than hacking this.
115 #include "editor/editor.h"
116 #include "editor/kdefs.h"
128 void arch_init(void);
129 void arch_init_start(void);
131 //Current version number
133 ubyte Version_major = 1; //FULL VERSION
134 ubyte Version_minor = 2;
136 static const char desc_id_checksum_str[] = DESC_ID_CHKSUM_TAG "0000"; //4-byte checksum
137 char desc_id_exit_num = 0;
139 int Function_mode=FMODE_MENU; //game or editor?
140 int Screen_mode=-1; //game screen or editor screen?
142 //--unused-- grs_bitmap Inferno_bitmap_title;
144 int WVIDEO_running=0; //debugger can set to 1 if running
147 int Inferno_is_800x600_available = 0;
150 //--unused-- int Cyberman_installed=0; // SWIFT device present
151 ubyte CybermouseActive=0;
153 int __far descent_critical_error_handler( unsigned deverr, unsigned errcode, unsigned __far * devhdr );
155 void check_joystick_calibration(void);
158 //--------------------------------------------------------------------------
160 extern int piggy_low_memory;
163 int descent_critical_error = 0;
164 unsigned descent_critical_deverror = 0;
165 unsigned descent_critical_errcode = 0;
167 extern int Network_allow_socket_changes;
169 extern void vfx_set_palette_sub(ubyte *);
171 extern int VR_low_res;
173 extern int Config_vr_type;
174 extern int Config_vr_resolution;
175 extern int Config_vr_tracking;
176 int grd_fades_disabled=1;
180 //read help from a file & print to screen
181 void print_commandline_help()
187 ifile = cfopen("help.tex","rb");
189 ifile = cfopen("help.txb","rb");
191 Error("Cannot load help text file.");
195 while (cfgets(line,LINE_LEN,ifile)) {
199 for (i = 0; i < strlen(line) - 1; i++) {
200 encode_rotate_left(&(line[i]));
201 line[i] = line[i] ^ BITMAP_TBL_XOR;
202 encode_rotate_left(&(line[i]));
207 continue; //don't show comments
215 // D2X-specific options:
216 printf( " D2X Options:\n\n");
217 printf( " -noredundancy %s\n", "Do not send messages when picking up redundant items in multi");
218 printf( " -shortpackets %s\n", "Set shortpackets to default as on");
219 printf( " -notitles %s\n", "Do not show titlescreens on startup");
220 printf( " -ini <file> %s\n", "option file (alternate to command line)");
221 printf( " -autodemo %s\n","FIXME: Undocumented");
222 printf( " -autoload %s\n","FIXME: Undocumented");
223 printf( " -bigpig %s\n","FIXME: Undocumented");
224 printf( " -bspgen %s\n","FIXME: Undocumented");
225 printf( " -cdproxy %s\n","FIXME: Undocumented");
226 printf( " -checktime %s\n","FIXME: Undocumented");
227 printf( " -codereadonly %s\n","FIXME: Undocumented");
228 printf( " -cyberimpact %s\n","FIXME: Undocumented");
229 printf( " -ddemul %s\n","FIXME: Undocumented");
230 printf( " -debug %s\n","FIXME: Undocumented");
231 printf( " -debugmode %s\n","FIXME: Undocumented");
232 printf( " -disallowgfx %s\n","FIXME: Undocumented");
233 printf( " -disallowreboot %s\n","FIXME: Undocumented");
234 printf( " -dynamicsockets %s\n","FIXME: Undocumented");
235 printf( " -emul %s\n","FIXME: Undocumented");
236 printf( " -forcegfx %s\n","FIXME: Undocumented");
237 printf( " -grabmouse %s\n","FIXME: Undocumented");
238 printf( " -hoarddata %s\n","FIXME: Undocumented");
239 printf( " -hw_3dacc %s\n","FIXME: Undocumented");
240 printf( " -hwsurface %s\n","FIXME: Undocumented");
241 printf( " -invulnerability %s\n","FIXME: Undocumented");
242 printf( " -ipxnetwork %s\n","FIXME: Undocumented");
243 printf( " -jasen %s\n","FIXME: Undocumented");
244 printf( " -joyslow %s\n","FIXME: Undocumented");
245 printf( " -kali %s\n","FIXME: Undocumented");
246 printf( " -logfile %s\n","FIXME: Undocumented");
247 printf( " -lowresmovies %s\n","FIXME: Undocumented");
248 printf( " -macdata %s\n","FIXME: Undocumented");
249 printf( " -memdbg %s\n","FIXME: Undocumented");
250 printf( " -monodebug %s\n","FIXME: Undocumented");
251 printf( " -nobm %s\n","FIXME: Undocumented");
252 printf( " -nocdrom %s\n","FIXME: Undocumented");
253 printf( " -nocyberman %s\n","FIXME: Undocumented");
254 printf( " -nofade %s\n","FIXME: Undocumented");
255 printf( " -nomatrixcheat %s\n","FIXME: Undocumented");
256 printf( " -nomixer %s\n","FIXME: Undocumented");
257 printf( " -nomodex %s\n","FIXME: Undocumented");
258 printf( " -nomovies %s\n","FIXME: Undocumented");
259 printf( " -norankings %s\n","FIXME: Undocumented");
260 printf( " -noredbook %s\n","FIXME: Undocumented");
261 printf( " -norun %s\n","FIXME: Undocumented");
262 printf( " -noscreens %s\n","FIXME: Undocumented");
263 printf( " -ordinaljoy %s\n","FIXME: Undocumented");
264 printf( " -packets %s\n","FIXME: Undocumented");
265 printf( " -rtscts %s\n","FIXME: Undocumented");
266 printf( " -semiwin %s\n","FIXME: Undocumented");
267 printf( " -showaddress %s\n","FIXME: Undocumented");
268 printf( " -showmeminfo %s\n","FIXME: Undocumented");
269 printf( " -socket %s\n","FIXME: Undocumented");
270 printf( " -specialdevice %s\n","FIXME: Undocumented");
271 printf( " -stickmag %s\n","FIXME: Undocumented");
272 printf( " -stopwatch %s\n","FIXME: Undocumented");
273 printf( " -superhires %s\n","FIXME: Undocumented");
274 printf( " -sysram %s\n","FIXME: Undocumented");
275 printf( " -text %s\n","FIXME: Undocumented");
276 printf( " -tsengdebug1 %s\n","FIXME: Undocumented");
277 printf( " -tsengdebug2 %s\n","FIXME: Undocumented");
278 printf( " -tsengdebug3 %s\n","FIXME: Undocumented");
279 printf( " -udp %s\n","FIXME: Undocumented");
280 printf( " -vidram %s\n","FIXME: Undocumented");
281 printf( " -xcontrol %s\n","FIXME: Undocumented");
282 printf( " -xname %s\n","FIXME: Undocumented");
283 printf( " -xver %s\n","FIXME: Undocumented");
284 printf( " -tmap <t> %s\n","select texmapper to use (c,fp,i386,pent,ppro)");
286 printf( "\n D2X System Options:\n\n");
289 printf( " -joy209 %s\n", "Use alternate port 209 for joystick");
291 #ifdef GR_SUPPORTS_FULLSCREEN_TOGGLE
292 printf( " -fullscreen %s\n", "Use fullscreen mode if available");
295 printf( " -gl_texmagfilt <f> %s\n","set GL_TEXTURE_MAG_FILTER (see readme.d1x)");
296 printf( " -gl_texminfilt <f> %s\n","set GL_TEXTURE_MIN_FILTER (see readme.d1x)");
297 printf( " -gl_mipmap %s\n","set gl texture filters to \"standard\" options for mipmapping");
298 printf( " -gl_simple %s\n","set gl texture filters to gl_nearest for \"original\" look. (default)");
299 printf( " -gl_alttexmerge %s\n","use new texmerge, usually uses less ram (default)");
300 printf( " -gl_stdtexmerge %s\n","use old texmerge, uses more ram, but _might_ be a bit faster");
301 printf( " -gl_voodoo %s\n","force fullscreen mode only");
302 printf( " -gl_16bittextures %s\n","attempt to use 16bit textures");
303 printf( " -gl_reticle <r> %s\n","use OGL reticle 0=never 1=above 320x* 2=always");
304 printf( " -gl_intensity4_ok %s\n","FIXME: Undocumented");
305 printf( " -gl_luminance4_alpha4_ok %s\n","FIXME: Undocumented");
306 printf( " -gl_readpixels_ok %s\n","FIXME: Undocumented");
307 printf( " -gl_rgba2_ok %s\n","FIXME: Undocumented");
308 printf( " -gl_test1 %s\n","FIXME: Undocumented");
309 printf( " -gl_test2 %s\n","FIXME: Undocumented");
310 printf( " -gl_vidmem %s\n","FIXME: Undocumented");
311 #ifdef OGL_RUNTIME_LOAD
312 printf( " -gl_library <l> %s\n","use alternate opengl library");
316 printf( " -nosdlvidmodecheck %s\n", "Some X servers don't like checking vidmode first, so just switch");
319 printf( " -serialdevice <s> %s\n", "Set serial/modem device to <s>");
320 printf( " -serialread <r> %s\n", "Set serial/modem to read from <r>");
323 printf( " -help, -?, ? %s\n", "View this help screen");
327 void do_joystick_init()
331 if (!FindArg( "-nojoystick" )) {
332 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_6);
334 if ( FindArg( "-joyslow" )) {
335 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_7);
336 joy_set_slow_reading(JOY_SLOW_READINGS);
338 if ( FindArg( "-joypolled" )) {
339 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_8);
340 joy_set_slow_reading(JOY_POLLED_READINGS);
342 if ( FindArg( "-joybios" )) {
343 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_9);
344 joy_set_slow_reading(JOY_BIOS_READINGS);
347 // Added from Descent v1.5 by John. Adapted by Samir.
349 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_10);
353 //set this to force game to run in low res
354 int disable_high_res=0;
356 void do_register_player(ubyte *title_pal)
358 Players[Player_num].callsign[0] = '\0';
364 //now, before we bring up the register player menu, we need to
365 //do some stuff to make sure the palette is ok. First, we need to
366 //get our current palette into the 2d's array, so the remapping will
367 //work. Second, we need to remap the fonts. Third, we need to fill
368 //in part of the fade tables so the darkening of the menu edges works
370 memcpy(gr_palette,title_pal,sizeof(gr_palette));
371 remap_fonts_and_menus(1);
372 RegisterPlayer(); //get player's name
378 void do_network_init()
380 if (!FindArg( "-nonetwork" )) {
384 con_printf(CON_VERBOSE, "\n%s ", TXT_INITIALIZING_NETWORK);
385 if ((t=FindArg("-socket")))
386 socket = atoi( Args[t+1] );
387 //@@if ( FindArg("-showaddress") ) showaddress=1;
388 if ((ipx_error=ipx_init(IPX_DEFAULT_SOCKET+socket))==0) {
389 con_printf(CON_VERBOSE, "%s %d.\n", TXT_IPX_CHANNEL, socket );
392 switch( ipx_error ) {
393 case 3: con_printf(CON_VERBOSE, "%s\n", TXT_NO_NETWORK); break;
394 case -2: con_printf(CON_VERBOSE, "%s 0x%x.\n", TXT_SOCKET_ERROR, IPX_DEFAULT_SOCKET+socket); break;
395 case -4: con_printf(CON_VERBOSE, "%s\n", TXT_MEMORY_IPX ); break;
397 con_printf(CON_VERBOSE, "%s %d", TXT_ERROR_IPX, ipx_error );
399 con_printf(CON_VERBOSE, "%s\n",TXT_NETWORK_DISABLED);
400 Network_active = 0; // Assume no network
402 ipx_read_user_file( "descent.usr" );
403 ipx_read_network_file( "descent.net" );
404 //@@if ( FindArg( "-dynamicsockets" ))
405 //@@ Network_allow_socket_changes = 1;
407 //@@ Network_allow_socket_changes = 0;
409 con_printf(CON_VERBOSE, "%s\n", TXT_NETWORK_DISABLED);
410 Network_active = 0; // Assume no network
416 #define PROGNAME "d2demo"
418 #define PROGNAME "d2"
421 extern char Language[];
423 //can we do highres menus?
424 extern int MenuHiresAvailable;
427 int intro_played = 0;
430 int Inferno_verbose = 0;
432 int open_movie_file(char *filename,int must_have);
434 #if defined(POLY_ACC)
435 #define MENU_HIRES_MODE SM_640x480x15xPA
437 #define MENU_HIRES_MODE SM(640,480)
440 // DESCENT II by Parallax Software
443 //extern ubyte gr_current_pal[];
447 char Auto_file[128] = "";
450 int main(int argc,char **argv)
453 ubyte title_pal[768];
455 con_init(); // Initialise the console
458 error_init(NULL, NULL);
460 args_init( argc,argv );
462 if ( FindArg( "-debug") )
464 con_threshold.value = (float)2;
467 if ( FindArg( "-verbose" ) )
469 con_threshold.value = (float)1;
476 //tell cfile about our counter
477 cfile_set_critical_error_counter_ptr(&descent_critical_error);
480 cfile_init("d2demo.hog"); //specify name of hogfile
482 #define HOGNAME "descent2.hog"
483 if (! cfile_init(HOGNAME)) { //didn't find HOG. Check on CD
485 Error("Could not find required file <%s>",HOGNAME);
492 //print out the banner title
493 con_printf(CON_NORMAL, "\nDESCENT 2 %s v%d.%d",VERSION_TYPE,Version_major,Version_minor);
494 con_printf(CON_NORMAL, " %s %s\n", __DATE__,__TIME__);
495 con_printf(CON_NORMAL, "%s\n%s\n",TXT_COPYRIGHT,TXT_TRADEMARK);
496 con_printf(CON_NORMAL, "This is a MODIFIED version of Descent 2. Copyright (c) 1999 Peter Hawkins\n");
499 if (FindArg( "-?" ) || FindArg( "-help" ) || FindArg( "?" ) ) {
500 print_commandline_help();
501 set_exit_message("");
505 con_printf(CON_NORMAL, "\n");
506 con_printf(CON_NORMAL, TXT_HELP, PROGNAME); //help message has %s for program name
507 con_printf(CON_NORMAL, "\n");
509 con_printf(CON_VERBOSE, "\n%s...", "Checking for Descent 2 CD-ROM");
511 if ( FindArg( "-autodemo" ))
514 if ( FindArg( "-noscreens" ) )
515 Skip_briefing_screens = 1;
517 if ((t=FindArg("-tmap"))){
518 select_tmap(Args[t+1]);
524 // if (init_graphics()) return 1;
527 if (!Inferno_is_800x600_available) {
528 con_printf(CON_NORMAL, "The editor will not be available, press any key to start game...\n" );
529 Function_mode = FMODE_MENU;
534 con_printf(CON_DEBUG,"WVIDEO_running = %d\n",WVIDEO_running);
536 con_printf (CON_VERBOSE, "%s", TXT_VERBOSE_1);
543 #if defined(POLY_ACC)
544 Current_display_mode = -1;
545 game_init_render_buffers(SM_640x480x15xPA, 640, 480, VR_NONE, VRF_COMPATIBLE_MENUS+VRF_ALLOW_COCKPIT );
548 if (!VR_offscreen_buffer) //if hasn't been initialied (by headset init)
549 set_display_mode(0); //..then set default display mode
552 i = FindArg( "-xcontrol" );
554 kconfig_init_external_controls( strtol(Args[i+1], NULL, 0), strtol(Args[i+2], NULL, 0) );
557 con_printf(CON_VERBOSE, "\n%s\n\n", TXT_INITIALIZING_GRAPHICS);
558 if (FindArg("-nofade"))
559 grd_fades_disabled=1;
561 if ((t=gr_init())!=0) //doesn't do much
562 Error(TXT_CANT_INIT_GFX,t);
568 // Load the palette stuff. Returns non-zero if error.
569 con_printf(CON_DEBUG, "\nInitializing palette system..." );
570 gr_use_palette_table(DEFAULT_PALETTE );
572 con_printf(CON_DEBUG, "\nInitializing font system..." );
573 gamefont_init(); // must load after palette data loaded.
575 //determine whether we're using high-res menus & movies
576 #if !defined(POLY_ACC)
577 if (FindArg("-nohires") || FindArg("-nohighres") || (gr_check_mode(MENU_HIRES_MODE) != 0) || disable_high_res)
578 MovieHires = MenuHires = MenuHiresAvailable = 0;
581 //NOTE LINK TO ABOVE!
582 MenuHires = MenuHiresAvailable = 1;
584 con_printf( CON_DEBUG, "\nInitializing movie libraries..." );
585 init_movies(); //init movie libraries
587 con_printf(CON_VERBOSE, "\nGoing into graphics mode...\n");
588 #if defined(POLY_ACC)
589 gr_set_mode(SM_640x480x15xPA);
591 gr_set_mode(MovieHires?SM(640,480):SM(320,200));
595 if ( FindArg( "-notitles" ) )
596 songs_play_song( SONG_TITLE, 1);
599 { //NOTE LINK TO ABOVE!
600 int played=MOVIE_NOT_PLAYED; //default is not played
601 int song_playing = 0;
604 #define MOVIE_REQUIRED 0
606 #define MOVIE_REQUIRED 1
609 #ifdef D2_OEM //$$POLY_ACC, jay.
610 { //show bundler screens
612 char filename[FILENAME_LEN];
614 played=MOVIE_NOT_PLAYED; //default is not played
616 played = PlayMovie("pre_i.mve",0);
619 strcpy(filename,MenuHires?"pre_i1b.pcx":"pre_i1.pcx");
621 while ((tfile=fopen(filename,"rb")) != NULL) {
623 show_title_screen( filename, 1, 0 );
631 init_subtitles("intro.tex");
632 played = PlayMovie("intro.mve",MOVIE_REQUIRED);
637 if (played != MOVIE_NOT_PLAYED)
639 else { //didn't get intro movie, try titles
641 played = PlayMovie("titles.mve",MOVIE_REQUIRED);
643 if (played == MOVIE_NOT_PLAYED) {
644 #if defined(POLY_ACC)
645 gr_set_mode(SM_640x480x15xPA);
647 gr_set_mode(MenuHires?SM_640x480V:SM_320x200C);
649 con_printf( CON_DEBUG, "\nPlaying title song..." );
650 songs_play_song( SONG_TITLE, 1);
652 con_printf( CON_DEBUG, "\nShowing logo screens..." );
653 show_title_screen( MenuHires?"iplogo1b.pcx":"iplogo1.pcx", 1, 1 );
654 show_title_screen( MenuHires?"logob.pcx":"logo.pcx", 1, 1 );
658 { //show bundler movie or screens
661 char filename[FILENAME_LEN];
664 played=MOVIE_NOT_PLAYED; //default is not played
666 //check if OEM movie exists, so we don't stop the music if it doesn't
667 movie_handle = open_movie_file("oem.mve",0);
668 if (movie_handle != -1) {
670 played = PlayMovie("oem.mve",0);
671 song_playing = 0; //movie will kill sound
675 strcpy(filename,MenuHires?"oem1b.pcx":"oem1.pcx");
677 while ((tfile=fopen(filename,"rb")) != NULL) {
679 show_title_screen( filename, 1, 0 );
687 songs_play_song( SONG_TITLE, 1);
691 PA_DFX (pa_splash());
693 con_printf( CON_DEBUG, "\nShowing loading screen..." );
695 //grs_bitmap title_bm;
700 strcpy(filename, "descentd.pcx");
703 strcpy(filename, MenuHires?"descntob.pcx":"descento.pcx");
705 strcpy(filename, MenuHires?"descentb.pcx":"descent.pcx");
709 #if defined(POLY_ACC)
710 gr_set_mode(SM_640x480x15xPA);
712 gr_set_mode(MenuHires?SM(640,480):SM(320,200));
715 FontHires = MenuHires;
717 if ((pcx_error=pcx_read_bitmap( filename, &grd_curcanv->cv_bitmap, grd_curcanv->cv_bitmap.bm_type, title_pal ))==PCX_ERROR_NONE) {
718 //vfx_set_palette_sub( title_pal );
720 gr_palette_fade_in( title_pal, 32, 0 );
722 Error( "Couldn't load pcx file '%s', PCX load error: %s\n",filename, pcx_errormsg(pcx_error));
725 con_printf( CON_DEBUG , "\nDoing bm_init..." );
733 if (FindArg("-hoarddata") != 0) {
734 #define MAX_BITMAPS_PER_BRUSH 30
735 grs_bitmap * bm[MAX_BITMAPS_PER_BRUSH];
739 ubyte palette[256*3];
742 char *sounds[] = {"selforb.raw","selforb.r22", //SOUND_YOU_GOT_ORB
743 "teamorb.raw","teamorb.r22", //SOUND_FRIEND_GOT_ORB
744 "enemyorb.raw","enemyorb.r22", //SOUND_OPPONENT_GOT_ORB
745 "OPSCORE1.raw","OPSCORE1.r22"}; //SOUND_OPPONENT_HAS_SCORED
747 ofile = fopen("hoard.ham","wb");
749 iff_error = iff_read_animbrush("orb.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
750 Assert(iff_error == IFF_NO_ERROR);
751 nframes_short = nframes;
752 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
753 fwrite(&bm[0]->bm_w,sizeof(short),1,ofile);
754 fwrite(&bm[0]->bm_h,sizeof(short),1,ofile);
755 fwrite(palette,3,256,ofile);
756 for (i=0;i<nframes;i++)
757 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
759 iff_error = iff_read_animbrush("orbgoal.abm",bm,MAX_BITMAPS_PER_BRUSH,&nframes,palette);
760 Assert(iff_error == IFF_NO_ERROR);
761 Assert(bm[0]->bm_w == 64 && bm[0]->bm_h == 64);
762 nframes_short = nframes;
763 fwrite(&nframes_short,sizeof(nframes_short),1,ofile);
764 fwrite(palette,3,256,ofile);
765 for (i=0;i<nframes;i++)
766 fwrite(bm[i]->bm_data,1,bm[i]->bm_w*bm[i]->bm_h,ofile);
769 iff_error = iff_read_bitmap(i?"orbb.bbm":"orb.bbm",&icon,BM_LINEAR,palette);
770 Assert(iff_error == IFF_NO_ERROR);
771 fwrite(&icon.bm_w,sizeof(short),1,ofile);
772 fwrite(&icon.bm_h,sizeof(short),1,ofile);
773 fwrite(palette,3,256,ofile);
774 fwrite(icon.bm_data,1,icon.bm_w*icon.bm_h,ofile);
777 for (i=0;i<sizeof(sounds)/sizeof(*sounds);i++) {
781 ifile = fopen(sounds[i],"rb");
782 Assert(ifile != NULL);
783 size = ffilelength(ifile);
784 buf = d_malloc(size);
785 fread(buf,1,size,ifile);
786 fwrite(&size,sizeof(size),1,ofile);
787 fwrite(buf,1,size,ofile);
798 //the bitmap loading code changes gr_palette, so restore it
799 memcpy(gr_palette,title_pal,sizeof(gr_palette));
801 if ( FindArg( "-norun" ) )
804 con_printf( CON_DEBUG, "\nInitializing 3d system..." );
807 con_printf( CON_DEBUG, "\nInitializing texture caching system..." );
808 texmerge_init( 10 ); // 10 cache bitmaps
810 con_printf( CON_DEBUG, "\nRunning game...\n" );
811 set_screen_mode(SCREEN_MENU);
815 // If built with editor, option to auto-load a level and quit game
816 // to write certain data.
819 if ( (t = FindArg( "-autoload" )) ) {
821 strcpy(Auto_file, Args[t+1]);
827 strcpy(Players[0].callsign, "dummy");
830 do_register_player(title_pal);
832 gr_palette_fade_out( title_pal, 32, 0 );
834 Game_mode = GM_GAME_OVER;
837 newdemo_start_playback("descent.dem");
838 if (Newdemo_state == ND_STATE_PLAYBACK )
839 Function_mode = FMODE_GAME;
842 //do this here because the demo code can do a longjmp when trying to
843 //autostart a demo from the main menu, never having gone into the game
846 while (Function_mode != FMODE_EXIT)
848 switch( Function_mode ) {
850 set_screen_mode(SCREEN_MENU);
852 newdemo_start_playback(NULL); // Randomly pick a file
853 if (Newdemo_state != ND_STATE_PLAYBACK)
854 Error("No demo files were found for autodemo mode!");
858 strcpy((char *)&Level_names[0], Auto_file);
860 Function_mode = FMODE_EXIT;
865 check_joystick_calibration();
866 gr_palette_clear(); //I'm not sure why we need this, but we do
869 if ( Function_mode == FMODE_EDITOR ) {
871 SetPlayerFromCurseg();
872 load_palette(NULL,1,0);
879 keyd_editor_mode = 0;
883 /* keep the mouse from wandering in SDL/X11 */
884 if (FindArg("-grabmouse"))
885 SDL_WM_GrabInput(SDL_GRAB_ON);
892 /* give control back to the WM */
893 if (FindArg("-grabmouse"))
894 SDL_WM_GrabInput(SDL_GRAB_OFF);
897 if ( Function_mode == FMODE_MENU )
898 songs_play_song( SONG_TITLE, 1 );
902 keyd_editor_mode = 1;
905 _harderr( (void*)descent_critical_error_handler ); // Reinstall game error handler
907 if ( Function_mode == FMODE_GAME ) {
908 Game_mode = GM_EDITOR;
909 editor_reset_stuff_on_level();
915 Error("Invalid function mode %d",Function_mode);
923 if (!FindArg( "-notitles" ))
928 if ( FindArg( "-showmeminfo" ) )
929 show_mem_info = 1; // Make memory statistics show
932 return(0); //presumably successful exit
936 void check_joystick_calibration() {
937 int x1, y1, x2, y2, c;
940 if ( (Config_control_type!=CONTROL_JOYSTICK) &&
941 (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) &&
942 (Config_control_type!=CONTROL_THRUSTMASTER_FCS) &&
943 (Config_control_type!=CONTROL_GRAVIS_GAMEPAD)
946 joy_get_pos( &x1, &y1 );
948 t1 = timer_get_fixed_seconds();
949 while( timer_get_fixed_seconds() < t1 + F1_0/100 )
952 joy_get_pos( &x2, &y2 );
954 // If joystick hasn't moved...
955 if ( (abs(x2-x1)<30) && (abs(y2-y1)<30) ) {
956 if ( (abs(x1)>30) || (abs(x2)>30) || (abs(y1)>30) || (abs(y2)>30) ) {
957 c = nm_messagebox( NULL, 2, TXT_CALIBRATE, TXT_SKIP, TXT_JOYSTICK_NOT_CEN );