2000-05-10 20:33:16 +00:00
|
|
|
/*
|
2000-05-20 02:00:28 +00:00
|
|
|
cl_sys_unix.c
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
(description)
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
2000-05-20 02:00:28 +00:00
|
|
|
Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
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.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
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.
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-05-11 16:03:29 +00:00
|
|
|
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:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
$Id$
|
2000-05-10 20:33:16 +00:00
|
|
|
*/
|
2000-05-11 16:03:29 +00:00
|
|
|
|
2000-05-17 10:03:19 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2000-12-08 06:51:37 +00:00
|
|
|
# include "config.h"
|
2000-05-17 10:03:19 +00:00
|
|
|
#endif
|
2000-05-20 02:00:28 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2000-05-10 20:33:16 +00:00
|
|
|
#include <stdlib.h>
|
2000-05-20 02:00:28 +00:00
|
|
|
#include <errno.h>
|
2000-05-10 20:33:16 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
2000-05-20 02:00:28 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <sys/types.h>
|
2000-05-10 20:33:16 +00:00
|
|
|
#include <sys/mman.h>
|
|
|
|
|
2000-12-30 05:18:48 +00:00
|
|
|
#include "cvar.h"
|
2000-12-05 06:33:44 +00:00
|
|
|
#include "host.h"
|
2000-05-21 08:24:45 +00:00
|
|
|
#include "qargs.h"
|
2000-12-05 06:33:44 +00:00
|
|
|
#include "sys.h"
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
int noconinput = 0;
|
|
|
|
qboolean is_server = false;
|
2001-02-08 19:24:27 +00:00
|
|
|
char *svs_info;
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2001-02-08 17:38:25 +00:00
|
|
|
#ifdef PACKET_LOGGING
|
|
|
|
void Net_LogStop (void);
|
|
|
|
#endif
|
2000-05-14 16:56:28 +00:00
|
|
|
|
2000-05-10 20:33:16 +00:00
|
|
|
// =======================================================================
|
|
|
|
// General routines
|
|
|
|
// =======================================================================
|
|
|
|
|
2000-10-31 05:24:34 +00:00
|
|
|
void
|
|
|
|
Sys_Quit (void)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
Host_Shutdown ();
|
|
|
|
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
|
2001-01-16 18:03:50 +00:00
|
|
|
|
|
|
|
#ifdef PACKET_LOGGING
|
|
|
|
Net_LogStop();
|
|
|
|
#endif
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
exit (0);
|
2000-05-10 20:33:16 +00:00
|
|
|
}
|
|
|
|
|
2000-10-31 05:24:34 +00:00
|
|
|
void
|
|
|
|
Sys_Init_Cvars (void)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
2000-12-31 04:46:04 +00:00
|
|
|
sys_nostdout = Cvar_Get ("sys_nostdout", "0", CVAR_NONE, "set to disable std out");
|
2000-12-08 06:51:37 +00:00
|
|
|
if (COM_CheckParm ("-nostdout"))
|
|
|
|
Cvar_Set (sys_nostdout, "1");
|
2000-10-31 05:24:34 +00:00
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Sys_Init (void)
|
2000-10-31 05:24:34 +00:00
|
|
|
{
|
2000-05-17 20:50:22 +00:00
|
|
|
#ifdef USE_INTEL_ASM
|
2000-12-08 06:51:37 +00:00
|
|
|
Sys_SetFPCW ();
|
2000-05-10 20:33:16 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Sys_Error (char *error, ...)
|
|
|
|
{
|
|
|
|
va_list argptr;
|
|
|
|
char string[1024];
|
2000-05-10 20:33:16 +00:00
|
|
|
|
|
|
|
// change stdin to non blocking
|
2000-12-08 06:51:37 +00:00
|
|
|
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
|
|
|
|
|
|
|
|
va_start (argptr, error);
|
|
|
|
vsnprintf (string, sizeof (string), error, argptr);
|
|
|
|
va_end (argptr);
|
|
|
|
fprintf (stderr, "Error: %s\n", string);
|
2000-05-10 20:33:16 +00:00
|
|
|
|
|
|
|
Host_Shutdown ();
|
|
|
|
exit (1);
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
}
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Sys_Warn (char *warning, ...)
|
|
|
|
{
|
|
|
|
va_list argptr;
|
|
|
|
char string[1024];
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
va_start (argptr, warning);
|
|
|
|
vsnprintf (string, sizeof (string), warning, argptr);
|
|
|
|
va_end (argptr);
|
|
|
|
fprintf (stderr, "Warning: %s", string);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Sys_DebugLog (char *file, char *fmt, ...)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
va_list argptr;
|
|
|
|
static char data[1024]; // why static ?
|
|
|
|
int fd;
|
2000-05-15 08:59:12 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
va_start (argptr, fmt);
|
|
|
|
vsnprintf (data, sizeof (data), fmt, argptr);
|
|
|
|
va_end (argptr);
|
2000-05-10 20:33:16 +00:00
|
|
|
// fd = open(file, O_WRONLY | O_BINARY | O_CREAT | O_APPEND, 0666);
|
2000-12-08 06:51:37 +00:00
|
|
|
fd = open (file, O_WRONLY | O_CREAT | O_APPEND, 0666);
|
|
|
|
write (fd, data, strlen (data));
|
|
|
|
close (fd);
|
2000-05-10 20:33:16 +00:00
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
floating_point_exception_handler (int whatever)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
// Sys_Warn("floating point exception\n");
|
|
|
|
signal (SIGFPE, floating_point_exception_handler);
|
2000-05-10 20:33:16 +00:00
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
char *
|
|
|
|
Sys_ConsoleInput (void)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
|
|
|
#if 0
|
2000-12-08 06:51:37 +00:00
|
|
|
static char text[256];
|
|
|
|
int len;
|
2000-05-10 20:33:16 +00:00
|
|
|
|
|
|
|
if (cls.state == ca_dedicated) {
|
2000-12-08 06:51:37 +00:00
|
|
|
len = read (0, text, sizeof (text));
|
2000-05-10 20:33:16 +00:00
|
|
|
if (len < 1)
|
|
|
|
return NULL;
|
2000-12-08 06:51:37 +00:00
|
|
|
text[len - 1] = 0; // rip off the /n and terminate
|
2000-05-10 20:33:16 +00:00
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-05-17 20:50:22 +00:00
|
|
|
#ifndef USE_INTEL_ASM
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Sys_HighFPPrecision (void)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Sys_LowFPPrecision (void)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
int skipframes;
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
int
|
|
|
|
main (int c, char **v)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
2000-12-08 06:51:37 +00:00
|
|
|
double time, oldtime, newtime;
|
|
|
|
int j;
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
// static char cwd[1024];
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
// signal(SIGFPE, floating_point_exception_handler);
|
|
|
|
signal (SIGFPE, SIG_IGN);
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
memset (&host_parms, 0, sizeof (host_parms));
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
COM_InitArgv (c, v);
|
2000-11-27 13:17:48 +00:00
|
|
|
host_parms.argc = com_argc;
|
|
|
|
host_parms.argv = com_argv;
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-11-27 13:17:48 +00:00
|
|
|
host_parms.memsize = 8 * 1024 * 1024; // 8MB default heap
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
j = COM_CheckParm ("-mem");
|
2000-05-10 20:33:16 +00:00
|
|
|
if (j)
|
2000-12-08 06:51:37 +00:00
|
|
|
host_parms.memsize = (int) (atof (com_argv[j + 1]) * 1024 * 1024);
|
2000-11-27 13:17:48 +00:00
|
|
|
host_parms.membase = malloc (host_parms.memsize);
|
|
|
|
if (!host_parms.membase) {
|
2000-12-08 06:51:37 +00:00
|
|
|
printf ("Can't allocate memory for zone.\n");
|
2000-05-15 00:43:19 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
noconinput = COM_CheckParm ("-noconinput");
|
2000-05-10 20:33:16 +00:00
|
|
|
if (!noconinput)
|
2000-12-08 06:51:37 +00:00
|
|
|
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK);
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
Host_Init ();
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
oldtime = Sys_DoubleTime ();
|
|
|
|
while (1) {
|
2000-12-12 06:17:02 +00:00
|
|
|
// find time spent rendering last frame
|
2000-12-08 06:51:37 +00:00
|
|
|
newtime = Sys_DoubleTime ();
|
|
|
|
time = newtime - oldtime;
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
Host_Frame (time);
|
2000-05-10 20:33:16 +00:00
|
|
|
oldtime = newtime;
|
2000-12-08 06:51:37 +00:00
|
|
|
}
|
2000-05-10 20:33:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2001-02-09 02:53:09 +00:00
|
|
|
Sys_MakeCodeWriteable
|
2000-05-10 20:33:16 +00:00
|
|
|
*/
|
2000-12-08 06:51:37 +00:00
|
|
|
void
|
|
|
|
Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
|
2000-05-10 20:33:16 +00:00
|
|
|
{
|
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
int r;
|
2000-05-10 20:33:16 +00:00
|
|
|
unsigned long addr;
|
2000-12-08 06:51:37 +00:00
|
|
|
int psize = getpagesize ();
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
addr = (startaddr & ~(psize - 1)) - psize;
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
// fprintf(stderr, "writable code %lx(%lx)-%lx, length=%lx\n", startaddr,
|
|
|
|
// addr, startaddr+length, length);
|
2000-05-10 20:33:16 +00:00
|
|
|
|
2000-12-08 06:51:37 +00:00
|
|
|
r = mprotect ((char *) addr, length + startaddr - addr + psize, 7);
|
2000-05-10 20:33:16 +00:00
|
|
|
|
|
|
|
if (r < 0)
|
2000-12-08 06:51:37 +00:00
|
|
|
Sys_Error ("Protection change failed\n");
|
2000-05-10 20:33:16 +00:00
|
|
|
|
|
|
|
}
|