home *** CD-ROM | disk | FTP | other *** search
/ Demon Gate 666 / DemonGate666.bin / mac / DETAILS / E-K□ / EASYW111 / EASYWAD.C next >
C/C++ Source or Header  |  1994-10-01  |  205KB  |  3,590 lines

  1. /**********************************************************************************************************************************/
  2. /* File         : EASYWAD.C                                                                                                       */
  3. /* Executable   : EASYWAD.EXE                                                                                                     */
  4. /* Helpfile     : EASYWAD.CFG                                                                                                     */
  5. /* Doc file     : EASYWAD.DOC                                                                                                     */
  6. /* Version num  : 1.11                                                                                                            */
  7. /* Last changed : 26-09-1994  8:59                                                                                                */
  8. /* Update count : 13                                                                                                              */
  9. /* OS type      : PC (DOS)                                                                                                        */
  10. /* Description  : Menu handler for multiple WAD files for DOOM (Trademark of Id Software)                                         */
  11. /* Compiler     : Microsoft (R) Quick C Compiler Version 2.00                                                                     */
  12. /* Linker       : Microsoft (R) QuickC Linker Version 4.06                                                                        */
  13. /* QCL attribs  : /AC /G2 /Ot /Zr (Compact model, optimized 80286 code, enable pointer checking)                                  */
  14. /* Other        : WM.BAT    : start file                                                                                          */
  15. /*                START.BAT : the result                                                                                          */
  16. /*                START.OPT : response file                                                                                       */
  17. /* Remarks      : Credits go to Brendon Wyber & Raphael Quinet (Doom Editor Utilities) for WadHeader and WadDirectory structures. */
  18. /*                                                                                                                                */
  19. /*                                   By M. van der Heide of ThunderWare Research Center                                           */
  20. /**********************************************************************************************************************************/
  21.  
  22. #include   <bios.h>
  23. #include   <ctype.h>
  24. #include   <direct.h>
  25. #include   <dos.h>
  26. #include   <graph.h>
  27. #include   <malloc.h>
  28. #include   <stdarg.h>
  29. #include   <stdio.h>
  30. #include   <stdlib.h>
  31. #include   <string.h>
  32.  
  33. #define    boolean            char
  34. #define    TRUE               1
  35. #define    FALSE              0
  36.  
  37. #define    DBLACK             0                                             /* Define names for the standard (VGA) palette colors */
  38. #define    DBLUE              1
  39. #define    DGREEN             2
  40. #define    DCYAN              3
  41. #define    DRED               4
  42. #define    DMAGENTA           5
  43. #define    DYELLOW            6
  44. #define    DWHITE             7
  45. #define    LBLACK             8
  46. #define    LBLUE              9
  47. #define    LGREEN             10
  48. #define    LCYAN              11
  49. #define    LRED               12
  50. #define    LMAGENTA           13
  51. #define    LYELLOW            14
  52. #define    LWHITE             15
  53.  
  54. #define    ANYATTR            _A_NORMAL|_A_RDONLY|_A_HIDDEN|_A_SYSTEM|_A_ARCH                                  /* File attributes */
  55. #define    SUBATTR            _A_NORMAL|_A_RDONLY|_A_HIDDEN|_A_SYSTEM|_A_ARCH|_A_SUBDIR                /* Subdirectory attributes */
  56. #define    MAXWADS            1000                                              /* Max number of WAD files the program can handle */
  57. #define    MAXAUTOINCLUDE     5                                        /* Maximum number of autoinclude-WAD files in a CONFIGFILE */
  58. #define    MAXWADDIRS         400                                  /* Max number of WAD file directories a CONFIGFILE may contain */
  59. #define    PAGE               54                                                             /* Max number of WAD files on screen */
  60. #define    WADHEIGHT          18                                                            /* Max number of filenames vertically */
  61. #define    WADWIDTH           27                                          /* Max positions taken for a filename+info horizontally */
  62. #define    MAXINFOLEN         16                                                           /* Max length of a WAD file info field */
  63. #define    ENTRYLEN           8                                        /* Length of the name of a 'directory' entry in a WAD file */
  64. #define    NOMEM              (void far *)0                                                            /* Memory allocation error */
  65.  
  66. #define    DEFAULTCONFIGFILE  "EASYWAD.CFG"
  67. #define    OTHERCONFIGFILE    '+'                             /* Used on the command line: use other config file than EASYWAD.CFG */
  68. #define    COMMENT            '#'                      /* All characters in a line following this one are ignored in a CONFIGFILE */
  69. #define    WADFILE            "*.WAD"
  70. #define    BATFILE            "START.BAT"                                                        /* This file is built at the end */
  71. #define    RESPONSEFILE       "START.OPT"                                        /* Response file if DOOMVERSION is 1.5 or higher */
  72. #define    DOSUB1             "/S"                                        /* Used in CONFIGFILE in a WADDIR entry: do subdirs too */
  73. #define    DOSUB2             "-S"
  74. #define    RESCAN1            "/R"                                              /* Used on the command line: rebuild WAD InfoFile */
  75. #define    RESCAN2            "-R"
  76.  
  77. #define    MAINWAD1           "DOOM.WAD"                                                    /* Main WAD file (registered version) */
  78. #define    MAINWAD2           "DOOM1.WAD"                                                    /* Main WAD file (shareware version) */
  79.  
  80. #define    STARTALONE         "DOOM"                                                        /* Define the start commands for DOOM */
  81. #define    STARTIPX           "IPXSETUP"
  82. #define    STARTLINK          "SERSETUP"
  83. #define    DMATCH             "-DEATHMATCH"                                             /* Define the command parameters for DOOM */
  84. #define    INCFILE            "-FILE"
  85. #define    DEVPARM            "-DEVPARM"
  86. #define    GOTOEPISODE        "-EPISODE"
  87. #define    GOTOANYTHING       "-WARP"
  88. #define    SKILL              "-SKILL"
  89. #define    NUMPLAYERS         "-NODES"
  90. #define    COMPORT            "-COM"
  91. #define    NOMONSTERS         "-NOMONSTERS"
  92. #define    RESPAWNMONSTERS    "-RESPAWN"
  93. #define    FASTMONSTERS       "-FAST"
  94. #define    DMATCHV2           "-ALTDEATH"
  95. #define    NWSOCKET           "-SOCKET"
  96.  
  97. #define    NOFIELD            0                                                                /* Number the FIELDs on the screen */
  98. #define    FILEFIELD          1
  99. #define    EPISODEFIELD       2
  100. #define    DIFFICULTYFIELD    3
  101. #define    PLAYTYPEFIELD      4
  102. #define    LEVELFIELD         5
  103. #define    DEATHMATCHFIELD    6
  104. #define    PAGERFIELD         7
  105. #define    RDPREVFIELD        8
  106. #define    STARTFIELD         9
  107. #define    AUTOMATICFIELD     10
  108. #define    DEATHMATCHV2FIELD  11
  109. #define    RESPAWNFIELD       12
  110. #define    NOMONSTERSFIELD    13
  111. #define    FASTMONSTERSFIELD  14
  112.  
  113. #define    DEFAULTVERSION     0                                                                     /* This effectively means 1.0 */
  114. #define    DEFAULTEPISODE     1 
  115. #define    DEFAULTDIFFICULTY  3 
  116. #define    DEFAULTPLAYTYPE    1 
  117. #define    DEFAULTLEVEL       1 
  118. #define    DEFAULTDMATCH      FALSE 
  119. #define    DEFAULTDMATCHV2    FALSE 
  120. #define    DEFAULTRESPAWN     FALSE
  121. #define    DEFAULTNOMONSTERS  FALSE
  122. #define    DEFAULTFASTMONST   FALSE
  123. #define    DEFAULTSOCKET      0
  124. #define    DEFAULTNODES       2
  125. #define    DEFAULTCOMPORT     1
  126. #define    DEFAULTWADDIR      "."                                                                            /* Current directory */
  127. #define    DEFAULTINFOFILE    "WADS.DSC"
  128.  
  129. #define    KEY_EPISODE        'E'                                                     /* Keyboard equivalents of mouse selections */
  130. #define    KEY_LEVEL          'L'
  131. #define    KEY_DIFFICULTY     'S'                                                                                      /* (Skill) */
  132. #define    KEY_PLAYTYPE       'T'
  133. #define    KEY_NODES          'N'
  134. #define    KEY_COMPORT        'C'
  135. #define    KEY_DEATHMATCH     'D'
  136. #define    KEY_DEATHMATCHV2   'V'
  137. #define    KEY_AUTO           'A'
  138. #define    KEY_READPREVIOUS   'R'
  139. #define    KEY_NOMONSTERS     'M'
  140. #define    KEY_RESPAWNMONST   'P'
  141. #define    KEY_FASTMONSTERS   'F'
  142. #define    KEY_ABORT          0x1B                                                                                       /* [ESC] */
  143. #define    KEY_STARTGAME      0x0D                                                                                    /* [RETURN] */
  144. #define    KEY_PAGEUP         0x4900
  145. #define    KEY_PAGEDOWN       0x5100
  146. #define    KEY_DELETEWAD      0x5300                                                                                     /* [DEL] */
  147. #define    KEY_HELP           0x3B00                                                                                      /* [F1] */
  148. #define    KEY_RESCAN         0x3F00                                                                                      /* [F5] */
  149. #define    KEY_TOGGLEFULL     0x4100                                                                                      /* [F7] */
  150. #define    KEY_TOGGLESORT     0x4200                                                                                      /* [F8] */
  151.  
  152. #define    KEY_CURSLEFT       0x4B00
  153. #define    KEY_CURSRIGHT      0x4D00
  154. #define    KEY_CURSUP         0x4800
  155. #define    KEY_CURSDOWN       0x5000
  156. #define    KEY_SELECTFILE     0x3900                                                                                   /* [SPACE] */
  157.  
  158. #define    RETURNERROR        1                                                                              /* Define exit codes */
  159. #define    RETURNABORT        1
  160. #define    RETURNSTART        0
  161.  
  162. #define    NUMEPISODE         3                                                         /* Define the number of possible episodes */
  163. #define    NUMLEVEL           9                                                           /* Define the number of possible levels */
  164. #define    NUMDIFFICULTY      5
  165. #define    NUMPLAYTYPE        3
  166.  
  167. #define    NUMOPTIONS         18                                                       /* Define the number of CONFIGFILE options */
  168.  
  169. #define    MAXIGNORE          12                                         /* Define number of WAD 'directory' identifiers per type */
  170. #define    MAXCOLORS          2
  171. #define    MAXDEMOS           1
  172. #define    MAXLEVELS          NUMEPISODE * NUMLEVEL
  173. #define    MAXSPRITES         74
  174. #define    MAXSOUNDS          2
  175. #define    MAXMUSIC           3
  176. #define    MAXGRAPHS          0
  177. #define    MAXADDSWITCHES     5
  178.  
  179. #define    NEWCOLORS          0x01                             /* Define bits for the 'NewStuff' field in the 'wadinfo' structure */
  180. #define    NEWDEMOS           0x02
  181. #define    NEWSOUNDS          0x04
  182. #define    NEWMUSIC           0x08
  183. #define    NEWSPRITES         0x10
  184. #define    NEWGRAPHS          0x20
  185.  
  186. #define    ToNumber(_Drv)    (toupper ((_Drv)) - 'A' + 1)                                   /* Convert drive name to drive number */
  187. #define    ToName(_Drv)      ((_Drv) + 'A' - 1)                                             /* Convert drive number to drive name */
  188.  
  189. struct     Mouse_s                                                                                           /* Define mouse info */
  190. {
  191.   int      OldXx;                                                                /* Coordinates stored from previous status check */
  192.   int      OldYy;
  193.   int      Xx;                                                                                                          /* 0 - 79 */
  194.   int      Yy;                                                                                                          /* 0 - 29 */
  195.   boolean  CoChange;                                        /* TRUE if coordinates have changed (mouse moved to a next character) */
  196.   boolean  Left;                                                                /* Status of the 3 mouse buttons; TRUE if pressed */
  197.   boolean  Middle;
  198.   boolean  Right;
  199.   boolean  LeftStillPressed;                                 /* TRUE if the left button was also pressed in previous status check */
  200. }          Mouse;
  201.  
  202. struct     WadDir_s                                                                             /* Define info for a WADDIR entry */
  203. {
  204.   char     Drive;                                                                         /* 1 = A, etc., 0 means: no drive given */
  205.   char     Name[_MAX_DIR];
  206.   boolean  DoSubDirs;                                                    /* TRUE if the subdirectories should be searched as well */
  207. };
  208.  
  209. struct     WadInfo_s                                         /* Define info for a WADFILE entry (also used for AUTOINCLUDE files) */
  210. {
  211.   char     Drive;                                                                         /* 1 = A, etc., 0 means: no drive given */
  212.   char     Path[_MAX_DIR];
  213.   char     OrigName[_MAX_FNAME + _MAX_EXT - 1];                                              /* The original name, with extension */
  214.   char     Name[_MAX_FNAME];                                                /* Filled out, no extension (as this is always *.WAD) */
  215.   char     Info[MAXINFOLEN + 1];                                                           /* Info as found in a WADINFOFILE file */
  216.   char     NewStuff;                                                 /* Each bit represents an identifier type (demo, sound, etc) */
  217.   long     NewLevels;                                                                             /* Each bit represents a level: */
  218.                                                                                                         /* bits  0- 8 = episode 1 */
  219.                                                                                                         /* bits  9-17 = episode 2 */
  220.                                                                                                         /* bits 18-26 = episode 3 */
  221.                                                                                                         /* bits 27-31 = unused    */
  222.   boolean  Selected;                                                                     /* TRUE if the WAD is selected on screen */
  223. };
  224.  
  225. struct     WadHeader_s                                                                        /* The first 12 bytes of a WAD file */
  226. {
  227.   char     Type[4];                                                          /* "PWAD" for a patch WAD, "IWAD" for an initial WAD */
  228.   long     DirSize;                                                                   /* Number of entries in the WAD 'directory' */
  229.   long     DirStart;                                       /* Pointer to the location (offset) of the 'directory' in the WAD file */
  230. };
  231.  
  232. struct     WadDirectory_s                                                                  /* A 'directory' entry in the WAD file */
  233. {
  234.   long     Start;                                                            /* Pointer to the data of this entry in the WAD file */
  235.   long     Size;                                                                                   /* Length in bytes of the data */
  236.   char     Name[ENTRYLEN];                                                                     /* Identifier (name) of this entry */
  237. };
  238.  
  239. struct     ExtCom_s                                                /* The commands that are available for the ADDSWITCHES keyword */
  240. {
  241.   char    *Command;                                                                                     /* The name of the switch */
  242.   boolean  InUse;                                                              /* TRUE if this switch was given in the CONFIGFILE */
  243. };
  244.  
  245. struct     ConfOp_s                                                                     /* The commands available in a CONFIGFILE */
  246. {
  247.   char    *OptionName;
  248.   enum
  249.   {
  250.     OPT_VERSION,
  251.     OPT_DOOMDIR,
  252.     OPT_WADDIR,
  253.     OPT_AUTOINC,
  254.     OPT_ADDSWIT,
  255.     OPT_PLAYTYP,
  256.     OPT_SET,
  257.     OPT_NUM,
  258.     OPT_STRING,
  259.     OPT_FILE,
  260.     OPT_SORTFIL
  261.   }        OptionType;
  262.   void far *DataPtr;
  263. };
  264.  
  265. struct     WadDir_s  far *WadDir[MAXWADDIRS];
  266. struct     WadInfo_s far *WadInfo[MAXWADS];
  267. struct     WadInfo_s far *AutoInc[MAXAUTOINCLUDE];
  268.  
  269. char       CurPath[_MAX_DIR];                                                           /* Current directory (preceded by drive:) */
  270. char       ConfigFile[_MAX_PATH];                                                                   /* Filename of the CONFIGFILE */
  271. char       InfoFile[_MAX_PATH];                                             /* Filename of WADINFOFILE as found in the CONFIGFILE */
  272. char       DoomDirectory[_MAX_PATH];                                        /* The main DOOM directory as found in the CONFIGFILE */
  273. char       IpxDriver[256];                                                     /* Different IPX driver as found in the CONFIGFILE */
  274. char       SerDriver[256];                                                     /* Different SER driver as found in the CONFIGFILE */
  275. char       S[256];                                                                                          /* All-purpose string */
  276. char       CurrentField;                                                                      /* Current FIELD type (see defines) */
  277. char       SelectionChange;                                                      /* Used in file FIELD; TRUE if selection toggled */
  278. char       CurrentPage;                                                                                /* Current file FIELD page */
  279. char       LastPage;                                                                                      /* Last file FIELD page */
  280. int        CurDrive;                                                                                             /* Current drive */
  281. int        DoomDrive;                                                                             /* Drive of main DOOM directory */
  282. int        TotalWads;                                                                          /* Total number of found WAD files */
  283. int        TotalWadDirs;                                                 /* Total number of read WADDIR entries in the CONFIGFILE */
  284. int        TotalAutoInc;                                              /* Total number of read AUTOINCLUDE entries in a CONFIGFILE */
  285. int        M;
  286. int        N;
  287. int        Dummy;                                                                               /* Used in _dos_setdrive function */
  288. boolean    OtherSerDriver;                                             /* TRUE if a different SERDRIVER was found in a CONFIGFILE */
  289. boolean    OtherIpxDriver;                                             /* TRUE if a different IPXDRIVER was found in a CONFIGFILE */
  290. boolean    UseMouse;                                                                            /* TRUE if a mouse has been found */
  291. boolean    MouseHidden;                                                        /* TRUE if the mouse pointer is temporarely hidden */
  292. boolean    Rescan           = FALSE;                                                /* TRUE if '-R' was given on the command line */
  293. boolean    ConfigChange     = FALSE;                              /* TRUE if a different CONFIGFILE was given on the command line */
  294. boolean    ScreenOpen       = FALSE;
  295. boolean    DoNotSearch      = FALSE;                                              /* TRUE if NOSEARCH was found in the CONFIGFILE */
  296. boolean    SortWadFiles     = FALSE;                                             /* TRUE if SORTFILES was found in the CONFIGFILE */
  297. boolean    SortByName       = TRUE;                                                          /* TRUE for "NAME", FALSE for "INFO" */
  298. boolean    NoFullName       = FALSE;                                            /* TRUE if NOFULLNAME was found in the CONFIGFILE */
  299. boolean    NoAutoReturn     = FALSE;                                          /* TRUE if NOAUTORETURN was found in the CONFIGFILE */
  300.  
  301. int        CurrentSelected  = 0;                                                           /* Current pointed WAD file, 0 if none */
  302. int        PreviousWad      = 0;                                                          /* Previous pointed WAD file, 0 if none */
  303. int        EpisodeActive    = DEFAULTEPISODE;                                                      /* Initialize selection FIELDs */
  304. int        DifficultyActive = DEFAULTDIFFICULTY;
  305. int        PlayTypeActive   = DEFAULTPLAYTYPE;
  306. int        NumNodesActive   = DEFAULTNODES;
  307. int        NetworkSocket    = DEFAULTSOCKET;
  308. int        CommPortActive   = DEFAULTCOMPORT;
  309. int        CurrentLevel     = DEFAULTLEVEL;
  310. int        DoomVersion      = DEFAULTVERSION;                          /* 'DoomVersion' holds the decimal 0, 1, 2, 4, 5, 6 or 666 */
  311. boolean    DeathmatchOn     = DEFAULTDMATCH;
  312. boolean    DeathmatchV2On   = DEFAULTDMATCHV2;
  313. boolean    RespMonstersOn   = DEFAULTRESPAWN;
  314. boolean    NoMonstersOn     = DEFAULTNOMONSTERS;
  315. boolean    FastMonstersOn   = DEFAULTFASTMONST;
  316.  
  317. char      *Episodes[]       = {"Knee-Deep in the Dead", "The Shores of Hell   ", "Inferno              "};
  318. char      *Difficulties[]   = {"I'm too young to die ", "Hey, not too rough   ", "Hurt me plenty       ", "Ultra-Violence!      ",
  319.                                "NIGHTMARE            "};
  320. char      *PlayTypes[]      = {"Alone                ", "IPX-compatible       ", "Serial link          "};
  321. char      *NumberNodes      =  "Number of players    ";
  322. char      *CommPort         =  "COM port             ";
  323. char      *Level            =  "LEVEL                ";
  324. char      *Deathmatch       =  "DEATHMATCH!          ";
  325. char      *DeathmatchV2     =  "DEATHMATCH! V2.0     ";
  326. char      *NoMonsters       =  "No Monsters          ";
  327. char      *RespawnMonsters  =  "Respawn monsters     ";
  328. char      *FastMonsters     =  "Fast monsters        ";
  329. char      *Boxes[]          = {"( ) ",                  "(\x07) "};
  330. char      *PreviousPage     =  "<<<";
  331. char      *NextPage         =  ">>>";
  332. char      *StartGame        =  "( START DOOM! )";
  333. char      *Automatic        =  "( AUTO SELECT )";
  334. char      *ReadPrevious     =  "(READ PREVIOUS)";
  335. char      *NoLevel          =  "-         ";
  336.  
  337. char      *IdIgnore[]       = {"THINGS",   "LINEDEFS", "SIDEDEFS", "VERTEXES", "SEGS", "SSECTORS", "NODES", "SECTORS", "REJECT",
  338.                                "BLOCKMAP", "INFOPACK", "PLATFORM"};                           /* Last 2 are NOT from Id Software! */
  339. char      *IdColors[]       = {"PLAYPAL", "COLORMAP", "c", "palette"};
  340. char      *IdDemos[]        = {"DEMO", "d", "demos"};
  341. char      *IdLevels[]       = {"E1M1", "E1M2", "E1M3", "E1M4", "E1M5", "E1M6", "E1M7", "E1M8", "E1M9",
  342.                                "E2M1", "E2M2", "E2M3", "E2M4", "E2M5", "E2M6", "E2M7", "E2M8", "E2M9",
  343.                                "E3M1", "E3M2", "E3M3", "E3M4", "E3M5", "E3M6", "E3M7", "E3M8", "E3M9", "E", "M"};
  344. char      *IdSprites[]      = {"SARG", "TROO", "BOSS", "PLAY", "POSS", "SPOS", "SKUL", "HEAD", "CYBR", "SPID", "CHG",  "SAW",
  345.                                "PIS",  "PBU",  "PSH",  "BAL",  "PUF",  "BLU",  "MIS",  "TFO",  "PUN",  "SHT",  "PLS",  "BFG",
  346.                                "BFS",  "BFE",  "POL",  "CAND", "CBRA", "SHOT", "MGUN", "LAUN", "CSAW", "CLIP", "SHEL", "ROCK",
  347.                                "STIM", "MEDI", "ARM",  "BAR",  "BPAK", "BROK", "AMMO", "SBOX", "ELEC", "BKEY", "YKEY", "RKEY",
  348.                                "SUIT", "PVIS", "BEXP", "PMAP", "PIN",  "BON",  "SOUL", "COL",  "FSKU", "CEYE", "TRE",  "SMI",
  349.                                "BSKU", "RSKU", "YSKU", "PLAS", "BFUG", "CELL", "PSTR", "CELP", "GOR",  "TGRN", "TBLU", "SMRT",
  350.                                "SMBT", "SMGT", "p", "sprites"};
  351. char      *IdSounds[]       = {"DS", "DP", "s", "sounds"};
  352. char      *IdMusic[]        = {"D_", "GENMIDI", "DMXGUS", "m", "music"};
  353. char      *IdGraphics[]     = {"g", "graphics"};
  354.  
  355. struct    ConfOp_s ConfOp[] = {{"DOOMDIR",     OPT_DOOMDIR,  NOMEM},
  356.                                {"DOOMVERSION", OPT_VERSION,  NOMEM},
  357.                                {"WADDIR",      OPT_WADDIR,   NOMEM},
  358.                                {"WADINFOFILE", OPT_FILE,     InfoFile},
  359.                                {"SETSKILL",    OPT_NUM,     &DifficultyActive},
  360.                                {"DEATHMATCH",  OPT_SET,     &DeathmatchOn},
  361.                                {"AUTOINCLUDE", OPT_AUTOINC,  NOMEM},
  362.                                {"NOSEARCH",    OPT_SET,     &DoNotSearch},
  363.                                {"SETCOMPORT",  OPT_NUM,     &CommPortActive},
  364.                                {"SETNODES",    OPT_NUM,     &NumNodesActive},
  365.                                {"SETPLAYTYPE", OPT_PLAYTYP,  NOMEM},
  366.                                {"ADDSWITCHES", OPT_ADDSWIT,  NOMEM},
  367.                                {"SORTFILES",   OPT_SORTFIL,  NOMEM},
  368.                                {"SETSOCKET",   OPT_NUM,     &NetworkSocket},
  369.                                {"IPXDRIVER",   OPT_STRING,   IpxDriver},
  370.                                {"SERDRIVER",   OPT_STRING,   SerDriver},
  371.                                {"NOFULLNAME",  OPT_SET,     &NoFullName},
  372.                                {"NOAUTORETURN",OPT_SET,     &NoAutoReturn}};
  373.  
  374. struct    ExtCom_s ExtCom[] = {{"-NOJOY",   FALSE},
  375.                                {"-NOMOUSE", FALSE},
  376.                                {"-NOMUSIC", FALSE},
  377.                                {"-NOSFX",   FALSE},
  378.                                {"-NOSOUND", FALSE}};
  379.  
  380. int ResetMouse (void)
  381.  
  382. /**********************************************************************************************************************************/
  383. /* Pre   : None.                                                                                                                  */
  384. /* Post  : The mouse driver has been reset. If no mouse was found, then 0 is returned. Anything else means success.               */
  385. /* Import: None.                                                                                                                  */
  386. /**********************************************************************************************************************************/
  387.  
  388. {
  389.   int Result;
  390.  
  391.   _asm
  392.   {
  393.     mov ax, 0x0000 
  394.     int 0x33
  395.     mov Result, ax
  396.   } 
  397.   return (Result);
  398. }
  399.  
  400. void ShowMouse (void)
  401.  
  402. /**********************************************************************************************************************************/
  403. /* Pre   : (global) 'UseMouse' is TRUE if a mouse has been detected.                                                              */
  404. /* Post  : The mouse pointer is made visable.                                                                                     */
  405. /* Import: None.                                                                                                                  */
  406. /**********************************************************************************************************************************/
  407.  
  408. {
  409.   if (UseMouse)
  410.     _asm
  411.     {
  412.       mov ax, 0x0001
  413.       int 0x33
  414.     }
  415. }
  416.  
  417. void HideMouse (void)
  418.  
  419. /**********************************************************************************************************************************/
  420. /* Pre   : (global) 'UseMouse' is TRUE if a mouse has been detected.                                                              */
  421. /* Post  : The mouse pointer is made invisable.                                                                                   */
  422. /* Import: None.                                                                                                                  */
  423. /**********************************************************************************************************************************/
  424.  
  425. {
  426.   if (UseMouse)
  427.     _asm
  428.     {
  429.       mov ax, 0x0002
  430.       int 0x33
  431.     }
  432. }
  433.  
  434. void MouseStatus (void)
  435.  
  436. /**********************************************************************************************************************************/
  437. /* Pre   : None.                                                                                                                  */
  438. /* Post  : The mouse driver has been read, which returns the status of the buttons and the x and y coordinates of the mouse.      */
  439. /*         All this information is stored in the 'Mouse' structure.                                                               */
  440. /* Import: None.                                                                                                                  */
  441. /**********************************************************************************************************************************/
  442.  
  443. {
  444.   int Result;
  445.  
  446.   Mouse.LeftStillPressed = Mouse.Left;
  447.   _asm
  448.   {
  449.     mov ax, 0x0003
  450.     int 0x33
  451.     mov Mouse.Xx, cx
  452.     mov Mouse.Yy, dx
  453.     mov Result, bx
  454.   }
  455.   Mouse.Left = (Result & 0x0001);                                                        /* Store the status of the mouse buttons */
  456.   Mouse.Right = (Result & 0x0002);
  457.   Mouse.Middle = (Result & 0x0004);
  458.   Mouse.Xx /= 0x0008;                                                       /* Convert pixel coordinates to character coordinates */
  459.   Mouse.Yy /= 0x0010;
  460.   Mouse.CoChange = (Mouse.OldXx != Mouse.Xx || Mouse.OldYy != Mouse.Yy);
  461.   if (!Mouse.Left)
  462.     Mouse.LeftStillPressed = FALSE;
  463. }
  464.  
  465. void DeAllocateAll (void)
  466.  
  467. /**********************************************************************************************************************************/
  468. /* Pre   : None.                                                                                                                  */
  469. /* Post  : If any WadDirs were initialized yet, then the memory is deallocated completely.                                        */
  470. /*         If any WadInfos were initialized yet, then the memory is deallocated completely.                                       */
  471. /*         If any AutoIncs were initialized yet, then the memory is deallocated completely.                                       */
  472. /* Import: None.                                                                                                                  */
  473. /**********************************************************************************************************************************/
  474.  
  475. {
  476.   fcloseall ();
  477.   flushall ();
  478.   while (-- TotalWadDirs >= 0)
  479.     _ffree (WadDir[TotalWadDirs]);
  480.   while (-- TotalWads >= 0)
  481.     _ffree (WadInfo[TotalWads]);
  482.   while (-- TotalAutoInc >= 0)
  483.     _ffree (AutoInc[TotalAutoInc]);
  484. }
  485.  
  486. void Bye (int ReturnType, char *Message, ...)
  487.  
  488. /**********************************************************************************************************************************/
  489. /* Pre   : 'ReturnType' holds the exit code, 'Message' holds the error message.                                                   */
  490. /* Post  : The error message has been printed, all memory is freed and the program has been aborted.                              */
  491. /* Import: DeAllocateAll.                                                                                                         */
  492. /**********************************************************************************************************************************/
  493.  
  494. {
  495.   va_list Args;
  496.  
  497.   if (ScreenOpen)                                                                                     /* Still in graphics mode ? */
  498.     _setvideomode (_DEFAULTMODE);                                                                        /* Then close the screen */
  499.   va_start (Args, Message);
  500.   vfprintf (stderr, Message, Args);                                                        /* Print the (formatted) error message */
  501.   va_end (Args);
  502.   _dos_setdrive (CurDrive, &Dummy);                                                         /* Return to home drive and directory */
  503.   chdir (CurPath);
  504.   DeAllocateAll ();
  505.   exit (ReturnType);
  506. }
  507.  
  508. void PrText (short UseBox, short Y0, short X0, unsigned char Color, char *Msg, ...)
  509.  
  510. /**********************************************************************************************************************************/
  511. /* Pre   : 'Y0' and 'X0' hold the coordinates, 'Color' holds the (VGA) color and 'Msg' holds the message to print.                */
  512. /*         UseBox < 0: no selection box is printed first;                                                                         */
  513. /*         UseBox = 0: an empty selection box is printed first;                                                                   */
  514. /*         UseBox > 0: a filled selection box is printed first;                                                                   */
  515. /*         If Y0 is 0, then the coordinates are not used; the text is written directly after the previous.                        */
  516. /* Post  : If the coordinates were non-zero, then the message is printed at these coordinates in the given color. The coordinates */
  517. /*         are first converted to the pixel coordinates according to the used font.                                               */
  518. /* Import: None.                                                                                                                  */
  519. /**********************************************************************************************************************************/
  520.  
  521. {
  522.   char     Message[80];
  523.   va_list  Args;
  524.  
  525.   va_start (Args, Msg);
  526.   vsprintf (Message, Msg, Args);                                                           /* Convert the message into one string */
  527.   va_end (Args);
  528.   if (Y0 != 0)
  529.     _settextposition (Y0, X0);
  530.   _settextcolor (Color);
  531.   if (UseBox == 0)
  532.     _outtext (Boxes[0]);
  533.   if (UseBox > 0)
  534.     _outtext (Boxes[1]);
  535.   _outtext (Message);
  536. }
  537.  
  538. void InitVideo (void)
  539.  
  540. /**********************************************************************************************************************************/
  541. /* Pre   : None.                                                                                                                  */
  542. /* Post  : A VGA display of 640 x 480 x 16 colors has been opened and the screen has been cleared.                                */
  543. /* Import: Bye.                                                                                                                   */
  544. /**********************************************************************************************************************************/
  545.  
  546. {
  547.   if (!_setvideomode (_VRES16COLOR))
  548.     Bye (RETURNERROR, "ERROR - You need a VGA videocard for this utility\n");
  549.   _clearscreen (_GCLEARSCREEN);
  550. }
  551.  
  552. char *TestName (char *OldName)
  553.  
  554. /**********************************************************************************************************************************/
  555. /* Pre   : 'OldName' holds the name to be tested.                                                                                 */
  556. /* Post  : The name is tested. The return value is a string of the (adapted) input with the following specifications:             */
  557. /*         - Each part (subdirname) has at most 8 characters, possibly followed by a '.' and at most 3 characters.                */
  558. /*         - Each of the characters is valid to the DOS system.                                                                   */
  559. /*         - Trailing backslashes have been cut, except when it was the only path character.                                      */
  560. /* Import: Bye.                                                                                                                   */
  561. /**********************************************************************************************************************************/
  562.  
  563. {
  564.   char    Level[_MAX_PATH];
  565.   char    NewName[_MAX_PATH];
  566.   char    Part[_MAX_FNAME];
  567.   int     LvlCnt;
  568.   int     Ex;
  569.   int     PathLenOldName;
  570.   int     CharCnt;
  571.   int     PartChar;
  572.   boolean PointDone;
  573.   boolean NError          = FALSE;
  574.   boolean DriveFound      = FALSE;
  575.   boolean Ready           = FALSE;
  576.  
  577.   PathLenOldName = strlen (OldName);
  578.   CharCnt = -1;
  579.   NewName[0] = '\0';
  580.   while (!Ready && !NError)
  581.   {
  582.     LvlCnt = 0;
  583.     while ((++ CharCnt < PathLenOldName) && OldName[CharCnt] != '\\' && OldName[CharCnt] != ':')
  584.       Level[LvlCnt ++] = OldName[CharCnt];
  585.     Level[LvlCnt] = '\0';
  586.     if (OldName[CharCnt] == ':')                                                                         /* Preceded by drive: ?  */
  587.       if (DriveFound)                                                                                   /* Already a drive found! */
  588.         NError = TRUE;
  589.       else
  590.       {
  591.         DriveFound = TRUE;
  592.         strncpy (NewName, OldName, CharCnt + 1);
  593.         NewName[CharCnt + 1] = '\0';
  594.         if (CharCnt != 1 || toupper (OldName[0]) < 'A' || toupper (OldName[0]) > 'Z')                      /* Test drive validity */
  595.           Bye (RETURNERROR, "\nERROR - Invalid drivename %s\n", NewName);
  596.         if (CharCnt == PathLenOldName - 1)
  597.           Ready = TRUE;                                                                               /* Only a driveletter given */
  598.         else
  599.           if (CharCnt == PathLenOldName - 2 && OldName[CharCnt + 1] == '\\')
  600.           {
  601.             Ready = TRUE;                                                                 /* Exceptional case: only drive:\ given */
  602.             strcpy (NewName, OldName);
  603.           }
  604.       }
  605.     else
  606.     {
  607.       if (CharCnt == PathLenOldName)                                                                      /* Handling last part ? */
  608.         Ready = TRUE;
  609.       if (CharCnt == PathLenOldName - 1 && OldName[CharCnt] == '\\')
  610.         Ready = TRUE;                                                                                     /* Ended with backslash */
  611.       PointDone = FALSE;
  612.       for (PartChar = 0 ; PartChar < strlen (Level) ; PartChar ++)
  613.         switch (Level[PartChar])
  614.         {
  615.           case '.'     : if (!PointDone)
  616.                          {
  617.                            strncpy (Part, Level, PartChar < 8 ? PartChar : 8);
  618.                            Part[PartChar < 8 ? PartChar : 8] = '\0';                                         /* Cut >8 characters */
  619.                            strcat (NewName, Part);
  620.                            strcat (NewName, ".");                                                                  /* Add the '.' */
  621.                            Ex = PartChar + 1;
  622.                            PointDone = TRUE;
  623.                          }
  624.                          else
  625.                            if (strcmp (Level, ".."))                                                          /* Exceptional case */
  626.                              NError = TRUE;
  627.                          break;
  628.           case ';'     :
  629.           case ','     :
  630.           case '\''    :
  631.           case '/'     :
  632.           case '('     :
  633.           case ')'     :
  634.           case '['     :
  635.           case ']'     :                                      /* Characters '>', '<', '|' '"' and '\' have already been taken out */
  636.           case '='     : NError = TRUE;                                                                     /* All bad characters */
  637.                          break;
  638.         }
  639.       if (!PointDone)                                                                       /* Finish filenames without extension */
  640.       {
  641.         strncpy (Part, Level, PartChar < 8 ? PartChar : 8);
  642.         Part[PartChar < 8 ? PartChar : 8] = '\0';
  643.         strcat (NewName, Part);
  644.         PointDone = TRUE;
  645.       }
  646.       else                                                                       /* This also deals with the second point in '..' */
  647.       {
  648.         strncpy (Part, Level + Ex, PartChar - Ex < 3 ? PartChar - Ex : 3);                                   /* Cut >3 characters */
  649.         Part[PartChar - Ex < 3 ? PartChar - Ex : 3] = '\0';
  650.         strcat (NewName, Part);
  651.       }
  652.       if (!Ready)
  653.         strcat (NewName, "\\");                                                                       /* Add the subdir character */
  654.     }
  655.   }
  656.   if (NError)                                                                                            /* Report bad characters */
  657.     Bye (RETURNERROR, "\nERROR - Invalid name %s\n", OldName);
  658.   if (!strlen (NewName) && OldName[0] == '\\')                                                              /* Input was root dir */
  659.     return ("\\");                                                                         /* Which should be treated differently */
  660.   else
  661.     return (NewName);                                                                                 /* Return (modified) string */
  662. }
  663.  
  664. void GetWadInfo (int WadNumber, boolean GoThere)
  665.  
  666. /**********************************************************************************************************************************/
  667. /* Pre   : 'WadNumber' holds the WAD file number in memory that should be checked.                                                */
  668. /*         'GoThere' is TRUE if the routine should first go to the required drive and directory.                                  */
  669. /* Post  : The WAD directory of the file has been found and read out. The structure 'wadinfo' has been updated.                   */
  670. /* Import: Bye.                                                                                                                   */
  671. /**********************************************************************************************************************************/
  672.  
  673. {
  674.   FILE   *Fp;
  675.   struct  WadDirectory_s WadDirectory;
  676.   struct  WadHeader_s    WadHeader;
  677.   char    Identifier[9];
  678.   char    DrivePath[_MAX_DIR];
  679.   int     O;
  680.   long    Entries;
  681.   boolean More;
  682.  
  683.   if (GoThere)                                                                                 /* Jump to the directory if needed */
  684.   {
  685.     _dos_setdrive (WadInfo[WadNumber]->Drive, &Dummy);
  686.     free (getcwd (DrivePath, _MAX_DIR - 1));                                                         /* Collect current directory */
  687.     chdir (WadInfo[WadNumber]->Path);
  688.   }
  689.   if (!(Fp = fopen (WadInfo[WadNumber]->OrigName, "rb")))
  690.     Bye (RETURNERROR, "\nERROR - Error opening file %s\n", WadInfo[WadNumber]->OrigName);
  691.   if (fread (&WadHeader, 1, sizeof (struct WadHeader_s), Fp) != sizeof (struct WadHeader_s))               /* Read the WAD header */
  692.     Bye (RETURNERROR, "\nERROR - Error reading file %s\n", WadInfo[WadNumber]->OrigName);
  693.   if (strnicmp (WadHeader.Type, "PWAD", 4) && strnicmp (WadHeader.Type, "IWAD", 4))                         /* Is it a WAD file ? */
  694.     Bye (RETURNERROR, "\nERROR - File %s is not a WAD file\n", WadInfo[WadNumber]->OrigName);
  695.   if (fseek (Fp, WadHeader.DirStart, SEEK_SET))                                     /* Go to the WAD 'directory' part of the file */
  696.     Bye (RETURNERROR, "\nERROR - Error reading file %s\n", WadInfo[WadNumber]->OrigName);
  697.   WadInfo[WadNumber]->NewStuff = 0x00;                                                                       /* Clear all entries */
  698.   WadInfo[WadNumber]->NewLevels = 0x00000000;
  699.   Entries = -1;                                                                              /* Count all WAD 'directory' entries */
  700.   while (++ Entries < WadHeader.DirSize)                                     /* The number of entries was found in the WAD header */
  701.   {
  702.     if (fread (&WadDirectory, 1, sizeof (struct WadDirectory_s), Fp) != sizeof (struct WadDirectory_s))          /* Read an entry */
  703.       Bye (RETURNERROR, "\nERROR - Error reading file %s\n", WadInfo[WadNumber]->OrigName);
  704.     for (O = 0 ; O < ENTRYLEN ; O ++)                                                       /* Fill the identifier to 8 positions */
  705.       Identifier[O] = WadDirectory.Name[O];
  706.     Identifier[ENTRYLEN] = '\0';                                                                          /* And make it a string */
  707.     More = TRUE;                                                            /* Now test it against all types and signal successes */
  708.     for (O = 0 ; O < MAXIGNORE && More ; O ++)
  709.       if (!strnicmp (Identifier, IdIgnore[O], strlen (IdIgnore[O])))
  710.         More = FALSE;
  711.     if (More)
  712.       for (O = 0 ; O < MAXCOLORS && More ; O ++)
  713.         if (!strnicmp (Identifier, IdColors[O], strlen (IdColors[O])))
  714.         {
  715.           More = FALSE;
  716.           WadInfo[WadNumber]->NewStuff |= NEWCOLORS;
  717.         }
  718.     if (More)
  719.       for (O = 0 ; O < MAXDEMOS && More ; O ++)
  720.         if (!strnicmp (Identifier, IdDemos[O], strlen (IdDemos[O])))
  721.         {
  722.           More = FALSE;
  723.           WadInfo[WadNumber]->NewStuff |= NEWDEMOS;
  724.         }
  725.     if (More)
  726.       for (O = 0 ; O < MAXLEVELS && More ; O ++)
  727.         if (!strnicmp (Identifier, IdLevels[O], strlen (IdLevels[O])))
  728.         {
  729.           More = FALSE;
  730.           WadInfo[WadNumber]->NewLevels |= ((long)1 << O);
  731.         }
  732.     if (More)
  733.       for (O = 0 ; O < MAXSPRITES && More ; O ++)
  734.         if (!strnicmp (Identifier, IdSprites[O], strlen (IdSprites[O])))
  735.         {
  736.           More = FALSE;
  737.           WadInfo[WadNumber]->NewStuff |= NEWSPRITES;
  738.         }
  739.     if (More)
  740.       for (O = 0 ; O < MAXSOUNDS && More ; O ++)
  741.         if (!strnicmp (Identifier, IdSounds[O], strlen (IdSounds[O])))
  742.         {
  743.           More = FALSE;
  744.           WadInfo[WadNumber]->NewStuff |= NEWSOUNDS;
  745.         }
  746.     if (More)
  747.       for (O = 0 ; O < MAXMUSIC && More ; O ++)
  748.         if (!strnicmp (Identifier, IdMusic[O], strlen (IdMusic[O])))
  749.         {
  750.           More = FALSE;
  751.           WadInfo[WadNumber]->NewStuff |= NEWMUSIC;
  752.         }
  753.     if (More && WadDirectory.Start != NULL && Identifier[0] != '\0')             /* All other identifiers are counted as graphics */
  754.       WadInfo[WadNumber]->NewStuff |= NEWGRAPHS;
  755.   }
  756.   fclose (Fp);
  757.   if (GoThere)
  758.   {
  759.     chdir (DrivePath);
  760.     _dos_setdrive (CurDrive, &Dummy);                                                                  /* Return to home location */
  761.   }
  762. }
  763.  
  764. void WriteWadInfo (char *FileName)
  765.  
  766. /**********************************************************************************************************************************/
  767. /* Pre   : 'FileName' holds the name of the file (which is the same as set in 'InfoFile').                                        */
  768. /* Post  : All found WAD files are considered. All files have their fields 'NewStuff' and 'NewLevels' initialized. This info is   */
  769. /*         converted into readable text and written to the file, together with the path information of the WAD file.              */
  770. /* Import: None.                                                                                                                  */
  771. /**********************************************************************************************************************************/
  772.  
  773. {
  774.   FILE    *Fp;
  775.   char     Memory;
  776.   char     P;
  777.   char     Q;
  778.   char     T[81];
  779.   int      WadNumber;
  780.   boolean  First;
  781.   boolean  New;
  782.   boolean  More;
  783.  
  784.   if (!(Fp = fopen (FileName, "w")))
  785.     Bye (RETURNERROR, "\nERROR - Cannot write WAD info file\n");
  786.   for (WadNumber = 0 ; WadNumber < TotalWads ; WadNumber ++)
  787.   {
  788.     More = FALSE;
  789.     S[0] = '\0';
  790.     fprintf (Fp, "%d %s %s ", WadInfo[WadNumber]->Drive, WadInfo[WadNumber]->Path, WadInfo[WadNumber]->OrigName);
  791.     More = (WadInfo[WadNumber]->NewLevels != 0x00000000);                            /* Are their any patch levels in this file ? */
  792.     if (More)                                                                                                      /* Skip if not */
  793.     {
  794.       for (P = 0 ; P < NUMEPISODE ; P ++)
  795.       {
  796.         Memory = -1;
  797.         First = TRUE;
  798.         if ((WadInfo[WadNumber]->NewLevels & ((long)0x1ff << (P * NUMLEVEL))) == ((long)0x1ff << (P * NUMLEVEL)))
  799.         {                                                                                   /* All 9 level-bits of an episode set */
  800.           sprintf (T, "%s%d-", IdLevels[MAXLEVELS], (int)P + 1);
  801.           strcat (S, T);
  802.         }
  803.         else                                                                                        /* Possibly a partial episode */
  804.           for (Q = 0 ; Q < NUMLEVEL ; Q ++)                                              /* Handle all level-bits in this episode */
  805.             if (WadInfo[WadNumber]->NewLevels & ((long)1 << (P * NUMLEVEL + Q)))
  806.             {
  807.               if (Memory == -1)
  808.                 if (First)
  809.                 {
  810.                   sprintf (T, "%s%d%s%d", IdLevels[MAXLEVELS], (int)P + 1, IdLevels[MAXLEVELS + 1], (int)Q + 1);
  811.                   strcat (S, T);
  812.                   First = FALSE;
  813.                   Memory = 1;
  814.                   New = FALSE;
  815.                 }
  816.                 else
  817.                 {
  818.                   sprintf (T, ",%d", (int)Q + 1);
  819.                   strcat (S, T);
  820.                   Memory = Q + 1;
  821.                   New = FALSE;
  822.                 }
  823.               else
  824.               {
  825.                 Memory ++;
  826.                 New = TRUE;
  827.               }
  828.             }
  829.             else
  830.             {
  831.               if (Memory > 0 && New)
  832.               {
  833.                 sprintf (T, "-%d", (int)Memory);
  834.                 strcat (S, T);
  835.               }
  836.               Memory = -1;
  837.             }
  838.         if (Memory > 0 && New)
  839.         {
  840.           sprintf (T, "-%d", (int)Memory);
  841.           strcat (S, T);
  842.         }
  843.       }
  844.       sprintf (T, "%-10s", S);
  845.       strcpy (S, T);
  846.     }                                                                                           /* No new levels in this WAD file */
  847.     else                                                                 /* If only one type was found (for example, only sounds) */
  848.       if (!(WadInfo[WadNumber]->NewStuff ^ NEWCOLORS))                   /* Then use the complete word ('sounds' in this example) */
  849.         sprintf (S, "%s", IdColors[MAXCOLORS + 1]);
  850.       else
  851.         if (!(WadInfo[WadNumber]->NewStuff ^ NEWDEMOS))
  852.           sprintf (S, "%s", IdDemos[MAXDEMOS + 1]);
  853.         else
  854.           if (!(WadInfo[WadNumber]->NewStuff ^ NEWSOUNDS))
  855.             sprintf (S, "%s", IdSounds[MAXSOUNDS + 1]);
  856.           else
  857.             if (!(WadInfo[WadNumber]->NewStuff ^ NEWMUSIC))
  858.               sprintf (S, "%s", IdMusic[MAXMUSIC + 1]);
  859.             else
  860.               if (!(WadInfo[WadNumber]->NewStuff ^ NEWSPRITES))
  861.                 sprintf (S, "%s", IdSprites[MAXSPRITES + 1]);
  862.               else
  863.                 if (!(WadInfo[WadNumber]->NewStuff ^ NEWGRAPHS))
  864.                   sprintf (S, "%s", IdGraphics[MAXGRAPHS + 1]);
  865.                 else
  866.                 {
  867.                   More = TRUE;                                                                       /* More than one type found */
  868.                   strcpy (S, NoLevel);                                                                /* Clear level string-part */
  869.                 }
  870.     if (More)                                                                               /* Levels found or more types than 1 */
  871.     {
  872.       if (WadInfo[WadNumber]->NewStuff & NEWCOLORS)                                  /* Print one character to indicate the type */
  873.         strcat (S, IdColors[MAXCOLORS]);
  874.       if (WadInfo[WadNumber]->NewStuff & NEWDEMOS)
  875.         strcat (S, IdDemos[MAXDEMOS]);
  876.       if (WadInfo[WadNumber]->NewStuff & NEWSOUNDS)
  877.         strcat (S, IdSounds[MAXSOUNDS]);
  878.       if (WadInfo[WadNumber]->NewStuff & NEWMUSIC)
  879.         strcat (S, IdMusic[MAXMUSIC]);
  880.       if (WadInfo[WadNumber]->NewStuff & NEWSPRITES)
  881.         strcat (S, IdSprites[MAXSPRITES]);
  882.       if (WadInfo[WadNumber]->NewStuff & NEWGRAPHS)
  883.         strcat (S, IdGraphics[MAXGRAPHS]);
  884.     }
  885.     sprintf (WadInfo[WadNumber]->Info, "%-16s", S);                                                                 /* MAXINFOLEN */
  886.     fprintf (Fp, "%-16s\n", S);
  887.   }
  888.   fclose (Fp);
  889. }
  890.  
  891. int NextString (FILE *Fp, char *String)
  892.  
  893. /**********************************************************************************************************************************/
  894. /* Pre   : 'Fp' points to the open CONFIGFILE, 'String' holds the address of the string to be read.                               */
  895. /* Post  : Any string is read. If it started with a '#' (COMMENT character), then the rest of the line has been ignored. The      */
  896. /*         function does not return before a string was read WITHOUT this character or EOF has been reached. The result of the    */
  897. /*         function is the length of the read string, or 0 if EOF was encountered.                                                */
  898. /* Import: None.                                                                                                                  */
  899. /**********************************************************************************************************************************/
  900.  
  901. {
  902.   char    Ch;
  903.   char    Cnt;
  904.   boolean Ready = FALSE;
  905.   boolean SkipSpaces;
  906.  
  907.   while (!Ready)                                                                            /* Read until a valid string is found */
  908.   {
  909.     SkipSpaces = TRUE;
  910.     while (SkipSpaces)
  911.     {
  912.       fscanf (Fp, "%c", &Ch);                                                                 /* Read until no white-spaces found */
  913.       if (feof (Fp))
  914.       {
  915.         String[0] = '\0';                                                                                         /* Or until EOF */
  916.         return (0);
  917.       }
  918.       SkipSpaces = isspace (Ch);
  919.     }
  920.     if (Ch == COMMENT)                                                              /* First character is the COMMENT character ? */
  921.       do
  922.       {
  923.         fscanf (Fp, "%c", &Ch);                                                                   /* Ignore until end of the line */
  924.         if (feof (Fp))
  925.         {
  926.           String[0] = '\0';                                                                                       /* Or until EOF */
  927.           return (0);
  928.         }
  929.       }
  930.       while (Ch != '\n');
  931.     else
  932.       Ready = TRUE;
  933.   }
  934.   Cnt = 0;
  935.   Ready = FALSE;
  936.   while (!Ready)
  937.   {
  938.     while (!isspace (Ch) && Ch != '"')                                                             /* Trap quoted argument(part)s */
  939.     {
  940.       String[Cnt ++] = Ch;
  941.       fscanf (Fp, "%c", &Ch);                                                                     /* Read until first white-space */
  942.       if (feof (Fp))
  943.       {
  944.         String[Cnt] = '\0';                                                                                       /* Or until EOF */
  945.         return (Cnt);
  946.       }
  947.     }
  948.     if (Ch == '"')                                                                                          /* Handle quoted part */
  949.     {
  950.       do
  951.       {
  952.         fscanf (Fp, "%c", &Ch);
  953.         if (feof (Fp))
  954.           Bye (RETURNERROR, "ERROR - Unexpected end of configuration file\n");
  955.         if (Ch == '\n')
  956.           Bye (RETURNERROR, "ERROR - Unexpected end of line in configuration file\n");
  957.         String[Cnt ++] = Ch;
  958.       }
  959.       while (Ch != '"');
  960.       Cnt --;
  961.       fscanf (Fp, "%c", &Ch);                                                                                 /* Read first after */
  962.       if (feof (Fp))
  963.       {
  964.         String[Cnt] = '\0';                                                                                       /* Or until EOF */
  965.         return (Cnt);
  966.       }
  967.     }
  968.     else
  969.       Ready = TRUE;
  970.   }
  971.   String[Cnt] = '\0';
  972.   return (Cnt);
  973. }
  974.  
  975. void HandleOptWaddir (char *Item)
  976.  
  977. /**********************************************************************************************************************************/
  978. /* Pre   : 'Item' holds an operand that has been read following an 'WADDIR' option.                                               */
  979. /* Post  : If 'Item' holds '/S' (or '-S'), then the previously declared WadDir is flagged 'DoSubDirs'. Otherwise, 'Item' holds a  */
  980. /*         filename, that is included in the WadDir list. If any error occurs, then no return is made.                            */
  981. /* Import: TestName, Bye.                                                                                                         */
  982. /**********************************************************************************************************************************/
  983.  
  984. {
  985.   int     DriveNo;
  986.  
  987.   if (!stricmp (Item, DOSUB1) || !stricmp (Item, DOSUB2))
  988.     if (TotalWadDirs == 0)
  989.       Bye (RETURNERROR, "ERROR - Badly placed switch %s in WADDIR field\n", DOSUB1);
  990.     else
  991.       WadDir[TotalWadDirs - 1]->DoSubDirs = TRUE;
  992.   else
  993.   {
  994.     if (TotalWadDirs == MAXWADDIRS)
  995.       Bye (RETURNERROR, "ERROR - Too many WADDIR entries\n");
  996.     if ((WadDir[TotalWadDirs] = ((struct WadDir_s far *)_fmalloc ((size_t)sizeof (struct WadDir_s)))) == NOMEM)
  997.       Bye (RETURNERROR, "FATAL ERROR - Out of memory\n");
  998.     strcpy (S, TestName (Item));
  999.     if (S[1] == ':')                                                                                      /* Preceded by drive: ? */
  1000.     {
  1001.       if (strlen (S) == 2)                                                                             /* Just a drive, no path ? */
  1002.         Bye (RETURNERROR, "ERROR - Missing path for WADDIR in configuration file\n");
  1003.       DriveNo = ToNumber (S[0]);
  1004.       if (DriveNo != CurDrive)                                                                                   /* A new drive ? */
  1005.         WadDir[TotalWadDirs]->Drive = DriveNo;                                                              /* Store drive number */
  1006.       else
  1007.         WadDir[TotalWadDirs]->Drive = 0;                                                            /* Signal: no new drive given */
  1008.       strcpy (WadDir[TotalWadDirs]->Name, strupr (S + 2));                                                          /* Store path */
  1009.     }
  1010.     else
  1011.     {
  1012.       WadDir[TotalWadDirs]->Drive = 0;                                                                  /* Signal: no drive given */
  1013.       strcpy (WadDir[TotalWadDirs]->Name, strupr (S));
  1014.     }
  1015.     WadDir[TotalWadDirs]->DoSubDirs = FALSE;
  1016.     TotalWadDirs ++;
  1017.   }
  1018. }
  1019.  
  1020. void HandleOptDoomdir (char *Item)
  1021.  
  1022. /**********************************************************************************************************************************/
  1023. /* Pre   : 'Item' holds the operand that has been read following a 'DOOMDIR' option.                                              */
  1024. /* Post  : The (global) variables 'DoomDrive' and 'DoomDirectory' have been initialized.                                          */
  1025. /* Import: TestName, Bye.                                                                                                         */
  1026. /**********************************************************************************************************************************/
  1027.  
  1028. {
  1029.   int     DriveNo;
  1030.  
  1031.   strcpy (S, TestName (Item));
  1032.   if (S[1] == ':')                                                                                        /* Preceded by drive: ? */
  1033.   {
  1034.     if (strlen (S) == 2)                                                                               /* Just a drive, no path ? */
  1035.       Bye (RETURNERROR, "ERROR - Missing path for DOOMDIR in configuration file\n");
  1036.     DriveNo = ToNumber (S[0]);
  1037.     if (DriveNo != CurDrive)                                                                                     /* A new drive ? */
  1038.       DoomDrive = DriveNo;                                                                                  /* Store drive number */
  1039.     else
  1040.       DoomDrive = 0;                                                                                /* Signal: no new drive given */
  1041.     strcpy (DoomDirectory, strupr (S + 2));                                                                         /* Store path */
  1042.   }
  1043.   else
  1044.   {
  1045.     DoomDrive = 0;                                                                                      /* Signal: no drive given */
  1046.     strcpy (DoomDirectory, strupr (S));
  1047.   }
  1048. }
  1049.  
  1050. void HandleOptAutoinc (char *Item)
  1051.  
  1052. /**********************************************************************************************************************************/
  1053. /* Pre   : 'Item' holds a filename that has been read following an 'AUTOINCLUDE' option.                                          */
  1054. /* Post  : The filename is include in the AutoInc list. If any error occurs, then no return is made.                              */
  1055. /* Import: TestName, Bye.                                                                                                         */
  1056. /**********************************************************************************************************************************/
  1057.  
  1058. {
  1059.   int     DriveNo;
  1060.   int     Index;
  1061.  
  1062.   if (TotalAutoInc == MAXAUTOINCLUDE)
  1063.     Bye (RETURNERROR, "ERROR - Too many AUTOINCLUDE entries\n");
  1064.   if ((AutoInc[TotalAutoInc] = ((struct WadInfo_s far *)_fmalloc ((size_t)sizeof (struct WadInfo_s)))) == NOMEM)
  1065.     Bye (RETURNERROR, "FATAL ERROR - Out of memory\n");
  1066.   strcpy (S, TestName (Item));
  1067.   if (S[1] == ':')                                                                                        /* Preceded by drive: ? */
  1068.   {
  1069.     if (strlen (S) == 2)                                                                               /* Just a drive, no path ? */
  1070.       Bye (RETURNERROR, "ERROR - Missing path for AUTOINCLUDE in configuration file\n");
  1071.     DriveNo = ToNumber (S[0]);
  1072.     if (DriveNo != CurDrive)                                                                                     /* A new drive ? */
  1073.       AutoInc[TotalAutoInc]->Drive = DriveNo;                                                               /* Store drive number */
  1074.     else
  1075.       AutoInc[TotalAutoInc]->Drive = 0;                                                             /* Signal: no new drive given */
  1076.     strcpy (AutoInc[TotalAutoInc]->Path, strupr (S + 2));                                                           /* Store path */
  1077.   }
  1078.   else
  1079.   {
  1080.     AutoInc[TotalAutoInc]->Drive = 0;                                                                   /* Signal: no drive given */
  1081.     strcpy (AutoInc[TotalAutoInc]->Path, strupr (S));
  1082.   }
  1083.   Index = strlen (AutoInc[TotalAutoInc]->Path) - 1;
  1084.   while (AutoInc[TotalAutoInc]->Path[Index] != '\\' && Index > 0)
  1085.     Index --;
  1086.   if (Index == 0)
  1087.   {
  1088.     strcpy (AutoInc[TotalAutoInc]->OrigName, AutoInc[TotalAutoInc]->Path);                                   /* No preceding path */
  1089.     strcpy (AutoInc[TotalAutoInc]->Path, DEFAULTWADDIR);
  1090.   }
  1091.   else
  1092.   {
  1093.     strcpy (AutoInc[TotalAutoInc]->OrigName, AutoInc[TotalAutoInc]->Path + Index + 1);          /* Copy over last part (filename) */
  1094.     AutoInc[TotalAutoInc]->Path[Index] = '\0';                                                          /* Cut filename from path */
  1095.   }
  1096.   TotalAutoInc ++;
  1097. }
  1098.  
  1099. void HandleOptAddSwitches (char *Item)
  1100.  
  1101. /**********************************************************************************************************************************/
  1102. /* Pre   : 'Item' holds the operand that has been read following an 'ADDSWITCHES' option.                                         */
  1103. /* Post  : If 'Item' holds a valid switch, then the 'InUse' flag of that switch is set. Otherwise no return is made.              */
  1104. /* Import: Bye.                                                                                                                   */
  1105. /**********************************************************************************************************************************/
  1106.  
  1107. {
  1108.   int Index;
  1109.  
  1110.   if (Item[0] == '-')                                                    /* Remember that all switches start with a '-' character */
  1111.   {
  1112.     Index = 0;
  1113.     while (Index < MAXADDSWITCHES && stricmp (Item, ExtCom[Index].Command))         /* Test the name against all allowed switches */
  1114.       Index ++;
  1115.     if (Index == MAXADDSWITCHES)
  1116.       Bye (RETURNERROR, "ERROR - Switch %s not supported in ADDSWITCHES\n", Item);
  1117.     ExtCom[Index].InUse = TRUE;
  1118.   }
  1119.   else
  1120.     Bye (RETURNERROR, "ERROR - Unrecognised ADDSWITCHES %s in configuration file\n", Item);
  1121. }
  1122.  
  1123. void ReadConfig (void)
  1124.  
  1125. /**********************************************************************************************************************************/
  1126. /* Pre   : The (global) 'ConfigFile' should be initialized.                                                                       */
  1127. /* Post  : If a configuration file is found, then it has been read out. Only 8 keywords are recognised:                           */
  1128. /*         - DOOMDIR, after which the name of the main DOOM directory should be given.                                            */
  1129. /*         - DOOMVERSION, after which the (float) DOOM version should be typed.                                                   */
  1130. /*         - WADDIR, after which a maximum of 400 WAD directories may be given; If an entry '/S' or '-S' is encountered, then all */
  1131. /*           subdirectories of the previously declared directory will also be used as WADDIRs.                                    */
  1132. /*         - WADINFOFILE, after which a WAD info file may be given. All simple errors are reported.                               */
  1133. /*         - SERDRIVER, after which a new serial driver should be given (in stead of SERSETUP);                                   */
  1134. /*         - IPXDRIVER, after which a new network driver should be given (in stead of IPXSETUP);                                  */
  1135. /*         - SETSKILL, after which the default skill (1-5) must be given.                                                         */
  1136. /*         - DEATHMATCH (no parameters). This means that deathmatch will be set as default.                                       */
  1137. /*         - AUTOINCLUDE, after which a maximum of 5 WAD files (complete with (partial) path) may be given. These files will then */
  1138. /*           automatically be selected when starting. If the file is not crossed when reading the directories (WADDIRs), then the */
  1139. /*           file is just not selected (no error will be generated).                                                              */
  1140. /*         - NOSEARCH (no parameters). If this keyword is given, then the program will not search all given WADDIR directories,   */
  1141. /*           it will use the WADINFOFILE instead and use all named entries instead. (This should be used with caution!)           */
  1142. /*         - SETCOMPORT, after which the default COM port (1-4) must be given for null-modem link.                                */
  1143. /*         - SETNODES, after which the default number of players (2-4) must be given for IPX link.                                */
  1144. /*         - SETSOCKET, after which a network socket (0-255) must be given.                                                       */
  1145. /*         - SETPLAYTYPE, after which one of the keywords "ALONE", "IPX" or "SERIAL" must be given.                               */
  1146. /*         - ADDSWITCHES, after which all the direct DOOM switches should be typed.                                               */
  1147. /*         - SORTFILES, after which one of the keywords "NAME" or "INFO" must be given.                                           */
  1148. /*         - NOFULLNAME (no parameters). Will stop using "music" i.s.o. "-         m".                                            */
  1149. /*         - NOAUTORETURN (no parameters). If this option is given, then no <CR> is passed to DOOM at startup.                    */
  1150. /*                                                                                                                                */
  1151. /*         If one (or all) are not found, then they are initialized with the defaults.                                            */
  1152. /*                                                                                                                                */
  1153. /*         If a character '#' is encountered, then the rest of this line is ignored (comment).                                    */
  1154. /*         Before returning, a test has been made if all selected switches are implemented in the given DOOM version.             */
  1155. /* Import: NextString, HandleOptWaddir, HandleOptAutoinc, HandleOptAddSwitches, HandleOptDoomdir, Bye.                            */
  1156. /**********************************************************************************************************************************/
  1157.  
  1158. {
  1159.   FILE    *Fp;
  1160.   char     Item[256];
  1161.   char     ContinueOption;
  1162.   boolean  Handled;
  1163.   
  1164.   TotalWadDirs = 0;                                                                                    /* Initialize all counters */
  1165.   TotalAutoInc = 0;
  1166.   strcpy (DoomDirectory, DEFAULTWADDIR);                                                  /* Use the current directory as default */
  1167.   strcpy (InfoFile, DEFAULTINFOFILE);                                                           /* Initialize a default file name */
  1168.   strcpy (IpxDriver, STARTIPX);
  1169.   strcpy (SerDriver, STARTLINK);
  1170.   if (Fp = fopen (ConfigFile, "r"))                                                            /* Skip if no CONFIGFILE was found */
  1171.   {
  1172.     NextString (Fp, Item);                                                          /* Read-ahead first string: must be a keyword */
  1173.     while (!feof (Fp))
  1174.     {
  1175.       Handled = FALSE;
  1176.       for (M = 0 ; !Handled && M < NUMOPTIONS ; M ++)
  1177.         if (!stricmp (Item, ConfOp[M].OptionName))
  1178.         {
  1179.           if (ConfOp[M].OptionType != OPT_SET)                                         /* Option takes one (or more) operand(s) ? */
  1180.           {
  1181.             NextString (Fp, Item);                                                                            /* Read the operand */
  1182.             if (feof (Fp))
  1183.               Bye (RETURNERROR, "ERROR - Missing operand after switch %s\n", ConfOp[M].OptionName);
  1184.           }
  1185.           ContinueOption = 0;                                                      /* Signal: no option has more than one operand */
  1186.           switch (ConfOp[M].OptionType)
  1187.           {
  1188.             case OPT_DOOMDIR : HandleOptDoomdir (Item);
  1189.                                break;
  1190.             case OPT_FILE    : strcpy (S, TestName (Item));
  1191.                                if (S[1] == ':' && S[2] == '\0')                                             /* Only a drive given */
  1192.                                  Bye (RETURNERROR, "ERROR - Missing pathname after %s in switch %s\n", S, ConfOp[M].OptionName);
  1193.                                strcpy ((char *)ConfOp[M].DataPtr, S);
  1194.                                break;
  1195.             case OPT_NUM     : for (N = 0 ; N < strlen (Item) ; N ++)
  1196.                                  if (strlen (Item) > 3 || !isdigit (Item[N]))
  1197.                                    Bye (RETURNERROR, "ERROR - Invalid number %s after switch %s\n", Item, ConfOp[M].OptionName);
  1198.                                *((int *)ConfOp[M].DataPtr) = atoi (Item);
  1199.                                break;
  1200.             case OPT_SET     : *((char *)ConfOp[M].DataPtr) = TRUE;
  1201.                                break;
  1202.             case OPT_STRING  : strcpy ((char *)ConfOp[M].DataPtr, Item);
  1203.                                break;
  1204.             case OPT_WADDIR  : ContinueOption = 1;
  1205.                                HandleOptWaddir (Item);
  1206.                                break;
  1207.             case OPT_AUTOINC : ContinueOption = 2;
  1208.                                HandleOptAutoinc (Item);
  1209.                                break;
  1210.             case OPT_ADDSWIT : ContinueOption = 3;
  1211.                                HandleOptAddSwitches (Item);
  1212.                                break;
  1213.             case OPT_PLAYTYP : if (!stricmp (Item, "ALONE"))
  1214.                                  PlayTypeActive = 1;
  1215.                                else
  1216.                                  if (!stricmp (Item, "IPX"))
  1217.                                    PlayTypeActive = 2;
  1218.                                  else
  1219.                                    if (!stricmp (Item, "SERIAL"))
  1220.                                      PlayTypeActive = 3;
  1221.                                    else
  1222.                                      Bye (RETURNERROR, "ERROR - Unknown playtype %s\n", Item);
  1223.                                break;
  1224.             case OPT_SORTFIL : SortWadFiles = TRUE;
  1225.                                if (!stricmp (Item, "NAME") || !stricmp (Item, "INFO"))
  1226.                                  SortByName = !stricmp (Item, "NAME");
  1227.                                else
  1228.                                  Bye (RETURNERROR, "ERROR - Unknown sort criteria %s after keyword SORTFILES\n", Item);
  1229.                                break;
  1230.             case OPT_VERSION : DoomVersion = 0;
  1231.                                if (Item[0] != '1' || Item[1] != '.')                         /* Version number must be one of 1.x */
  1232.                                  Bye (RETURNERROR, "ERROR - Invalid DOOM version number %s\n", Item);
  1233.                                for (N = 2 ; N < strlen (Item) && isdigit (Item[N]) ; N ++)
  1234.                                  DoomVersion = DoomVersion * 10 + Item[N] - '0';
  1235.                                if (Item[N] != '\0')
  1236.                                  Bye (RETURNERROR, "ERROR - Invalid DOOM version number %s\n", Item);
  1237.                                if (DoomVersion == 3 || (DoomVersion > 6 && DoomVersion != 666))   /* Non-existing version numbers */
  1238.                                  Bye (RETURNERROR, "ERROR - DOOM version number %s does not exist!\n", Item);
  1239.           }
  1240.           Handled = TRUE;
  1241.         }
  1242.       if (!Handled)                                                                       /* Read item is not one of the keywords */
  1243.         switch (ContinueOption)
  1244.         {
  1245.           case 0 : Bye (RETURNERROR, "ERROR - Unknown keyword %s in configuration file\n", Item);
  1246.           case 1 : HandleOptWaddir (Item);
  1247.                    break;
  1248.           case 2 : HandleOptAutoinc (Item);
  1249.                    break;
  1250.           case 3 : HandleOptAddSwitches (Item);
  1251.         }
  1252.       NextString (Fp, Item);                                                                                  /* Read next option */
  1253.     }
  1254.     fclose (Fp);
  1255.   }
  1256.   else
  1257.     if (ConfigChange)                                                             /* It is an error if a different file was given */
  1258.       Bye (RETURNERROR, "ERROR - configuration file not found\n");
  1259.   OtherSerDriver = strcmp (SerDriver, STARTLINK);
  1260.   OtherIpxDriver = strcmp (IpxDriver, STARTIPX);
  1261.   if (TotalWadDirs == 0)                                                               /* No CONFIGFILE or WADDIR entries found ? */
  1262.   {
  1263.     if ((WadDir[0] = ((struct WadDir_s far *)_fmalloc ((size_t)sizeof (struct WadDir_s)))) == NOMEM)
  1264.       Bye (RETURNERROR, "FATAL ERROR - Out of memory\n");
  1265.     WadDir[0]->Drive = 0;                                                               /* Then use the DOOM directory as default */
  1266.     strcpy (WadDir[0]->Name, DoomDirectory);
  1267.     TotalWadDirs = 1;
  1268.   }
  1269.   if (DifficultyActive == 0 || DifficultyActive > 5)                                     /* Filter out nonsense numerical options */
  1270.     Bye (RETURNERROR, "ERROR - Invalid skill number %d\n", DifficultyActive);
  1271.   if (CommPortActive == 0 || CommPortActive > 4)
  1272.     Bye (RETURNERROR, "ERROR - Invalid COM port number %d\n", CommPortActive);
  1273.   if (NumNodesActive < 2 || NumNodesActive > 4)
  1274.     Bye (RETURNERROR, "ERROR - You cannot play network DOOM with %d player(s)\n", NumNodesActive);
  1275.   if (DoomVersion < 2)
  1276.   {
  1277.     if (DeathmatchOn)
  1278.       Bye (RETURNERROR, "ERROR - Switch DEATHMATCH needs DOOM version 1.2\n");
  1279.     if (DifficultyActive == 5)
  1280.       Bye (RETURNERROR, "ERROR - Skill level 5 needs DOOM version 1.2\n");
  1281.     if (CommPortActive != DEFAULTCOMPORT)
  1282.       Bye (RETURNERROR, "ERROR - Switch SETCOMPORT needs DOOM version 1.2\n");
  1283.     if (PlayTypeActive == 3)
  1284.       Bye (RETURNERROR, "ERROR - Switch SETPLAYTYPE SERIAL needs DOOM version 1.2\n");
  1285.     if (strcmp (SerDriver, STARTLINK))
  1286.       Bye (RETURNERROR, "ERROR - Switch SERDRIVER needs DOOM version 1.2\n");
  1287.     if (PlayTypeActive == 2 && DoomVersion == 0)
  1288.       Bye (RETURNERROR, "ERROR - Switch SETPLAYTYPE IPX needs DOOM version 1.1\n");
  1289.     if (strcmp (IpxDriver, STARTIPX) && DoomVersion == 0)
  1290.       Bye (RETURNERROR, "ERROR - Switch IPXDRIVER needs DOOM version 1.1\n");
  1291.     if (NetworkSocket != DEFAULTSOCKET && DoomVersion == 0)
  1292.       Bye (RETURNERROR, "ERROR - Switch SETSOCKET needs DOOM version 1.1\n");
  1293.     if (NumNodesActive != DEFAULTNODES && DoomVersion == 0)
  1294.       Bye (RETURNERROR, "ERROR - Switch SETNODES needs DOOM version 1.1\n");
  1295.   }
  1296.   if (DoomVersion >= 5 && DeathmatchOn)
  1297.   {
  1298.     DeathmatchOn = FALSE;                                                    /* Select the better deathmatch version if available */
  1299.     DeathmatchV2On = TRUE;
  1300.   }
  1301. }
  1302.  
  1303. void PrintEpisodes (char HighLite)
  1304.  
  1305. /**********************************************************************************************************************************/
  1306. /* Pre   : 'HighLite' contains the pointed episode, or 0 if none was pointed to.                                                  */
  1307. /* Post  : The episodes have been printed. The active episode has a checked box, all others have empty boxes. The pointed episode */
  1308. /*         is printed in a different color.                                                                                       */
  1309. /* Import: PrText.                                                                                                                */
  1310. /**********************************************************************************************************************************/
  1311.  
  1312. {
  1313.   for (M = 0 ; M < NUMEPISODE ; M ++)
  1314.   {
  1315.     if (M == HighLite - 1)
  1316.       PrText ((M == EpisodeActive - 1), 3 + M, 1, LRED, Episodes[M]);
  1317.     else
  1318.       PrText ((M == EpisodeActive - 1), 3 + M, 1, LMAGENTA, Episodes[M]);
  1319.   }
  1320. }
  1321.  
  1322. void PrintDifficulties (char HighLite)
  1323.  
  1324. /**********************************************************************************************************************************/
  1325. /* Pre   : 'HighLite' contains the pointed difficulty, or 0 if none was pointed to.                                               */
  1326. /* Post  : The difficulties have been printed. The active difficulty has a checked box, all others have empty boxes. The pointed  */
  1327. /*         difficulty is printed in a different color.                                                                            */
  1328. /*         If (global) 'DoomVersion' is less than 1.2, then the difficulty 'Nightmare' (the last in the row) is not printed.      */
  1329. /* Import: PrText.                                                                                                                */
  1330. /**********************************************************************************************************************************/
  1331.  
  1332. {
  1333.   int MaxDiff;
  1334.  
  1335.   MaxDiff = (DoomVersion >= 2) ? NUMDIFFICULTY : NUMDIFFICULTY - 1;                         /* NIGHTMARE only available from v1.2 */
  1336.   for (M = 0 ; M < MaxDiff ; M ++)
  1337.   {
  1338.     if (M == HighLite - 1)
  1339.       PrText ((M == DifficultyActive - 1), 3 + M, 28, LRED, Difficulties[M]);
  1340.     else
  1341.       PrText ((M == DifficultyActive - 1), 3 + M, 28, LMAGENTA, Difficulties[M]);
  1342.   }
  1343.   if (DoomVersion < 2)
  1344.     PrText (0, 7, 28, LBLACK, Difficulties[4]);
  1345. }
  1346.  
  1347. void PrintPlayTypes (char HighLite)
  1348.  
  1349. /**********************************************************************************************************************************/
  1350. /* Pre   : 'HighLite' contains the pointed playtype, or 0 if none was pointed to.                                                 */
  1351. /* Post  : The playtypes have been printed. The active playtype has a checked box, all others have empty boxes. The pointed       */
  1352. /*         playtype is printed in a different color.                                                                              */
  1353. /* Import: PrText.                                                                                                                */
  1354. /**********************************************************************************************************************************/
  1355.  
  1356. {
  1357.   unsigned char PType[NUMPLAYTYPE] = {LMAGENTA, LMAGENTA, LMAGENTA};
  1358.  
  1359.   if (DoomVersion == 0)                                                                   /* Doom v1.0 could only be played alone */
  1360.     for (M = 0 ; M < NUMPLAYTYPE ; M ++)
  1361.       PType[M] = LBLACK;
  1362.   if (DoomVersion == 1)
  1363.     PType[NUMPLAYTYPE - 1] = LBLACK;
  1364.   for (M = 0 ; M < NUMPLAYTYPE ; M ++)                                                       /* v1.1 had IPX, v1.2 also had modem */
  1365.   {
  1366.     if (M == HighLite - 1)
  1367.       PrText ((M == PlayTypeActive - 1), 3 + M, 55, LRED, PlayTypes[M]);
  1368.     else
  1369.       PrText ((M == PlayTypeActive - 1), 3 + M, 55, PType[M], PlayTypes[M]);
  1370.   }
  1371.   switch (PlayTypeActive)
  1372.   {
  1373.     case 1: PrText (-1, 6, 55, DBLACK, "                     ");                                                         /* Alone */
  1374.             break;
  1375.     case 2: if (!OtherIpxDriver)                                                                                /* IPX compatible */
  1376.               if (HighLite == 4)
  1377.                 PrText (-1, 6, 55, LRED, "(%c) %s", NumNodesActive + '0', NumberNodes);
  1378.               else
  1379.                 PrText (-1, 6, 55, LMAGENTA, "(%c) %s", NumNodesActive + '0', NumberNodes);
  1380.             else
  1381.               PrText (-1, 6, 55, LBLACK, "(%c) %s", NumNodesActive + '0', NumberNodes);
  1382.             break;
  1383.     case 3: if (!OtherSerDriver)                                                                               /* Null-modem link */
  1384.               if (HighLite == 4)
  1385.                 PrText (-1, 6, 55, LRED, "(%c) %s", CommPortActive + '0', CommPort);
  1386.               else
  1387.                 PrText (-1, 6, 55, LMAGENTA, "(%c) %s", CommPortActive + '0', CommPort);
  1388.             else
  1389.               PrText (-1, 6, 55, LBLACK, "(%c) %s", CommPortActive + '0', CommPort);
  1390.   }
  1391. }
  1392.  
  1393. void PrintRespawnMonsters (boolean HighLite)
  1394.  
  1395. /**********************************************************************************************************************************/
  1396. /* Pre   : 'HighLite' is TRUE if this item was pointed to.                                                                        */
  1397. /* Post  : The RESPAWN text has been printed, with a checked box before it if it was selected, or empty otherwise.                */
  1398. /*         If 'HighLite' was TRUE, then the text is printed in a different color.                                                 */
  1399. /*         If (global) 'DoomVersion' is less than 1.2, then nothing has been done here.                                           */
  1400. /* Import: PrText.                                                                                                                */
  1401. /**********************************************************************************************************************************/
  1402.  
  1403. {
  1404.   if (DoomVersion >= 2)                                                                       /* Respawn only available from v1.2 */
  1405.     if (HighLite)
  1406.       PrText (RespMonstersOn, 10, 28, LRED, RespawnMonsters);
  1407.     else
  1408.       PrText (RespMonstersOn, 10, 28, LMAGENTA, RespawnMonsters);
  1409.   else
  1410.     PrText (RespMonstersOn, 10, 28, LBLACK, RespawnMonsters);
  1411. }
  1412.  
  1413. void PrintNoMonsters (boolean HighLite)
  1414.  
  1415. /**********************************************************************************************************************************/
  1416. /* Pre   : 'HighLite' is TRUE if this item was pointed to.                                                                        */
  1417. /* Post  : The NOMONSTERS text has been printed, with a checked box before it if it was selected, or empty otherwise.             */
  1418. /*         If 'HighLite' was TRUE, then the text is printed in a different color.                                                 */
  1419. /*         If (global) 'DoomVersion' is less than 1.2, then nothing has been done here.                                           */
  1420. /* Import: PrText.                                                                                                                */
  1421. /**********************************************************************************************************************************/
  1422.  
  1423. {
  1424.   if (DoomVersion >= 2)                                                                    /* NoMonsters only available from v1.2 */
  1425.     if (HighLite)
  1426.       PrText (NoMonstersOn, 9, 28, LRED, NoMonsters);
  1427.     else
  1428.       PrText (NoMonstersOn, 9, 28, LMAGENTA, NoMonsters);
  1429.   else
  1430.     PrText (NoMonstersOn, 9, 28, LBLACK, NoMonsters);
  1431. }
  1432.  
  1433. void PrintFastMonsters (boolean HighLite)
  1434.  
  1435. /**********************************************************************************************************************************/
  1436. /* Pre   : 'HighLite' is TRUE if this item was pointed to.                                                                        */
  1437. /* Post  : The FASTMONSTERS text has been printed, with a checked box before it if it was selected, or empty otherwise.           */
  1438. /*         If 'HighLite' was TRUE, then the text is printed in a different color.                                                 */
  1439. /*         If (global) 'DoomVersion' is less than 1.5, then nothing has been done here.                                           */
  1440. /* Import: PrText.                                                                                                                */
  1441. /**********************************************************************************************************************************/
  1442.  
  1443. {
  1444.   if (DoomVersion >= 5)                                                                  /* FastMonsters only available from v1.5 */
  1445.     if (HighLite)
  1446.       PrText (FastMonstersOn, 11, 28, LRED, FastMonsters);
  1447.     else
  1448.       PrText (FastMonstersOn, 11, 28, LMAGENTA, FastMonsters);
  1449.   else
  1450.     PrText (FastMonstersOn, 11, 28, LBLACK, FastMonsters);
  1451. }
  1452.  
  1453. void PrintDeathmatch (boolean HighLite)
  1454.  
  1455. /**********************************************************************************************************************************/
  1456. /* Pre   : 'HighLite' is TRUE if this item was pointed to.                                                                        */
  1457. /* Post  : The DEATHMATCH text has been printed, with a checked box before it if it was selected, or empty otherwise.             */
  1458. /*         If 'HighLite' was TRUE, then the text is printed in a different color.                                                 */
  1459. /*         If (global) 'DoomVersion' is less than 1.2, then nothing has been done here.                                           */
  1460. /* Import: PrText.                                                                                                                */
  1461. /**********************************************************************************************************************************/
  1462.  
  1463. {
  1464.   if (DoomVersion >= 2)                                                                    /* Deathmatch only available from v1.2 */
  1465.     if (HighLite)
  1466.       PrText (DeathmatchOn, 8, 55, LRED, Deathmatch);
  1467.     else
  1468.       PrText (DeathmatchOn, 8, 55, LMAGENTA, Deathmatch);
  1469.   else
  1470.     PrText (DeathmatchOn, 8, 55, LBLACK, Deathmatch);
  1471. }
  1472.  
  1473. void PrintV2Deathmatch (boolean HighLite)
  1474.  
  1475. /**********************************************************************************************************************************/
  1476. /* Pre   : 'HighLite' is TRUE if this item was pointed to.                                                                        */
  1477. /* Post  : The DEATHMATCH V2 text has been printed, with a checked box before it if it was selected, or empty otherwise.          */
  1478. /*         If 'HighLite' was TRUE, then the text is printed in a different color.                                                 */
  1479. /*         If (global) 'DoomVersion' is less than 1.5, then nothing has been done here.                                           */
  1480. /* Import: PrText.                                                                                                                */
  1481. /**********************************************************************************************************************************/
  1482.  
  1483. {
  1484.   if (DoomVersion >= 5)                                                                    /* Deathmatch only available from v1.2 */
  1485.     if (HighLite)
  1486.       PrText (DeathmatchV2On, 9, 55, LRED, DeathmatchV2);
  1487.     else
  1488.       PrText (DeathmatchV2On, 9, 55, LMAGENTA, DeathmatchV2);
  1489.   else
  1490.     PrText (DeathmatchV2On, 9, 55, LBLACK, DeathmatchV2);
  1491. }
  1492.  
  1493. void PrintLevel (boolean HighLite)
  1494.  
  1495. /**********************************************************************************************************************************/
  1496. /* Pre   : 'HighLite' is TRUE if this item was pointed to.                                                                        */
  1497. /* Post  : The LEVEL text has been printed, with a box before it, containing the current level.                                   */
  1498. /*         If 'HighLite' was TRUE, then the text is printed in a different color.                                                 */
  1499. /* Import: PrText.                                                                                                                */
  1500. /**********************************************************************************************************************************/
  1501.  
  1502. {
  1503.   if (HighLite)
  1504.     PrText (-1, 7, 1, LRED, "(%c) %s", CurrentLevel + '0', Level);
  1505.   else
  1506.     PrText (-1, 7, 1, LMAGENTA, "(%c) %s", CurrentLevel + '0', Level);
  1507. }
  1508.  
  1509. void PrintWadFiles (void)
  1510.  
  1511. /**********************************************************************************************************************************/
  1512. /* Pre   : None.                                                                                                                  */
  1513. /* Post  : The active page with WAD files has been printed (as determined by 'CurrentPage') has been printed. All selected WAD    */
  1514. /*         files are printed in a different color, any unused part of the page has been cleared from the screen. After each name  */
  1515. /*         is the read info printed. Highliting of a pointed wadfile is not handled here.                                         */
  1516. /* Import: PrText.                                                                                                                */
  1517. /**********************************************************************************************************************************/
  1518.  
  1519. {
  1520.   int PositionX;
  1521.   int PositionY;
  1522.  
  1523.   for (M = CurrentPage * PAGE ; M < (CurrentPage + 1) * PAGE ; M += WADHEIGHT)                              /* Handle each column */
  1524.     for (N = M ; N < M + WADHEIGHT ; N ++)                                                       /* Handle each row in the column */
  1525.     {
  1526.       PositionY = 13 + (N % WADHEIGHT);
  1527.       PositionX = ((M - CurrentPage * PAGE) / WADHEIGHT) * WADWIDTH + 1;
  1528.       if (N < TotalWads)                                                                              /* WAD file number exists ? */
  1529.       {
  1530.         if (WadInfo[N]->Selected)
  1531.           PrText (-1, PositionY, PositionX, DGREEN, WadInfo[N]->Name);                                          /* Print filename */
  1532.         else
  1533.           PrText (-1, PositionY, PositionX, DWHITE, WadInfo[N]->Name);
  1534.         PrText (-1, PositionY, PositionX + _MAX_FNAME, DCYAN, WadInfo[N]->Info);                                    /* Print info */
  1535.       }
  1536.       else                                                                             /* WAD file number after the last WAD file */
  1537.         PrText (-1, PositionY, PositionX, DBLACK, "                         ");                         /* Clear this screen part */
  1538.     }
  1539. }
  1540.  
  1541. void PrintPagers (char HighLite)
  1542.  
  1543. /**********************************************************************************************************************************/
  1544. /* Pre   : 'HighLite' is 1 for left, 2 for right or 0 for no pager.                                                               */
  1545. /* Post  : The pagers have been printed. The 'HighLite' pager in a different color.                                               */
  1546. /* Import: PrText.                                                                                                                */
  1547. /**********************************************************************************************************************************/
  1548.  
  1549. {
  1550.   if (CurrentPage > 0)                                                                              /* Are there previous pages ? */
  1551.     if (HighLite == 1)                                                                  /* Print pager for 'previous' page (left) */
  1552.       PrText (-1, 11, 60, LRED, PreviousPage);
  1553.     else
  1554.       PrText (-1, 11, 60, LWHITE, PreviousPage);
  1555.   else
  1556.     PrText (-1, 11, 60, LBLACK, PreviousPage);
  1557.   if (CurrentPage < LastPage)                                                                           /* Are there next pages ? */
  1558.     if (HighLite == 2)                                                                     /* Print pager for 'next' page (right) */
  1559.       PrText (-1, 11, 78, LRED, NextPage);
  1560.     else
  1561.       PrText (-1, 11, 78, LWHITE, NextPage);
  1562.   else
  1563.     PrText (-1, 11, 78, LBLACK, NextPage);
  1564. }
  1565.  
  1566. void PrintRdPrev (boolean HighLite)
  1567.  
  1568. /**********************************************************************************************************************************/
  1569. /* Pre   : 'HighLite' is TRUE if this item is selected.                                                                           */
  1570. /* Post  : The read previous text has been printed. If 'HighLite' was TRUE, than in a different color.                            */
  1571. /* Import: PrText.                                                                                                                */
  1572. /**********************************************************************************************************************************/
  1573.  
  1574. {
  1575.   if (HighLite)
  1576.     PrText (-1, 11, 1, LRED, ReadPrevious);
  1577.   else
  1578.     PrText (-1, 11, 1, LMAGENTA, ReadPrevious);
  1579. }
  1580.  
  1581. void PrintAutomatic (boolean HighLite)
  1582.  
  1583. /**********************************************************************************************************************************/
  1584. /* Pre   : 'HighLite' is TRUE if this item is selected.                                                                           */
  1585. /* Post  : The automatic text has been printed. If 'HighLite' was TRUE, than in a different color.                                */
  1586. /* Import: PrText.                                                                                                                */
  1587. /**********************************************************************************************************************************/
  1588.  
  1589. {
  1590.   if (HighLite)
  1591.     PrText (-1, 10, 1, LRED, Automatic);
  1592.   else
  1593.     PrText (-1, 10, 1, LMAGENTA, Automatic);
  1594. }
  1595.  
  1596. void PrintStart (boolean HighLite)
  1597.  
  1598. /**********************************************************************************************************************************/
  1599. /* Pre   : 'HighLite' is TRUE if this item is selected.                                                                           */
  1600. /* Post  : The start text has been printed. If 'HighLite' was TRUE, than in a different color.                                    */
  1601. /* Import: PrText.                                                                                                                */
  1602. /**********************************************************************************************************************************/
  1603.  
  1604. {
  1605.   if (HighLite)
  1606.     PrText (-1, 9, 1, LRED, StartGame);
  1607.   else
  1608.     PrText (-1, 9, 1, LMAGENTA, StartGame);
  1609. }
  1610.  
  1611. void UnselectPreviousField (char SkipFieldNum)
  1612.  
  1613. /**********************************************************************************************************************************/
  1614. /* Pre   : 'SkipFieldNum' holds the field number that should NOT be unselected.                                                   */
  1615. /* Post  : The previous selected field has been unselected, if one was pointed to and it was not 'SkipFieldNum'.                  */
  1616. /* Import: PrintEpisodes, PrintDifficulties, PrintPlayTypes, PrintLevel, PrintDeathmatch, PrintPagers, PrintRdPrev, PrintStart,   */
  1617. /*         PrintAutomatic, PrintDeathmatchV2, PrintRespawnMonsters, PrintNoMonsters, PrintFastMonsters, PrText, HideMouse,        */
  1618. /*         ShowMouse.                                                                                                             */
  1619. /**********************************************************************************************************************************/
  1620.  
  1621. {
  1622.   int PositionX;
  1623.   int PositionY;
  1624.   int OldWadNumber;
  1625.  
  1626.   if (CurrentField != NOFIELD && CurrentField != SkipFieldNum)
  1627.   {
  1628.     switch (CurrentField)
  1629.     {
  1630.       case EPISODEFIELD      : PrintEpisodes (0);
  1631.                                break;
  1632.       case DIFFICULTYFIELD   : PrintDifficulties (0);
  1633.                                break;
  1634.       case PLAYTYPEFIELD     : PrintPlayTypes (0);
  1635.                                break;
  1636.       case LEVELFIELD        : PrintLevel (FALSE);
  1637.                                break;
  1638.       case DEATHMATCHFIELD   : PrintDeathmatch (FALSE);
  1639.                                break;
  1640.       case DEATHMATCHV2FIELD : PrintV2Deathmatch (FALSE);
  1641.                                break;
  1642.       case RESPAWNFIELD      : PrintRespawnMonsters (FALSE);
  1643.                                break;
  1644.       case NOMONSTERSFIELD   : PrintNoMonsters (FALSE);
  1645.                                break;
  1646.       case FASTMONSTERSFIELD : PrintFastMonsters (FALSE);
  1647.                                break;
  1648.       case PAGERFIELD        : PrintPagers (0);
  1649.                                break;
  1650.       case RDPREVFIELD       : PrintRdPrev (FALSE);
  1651.                                break;
  1652.       case STARTFIELD        : PrintStart (FALSE);
  1653.                                break;
  1654.       case AUTOMATICFIELD    : PrintAutomatic (FALSE);
  1655.                                break;
  1656.       case FILEFIELD         : PositionY = 13 + ((PreviousWad - 1) % WADHEIGHT);           /* Location of previously selected WAD */
  1657.                                PositionX = ((PreviousWad - 1) / WADHEIGHT) * WADWIDTH + 1;
  1658.                                OldWadNumber = CurrentPage * PAGE + PreviousWad - 1;                         /* Number of that WAD */
  1659.                                HideMouse ();
  1660.                                if (WadInfo[OldWadNumber]->Selected)
  1661.                                  PrText (-1, PositionY, PositionX, DGREEN, WadInfo[OldWadNumber]->Name);
  1662.                                else
  1663.                                  PrText (-1, PositionY, PositionX, DWHITE, WadInfo[OldWadNumber]->Name);
  1664.                                ShowMouse ();
  1665.     }
  1666.   }
  1667. }
  1668.  
  1669. boolean WaitForConfirmation (void)
  1670.  
  1671. /**********************************************************************************************************************************/
  1672. /* Pre   : None.                                                                                                                  */
  1673. /* Post  : The user must press a key. If this key is 'Y', then TRUE is returned, otherwise FALSE.                                 */
  1674. /* Import: None.                                                                                                                  */
  1675. /**********************************************************************************************************************************/
  1676.  
  1677. {
  1678.   unsigned int Key;
  1679.  
  1680.   while (!_bios_keybrd (_KEYBRD_READY))                                                                         /* Wait for a key */
  1681.     ;
  1682.   Key = _bios_keybrd (_KEYBRD_READ) & 0x00FF;                                                                 /* Read pressed key */
  1683.   return (toupper ((char)Key) == 'Y');                                                                /* Return TRUE if it is 'Y' */
  1684. }
  1685.  
  1686. boolean Requester (short Y0, short X0, short DY, short DX)
  1687.  
  1688. /**********************************************************************************************************************************/
  1689. /* Pre   : 'Y0' and 'X0' hold the top-left coordinates of the requester that is to be printed. The hight will be 'DY' lines, the  */
  1690. /*         width will be 'DX' columns.                                                                                            */
  1691. /* Post  : The requester has been drawn.                                                                                          */
  1692. /*         Note that the requester is surrounded with an empty zone.                                                              */
  1693. /* Import: HideMouse, UnselectPreviousField, PrText.                                                                              */
  1694. /**********************************************************************************************************************************/
  1695.  
  1696. {
  1697.   HideMouse ();                                                                           /* Clear mousepointer and hi-light bars */
  1698.   UnselectPreviousField (NOFIELD);
  1699.   CurrentField = NOFIELD;
  1700.   Mouse.CoChange = TRUE;                                                                         /* Signal: re-hi-light on return */
  1701.   for (M = 0 ; M < DX ; M ++)
  1702.     PrText (-1, Y0, X0 + M, DBLACK, " ");
  1703.   PrText (-1, Y0 + 1, X0, LRED, " \xC9");
  1704.   for (M = 0 ; M < (DX - 4) ; M ++)
  1705.     PrText (-1, 0, 0, LRED, "\xCD");
  1706.   PrText (-1, 0, 0, LRED, "\xBB ");
  1707.   for (M = 2 ; M < (DY - 2) ; M ++)
  1708.   {
  1709.     PrText (-1, Y0 + M, X0, LRED, " \xBA");
  1710.     for (N = 0 ; N < (DX - 4) ; N ++)
  1711.       PrText (-1, 0, 0, DBLACK, " ");
  1712.     PrText (-1, 0, 0, LRED, "\xBA ");
  1713.   }
  1714.   PrText (-1, Y0 + DY - 2, X0, LRED, " \xC8");
  1715.   for (M = 0 ; M < (DX - 4) ; M ++)
  1716.     PrText (-1, 0, 0, LRED, "\xCD");
  1717.   PrText (-1, 0, 0, LRED, "\xBC ");
  1718.   for (M = 0 ; M < DX ; M ++)
  1719.     PrText (-1, Y0 + DY - 1, X0 + M, DBLACK, " ");
  1720. }
  1721.  
  1722. void GiveHelp (void)
  1723.  
  1724. /**********************************************************************************************************************************/
  1725. /* Pre   : The user pressed [F1].                                                                                                 */
  1726. /* Post  : A requester has been drawn, containing a listing of all available keys (depending on DOOM version number and whether a */
  1727. /*         mouse has been found). The user must press a key to return.                                                            */
  1728. /* Import: Requester, PrText, WaitForConfirmation, PrintWadFiles, ShowMouse.                                                      */
  1729. /**********************************************************************************************************************************/
  1730.  
  1731. {
  1732.   Requester (14, 2, 16, 78);
  1733.   PrText (-1, 17, 24, DCYAN, "The following keys are available:");
  1734.   PrText (-1, 19, 5, DWHITE, "%c  ", KEY_EPISODE);
  1735.   PrText (-1, 0, 0, DCYAN, "Episode");
  1736.   PrText (-1, 20, 5, DWHITE, "%c  ", KEY_LEVEL);
  1737.   PrText (-1, 0, 0, DCYAN, "Level");
  1738.   PrText (-1, 21, 5, DWHITE, "%c  ", KEY_DIFFICULTY);
  1739.   PrText (-1, 0, 0, DCYAN, "Skill");
  1740.   if (DoomVersion >= 1)
  1741.   {
  1742.     PrText (-1, 22, 5, DWHITE, "%c  ", KEY_PLAYTYPE);
  1743.     PrText (-1, 0, 0, DCYAN, "Playtype");
  1744.     if (!OtherIpxDriver)
  1745.     {
  1746.       PrText (-1, 25, 5, DWHITE, "%c  ", KEY_NODES);
  1747.       PrText (-1, 0, 0, DCYAN, "Number of players");
  1748.     }
  1749.   }
  1750.   if (DoomVersion >= 2)
  1751.   {
  1752.     PrText (-1, 23, 5, DWHITE, "%c  ", KEY_DEATHMATCH);
  1753.     PrText (-1, 0, 0, DCYAN, "Deathmatch");
  1754.     if (!OtherSerDriver)
  1755.     {
  1756.       PrText (-1, 26, 5, DWHITE, "%c  ", KEY_COMPORT);
  1757.       PrText (-1, 0, 0, DCYAN, "COM port");
  1758.     }
  1759.     PrText (-1, 19, 28, DWHITE, "%c       ", KEY_NOMONSTERS);
  1760.     PrText (-1, 0, 0, DCYAN, "No monsters");
  1761.     PrText (-1, 20, 28, DWHITE, "%c       ", KEY_RESPAWNMONST);
  1762.     PrText (-1, 0, 0, DCYAN, "Respawn monsters");
  1763.   }
  1764.   if (DoomVersion >= 5)
  1765.   {
  1766.     PrText (-1, 24, 5, DWHITE, "%c  ", KEY_DEATHMATCHV2);
  1767.     PrText (-1, 0, 0, DCYAN, "Deathmatch v2.0");
  1768.     PrText (-1, 21, 28, DWHITE, "%c       ", KEY_FASTMONSTERS);
  1769.     PrText (-1, 0, 0, DCYAN, "Fast monsters");
  1770.   }
  1771.   PrText (-1, 22, 28, DWHITE, "%c       ", KEY_AUTO);
  1772.   PrText (-1, 0, 0, DCYAN, "AUTO SELECT");
  1773.   PrText (-1, 23, 28, DWHITE, "%c       ", KEY_READPREVIOUS);
  1774.   PrText (-1, 0, 0, DCYAN, "READ PREVIOUS");
  1775.   PrText (-1, 24, 28, DWHITE, "[ENTER] ");
  1776.   PrText (-1, 0, 0, DCYAN, "START DOOM!");
  1777.   PrText (-1, 25, 28, DWHITE, "[ESC]   ");
  1778.   PrText (-1, 0, 0, DCYAN, "Abort EasyWAD");
  1779.   PrText (-1, 26, 28, DWHITE, "[DEL]   ");
  1780.   PrText (-1, 0, 0, DCYAN, "Delete WAD");
  1781.   PrText (-1, 19, 55, DWHITE, "[PG UP] ");
  1782.   PrText (-1, 0, 0, DCYAN, "Next WAD page");
  1783.   PrText (-1, 20, 55, DWHITE, "[PG DN] ");
  1784.   PrText (-1, 0, 0, DCYAN, "Previous page");
  1785.   PrText (-1, 21, 55, DWHITE, "[F1]    ");
  1786.   PrText (-1, 0, 0, DCYAN, "This help page");
  1787.   PrText (-1, 22, 55, DWHITE, "[F5]    ");
  1788.   PrText (-1, 0, 0, DCYAN, "Rescan WADDIRs");
  1789.   PrText (-1, 23, 55, DWHITE, "[F7]    ");
  1790.   PrText (-1, 0, 0, DCYAN, "Reset fullname");
  1791.   PrText (-1, 24, 55, DWHITE, "[F8]    ");
  1792.   PrText (-1, 0, 0, DCYAN, "Resort WADs");
  1793.   if (!UseMouse)
  1794.   {
  1795.     PrText (-1, 25, 55, DWHITE, "[CURS]  ");
  1796.     PrText (-1, 0, 0, DCYAN, "Move around");
  1797.     PrText (-1, 26, 55, DWHITE, "[SPACE] ");
  1798.     PrText (-1, 0, 0, DCYAN, "Select WAD");
  1799.   }
  1800.   WaitForConfirmation ();
  1801.   for (M = 15 ; M < 29 ; M ++)                                                                                 /* Erase requester */
  1802.     PrText (-1, M, 3, DBLACK, "                                                                            ");
  1803.   PrintWadFiles ();
  1804.   ShowMouse ();
  1805. }
  1806.  
  1807. void SortFiles (void)
  1808.  
  1809. /**********************************************************************************************************************************/
  1810. /* Pre   : None.                                                                                                                  */
  1811. /* Post  : If (global) 'SortWadFiles' is TRUE, then the WAD files in memory have been sorted according to the sorttype.           */
  1812. /*         If (global) 'SortByName' is TRUE, then they have been sorted by name, otherwise they have been sorted by info field.   */
  1813. /* Import: None.                                                                                                                  */
  1814. /**********************************************************************************************************************************/
  1815.  
  1816. {
  1817.   boolean  More;
  1818.   struct   WadInfo_s far *TmpPtr;                                                           /* Entry as read from the WADINFOFILE */
  1819.  
  1820.   if (SortWadFiles)                                                                            /* SORTFILES given in CONFIGFILE ? */
  1821.   {
  1822.     More = TRUE;
  1823.     for (N = 0 ; N < TotalWads - 1 && More ; N ++)                                                        /* Perform a bubblesort */
  1824.     {
  1825.       More = FALSE;
  1826.       for (M = 0 ; M < TotalWads - 1 ; M ++)
  1827.         if (SortByName)                                                                                   /* Sort by 'Name' field */
  1828.         {
  1829.           if (strcmp (WadInfo[M]->Name, WadInfo[M + 1]->Name) > 0)                                /* Next 'larger' than current ? */
  1830.           {
  1831.             More = TRUE;
  1832.             TmpPtr = WadInfo[M];                                                                        /* Then flip the pointers */
  1833.             WadInfo[M] = WadInfo[M + 1];
  1834.             WadInfo[M + 1] = TmpPtr;
  1835.           }
  1836.         }
  1837.         else                                                                                              /* Sort by 'Info' field */
  1838.         {
  1839.           if (strcmp (WadInfo[M]->Info, WadInfo[M + 1]->Info) > 0)
  1840.           {
  1841.             More = TRUE;
  1842.             TmpPtr = WadInfo[M];
  1843.             WadInfo[M] = WadInfo[M + 1];
  1844.             WadInfo[M + 1] = TmpPtr;
  1845.           }
  1846.         }
  1847.     }
  1848.   }
  1849. }
  1850.  
  1851. void ConvertFullName (struct WadInfo_s far *ConInfo)
  1852.  
  1853. /**********************************************************************************************************************************/
  1854. /* Pre   : 'ConInfo' points to the WadInfo structure that should have its Info field re-examined.                                 */
  1855. /* Post  : If the Info field contained a full name (e.g. 'music'), then it is converted to the short name (e.g. '-         m').   */
  1856. /*         Before returning, the Info field is expanded to contain exactly MAXINFOLEN characters.                                 */
  1857. /* Import: None.                                                                                                                  */
  1858. /**********************************************************************************************************************************/
  1859.  
  1860. {
  1861.   int Index;
  1862.   int SLNoLevel;                                                                                                /* StrLen NoLevel */
  1863.  
  1864.   for (Index = strlen (ConInfo->Info) - 1 ; ConInfo->Info[Index] == ' ' && Index > 0 ; Index --)           /* Cut trailing spaces */
  1865.     ConInfo->Info[Index] = '\0';
  1866.   if (NoFullName)                                                                   /* Convert full names to short name if wanted */
  1867.   {
  1868.     if (!strcmp (ConInfo->Info, IdColors[MAXCOLORS + 1]))
  1869.       sprintf (ConInfo->Info, "%s%s", NoLevel, IdColors[MAXCOLORS]);
  1870.     else
  1871.       if (!strcmp (ConInfo->Info, IdDemos[MAXDEMOS + 1]))
  1872.         sprintf (ConInfo->Info, "%s%s", NoLevel, IdDemos[MAXDEMOS]);
  1873.       else
  1874.         if (!strcmp (ConInfo->Info, IdSounds[MAXSOUNDS + 1]))
  1875.           sprintf (ConInfo->Info, "%s%s", NoLevel, IdSounds[MAXSOUNDS]);
  1876.         else
  1877.           if (!strcmp (ConInfo->Info, IdMusic[MAXMUSIC + 1]))
  1878.             sprintf (ConInfo->Info, "%s%s", NoLevel, IdMusic[MAXMUSIC]);
  1879.           else
  1880.             if (!strcmp (ConInfo->Info, IdSprites[MAXSPRITES + 1]))
  1881.               sprintf (ConInfo->Info, "%s%s", NoLevel, IdSprites[MAXSPRITES]);
  1882.             else
  1883.               if (!strcmp (ConInfo->Info, IdGraphics[MAXGRAPHS + 1]))
  1884.                 sprintf (ConInfo->Info, "%s%s", NoLevel, IdGraphics[MAXGRAPHS]);
  1885.   }
  1886.   else
  1887.   {
  1888.     SLNoLevel = strlen (NoLevel);                                                         /* Just to speed things up a little ... */
  1889.     if (!strncmp (ConInfo->Info, NoLevel, SLNoLevel))
  1890.     {
  1891.       if (!strcmp (ConInfo->Info + SLNoLevel, IdColors[MAXCOLORS]))
  1892.         strcpy (ConInfo->Info, IdColors[MAXCOLORS + 1]);
  1893.       else
  1894.         if (!strcmp (ConInfo->Info + SLNoLevel, IdDemos[MAXDEMOS]))
  1895.           strcpy (ConInfo->Info, IdDemos[MAXDEMOS + 1]);
  1896.         else
  1897.           if (!strcmp (ConInfo->Info + SLNoLevel, IdSounds[MAXSOUNDS]))
  1898.             strcpy (ConInfo->Info, IdSounds[MAXSOUNDS + 1]);
  1899.           else
  1900.             if (!strcmp (ConInfo->Info + SLNoLevel, IdMusic[MAXMUSIC]))
  1901.               strcpy (ConInfo->Info, IdMusic[MAXMUSIC + 1]);
  1902.             else
  1903.               if (!strcmp (ConInfo->Info + SLNoLevel, IdSprites[MAXSPRITES]))
  1904.                 strcpy (ConInfo->Info, IdSprites[MAXSPRITES + 1]);
  1905.               else
  1906.                 if (!strcmp (ConInfo->Info + SLNoLevel, IdGraphics[MAXGRAPHS]))
  1907.                   strcpy (ConInfo->Info, IdGraphics[MAXGRAPHS + 1]);
  1908.       }
  1909.     }
  1910.   for (Index = strlen (ConInfo->Info) ; Index < MAXINFOLEN ; Index ++)                              /* Fill info field to maximum */
  1911.     ConInfo->Info[Index] = ' ';
  1912.   ConInfo->Info[Index] = '\0';
  1913. }
  1914.  
  1915. void HandleFileSort (boolean Toggle)
  1916.  
  1917. /**********************************************************************************************************************************/
  1918. /* Pre   : 'Toggle' is TRUE if the sort criterium should be toggled (when called from ToggleFileSort), FALSE if not (when called  */
  1919. /*         from RescanFiles). A requester border should have been previously drawn, together with the top text line.              */
  1920. /* Post  : The question is finished in the requester. The user must confirm the question. If confirmed, then the files are sorted */
  1921. /*         according to 'Toggle'. If this was TRUE, then the criterium is toggled from "NAME" to "INFO" first. Afterward the      */
  1922. /*         requester has been removed and the files reprinted (if the sort was done, then page 1 is automatically selected).      */
  1923. /* Import: WaitForConfirmation, PrintWadFiles, ShowMouse, SortFiles, PrText, PrintPagers.                                         */
  1924. /**********************************************************************************************************************************/
  1925.  
  1926. {
  1927.   PrText (-1, 20, 32, LRED, "RESORT THE FILES ?");
  1928.   PrText (-1, 22, 31, DRED, "PRESS <Y> TO CONFIRM");
  1929.   if (!WaitForConfirmation ())                                                                                  /* Acknowledged ? */
  1930.   {                                                                                                            /* Step out if not */
  1931.     for (M = 16 ; M < 25 ; M ++)                                                                               /* Erase requester */
  1932.       PrText (-1, M, 26, DBLACK, "                                ");
  1933.     PrintWadFiles ();
  1934.     ShowMouse ();
  1935.     return;
  1936.   }
  1937.   if (Toggle)
  1938.   {
  1939.     SortWadFiles = TRUE;
  1940.     SortByName = !SortByName;                                                                 /* Toggle between "NAME" and "INFO" */
  1941.   }
  1942.   PrText (-1, 18, 29, DRED, "                        ");
  1943.   PrText (-1, 20, 32, LRED, "    Sorting ...   ");
  1944.   PrText (-1, 22, 31, DRED, "                    ");
  1945.   SortFiles ();
  1946.   for (M = 16 ; M < 25 ; M ++)                                                                                 /* Erase requester */
  1947.     PrText (-1, M, 26, DBLACK, "                                ");
  1948.   CurrentPage = 0;
  1949.   CurrentSelected = 0;
  1950.   PrintPagers (0);
  1951.   PrintWadFiles ();
  1952.   ShowMouse ();
  1953. }
  1954.  
  1955. void ToggleFileSort (void)
  1956.  
  1957. /**********************************************************************************************************************************/
  1958. /* Pre   : The user pressed [F8].                                                                                                 */
  1959. /* Post  : A requester has been drawn to confirm the action. If this was acknowledged, then the file sort criterium has been      */
  1960. /*         toggled, the files have been resorted and reprinted.                                                                   */
  1961. /* Import: Requester, PrText, HandleFileSort.                                                                                     */
  1962. /**********************************************************************************************************************************/
  1963.  
  1964. {
  1965.   Requester (15, 25, 11, 32);
  1966.   PrText (-1, 18, 29, DRED, "ARE YOU SURE YOU WANT TO");
  1967.   HandleFileSort (TRUE);
  1968. }
  1969.  
  1970. void RescanFiles (void)
  1971.  
  1972. /**********************************************************************************************************************************/
  1973. /* Pre   : The user pressed [F5].                                                                                                 */
  1974. /* Post  : A requester has been drawn to confirm the action. If this was acknowledged, then all files that are currently in       */
  1975. /*         memory have been rescanned, and the result has been written to the WADINFOFILE. After this, the user has been asked if */
  1976. /*         the files should be resorted. At the end, all files are reprinted on screen.                                           */
  1977. /* Import: Requester, PrText, HandleFileSort, GetWadInfo, WriteWadInfo, WaitForConfirmation, ShowMouse, ConvertFullName.          */
  1978. /**********************************************************************************************************************************/
  1979.  
  1980. {
  1981.   int CountWadFiles;
  1982.  
  1983.   Requester (15, 25, 11, 32);
  1984.   PrText (-1, 18, 29, DRED, "ARE YOU SURE YOU WANT TO");
  1985.   PrText (-1, 20, 32, LRED, "RESCAN THE FILES ?");
  1986.   PrText (-1, 22, 31, DRED, "PRESS <Y> TO CONFIRM");
  1987.   if (!WaitForConfirmation ())                                                                                  /* Acknowledged ? */
  1988.   {                                                                                                            /* Step out if not */
  1989.     for (M = 16 ; M < 25 ; M ++)                                                                               /* Erase requester */
  1990.       PrText (-1, M, 26, DBLACK, "                                ");
  1991.     PrintWadFiles ();
  1992.     ShowMouse ();
  1993.     return;
  1994.   }
  1995.   PrText (-1, 18, 29, DRED, "                        ");
  1996.   PrText (-1, 20, 32, LRED, "   Searching ...  ");
  1997.   PrText (-1, 22, 31, DRED, "                    ");
  1998.   for (CountWadFiles = 0 ; CountWadFiles < TotalWads ; CountWadFiles ++)
  1999.     GetWadInfo (CountWadFiles, TRUE);                                                     /* Collect information on each WAD file */
  2000.   PrText (-1, 20, 29, LRED, "Writing WADINFOFILE ... ");
  2001.   WriteWadInfo (InfoFile);                                                                                    /* Write the result */
  2002.   for (CountWadFiles = 0 ; CountWadFiles < TotalWads ; CountWadFiles ++)
  2003.     ConvertFullName (WadInfo[CountWadFiles]);                                      /* Convert full names to short names if wanted */
  2004.   PrText (-1, 20, 29, LRED, "                        ");
  2005.   PrText (-1, 18, 34, DRED, "DO YOU WANT TO");
  2006.   HandleFileSort (FALSE);                                                                         /* Handle sorting of the result */
  2007. }
  2008.  
  2009. void ToggleFullName (void)
  2010.  
  2011. /**********************************************************************************************************************************/
  2012. /* Pre   : The user pressed [F7].                                                                                                 */
  2013. /* Post  : A requester has been drawn to confirm the action. If this was acknowledged, then the full name criterium has been      */
  2014. /*         toggled, the files have been resorted and reprinted.                                                                   */
  2015. /* Import: Requester, PrText, HandleFileSort.                                                                                     */
  2016. /**********************************************************************************************************************************/
  2017.  
  2018. {
  2019.   int CountWadFiles;
  2020.  
  2021.   Requester (15, 25, 11, 32);
  2022.   PrText (-1, 18, 29, DRED, "ARE YOU SURE YOU WANT TO");
  2023.   PrText (-1, 20, 31, LRED, "CONVERT FULL NAMES ?");
  2024.   PrText (-1, 22, 31, DRED, "PRESS <Y> TO CONFIRM");
  2025.   if (!WaitForConfirmation ())                                                                                  /* Acknowledged ? */
  2026.   {                                                                                                            /* Step out if not */
  2027.     for (M = 16 ; M < 25 ; M ++)                                                                               /* Erase requester */
  2028.       PrText (-1, M, 26, DBLACK, "                                ");
  2029.     PrintWadFiles ();
  2030.     ShowMouse ();
  2031.     return;
  2032.   }
  2033.   PrText (-1, 18, 29, DRED, "                        ");
  2034.   PrText (-1, 20, 31, LRED, "   Converting ...   ");
  2035.   PrText (-1, 22, 31, DRED, "                    ");
  2036.   NoFullName = !NoFullName;                                                                             /* Toggle NoFullName flag */
  2037.   for (CountWadFiles = 0 ; CountWadFiles < TotalWads ; CountWadFiles ++)
  2038.     ConvertFullName (WadInfo[CountWadFiles]);
  2039.   PrText (-1, 20, 31, DRED, "                    ");
  2040.   PrText (-1, 18, 34, DRED, "DO YOU WANT TO");
  2041.   HandleFileSort (FALSE);                                                                         /* Handle sorting of the result */
  2042. }
  2043.  
  2044. void DeleteWadFile (void)
  2045.  
  2046. /**********************************************************************************************************************************/
  2047. /* Pre   : None.                                                                                                                  */
  2048. /* Post  : The user has been asked permission to delete the hi-lighted file. If he/she comfirmed, then the file has been deleted  */
  2049. /*         from disk and memory. If the file is protected on disk, then nothing is done.                                          */
  2050. /* Import: Requester, PrintWadFiles, ShowMouse, UnselectPreviousWad, WaitForConfirmation.                                         */
  2051. /**********************************************************************************************************************************/
  2052.  
  2053. {
  2054.   int DeleteWadNumber;
  2055.  
  2056.   if (CurrentField != FILEFIELD)                                                       /* Return immediately if no file appointed */
  2057.     return;
  2058.   DeleteWadNumber = CurrentPage * PAGE + CurrentSelected - 1;                                         /* Determine the WAD number */
  2059.   Requester (15, 25, 11, 32);
  2060.   PrText (-1, 18, 29, DRED, "ARE YOU SURE YOU WANT TO");
  2061.   sprintf (S, "DELETE %s", WadInfo[DeleteWadNumber]->Name);
  2062.   for (M = strlen (S) - 1 ; S[M] == ' ' ; M --)
  2063.     S[M] = '\0';
  2064.   strcat (S, " ?");
  2065.   PrText (-1, 20, 40 - (strlen (S) / 2), LRED, S);
  2066.   PrText (-1, 22, 31, DRED, "PRESS <Y> TO CONFIRM");
  2067.   if (!WaitForConfirmation ())                                                                                  /* Acknowledged ? */
  2068.   {                                                                                                            /* Step out if not */
  2069.     for (M = 16 ; M < 25 ; M ++)                                                                               /* Erase requester */
  2070.       PrText (-1, M, 26, DBLACK, "                                ");
  2071.     PrintWadFiles ();
  2072.     ShowMouse ();
  2073.     return;
  2074.   }
  2075.   for (M = 16 ; M < 25 ; M ++)                                                                                 /* Erase requester */
  2076.     PrText (-1, M, 26, DBLACK, "                                       ");
  2077.   if (WadInfo[DeleteWadNumber]->Drive)                                                         /* Build complete path to the file */
  2078.     sprintf (S, "%c:", ToName (WadInfo[DeleteWadNumber]->Drive));
  2079.   else
  2080.     sprintf (S, "%c:", ToName (CurDrive));
  2081.   if (!strcmp (WadInfo[DeleteWadNumber]->Path, DEFAULTWADDIR))
  2082.     strcat (S, CurPath + 2);
  2083.   else
  2084.     strcat (S, WadInfo[DeleteWadNumber]->Path);
  2085.   strcat (S, "\\");
  2086.   strcat (S, WadInfo[DeleteWadNumber]->OrigName);
  2087.   if (_dos_setfileattr (S, _A_NORMAL))                                                    /* Clear any preventing file attributes */
  2088.   {                                                                                  /* Step out if protected from a higher level */
  2089.     PrintWadFiles ();
  2090.     ShowMouse ();
  2091.     return;
  2092.   }
  2093.   if (remove (S) == -1)                                                                          /* Now remove the file from disk */
  2094.   {                                                                                  /* Step out if protected from a higher level */
  2095.     PrintWadFiles ();
  2096.     ShowMouse ();
  2097.     return;
  2098.   }
  2099.   _ffree (WadInfo[DeleteWadNumber]);                                                               /* Remove the file from memory */
  2100.   for (M = DeleteWadNumber ; M < TotalWads ; M ++)                                          /* Move all files thereafter one back */
  2101.     WadInfo[M] = WadInfo[M + 1];
  2102.   TotalWads --;
  2103.   PrintWadFiles ();                                                                                           /* Print result ... */
  2104.   ShowMouse ();
  2105. }
  2106.  
  2107. void HandleFile (unsigned int Key)
  2108.  
  2109. /**********************************************************************************************************************************/
  2110. /* Pre   : 'Key' holds the preesed (raw) key code that caused calling this routine; if (global) 'UseMouse' was FALSE.             */
  2111. /*         Considered keys are the cursor keys and space. If 'UseMouse' was TRUE, than 'Key' is always 0x0000 (dummy).            */
  2112. /* Post  : The mouse pointer was at the bottom of the screen. The pointed filename has been highlighted. If the right mousebutton */
  2113. /*         was pressed, then the file is selected, which is shown by a different color. If the file was already selected, then it */
  2114. /*         is now deselected. Selection can only be done once on a button press. To invert the selection, the mouse button must   */
  2115. /*         first be released, and then pressed again.                                                                             */
  2116. /* Import: HideMouse, ShowMouse, UnselectPreviousField.                                                                           */
  2117. /**********************************************************************************************************************************/
  2118.  
  2119. {
  2120.   int PositionX;
  2121.   int PositionY;
  2122.   int OldWadNumber;
  2123.   int NewWadNumber;
  2124.  
  2125.   UnselectPreviousField (FILEFIELD);
  2126.   PositionY = 13 + ((PreviousWad - 1) % WADHEIGHT);                                        /* Location of previously selected WAD */
  2127.   PositionX = ((PreviousWad - 1) / WADHEIGHT) * WADWIDTH + 1;
  2128.   OldWadNumber = CurrentPage * PAGE + PreviousWad - 1;                                                      /* Number of that WAD */
  2129.   CurrentSelected = 0;                                                                              /* Signal: no file pointed to */
  2130.   if (UseMouse)
  2131.   {
  2132.     if (Mouse.Xx <= 7)                                                                               /* Determine the file column */
  2133.       CurrentSelected = Mouse.Yy - 11;
  2134.     else
  2135.       if (Mouse.Xx >= 27 && Mouse.Xx <= 34)
  2136.         CurrentSelected = Mouse.Yy - 11 + WADHEIGHT;
  2137.       else
  2138.         if (Mouse.Xx >= 54 && Mouse.Xx <= 61)
  2139.           CurrentSelected = Mouse.Yy - 11 + (2 * WADHEIGHT);
  2140.     if (CurrentPage * PAGE + CurrentSelected > TotalWads)                                                    /* Empty screen part */
  2141.       CurrentSelected = -1;
  2142.     MouseHidden = FALSE;
  2143.     if (CurrentField == FILEFIELD && Mouse.CoChange)                       /* Only unhighlite the previous one if the mouse moved */
  2144.     {
  2145.       HideMouse ();
  2146.       MouseHidden = TRUE;                                                                         /* Signal: mouse pointer hidden */
  2147.       if (WadInfo[OldWadNumber]->Selected)
  2148.         PrText (-1, PositionY, PositionX, DGREEN, WadInfo[OldWadNumber]->Name);
  2149.       else
  2150.         PrText (-1, PositionY, PositionX, DWHITE, WadInfo[OldWadNumber]->Name);
  2151.     }
  2152.   }
  2153.   else
  2154.   {
  2155.     switch (Key)
  2156.     {
  2157.       case KEY_CURSLEFT   : if (PreviousWad > WADHEIGHT)                                                 /* Possible to go left ? */
  2158.                               CurrentSelected = PreviousWad - WADHEIGHT;
  2159.                             else                                                          /* Determine the far right and go there */
  2160.                               if ((CurrentPage * PAGE + PreviousWad + 2 * WADHEIGHT) <= TotalWads)
  2161.                                 CurrentSelected = PreviousWad + 2 * WADHEIGHT;                                       /* 3 columns */
  2162.                               else
  2163.                                 if ((CurrentPage * PAGE + PreviousWad + WADHEIGHT) <= TotalWads)                     /* 2 columns */
  2164.                                   CurrentSelected = PreviousWad + WADHEIGHT;
  2165.                                 else                                                           /* Only 1 column; no move possible */
  2166.                                   CurrentSelected = PreviousWad;
  2167.                             break;
  2168.       case KEY_CURSRIGHT  : if ((PreviousWad < 2 * WADHEIGHT) && (CurrentPage * PAGE + PreviousWad + WADHEIGHT) <= TotalWads)
  2169.                               CurrentSelected = PreviousWad + WADHEIGHT;
  2170.                             else
  2171.                               CurrentSelected = PreviousWad % WADHEIGHT;
  2172.                             break;
  2173.       case KEY_CURSUP     : if (((PreviousWad - 1) % WADHEIGHT) > 0)
  2174.                               CurrentSelected = PreviousWad - 1;
  2175.                             else
  2176.                               if ((CurrentPage * PAGE + PreviousWad + WADHEIGHT) <= TotalWads)
  2177.                                 CurrentSelected = PreviousWad - 1 + WADHEIGHT;
  2178.                               else
  2179.                                 CurrentSelected = TotalWads % PAGE;
  2180.                             break;
  2181.       case KEY_CURSDOWN   : if (((PreviousWad - 1) % WADHEIGHT) < (WADHEIGHT - 1))
  2182.                               if ((CurrentPage * PAGE + PreviousWad + 1) <= TotalWads)
  2183.                                 CurrentSelected = PreviousWad + 1;
  2184.                               else
  2185.                                 CurrentSelected = (TotalWads % PAGE) - (TotalWads % WADHEIGHT) + 1;
  2186.                             else
  2187.                               CurrentSelected = PreviousWad + 1 - WADHEIGHT;
  2188.                             break;
  2189.       case KEY_SELECTFILE : CurrentSelected = PreviousWad;
  2190.     }
  2191.     if (Key != KEY_SELECTFILE)                                                                     /* Unhighlite the previous one */
  2192.       if (WadInfo[OldWadNumber]->Selected)
  2193.         PrText (-1, PositionY, PositionX, DGREEN, WadInfo[OldWadNumber]->Name);
  2194.       else
  2195.         PrText (-1, PositionY, PositionX, DWHITE, WadInfo[OldWadNumber]->Name);
  2196.   }
  2197.   NewWadNumber = CurrentPage * PAGE + CurrentSelected - 1;
  2198.   if ((UseMouse && (Mouse.Left && !Mouse.LeftStillPressed && CurrentSelected > 0))                      /* Mouse button pressed ? */
  2199.       || (Key == KEY_SELECTFILE))
  2200.   {
  2201.     WadInfo[NewWadNumber]->Selected = !WadInfo[NewWadNumber]->Selected;                                       /* Invert selection */
  2202.     SelectionChange = TRUE;                                                                               /* Signal: screenchange */
  2203.   }
  2204.   else
  2205.     SelectionChange = FALSE;
  2206.   if (CurrentSelected > 0)                                                                    /* A (valid) new file is pointed to */
  2207.   {
  2208.     if (Mouse.CoChange || SelectionChange || !UseMouse)                                                  /* Color change needed ? */
  2209.     {
  2210.       PositionY = 13 + ((CurrentSelected - 1) % WADHEIGHT);
  2211.       PositionX = ((CurrentSelected - 1) / WADHEIGHT) * WADWIDTH + 1;
  2212.       if (!MouseHidden)                                                                   /* Hide the mouse if not hidden already */
  2213.         HideMouse ();
  2214.       MouseHidden = TRUE;
  2215.       if (WadInfo[NewWadNumber]->Selected)                                                                 /* 'Draw' highlite bar */
  2216.         PrText (-1, PositionY, PositionX, LGREEN, WadInfo[NewWadNumber]->Name);
  2217.       else
  2218.         PrText (-1, PositionY, PositionX, LRED, WadInfo[NewWadNumber]->Name);
  2219.     }
  2220.     CurrentField = FILEFIELD;
  2221.     PreviousWad = CurrentSelected;
  2222.   }
  2223.   else
  2224.     CurrentField = NOFIELD;
  2225.   if (MouseHidden)                                                                         /* Reprint the mouse pointer if needed */
  2226.     ShowMouse ();
  2227. }
  2228.  
  2229. void HandleEpisode (boolean KeyInput)
  2230.  
  2231. /**********************************************************************************************************************************/
  2232. /* Pre   : 'KeyInput' is TRUE if this routine was called because of a keypress.                                                   */
  2233. /* Post  : The mouse pointer was at the episode block. The pointed episode has been highlited. If the mouse button was pressed,   */
  2234. /*         then this episode is selected (and the previous automatically de-selected). The new result is reprinted.               */
  2235. /* Import: HideMouse, ShowMouse, PrintEpisodes, UnselectPreviousField.                                                            */
  2236. /**********************************************************************************************************************************/
  2237.  
  2238. {
  2239.   HideMouse ();
  2240.   if (!KeyInput)
  2241.     UnselectPreviousField (EPISODEFIELD);
  2242.   if (Mouse.Left && !Mouse.LeftStillPressed)                                                            /* Mouse button pressed ? */
  2243.     EpisodeActive = Mouse.Yy - 1;                                                            /* Make the highlited episode active */
  2244.   else
  2245.     if (KeyInput)                                                                                                  /* Key pressed */
  2246.       if (++ EpisodeActive > NUMEPISODE)                                                               /* Increase episode number */
  2247.         EpisodeActive = 1;
  2248.   if (KeyInput)
  2249.     if (CurrentField == EPISODEFIELD)
  2250.       PrintEpisodes (Mouse.Yy - 1);
  2251.     else
  2252.       PrintEpisodes (0);
  2253.   else
  2254.   {
  2255.     PrintEpisodes (Mouse.Yy - 1);
  2256.     CurrentField = EPISODEFIELD;
  2257.   }
  2258.   ShowMouse ();
  2259. }
  2260.   
  2261. void HandleDifficulty (boolean KeyInput)
  2262.  
  2263. /**********************************************************************************************************************************/
  2264. /* Pre   : 'KeyInput' is TRUE if this routine was called because of a keypress.                                                   */
  2265. /* Post  : The mouse pointer was at the difficulty block. The pointed difficulty has been highlited. If the mouse button was      */
  2266. /*         pressed then this difficulty is selected (and the previous automatically de-selected). The new result is reprinted.    */
  2267. /* Import: HideMouse, ShowMouse, PrintDifficulties, UnselectPreviousField.                                                        */
  2268. /**********************************************************************************************************************************/
  2269.  
  2270. {
  2271.   int MaxDiff;
  2272.  
  2273.   MaxDiff = (DoomVersion >= 2) ? NUMDIFFICULTY : NUMDIFFICULTY - 1;                         /* NIGHTMARE only available from v1.2 */
  2274.   HideMouse ();
  2275.   if (!KeyInput)
  2276.     UnselectPreviousField (DIFFICULTYFIELD);
  2277.   if (Mouse.Left && !Mouse.LeftStillPressed)
  2278.     DifficultyActive = Mouse.Yy - 1;
  2279.   else
  2280.     if (KeyInput)
  2281.       if (++ DifficultyActive > MaxDiff)
  2282.         DifficultyActive = 1;
  2283.   if (KeyInput)
  2284.     if (CurrentField == DIFFICULTYFIELD)
  2285.       PrintDifficulties (Mouse.Yy - 1);
  2286.     else
  2287.       PrintDifficulties (0);
  2288.   else
  2289.   {
  2290.     PrintDifficulties (Mouse.Yy - 1);
  2291.     CurrentField = DIFFICULTYFIELD;
  2292.   }
  2293.   ShowMouse ();
  2294. }
  2295.   
  2296. void HandlePlayType (boolean KeyInput, char Key)
  2297.  
  2298. /**********************************************************************************************************************************/
  2299. /* Pre   : 'KeyInput' is TRUE if this routine was called because of a keypress.                                                   */
  2300. /*         If it was TRUE, then 'Key' holds the (ASCII) keyvalue, otherwise 'Key' holds 0x00 (dummy).                             */
  2301. /* Post  : The mouse pointer was at the playtype block. The pointed playtype has been highlited. If the mouse button was pressed  */
  2302. /*         then this playtype is selected (and the previous automatically de-selected). The new result is reprinted.              */
  2303. /*         If the mouse pointer was at the fourth line, than the PlayType parameter of the current PlayType is handled.           */
  2304. /* Import: HideMouse, ShowMouse, PrintPlayTypes, UnselectPreviousField.                                                           */
  2305. /**********************************************************************************************************************************/
  2306.  
  2307. {
  2308.   int Mpt;
  2309.  
  2310.   if (DoomVersion == 0)                                                                   /* DOOM v1.0 could only be played alone */
  2311.     return;
  2312.   HideMouse ();
  2313.   if (DoomVersion == 1 && Mouse.Yy == 4)
  2314.   {
  2315.     UnselectPreviousField (NOFIELD);
  2316.     CurrentField = NOFIELD;
  2317.     PrintPlayTypes (0);
  2318.     ShowMouse ();
  2319.     return;
  2320.   }
  2321.   Mpt = ((DoomVersion >= 2) ? NUMPLAYTYPE : NUMPLAYTYPE - 1);                           /* v1.1 also had IPX, v1.2 also had modem */
  2322.   if (!KeyInput)
  2323.     UnselectPreviousField (PLAYTYPEFIELD);
  2324.   if (KeyInput)
  2325.   {
  2326.     switch (Key)
  2327.     {
  2328.       case KEY_PLAYTYPE : if (++ PlayTypeActive > Mpt)
  2329.                             PlayTypeActive = 1;
  2330.                           break;
  2331.       case KEY_NODES    : if (PlayTypeActive == 2 && !OtherIpxDriver)                                           /* IPX compatible */
  2332.                             if (++ NumNodesActive == 5)                                             /* Increase number of players */
  2333.                               NumNodesActive = 2;                                                      /* Must be between 2 and 4 */
  2334.                           break;
  2335.       case KEY_COMPORT  : if (PlayTypeActive == 3 && !OtherSerDriver)                                          /* Null-modem link */
  2336.                             if (++ CommPortActive == 5)                                               /* Increase COM port number */
  2337.                               CommPortActive = 1;                                                      /* Must be between 1 and 4 */
  2338.     }
  2339.     if (CurrentField == PLAYTYPEFIELD)
  2340.       PrintPlayTypes (Mouse.Yy - 1);
  2341.     else
  2342.       PrintPlayTypes (0);
  2343.   }
  2344.   else                                                                                                             /* Mouse input */
  2345.   {
  2346.     if (Mouse.Left && !Mouse.LeftStillPressed)
  2347.       if (Mouse.Yy <= Mpt + 1)                                                                               /* Change PlayType ? */
  2348.         PlayTypeActive = Mouse.Yy - 1;
  2349.       else
  2350.         if (PlayTypeActive == 2 && !OtherIpxDriver)                                                             /* IPX compatible */
  2351.         {
  2352.           if (++ NumNodesActive == 5)                                                               /* Increase number of players */
  2353.             NumNodesActive = 2;                                                                        /* Must be between 2 and 4 */
  2354.         }
  2355.         else
  2356.           if (PlayTypeActive == 3 && !OtherSerDriver)                                                         /* Null-modem link */
  2357.           {
  2358.             if (++ CommPortActive == 5)                                                               /* Increase COM port number */
  2359.               CommPortActive = 1;                                                                      /* Must be between 1 and 4 */
  2360.           }
  2361.     PrintPlayTypes (Mouse.Yy - 1);
  2362.     CurrentField = PLAYTYPEFIELD;
  2363.   }
  2364.   ShowMouse ();
  2365. }
  2366.   
  2367. void HandleRespawnMonsters (boolean KeyInput)
  2368.  
  2369. /**********************************************************************************************************************************/
  2370. /* Pre   : 'KeyInput' is TRUE if this routine was called because of a keypress.                                                   */
  2371. /* Post  : The mouse pointer was at the respawn item. This item has been highlited. If the mouse button was pressed, then the     */
  2372. /*         active value is inverted. The new result is reprinted.                                                                 */
  2373. /*         If (global) 'DoomVersion' is less than 1.2, then nothing has been done here.                                           */
  2374. /* Import: HideMouse, ShowMouse, PrintRespawnMonsters, PrintNoMonsters, UnselectPreviousField.                                    */
  2375. /**********************************************************************************************************************************/
  2376.  
  2377. {
  2378.   HideMouse ();
  2379.   if (!KeyInput)
  2380.     UnselectPreviousField (RESPAWNFIELD);
  2381.   if (DoomVersion >= 2)                                                                       /* Respawn only available from v1.2 */
  2382.   {
  2383.     if ((Mouse.Left && !Mouse.LeftStillPressed) || KeyInput)
  2384.       if (RespMonstersOn = !RespMonstersOn)                                                            /* Toggle the RESPAWN item */
  2385.         NoMonstersOn = FALSE;
  2386.     if (KeyInput)
  2387.     {
  2388.       PrintRespawnMonsters (CurrentField == RESPAWNFIELD);
  2389.       PrintNoMonsters (CurrentField == NOMONSTERSFIELD);
  2390.     }
  2391.     else
  2392.     {
  2393.       PrintRespawnMonsters (TRUE);
  2394.       PrintNoMonsters (FALSE);
  2395.       CurrentField = RESPAWNFIELD;
  2396.     }
  2397.   }
  2398.   ShowMouse ();
  2399. }
  2400.  
  2401. void HandleNoMonsters (boolean KeyInput)
  2402.  
  2403. /**********************************************************************************************************************************/
  2404. /* Pre   : 'KeyInput' is TRUE if this routine was called because of a keypress.                                                   */
  2405. /* Post  : The mouse pointer was at the nomonsters item. This item has been highlited. If the mouse button was pressed, then the  */
  2406. /*         active value is inverted. The new result is reprinted.                                                                 */
  2407. /*         If (global) 'DoomVersion' is less than 1.2, then nothing has been done here.                                           */
  2408. /* Import: HideMouse, ShowMouse, PrintNoMonsters, PrintRespawnMonsters, PrintFastMonsters, UnselectPreviousField.                 */
  2409. /**********************************************************************************************************************************/
  2410.  
  2411. {
  2412.   HideMouse ();
  2413.   if (!KeyInput)
  2414.     UnselectPreviousField (NOMONSTERSFIELD);
  2415.   if (DoomVersion >= 2)                                                                    /* NoMonsters only available from v1.2 */
  2416.   {
  2417.     if ((Mouse.Left && !Mouse.LeftStillPressed) || KeyInput)
  2418.       if (NoMonstersOn = !NoMonstersOn)                                                             /* Toggle the NOMONSTERS item */
  2419.       {
  2420.         RespMonstersOn = FALSE;                                                                     /* These are contradictionary */
  2421.         FastMonstersOn = FALSE;
  2422.       }
  2423.     if (KeyInput)
  2424.     {
  2425.       PrintNoMonsters (CurrentField == NOMONSTERSFIELD);
  2426.       PrintRespawnMonsters (CurrentField == RESPAWNFIELD);
  2427.       PrintFastMonsters (CurrentField == FASTMONSTERSFIELD);
  2428.     }
  2429.     else
  2430.     {
  2431.       PrintNoMonsters (TRUE);
  2432.       PrintRespawnMonsters (FALSE);
  2433.       PrintFastMonsters (FALSE);
  2434.       CurrentField = NOMONSTERSFIELD;
  2435.     }
  2436.   }
  2437.   ShowMouse ();
  2438. }
  2439.  
  2440. void HandleFastMonsters (boolean KeyInput)
  2441.  
  2442. /**********************************************************************************************************************************/
  2443. /* Pre   : 'KeyInput' is TRUE if this routine was called because of a keypress.                                                   */
  2444. /* Post  : The mouse pointer was at the fastmonsters item. This item has been highlited. If the mouse button was pressed, then    */
  2445. /*         the active value is inverted. The new result is reprinted.                                                             */
  2446. /*         If (global) 'DoomVersion' is less than 1.5, then nothing has been done here.                                           */
  2447. /* Import: HideMouse, ShowMouse, PrintFastMonsters, PrintNoMonsters, UnselectPreviousField.                                       */
  2448. /**********************************************************************************************************************************/
  2449.  
  2450. {
  2451.   HideMouse ();
  2452.   if (!KeyInput)
  2453.     UnselectPreviousField (FASTMONSTERSFIELD);
  2454.   if (DoomVersion >= 5)                                                                  /* FastMonsters only available from v1.5 */
  2455.   {
  2456.     if ((Mouse.Left && !Mouse.LeftStillPressed) || KeyInput)
  2457.       if (FastMonstersOn = !FastMonstersOn)                                                       /* Toggle the FASTMONSTERS item */
  2458.         NoMonstersOn = FALSE;                                                                       /* These are contradictionary */
  2459.     if (KeyInput)
  2460.     {
  2461.       PrintFastMonsters (CurrentField == FASTMONSTERSFIELD);
  2462.       PrintNoMonsters (CurrentField == NOMONSTERSFIELD);
  2463.     }
  2464.     else
  2465.     {
  2466.       PrintFastMonsters (TRUE);
  2467.       PrintNoMonsters (FALSE);
  2468.       CurrentField = FASTMONSTERSFIELD;
  2469.     }
  2470.   }
  2471.   ShowMouse ();
  2472. }
  2473.  
  2474. void HandleDeathmatch (boolean KeyInput)
  2475.  
  2476. /**********************************************************************************************************************************/
  2477. /* Pre   : 'KeyInput' is TRUE if this routine was called because of a keypress.                                                   */
  2478. /* Post  : The mouse pointer was at the deathmatch item. This item has been highlited. If the mouse button was pressed, then the  */
  2479. /*         active value is inverted. The new result is reprinted.                                                                 */
  2480. /*         If (global) 'DoomVersion' is less than 1.2, then nothing has been done here.                                           */
  2481. /* Import: HideMouse, ShowMouse, PrintDeathmatch, UnselectPreviousField, PrintV2Deathmatch.                                       */
  2482. /**********************************************************************************************************************************/
  2483.  
  2484. {
  2485.   HideMouse ();
  2486.   if (!KeyInput)
  2487.     UnselectPreviousField (DEATHMATCHFIELD);
  2488.   if (DoomVersion >= 2)                                                                    /* Deathmatch only available from v1.2 */
  2489.   {
  2490.     if ((Mouse.Left && !Mouse.LeftStillPressed) || KeyInput)
  2491.       if (DeathmatchOn = !DeathmatchOn)                                                             /* Toggle the DEATHMATCH item */
  2492.         DeathmatchV2On = FALSE;
  2493.     if (KeyInput)
  2494.     {
  2495.       PrintDeathmatch (CurrentField == DEATHMATCHFIELD);
  2496.       PrintV2Deathmatch (CurrentField == DEATHMATCHV2FIELD);
  2497.     }
  2498.     else
  2499.     {
  2500.       PrintDeathmatch (TRUE);
  2501.       PrintV2Deathmatch (FALSE);
  2502.       CurrentField = DEATHMATCHFIELD;
  2503.     }
  2504.   }
  2505.   ShowMouse ();
  2506. }
  2507.   
  2508. void HandleV2Deathmatch (boolean KeyInput)
  2509.  
  2510. /**********************************************************************************************************************************/
  2511. /* Pre   : 'KeyInput' is TRUE if this routine was called because of a keypress.                                                   */
  2512. /* Post  : The mouse pointer was at the deathmatch item. This item has been highlited. If the mouse button was pressed, then the  */
  2513. /*         active value is inverted. The new result is reprinted.                                                                 */
  2514. /*         If (global) 'DoomVersion' is less than 1.5, then nothing has been done here.                                           */
  2515. /* Import: HideMouse, ShowMouse, PrintDeathmatch, UnselectPreviousField, PrintV2Deathmatch.                                       */
  2516. /**********************************************************************************************************************************/
  2517.  
  2518. {
  2519.   HideMouse ();
  2520.   if (!KeyInput)
  2521.     UnselectPreviousField (DEATHMATCHV2FIELD);
  2522.   if (DoomVersion >= 5)                                                               /* Deathmatch v2.0 only available from v1.5 */
  2523.   {
  2524.     if ((Mouse.Left && !Mouse.LeftStillPressed) || KeyInput)
  2525.       if (DeathmatchV2On = !DeathmatchV2On)
  2526.         DeathmatchOn = FALSE;
  2527.     if (KeyInput)
  2528.     {
  2529.       PrintV2Deathmatch (CurrentField == DEATHMATCHV2FIELD);
  2530.       PrintDeathmatch (CurrentField == DEATHMATCHFIELD);
  2531.     }
  2532.     else
  2533.     {
  2534.       PrintV2Deathmatch (TRUE);
  2535.       PrintDeathmatch (FALSE);
  2536.       CurrentField = DEATHMATCHV2FIELD;
  2537.     }
  2538.   }
  2539.   ShowMouse ();
  2540. }
  2541.   
  2542. void HandleLevel (boolean KeyInput)
  2543.  
  2544. /**********************************************************************************************************************************/
  2545. /* Pre   : 'KeyInput' is TRUE if this routine was called because of a keypress.                                                   */
  2546. /* Post  : The mouse pointer was at the level item. This level has been highlited. If the mouse button was pressed, then the      */
  2547. /*         active level is increased. If it exceeded 9, then it is wrapped back to 1. The new result is reprinted.                */
  2548. /* Import: HideMouse, ShowMouse, PrintLevel, UnselectPreviousField.                                                               */
  2549. /**********************************************************************************************************************************/
  2550.  
  2551. {
  2552.   HideMouse ();
  2553.   if (!KeyInput)
  2554.     UnselectPreviousField (LEVELFIELD);
  2555.   if ((Mouse.Left && !Mouse.LeftStillPressed) || KeyInput)
  2556.     if (++ CurrentLevel > NUMLEVEL)                                                                     /* Increase current level */
  2557.       CurrentLevel = 1;                                                                      /* After level 9 comes level 1 again */
  2558.   if (KeyInput)
  2559.     PrintLevel (CurrentField == LEVELFIELD);
  2560.   else
  2561.   {
  2562.     CurrentField = LEVELFIELD;
  2563.     PrintLevel (TRUE);
  2564.   }
  2565.   ShowMouse ();
  2566. }
  2567.   
  2568. void HandlePreviousPage (boolean KeyInput)
  2569.  
  2570. /**********************************************************************************************************************************/
  2571. /* Pre   : 'KeyInput' is TRUE if this routine is entered because the [PAGE UP] key was pressed.                                   */
  2572. /* Post  : The mouse pointer was at the previouspage item. This item has been highlited. If the mouse button was pressed, then    */
  2573. /*         a test is made if there are previous pages. If not, then the keyboard bell is sound, otherwise the previous page has   */
  2574. /*         been made the current. This new page has been printed.                                                                 */
  2575. /* Import: HideMouse, ShowMouse, PrintWadFiles, PrintPagers, UnselectPreviousField.                                               */
  2576. /**********************************************************************************************************************************/
  2577.  
  2578. {
  2579.   if (CurrentPage == 0)                                                                  /* Step out if there is no previous page */
  2580.     return;
  2581.   HideMouse ();
  2582.   if (!KeyInput)
  2583.     UnselectPreviousField (PAGERFIELD);
  2584.   if ((Mouse.Left && !Mouse.LeftStillPressed) || KeyInput)
  2585.   {
  2586.     CurrentPage --;                                                                                             /* Go back a page */
  2587.     PrText (-1, 11, 69, LWHITE, "%2d", CurrentPage + 1);
  2588.     PrintWadFiles ();                                                                                      /* Print this new page */
  2589.     if (!UseMouse)
  2590.       PrText (-1, 13 + ((PreviousWad - 1) % WADHEIGHT),
  2591.                   ((PreviousWad - 1) / WADHEIGHT) * WADWIDTH + 1,
  2592.                   LRED, WadInfo[CurrentPage * PAGE + PreviousWad - 1]->Name);                  /* Hi-light 'new current' WAD file */
  2593.   }
  2594.   if (!KeyInput)
  2595.   {
  2596.     PrintPagers (1);
  2597.     CurrentField = PAGERFIELD;
  2598.   }
  2599.   else
  2600.     PrintPagers (CurrentField == PAGERFIELD ? 1 : 0);
  2601.   ShowMouse ();
  2602. }
  2603.  
  2604. void HandleNextPage (boolean KeyInput)
  2605.  
  2606. /**********************************************************************************************************************************/
  2607. /* Pre   : 'KeyInput' is TRUE if this routine was called because the user pressed the [PAGE DOWN] key.                            */
  2608. /* Post  : The mouse pointer was at the nextpage item. This item has been highlited. If the mouse button was pressed, then a test */
  2609. /*         is made if there are next pages. If not, then the keyboard bell is sound, otherwise the next page has been made the    */
  2610. /*         current. This new page has been printed.                                                                               */
  2611. /* Import: HideMouse, ShowMouse, PrintWadFiles, PrintPagers, UnselectPreviousField.                                               */
  2612. /**********************************************************************************************************************************/
  2613.  
  2614. {
  2615.   if (CurrentPage == LastPage)                                                               /* Step out if there is no next page */
  2616.     return;
  2617.   HideMouse ();
  2618.   if (!KeyInput)
  2619.     UnselectPreviousField (PAGERFIELD);
  2620.   if ((Mouse.Left && !Mouse.LeftStillPressed) || KeyInput)
  2621.   {
  2622.     CurrentPage ++;
  2623.     PrText (-1, 11, 69, LWHITE, "%2d", CurrentPage + 1);
  2624.     PrintWadFiles ();
  2625.     if (!UseMouse)
  2626.     {
  2627.       if ((CurrentPage * PAGE + PreviousWad - 1) >= TotalWads)              /* If not a full page, then test that the new pointed */
  2628.         PreviousWad = TotalWads % PAGE;                                    /* WAD file is valid, otherwise set it to the last one */
  2629.       PrText (-1, 13 + ((PreviousWad - 1) % WADHEIGHT),
  2630.                   ((PreviousWad - 1) / WADHEIGHT) * WADWIDTH + 1,
  2631.                   LRED, WadInfo[CurrentPage * PAGE + PreviousWad - 1]->Name);                  /* Hi-light 'new current' WAD file */
  2632.     }
  2633.   }
  2634.   if (!KeyInput)
  2635.   {
  2636.     PrintPagers (2);
  2637.     CurrentField = PAGERFIELD;
  2638.   }
  2639.   else
  2640.     PrintPagers (CurrentField == PAGERFIELD ? 2 : 0);
  2641.   ShowMouse ();
  2642. }
  2643.  
  2644. void HandleReadPrev (boolean KeyInput)
  2645.  
  2646. /**********************************************************************************************************************************/
  2647. /* Pre   : 'KeyInput' is TRUE if this routine was called because of a keypress.                                                   */
  2648. /* Post  : The mouse pointer was at the read previous item. This item has been highlited. If the mouse button was pressed, then   */
  2649. /*         the file 'START.BAT' is read. Each item is set to the read value, all read WAD files are selected.                     */
  2650. /* Import: HideMouse, ShowMouse, PrintRdPrev, PrintEpisodes, PrintDifficulties, PrintPlayTypes, PrintDeathmatch, PrintLevel,      */
  2651. /*         PrintWadFiles, UnselectPreviousField.                                                                                  */
  2652. /**********************************************************************************************************************************/
  2653.  
  2654. {
  2655.   FILE    *Fp;
  2656.   char     FileName[_MAX_FNAME];
  2657.   char     Directory[_MAX_DIR];
  2658.   char     Tmp[_MAX_DIR];
  2659.   char     DriveNum;
  2660.   boolean  Handled;
  2661.   boolean  Stop;
  2662.  
  2663.   HideMouse ();
  2664.   if (!KeyInput)
  2665.     UnselectPreviousField (RDPREVFIELD);
  2666.   if (!KeyInput)
  2667.   {
  2668.     PrintRdPrev (TRUE);
  2669.     CurrentField = RDPREVFIELD;
  2670.   }
  2671.   if ((Mouse.Left && !Mouse.LeftStillPressed) || KeyInput)
  2672.   {
  2673.     Stop = FALSE;
  2674.     if (!(Fp = fopen (BATFILE, "r")))                                                                         /* Open "START.BAT" */
  2675.       Stop = TRUE;
  2676.     else
  2677.     {
  2678.       EpisodeActive = DEFAULTEPISODE;                                                          /* Set all items to their defaults */
  2679.       DifficultyActive = DEFAULTDIFFICULTY;
  2680.       PlayTypeActive = DEFAULTPLAYTYPE;
  2681.       CurrentLevel = DEFAULTLEVEL;
  2682.       DeathmatchOn = DEFAULTDMATCH;
  2683.       DeathmatchV2On = DEFAULTDMATCHV2;
  2684.       RespMonstersOn = DEFAULTRESPAWN;
  2685.       NoMonstersOn = DEFAULTNOMONSTERS;
  2686.       FastMonstersOn = DEFAULTFASTMONST;
  2687.       CommPortActive = DEFAULTCOMPORT;
  2688.       NumNodesActive = DEFAULTNODES;
  2689.       for (M = 0 ; M < TotalWads ; M ++)                                                                /* Unselect all WAD files */
  2690.         WadInfo[M]->Selected = FALSE;
  2691.       fscanf (Fp, "%s", S);                                                                             /* First read the command */
  2692.       while (!feof (Fp)
  2693.              && stricmp (S, STARTALONE)
  2694.              && stricmp (S, STARTIPX) && stricmp (S, IpxDriver)
  2695.              && stricmp (S, STARTLINK) && stricmp (S, SerDriver))
  2696.         fscanf (Fp, "%s", S);
  2697.       if (!stricmp (S, STARTALONE))
  2698.         PlayTypeActive = 1;
  2699.       else
  2700.         if (!stricmp (S, STARTIPX) || !stricmp (S, IpxDriver))
  2701.           PlayTypeActive = 2;
  2702.         else
  2703.             if (!stricmp (S, STARTLINK) || !stricmp (S, SerDriver))
  2704.               PlayTypeActive = 3;
  2705.             else
  2706.               Stop = TRUE;                                                                            /* Not a DOOM start command */
  2707.       if (!Stop)
  2708.       {
  2709.         fscanf (Fp, "%s", S);
  2710.         while (!feof (Fp) && !Stop)                                                                      /* Handle each parameter */
  2711.         {
  2712.           Handled = FALSE;
  2713.           if (S[0] == '@')                                                                           /* 'Response' file following */
  2714.           {
  2715.             fclose (Fp);                                                                                     /* Close "START.BAT" */
  2716.             if (!(Fp = fopen (S + 1, "r")))                                                           /* Open the 'Response' file */
  2717.               Stop = TRUE;                                                                     /* Stop if the file does not exist */
  2718.             else
  2719.               fscanf (Fp, "%s", S);                                                                /* Else: read the first string */
  2720.           }
  2721.           if (!feof (Fp) && !stricmp (S, NWSOCKET) && !Stop)                                                   /* Found '-SOCKET' */
  2722.           {
  2723.             fscanf (Fp, "%s", S);                                                           /* '-SOCKET' takes a parameter: 0-255 */
  2724.             if (feof (Fp))
  2725.               Stop = TRUE;
  2726.             for (N = 0 ; N < strlen (S) && !Stop ; N ++)
  2727.               Stop = !isdigit (S[N]);
  2728.             if (!Stop)
  2729.             {
  2730.               NetworkSocket = atoi (S);
  2731.               Handled = TRUE;
  2732.               fscanf (Fp, "%s", S);
  2733.             }
  2734.           }
  2735.           if (!feof (Fp) && !stricmp (S, SKILL) && !Stop)                                                       /* Found '-SKILL' */
  2736.           {
  2737.             fscanf (Fp, "%s", S);                                                              /* '-SKILL' takes a parameter: 1-5 */
  2738.             if (feof (Fp) || strlen (S) != 1 || S[0] < '1' || S[0] > '5')
  2739.               Stop = TRUE;
  2740.             else
  2741.             {
  2742.               DifficultyActive = S[0] - '0';
  2743.               Handled = TRUE;
  2744.               fscanf (Fp, "%s", S);
  2745.             }
  2746.           }
  2747.           if (!feof (Fp) && !stricmp (S, DMATCH) && !Stop)                                                 /* Found '-DEATHMATCH' */
  2748.           {
  2749.             DeathmatchOn = TRUE;
  2750.             Handled = TRUE;
  2751.             fscanf (Fp, "%s", S);
  2752.           }
  2753.           if (!feof (Fp) && !stricmp (S, DMATCHV2) && !Stop)                                                 /* Found '-ALTDEATH' */
  2754.           {
  2755.             DeathmatchV2On = TRUE;
  2756.             Handled = TRUE;
  2757.             fscanf (Fp, "%s", S);
  2758.           }
  2759.           if (!feof (Fp) && !stricmp (S, NOMONSTERS) && !Stop)                                             /* Found '-NOMONSTERS' */
  2760.           {
  2761.             NoMonstersOn = TRUE;
  2762.             Handled = TRUE;
  2763.             fscanf (Fp, "%s", S);
  2764.           }
  2765.           if (!feof (Fp) && !stricmp (S, RESPAWNMONSTERS) && !Stop)                                           /* Found '-RESPAWN' */
  2766.           {
  2767.             RespMonstersOn = TRUE;
  2768.             Handled = TRUE;
  2769.             fscanf (Fp, "%s", S);
  2770.           }
  2771.           if (!feof (Fp) && !stricmp (S, FASTMONSTERS) && !Stop)                                                 /* Found '-FAST' */
  2772.           {
  2773.             FastMonstersOn = TRUE;
  2774.             Handled = TRUE;
  2775.             fscanf (Fp, "%s", S);
  2776.           }
  2777.           if (!feof (Fp) && !stricmp (S, DEVPARM) && !Stop)                                                   /* Found '-DEVPARM' */
  2778.           {
  2779.             Handled = TRUE;                                                                               /* (Ignore the keyword) */
  2780.             fscanf (Fp, "%s", S);
  2781.           }
  2782.           if (!feof (Fp) && !stricmp (S, GOTOANYTHING) && !Stop)                                                 /* Found '-WARP' */
  2783.           {
  2784.             fscanf (Fp, "%s", S);                                  /* '-WARP' takes two parameters: episode (1-3) and level (1-9) */
  2785.             if (feof (Fp) || strlen (S) != 1 || S[0] < '1' || S[0] > '3')
  2786.               Stop = TRUE;
  2787.             else
  2788.             {
  2789.               EpisodeActive = S[0] - '0';
  2790.               fscanf (Fp, "%s", S);
  2791.               if (feof (Fp) || strlen (S) != 1 || S[0] < '1' || S[0] > '9')
  2792.                 Stop = TRUE;
  2793.               else
  2794.               {
  2795.                 CurrentLevel = S[0] - '0';
  2796.                 Handled = TRUE;
  2797.                 fscanf (Fp, "%s", S);
  2798.               }
  2799.             }
  2800.           }
  2801.           if (!feof (Fp) && !strnicmp (S, COMPORT, 4) && !Stop)                                                  /* Found '-COM#' */
  2802.           {
  2803.             if (strlen (S) != 5 || S[4] < '1' || S[0] > '4')                       /* COM port number is last char in this string */
  2804.               Stop = TRUE;                                                                     /* Port number must be between 1-4 */
  2805.             else
  2806.             {
  2807.               CommPortActive = S[4] - '0';
  2808.               Handled = TRUE;
  2809.               fscanf (Fp, "%s", S);
  2810.             }
  2811.           }
  2812.           if (!feof (Fp) && !stricmp (S, NUMPLAYERS) && !Stop)                                                  /* Found '-NODES' */
  2813.           {
  2814.             fscanf (Fp, "%s", S);                                                              /* '-NODES' takes a parameter: 2-4 */
  2815.             if (feof (Fp) || strlen (S) != 1 || S[0] < '2' || S[0] > '4')
  2816.               Stop = TRUE;
  2817.             else
  2818.             {
  2819.               NumNodesActive = S[0] - '0';
  2820.               Handled = TRUE;
  2821.               fscanf (Fp, "%s", S);
  2822.             }
  2823.           }
  2824.           if (!feof (Fp) && !stricmp (S, GOTOEPISODE) && !Stop)                                               /* Found '-EPISODE' */
  2825.           {
  2826.             fscanf (Fp, "%s", S);                                                            /* '-EPISODE' takes a parameter: 1-3 */
  2827.             if (feof (Fp) || strlen (S) != 1 || S[0] < '1' || S[0] > '3')
  2828.               Stop = TRUE;
  2829.             else
  2830.             {
  2831.               EpisodeActive = S[0] - '0';
  2832.               Handled = TRUE;
  2833.               fscanf (Fp, "%s", S);
  2834.             }
  2835.           }
  2836.           if (!feof (Fp) && !stricmp (S, INCFILE) && !Stop)                                                      /* Found '-FILE' */
  2837.           {
  2838.             fscanf (Fp, "%s", S);                                                /* Read-ahead first filename (at least 1 needed) */
  2839.             do                                                                    /* Each following word is a filename, until the */
  2840.             {                                                                      /* next keyword is found or EOF is encountered */
  2841.               if (!feof (Fp) && !Stop)
  2842.               {
  2843.                 DriveNum = DoomDrive;                                                         /* Assume: not preceded by a drive: */
  2844.                 if (S[1] == ':')                                                                            /* Preceded by drive: */
  2845.                   if (toupper (S[0]) < 'A' || toupper (S[0]) > 'Z')
  2846.                     Stop = TRUE;
  2847.                   else
  2848.                   {
  2849.                     DriveNum = ToNumber (S[0]);
  2850.                     for (M = 2 ; M <= strlen (S) ; M ++)                                                             /* Cut drive */
  2851.                       S[M - 2] = S[M];
  2852.                   }
  2853.                 if (!Stop)
  2854.                   if (stricmp (S + strlen (S) - 4, ".WAD"))                                      /* Filename MUST end with '.WAD' */
  2855.                     Stop = TRUE;
  2856.                 if (!Stop)
  2857.                 {
  2858.                   S[strlen (S) - 4] = '\0';                                                   /* Cut the '.WAD' from the filename */
  2859.                   M = strlen (S);
  2860.                   if (!M || S[M - 1] == '\\')                                           /* Ended with a '\' or no filename at all */
  2861.                     Stop = TRUE;
  2862.                   else
  2863.                   {
  2864.                     while (S[-- M] != '\\' && M >= 0)
  2865.                       ;
  2866.                     if (M >= 0)                                                                               /* Preceded by path */
  2867.                     {
  2868.                       if (M == 0)
  2869.                         strcpy (Directory, "\\");                                                      /* Handle root differently */
  2870.                       else
  2871.                       {
  2872.                         strncpy (Directory, strupr (S), M);
  2873.                         Directory[M] = '\0';
  2874.                         if (DriveNum == DoomDrive && Directory[0] != '\\')
  2875.                         {
  2876.                           sprintf (Tmp, "%s\\%s", DoomDirectory, Directory);
  2877.                           strcpy (Directory, Tmp);
  2878.                         }
  2879.                       }
  2880.                       strcpy (FileName, strupr (S) + M + 1);
  2881.                     }
  2882.                     else                                                                                               /* No path */
  2883.                     {
  2884.                       strcpy (FileName, strupr (S));
  2885.                       if (DriveNum == DoomDrive)
  2886.                         strcpy (Directory, DoomDirectory);
  2887.                       else
  2888.                         strcpy (Directory, DEFAULTWADDIR);
  2889.                     }
  2890.                     if (strlen (FileName) > 8)                                        /* Filename contains more than 8 characters */
  2891.                       Stop = TRUE;
  2892.                     else
  2893.                     {
  2894.                       for (M = strlen (FileName) ; M < 8 ; M ++)                             /* Fill out filename to 8 characters */
  2895.                         FileName[M] = ' ';
  2896.                       FileName[M] = '\0';
  2897.                       Handled = FALSE;
  2898.                       for (M = 0 ; M < TotalWads && !Handled; M ++)                  /* Match against all WAD filenames in memory */
  2899.                         if (WadInfo[M]->Drive == DriveNum)
  2900.                           if (!strcmp (WadInfo[M]->Path, Directory))
  2901.                             if (!strcmp (WadInfo[M]->Name, FileName))
  2902.                             {
  2903.                               Handled = TRUE;
  2904.                               WadInfo[M]->Selected = TRUE;                            /* If it matches, than auto-select the file */
  2905.                             }
  2906.                       fscanf (Fp, "%s", S);                                                                          /* Read next */
  2907.                     }
  2908.                   }
  2909.                 }
  2910.               }
  2911.             }
  2912.             while (!feof (Fp) && S[0] != '-' && !Stop);
  2913.             Handled = TRUE;
  2914.           }
  2915.           if (!Handled && !feof (Fp) && !Stop)
  2916.             fscanf (Fp, "%s", S);                                                                           /* Other switch: skip */
  2917.         }
  2918.       }
  2919.       fclose (Fp);
  2920.       if (DoomVersion < 5)                               /* Reset all functions that have been read, but are for a higher version */
  2921.       {
  2922.         FastMonstersOn = FALSE;
  2923.         DeathmatchV2On = FALSE;
  2924.       }
  2925.       if (DoomVersion < 2)
  2926.       {
  2927.         DeathmatchOn = FALSE;
  2928.         RespMonstersOn = FALSE;
  2929.         NoMonstersOn = FALSE;
  2930.         CommPortActive = DEFAULTCOMPORT;
  2931.         if (DifficultyActive == 5)
  2932.           DifficultyActive = DEFAULTDIFFICULTY;
  2933.         if (PlayTypeActive == 3 && DoomVersion < 2)
  2934.           PlayTypeActive = DEFAULTPLAYTYPE;
  2935.         if (PlayTypeActive == 2 && DoomVersion < 1)
  2936.           PlayTypeActive = DEFAULTPLAYTYPE;
  2937.       }
  2938.       if (DeathmatchOn && DeathmatchV2On)                                          /* -DEATHMATCH -ALTDEATH means deathmatch v2.0 */
  2939.         DeathmatchOn = FALSE;
  2940.       if (NoMonstersOn)                                                                              /* Handle contradictionaries */
  2941.       {
  2942.         RespMonstersOn = FALSE;
  2943.         FastMonstersOn = FALSE;
  2944.       }
  2945.       PrintEpisodes (0);                                                                 /* Redraw the screen with the read items */
  2946.       PrintLevel (FALSE);
  2947.       PrintDifficulties (0);
  2948.       PrintPlayTypes (0);
  2949.       PrintDeathmatch (FALSE);
  2950.       PrintV2Deathmatch (FALSE);
  2951.       PrintNoMonsters (FALSE);
  2952.       PrintRespawnMonsters (FALSE);
  2953.       PrintFastMonsters (FALSE);
  2954.       PrintWadFiles ();
  2955.     }
  2956.   }
  2957.   ShowMouse ();
  2958. }
  2959.  
  2960. void HandleAutomatic (boolean KeyInput)
  2961.  
  2962. /**********************************************************************************************************************************/
  2963. /* Pre   : 'KeyInput' is TRUE if this routine was called because of a keypress.                                                   */
  2964. /* Post  : The mouse pointer was at the automatic item. This item has been highlited. If the mouse button was pressed, then this  */
  2965. /*         routine reads all selected WAD files and initializes the current episode and level to the lowest ones found.           */
  2966. /* Import: HideMouse, ShowMouse, PrintAutomatic, PrintEpisodes, PrintLevel, UnselectPreviousField.                                */
  2967. /**********************************************************************************************************************************/
  2968.  
  2969. {
  2970.   long  Startpoint;
  2971.   long  LevelMask;
  2972.  
  2973.   HideMouse ();
  2974.   if (!KeyInput)
  2975.     UnselectPreviousField (AUTOMATICFIELD);
  2976.   if (!KeyInput)
  2977.   {
  2978.     PrintAutomatic (TRUE);
  2979.     CurrentField = AUTOMATICFIELD;
  2980.   }
  2981.   ShowMouse ();
  2982.   if ((Mouse.Left && !Mouse.LeftStillPressed) || KeyInput)
  2983.   {
  2984.     Startpoint = 0x00000000;
  2985.     for (M = 0 ; M < TotalWads ; M ++)
  2986.       if (WadInfo[M]->Selected)                                       /* Now merge all level information of all selcted WAD files */
  2987.       {
  2988.         GetWadInfo (M, TRUE);
  2989.         Startpoint |= WadInfo[M]->NewLevels;
  2990.       }
  2991.     if (Startpoint != 0x00000000)                                                          /* Selected files contain new levels ? */
  2992.     {
  2993.       CurrentLevel = 0;
  2994.       EpisodeActive = 1;
  2995.       LevelMask = 0x00000001;
  2996.       while ((Startpoint & LevelMask) != LevelMask)                                    /* Search for the lowest episode and level */
  2997.       {
  2998.         LevelMask *= 2;                                                                                             /* Shift left */
  2999.         if (++ CurrentLevel == NUMLEVEL)
  3000.         {
  3001.           CurrentLevel = 0;
  3002.           EpisodeActive ++;
  3003.         }
  3004.       }
  3005.       if (++ CurrentLevel == NUMLEVEL)                                                                 /* First level is 1, not 0 */
  3006.       {
  3007.         CurrentLevel = 1;
  3008.         EpisodeActive ++;
  3009.       }
  3010.     }
  3011.     else                                                                                                /* No levels in the files */
  3012.     {
  3013.       CurrentLevel = 1;
  3014.       EpisodeActive = 1;
  3015.     }
  3016.     PrintEpisodes (0);                                                                  /* Redraw the screen with the new results */
  3017.     PrintLevel (0);
  3018.   }
  3019. }
  3020.  
  3021. boolean HandleStartGame (boolean KeyInput)
  3022.  
  3023. /**********************************************************************************************************************************/
  3024. /* Pre   : 'KeyInput' is TRUE if this routine was called because of a keypress.                                                   */
  3025. /* Post  : The mouse pointer was at the startgame item. This item has been highlited. If the mouse button was pressed, then this  */
  3026. /*         routine returns FALSE (which effectively means: start the game), otherwise TRUE.                                       */
  3027. /* Import: HideMouse, ShowMouse, PrintStart, UnselectPreviousField.                                                               */
  3028. /**********************************************************************************************************************************/
  3029.  
  3030. {
  3031.   HideMouse ();
  3032.   UnselectPreviousField (STARTFIELD);
  3033.   PrintStart (TRUE);
  3034.   CurrentField = STARTFIELD;
  3035.   ShowMouse ();
  3036.   return ((!Mouse.Left || Mouse.LeftStillPressed) && !KeyInput);
  3037. }
  3038.  
  3039. int main (int argc, char *argv[])
  3040.  
  3041. /**********************************************************************************************************************************/
  3042. /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> MAIN ROUTINE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
  3043. /* Import: ResetMouse, ReadConfig, PrintEpisodes, PrintDifficulties, PrintPlayTypes, PrintDeathmatch, PrintLevel, PrintWadFiles,  */
  3044. /*         PrintPagers, ShowMouse, MouseStatus, HandleEpisode, HandleDifficulty, HandleDeathmatch, HandleLevel, HandleNextPage,   */
  3045. /*         HandlePreviousPage, HideMouse, DeAllocateAll, PrintStart, PrintRdPrev, HandleStartGame, HandleReadPrev, GetWadInfo,    */
  3046. /*         WriteWadInfo, PrintAutomatic, HandleAutomatic, HandlePlayType, UnselectPreviousField, InitVideo, PrintV2Deathmatch,    */
  3047. /*         PrintRespawnMonsters, PrintNoMonsters, PrintFastMonsters, HandleV2Deathmatch, HandleRespawnMonsters, HandleNoMonsters, */
  3048. /*         HandleFastMonsters, SortFiles, RescanFiles, ToggleFileSort, Bye, PrText.                                               */
  3049. /**********************************************************************************************************************************/
  3050.  
  3051. {
  3052.   FILE    *Fp;
  3053.   struct   find_t      FileBlock;
  3054.   struct   WadInfo_s   ReadInfo;                                                            /* Entry as read from the WADINFOFILE */
  3055.   char     DrivePath[_MAX_DIR];                                                                   /* Current directory of a drive */
  3056.   char     NextArgument;                                                                   /* Argument number on the command line */
  3057.   char     Ch;
  3058.   char     SepChar;                                                                    /* Seperation char in START.*; '\n' or ' ' */
  3059.   boolean  SepCharNeeded;
  3060.   boolean  More;
  3061.   boolean  FirstWad;                                                                  /* First WAD file to include in START.BAT ? */
  3062.   boolean  AutoFound;                                                                  /* Files given as AUTOINCLUDE paremeters ? */
  3063.   boolean  DriveChanged;                                                          /* Handling other drive than the 'home' drive ? */
  3064.   boolean  CLineError  = FALSE;                                                                 /* Nonsense on the command line ? */
  3065.   boolean  DevparmDone = FALSE;                                                 /* TRUE if DEVPARM has been included in START.BAT */
  3066.   unsigned int Key;
  3067.  
  3068.   free (getcwd (CurPath, _MAX_DIR - 1));                                                             /* Collect current directory */
  3069.   CurDrive = ToNumber (CurPath[0]);                                                                       /* Derive current drive */
  3070.   UseMouse = ResetMouse ();                                                                       /* Force mouse to re-initialize */
  3071.   strcpy (ConfigFile, DEFAULTCONFIGFILE);
  3072.   NextArgument = 0;                                                                              /* Handle command line arguments */
  3073.   if (argc > 3)                                                                                 /* (Max number of arguments is 2) */
  3074.     CLineError = TRUE;
  3075.   while (++ NextArgument < argc)
  3076.     if (!stricmp (argv[NextArgument], RESCAN1) || !stricmp (argv[NextArgument], RESCAN2))              /* Handle any -r parameter */
  3077.       Rescan = TRUE;
  3078.     else
  3079.       if (argv[NextArgument][0] == OTHERCONFIGFILE)                                                 /* Handle any +file parameter */
  3080.       {
  3081.         strcpy (ConfigFile, argv[NextArgument] + 1);
  3082.         ConfigChange = TRUE;
  3083.       }
  3084.       else
  3085.         CLineError = TRUE;
  3086.   if (CLineError)
  3087.     Bye (RETURNERROR, "Usage: EASYWAD [%s] [%cconfig]\n", RESCAN1, OTHERCONFIGFILE);
  3088.   ReadConfig ();                                                                                 /* Find CONFIGFILE and handle it */
  3089.   if (!(Fp = fopen (InfoFile, "r")))                                                               /* Test if the InfoFile exists */
  3090.     Rescan = TRUE;                                                                                    /* No, it should be created */
  3091.   else
  3092.     fclose (Fp);
  3093.   TotalWads = 0;
  3094.   if (Rescan)
  3095.     DoNotSearch = FALSE;                                                 /* Override if there is no infofile or if '-R' was given */
  3096.   _dos_setdrive (CurDrive, &Dummy);                                             /* Start from 'home' location (for partial paths) */
  3097.   chdir (CurPath);
  3098.   if (!DoNotSearch)                                                                            /* Search all WADDIR directories ? */
  3099.   {
  3100.     printf ("Searching for WAD files ... ");
  3101.     for (N = 0 ; N < TotalWadDirs ; N ++)                                                         /* Handle all given directories */
  3102.     {
  3103.       DriveChanged = FALSE;
  3104.       if (WadDir[N]->Drive)                                                                      /* Change drive if one was given */
  3105.       {
  3106.         _dos_setdrive (WadDir[N]->Drive, &Dummy);
  3107.         _dos_getdrive (&Dummy);
  3108.         if (Dummy != WadDir[N]->Drive)                                /* Check that the change has been made and report any error */
  3109.           Bye (RETURNERROR, "ERROR - Drive of WADDIR does not exist\n");
  3110.         DriveChanged = TRUE;
  3111.       }
  3112.       free (getcwd (DrivePath, _MAX_DIR - 1));                                         /* Collect current directory of this drive */
  3113.       if (strcmp (WadDir[N]->Name, DEFAULTWADDIR))                                   /* Change directory if the entry was not "." */
  3114.         if (chdir (WadDir[N]->Name))                                          /* Report the error if the directory does not exist */
  3115.           Bye (RETURNERROR, "ERROR - Directory of WADDIR does not exist\n");
  3116.       More = !_dos_findfirst (WADFILE, ANYATTR, &FileBlock);                                         /* Look-ahead for a WAD file */
  3117.       while (TotalWads < MAXWADS && More)                                               /* Handle all WAD files in this directory */
  3118.       {
  3119.         if ((strcmp (WadDir[N]->Name, DEFAULTWADDIR)
  3120.             || (strcmp (FileBlock.name, MAINWAD1) && strcmp (FileBlock.name, MAINWAD2)))
  3121.             && FileBlock.size >= sizeof (struct WadHeader_s))                    /* Exclude the main DOOM WAD and too small files */
  3122.         {
  3123.           if ((WadInfo[TotalWads] = ((struct WadInfo_s far *)_fmalloc ((size_t)sizeof (struct WadInfo_s)))) == NOMEM)
  3124.             Bye (RETURNERROR, "FATAL ERROR - Out of memory\n");
  3125.           strcpy (WadInfo[TotalWads]->OrigName, FileBlock.name);                                                 /* Copy filename */
  3126.           strncpy (WadInfo[TotalWads]->Name, FileBlock.name, strlen (FileBlock.name) - 4);        /* Copy name, without extension */
  3127.           for (M = strlen (FileBlock.name) - 4 ; M < 8 ; M ++)                                        /* Fill out to 8 characters */
  3128.             WadInfo[TotalWads]->Name[M] = ' ';
  3129.           WadInfo[TotalWads]->Name[M] = '\0';                                                           /* Make it a valid string */
  3130.           WadInfo[TotalWads]->Drive = WadDir[N]->Drive;
  3131.           strcpy (WadInfo[TotalWads]->Path, WadDir[N]->Name);
  3132.           for (M = 0 ; M < MAXINFOLEN ; M ++)
  3133.             WadInfo[TotalWads]->Info[M] = ' ';                                                     /* Initialize the other fields */
  3134.           WadInfo[TotalWads]->Info[M] = '\0';
  3135.           WadInfo[TotalWads]->Selected = FALSE;
  3136.           if (Rescan)
  3137.             GetWadInfo (TotalWads, FALSE);                                                          /* Read out the WAD directory */
  3138.           TotalWads ++;
  3139.         }
  3140.         More = !_dos_findnext (&FileBlock);
  3141.       }
  3142.       if (WadDir[N]->DoSubDirs)
  3143.       {
  3144.         More = !_dos_findfirst ("*.*", SUBATTR, &FileBlock);                                           /* Look for subdirectories */
  3145.         while (More)
  3146.         {
  3147.           while ((!(FileBlock.attrib & _A_SUBDIR) || (FileBlock.name[0] == '.')) && More)                      /* Not '.' or '..' */
  3148.             More = !_dos_findnext (&FileBlock);
  3149.           if (More)
  3150.           {
  3151.             if (TotalWadDirs == MAXWADDIRS)
  3152.               Bye (RETURNERROR, "ERROR - Too many WADDIR entries, max is %d\n", MAXWADDIRS);
  3153.             if ((WadDir[TotalWadDirs] = ((struct WadDir_s far *)_fmalloc ((size_t)sizeof (struct WadDir_s)))) == NOMEM)
  3154.               Bye (RETURNERROR, "FATAL ERROR - Out of memory\n");
  3155.             WadDir[TotalWadDirs]->Drive = WadDir[N]->Drive;                              /* Add this directory to the WADDIR list */
  3156.             sprintf (WadDir[TotalWadDirs]->Name, "%s\\%s", WadDir[N]->Name, FileBlock.name);
  3157.             WadDir[TotalWadDirs ++]->DoSubDirs = TRUE;                                                         /* Signal: recurse */
  3158.             More = !_dos_findnext (&FileBlock);
  3159.           }
  3160.         }
  3161.       }
  3162.       chdir (DrivePath);                                                         /* Return to the current directory of this drive */
  3163.       if (DriveChanged)
  3164.         _dos_setdrive (CurDrive, &Dummy);                                                                 /* Return to home drive */
  3165.     }
  3166.   }
  3167.   _dos_setdrive (CurDrive, &Dummy);                                                                    /* Return to home location */
  3168.    chdir (CurPath);
  3169.   if (Rescan)
  3170.   {
  3171.     printf ("Writing WADINFOFILE ... ");
  3172.     WriteWadInfo (InfoFile);
  3173.   }
  3174.   if (!(Fp = fopen (InfoFile, "r")))                                            /* Now handle the InfoFile, which should be found */
  3175.     Bye (RETURNERROR, "ERROR - Drive read error\n");
  3176.   fscanf (Fp, "%s", S);                                                             /* Read-ahead: first part is the drive number */
  3177.   while (!feof (Fp))
  3178.   {
  3179.     ReadInfo.Drive = atoi (S);                                                                               /* Convert to number */
  3180.     fscanf (Fp, "%s", ReadInfo.Path);                                                             /* Second part is the directory */
  3181.     fscanf (Fp, "%s ", ReadInfo.OrigName);                                                         /* Third part is the  filename */
  3182.     More = TRUE;
  3183.     for (M = 0 ; M < MAXINFOLEN && More ; M ++)                                   /* Last part is the info. It may contain spaces */
  3184.     {
  3185.       fscanf (Fp, "%c", &ReadInfo.Info[M]);
  3186.       if (ReadInfo.Info[M] == '\n')                                                              /* String shorter than maximum ? */
  3187.         More = FALSE;
  3188.     }
  3189.     while (More)                                                                                     /* End of line not yet found */
  3190.     {
  3191.       fscanf (Fp, "%c", &Ch);
  3192.       if (Ch == '\n')                                                                                /* Read rest of the line out */
  3193.         More = FALSE;
  3194.     }
  3195.     ReadInfo.Info[M] = '\0';
  3196.     ConvertFullName (&ReadInfo);                                                          /* Convert full to short name if wanted */
  3197.     if (DoNotSearch)
  3198.     {
  3199.       if ((WadInfo[TotalWads] = ((struct WadInfo_s far *)_fmalloc ((size_t)sizeof (struct WadInfo_s)))) == NOMEM)
  3200.         Bye (RETURNERROR, "FATAL ERROR - Out of memory\n");
  3201.       strcpy (WadInfo[TotalWads]->OrigName, ReadInfo.OrigName);                                                  /* Copy filename */
  3202.       strncpy (WadInfo[TotalWads]->Name, ReadInfo.OrigName, strlen (ReadInfo.OrigName) - 4);      /* Copy name, without extension */
  3203.       for (M = strlen (ReadInfo.OrigName) - 4 ; M < 8 ; M ++)                                         /* Fill out to 8 characters */
  3204.         WadInfo[TotalWads]->Name[M] = ' ';
  3205.       WadInfo[TotalWads]->Name[M] = '\0';
  3206.       WadInfo[TotalWads]->Drive = ReadInfo.Drive;
  3207.       strcpy (WadInfo[TotalWads]->Path, ReadInfo.Path);
  3208.       strcpy (WadInfo[TotalWads]->Info, ReadInfo.Info);
  3209.       WadInfo[TotalWads]->Selected = FALSE;
  3210.       TotalWads ++;
  3211.     }
  3212.     else
  3213.     {
  3214.       More = TRUE;
  3215.       for (M = 0 ; M < TotalWads && More; M ++)                                          /* Match against all read WAD file names */
  3216.         if (WadInfo[M]->Drive == ReadInfo.Drive)
  3217.           if (!stricmp (WadInfo[M]->Path, ReadInfo.Path))
  3218.             if (!stricmp (WadInfo[M]->OrigName, ReadInfo.OrigName))
  3219.             {
  3220.               More = FALSE;
  3221.               strcpy (WadInfo[M]->Info, ReadInfo.Info);                                    /* Copy info field to correct WAD file */
  3222.             }
  3223.     }
  3224.     fscanf (Fp, "%s", S);
  3225.   }
  3226.   fclose (Fp);
  3227.   if (TotalWads == 0)                              /* Abort the program if no WAD files were found (other than the main DOOM WAD) */
  3228.   {
  3229.     remove (InfoFile);
  3230.     Bye (RETURNERROR, "No WAD files found!\n");
  3231.   }
  3232.   SortFiles ();                                                                       /* Sort the WAD files if that was requested */
  3233.   N = -1;
  3234.   while (++ N < TotalAutoInc)                                                                   /* Handle all AUTOINCLUDE entries */
  3235.   {
  3236.     AutoFound = FALSE;
  3237.     for (M = 0 ; M < TotalWads && !AutoFound ; M ++)                                         /* AUTOINCLUDE file ? Then select it */
  3238.       if ((WadInfo[M]->Drive == AutoInc[N]->Drive)
  3239.            && (!strcmp (WadInfo[M]->Path, AutoInc[N]->Path))
  3240.            && (!strcmp (WadInfo[M]->OrigName, AutoInc[N]->OrigName)))
  3241.       {
  3242.         WadInfo[M]->Selected = TRUE;
  3243.         AutoFound = TRUE;
  3244.       }
  3245.   }
  3246.   CurrentPage = 0;
  3247.   LastPage = TotalWads / PAGE;
  3248.  
  3249.   InitVideo ();                                                /* Open a VGA screen of 640x480x16 (80x30 characters in text mode) */
  3250.   ScreenOpen = TRUE;                                                                                  /* Signal: in graphics mode */
  3251.   PrText (-1, 1, 1, LWHITE, "DOOM EasyWAD v1.11 - (C) 1994 ThunderWare Research Center");                      /* Draw the screen */
  3252.   PrText (-1, 1, 72, DWHITE, "F1 = HELP");
  3253.   PrText (-1, 11, 64, LWHITE, "PAGE  1 OF %2d", LastPage + 1);
  3254.   PrintEpisodes (0);
  3255.   PrintDifficulties (0);
  3256.   PrintPlayTypes (0);
  3257.   PrintLevel (FALSE);
  3258.   PrintDeathmatch (FALSE);
  3259.   PrintV2Deathmatch (FALSE);
  3260.   PrintRespawnMonsters (FALSE);
  3261.   PrintNoMonsters (FALSE);
  3262.   PrintFastMonsters (FALSE);
  3263.   PrintWadFiles ();
  3264.   PrintPagers (0);
  3265.   PrintRdPrev (FALSE);
  3266.   PrintAutomatic (FALSE);
  3267.   PrintStart (FALSE);
  3268.  
  3269.   if (UseMouse)
  3270.   {
  3271.     ShowMouse ();                                                                                       /* Show the mouse pointer */
  3272.     MouseStatus ();                                                                                   /* Get current mouse status */
  3273.     Mouse.OldXx = Mouse.Xx;                                                                 /* Initialize all non-hardware fields */
  3274.     Mouse.OldYy = Mouse.Yy;
  3275.     Mouse.CoChange = TRUE;
  3276.     Mouse.LeftStillPressed = FALSE;
  3277.     CurrentField = NOFIELD;                                                                  /* Signal: check FIELD type directly */
  3278.   }
  3279.   else
  3280.   {
  3281.     CurrentField = FILEFIELD;                                                        /* Hi-lighting is only done in the FILEFIELD */
  3282.     PreviousWad = 1;
  3283.     PrText (-1, 13, 1, LRED, WadInfo[0]->Name);                                                    /* Hi-light the first WAD file */
  3284.   }
  3285.   More = TRUE;
  3286.   while (More)                                                                               /* Or: while not [START] pressed ... */
  3287.   {
  3288.     if (_bios_keybrd (_KEYBRD_READY))                                                                            /* Key pressed ? */
  3289.     {
  3290.       Key = _bios_keybrd (_KEYBRD_READ);                                                                          /* Read the key */
  3291.       if ((Key & 0xFF00) == KEY_PAGEDOWN)
  3292.         HandlePreviousPage (TRUE);
  3293.       else
  3294.         if ((Key & 0xFF00) == KEY_PAGEUP)
  3295.           HandleNextPage (TRUE);
  3296.         else
  3297.           if (!UseMouse                                                                       /* Only available if no mouse found */
  3298.               && ((Key & 0xFF00) == KEY_CURSLEFT
  3299.                || (Key & 0xFF00) == KEY_CURSRIGHT
  3300.                || (Key & 0xFF00) == KEY_CURSUP
  3301.                || (Key & 0xFF00) == KEY_CURSDOWN
  3302.                || (Key & 0xFF00) == KEY_SELECTFILE))
  3303.             HandleFile (Key & 0xFF00);
  3304.           else
  3305.             if ((Key & 0xFF00) == KEY_DELETEWAD)
  3306.               DeleteWadFile ();
  3307.             else
  3308.               if ((Key & 0xFF00) == KEY_TOGGLESORT)
  3309.                 ToggleFileSort ();
  3310.               else
  3311.                 if ((Key & 0xFF00) == KEY_RESCAN)
  3312.                   RescanFiles ();
  3313.                 else
  3314.                   if ((Key & 0xFF00) == KEY_HELP)
  3315.                     GiveHelp ();
  3316.                   else
  3317.                     if ((Key & 0xFF00) == KEY_TOGGLEFULL)
  3318.                       ToggleFullName ();
  3319.                     else
  3320.                       switch (toupper ((char)(Key & 0x00FF)))
  3321.                       {
  3322.                         case KEY_ABORT        : Bye (RETURNABORT, "Program aborted - Thank you for using DOOM EasyWAD\n");
  3323.                         case KEY_STARTGAME    : More = HandleStartGame (TRUE);
  3324.                                                 break;
  3325.                         case KEY_EPISODE      : HandleEpisode (TRUE);
  3326.                                                 break;
  3327.                         case KEY_DIFFICULTY   : HandleDifficulty (TRUE);
  3328.                                                 break;
  3329.                         case KEY_LEVEL        : HandleLevel (TRUE);
  3330.                                                 break;
  3331.                         case KEY_DEATHMATCH   : HandleDeathmatch (TRUE);
  3332.                                                 break;
  3333.                         case KEY_DEATHMATCHV2 : HandleV2Deathmatch (TRUE);
  3334.                                                 break;
  3335.                         case KEY_NOMONSTERS   : HandleNoMonsters (TRUE);
  3336.                                                 break;
  3337.                         case KEY_RESPAWNMONST : HandleRespawnMonsters (TRUE);
  3338.                                                 break;
  3339.                         case KEY_FASTMONSTERS : HandleFastMonsters (TRUE);
  3340.                                                 break;
  3341.                         case KEY_NODES        :
  3342.                         case KEY_COMPORT      :
  3343.                         case KEY_PLAYTYPE     : HandlePlayType (TRUE, toupper ((char)(Key & 0x00FF)));
  3344.                                                 break;
  3345.                         case KEY_AUTO         : HandleAutomatic (TRUE);
  3346.                                                 break;
  3347.                         case KEY_READPREVIOUS : HandleReadPrev (TRUE);
  3348.                       }
  3349.     }
  3350.     if (UseMouse && (Mouse.CoChange || Mouse.Left))                                        /* Mouse moved or left buttonpressed ? */
  3351.     {
  3352.       if (Mouse.Yy > 11)                                              /* Find out which FIELD is pointed to and handle that field */
  3353.         HandleFile (0x0000);                                                                                    /* Signal: no key */
  3354.       else
  3355.         if (Mouse.Yy > 1 && Mouse.Yy < 5 && Mouse.Xx < 25)
  3356.           HandleEpisode (FALSE);
  3357.         else
  3358.           if (Mouse.Yy > 1 && Mouse.Yy < ((DoomVersion >= 2) ? 7 : 6) && Mouse.Xx > 26 && Mouse.Xx < 51)
  3359.             HandleDifficulty (FALSE);
  3360.           else
  3361.             if (Mouse.Yy > 1 && Mouse.Yy < 6 && Mouse.Xx > 53)
  3362.               HandlePlayType (FALSE, 0x00);
  3363.             else
  3364.               if (Mouse.Yy == 7 && Mouse.Xx > 53)
  3365.                 HandleDeathmatch (FALSE);
  3366.               else
  3367.                 if (Mouse.Yy == 8 && Mouse.Xx > 53)
  3368.                   HandleV2Deathmatch (FALSE);
  3369.                 else
  3370.                   if (Mouse.Yy == 8 && Mouse.Xx > 26 && Mouse.Xx < 51)
  3371.                     HandleNoMonsters (FALSE);
  3372.                   else
  3373.                     if (Mouse.Yy == 9 && Mouse.Xx > 26 && Mouse.Xx < 51)
  3374.                       HandleRespawnMonsters (FALSE);
  3375.                     else
  3376.                       if (Mouse.Yy == 10 && Mouse.Xx > 26 && Mouse.Xx < 51)
  3377.                         HandleFastMonsters (FALSE);
  3378.                       else
  3379.                         if (Mouse.Yy == 6 && Mouse.Xx < 25)
  3380.                           HandleLevel (FALSE);
  3381.                         else
  3382.                           if (Mouse.Yy == 10 && Mouse.Xx > 76)
  3383.                             HandleNextPage (FALSE);
  3384.                           else
  3385.                             if (Mouse.Yy == 10 && Mouse.Xx > 58 && Mouse.Xx < 62)
  3386.                               HandlePreviousPage (FALSE);
  3387.                             else
  3388.                               if (Mouse.Yy == 8 && Mouse.Xx < 15)
  3389.                                 More = HandleStartGame (FALSE);
  3390.                               else
  3391.                                 if (Mouse.Yy == 9 && Mouse.Xx < 15)
  3392.                                   HandleAutomatic (FALSE);
  3393.                                 else
  3394.                                   if (Mouse.Yy == 10 && Mouse.Xx < 15)
  3395.                                     HandleReadPrev (FALSE);
  3396.                                   else
  3397.                                     if (CurrentField != NOFIELD)                                       /* No FIELD was pointed to */
  3398.                                     {                        /* If previously a FIELD WAS pointed to, then un-highlite that field */
  3399.                                       HideMouse ();
  3400.                                       UnselectPreviousField (NOFIELD);
  3401.                                       ShowMouse ();
  3402.                                       CurrentField = NOFIELD;
  3403.                                     }
  3404.       Mouse.OldXx = Mouse.Xx;
  3405.       Mouse.OldYy = Mouse.Yy;
  3406.     }
  3407.     if (UseMouse)
  3408.     {
  3409.       MouseStatus ();
  3410.       if (Mouse.Right)
  3411.       {
  3412.         HideMouse ();
  3413.         Bye (RETURNABORT, "Program aborted - Thank you for using DOOM EasyWAD\n");
  3414.       }
  3415.     }
  3416.   }
  3417.   HideMouse ();
  3418.   _setvideomode (_DEFAULTMODE);                                                                               /* Close the screen */
  3419.   ScreenOpen = FALSE;                                                                                   /* Signal: in normal mode */
  3420.   
  3421.   if (!(Fp = fopen (BATFILE, "w")))                                                                           /* Open "START.BAT" */
  3422.     Bye (RETURNERROR, "ERROR - Cannot create file, disk full ?\n");
  3423.   fprintf (Fp, "@ECHO OFF\n");
  3424.   if (DoomDrive)
  3425.     fprintf (Fp, "%c:\n", ToName (DoomDrive));
  3426.   if (strcmp (DoomDirectory, DEFAULTWADDIR))
  3427.     fprintf (Fp, "CD %s\n", DoomDirectory);
  3428.   if (!NoAutoReturn)
  3429.     fprintf (Fp, "ECHO.| ");
  3430.   switch (PlayTypeActive)                                                                /* Print the correct command to the file */
  3431.   {
  3432.     case 1 : fprintf (Fp, "%s", STARTALONE);
  3433.              break;
  3434.     case 2 : fprintf (Fp, "%s", IpxDriver);
  3435.              break;
  3436.     case 3 : fprintf (Fp, "%s", SerDriver);
  3437.   }
  3438.   if (DoomVersion >= 5)
  3439.   {
  3440.     fprintf (Fp, " @%s\\%s\n", CurPath, RESPONSEFILE);                                   /* CurPath also contains the drive: part */
  3441.     if (DoomDrive)
  3442.       fprintf (Fp, "%c:\n", ToName (CurDrive));
  3443.     if (strcmp (DoomDirectory, DEFAULTWADDIR))
  3444.       fprintf (Fp, "CD %s\n", CurPath + 2);
  3445.     fclose (Fp);
  3446.     if (!(Fp = fopen (RESPONSEFILE, "w")))                                                                    /* Open "START.OPT" */
  3447.       Bye (RETURNERROR, "ERROR - Cannot create file, disk full ?\n");
  3448.     SepChar = '\n';
  3449.   }
  3450.   else
  3451.   {
  3452.     SepChar = ' ';
  3453.     if (PlayTypeActive != 1)
  3454.       fprintf (Fp, " ");
  3455.   }
  3456.   SepCharNeeded = TRUE;
  3457.   switch (PlayTypeActive)
  3458.   {
  3459.     case 1 : if (DoomVersion >= 5)
  3460.                SepCharNeeded = FALSE;
  3461.              break;
  3462.     case 2 : if (!OtherIpxDriver)
  3463.                fprintf (Fp, "%s%c%d%c%d", NUMPLAYERS, SepChar, NumNodesActive, SepChar, NetworkSocket);
  3464.              break;
  3465.     case 3 : if (!OtherSerDriver)
  3466.                fprintf (Fp, "%s%d", COMPORT, CommPortActive);
  3467.   }
  3468.   if (DifficultyActive != DEFAULTDIFFICULTY)                                                            /* Different difficulty ? */
  3469.   {
  3470.     if (SepCharNeeded)
  3471.       fprintf (Fp, "%c", SepChar);
  3472.     SepCharNeeded = TRUE;
  3473.     fprintf (Fp, "%s%c%d", SKILL, SepChar, DifficultyActive);                                                      /* Then add it */
  3474.   }
  3475.   if (DeathmatchOn != DEFAULTDMATCH)                                                     /* DEATHMATCH wanted (and implemented) ? */
  3476.   {
  3477.     if (SepCharNeeded)
  3478.       fprintf (Fp, "%c", SepChar);
  3479.     SepCharNeeded = TRUE;
  3480.     fprintf (Fp, "%s", DMATCH);
  3481.   }
  3482.   if (DeathmatchV2On != DEFAULTDMATCHV2)                                                              /* DEATHMATCH v2.0 wanted ? */
  3483.   {
  3484.     if (SepCharNeeded)
  3485.       fprintf (Fp, "%c", SepChar);
  3486.     SepCharNeeded = TRUE;
  3487.     fprintf (Fp, "%s%c%s", DMATCH, SepChar, DMATCHV2);
  3488.   }
  3489.   if (NoMonstersOn != DEFAULTNOMONSTERS)                                                                   /* NOMONSTERS wanted ? */
  3490.   {
  3491.     if (SepCharNeeded)
  3492.       fprintf (Fp, "%c", SepChar);
  3493.     if (!DevparmDone)
  3494.     {
  3495.       fprintf (Fp, "%s%c", DEVPARM, SepChar);
  3496.       DevparmDone = TRUE;
  3497.     }
  3498.     SepCharNeeded = TRUE;
  3499.     fprintf (Fp, "%s", NOMONSTERS);
  3500.   }
  3501.   if (RespMonstersOn != DEFAULTRESPAWN)                                                                       /* RESPAWN wanted ? */
  3502.   {
  3503.     if (SepCharNeeded)
  3504.       fprintf (Fp, "%c", SepChar);
  3505.     if (!DevparmDone)
  3506.     {
  3507.       fprintf (Fp, "%s%c", DEVPARM, SepChar);
  3508.       DevparmDone = TRUE;
  3509.     }
  3510.     SepCharNeeded = TRUE;
  3511.     fprintf (Fp, "%s", RESPAWNMONSTERS);
  3512.   }
  3513.   if (FastMonstersOn != DEFAULTFASTMONST)                                                                /* FASTMONSTERS wanted ? */
  3514.   {
  3515.     if (SepCharNeeded)
  3516.       fprintf (Fp, "%c", SepChar);
  3517.     if (!DevparmDone)
  3518.     {
  3519.       fprintf (Fp, "%s%c", DEVPARM, SepChar);
  3520.       DevparmDone = TRUE;
  3521.     }
  3522.     SepCharNeeded = TRUE;
  3523.     fprintf (Fp, "%s", FASTMONSTERS);
  3524.   }
  3525.   if (CurrentLevel != DEFAULTLEVEL)                                                                 /* Different starting level ? */
  3526.   {
  3527.     if (SepCharNeeded)
  3528.       fprintf (Fp, "%c", SepChar);
  3529.     if (!DevparmDone)
  3530.     {
  3531.       fprintf (Fp, "%s%c", DEVPARM, SepChar);
  3532.       DevparmDone = TRUE;
  3533.     }
  3534.     SepCharNeeded = TRUE;
  3535.     fprintf (Fp, "%s%c%d%c%d", GOTOANYTHING, SepChar, EpisodeActive, SepChar, CurrentLevel);
  3536.   }
  3537.   if (CurrentLevel == DEFAULTLEVEL && EpisodeActive != DEFAULTEPISODE)                     /* Other episode, but no other level ? */
  3538.   {
  3539.     if (SepCharNeeded)
  3540.       fprintf (Fp, "%c", SepChar);
  3541.     SepCharNeeded = TRUE;
  3542.     fprintf (Fp, "%s%c%d", GOTOEPISODE, SepChar, EpisodeActive);                                         /* "-DEVPARM" not needed */
  3543.   }
  3544.   for (M = 0 ; M < MAXADDSWITCHES ; M ++)                                                          /* Now add the direct switches */
  3545.     if (ExtCom[M].InUse)
  3546.     {
  3547.       if (SepCharNeeded)
  3548.         fprintf (Fp, "%c", SepChar);
  3549.       SepCharNeeded = TRUE;
  3550.       fprintf (Fp, ExtCom[M].Command);
  3551.     }
  3552.   FirstWad = TRUE;
  3553.   strcat (DoomDirectory, "\\");
  3554.   for (M = 0 ; M < TotalWads ; M ++)                                                                /* Add each selected WAD file */
  3555.     if (WadInfo[M]->Selected)
  3556.     {
  3557.       if (FirstWad)                                                                       /* Before adding the first, add "-FILE" */
  3558.       {
  3559.         FirstWad = FALSE;
  3560.         if (SepCharNeeded)
  3561.           fprintf (Fp, "%c", SepChar);
  3562.         fprintf (Fp, "%s", INCFILE);
  3563.       }
  3564.       if (WadInfo[M]->Drive && WadInfo[M]->Drive != DoomDrive)
  3565.         fprintf (Fp, "%c%c:", SepChar, ToName (WadInfo[M]->Drive));                                     /* Add the drive if found */
  3566.       else
  3567.         fprintf (Fp, "%c", SepChar);
  3568.       if (strcmp (WadInfo[M]->Path, DEFAULTWADDIR))
  3569.         if (strncmp (WadInfo[M]->Path, DoomDirectory, strlen (DoomDirectory)))                  /* Subdir of the DOOM directory ? */
  3570.           fprintf (Fp, "%s\\", WadInfo[M]->Path);                                                          /* Add the path if not */
  3571.         else
  3572.           if (WadInfo[M]->Drive == DoomDrive)                                                              /* Drive matches too ? */
  3573.             fprintf (Fp, "%s\\", WadInfo[M]->Path + strlen (DoomDirectory));                           /* Cut DOOM directory part */
  3574.           else
  3575.             fprintf (Fp, "%s\\", WadInfo[M]->Path);                                                        /* Add the path if not */
  3576.       fprintf (Fp, "%s", WadInfo[M]->OrigName);                                                               /* Add the filename */
  3577.     }
  3578.   fprintf (Fp, "\n");                                                                                          /* Add the newline */
  3579.   if (DoomVersion < 5)
  3580.   {
  3581.     if (DoomDrive)
  3582.       fprintf (Fp, "%c:\n", ToName (CurDrive));
  3583.     if (strcmp (DoomDirectory, DEFAULTWADDIR))
  3584.       fprintf (Fp, "CD %s\n", CurPath + 2);
  3585.   }
  3586.   fclose (Fp);                                                                 /* Done; free all memory and shut down the program */
  3587.   DeAllocateAll ();
  3588.   exit (RETURNSTART);
  3589. }
  3590.