foxygit / doom Log in
commit ae18d8c4b6f7f918aa5ec496ca32899793cbe41e
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Fri Nov 21 18:03:06 2008 +0000
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Fri Nov 21 18:03:06 2008 +0000

    Move setup/ into src/ and merge with main codebase. Remove duplicated
    code. Split out I_Endoom to separate i_endoom.c file.

    Subversion-branch: /branches/raven-branch
    Subversion-revision: 1384
---
 configure.in                            |   4 +-
 setup/configfile.c                      | 599 --------------------------------
 setup/configfile.h                      |  42 ---
 src/Makefile.am                         |  45 ++-
 src/d_dedicated.c                       |  23 --
 src/doom/d_main.c                       |  11 +-
 src/heretic/d_main.c                    |  12 +-
 src/hexen/h2_main.c                     |  10 +-
 setup/m_argv.c => src/i_endoom.c        |  66 ++--
 setup/m_argv.h => src/i_endoom.h        |  21 +-
 src/i_system.c                          |  59 +---
 src/i_system.h                          |   5 -
 src/i_timer.c                           |   5 +
 src/i_timer.h                           |   3 +
 src/i_video.h                           |   3 -
 src/m_config.c                          |  25 ++
 src/m_config.h                          |   1 +
 {setup => src}/setup-res.rc.in          |   0
 {setup => src/setup}/.gitignore         |   0
 {setup => src/setup}/Makefile.am        |  29 +-
 {setup => src/setup}/compatibility.c    |   0
 {setup => src/setup}/compatibility.h    |   0
 {setup => src/setup}/display.c          |   0
 {setup => src/setup}/display.h          |   0
 {setup => src/setup}/execute.c          |   7 +-
 {setup => src/setup}/execute.h          |   0
 {setup => src/setup}/joystick.c         |   0
 {setup => src/setup}/joystick.h         |   0
 {setup => src/setup}/keyboard.c         |   0
 {setup => src/setup}/keyboard.h         |   0
 {setup => src/setup}/mainmenu.c         |  14 +-
 {setup => src/setup}/mouse.c            |   0
 {setup => src/setup}/mouse.h            |   0
 {setup => src/setup}/multiplayer.c      |   5 +-
 {setup => src/setup}/multiplayer.h      |   0
 {setup => src/setup}/setup-manifest.xml |   0
 {setup => src/setup}/setup_icon.c       |   0
 {setup => src/setup}/sound.c            |   0
 {setup => src/setup}/sound.h            |   0
 {setup => src/setup}/txt_joybinput.c    |   0
 {setup => src/setup}/txt_joybinput.h    |   0
 {setup => src/setup}/txt_keyinput.c     |   0
 {setup => src/setup}/txt_keyinput.h     |   0
 {setup => src/setup}/txt_mouseinput.c   |   0
 {setup => src/setup}/txt_mouseinput.h   |   0
 45 files changed, 161 insertions(+), 828 deletions(-)

diff --git a/configure.in b/configure.in
index 5703560e..f4b6202a 100644
--- a/configure.in
+++ b/configure.in
@@ -79,15 +79,15 @@ AC_OUTPUT([
 Makefile
 textscreen/Makefile
 textscreen/examples/Makefile
-setup/Makefile
 man/Makefile
 src/Makefile
 src/doom/Makefile
 src/heretic/Makefile
 src/hexen/Makefile
+src/setup/Makefile
 pcsound/Makefile
 src/resource.rc
+src/setup-res.rc
 src/doom-screensaver.desktop
-setup/setup-res.rc
 ])

diff --git a/setup/configfile.c b/setup/configfile.c
deleted file mode 100644
index 3f75d7f1..00000000
--- a/setup/configfile.c
+++ /dev/null
@@ -1,599 +0,0 @@
-// Emacs style mode select   -*- C++ -*-
-//-----------------------------------------------------------------------------
-//
-// Copyright(C) 1993-1996 Id Software, Inc.
-// Copyright(C) 2005 Simon Howard
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-// 02111-1307, USA.
-//
-//
-// DESCRIPTION:
-//     Configuration file load/save code.
-//
-//-----------------------------------------------------------------------------
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <string.h>
-
-// for mkdir:
-
-#ifdef _WIN32
-#include <io.h>
-#else
-#include <sys/stat.h>
-#include <sys/types.h>
-#endif
-
-#include "config.h"
-
-#include "doomfeatures.h"
-#include "doomkeys.h"
-#include "doomtype.h"
-#include "d_englsh.h"
-
-#include "m_argv.h"
-
-#include "compatibility.h"
-#include "display.h"
-#include "joystick.h"
-#include "keyboard.h"
-#include "mouse.h"
-#include "multiplayer.h"
-#include "sound.h"
-
-char *configdir;
-
-//
-// Create a directory
-//
-
-void M_MakeDirectory(char *path)
-{
-#ifdef _WIN32
-    mkdir(path);
-#else
-    mkdir(path, 0755);
-#endif
-}
-
-
-//
-// SetConfigDir:
-//
-// Sets the location of the configuration directory, where configuration
-// files are stored - default.cfg, chocolate-doom.cfg, savegames, etc.
-//
-
-void M_SetConfigDir(void)
-{
-#ifndef _WIN32
-    // Ignore the HOME environment variable on Windows - just behave
-    // like Vanilla Doom.
-
-    char *homedir;
-
-    homedir = getenv("HOME");
-
-    if (homedir != NULL)
-    {
-        // put all configuration in a config directory off the
-        // homedir
-
-        configdir = malloc(strlen(homedir) + strlen(PACKAGE_TARNAME) + 5);
-
-        sprintf(configdir, "%s/.%s/", homedir, PACKAGE_TARNAME);
-
-        // make the directory if it doesnt already exist
-
-        M_MakeDirectory(configdir);
-    }
-    else
-#endif /* #ifndef _WIN32 */
-    {
-#ifdef _WIN32
-        // when given the -cdrom option, save config+savegames in
-        // c:\doomdata.  This only applies under Windows.
-
-        if (M_CheckParm("-cdrom") > 0)
-        {
-            printf(D_CDROM);
-            configdir = strdup("c:\\doomdata\\");
-
-            M_MakeDirectory(configdir);
-        }
-        else
-#endif
-        {
-            configdir = strdup("");
-        }
-    }
-}
-
-
-
-//
-// DEFAULTS
-//
-
-// These are options that are not controlled by setup.
-
-static int showMessages = 1;
-static int screenblocks = 9;
-static int detailLevel = 0;
-static int usegamma = 0;
-
-// dos specific options: these are unused but should be maintained
-// so that the config file can be shared between chocolate
-// doom and doom.exe
-
-static int snd_sbport = 0;
-static int snd_sbirq = 0;
-static int snd_sbdma = 0;
-static int snd_mport = 0;
-
-typedef enum
-{
-    DEFAULT_INT,
-    DEFAULT_STRING,
-    DEFAULT_FLOAT,
-    DEFAULT_KEY,
-} default_type_t;
-
-typedef struct
-{
-    // Name of the variable
-    char *         name;
-
-    // Pointer to the location in memory of the variable
-    void *         location;
-
-    // Type of the variable
-    default_type_t type;
-
-    // If this is a key value, the original integer scancode we read from
-    // the config file before translating it to the internal key value.
-    // If zero, we didn't read this value from a config file.
-    int            untranslated;
-
-    // The value we translated the scancode into when we read the
-    // config file on startup.  If the variable value is different from
-    // this, it has been changed and needs to be converted; otherwise,
-    // use the 'untranslated' value.
-    int            original_translated;
-} default_t;
-
-typedef struct
-{
-    default_t *defaults;
-    int        numdefaults;
-    char      *filename;
-} default_collection_t;
-
-static default_t doom_defaults_list[] =
-{
-    {"mouse_sensitivity", &mouseSensitivity, DEFAULT_INT, 0, 0},
-    {"sfx_volume",&sfxVolume, DEFAULT_INT, 0, 0},
-    {"music_volume",&musicVolume, DEFAULT_INT, 0, 0},
-    {"show_messages",&showMessages, DEFAULT_INT, 0, 0},
-
-    {"key_right",&key_right, DEFAULT_KEY, 0, 0},
-    {"key_left",&key_left, DEFAULT_KEY, 0, 0},
-    {"key_up",&key_up, DEFAULT_KEY, 0, 0},
-    {"key_down",&key_down, DEFAULT_KEY, 0, 0},
-    {"key_strafeleft",&key_strafeleft, DEFAULT_KEY, 0, 0},
-    {"key_straferight",&key_straferight, DEFAULT_KEY, 0, 0},
-
-    {"key_fire",&key_fire, DEFAULT_KEY, 0, 0},
-    {"key_use",&key_use, DEFAULT_KEY, 0, 0},
-    {"key_strafe",&key_strafe, DEFAULT_KEY, 0, 0},
-    {"key_speed",&key_speed, DEFAULT_KEY, 0, 0},
-
-    {"use_mouse",&usemouse, DEFAULT_INT, 0, 0},
-    {"mouseb_fire",&mousebfire, DEFAULT_INT, 0, 0},
-    {"mouseb_strafe",&mousebstrafe, DEFAULT_INT, 0, 0},
-    {"mouseb_forward",&mousebforward, DEFAULT_INT, 0, 0},
-
-    {"use_joystick",&usejoystick, DEFAULT_INT, 0, 0},
-    {"joyb_fire",&joybfire, DEFAULT_INT, 0, 0},
-    {"joyb_strafe",&joybstrafe, DEFAULT_INT, 0, 0},
-    {"joyb_use",&joybuse, DEFAULT_INT, 0, 0},
-    {"joyb_speed",&joybspeed, DEFAULT_INT, 0, 0},
-
-    {"screenblocks",&screenblocks, DEFAULT_INT, 0, 0},
-    {"detaillevel",&detailLevel, DEFAULT_INT, 0, 0},
-
-    {"snd_channels",&numChannels, DEFAULT_INT, 0, 0},
-
-    {"snd_musicdevice", &snd_musicdevice, DEFAULT_INT, 0, 0},
-    {"snd_sfxdevice", &snd_sfxdevice, DEFAULT_INT, 0, 0},
-    {"snd_sbport", &snd_sbport, DEFAULT_INT, 0, 0},
-    {"snd_sbirq", &snd_sbirq, DEFAULT_INT, 0, 0},
-    {"snd_sbdma", &snd_sbdma, DEFAULT_INT, 0, 0},
-    {"snd_mport", &snd_mport, DEFAULT_INT, 0, 0},
-
-    {"usegamma", &usegamma, DEFAULT_INT, 0, 0},
-
-    {"chatmacro0", &chat_macros[0], DEFAULT_STRING, 0, 0 },
-    {"chatmacro1", &chat_macros[1], DEFAULT_STRING, 0, 0 },
-    {"chatmacro2", &chat_macros[2], DEFAULT_STRING, 0, 0 },
-    {"chatmacro3", &chat_macros[3], DEFAULT_STRING, 0, 0 },
-    {"chatmacro4", &chat_macros[4], DEFAULT_STRING, 0, 0 },
-    {"chatmacro5", &chat_macros[5], DEFAULT_STRING, 0, 0 },
-    {"chatmacro6", &chat_macros[6], DEFAULT_STRING, 0, 0 },
-    {"chatmacro7", &chat_macros[7], DEFAULT_STRING, 0, 0 },
-    {"chatmacro8", &chat_macros[8], DEFAULT_STRING, 0, 0 },
-    {"chatmacro9", &chat_macros[9], DEFAULT_STRING, 0, 0 },
-};
-
-static default_collection_t doom_defaults =
-{
-    doom_defaults_list,
-    arrlen(doom_defaults_list),
-    NULL,
-};
-
-static default_t extra_defaults_list[] =
-{
-    {"autoadjust_video_settings",   &autoadjust_video_settings, DEFAULT_INT, 0, 0},
-    {"fullscreen",                  &fullscreen, DEFAULT_INT, 0, 0},
-    {"aspect_ratio_correct",        &aspect_ratio_correct, DEFAULT_INT, 0, 0},
-    {"startup_delay",               &startup_delay, DEFAULT_INT, 0, 0},
-    {"screen_width",                &screen_width, DEFAULT_INT, 0, 0},
-    {"screen_height",               &screen_height, DEFAULT_INT, 0, 0},
-    {"grabmouse",                   &grabmouse, DEFAULT_INT, 0, 0},
-    {"novert",                      &novert, DEFAULT_INT, 0, 0},
-    {"mouse_acceleration",          &mouse_acceleration, DEFAULT_FLOAT, 0, 0},
-    {"mouse_threshold",             &mouse_threshold, DEFAULT_INT, 0, 0},
-    {"snd_samplerate",              &snd_samplerate, DEFAULT_INT, 0, 0},
-    {"show_endoom",                 &show_endoom, DEFAULT_INT, 0, 0},
-    {"vanilla_savegame_limit",      &vanilla_savegame_limit, DEFAULT_INT, 0, 0},
-    {"vanilla_demo_limit",          &vanilla_demo_limit, DEFAULT_INT, 0, 0},
-    {"vanilla_keyboard_mapping",    &vanilla_keyboard_mapping, DEFAULT_INT, 0, 0},
-#ifdef FEATURE_MULTIPLAYER
-    {"player_name",                 &net_player_name,          DEFAULT_STRING, 0, 0},
-#endif
-    {"video_driver",                &video_driver,             DEFAULT_STRING, 0, 0},
-    {"joystick_index",              &joystick_index, DEFAULT_INT, 0, 0},
-    {"joystick_x_axis",             &joystick_x_axis, DEFAULT_INT, 0, 0},
-    {"joystick_x_invert",           &joystick_x_invert, DEFAULT_INT, 0, 0},
-    {"joystick_y_axis",             &joystick_y_axis, DEFAULT_INT, 0, 0},
-    {"joystick_y_invert",           &joystick_y_invert, DEFAULT_INT, 0, 0},
-    {"joyb_strafeleft",             &joybstrafeleft, DEFAULT_INT, 0, 0},
-    {"joyb_straferight",            &joybstraferight, DEFAULT_INT, 0, 0},
-    {"dclick_use",                  &dclick_use, DEFAULT_INT, 0, 0},
-    {"mouseb_strafeleft",           &mousebstrafeleft, DEFAULT_INT, 0, 0},
-    {"mouseb_straferight",          &mousebstraferight, DEFAULT_INT, 0, 0},
-    {"mouseb_use",                  &mousebuse, DEFAULT_INT, 0, 0},
-    {"mouseb_backward",             &mousebbackward, DEFAULT_INT, 0, 0},
-    {"use_libsamplerate",           &use_libsamplerate, DEFAULT_INT, 0, 0},
-};
-
-static default_collection_t extra_defaults =
-{
-    extra_defaults_list,
-    arrlen(extra_defaults_list),
-    NULL,
-};
-
-static int scantokey[128] =
-{
-    0  ,    27,     '1',    '2',    '3',    '4',    '5',    '6',
-    '7',    '8',    '9',    '0',    '-',    '=',    KEY_BACKSPACE, 9,
-    'q',    'w',    'e',    'r',    't',    'y',    'u',    'i',
-    'o',    'p',    '[',    ']',    13,		KEY_RCTRL, 'a',    's',
-    'd',    'f',    'g',    'h',    'j',    'k',    'l',    ';',
-    '\'',   '`',    KEY_RSHIFT,'\\',   'z',    'x',    'c',    'v',
-    'b',    'n',    'm',    ',',    '.',    '/',    KEY_RSHIFT,KEYP_MULTIPLY,
-    KEY_RALT,  ' ',  KEY_CAPSLOCK,KEY_F1,  KEY_F2,   KEY_F3,   KEY_F4,   KEY_F5,
-    KEY_F6,   KEY_F7,   KEY_F8,   KEY_F9,   KEY_F10,  KEY_PAUSE,KEY_SCRLCK,KEY_HOME,
-    KEY_UPARROW,KEY_PGUP,KEYP_MINUS,KEY_LEFTARROW,KEYP_5,KEY_RIGHTARROW,KEYP_PLUS,KEY_END,
-    KEY_DOWNARROW,KEY_PGDN,KEY_INS,KEY_DEL,0,   0,      0,      KEY_F11,
-    KEY_F12,  0,      0,      0,      0,      0,      0,      0,
-    0,      0,      0,      0,      0,      0,      0,      0,
-    0,      0,      0,      0,      0,      0,      0,      0,
-    0,      0,      0,      0,      0,      0,      0,      0,
-    0,      0,      0,      0,      0,      0,      0,      0
-};
-
-
-static void SaveDefaultCollection(default_collection_t *collection)
-{
-    default_t *defaults;
-    int i, v;
-    FILE *f;
-
-    f = fopen (collection->filename, "w");
-    if (!f)
-	return; // can't write the file, but don't complain
-
-    defaults = collection->defaults;
-
-    for (i=0 ; i<collection->numdefaults ; i++)
-    {
-        int chars_written;
-
-        // Print the name and line up all values at 30 characters
-
-        chars_written = fprintf(f, "%s ", defaults[i].name);
-
-        for (; chars_written < 30; ++chars_written)
-            fprintf(f, " ");
-
-        // Print the value
-
-        switch (defaults[i].type)
-        {
-            case DEFAULT_KEY:
-
-                // use the untranslated version if we can, to reduce
-                // the possibility of screwing up the user's config
-                // file
-
-                v = * (int *) defaults[i].location;
-
-                if (defaults[i].untranslated
-                 && v == defaults[i].original_translated)
-                {
-                    // Has not been changed since the last time we
-                    // read the config file.
-
-                    v = defaults[i].untranslated;
-                }
-                else
-                {
-                    // search for a reverse mapping back to a scancode
-                    // in the scantokey table
-
-                    int s;
-
-                    for (s=0; s<128; ++s)
-                    {
-                        if (scantokey[s] == v)
-                        {
-                            v = s;
-                            break;
-                        }
-                    }
-                }
-
-	        fprintf(f, "%i", v);
-                break;
-
-            case DEFAULT_INT:
-	        fprintf(f, "%i", * (int *) defaults[i].location);
-                break;
-
-            case DEFAULT_FLOAT:
-                fprintf(f, "%f", * (float *) defaults[i].location);
-                break;
-
-            case DEFAULT_STRING:
-	        fprintf(f,"\"%s\"", * (char **) (defaults[i].location));
-                break;
-        }
-
-        fprintf(f, "\n");
-    }
-
-    fclose (f);
-}
-
-// Parses integer values in the configuration file
-
-static int ParseIntParameter(char *strparm)
-{
-    int parm;
-
-    if (strparm[0] == '0' && strparm[1] == 'x')
-        sscanf(strparm+2, "%x", &parm);
-    else
-        sscanf(strparm, "%i", &parm);
-
-    return parm;
-}
-
-static void LoadDefaultCollection(default_collection_t *collection)
-{
-    default_t  *defaults = collection->defaults;
-    int		i;
-    FILE*	f;
-    char	defname[80];
-    char	strparm[100];
-
-    // read the file in, overriding any set defaults
-    f = fopen(collection->filename, "r");
-
-    if (!f)
-    {
-        // File not opened, but don't complain
-
-        return;
-    }
-
-    while (!feof(f))
-    {
-        if (fscanf (f, "%79s %[^\n]\n", defname, strparm) != 2)
-        {
-            // This line doesn't match
-
-            continue;
-        }
-
-        // Strip off trailing non-printable characters (\r characters
-        // from DOS text files)
-
-        while (strlen(strparm) > 0 && !isprint(strparm[strlen(strparm)-1]))
-        {
-            strparm[strlen(strparm)-1] = '\0';
-        }
-
-        // Find the setting in the list
-
-        for (i=0; i<collection->numdefaults; ++i)
-        {
-            default_t *def = &collection->defaults[i];
-            char *s;
-            int intparm;
-
-            if (strcmp(defname, def->name) != 0)
-            {
-                // not this one
-                continue;
-            }
-
-            // parameter found
-
-            switch (def->type)
-            {
-                case DEFAULT_STRING:
-                    s = strdup(strparm + 1);
-                    s[strlen(s) - 1] = '\0';
-                    * (char **) def->location = s;
-                    break;
-
-                case DEFAULT_INT:
-                    * (int *) def->location = ParseIntParameter(strparm);
-                    break;
-
-                case DEFAULT_KEY:
-
-                    // translate scancodes read from config
-                    // file (save the old value in untranslated)
-
-                    intparm = ParseIntParameter(strparm);
-                    defaults[i].untranslated = intparm;
-                    intparm = scantokey[intparm];
-
-                    defaults[i].original_translated = intparm;
-                    * (int *) def->location = intparm;
-                    break;
-
-                case DEFAULT_FLOAT:
-                    * (float *) def->location = atof(strparm);
-                    break;
-            }
-
-            // finish
-
-            break;
-        }
-    }
-
-    fclose (f);
-}
-
-//
-// M_SaveDefaults
-//
-
-void M_SaveDefaults (void)
-{
-    SaveDefaultCollection(&doom_defaults);
-    SaveDefaultCollection(&extra_defaults);
-}
-
-
-//
-// M_LoadDefaults
-//
-
-void M_LoadDefaults (void)
-{
-    int i;
-
-    // check for a custom default file
-    i = M_CheckParm ("-config");
-
-    if (i && i<myargc-1)
-    {
-	doom_defaults.filename = myargv[i+1];
-	printf ("	default file: %s\n",doom_defaults.filename);
-    }
-    else
-    {
-        doom_defaults.filename = malloc(strlen(configdir) + 20);
-        sprintf(doom_defaults.filename, "%sdefault.cfg", configdir);
-    }
-
-//    printf("saving config in %s\n", doom_defaults.filename);
-
-    i = M_CheckParm("-extraconfig");
-
-    if (i && i<myargc-1)
-    {
-        extra_defaults.filename = myargv[i+1];
-        printf("        extra configuration file: %s\n",
-               extra_defaults.filename);
-    }
-    else
-    {
-        extra_defaults.filename
-            = malloc(strlen(configdir) + strlen(PACKAGE_TARNAME) + 10);
-        sprintf(extra_defaults.filename, "%s%s.cfg",
-                configdir, PACKAGE_TARNAME);
-    }
-
-    LoadDefaultCollection(&doom_defaults);
-    LoadDefaultCollection(&extra_defaults);
-}
-
-//
-// Save normal (default.cfg) defaults to a given file
-//
-
-void M_SaveMainDefaults(char *filename)
-{
-    char *main_filename;
-
-    // Save the normal filename and set this one
-
-    main_filename = doom_defaults.filename;
-    doom_defaults.filename = filename;
-
-    // Save the file
-
-    SaveDefaultCollection(&doom_defaults);
-
-    // Restore the normal filename
-
-    doom_defaults.filename = main_filename;
-}
-
-//
-// Save extra (chocolate-doom.cfg) defaults to a given file
-//
-
-void M_SaveExtraDefaults(char *filename)
-{
-    char *main_filename;
-
-    // Save the normal filename and set this one
-
-    main_filename = extra_defaults.filename;
-    extra_defaults.filename = filename;
-
-    // Save the file
-
-    SaveDefaultCollection(&extra_defaults);
-
-    // Restore the normal filename
-
-    extra_defaults.filename = main_filename;
-}
-
diff --git a/setup/configfile.h b/setup/configfile.h
deleted file mode 100644
index f7c6156e..00000000
--- a/setup/configfile.h
+++ /dev/null
@@ -1,42 +0,0 @@
-// Emacs style mode select   -*- C++ -*-
-//-----------------------------------------------------------------------------
-//
-// Copyright(C) 1993-1996 Id Software, Inc.
-// Copyright(C) 2005 Simon Howard
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-// 02111-1307, USA.
-//
-// DESCRIPTION:
-//
-//
-//-----------------------------------------------------------------------------
-
-
-#ifndef __SETUP_CONFIG__
-#define __SETUP_CONFIG__
-
-extern char *configdir;
-
-void M_LoadDefaults (void);
-void M_SaveDefaults (void);
-
-void M_SetConfigDir(void);
-
-void M_SaveMainDefaults(char *filename);
-void M_SaveExtraDefaults(char *filename);
-
-#endif
-
diff --git a/src/Makefile.am b/src/Makefile.am
index 8f9f11d3..8e1e7544 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,22 +1,30 @@

-SUBDIRS=doom heretic hexen
+SUBDIRS=doom heretic hexen setup

 gamesdir = $(prefix)/games

 games_PROGRAMS = chocolate-doom     \
                  chocolate-heretic  \
                  chocolate-hexen    \
-                 chocolate-server
+                 chocolate-server   \
+                 chocolate-setup

 AM_CFLAGS = -Idoom -I../textscreen -I../pcsound @SDL_CFLAGS@ @SDLMIXER_CFLAGS@ @SDLNET_CFLAGS@

+# Common source files used by absolutely everything:
+
+COMMON_SOURCE_FILES=\
+i_main.c                                   \
+i_system.c           i_system.h            \
+m_argv.c             m_argv.h              \
+m_misc.c             m_misc.h
+
+# Dedicated server (chocolate-server):
+
 DEDSERV_FILES=\
 d_dedicated.c                              \
 d_mode.c             d_mode.h              \
-i_main.c                                   \
 i_timer.c            i_timer.h             \
-m_argv.c             m_argv.h              \
-m_misc.c             m_misc.h              \
 net_common.c         net_common.h          \
 net_dedicated.c      net_dedicated.h       \
 net_io.c             net_io.h              \
@@ -26,10 +34,12 @@ net_server.c         net_server.h          \
 net_structrw.c       net_structrw.h        \
 z_native.c           z_zone.h

-chocolate_server_SOURCES=$(DEDSERV_FILES)
+chocolate_server_SOURCES=$(COMMON_SOURCE_FILES) $(DEDSERV_FILES)
 chocolate_server_LDADD = @LDFLAGS@ @SDL_LIBS@ @SDLNET_LIBS@

-MAIN_SOURCE_FILES=\
+# Source files used by the game binaries (chocolate-doom, etc.)
+
+GAME_SOURCE_FILES=\
 d_event.c            d_event.h             \
                      doomkeys.h            \
                      doomfeatures.h        \
@@ -38,22 +48,19 @@ d_iwad.c             d_iwad.h              \
 d_mode.c             d_mode.h              \
                      d_ticcmd.h            \
 i_cdmus.c            i_cdmus.h             \
-i_main.c                                   \
+i_endoom.c           i_endoom.h            \
 i_joystick.c         i_joystick.h          \
 i_scale.c            i_scale.h             \
                      i_swap.h              \
 i_sound.c            i_sound.h             \
-i_system.c           i_system.h            \
 i_timer.c            i_timer.h             \
 i_video.c            i_video.h             \
 i_videohr.c          i_videohr.h           \
-m_argv.c             m_argv.h              \
 m_bbox.c             m_bbox.h              \
 m_cheat.c            m_cheat.h             \
 m_config.c           m_config.h            \
 m_controls.c         m_controls.h          \
 m_fixed.c            m_fixed.h             \
-m_misc.c             m_misc.h              \
 md5.c                md5.h                 \
 memio.c              memio.h               \
 tables.c             tables.h              \
@@ -65,7 +72,7 @@ w_file.c             w_file.h              \
 w_file_stdc.c                              \
 w_file_posix.c                             \
 w_file_win32.c                             \
-z_zone.c             z_zone.h
+z_zone.c             z_zone.h

 # source files needed for FEATURE_DEHACKED

@@ -101,7 +108,8 @@ i_sdlsound.c                               \
 i_sdlmusic.c                               \
 mus2mid.c            mus2mid.h

-SOURCE_FILES = $(MAIN_SOURCE_FILES)                \
+SOURCE_FILES = $(COMMON_SOURCE_FILES)              \
+               $(GAME_SOURCE_FILES)                \
                $(FEATURE_DEHACKED_SOURCE_FILES)    \
                $(FEATURE_WAD_MERGE_SOURCE_FILES)   \
                $(FEATURE_SOUND_SOURCE_FILES)
@@ -138,6 +146,17 @@ endif

 chocolate_hexen_LDADD = hexen/libhexen.a $(EXTRA_LIBS)

+# Source files needed for chocolate-setup:
+
+SETUP_FILES=                               \
+m_config.c           m_config.h            \
+z_native.c           z_zone.h
+
+chocolate_setup_SOURCES=$(SETUP_FILES) $(COMMON_SOURCE_FILES)
+chocolate_setup_LDADD = setup/libsetup.a                     \
+                        ../textscreen/libtextscreen.a        \
+                        @LDFLAGS@ @SDL_LIBS@ @SDLNET_LIBS@
+
 EXTRA_DIST =                        \
         icon.c                      \
         doom-screensaver.desktop.in
diff --git a/src/d_dedicated.c b/src/d_dedicated.c
index 158fa40c..defe8083 100644
--- a/src/d_dedicated.c
+++ b/src/d_dedicated.c
@@ -43,29 +43,6 @@ void NET_CL_Run(void)
     // In a standalone dedicated server, we don't have a client.
 }

-//
-// I_Error
-//
-// We have our own I_Error function for the dedicated server.
-// The normal one does extra things like shutdown graphics, etc.
-
-void I_Error (char *error, ...)
-{
-    va_list	argptr;
-
-    // Message first.
-    va_start(argptr,error);
-    fprintf(stderr, "Error: ");
-    vfprintf(stderr,error,argptr);
-    fprintf(stderr, "\n");
-    va_end(argptr);
-
-    fflush(stderr);
-
-    exit(-1);
-}
-
-
 void D_DoomMain(void)
 {
     printf(PACKAGE_NAME " standalone dedicated server\n");
diff --git a/src/doom/d_main.c b/src/doom/d_main.c
index 419e871c..91224e88 100644
--- a/src/doom/d_main.c
+++ b/src/doom/d_main.c
@@ -60,6 +60,8 @@
 #include "m_menu.h"
 #include "p_saveg.h"

+#include "i_endoom.h"
+#include "i_joystick.h"
 #include "i_system.h"
 #include "i_timer.h"
 #include "i_video.h"
@@ -346,7 +348,10 @@ void D_BindVariables(void)
 {
     int i;

-    I_BindVariables();
+    I_BindVideoVariables();
+    I_BindJoystickVariables();
+    I_BindSoundVariables();
+
     M_BindBaseControls();
 #ifdef FEATURE_MULTIPLAYER
     NET_BindVariables();
@@ -1674,7 +1679,9 @@ void D_DoomMain (void)
     P_Init ();

     printf (DEH_String("I_Init: Setting up machine state.\n"));
-    I_Init ();
+    I_CheckIsScreensaver();
+    I_InitTimer();
+    I_InitJoystick();

 #ifdef FEATURE_MULTIPLAYER
     printf ("NET_Init: Initialise network subsystem.\n");
diff --git a/src/heretic/d_main.c b/src/heretic/d_main.c
index 2ac92b44..b8edd430 100644
--- a/src/heretic/d_main.c
+++ b/src/heretic/d_main.c
@@ -34,7 +34,11 @@
 #include "ct_chat.h"
 #include "doomdef.h"
 #include "d_iwad.h"
+#include "i_endoom.h"
+#include "i_joystick.h"
+#include "i_sound.h"
 #include "i_system.h"
+#include "i_timer.h"
 #include "i_video.h"
 #include "m_argv.h"
 #include "m_config.h"
@@ -744,7 +748,9 @@ void D_BindVariables(void)
     extern int snd_Channels;
     int i;

-    I_BindVariables();
+    I_BindVideoVariables();
+    I_BindJoystickVariables();
+    I_BindSoundVariables();
     M_BindBaseControls();
     M_BindHereticControls();

@@ -975,7 +981,9 @@ void D_DoomMain(void)
     IncThermo();

     tprintf("I_Init: Setting up machine state.\n", 1);
-    I_Init();
+    I_CheckIsScreensaver();
+    I_InitTimer();
+    I_InitJoystick();
     IncThermo();

     tprintf("S_Init: Setting up sound.\n", 1);
diff --git a/src/hexen/h2_main.c b/src/hexen/h2_main.c
index f1d6ca90..f7bc665e 100644
--- a/src/hexen/h2_main.c
+++ b/src/hexen/h2_main.c
@@ -42,7 +42,9 @@
 #include "d_mode.h"
 #include "m_misc.h"
 #include "s_sound.h"
+#include "i_joystick.h"
 #include "i_system.h"
+#include "i_timer.h"
 #include "m_argv.h"
 #include "m_config.h"
 #include "m_controls.h"
@@ -154,7 +156,9 @@ void D_BindVariables(void)
 {
     int i;

-    I_BindVariables();
+    I_BindVideoVariables();
+    I_BindJoystickVariables();
+    I_BindSoundVariables();
     M_BindBaseControls();
     M_BindHereticControls();
     M_BindHexenControls();
@@ -296,7 +300,9 @@ void D_DoomMain(void)
     ST_Message("SN_InitSequenceScript: Registering sound sequences.\n");
     SN_InitSequenceScript();
     ST_Message("I_Init: Setting up machine state.\n");
-    I_Init();
+    I_CheckIsScreensaver();
+    I_InitTimer();
+    I_InitJoystick();

     S_Init();
     S_Start();
diff --git a/setup/m_argv.c b/src/i_endoom.c
similarity index 55%
rename from setup/m_argv.c
rename to src/i_endoom.c
index ae9ab917..b943e47c 100644
--- a/setup/m_argv.c
+++ b/src/i_endoom.c
@@ -1,9 +1,7 @@
 // Emacs style mode select   -*- C++ -*-
 //-----------------------------------------------------------------------------
 //
-// Copyright(C) 1993-1996 Id Software, Inc.
-// Copyright(C) 2005 Simon Howard
-// Copyright(C) 2008 "GhostlyDeath" (ghostlydeath@gmail.com)
+// Copyright(C) 2005-8 Simon Howard
 //
 // This program is free software; you can redistribute it and/or
 // modify it under the terms of the GNU General Public License
@@ -21,45 +19,53 @@
 // 02111-1307, USA.
 //
 // DESCRIPTION:
+//    Exit text-mode ENDOOM screen.
 //
 //-----------------------------------------------------------------------------

+#include "doomtype.h"
+#include "i_video.h"

+#include "txt_main.h"

-#include <string.h>
+//
+// Displays the text mode ending screen after the game quits
+//

-int		myargc;
-char**		myargv;
+void I_Endoom(byte *endoom_data)
+{
+    unsigned char *screendata;

-// From doomdef.h -- no need to include it all!
-#ifdef _WIN32
-#define snprintf _snprintf
-#define vsnprintf _vsnprintf
-#define strcasecmp stricmp
-#define strncasecmp strnicmp
-#else
-#include <strings.h>
-#endif
+    // Set up text mode screen

-//
-// M_CheckParm
-// Checks for the given parameter
-// in the program's command line arguments.
-// Returns the argument number (1 to argc-1)
-// or 0 if not present
-int M_CheckParm (char *check)
-{
-    int		i;
+    TXT_Init();
+
+    // Make sure the new window has the right title and icon
+
+    I_SetWindowTitle("Exit screen");
+    I_SetWindowIcon();
+
+    // Write the data to the screen memory
+
+    screendata = TXT_GetScreenData();
+    memcpy(screendata, endoom_data, 4000);

-    for (i = 1;i<myargc;i++)
+    // Wait for a keypress
+
+    while (true)
     {
-	if ( !strcasecmp(check, myargv[i]) )
-	    return i;
-    }
+        TXT_UpdateScreen();

-    return 0;
-}
+        if (TXT_GetChar() >= 0)
+        {
+            break;
+        }

+        TXT_Sleep(0);
+    }

+    // Shut down text mode screen

+    TXT_Shutdown();
+}

diff --git a/setup/m_argv.h b/src/i_endoom.h
similarity index 82%
rename from setup/m_argv.h
rename to src/i_endoom.h
index bd1518b9..b4fa34dd 100644
--- a/setup/m_argv.h
+++ b/src/i_endoom.h
@@ -20,23 +20,18 @@
 // 02111-1307, USA.
 //
 // DESCRIPTION:
-//  Nil.
-//
+//    Exit text-mode ENDOOM screen.
+//
 //-----------------------------------------------------------------------------


-#ifndef __M_ARGV__
-#define __M_ARGV__
+#ifndef __I_ENDOOM__
+#define __I_ENDOOM__

-//
-// MISC
-//
-extern  int	myargc;
-extern  char**	myargv;
-
-// Returns the position of the given parameter
-// in the arg list (0 if not found).
-int M_CheckParm (char* check);
+// Display the Endoom screen on shutdown.  Pass a pointer to the
+// ENDOOM lump.

+void I_Endoom(byte *data);

 #endif
+
diff --git a/src/i_system.c b/src/i_system.c
index 77c06436..1003075f 100644
--- a/src/i_system.c
+++ b/src/i_system.c
@@ -51,7 +51,6 @@
 #include "i_video.h"

 #include "i_system.h"
-#include "txt_main.h"

 #include "w_wad.h"
 #include "z_zone.h"
@@ -178,53 +177,21 @@ boolean I_ConsoleStdout(void)
 //
 // I_Init
 //
+/*
 void I_Init (void)
 {
     I_CheckIsScreensaver();
     I_InitTimer();
     I_InitJoystick();
 }
-
-//
-// Displays the text mode ending screen after the game quits
-//
-
-void I_Endoom(byte *endoom_data)
+void I_BindVariables(void)
 {
-    unsigned char *screendata;
-
-    // Set up text mode screen
-
-    TXT_Init();
-
-    // Make sure the new window has the right title and icon
-
-    I_SetWindowTitle("Exit screen");
-    I_SetWindowIcon();
-
-    // Write the data to the screen memory
-
-    screendata = TXT_GetScreenData();
-    memcpy(screendata, endoom_data, 4000);
-
-    // Wait for a keypress
-
-    while (true)
-    {
-        TXT_UpdateScreen();
-
-        if (TXT_GetChar() >= 0)
-        {
-            break;
-        }
-
-        TXT_Sleep(0);
-    }
-
-    // Shut down text mode screen
-
-    TXT_Shutdown();
+    I_BindVideoVariables();
+    I_BindJoystickVariables();
+    I_BindSoundVariables();
 }
+*/
+

 //
 // I_Quit
@@ -247,11 +214,6 @@ void I_Quit (void)
     exit(0);
 }

-void I_WaitVBL(int count)
-{
-    I_Sleep((count * 1000) / 70);
-}
-
 //
 // I_Error
 //
@@ -314,10 +276,3 @@ void I_Error (char *error, ...)
     exit(-1);
 }

-void I_BindVariables(void)
-{
-    I_BindVideoVariables();
-    I_BindJoystickVariables();
-    I_BindSoundVariables();
-}
-
diff --git a/src/i_system.h b/src/i_system.h
index 2af3aa33..b34f61e4 100644
--- a/src/i_system.h
+++ b/src/i_system.h
@@ -80,11 +80,6 @@ void I_AtExit(atexit_func_t func, boolean run_if_error);

 void I_BindVariables(void);

-// Display the Endoom screen on shutdown.  Pass a pointer to the
-// ENDOOM lump.
-
-void I_Endoom(byte *data);
-
 // Print startup banner copyright message.

 void I_PrintStartupBanner(char *gamedescription);
diff --git a/src/i_timer.c b/src/i_timer.c
index 8ae68b82..ef97b7b7 100644
--- a/src/i_timer.c
+++ b/src/i_timer.c
@@ -73,6 +73,11 @@ void I_Sleep(int ms)
     SDL_Delay(ms);
 }

+void I_WaitVBL(int count)
+{
+    I_Sleep((count * 1000) / 70);
+}
+

 void I_InitTimer(void)
 {
diff --git a/src/i_timer.h b/src/i_timer.h
index 85816064..17390884 100644
--- a/src/i_timer.h
+++ b/src/i_timer.h
@@ -43,5 +43,8 @@ void I_Sleep(int ms);
 // Initialise timer
 void I_InitTimer(void);

+// Wait for vertical retrace or pause a bit.
+void I_WaitVBL(int count);
+
 #endif

diff --git a/src/i_video.h b/src/i_video.h
index 5af31e92..1c668474 100644
--- a/src/i_video.h
+++ b/src/i_video.h
@@ -85,9 +85,6 @@ void I_SetPalette (byte* palette);
 void I_UpdateNoBlit (void);
 void I_FinishUpdate (void);

-// Wait for vertical retrace or pause a bit.
-void I_WaitVBL(int count);
-
 void I_ReadScreen (byte* scr);

 void I_BeginRead (void);
diff --git a/src/m_config.c b/src/m_config.c
index 4f92d09e..a4db1c98 100644
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -980,6 +980,31 @@ void M_SaveDefaults (void)
     SaveDefaultCollection(&extra_defaults);
 }

+//
+// Save defaults to alternate filenames
+//
+
+void M_SaveDefaultsAlternate(char *main, char *extra)
+{
+    char *orig_main;
+    char *orig_extra;
+
+    // Temporarily change the filenames
+
+    orig_main = doom_defaults.filename;
+    orig_extra = extra_defaults.filename;
+
+    doom_defaults.filename = main;
+    extra_defaults.filename = extra;
+
+    M_SaveDefaults();
+
+    // Restore normal filenames
+
+    doom_defaults.filename = orig_main;
+    extra_defaults.filename = orig_extra;
+}
+
 //
 // M_LoadDefaults
 //
diff --git a/src/m_config.h b/src/m_config.h
index 16468b5d..6f2bb894 100644
--- a/src/m_config.h
+++ b/src/m_config.h
@@ -30,6 +30,7 @@

 void M_LoadDefaults(void);
 void M_SaveDefaults(void);
+void M_SaveDefaultsAlternate(char *main, char *extra);
 void M_SetConfigDir(void);
 void M_BindVariable(char *name, void *variable);
 void M_SetConfigFilenames(char *main_config, char *extra_config);
diff --git a/setup/setup-res.rc.in b/src/setup-res.rc.in
similarity index 100%
rename from setup/setup-res.rc.in
rename to src/setup-res.rc.in
diff --git a/setup/.gitignore b/src/setup/.gitignore
similarity index 100%
rename from setup/.gitignore
rename to src/setup/.gitignore
diff --git a/setup/Makefile.am b/src/setup/Makefile.am
similarity index 56%
rename from setup/Makefile.am
rename to src/setup/Makefile.am
index f845f853..6028eab7 100644
--- a/setup/Makefile.am
+++ b/src/setup/Makefile.am
@@ -1,18 +1,13 @@

-gamesdir = $(prefix)/games
+AM_CFLAGS = @SDL_CFLAGS@ -I../../textscreen -I.. -DINSTALL_DIR="\"$(gamesdir)\""

-AM_CFLAGS = @SDL_CFLAGS@ -I../textscreen -I../src -DINSTALL_DIR="\"$(gamesdir)\""
+noinst_LIBRARIES = libsetup.a

-games_PROGRAMS = chocolate-setup
-
-chocolate_setup_LDADD = ../textscreen/libtextscreen.a @LDFLAGS@ @SDL_LIBS@
 SOURCE_FILES =                                  \
     compatibility.c   compatibility.h           \
-    configfile.c      configfile.h              \
     display.c         display.h                 \
     joystick.c        joystick.h                \
     keyboard.c        keyboard.h                \
-    m_argv.c          m_argv.h                  \
     mainmenu.c                                  \
     mouse.c           mouse.h                   \
     multiplayer.c     multiplayer.h             \
@@ -22,25 +17,9 @@ SOURCE_FILES =                                  \
     txt_keyinput.c    txt_keyinput.h            \
     txt_mouseinput.c  txt_mouseinput.h

+libsetup_a_SOURCES = $(SOURCE_FILES)
+
 EXTRA_DIST=                                     \
     setup_icon.c                                \
     setup-manifest.xml

-if HAVE_WINDRES
-chocolate_setup_SOURCES=$(SOURCE_FILES) setup-res.rc
-else
-chocolate_setup_SOURCES=$(SOURCE_FILES)
-endif
-
-.rc.o:
-	$(WINDRES) $^ -o $@
-%.o : %.rc
-	$(WINDRES) $^ -o $@
-
-if HAVE_PYTHON
-
-setup_icon.c : ../data/setup.ico
-	../data/convert-icon $^ $@
-
-endif
-
diff --git a/setup/compatibility.c b/src/setup/compatibility.c
similarity index 100%
rename from setup/compatibility.c
rename to src/setup/compatibility.c
diff --git a/setup/compatibility.h b/src/setup/compatibility.h
similarity index 100%
rename from setup/compatibility.h
rename to src/setup/compatibility.h
diff --git a/setup/display.c b/src/setup/display.c
similarity index 100%
rename from setup/display.c
rename to src/setup/display.c
diff --git a/setup/display.h b/src/setup/display.h
similarity index 100%
rename from setup/display.h
rename to src/setup/display.h
diff --git a/setup/execute.c b/src/setup/execute.c
similarity index 98%
rename from setup/execute.c
rename to src/setup/execute.c
index b5b8a7c6..9846cd20 100644
--- a/setup/execute.c
+++ b/src/setup/execute.c
@@ -38,9 +38,9 @@
 #include "textscreen.h"

 #include "config.h"
-#include "configfile.h"
 #include "execute.h"
 #include "m_argv.h"
+#include "m_config.h"

 #ifdef _WIN32
 #define DOOM_BINARY PACKAGE_TARNAME ".exe"
@@ -221,7 +221,7 @@ static void TestCallback(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(data))
     char *extra_cfg;
     txt_window_t *testwindow;
     txt_label_t *label;
-
+
     testwindow = TXT_NewWindow("Starting Doom");

     label = TXT_NewLabel("Starting Doom to test the\n"
@@ -235,8 +235,7 @@ static void TestCallback(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(data))
     main_cfg = TempFile("tmp.cfg");
     extra_cfg = TempFile("extratmp.cfg");

-    M_SaveMainDefaults(main_cfg);
-    M_SaveExtraDefaults(extra_cfg);
+    M_SaveDefaultsAlternate(main_cfg, extra_cfg);

     // Run with the -testcontrols parameter

diff --git a/setup/execute.h b/src/setup/execute.h
similarity index 100%
rename from setup/execute.h
rename to src/setup/execute.h
diff --git a/setup/joystick.c b/src/setup/joystick.c
similarity index 100%
rename from setup/joystick.c
rename to src/setup/joystick.c
diff --git a/setup/joystick.h b/src/setup/joystick.h
similarity index 100%
rename from setup/joystick.h
rename to src/setup/joystick.h
diff --git a/setup/keyboard.c b/src/setup/keyboard.c
similarity index 100%
rename from setup/keyboard.c
rename to src/setup/keyboard.c
diff --git a/setup/keyboard.h b/src/setup/keyboard.h
similarity index 100%
rename from setup/keyboard.h
rename to src/setup/keyboard.h
diff --git a/setup/mainmenu.c b/src/setup/mainmenu.c
similarity index 96%
rename from setup/mainmenu.c
rename to src/setup/mainmenu.c
index d4dfe0db..1585c96b 100644
--- a/setup/mainmenu.c
+++ b/src/setup/mainmenu.c
@@ -18,6 +18,7 @@
 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 // 02111-1307, USA.
 //
+
 #include <stdlib.h>

 #include "config.h"
@@ -25,8 +26,8 @@

 #include "execute.h"

-#include "configfile.h"
 #include "m_argv.h"
+#include "m_config.h"

 #include "setup_icon.c"

@@ -42,7 +43,8 @@ static void DoQuit(void *widget, void *dosave)
 {
     if (dosave != NULL)
     {
-        M_SaveDefaults();
+        // DANGER: this is broken.  Do not save.
+//        M_SaveDefaults();
     }

     exit(0);
@@ -140,6 +142,7 @@ static void InitConfig(void)
     SetChatMacroDefaults();
     SetPlayerNameDefault();

+    M_SetConfigFilenames("default.cfg", "chocolate-doom.cfg");
     M_SetConfigDir();
     M_LoadDefaults();
 }
@@ -207,14 +210,9 @@ static void RunGUI(void)
     TXT_GUIMainLoop();
 }

-int main(int argc, char *argv[])
+void D_DoomMain(void)
 {
-    myargc = argc;
-    myargv = argv;
-
     InitConfig();
     RunGUI();
-
-    return 0;
 }

diff --git a/setup/mouse.c b/src/setup/mouse.c
similarity index 100%
rename from setup/mouse.c
rename to src/setup/mouse.c
diff --git a/setup/mouse.h b/src/setup/mouse.h
similarity index 100%
rename from setup/mouse.h
rename to src/setup/mouse.h
diff --git a/setup/multiplayer.c b/src/setup/multiplayer.c
similarity index 99%
rename from setup/multiplayer.c
rename to src/setup/multiplayer.c
index cbc76dde..b1f1d67b 100644
--- a/setup/multiplayer.c
+++ b/src/setup/multiplayer.c
@@ -22,15 +22,14 @@
 #include <stdlib.h>
 #include <string.h>

-#include "d_englsh.h"
+#include "doom/d_englsh.h"
 #include "textscreen.h"
 #include "doomtype.h"

-#include "configfile.h"
-
 #include "execute.h"

 #include "multiplayer.h"
+#include "m_config.h"

 #define NUM_WADS 10
 #define NUM_EXTRA_PARAMS 10
diff --git a/setup/multiplayer.h b/src/setup/multiplayer.h
similarity index 100%
rename from setup/multiplayer.h
rename to src/setup/multiplayer.h
diff --git a/setup/setup-manifest.xml b/src/setup/setup-manifest.xml
similarity index 100%
rename from setup/setup-manifest.xml
rename to src/setup/setup-manifest.xml
diff --git a/setup/setup_icon.c b/src/setup/setup_icon.c
similarity index 100%
rename from setup/setup_icon.c
rename to src/setup/setup_icon.c
diff --git a/setup/sound.c b/src/setup/sound.c
similarity index 100%
rename from setup/sound.c
rename to src/setup/sound.c
diff --git a/setup/sound.h b/src/setup/sound.h
similarity index 100%
rename from setup/sound.h
rename to src/setup/sound.h
diff --git a/setup/txt_joybinput.c b/src/setup/txt_joybinput.c
similarity index 100%
rename from setup/txt_joybinput.c
rename to src/setup/txt_joybinput.c
diff --git a/setup/txt_joybinput.h b/src/setup/txt_joybinput.h
similarity index 100%
rename from setup/txt_joybinput.h
rename to src/setup/txt_joybinput.h
diff --git a/setup/txt_keyinput.c b/src/setup/txt_keyinput.c
similarity index 100%
rename from setup/txt_keyinput.c
rename to src/setup/txt_keyinput.c
diff --git a/setup/txt_keyinput.h b/src/setup/txt_keyinput.h
similarity index 100%
rename from setup/txt_keyinput.h
rename to src/setup/txt_keyinput.h
diff --git a/setup/txt_mouseinput.c b/src/setup/txt_mouseinput.c
similarity index 100%
rename from setup/txt_mouseinput.c
rename to src/setup/txt_mouseinput.c
diff --git a/setup/txt_mouseinput.h b/src/setup/txt_mouseinput.h
similarity index 100%
rename from setup/txt_mouseinput.h
rename to src/setup/txt_mouseinput.h