home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the DOOM Programming Gurus / Tricks_of_the_Doom_Programming_Gurus.iso / bonus / utils / easywad / easywad.c next >
Encoding:
C/C++ Source or Header  |  1995-02-22  |  201.4 KB  |  3,588 lines

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