]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - sys_win.c
build number 101
[xonotic/darkplaces.git] / sys_win.c
index d87240bd83ce164b61fbcbbabebff84b92bac968..a7f21401318f46288313024988d98f267096b0b6 100644 (file)
--- a/sys_win.c
+++ b/sys_win.c
@@ -26,11 +26,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "conproc.h"
 #include "direct.h"
 
-// LordHavoc: raised min to 24mb (was 8.5mb)
-#define MINIMUM_WIN_MEMORY             0x1800000
-// LordHavoc: raised max to 24mb (was 16mb)
-#define MAXIMUM_WIN_MEMORY             0x1800000
-
 #define CONSOLE_ERROR_TIMEOUT  60.0    // # of seconds to wait on Sys_Error running
                                                                                //  dedicated before exiting
 #define PAUSE_SLEEP            50                              // sleep time on pause or minimization
@@ -55,10 +50,7 @@ static HANDLE        hFile;
 static HANDLE  heventParent;
 static HANDLE  heventChild;
 
-void MaskExceptions (void);
 void Sys_InitFloatTime (void);
-void Sys_PushFPCW_SetHigh (void);
-void Sys_PopFPCW (void);
 
 volatile int                                   sys_checksum;
 
@@ -68,6 +60,7 @@ volatile int                                  sys_checksum;
 Sys_PageIn
 ================
 */
+/*
 void Sys_PageIn (void *ptr, int size)
 {
        byte    *x;
@@ -87,6 +80,7 @@ void Sys_PageIn (void *ptr, int size)
                }
        }
 }
+*/
 
 
 /*
@@ -121,17 +115,12 @@ int filelength (FILE *f)
 {
        int             pos;
        int             end;
-       int             t;
-
-       t = VID_ForceUnlockedAndReturnState ();
 
        pos = ftell (f);
        fseek (f, 0, SEEK_END);
        end = ftell (f);
        fseek (f, pos, SEEK_SET);
 
-       VID_ForceLockState (t);
-
        return end;
 }
 
@@ -139,9 +128,6 @@ int Sys_FileOpenRead (char *path, int *hndl)
 {
        FILE    *f;
        int             i, retval;
-       int             t;
-
-       t = VID_ForceUnlockedAndReturnState ();
 
        i = findhandle ();
 
@@ -159,8 +145,6 @@ int Sys_FileOpenRead (char *path, int *hndl)
                retval = filelength(f);
        }
 
-       VID_ForceLockState (t);
-
        return retval;
 }
 
@@ -168,10 +152,7 @@ int Sys_FileOpenWrite (char *path)
 {
        FILE    *f;
        int             i;
-       int             t;
 
-       t = VID_ForceUnlockedAndReturnState ();
-       
        i = findhandle ();
 
        f = fopen(path, "wb");
@@ -179,71 +160,42 @@ int Sys_FileOpenWrite (char *path)
                Host_Error ("Error opening %s: %s", path,strerror(errno));
        sys_handles[i] = f;
        
-       VID_ForceLockState (t);
-
        return i;
 }
 
 void Sys_FileClose (int handle)
 {
-       int             t;
-
-       t = VID_ForceUnlockedAndReturnState ();
        fclose (sys_handles[handle]);
        sys_handles[handle] = NULL;
-       VID_ForceLockState (t);
 }
 
 void Sys_FileSeek (int handle, int position)
 {
-       int             t;
-
-       t = VID_ForceUnlockedAndReturnState ();
        fseek (sys_handles[handle], position, SEEK_SET);
-       VID_ForceLockState (t);
 }
 
 int Sys_FileRead (int handle, void *dest, int count)
 {
-       int             t, x;
-
-       t = VID_ForceUnlockedAndReturnState ();
-       x = fread (dest, 1, count, sys_handles[handle]);
-       VID_ForceLockState (t);
-       return x;
+       return fread (dest, 1, count, sys_handles[handle]);
 }
 
 int Sys_FileWrite (int handle, void *data, int count)
 {
-       int             t, x;
-
-       t = VID_ForceUnlockedAndReturnState ();
-       x = fwrite (data, 1, count, sys_handles[handle]);
-       VID_ForceLockState (t);
-       return x;
+       return fwrite (data, 1, count, sys_handles[handle]);
 }
 
 int    Sys_FileTime (char *path)
 {
        FILE    *f;
-       int             t, retval;
-
-       t = VID_ForceUnlockedAndReturnState ();
        
        f = fopen(path, "rb");
-
        if (f)
        {
                fclose(f);
-               retval = 1;
-       }
-       else
-       {
-               retval = -1;
+               return 1;
        }
        
-       VID_ForceLockState (t);
-       return retval;
+       return -1;
 }
 
 void Sys_mkdir (char *path)
@@ -260,6 +212,7 @@ SYSTEM IO
 ===============================================================================
 */
 
+#if NOTUSED
 /*
 ================
 Sys_MakeCodeWriteable
@@ -272,28 +225,9 @@ void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
        if (!VirtualProtect((LPVOID)startaddr, length, PAGE_READWRITE, &flOldProtect))
                Sys_Error("Protection change failed\n");
 }
+#endif
 
 
-//#ifndef _M_IX86
-
-void Sys_SetFPCW (void)
-{
-}
-
-void Sys_PushFPCW_SetHigh (void)
-{
-}
-
-void Sys_PopFPCW (void)
-{
-}
-
-void MaskExceptions (void)
-{
-}
-
-//#endif
-
 /*
 ================
 Sys_Init
@@ -305,17 +239,19 @@ void Sys_Init (void)
        unsigned int    lowpart, highpart;
        OSVERSIONINFO   vinfo;
 
-       MaskExceptions ();
-       Sys_SetFPCW ();
-
        if (!QueryPerformanceFrequency (&PerformanceFreq))
                Sys_Error ("No hardware timer available");
 
 // get 32 out of the 64 time bits such that we have around
 // 1 microsecond resolution
+#ifdef __BORLANDC__
+       lowpart = (unsigned int)PerformanceFreq.u.LowPart;
+       highpart = (unsigned int)PerformanceFreq.u.HighPart;
+#else
        lowpart = (unsigned int)PerformanceFreq.LowPart;
        highpart = (unsigned int)PerformanceFreq.HighPart;
-       lowshift = 0;
+#endif 
+        lowshift = 0;
 
        while (highpart || (lowpart > 2000000.0))
        {
@@ -362,10 +298,7 @@ void Sys_Error (char *error, ...)
        static int      in_sys_error3 = 0;
 
        if (!in_sys_error3)
-       {
                in_sys_error3 = 1;
-               VID_ForceUnlockedAndReturnState ();
-       }
 
        va_start (argptr, error);
        vsprintf (text, error, argptr);
@@ -446,8 +379,6 @@ void Sys_Printf (char *fmt, ...)
 void Sys_Quit (void)
 {
 
-       VID_ForceUnlockedAndReturnState ();
-
        Host_Shutdown();
 
        if (tevent)
@@ -477,13 +408,16 @@ double Sys_FloatTime (void)
        unsigned int            temp, t2;
        double                          time;
 
-       Sys_PushFPCW_SetHigh ();
-
        QueryPerformanceCounter (&PerformanceCount);
 
+#ifdef __BORLANDC__
+       temp = ((unsigned int)PerformanceCount.u.LowPart >> lowshift) |
+           ((unsigned int)PerformanceCount.u.HighPart << (32 - lowshift));
+#else
+
        temp = ((unsigned int)PerformanceCount.LowPart >> lowshift) |
                   ((unsigned int)PerformanceCount.HighPart << (32 - lowshift));
-
+#endif
        if (first)
        {
                oldtime = temp;
@@ -524,8 +458,6 @@ double Sys_FloatTime (void)
                }
        }
 
-       Sys_PopFPCW ();
-
     return curtime;
 }
 
@@ -676,7 +608,7 @@ WinMain
 void SleepUntilInput (int time)
 {
 
-       MsgWaitForMultipleObjects(1, &tevent, FALSE, time, QS_ALLINPUT);
+       MsgWaitForMultipleObjects(1, &tevent, false, time, QS_ALLINPUT);
 }
 
 
@@ -689,17 +621,13 @@ HINSTANCE global_hInstance;
 int                    global_nCmdShow;
 char           *argv[MAX_NUM_ARGVS];
 static char    *empty_string = "";
-HWND           hwnd_dialog;
-
 
 int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
 {
-       quakeparms_t    parms;
        double                  time, oldtime, newtime/*, timediff*/;
        MEMORYSTATUS    lpBuffer;
        static  char    cwd[1024];
        int                             t;
-       RECT                    rect;
 
     /* previous instances do not exist in Win32 */
     if (hPrevInstance)
@@ -717,21 +645,22 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin
        if (cwd[strlen(cwd)-1] == '/')
                cwd[strlen(cwd)-1] = 0;
 
-       parms.basedir = cwd;
-       parms.cachedir = NULL;
+       memset(&host_parms, 0, sizeof(host_parms));
+
+       host_parms.basedir = cwd;
 
-       parms.argc = 1;
+       host_parms.argc = 1;
        argv[0] = empty_string;
 
-       while (*lpCmdLine && (parms.argc < MAX_NUM_ARGVS))
+       while (*lpCmdLine && (host_parms.argc < MAX_NUM_ARGVS))
        {
                while (*lpCmdLine && ((*lpCmdLine <= 32) || (*lpCmdLine > 126)))
                        lpCmdLine++;
 
                if (*lpCmdLine)
                {
-                       argv[parms.argc] = lpCmdLine;
-                       parms.argc++;
+                       argv[host_parms.argc] = lpCmdLine;
+                       host_parms.argc++;
 
                        while (*lpCmdLine && ((*lpCmdLine > 32) && (*lpCmdLine <= 126)))
                                lpCmdLine++;
@@ -745,84 +674,34 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin
                }
        }
 
-       parms.argv = argv;
+       host_parms.argv = argv;
 
-       COM_InitArgv (parms.argc, parms.argv);
+       COM_InitArgv (host_parms.argc, host_parms.argv);
 
-       parms.argc = com_argc;
-       parms.argv = com_argv;
+       host_parms.argc = com_argc;
+       host_parms.argv = com_argv;
 
        isDedicated = (COM_CheckParm ("-dedicated") != 0);
 
-       if (!isDedicated)
-       {
-               hwnd_dialog = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, NULL);
-
-               if (hwnd_dialog)
-               {
-                       if (GetWindowRect (hwnd_dialog, &rect))
-                       {
-                               if (rect.left > (rect.top * 2))
-                               {
-                                       SetWindowPos (hwnd_dialog, 0,
-                                               (rect.left / 2) - ((rect.right - rect.left) / 2),
-                                               rect.top, 0, 0,
-                                               SWP_NOZORDER | SWP_NOSIZE);
-                               }
-                       }
-
-                       ShowWindow (hwnd_dialog, SW_SHOWDEFAULT);
-                       UpdateWindow (hwnd_dialog);
-                       SetForegroundWindow (hwnd_dialog);
-               }
-       }
-
 // take the greater of all the available memory or half the total memory,
 // but at least 8 Mb and no more than 16 Mb, unless they explicitly
 // request otherwise
-       parms.memsize = lpBuffer.dwAvailPhys;
-
-       if (parms.memsize < MINIMUM_WIN_MEMORY)
-               parms.memsize = MINIMUM_WIN_MEMORY;
-
-       if (parms.memsize < (lpBuffer.dwTotalPhys >> 1))
-               parms.memsize = lpBuffer.dwTotalPhys >> 1;
+       /*
+       host_parms.memsize = lpBuffer.dwAvailPhys;
 
-       if (parms.memsize > MAXIMUM_WIN_MEMORY)
-               parms.memsize = MAXIMUM_WIN_MEMORY;
-
-       if (COM_CheckParm ("-heapsize"))
-       {
-               t = COM_CheckParm("-heapsize") + 1;
-
-               if (t < com_argc)
-                       parms.memsize = atoi (com_argv[t]) * 1024;
-       }
-
-       if (COM_CheckParm ("-mem"))
-       {
-               t = COM_CheckParm("-mem") + 1;
-
-               if (t < com_argc)
-                       parms.memsize = atoi (com_argv[t]) * 1048576;
-       }
-
-       if (COM_CheckParm ("-winmem"))
-       {
-               t = COM_CheckParm("-winmem") + 1;
-
-               if (t < com_argc)
-                       parms.memsize = atoi (com_argv[t]) * 1048576;
-       }
+       if (host_parms.memsize < MINIMUM_WIN_MEMORY)
+               host_parms.memsize = MINIMUM_WIN_MEMORY;
 
-       parms.membase = malloc (parms.memsize);
+       if (host_parms.memsize < (lpBuffer.dwTotalPhys >> 1))
+               host_parms.memsize = lpBuffer.dwTotalPhys >> 1;
 
-       if (!parms.membase)
-               Sys_Error ("Not enough memory free; check disk space\n");
+       if (host_parms.memsize > MAXIMUM_WIN_MEMORY)
+               host_parms.memsize = MAXIMUM_WIN_MEMORY;
+       */
 
-       Sys_PageIn (parms.membase, parms.memsize);
+//     Sys_PageIn (parms.membase, parms.memsize);
 
-       tevent = CreateEvent(NULL, FALSE, FALSE, NULL);
+       tevent = CreateEvent(NULL, false, false, NULL);
 
        if (!tevent)
                Sys_Error ("Couldn't create event");
@@ -865,7 +744,7 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin
        S_BlockSound ();
 
        Sys_Printf ("Host_Init\n");
-       Host_Init (&parms);
+       Host_Init ();
 
        oldtime = Sys_FloatTime ();
 
@@ -920,6 +799,6 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin
        }
 
     /* return success of application */
-    return TRUE;
+    return true;
 }