1998-04-07 00:00:00 +00:00
|
|
|
// Emacs style mode select -*- C++ -*-
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// $Id:$
|
|
|
|
//
|
|
|
|
// Copyright (C) 1993-1996 by id Software, Inc.
|
|
|
|
//
|
|
|
|
// This source is available for distribution and/or modification
|
|
|
|
// only under the terms of the DOOM Source Code License as
|
|
|
|
// published by id Software. All rights reserved.
|
|
|
|
//
|
|
|
|
// The source is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
// $Log:$
|
|
|
|
//
|
|
|
|
// DESCRIPTION:
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
1998-12-22 00:00:00 +00:00
|
|
|
#include <io.h>
|
|
|
|
#include <direct.h>
|
1998-04-07 00:00:00 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/timeb.h>
|
|
|
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
#include <mmsystem.h>
|
|
|
|
|
1998-12-22 00:00:00 +00:00
|
|
|
#include "version.h"
|
1998-04-07 00:00:00 +00:00
|
|
|
#include "doomdef.h"
|
1998-12-22 00:00:00 +00:00
|
|
|
#include "cmdlib.h"
|
1998-04-07 00:00:00 +00:00
|
|
|
#include "m_argv.h"
|
1998-04-07 00:00:00 +00:00
|
|
|
#include "m_misc.h"
|
|
|
|
#include "i_video.h"
|
|
|
|
#include "i_sound.h"
|
|
|
|
#include "i_music.h"
|
|
|
|
|
1998-12-22 00:00:00 +00:00
|
|
|
#include "d_main.h"
|
1998-04-07 00:00:00 +00:00
|
|
|
#include "d_net.h"
|
|
|
|
#include "g_game.h"
|
1998-07-14 00:00:00 +00:00
|
|
|
#include "i_input.h"
|
1998-04-07 00:00:00 +00:00
|
|
|
#include "i_system.h"
|
1998-12-22 00:00:00 +00:00
|
|
|
#include "c_dispch.h"
|
1998-04-07 00:00:00 +00:00
|
|
|
|
1998-07-14 00:00:00 +00:00
|
|
|
#ifdef USEASM
|
|
|
|
BOOL STACK_ARGS CheckMMX (char *vendorid);
|
|
|
|
#endif
|
|
|
|
|
1999-02-17 00:00:00 +00:00
|
|
|
extern HWND Window;
|
1998-04-07 00:00:00 +00:00
|
|
|
|
1998-07-14 00:00:00 +00:00
|
|
|
BOOL UseMMX;
|
|
|
|
BOOL fastdemo;
|
1998-04-07 00:00:00 +00:00
|
|
|
|
1998-04-07 00:00:00 +00:00
|
|
|
float mb_used = 8.0;
|
1998-04-07 00:00:00 +00:00
|
|
|
|
1998-07-14 00:00:00 +00:00
|
|
|
int (*I_GetTime) (void);
|
|
|
|
|
|
|
|
os_t OSPlatform;
|
1998-04-07 00:00:00 +00:00
|
|
|
|
1998-07-14 00:00:00 +00:00
|
|
|
void I_Tactile (int on, int off, int total)
|
1998-04-07 00:00:00 +00:00
|
|
|
{
|
|
|
|
// UNUSED.
|
|
|
|
on = off = total = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ticcmd_t emptycmd;
|
|
|
|
ticcmd_t* I_BaseTiccmd(void)
|
|
|
|
{
|
|
|
|
return &emptycmd;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int I_GetHeapSize (void)
|
|
|
|
{
|
1998-04-07 00:00:00 +00:00
|
|
|
return (int)(mb_used*1024*1024);
|
1998-04-07 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
1998-07-14 00:00:00 +00:00
|
|
|
byte* I_ZoneBase (int *size)
|
1998-04-07 00:00:00 +00:00
|
|
|
{
|
1998-04-07 00:00:00 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
i = M_CheckParm ("-heapsize");
|
|
|
|
if (i && i < myargc - 1)
|
|
|
|
mb_used = (float)atof (myargv[i + 1]);
|
|
|
|
*size = (int)(mb_used*1024*1024);
|
1998-04-07 00:00:00 +00:00
|
|
|
return (byte *) malloc (*size);
|
|
|
|
}
|
|
|
|
|
1998-12-22 00:00:00 +00:00
|
|
|
void I_BeginRead(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void I_EndRead(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
byte* I_AllocLow(int length)
|
|
|
|
{
|
|
|
|
byte* mem;
|
|
|
|
|
|
|
|
mem = (byte *)malloc (length);
|
|
|
|
if (mem) {
|
|
|
|
memset (mem,0,length);
|
|
|
|
}
|
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static DWORD basetime = 0;
|
|
|
|
|
|
|
|
// [RH] Returns time in milliseconds
|
|
|
|
unsigned int I_MSTime (void)
|
|
|
|
{
|
|
|
|
DWORD tm;
|
|
|
|
|
|
|
|
tm = timeGetTime();
|
|
|
|
if (!basetime)
|
|
|
|
basetime = tm;
|
1998-04-07 00:00:00 +00:00
|
|
|
|
1998-12-22 00:00:00 +00:00
|
|
|
return tm - basetime;
|
|
|
|
}
|
1998-04-07 00:00:00 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// I_GetTime
|
1998-12-22 00:00:00 +00:00
|
|
|
// returns time in 1/35th second tics
|
1998-04-07 00:00:00 +00:00
|
|
|
//
|
1998-07-14 00:00:00 +00:00
|
|
|
int I_GetTimeReally (void)
|
1998-04-07 00:00:00 +00:00
|
|
|
{
|
|
|
|
DWORD tm;
|
|
|
|
|
|
|
|
tm = timeGetTime();
|
|
|
|
if (!basetime)
|
|
|
|
basetime = tm;
|
|
|
|
|
|
|
|
return ((tm-basetime)*TICRATE)/1000;
|
|
|
|
}
|
|
|
|
|
1998-12-22 00:00:00 +00:00
|
|
|
// [RH] Increments the time count every time it gets called.
|
1998-07-14 00:00:00 +00:00
|
|
|
// Used only by -fastdemo (just like BOOM).
|
|
|
|
int I_GetTimeFake (void)
|
|
|
|
{
|
|
|
|
static int tic = 0;
|
1998-04-07 00:00:00 +00:00
|
|
|
|
1998-07-14 00:00:00 +00:00
|
|
|
return tic++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void I_WaitVBL (int count)
|
|
|
|
{
|
|
|
|
// I_WaitVBL is never used to actually synchronize to the
|
|
|
|
// vertical blank. Instead, it's used for delay purposes.
|
|
|
|
|
|
|
|
Sleep (1000 * count / 70);
|
|
|
|
}
|
|
|
|
|
|
|
|
// [RH] Detect the OS the game is running under
|
|
|
|
void I_DetectOS (void)
|
|
|
|
{
|
|
|
|
OSVERSIONINFO info;
|
|
|
|
char *osname;
|
|
|
|
|
|
|
|
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
|
|
|
GetVersionEx (&info);
|
|
|
|
|
|
|
|
switch (info.dwPlatformId) {
|
|
|
|
case VER_PLATFORM_WIN32s:
|
|
|
|
OSPlatform = os_Win32s;
|
|
|
|
osname = "Windows 3.1 with Win32s";
|
|
|
|
break;
|
|
|
|
case VER_PLATFORM_WIN32_WINDOWS:
|
|
|
|
OSPlatform = os_Win95;
|
1998-12-22 00:00:00 +00:00
|
|
|
osname = info.dwMinorVersion > 0 ? "Windows 98" : "Windows 95";
|
1998-07-14 00:00:00 +00:00
|
|
|
break;
|
|
|
|
case VER_PLATFORM_WIN32_NT:
|
|
|
|
OSPlatform = os_WinNT;
|
|
|
|
osname = "Windows NT";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
OSPlatform = os_unknown;
|
|
|
|
osname = "Unknown OS";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-02-17 00:00:00 +00:00
|
|
|
Printf (PRINT_HIGH, "OS: %s %u.%u (build %u)\n",
|
1998-07-14 00:00:00 +00:00
|
|
|
osname,
|
|
|
|
info.dwMajorVersion, info.dwMinorVersion,
|
|
|
|
info.dwBuildNumber & (OSPlatform == os_Win95 ? 0xffff : 0xfffffff),
|
|
|
|
info.szCSDVersion);
|
|
|
|
if (info.szCSDVersion[0])
|
1999-02-17 00:00:00 +00:00
|
|
|
Printf (PRINT_HIGH, " %s\n", info.szCSDVersion);
|
1998-07-14 00:00:00 +00:00
|
|
|
|
|
|
|
if (OSPlatform == os_Win32s) {
|
|
|
|
I_FatalError ("Sorry, Win32s is not currently supported.\n"
|
|
|
|
"(And probably never will be.)\n"
|
|
|
|
"Upgrade to a newer version of Windows.");
|
|
|
|
} else if (OSPlatform == os_unknown) {
|
1999-02-17 00:00:00 +00:00
|
|
|
Printf (PRINT_HIGH, "(Assuming Windows 95)\n");
|
1998-07-14 00:00:00 +00:00
|
|
|
OSPlatform = os_Win95;
|
|
|
|
}
|
|
|
|
}
|
1998-04-07 00:00:00 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// I_Init
|
|
|
|
//
|
|
|
|
void I_Init (void)
|
|
|
|
{
|
1998-04-07 00:00:00 +00:00
|
|
|
#ifndef USEASM
|
|
|
|
UseMMX = 0;
|
|
|
|
#else
|
|
|
|
char vendorid[13];
|
|
|
|
|
|
|
|
vendorid[0] = vendorid[12] = 0;
|
|
|
|
UseMMX = CheckMMX (vendorid);
|
|
|
|
if (M_CheckParm ("-nommx"))
|
|
|
|
UseMMX = 0;
|
|
|
|
|
|
|
|
if (vendorid[0])
|
1999-02-17 00:00:00 +00:00
|
|
|
Printf (PRINT_HIGH, "CPUID: %s (", vendorid);
|
1998-04-07 00:00:00 +00:00
|
|
|
|
|
|
|
if (UseMMX)
|
1999-02-17 00:00:00 +00:00
|
|
|
Printf (PRINT_HIGH, "using MMX)\n");
|
1998-04-07 00:00:00 +00:00
|
|
|
else
|
1999-02-17 00:00:00 +00:00
|
|
|
Printf (PRINT_HIGH, "not using MMX)\n");
|
1998-04-07 00:00:00 +00:00
|
|
|
#endif
|
|
|
|
|
1998-07-14 00:00:00 +00:00
|
|
|
// [RH] Support for BOOM's -fastdemo
|
|
|
|
if (fastdemo)
|
|
|
|
I_GetTime = I_GetTimeFake;
|
|
|
|
else
|
|
|
|
I_GetTime = I_GetTimeReally;
|
|
|
|
|
1998-04-07 00:00:00 +00:00
|
|
|
I_InitSound();
|
1998-07-14 00:00:00 +00:00
|
|
|
I_InitInput (Window);
|
1998-04-07 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// I_Quit
|
|
|
|
//
|
1998-12-22 00:00:00 +00:00
|
|
|
static int has_exited;
|
1998-04-07 00:00:00 +00:00
|
|
|
|
1999-02-17 00:00:00 +00:00
|
|
|
void STACK_ARGS I_Quit (void)
|
1998-04-07 00:00:00 +00:00
|
|
|
{
|
1998-12-22 00:00:00 +00:00
|
|
|
has_exited = 1; /* Prevent infinitely recursive exits -- killough */
|
1998-04-07 00:00:00 +00:00
|
|
|
|
1998-12-22 00:00:00 +00:00
|
|
|
if (demorecording)
|
|
|
|
G_CheckDemoStatus();
|
|
|
|
M_SaveDefaults ();
|
1998-04-07 00:00:00 +00:00
|
|
|
|
1998-12-22 00:00:00 +00:00
|
|
|
if (errortext[0]) {
|
|
|
|
if (Window)
|
|
|
|
ShowWindow (Window, SW_HIDE);
|
|
|
|
MessageBox (Window, errortext, "ZDOOM Fatal Error", MB_OK|MB_ICONSTOP|MB_TASKMODAL);
|
1998-04-07 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// I_Error
|
|
|
|
//
|
1998-12-22 00:00:00 +00:00
|
|
|
extern FILE *Logfile;
|
|
|
|
BOOL gameisdead;
|
1998-04-07 00:00:00 +00:00
|
|
|
|
1999-02-17 00:00:00 +00:00
|
|
|
void STACK_ARGS I_FatalError (char *error, ...)
|
1998-04-07 00:00:00 +00:00
|
|
|
{
|
1998-12-22 00:00:00 +00:00
|
|
|
gameisdead = true;
|
|
|
|
|
|
|
|
if (!errortext[0]) // ignore all but the first message -- killough
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
va_list argptr;
|
|
|
|
va_start (argptr, error);
|
|
|
|
index = vsprintf (errortext, error, argptr);
|
|
|
|
sprintf (errortext + index, "\nGetLastError = %d", GetLastError());
|
|
|
|
va_end (argptr);
|
|
|
|
}
|
1998-04-07 00:00:00 +00:00
|
|
|
|
1998-12-22 00:00:00 +00:00
|
|
|
if (!has_exited) // If it hasn't exited yet, exit now -- killough
|
|
|
|
{
|
|
|
|
has_exited = 1; // Prevent infinitely recursive exits -- killough
|
1998-07-14 00:00:00 +00:00
|
|
|
|
1998-12-22 00:00:00 +00:00
|
|
|
// [RH] Record error to log (if logging)
|
|
|
|
if (Logfile)
|
|
|
|
fprintf (Logfile, "\n**** DIED WITH FATAL ERROR:\n%s\n", errortext);
|
|
|
|
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
}
|
1998-04-07 00:00:00 +00:00
|
|
|
|
1999-02-17 00:00:00 +00:00
|
|
|
void STACK_ARGS I_Error (char *error, ...)
|
1998-12-22 00:00:00 +00:00
|
|
|
{
|
|
|
|
va_list argptr;
|
1998-04-07 00:00:00 +00:00
|
|
|
|
1998-12-22 00:00:00 +00:00
|
|
|
va_start (argptr, error);
|
|
|
|
vsprintf (errortext, error, argptr);
|
|
|
|
va_end (argptr);
|
1998-04-07 00:00:00 +00:00
|
|
|
|
1998-12-22 00:00:00 +00:00
|
|
|
if (errorjmpable)
|
|
|
|
longjmp (errorjmp, 1);
|
|
|
|
else
|
|
|
|
I_FatalError (NULL);
|
1998-04-07 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
1998-12-22 00:00:00 +00:00
|
|
|
char DoomStartupTitle[256] = { 0 };
|
1998-04-07 00:00:00 +00:00
|
|
|
|
1998-07-14 00:00:00 +00:00
|
|
|
void I_SetTitleString (const char *title)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
1998-12-22 00:00:00 +00:00
|
|
|
for (i = 0; title[i]; i++)
|
|
|
|
DoomStartupTitle[i] = title[i] | 0x80;
|
1998-07-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void I_PrintStr (int xp, const char *cp, int count, BOOL scroll) {
|
1999-02-21 00:00:00 +00:00
|
|
|
// used in the DOS version
|
1998-12-22 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
1999-02-21 00:00:00 +00:00
|
|
|
long I_FindFirst (char *filespec, findstate_t *fileinfo)
|
1998-12-22 00:00:00 +00:00
|
|
|
{
|
1999-02-21 00:00:00 +00:00
|
|
|
return _findfirst (filespec, fileinfo);
|
|
|
|
}
|
|
|
|
int I_FindNext (long handle, findstate_t *fileinfo)
|
|
|
|
{
|
|
|
|
return _findnext (handle, fileinfo);
|
|
|
|
}
|
1998-12-22 00:00:00 +00:00
|
|
|
|
1999-02-21 00:00:00 +00:00
|
|
|
int I_FindClose (long handle)
|
|
|
|
{
|
|
|
|
return _findclose (handle);
|
1998-12-22 00:00:00 +00:00
|
|
|
}
|