summaryrefslogtreecommitdiffstats
path: root/apps/plugins/doom/d_main.c
blob: be45e6a37ef0192c214fac17323ff6186b3c669f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
/* Emacs style mode select   -*- C++ -*-
 *-----------------------------------------------------------------------------
 *
 *
 *  PrBoom a Doom port merged with LxDoom and LSDLDoom
 *  based on BOOM, a modified and improved DOOM engine
 *  Copyright (C) 1999 by
 *  id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
 *  Copyright (C) 1999-2000 by
 *  Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 *  02111-1307, USA.
 *
 * DESCRIPTION:
 *  DOOM main program (D_DoomMain) and game loop (D_DoomLoop),
 *  plus functions to determine game mode (shareware, registered),
 *  parse command line parameters, configure game parameters (turbo),
 *  and call the startup functions.
 *
 *-----------------------------------------------------------------------------
 */


#include "rockmacros.h"

#include "doomdef.h"
#include "doomtype.h"
#include "doomstat.h"
#include "dstrings.h"
#include "sounds.h"
#include "z_zone.h"
#include "w_wad.h"
#include "s_sound.h"
#include "v_video.h"
#include "f_finale.h"
#include "f_wipe.h"
#include "m_argv.h"
#include "m_misc.h"
#include "m_menu.h"
#include "i_system.h"
#include "i_sound.h"
#include "i_video.h"
#include "g_game.h"
#include "hu_stuff.h"
#include "wi_stuff.h"
#include "st_stuff.h"
#include "am_map.h"
#include "p_setup.h"
#include "r_draw.h"
#include "r_main.h"
#include "d_main.h"
#include "d_deh.h"  // Ty 04/08/98 - Externalizations
#include "m_swap.h"

// DEHacked support - Ty 03/09/97 // CPhipps - const char*'s
void ProcessDehFile(const char *filename, const char *outfilename, int lumpnum);

// CPhipps - removed wadfiles[] stuff

boolean devparm;        // started game with -devparm

// jff 1/24/98 add new versions of these variables to remember command line
boolean clnomonsters;   // checkparm of -nomonsters
boolean clrespawnparm;  // checkparm of -respawn
boolean clfastparm;     // checkparm of -fast
// jff 1/24/98 end definition of command line version of play mode switches

boolean nomonsters;     // working -nomonsters
boolean respawnparm;    // working -respawn
boolean fastparm;       // working -fast
boolean dehout=true;

boolean singletics = false; // debug flag to cancel adaptiveness

bool doomexit;

//jff 1/22/98 parms for disabling music and sound
boolean nomusicparm=0;

//jff 4/18/98
extern boolean inhelpscreens;

skill_t startskill;
int     startepisode;
int     startmap;
boolean autostart;
int    debugfile;
int ffmap;

boolean advancedemo;

extern boolean timingdemo, singledemo, demoplayback, fastdemo; // killough

int      basetic;

void D_DoAdvanceDemo (void);

/*
 * D_PostEvent - Event handling
 *
 * Called by I/O functions when an event is received.
 * Try event handlers for each code area in turn.
 */

void D_PostEvent(event_t *ev)
{
   /* cph - suppress all input events at game start
    * FIXME: This is a lousy kludge */
   if (gametic < 3)
       return;

   if(!M_Responder(ev)) {
       if(gamestate == GS_LEVEL && (
              HU_Responder(ev) ||
              ST_Responder(ev) ||
              AM_Responder(ev)
              ))
           return;
       else
           G_Responder(ev);
   }
}

//
// D_Wipe
//
// CPhipps - moved the screen wipe code from D_Display to here
// The screens to wipe between are already stored, this just does the timing
// and screen updating

static void D_Wipe(void)
{
   boolean done;
   int wipestart = I_GetTime () - 1;

   do
   {
      int nowtime, tics;
      do
      {
         //I_uSleep(5000); // CPhipps - don't thrash cpu in this loop
         nowtime = I_GetTime();
         tics = nowtime - wipestart;
      }
      while (!tics);
      wipestart = nowtime;

      done = wipe_ScreenWipe(0,0,SCREENWIDTH,SCREENHEIGHT,tics);
      M_Drawer();                   // menu is drawn even on top of wipes
      I_FinishUpdate();             // page flip or blit buffer
   }
   while (!done);
}

//
// D_Display
//  draw current display, possibly wiping it from the previous
//

// wipegamestate can be set to -1 to force a wipe on the next draw
gamestate_t    wipegamestate = GS_DEMOSCREEN;
extern boolean setsizeneeded;
extern int     showMessages;

void D_Display (void)
{
   static boolean isborderstate        IDATA_ATTR= false;
   static boolean borderwillneedredraw IDATA_ATTR= false;
   static  gamestate_t  oldgamestate IDATA_ATTR= -1;
   boolean wipe;
   boolean viewactive = false, isborder = false;

   if (nodrawers)                   // for comparative timing / profiling
      return; 

   // save the current screen if about to wipe
   if ((wipe = gamestate != wipegamestate))
      wipe_StartScreen(0, 0, SCREENWIDTH, SCREENHEIGHT);

   if (gamestate != GS_LEVEL) { // Not a level
      switch (oldgamestate) {
      case (gamestate_t)-1:
      case GS_LEVEL:
         V_SetPalette(0); // cph - use default (basic) palette
      default:
         break;
      }

      switch (gamestate) {
      case GS_INTERMISSION:
         WI_Drawer();
         break;
      case GS_FINALE:
         F_Drawer();
         break;
      case GS_DEMOSCREEN:
         D_PageDrawer();
         break;
      default:
         break;
      }
   } else if (gametic != basetic) { // In a level
      boolean redrawborderstuff;

      HU_Erase();

      if (setsizeneeded) {               // change the view size if needed
         R_ExecuteSetViewSize();
         oldgamestate = -1;            // force background redraw
      }

      // Work out if the player view is visible, and if there is a border
      viewactive = (!(automapmode & am_active) || (automapmode & am_overlay)) && !inhelpscreens;
      isborder = viewactive ? (viewheight != SCREENHEIGHT) : (!inhelpscreens && (automapmode & am_active));

      if (oldgamestate != GS_LEVEL) {
         R_FillBackScreen ();    // draw the pattern into the back screen
         redrawborderstuff = isborder;
      } else {
         // CPhipps -
         // If there is a border, and either there was no border last time,
         // or the border might need refreshing, then redraw it.
         redrawborderstuff = isborder && (!isborderstate || borderwillneedredraw);
         // The border may need redrawing next time if the border surrounds the screen,
         // and there is a menu being displayed
         borderwillneedredraw = menuactive && isborder && viewactive && (viewwidth != SCREENWIDTH);
      }

      if (redrawborderstuff)
         R_DrawViewBorder();

      // Now do the drawing
      if (viewactive)
         R_RenderPlayerView (&players[displayplayer]);
      if (automapmode & am_active)
         AM_Drawer();
      ST_Drawer((viewheight != SCREENHEIGHT) || ((automapmode & am_active) && !(automapmode & am_overlay)), redrawborderstuff);
      R_DrawViewBorder();

      HU_Drawer();
   }

   isborderstate      = isborder;
   oldgamestate = wipegamestate = gamestate;

   // draw pause pic
   if (paused) {
      static int x;

      if (!x) { // Cache results of x pos calc
         int lump = W_GetNumForName("M_PAUSE");
         const patch_t* p = W_CacheLumpNum(lump);
         x = (320 - SHORT(p->width))/2;
         W_UnlockLumpNum(lump);
      }

      // CPhipps - updated for new patch drawing
      V_DrawNamePatch(x, (!(automapmode & am_active) || (automapmode & am_overlay))
                      ? 4+(viewwindowy*200/SCREENHEIGHT) : 4, // cph - Must un-stretch viewwindowy
                      0, "M_PAUSE", CR_DEFAULT, VPT_STRETCH);
   }

   // menus go directly to the screen
   M_Drawer();          // menu is drawn even on top of everything
   D_BuildNewTiccmds();

   // normal update
   if (!wipe)
      I_FinishUpdate ();              // page flip or blit buffer
   else {
      // wipe update
      wipe_EndScreen(0, 0, SCREENWIDTH, SCREENHEIGHT);
      D_Wipe();
   }
}

//
//  D_DoomLoop()
//
// Not a globally visible function,
//  just included for source reference,
//  called by D_DoomMain, never exits.
// Manages timing and IO,
//  calls all ?_Responder, ?_Ticker, and ?_Drawer,
//  calls I_GetTime, I_StartFrame, and I_StartTic
//

extern  boolean demorecording;

static void D_DoomLoop (void)
{
   basetic = gametic;

   I_SubmitSound();

   while (!doomexit)
   {
      // process one or more tics
      if (singletics)
      {
         I_StartTic ();
         G_BuildTiccmd (&netcmds[consoleplayer][maketic%BACKUPTICS]);
         if (advancedemo)
            D_DoAdvanceDemo ();
         M_Ticker ();
         G_Ticker ();
         gametic++;
         maketic++;
      }
      else
         TryRunTics (); // will run at least one tic

      // killough 3/16/98: change consoleplayer to displayplayer
      if (players[displayplayer].mo) // cph 2002/08/10
         S_UpdateSounds(players[displayplayer].mo);// move positional sounds

      // Update display, next frame, with current state.
      D_Display();

      // Give the system some time
      rb->yield();
   }
}

//
//  DEMO LOOP
//

static int  demosequence;         // killough 5/2/98: made static
static int  pagetic;
static const char *pagename; // CPhipps - const

//
// D_PageTicker
// Handles timing for warped projection
//
void D_PageTicker(void)
{
   if (--pagetic < 0)
      D_AdvanceDemo();
}

//
// D_PageDrawer
//
void D_PageDrawer(void)
{
   // CPhipps - updated for new patch drawing
   V_DrawNamePatch(0, 0, 0, pagename, CR_DEFAULT, VPT_STRETCH);
}

//
// D_AdvanceDemo
// Called after each demo or intro demosequence finishes
//
void D_AdvanceDemo (void)
{
   advancedemo = true;
}

/* killough 11/98: functions to perform demo sequences
 * cphipps 10/99: constness fixes
 */

static void D_SetPageName(const char *name)
{
   pagename = name;
}

static void D_DrawTitle1(const char *name)
{
   S_StartMusic(mus_intro);
   pagetic = (TICRATE*170)/35;
   D_SetPageName(name);
}

static void D_DrawTitle2(const char *name)
{
   S_StartMusic(mus_dm2ttl);
   D_SetPageName(name);
}

/* killough 11/98: tabulate demo sequences
 */

static struct
{
   void (*func)(const char *);
   const char *name;
} const demostates[][4] =
   {
      {
         {D_DrawTitle1, "TITLEPIC"},
         {D_DrawTitle1, "TITLEPIC"},
         {D_DrawTitle2, "TITLEPIC"},
         {D_DrawTitle1, "TITLEPIC"},
      },

      {
         {G_DeferedPlayDemo, "demo1"},
         {G_DeferedPlayDemo, "demo1"},
         {G_DeferedPlayDemo, "demo1"},
         {G_DeferedPlayDemo, "demo1"},
      },
      {
         {D_SetPageName, "CREDIT"},
         {D_SetPageName, "CREDIT"},
         {D_SetPageName, "CREDIT"},
         {D_SetPageName, "CREDIT"},
      },

      {
         {G_DeferedPlayDemo, "demo2"},
         {G_DeferedPlayDemo, "demo2"},
         {G_DeferedPlayDemo, "demo2"},
         {G_DeferedPlayDemo, "demo2"},
      },

      {
         {D_SetPageName, "HELP2"},
         {D_SetPageName, "HELP2"},
         {D_SetPageName, "CREDIT"},
         {D_DrawTitle1,  "TITLEPIC"},
      },

      {
         {G_DeferedPlayDemo, "demo3"},
         {G_DeferedPlayDemo, "demo3"},
         {G_DeferedPlayDemo, "demo3"},
         {G_DeferedPlayDemo, "demo3"},
      },

      {
         {NULL,0},
         {NULL,0},
         {NULL,0},
         {D_SetPageName, "CREDIT"},
      },

      {
         {NULL,0},
         {NULL,0},
         {NULL,0},
         {G_DeferedPlayDemo, "demo4"},
      },

      {
         {NULL,0},
         {NULL,0},
         {NULL,0},
         {NULL,0},
      }
   };

/*
 * This cycles through the demo sequences.
 * killough 11/98: made table-driven
 */

void D_DoAdvanceDemo(void)
{
   players[consoleplayer].playerstate = PST_LIVE;  /* not reborn */
   advancedemo = usergame = paused = false;
   gameaction = ga_nothing;

   pagetic = TICRATE * 11;         /* killough 11/98: default behavior */
   gamestate = GS_DEMOSCREEN;

   if (netgame && !demoplayback) {
      demosequence = 0;
   } else
      if (!demostates[++demosequence][gamemode].func)
         demosequence = 0;
   demostates[demosequence][gamemode].func(demostates[demosequence][gamemode].name);
}

//
// D_StartTitle
//
void D_StartTitle (void)
{
   gameaction = ga_nothing;
   demosequence = -1;
   D_AdvanceDemo();
}

//
// D_AddFile
//
// Rewritten by Lee Killough
//
// Ty 08/29/98 - add source parm to indicate where this came from
// CPhipps - static, const char* parameter
//         - source is an enum
//         - modified to allocate & use new wadfiles array
void D_AddFile (const char *file, wad_source_t source)
{
   wadfiles = realloc(wadfiles, sizeof(*wadfiles)*(numwadfiles+1));
   wadfiles[numwadfiles].name =
      AddDefaultExtension(strcpy(malloc(strlen(file)+5), file), ".wad");
   wadfiles[numwadfiles].src = source; // Ty 08/29/98
   numwadfiles++;
}

//
// CheckIWAD
//
// Verify a file is indeed tagged as an IWAD
// Scan its lumps for levelnames and return gamemode as indicated
// Detect missing wolf levels in DOOM II
//
// The filename to check is passed in iwadname, the gamemode detected is
// returned in gmode, hassec returns the presence of secret levels
//
// jff 4/19/98 Add routine to test IWAD for validity and determine
// the gamemode from it. Also note if DOOM II, whether secret levels exist
// CPhipps - const char* for iwadname, made static
#if 0
static void CheckIWAD(const char *iwadname,GameMode_t *gmode,boolean *hassec)
{
   if ( !fileexists (iwadname) )
   {
      int ud=0,rg=0,sw=0,cm=0,sc=0;
      int handle;

      // Identify IWAD correctly
      if ( (handle = open (iwadname,O_RDONLY)) != -1)
      {
         wadinfo_t header;

         // read IWAD header
         read (handle, &header, sizeof(header));
         if (!strncmp(header.identification,"IWAD",4))
         {
            size_t length;
            filelump_t *fileinfo;

            // read IWAD directory
            header.numlumps = LONG(header.numlumps);
            header.infotableofs = LONG(header.infotableofs);
            length = header.numlumps;
            fileinfo = malloc(length*sizeof(filelump_t));
            lseek (handle, header.infotableofs, SEEK_SET);
            read (handle, fileinfo, length*sizeof(filelump_t));
            close(handle);

            // scan directory for levelname lumps
            while (length--)
               if (fileinfo[length].name[0] == 'E' &&
                     fileinfo[length].name[2] == 'M' &&
                     fileinfo[length].name[4] == 0)
               {
                  if (fileinfo[length].name[1] == '4')
                     ++ud;
                  else if (fileinfo[length].name[1] == '3')
                     ++rg;
                  else if (fileinfo[length].name[1] == '2')
                     ++rg;
                  else if (fileinfo[length].name[1] == '1')
                     ++sw;
               }
               else if (fileinfo[length].name[0] == 'M' &&
                        fileinfo[length].name[1] == 'A' &&
                        fileinfo[length].name[2] == 'P' &&
                        fileinfo[length].name[5] == 0)
               {
                  ++cm;
                  if (fileinfo[length].name[3] == '3')
                     if (fileinfo[length].name[4] == '1' ||
                           fileinfo[length].name[4] == '2')
                        ++sc;
               }

            free(fileinfo);
         }
         else // missing IWAD tag in header
            I_Error("CheckIWAD: IWAD tag %s not present", iwadname);
      }
      else // error from open call
         I_Error("CheckIWAD: Can't open IWAD %s", iwadname);

      // Determine game mode from levels present
      // Must be a full set for whichever mode is present
      // Lack of wolf-3d levels also detected here

      *gmode = indetermined;
      *hassec = false;
      if (cm>=30)
      {
         *gmode = commercial;
         *hassec = sc>=2;
      }
      else if (ud>=9)
         *gmode = retail;
      else if (rg>=18)
         *gmode = registered;
      else if (sw>=9)
         *gmode = shareware;
   }
   else // error from access call
      I_Error("CheckIWAD: IWAD %s not readable", iwadname);
}
#endif
void D_DoomMainSetup(void)
{
   int   p;

   nomonsters = M_CheckParm ("-nomonsters");
   respawnparm = M_CheckParm ("-respawn");
   fastparm = M_CheckParm ("-fast");
   devparm = M_CheckParm ("-devparm");
   if (M_CheckParm ("-altdeath"))
      deathmatch = 2;
   else if (M_CheckParm ("-deathmatch"))
      deathmatch = 1;

   printf("Welcome to Rockdoom\n");

   switch ( gamemode )
   {
   case retail:
      printf ("The Ultimate DOOM Startup v%d.%d\n",DVERSION/100,DVERSION%100);
      break;
   case shareware:
      printf ("DOOM Shareware Startup v%d.%d\n",DVERSION/100,DVERSION%100);
      break;
   case registered:
      printf ("DOOM Registered Startup v%d.%d\n",DVERSION/100,DVERSION%100);
      break;
   case commercial:
      switch (gamemission)
      {
      case pack_plut:
         printf ("DOOM 2: Plutonia Experiment v%d.%d\n",DVERSION/100,DVERSION%100);
         break;
      case pack_tnt:
         printf ("DOOM 2: TNT - Evilution v%d.%d\n",DVERSION/100,DVERSION%100);
         break;
      default:
         printf ("DOOM 2: Hell on Earth v%d.%d\n",DVERSION/100,DVERSION%100);
         break;
      }
      break;
   default:
      printf ("Public DOOM v%d.%d\n",DVERSION/100,DVERSION%100);
      break;
   }

   if (devparm)
      printf(D_DEVSTR);

   // turbo option
   if ((p=M_CheckParm ("-turbo")))
   {
      int scale = 200;
      extern int forwardmove[2];
      extern int sidemove[2];

      if (p<myargc-1)
         scale = atoi (myargv[p+1]);
      if (scale < 10)
         scale = 10;
      if (scale > 400)
         scale = 400;
      printf ("turbo scale: %d%%\n",scale);
      forwardmove[0] = forwardmove[0]*scale/100;
      forwardmove[1] = forwardmove[1]*scale/100;
      sidemove[0] = sidemove[0]*scale/100;
      sidemove[1] = sidemove[1]*scale/100;
   }

   // get skill / episode / map from parms
   startskill = sk_medium;
   startepisode = 1;
   startmap = 1;
   autostart = false;

   p = M_CheckParm ("-skill");
   if (p && p < myargc-1)
   {
      startskill = myargv[p+1][0]-'1';
      autostart = true;
   }

   p = M_CheckParm ("-episode");
   if (p && p < myargc-1)
   {
      startepisode = myargv[p+1][0]-'0';
      startmap = 1;
      autostart = true;
   }

   p = M_CheckParm ("-warp");
   if (p && p < myargc-1)
   {
      if (gamemode == commercial)
         startmap = atoi (myargv[p+1]);
      else
      {
         startepisode = myargv[p+1][0]-'0';
         startmap = myargv[p+2][0]-'0';
      }
      autostart = true;
   }

   // CPhipps - move up netgame init
   printf("D_InitNetGame: Checking for network game.\n");
   D_InitNetGame();

   // init subsystems
   printf ("V_Init: allocate screens.\n");
   V_Init ();

   printf ("W_Init: Init WADfiles.\n");
   W_Init();

	if ((p = W_CheckNumForName("DEHACKED")) != -1) // cph - add dehacked-in-a-wad support
		ProcessDehFile(NULL, dehout ? "/dehlog.txt" : NULL, p);

   V_InitColorTranslation(); //jff 4/24/98 load color translation lumps

   // Check for -file in shareware
   if (modifiedgame)
   {
      // These are the lumps that will be checked in IWAD,
      // if any one is not present, execution will be aborted.
      const char name[23][8]=
         {
            "e2m1","e2m2","e2m3","e2m4","e2m5","e2m6","e2m7","e2m8","e2m9",
            "e3m1","e3m3","e3m3","e3m4","e3m5","e3m6","e3m7","e3m8","e3m9",
            "dphoof","bfgga0","heada1","cybra1","spida1d1"
         };
      int i;

      if ( gamemode == shareware)
         I_Error("\nYou cannot -file with the shareware version. Register!\n");

      // Check for fake IWAD with right name,
      // but w/o all the lumps of the registered version.
      if (gamemode == registered)
         for (i = 0;i < 23; i++)
            if (W_CheckNumForName(name[i])<0)
               I_Error("This is not the registered version.\n");
   }

   // Iff additonal PWAD files are used, print modified banner
   if (modifiedgame)
      printf ("ATTENTION:  This version of DOOM has been modified.\n");

   // Check and print which version is executed.
   switch ( gamemode )
   {
   case shareware:
   case indetermined:
      printf ("Shareware!\n");
      break;
   case registered:
   case retail:
   case commercial:
      printf ("Commercial product - do not distribute!\n");
      break;
   default:
      // Ouch.
      break;
   }

   printf ("M_Init: Init miscellaneous info.\n");
   M_Init ();

   printf ("R_Init: Init DOOM refresh daemon - ");
   R_Init ();

   printf ("P_Init: Init Playloop state.\n");
   P_Init ();

   printf ("I_Init: Setting up machine state.\n");
   I_Init ();

   printf ("S_Init: Setting up sound.\n");
   S_Init (snd_SfxVolume /* *8 */, snd_MusicVolume /* *8*/ );

   printf ("HU_Init: Setting up heads up display.\n");
   HU_Init ();

   I_InitGraphics ();

   printf ("ST_Init: Init status bar.\n");
   ST_Init ();

   // check for a driver that wants intermission stats
   p = M_CheckParm ("-statcopy");
   if (p && p<myargc-1)
   {
      // for statistics driver
      extern  void* statcopy;

      statcopy = (void*)(long)atoi(myargv[p+1]);
      printf ("External statistics registered.\n");
   }

   // start the apropriate game based on parms
   p = M_CheckParm ("-record");
   if (p && p < myargc-1)
   {
      G_RecordDemo (myargv[p+1]);
      autostart = true;
   }

   p = M_CheckParm ("-loadgame");
   if (p && p < myargc-1)
      G_LoadGame (atoi(myargv[p+1]), false);

   if ( gameaction != ga_loadgame )
   {
      if (!singledemo) {                  /* killough 12/98 */
         if (autostart || netgame)
            G_InitNew (startskill, startepisode, startmap);
         else
            D_StartTitle ();                // start up intro loop
      }
   }
}

//
// D_DoomMain
//
void D_DoomMain (void)
{
   D_DoomMainSetup(); // get this crap off the stack

   D_DoomLoop ();  // never returns
}