backport 0.5's sys stuff. much saner linking.

This commit is contained in:
Bill Currie 2001-08-20 22:08:54 +00:00
parent 4fa410afef
commit 1ed975edd5
13 changed files with 554 additions and 808 deletions

View file

@ -236,9 +236,10 @@ AC_FUNC_MMAP
AC_TYPE_SIGNAL
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(
access _access \
connect dlopen fcntl ftime getaddrinfo gethostname gethostbyname \
getnameinfo gettimeofday mkdir select socket stat strerror \
strstr snprintf vsnprintf _snprintf _vsnprintf
getnameinfo gettimeofday mkdir _mkdir select socket stat strerror \
strstr snprintf vsnprintf _snprintf _vsnprintf mprotect
)
dnl Checks for stricmp/strcasecmp

View file

@ -26,49 +26,30 @@
$Id$
*/
#ifndef _SYS_H
#define _SYS_H
#ifndef __sys_h
#define __sys_h
#include "gcc_attr.h"
#include <stdarg.h>
//
// file IO
//
#include "QF/gcc_attr.h"
// returns the file size
// return -1 if file is not present
// the file should be in BINARY mode for stupid OSs that care
int Sys_FileOpenRead (char *path, int *hndl);
extern struct cvar_s *sys_nostdout;
int Sys_FileOpenWrite (char *path);
void Sys_FileClose (int handle);
void Sys_FileSeek (int handle, int position);
int Sys_FileRead (int handle, void *dest, int count);
int Sys_FileWrite (int handle, void *data, int count);
int Sys_FileTime (char *path);
void Sys_mkdir (char *path);
extern const char sys_char_map[256];
//
// memory protection
//
void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length);
int Sys_FileTime (const char *path);
void Sys_mkdir (const char *path);
//
// system IO
//
void Sys_DebugLog(char *file, char *fmt, ...) __attribute__((format(printf,2,3)));
typedef void (*sys_printf_t) (const char *fmt, va_list args);
void Sys_Error (char *error, ...) __attribute__((format(printf,1,2)));
// an error will cause the entire program to exit
void Sys_Printf (char *fmt, ...) __attribute__((format(printf,1,2)));
// send text to the console
void Sys_SetPrintf (sys_printf_t func);
void Sys_Printf (const char *fmt, ...) __attribute__((format(printf,1,2)));
void Sys_Error (const char *error, ...) __attribute__((format(printf,1,2), noreturn));
void Sys_Quit (void);
double Sys_DoubleTime (void);
char *Sys_ConsoleInput (void);
const char *Sys_ConsoleInput (void);
void Sys_Sleep (void);
// called to yield for a little bit so as
@ -78,11 +59,19 @@ void Sys_LowFPPrecision (void);
void Sys_HighFPPrecision (void);
void Sys_SetFPCW (void);
void Sys_Printf (char *fmt, ...) __attribute__((format(printf,1,2)));
// send text to the console
void Sys_Init (void);
void Sys_Init_Cvars (void);
#endif // _SYS_H
//
// memory protection
//
void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length);
//
// system IO
//
void Sys_DebugLog(const char *file, const char *fmt, ...) __attribute__((format(printf,2,3)));
#endif // __sys_h

View file

@ -31,7 +31,7 @@ AUTOMAKE_OPTIONS= foreign
#
# Stuff that is common to both client and server
#
INCLUDES= -I$(top_srcdir)/include $(GGI_CFLAGS) $(MGL_CFLAGS) $(SDL_CFLAGS) $(SVGA_CFLAGS) $(X_CFLAGS) $(GLX_CFLAGS) $(TDFXGL_CFLAGS)
INCLUDES= -I$(top_srcdir)/include $(GGI_CFLAGS) $(MGL_CFLAGS) $(SVGA_CFLAGS) $(X_CFLAGS) $(GLX_CFLAGS) $(TDFXGL_CFLAGS)
bin_PROGRAMS = @TARGETS@
@ -71,11 +71,11 @@ EXTRA_libqfnet_a_SOURCES= net_chan.c net_com.c net_udp.c net_udp6.c
# ... System type
#
if SYSTYPE_WIN32
libqfsys_sv_a_SOURCES= fnmatch.c dirent.c sv_sys_win.c sys_win.c
libqfsys_sv_a_SOURCES= fnmatch.c dirent.c sv_sys_win.c sys.c
else
libqfsys_sv_a_SOURCES= sv_sys_unix.c sys_unix.c
libqfsys_sv_a_SOURCES= sv_sys_unix.c sys.c
endif
EXTRA_libqfsys_sv_a_SOURCES= fnmatch.c dirent.c sv_sys_unix.c sv_sys_win.c sys_unix.c sys_win.c
EXTRA_libqfsys_sv_a_SOURCES= fnmatch.c dirent.c sv_sys_unix.c sv_sys_win.c sys.c sys.c
server_SOURCES= pr_edict.c pr_exec.c pr_offs.c sv_ccmds.c sv_cvar.c \
sv_ents.c sv_init.c sv_main.c sv_misc.c sv_model.c \
@ -92,11 +92,11 @@ qf_server_DEPENDENCIES= libqfnet.a libqfsys_sv.a
# ... System type
#
if SYSTYPE_WIN32
libqfsys_cl_a_SOURCES= cl_sys_win.c fnmatch.c dirent.c sys_win.c
libqfsys_cl_a_SOURCES= cl_sys_win.c fnmatch.c dirent.c sys.c
else
libqfsys_cl_a_SOURCES= cl_sys_unix.c sys_unix.c
libqfsys_cl_a_SOURCES= cl_sys_unix.c sys.c
endif
EXTRA_libqfsys_cl_a_SOURCES= cl_sys_sdl.c cl_sys_unix.c cl_sys_win.c sys_win.c sys_unix.c fnmatch.c dirent.c
EXTRA_libqfsys_cl_a_SOURCES= cl_sys_sdl.c cl_sys_unix.c cl_sys_win.c sys.c sys.c fnmatch.c dirent.c
#
# ... Digital audio
@ -115,6 +115,7 @@ libqfsnd_a_SOURCES= snd_dma.c snd_mem.c snd_mix.c snd_oss.c
endif
if SNDTYPE_SDL
libqfsnd_a_SOURCES= snd_dma.c snd_mem.c snd_mix.c snd_sdl.c
libqfsnd_a_INCLUDES= $(SDL_CFLAGS)
endif
if SNDTYPE_SGI
libqfsnd_a_SOURCES= snd_dma.c snd_mem.c snd_mix.c snd_sgi.c
@ -140,6 +141,7 @@ libqfcd_a_SOURCES= cd_linux.c
endif
if CDTYPE_SDL
libqfcd_a_SOURCES= cd_sdl.c
libqfcd_a_INCLUDES=$(SDL_CFLAGS)
endif
if CDTYPE_SGI
libqfcd_a_SOURCES= cd_sgi.c
@ -319,3 +321,39 @@ EXTRA_DIST= makefile.mgw makefile.win \
# Kill the temp files, hopefully.
CLEANFILES = *.i *.s $(YACCLEX_CLEANFILES)
cl_sys_sdl.o: cl_sys_sdl.c
@echo '$(COMPILE) $(SDL_CFLAGS) -c $<'; \
$(COMPILE) $(SDL_CFLAGS) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
in_sdl.o: in_sdl.c
@echo '$(COMPILE) $(SDL_CFLAGS) -c $<'; \
$(COMPILE) $(SDL_CFLAGS) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
vid_sdl.o: vid_sdl.c
@echo '$(COMPILE) $(SDL_CFLAGS) -c $<'; \
$(COMPILE) $(SDL_CFLAGS) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp
vid_sgl.o: vid_sgl.c
@echo '$(COMPILE) $(SDL_CFLAGS) -c $<'; \
$(COMPILE) $(SDL_CFLAGS) -Wp,-MD,.deps/$(*F).pp -c $<
@-cp .deps/$(*F).pp .deps/$(*F).P; \
tr ' ' '\012' < .deps/$(*F).pp \
| sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
>> .deps/$(*F).P; \
rm .deps/$(*F).pp

View file

@ -26,15 +26,12 @@
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
@ -60,111 +57,51 @@
#include <SDL.h>
#include <SDL_main.h>
#include "cvar.h"
#include "sys.h"
#include "qargs.h"
#include "qargs.h"
#include "client.h"
#include "compat.h"
#include "host.h"
qboolean is_server = false;
qboolean noconinput = false;
char *svs_info;
int starttime;
int noconinput;
#ifdef _WIN32
# include "winquake.h"
// fixme: minimized is not currently supported under
// FIXME: minimized is not currently supported under
// SDL
qboolean Minimized = false;
void MaskExceptions (void);
#endif
void
Sys_DebugLog (char *file, char *fmt, ...)
{
int fd;
static char data[1024]; // why static ?
va_list argptr;
va_start (argptr, fmt);
vsnprintf (data, sizeof (data), fmt, argptr);
va_end (argptr);
fd = open (file, O_WRONLY | O_CREAT | O_APPEND, 0666);
write (fd, data, strlen (data));
close (fd);
};
/*
FILE IO
*/
Sys_Init_Cvars
int
Sys_FileTime (char *path)
{
QFile *f;
int retval;
f = Qopen (path, "rb");
if (f) {
Qclose (f);
retval = 1;
} else {
retval = -1;
}
return retval;
}
/*
SYSTEM IO
*/
/*
Sys_MakeCodeWriteable
Quake calls this so the system can register variables before host_hunklevel
is marked
*/
void
Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
Sys_Init_Cvars (void)
{
#ifdef _WIN32
DWORD flOldProtect;
// copy on write or just read-write?
if (!VirtualProtect
((LPVOID) startaddr, length, PAGE_READWRITE,
&flOldProtect)) Sys_Error ("Protection change failed\n");
#else
int r;
unsigned long addr;
int psize = getpagesize ();
addr = (startaddr & ~(psize - 1)) - psize;
// fprintf(stderr, "writable code %lx(%lx)-%lx, length=%lx\n", startaddr,
// addr, startaddr+length, length);
r = mprotect ((char *) addr, length + startaddr - addr + psize, 7);
if (r < 0)
Sys_Error ("Protection change failed\n");
#endif
sys_nostdout = Cvar_Get ("sys_nostdout", "0", CVAR_NONE, NULL,
"set to disable std out");
if (COM_CheckParm ("-nostdout"))
Cvar_Set (sys_nostdout, "1");
}
/*
Sys_Init
*/
void
Sys_Init (void)
{
#ifdef WIN32
OSVERSIONINFO vinfo;
#endif
#ifdef USE_INTEL_ASM
#ifdef _WIN32
MaskExceptions ();
@ -190,9 +127,22 @@ Sys_Init (void)
#endif
}
/*
Sys_Quit
*/
void
Sys_Error (char *error, ...)
Sys_Quit (void)
{
Host_Shutdown ();
exit (0);
}
/*
Sys_Error
*/
void
Sys_Error (const char *error, ...)
{
va_list argptr;
char text[1024];
@ -213,41 +163,53 @@ Sys_Error (char *error, ...)
exit (1);
}
void
Sys_Quit (void)
{
Host_Shutdown ();
exit (0);
}
char *
void
Sys_DebugLog (const char *file, const char *fmt, ...)
{
int fd;
static char data[1024]; // why static ?
va_list argptr;
va_start (argptr, fmt);
vsnprintf (data, sizeof (data), fmt, argptr);
va_end (argptr);
fd = open (file, O_WRONLY | O_CREAT | O_APPEND, 0666);
write (fd, data, strlen (data));
close (fd);
};
/*
Sys_ConsoleInput
Checks for a complete line of text typed in at the console, then forwards
it to the host command processor
*/
const char *
Sys_ConsoleInput (void)
{
return NULL;
}
void
Sys_Sleep (void)
{
}
void
Sys_Init_Cvars (void)
{
sys_nostdout = Cvar_Get ("sys_nostdout", "0", CVAR_NONE, NULL, "Set to disable std out");
if (COM_CheckParm ("-nostdout"))
Cvar_Set (sys_nostdout, "1");
}
#ifndef SDL_main
# define SDL_main main
#endif
/*
main
*/
int
SDL_main (int c, char **v)
{
double time, oldtime, newtime;
int j;
@ -261,7 +223,7 @@ SDL_main (int c, char **v)
host_parms.argc = com_argc;
host_parms.argv = com_argv;
host_parms.memsize = 16 * 1024 * 1024;
host_parms.memsize = 16 * 1024 * 1024; // 16MB default heap
j = COM_CheckParm ("-mem");
if (j)
@ -272,6 +234,7 @@ SDL_main (int c, char **v)
printf ("Can't allocate memory for zone.\n");
return 1;
}
#ifndef WIN32
noconinput = COM_CheckParm ("-noconinput");
if (!noconinput)
@ -282,17 +245,15 @@ SDL_main (int c, char **v)
oldtime = Sys_DoubleTime ();
while (1) {
// find time spent rendering last frame
// find time spent rendering last frame
newtime = Sys_DoubleTime ();
time = newtime - oldtime;
Host_Frame (time);
oldtime = newtime;
}
}
/* fixme: evil stub for directsound crap */
void
IN_Accumulate (void)
{

View file

@ -45,39 +45,28 @@
#include <sys/mman.h>
#include "cvar.h"
#include "host.h"
#include "qargs.h"
#include "sys.h"
#include "host.h"
#include "net.h"
int noconinput = 0;
qboolean is_server = false;
char *svs_info;
#ifdef PACKET_LOGGING
void Net_LogStop (void);
#endif
// =======================================================================
// General routines
// =======================================================================
void
Sys_Quit (void)
{
Host_Shutdown ();
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
#ifdef PACKET_LOGGING
Net_LogStop();
#endif
exit (0);
}
/*
Sys_Init_Cvars
Quake calls this so the system can register variables before host_hunklevel
is marked
*/
void
Sys_Init_Cvars (void)
{
sys_nostdout = Cvar_Get ("sys_nostdout", "0", CVAR_NONE, NULL, "set to disable std out");
sys_nostdout = Cvar_Get ("sys_nostdout", "0", CVAR_NONE, NULL,
"set to disable std out");
if (COM_CheckParm ("-nostdout"))
Cvar_Set (sys_nostdout, "1");
}
@ -90,8 +79,25 @@ Sys_Init (void)
#endif
}
/*
Sys_Quit
*/
void
Sys_Error (char *error, ...)
Sys_Quit (void)
{
Host_Shutdown ();
fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NONBLOCK);
//Net_LogStop();
exit (0);
}
/*
Sys_Error
*/
void
Sys_Error (const char *error, ...)
{
va_list argptr;
char string[1024];
@ -106,7 +112,6 @@ Sys_Error (char *error, ...)
Host_Shutdown ();
exit (1);
}
void
@ -122,7 +127,7 @@ Sys_Warn (char *warning, ...)
}
void
Sys_DebugLog (char *file, char *fmt, ...)
Sys_DebugLog (const char *file, const char *fmt, ...)
{
va_list argptr;
static char data[1024]; // why static ?
@ -131,20 +136,28 @@ Sys_DebugLog (char *file, char *fmt, ...)
va_start (argptr, fmt);
vsnprintf (data, sizeof (data), fmt, argptr);
va_end (argptr);
// fd = open(file, O_WRONLY | O_BINARY | O_CREAT | O_APPEND, 0666);
// fd = open(file, O_WRONLY | O_BINARY | O_CREAT | O_APPEND, 0666);
fd = open (file, O_WRONLY | O_CREAT | O_APPEND, 0666);
write (fd, data, strlen (data));
close (fd);
}
void
floating_point_exception_handler (int whatever)
{
// Sys_Warn("floating point exception\n");
// Sys_Warn("floating point exception\n");
signal (SIGFPE, floating_point_exception_handler);
}
char *
/*
Sys_ConsoleInput
Checks for a complete line of text typed in at the console, then forwards
it to the host command processor
*/
const char *
Sys_ConsoleInput (void)
{
#if 0
@ -163,12 +176,14 @@ Sys_ConsoleInput (void)
return NULL;
}
#ifndef USE_INTEL_ASM
void
Sys_HighFPPrecision (void)
{
}
void
Sys_LowFPPrecision (void)
{
@ -177,15 +192,18 @@ Sys_LowFPPrecision (void)
int skipframes;
/*
main
*/
int
main (int c, char **v)
main (int c, char *v[])
{
double time, oldtime, newtime;
int j;
// static char cwd[1024];
// static char cwd[1024];
// signal(SIGFPE, floating_point_exception_handler);
// signal(SIGFPE, floating_point_exception_handler);
signal (SIGFPE, SIG_IGN);
memset (&host_parms, 0, sizeof (host_parms));
@ -194,12 +212,13 @@ main (int c, char **v)
host_parms.argc = com_argc;
host_parms.argv = com_argv;
host_parms.memsize = 16 * 1024 * 1024; // 8MB default heap
host_parms.memsize = 16 * 1024 * 1024; // 16MB default heap
j = COM_CheckParm ("-mem");
if (j)
host_parms.memsize = (int) (atof (com_argv[j + 1]) * 1024 * 1024);
host_parms.membase = malloc (host_parms.memsize);
if (!host_parms.membase) {
printf ("Can't allocate memory for zone.\n");
return 1;
@ -221,27 +240,3 @@ main (int c, char **v)
oldtime = newtime;
}
}
/*
Sys_MakeCodeWriteable
*/
void
Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
{
int r;
unsigned long addr;
int psize = getpagesize ();
addr = (startaddr & ~(psize - 1)) - psize;
// fprintf(stderr, "writable code %lx(%lx)-%lx, length=%lx\n", startaddr,
// addr, startaddr+length, length);
r = mprotect ((char *) addr, length + startaddr - addr + psize, 7);
if (r < 0)
Sys_Error ("Protection change failed\n");
}

View file

@ -38,16 +38,20 @@
#include <conio.h>
#include <windows.h>
#include "client.h"
#include "console.h"
#include "host.h"
#include "cvar.h"
#include "qargs.h"
#include "resource.h"
#include "screen.h"
#include "sound.h"
#include "sys.h"
#include "vid.h"
#include "client.h"
#include "compat.h"
#include "host.h"
#include "net.h"
#include "resource.h"
qboolean is_server = false;
char *svs_info;
@ -78,92 +82,18 @@ void MaskExceptions (void);
void Sys_PopFPCW (void);
void Sys_PushFPCW_SetHigh (void);
void
Sys_DebugLog (char *file, char *fmt, ...)
{
va_list argptr;
static char data[1024];
int fd;
va_start (argptr, fmt);
vsnprintf (data, sizeof (data), fmt, argptr);
va_end (argptr);
fd = open (file, O_WRONLY | O_CREAT | O_APPEND, 0666);
write (fd, data, strlen (data));
close (fd);
};
/*
FILE IO
Sys_Init_Cvars
Quake calls this so the system can register variables before host_hunklevel
is marked
*/
/*
wfilelength
*/
int
wfilelength (QFile *f)
{
int pos;
int end;
pos = Qtell (f);
Qseek (f, 0, SEEK_END);
end = Qtell (f);
Qseek (f, pos, SEEK_SET);
return end;
}
int
Sys_FileTime (char *path)
{
QFile *f;
int t, retval;
t = VID_ForceUnlockedAndReturnState ();
f = Qopen (path, "rb");
if (f) {
Qclose (f);
retval = 1;
} else {
retval = -1;
}
VID_ForceLockState (t);
return retval;
}
/*
SYSTEM IO
*/
/*
Sys_MakeCodeWriteable
*/
void
Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
{
DWORD flOldProtect;
//@@@ copy on write or just read-write?
if (!VirtualProtect
((LPVOID) startaddr, length, PAGE_READWRITE,
&flOldProtect)) Sys_Error ("Protection change failed\n");
}
/*
Sys_Init
*/
void
Sys_Init_Cvars (void)
{
sys_nostdout = Cvar_Get ("sys_nostdout", "1", CVAR_NONE, NULL, "unset to enable std out - windows does NOT support this");
sys_nostdout = Cvar_Get ("sys_nostdout", "1", CVAR_NONE, NULL,
"unset to enable std out - windows does NOT support this");
}
void
@ -213,9 +143,32 @@ Sys_Init (void)
WinNT = false;
}
/*
Sys_Quit
*/
void
Sys_Error (char *error, ...)
Sys_Quit (void)
{
VID_ForceUnlockedAndReturnState ();
Host_Shutdown ();
if (tevent)
CloseHandle (tevent);
if (qwclsemaphore)
CloseHandle (qwclsemaphore);
//Net_LogStop();
exit (0);
}
/*
Sys_Error
*/
void
Sys_Error (const char *error, ...)
{
va_list argptr;
char text[1024]; // , text2[1024];
@ -236,28 +189,42 @@ Sys_Error (char *error, ...)
}
void
Sys_Quit (void)
Sys_DebugLog (const char *file, const char *fmt, ...)
{
VID_ForceUnlockedAndReturnState ();
va_list argptr;
static char data[1024];
int fd;
Host_Shutdown ();
va_start (argptr, fmt);
vsnprintf (data, sizeof (data), fmt, argptr);
va_end (argptr);
fd = open (file, O_WRONLY | O_CREAT | O_APPEND, 0666);
write (fd, data, strlen (data));
close (fd);
};
if (tevent)
CloseHandle (tevent);
if (qwclsemaphore)
CloseHandle (qwclsemaphore);
int
wfilelength (QFile *f)
{
int pos;
int end;
#ifdef PACKET_LOGGING
Net_LogStop();
#endif
pos = Qtell (f);
Qseek (f, 0, SEEK_END);
end = Qtell (f);
Qseek (f, pos, SEEK_SET);
exit (0);
return end;
}
/*
Sys_ConsoleInput
char *
Checks for a complete line of text typed in at the console, then forwards
it to the host command processor
*/
const char *
Sys_ConsoleInput (void)
{
static char text[256];
@ -362,7 +329,6 @@ Sys_ConsoleInput (void)
}
}
}
return NULL;
}
@ -371,6 +337,13 @@ Sys_Sleep (void)
{
}
void
SleepUntilInput (int time)
{
MsgWaitForMultipleObjects (1, &tevent, FALSE, time, QS_ALLINPUT);
}
void
IN_SendKeyEvents (void)
@ -389,37 +362,20 @@ IN_SendKeyEvents (void)
}
/*
WINDOWS CRAP
*/
/*
WinMain
*/
void
SleepUntilInput (int time)
{
MsgWaitForMultipleObjects (1, &tevent, FALSE, time, QS_ALLINPUT);
}
/*
WinMain
*/
HINSTANCE global_hInstance;
int global_nCmdShow;
char *argv[MAX_NUM_ARGVS];
static char *empty_string = "";
/*
main
*/
int WINAPI
WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nCmdShow)
{
// MSG msg;
// MSG msg;
double time, oldtime, newtime;
MEMORYSTATUS lpBuffer;
static char cwd[1024];
@ -462,7 +418,6 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
*lpCmdLine = 0;
lpCmdLine++;
}
}
}
@ -523,8 +478,8 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
if (!tevent)
Sys_Error ("Couldn't create event");
// because sound is off until we become active
S_BlockSound ();
// because sound is off until we become active
//XXX S_BlockSound ();
Sys_Printf ("Host_Init\n");
Host_Init ();

View file

@ -1373,7 +1373,7 @@ SV_GetConsoleCommands (void)
char *cmd;
while (1) {
cmd = Sys_ConsoleInput ();
cmd = (char*)Sys_ConsoleInput ();
if (!cmd)
break;
Cbuf_AddText (cmd);

View file

@ -47,9 +47,10 @@
#include "cvar.h"
#include "qargs.h"
#include "server.h"
#include "sys.h"
#include "server.h"
#ifdef NeXT
# include <libc.h>
#endif
@ -64,14 +65,49 @@ char *svs_info = svs.info;
/*
REQUIRED SYS FUNCTIONS
Sys_Init_Cvars
Quake calls this so the system can register variables before host_hunklevel
is marked
*/
void
Sys_Init_Cvars (void)
{
sys_nostdout = Cvar_Get ("sys_nostdout", "0", CVAR_NONE, NULL,
"Toggles console screen output");
sys_extrasleep = Cvar_Get ("sys_extrasleep", "0", CVAR_NONE, NULL,
"Set to cause whatever amount delay in microseconds you want. Mostly useful to generate simulated bad connections.");
sys_dead_sleep = Cvar_Get ("sys_dead_sleep", "1", CVAR_NONE, NULL,
"When set, the server gets NO cpu if no clients are connected"
"and there's no other activity. *MIGHT* cause problems with"
"some mods.");
}
void
Sys_Init (void)
{
#ifdef USE_INTEL_ASM
Sys_SetFPCW ();
#endif
}
/*
Sys_Quit
*/
void
Sys_Quit (void)
{
//Net_LogStop();
exit (0);
}
/*
Sys_Error
*/
void
Sys_Error (char *error, ...)
Sys_Error (const char *error, ...)
{
va_list argptr;
char string[1024];
@ -85,20 +121,6 @@ Sys_Error (char *error, ...)
}
/*
Sys_Quit
*/
void
Sys_Quit (void)
{
#ifdef PACKET_LOGGING
Net_LogStop();
#endif
exit (0); // appkit isn't running
}
static int do_stdin = 1;
/*
@ -107,7 +129,7 @@ static int do_stdin = 1;
Checks for a complete line of text typed in at the console, then forwards
it to the host command processor
*/
char *
const char *
Sys_ConsoleInput (void)
{
static char text[256];
@ -130,32 +152,6 @@ Sys_ConsoleInput (void)
return text;
}
/*
Sys_Init
Quake calls this so the system can register variables before host_hunklevel
is marked
*/
void
Sys_Init_Cvars (void)
{
sys_nostdout = Cvar_Get ("sys_nostdout", "0", CVAR_NONE, NULL, "Toggles console screen output");
sys_extrasleep = Cvar_Get ("sys_extrasleep", "0", CVAR_NONE, NULL,
"Set to cause whatever amount delay in microseconds you want. Mostly useful to generate simulated bad connections.");
sys_dead_sleep = Cvar_Get ("sys_dead_sleep", "1", CVAR_NONE, NULL,
"When set, the server gets NO cpu if no clients are connected"
"and there's no other activity. *MIGHT* cause problems with"
"some mods.");
}
void
Sys_Init (void)
{
#ifdef USE_INTEL_ASM
Sys_SetFPCW ();
#endif
}
/*
main
*/

View file

@ -1,5 +1,5 @@
/*
sys_win.c
sv_sys_win.c
(description)
@ -35,6 +35,7 @@
#include <winsock.h>
#include <conio.h>
#include "compat.h"
#include "qargs.h"
#include "cvar.h"
#include "server.h"
@ -49,29 +50,65 @@ char *svs_info = svs.info;
extern cvar_t *sys_nostdout;
cvar_t *sys_sleep;
/*
Sys_FileTime
Sys_Init_Cvars
Quake calls this so the system can register variables before host_hunklevel
is marked
*/
int
Sys_FileTime (char *path)
void
Sys_Init_Cvars (void)
{
QFile *f;
f = Qopen (path, "rb");
if (f) {
Qclose (f);
return 1;
}
return -1;
sys_nostdout = Cvar_Get ("sys_nostdout", "0", CVAR_NONE, NULL,
"Toggle console output");
sys_sleep = Cvar_Get ("sys_sleep", "8", CVAR_NONE, NULL,
"Sleep how long in seconds between checking for connections. minimum is 0, maximum is 13");
}
void
Sys_Init (void)
{
OSVERSIONINFO vinfo;
#ifdef USE_INTEL_ASM
Sys_SetFPCW ();
#endif
// make sure the timer is high precision, otherwise
// NT gets 18ms resolution
timeBeginPeriod (1);
vinfo.dwOSVersionInfoSize = sizeof (vinfo);
if (!GetVersionEx (&vinfo))
Sys_Error ("Couldn't get OS info");
if ((vinfo.dwMajorVersion < 4) ||
(vinfo.dwPlatformId == VER_PLATFORM_WIN32s)) {
Sys_Error (PROGRAM " requires at least Win95 or NT 4.0");
}
if (vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
WinNT = true;
else
WinNT = false;
}
/*
Sys_Quit
*/
void
Sys_Quit (void)
{
//Net_LogStop();
exit (0);
}
/*
Sys_Error
*/
void
Sys_Error (char *error, ...)
Sys_Error (const char *error, ...)
{
va_list argptr;
char text[1024];
@ -89,8 +126,11 @@ Sys_Error (char *error, ...)
/*
Sys_ConsoleInput
Checks for a complete line of text typed in at the console, then forwards
it to the host command processor
*/
char *
const char *
Sys_ConsoleInput (void)
{
static char text[256];
@ -126,72 +166,11 @@ Sys_ConsoleInput (void)
return NULL;
}
/*
Sys_Quit
*/
void
Sys_Quit (void)
{
#ifdef PACKET_LOGGING
Net_LogStop();
#endif
exit (0);
}
/*
Sys_Init
Quake calls this so the system can register variables before host_hunklevel
is marked
*/
void
Sys_Init_Cvars (void)
{
sys_nostdout = Cvar_Get ("sys_nostdout", "0", CVAR_NONE, NULL, "Toggle console output");
sys_sleep = Cvar_Get ("sys_sleep", "8", CVAR_NONE, NULL,
"Sleep how long in seconds between checking for connections. minimum is 0, maximum is 13");
}
void
Sys_Init (void)
{
OSVERSIONINFO vinfo;
#ifdef USE_INTEL_ASM
Sys_SetFPCW ();
#endif
// make sure the timer is high precision, otherwise
// NT gets 18ms resolution
timeBeginPeriod (1);
vinfo.dwOSVersionInfoSize = sizeof (vinfo);
if (!GetVersionEx (&vinfo))
Sys_Error ("Couldn't get OS info");
if ((vinfo.dwMajorVersion < 4) ||
(vinfo.dwPlatformId == VER_PLATFORM_WIN32s)) {
Sys_Error (PROGRAM " requires at least Win95 or NT 4.0");
}
if (vinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
WinNT = true;
else
WinNT = false;
}
/*
main
*/
char *newargv[256];
#ifdef main
# if main == SDL_main
# undef main
# endif
#endif
int
main (int argc, char **argv)
{

View file

@ -1,10 +1,9 @@
/*
sys_unix.c
sys.c
(description)
virtual filesystem functions
Copyright (C) 1996-1997 Id Software, Inc.
Copyright (C) 2000 Marcus Sundberg [mackan@stacken.kth.se]
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@ -26,34 +25,48 @@
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/stat.h>
#include <stdarg.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#ifdef HAVE_STRING_H
#include <string.h>
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
#include <strings.h>
# include <strings.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_LIMITS_H
# include <limits.h>
#endif
#ifdef HAVE_IO_H
# include <io.h>
#endif
#ifdef HAVE_WINDOWS_H
# include <windows.h>
#endif
#ifdef HAVE_SYS_MMAN_H
# include <sys/mman.h>
#endif
#include "compat.h"
#include "cvar.h"
#include "host.h"
#include "qargs.h"
#include "server.h"
#include "sys.h"
static void Sys_StdPrintf (const char *fmt, va_list args);
cvar_t *sys_nostdout;
static sys_printf_t sys_printf_function = Sys_StdPrintf;
/* The translation table between the graphical font and plain ASCII --KB */
static char qfont_table[256] = {
const char sys_char_map[256] = {
'\0', '#', '#', '#', '#', '.', '#', '#',
'#', 9, 10, '#', ' ', 13, '.', '.',
'[', ']', '0', '1', '2', '3', '4', '5',
@ -90,13 +103,65 @@ static char qfont_table[256] = {
};
#define MAXPRINTMSG 4096
void
Sys_mkdir (const char *path)
{
#ifdef HAVE_MKDIR
# ifdef _WIN32
if (mkdir (path) == 0)
return;
# else
if (mkdir (path, 0777) == 0)
return;
# endif
#else
# ifdef HAVE__MKDIR
if (_mkdir (path) == 0)
return;
# else
# error do not know how to make directories
# endif
#endif
if (errno != EEXIST)
Sys_Error ("mkdir %s: %s", path, strerror (errno));
}
int
Sys_FileTime (const char *path)
{
#ifdef HAVE_ACCESS
if (access (path, R_OK) == 0)
return 0;
#else
# ifdef HAVE__ACCESS
if (_access (path, R_OK) == 0)
return 0;
# else
# error do not know how to check access
# endif
#endif
return -1;
}
/*
Sys_SetPrintf
for want of a better name, but it sets the function pointer for the
actual implementation of Sys_Printf.
*/
void
Sys_SetPrintf (sys_printf_t func)
{
sys_printf_function = func;
}
/*
Sys_Printf
*/
void
Sys_Printf (char *fmt, ...)
static void
Sys_StdPrintf (const char *fmt, va_list args)
{
va_list argptr;
char msg[MAXPRINTMSG];
unsigned char *p;
@ -104,64 +169,92 @@ Sys_Printf (char *fmt, ...)
if (sys_nostdout && sys_nostdout->int_val)
return;
va_start (argptr, fmt);
vsnprintf (msg, sizeof (msg), fmt, argptr);
va_end (argptr);
vsnprintf (msg, sizeof (msg), fmt, args);
/* translate to ASCII instead of printing [xx] --KB */
for (p = (unsigned char *) msg; *p; p++)
putc (qfont_table[*p], stdout);
putc (sys_char_map[*p], stdout);
fflush (stdout);
}
/*
Sys_FileTime
returns -1 if not present
*/
int
Sys_FileTime (char *path)
{
struct stat buf;
if (stat (path, &buf) == -1)
return -1;
return buf.st_mtime;
}
/*
Sys_mkdir
*/
void
Sys_mkdir (char *path)
Sys_Printf (const char *fmt, ...)
{
if (mkdir (path, 0777) == 0)
return;
if (errno != EEXIST)
Sys_Error ("mkdir %s: %s", path, strerror (errno));
va_list args;
va_start (args, fmt);
sys_printf_function (fmt, args);
va_end (args);
}
/*
Sys_DoubleTime
*/
double
Sys_DoubleTime (void)
{
struct timeval tp;
struct timezone tzp;
static int secbase;
static qboolean first = true;
#ifdef _WIN32
static DWORD starttime;
DWORD now;
gettimeofday (&tp, &tzp);
now = timeGetTime ();
if (!secbase) {
secbase = tp.tv_sec;
return tp.tv_usec / 1000000.0;
if (first) {
first = false;
starttime = now;
return 0.0;
}
return (tp.tv_sec - secbase) + tp.tv_usec / 1000000.0;
if (now < starttime) // wrapped?
return (now / 1000.0) + (LONG_MAX - starttime / 1000.0);
if (now - starttime == 0)
return 0.0;
return (now - starttime) / 1000.0;
#else
struct timeval tp;
struct timezone tzp;
double now;
static double start_time;
gettimeofday (&tp, &tzp);
now = tp.tv_sec + tp.tv_usec / 1e6;
if (first) {
first = false;
start_time = now;
}
return now - start_time;
#endif
}
void
Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
{
#ifdef _WIN32
DWORD flOldProtect;
if (!VirtualProtect
((LPVOID) startaddr, length, PAGE_READWRITE,
&flOldProtect)) Sys_Error ("Protection change failed\n");
#else
# ifdef HAVE_MPROTECT
int r;
unsigned long addr;
int psize = getpagesize ();
addr = (startaddr & ~(psize - 1)) - psize;
// fprintf(stderr, "writable code %lx(%lx)-%lx, length=%lx\n", startaddr,
// addr, startaddr+length, length);
r = mprotect ((char *) addr, length + startaddr - addr + psize, 7);
if (r < 0)
Sys_Error ("Protection change failed\n");
# endif
#endif
}

50
source/sys_error.c Normal file
View file

@ -0,0 +1,50 @@
/*
sys.c
virtual filesystem functions
Copyright (C) 1996-1997 Id Software, Inc.
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:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <stdio.h>
#include <stdarg.h>
#include "compat.h"
#include "sys.h"
void
QFutil_Sys_Error (const char *error, ...)
{
va_list argptr;
char string[1024];
va_start (argptr, error);
vsnprintf (string, sizeof (string), error, argptr);
fprintf (stderr, "Error: %s\n", string);
exit (1);
}
void Sys_Error (const char *error, ...) __attribute ((weak, alias ("QFutil_Sys_Error")));

View file

@ -1,173 +0,0 @@
/*
sys_null.c
null system driver to aid porting efforts
Copyright (C) 1996-1997 Id Software, Inc.
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:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <errno.h>
/*
filelength
*/
int
filelength (QFile *f)
{
int pos;
int end;
pos = Qtell (f);
Qseek (f, 0, SEEK_END);
end = Qtell (f);
Qseek (f, pos, SEEK_SET);
return end;
}
int
Sys_FileTime (char *path)
{
QFile *f;
f = Qopen (path, "rb");
if (f) {
Qclose (f);
return 1;
}
return -1;
}
void
Sys_mkdir (char *path)
{
}
/*
SYSTEM IO
*/
void
Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
{
}
void
Sys_DebugLog (char *file, char *fmt, ...)
{
}
void
Sys_Error (char *error, ...)
{
va_list argptr;
printf ("I_Error: ");
va_start (argptr, error);
vprintf (error, argptr);
va_end (argptr);
printf ("\n");
exit (1);
}
void
Sys_Printf (char *fmt, ...)
{
va_list argptr;
va_start (argptr, fmt);
vprintf (fmt, argptr);
va_end (argptr);
}
void
Sys_Quit (void)
{
exit (0);
}
double
Sys_FloatTime (void)
{
static double t;
t += 0.1;
return t;
}
char *
Sys_ConsoleInput (void)
{
return NULL;
}
void
Sys_Sleep (void)
{
}
void
IN_SendKeyEvents (void)
{
}
void
Sys_HighFPPrecision (void)
{
}
void
Sys_LowFPPrecision (void)
{
}
//=============================================================================
void
main (int argc, char **argv)
{
host_parms.memsize = 5861376;
host_parms.membase = malloc (host_parms.memsize);
COM_InitArgv (argc, argv);
host_parms.argc = com_argc;
host_parms.argv = com_argv;
printf ("Host_Init\n");
Host_Init ();
while (1) {
Host_Frame (0.1);
}
}

View file

@ -1,138 +0,0 @@
/*
sys_win.c
(description)
Copyright (C) 1996-1997 Id Software, Inc.
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:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
$Id$
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <limits.h>
#include <direct.h>
#include <windows.h>
#include "server.h"
cvar_t *sys_nostdout;
/* The translation table between the graphical font and plain ASCII --KB */
static char qfont_table[256] = {
'\0', '#', '#', '#', '#', '.', '#', '#',
'#', 9, 10, '#', ' ', 13, '.', '.',
'[', ']', '0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', '.', '<', '=', '>',
' ', '!', '"', '#', '$', '%', '&', '\'',
'(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', ':', ';', '<', '=', '>', '?',
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z', '{', '|', '}', '~', '<',
'<', '=', '>', '#', '#', '.', '#', '#',
'#', '#', ' ', '#', ' ', '>', '.', '.',
'[', ']', '0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', '.', '<', '=', '>',
' ', '!', '"', '#', '$', '%', '&', '\'',
'(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', ':', ';', '<', '=', '>', '?',
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z', '{', '|', '}', '~', '<'
};
/*
Sys_DoubleTime
*/
double
Sys_DoubleTime (void)
{
static DWORD starttime;
static qboolean first = true;
DWORD now;
now = timeGetTime ();
if (first) {
first = false;
starttime = now;
return 0.0;
}
if (now < starttime) // wrapped?
return (now / 1000.0) + (LONG_MAX - starttime / 1000.0);
if (now - starttime == 0)
return 0.0;
return (now - starttime) / 1000.0;
}
#define MAXPRINTMSG 4096
/*
Sys_Printf
*/
void
Sys_Printf (char *fmt, ...)
{
va_list argptr;
char msg[MAXPRINTMSG];
unsigned char *p;
if (sys_nostdout && sys_nostdout->int_val)
return;
va_start (argptr, fmt);
vsnprintf (msg, sizeof (msg), fmt, argptr);
va_end (argptr);
/* translate to ASCII instead of printing [xx] --KB */
for (p = (unsigned char *) msg; *p; p++)
putc (qfont_table[*p], stdout);
fflush (stdout);
}
/*
Sys_mkdir
*/
void
Sys_mkdir (char *path)
{
_mkdir (path);
}