28 char *cachedir = "/tmp";
30 cvar_t sys_linerefresh = {"sys_linerefresh","0"};// set for entity display
32 extern cvar_t timestamps;
33 extern cvar_t timeformat;
35 /* The translation table between the graphical font and plain ASCII --KB */
36 static char qfont_table[256] = {
37 '\0', '#', '#', '#', '#', '.', '#', '#',
38 '#', 9, 10, '#', ' ', 13, '.', '.',
39 '[', ']', '0', '1', '2', '3', '4', '5',
40 '6', '7', '8', '9', '.', '<', '=', '>',
41 ' ', '!', '"', '#', '$', '%', '&', '\'',
42 '(', ')', '*', '+', ',', '-', '.', '/',
43 '0', '1', '2', '3', '4', '5', '6', '7',
44 '8', '9', ':', ';', '<', '=', '>', '?',
45 '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
46 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
47 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
48 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
49 '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
50 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
51 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
52 'x', 'y', 'z', '{', '|', '}', '~', '<',
54 '<', '=', '>', '#', '#', '.', '#', '#',
55 '#', '#', ' ', '#', ' ', '>', '.', '.',
56 '[', ']', '0', '1', '2', '3', '4', '5',
57 '6', '7', '8', '9', '.', '<', '=', '>',
58 ' ', '!', '"', '#', '$', '%', '&', '\'',
59 '(', ')', '*', '+', ',', '-', '.', '/',
60 '0', '1', '2', '3', '4', '5', '6', '7',
61 '8', '9', ':', ';', '<', '=', '>', '?',
62 '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
63 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
64 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
65 'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
66 '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
67 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
68 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
69 'x', 'y', 'z', '{', '|', '}', '~', '<'
72 // =======================================================================
74 // =======================================================================
76 void Sys_DebugNumber(int y, int val)
81 void Sys_Printf (char *fmt, ...)
86 va_start (argptr,fmt);
87 vsprintf (text,fmt,argptr);
89 fprintf(stderr, "%s", text);
94 void Sys_Printf (char *fmt, ...)
98 char text[1024], *t_p;
104 va_start (argptr,fmt);
105 vsprintf (text,fmt,argptr);
111 // make sure everything goes through, even though we are non-blocking
114 r = write (1, text, l);
127 #define MAX_PRINT_MSG 4096
128 void Sys_Printf (char *fmt, ...)
131 char start[MAX_PRINT_MSG]; // String we started with
132 char stamp[MAX_PRINT_MSG]; // Time stamp
133 char final[MAX_PRINT_MSG]; // String we print
136 struct tm *local = NULL;
140 va_start (argptr, fmt);
141 vsnprintf (start, sizeof(start), fmt, argptr);
147 if (timestamps.value) {
148 mytime = time (NULL);
149 local = localtime (&mytime);
150 strftime (stamp, sizeof (stamp), timeformat.string, local);
152 snprintf (final, sizeof (final), "%s%s", stamp, start);
154 snprintf (final, sizeof (final), "%s", start);
157 for (p = (unsigned char *) final; *p; p++) {
158 putc (qfont_table[*p], stdout);
165 "\x1b[?7h\x1b[40m\x1b[2J\x1b[0;1;41m\x1b[1;1H QUAKE: The Doomed Dimension \x1b[33mby \x1b[44mid\x1b[41m Software \x1b[2;1H ---------------------------------------------------------------------------- \x1b[3;1H CALL 1-800-IDGAMES TO ORDER OR FOR TECHNICAL SUPPORT \x1b[4;1H PRICE: $45.00 (PRICES MAY VARY OUTSIDE THE US.) \x1b[5;1H \x1b[6;1H \x1b[37mYes! You only have one fourth of this incredible epic. That is because most \x1b[7;1H of you have paid us nothing or at most, very little. You could steal the \x1b[8;1H game from a friend. But we both know you'll be punished by God if you do. \x1b[9;1H \x1b[33mWHY RISK ETERNAL DAMNATION? CALL 1-800-IDGAMES AND BUY NOW! \x1b[10;1H \x1b[37mRemember, we love you almost as much as He does. \x1b[11;1H \x1b[12;1H \x1b[33mProgramming: \x1b[37mJohn Carmack, Michael Abrash, John Cash \x1b[13;1H \x1b[33mDesign: \x1b[37mJohn Romero, Sandy Petersen, American McGee, Tim Willits \x1b[14;1H \x1b[33mArt: \x1b[37mAdrian Carmack, Kevin Cloud \x1b[15;1H \x1b[33mBiz: \x1b[37mJay Wilbur, Mike Wilson, Donna Jackson \x1b[16;1H \x1b[33mProjects: \x1b[37mShawn Green \x1b[33mSupport: \x1b[37mBarrett Alexander \x1b[17;1H \x1b[33mSound Effects: \x1b[37mTrent Reznor and Nine Inch Nails \x1b[18;1H For other information or details on ordering outside the US, check out the \x1b[19;1H files accompanying QUAKE or our website at http://www.idsoftware.com. \x1b[20;1H \x1b[0;41mQuake is a trademark of Id Software, inc., (c)1996 Id Software, inc. \x1b[21;1H All rights reserved. NIN logo is a registered trademark licensed to \x1b[22;1H Nothing Interactive, Inc. All rights reserved. \x1b[40m\x1b[23;1H\x1b[0m";
167 "\x1b[?7h\x1b[40m\x1b[2J\x1b[0;1;41m\x1b[1;1H QUAKE \x1b[33mby \x1b[44mid\x1b[41m Software \x1b[2;1H ----------------------------------------------------------------------------- \x1b[3;1H \x1b[37mWhy did you quit from the registered version of QUAKE? Did the \x1b[4;1H scary monsters frighten you? Or did Mr. Sandman tug at your \x1b[5;1H little lids? No matter! What is important is you love our \x1b[6;1H game, and gave us your money. Congratulations, you are probably \x1b[7;1H not a thief. \x1b[8;1H Thank You. \x1b[9;1H \x1b[33;44mid\x1b[41m Software is: \x1b[10;1H PROGRAMMING: \x1b[37mJohn Carmack, Michael Abrash, John Cash \x1b[11;1H \x1b[33mDESIGN: \x1b[37mJohn Romero, Sandy Petersen, American McGee, Tim Willits \x1b[12;1H \x1b[33mART: \x1b[37mAdrian Carmack, Kevin Cloud \x1b[13;1H \x1b[33mBIZ: \x1b[37mJay Wilbur, Mike Wilson \x1b[33mPROJECTS MAN: \x1b[37mShawn Green \x1b[14;1H \x1b[33mBIZ ASSIST: \x1b[37mDonna Jackson \x1b[33mSUPPORT: \x1b[37mBarrett Alexander \x1b[15;1H \x1b[33mSOUND EFFECTS AND MUSIC: \x1b[37mTrent Reznor and Nine Inch Nails \x1b[16;1H \x1b[17;1H If you need help running QUAKE refer to the text files in the \x1b[18;1H QUAKE directory, or our website at http://www.idsoftware.com. \x1b[19;1H If all else fails, call our technical support at 1-800-IDGAMES. \x1b[20;1H \x1b[0;41mQuake is a trademark of Id Software, inc., (c)1996 Id Software, inc. \x1b[21;1H All rights reserved. NIN logo is a registered trademark licensed \x1b[22;1H to Nothing Interactive, Inc. All rights reserved. \x1b[23;1H\x1b[40m\x1b[0m";
173 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
175 if (registered.value)
191 void Sys_Error (char *error, ...)
196 // change stdin to non blocking
197 fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
199 va_start (argptr,error);
200 vsprintf (string,error,argptr);
202 fprintf(stderr, "Error: %s\n", string);
209 void Sys_Warn (char *warning, ...)
214 va_start (argptr,warning);
215 vsprintf (string,warning,argptr);
217 fprintf(stderr, "Warning: %s", string);
224 returns -1 if not present
227 int Sys_FileTime (char *path)
231 if (stat (path,&buf) == -1)
238 void Sys_mkdir (char *path)
243 int Sys_FileOpenRead (char *path, int *handle)
246 struct stat fileinfo;
249 h = open (path, O_RDONLY, 0666);
254 if (fstat (h,&fileinfo) == -1)
255 Sys_Error ("Error fstating %s", path);
257 return fileinfo.st_size;
260 int Sys_FileOpenWrite (char *path)
266 handle = open(path,O_RDWR | O_CREAT | O_TRUNC
270 Sys_Error ("Error opening %s: %s", path,strerror(errno));
275 int Sys_FileWrite (int handle, void *src, int count)
277 return write (handle, src, count);
280 void Sys_FileClose (int handle)
285 void Sys_FileSeek (int handle, int position)
287 lseek (handle, position, SEEK_SET);
290 int Sys_FileRead (int handle, void *dest, int count)
292 return read (handle, dest, count);
295 void Sys_DebugLog(char *file, char *fmt, ...)
298 static char data[1024];
301 va_start(argptr, fmt);
302 vsprintf(data, fmt, argptr);
304 // fd = open(file, O_WRONLY | O_BINARY | O_CREAT | O_APPEND, 0666);
305 fd = open(file, O_WRONLY | O_CREAT | O_APPEND, 0666);
306 write(fd, data, strlen(data));
310 void Sys_EditFile(char *filename)
317 term = getenv("TERM");
318 if (term && !strcmp(term, "xterm"))
320 editor = getenv("VISUAL");
322 editor = getenv("EDITOR");
324 editor = getenv("EDIT");
327 sprintf(cmd, "xterm -e %s %s", editor, filename);
333 double Sys_FloatTime (void)
339 gettimeofday(&tp, &tzp);
344 return tp.tv_usec/1000000.0;
347 return (tp.tv_sec - secbase) + tp.tv_usec/1000000.0;
350 // =======================================================================
351 // Sleeps for microseconds
352 // =======================================================================
354 static volatile int oktogo;
356 void alarm_handler(int x)
361 void Sys_LineRefresh(void)
365 void floating_point_exception_handler(int whatever)
367 // Sys_Warn("floating point exception\n");
368 signal(SIGFPE, floating_point_exception_handler);
371 char *Sys_ConsoleInput(void)
373 static char text[256];
376 struct timeval timeout;
378 if (cls.state == ca_dedicated) {
380 FD_SET(0, &fdset); // stdin
383 if (select (1, &fdset, NULL, NULL, &timeout) == -1 || !FD_ISSET(0, &fdset))
386 len = read (0, text, sizeof(text));
389 text[len-1] = 0; // rip off the /n and terminate
397 void Sys_HighFPPrecision (void)
401 void Sys_LowFPPrecision (void)
406 int main (int c, char **v)
409 double time, oldtime, newtime;
412 extern int recording;
415 // static char cwd[1024];
417 // signal(SIGFPE, floating_point_exception_handler);
418 signal(SIGFPE, SIG_IGN);
420 memset(&parms, 0, sizeof(parms));
423 parms.argc = com_argc;
424 parms.argv = com_argv;
426 parms.memsize = 24*1024*1024;
428 j = COM_CheckParm("-mem");
430 parms.memsize = (int) (atof(com_argv[j+1]) * 1024 * 1024);
431 parms.membase = malloc (parms.memsize);
434 printf("Unable to allocate heap memory\n");
438 parms.basedir = basedir;
439 // caching is disabled by default, use -cachedir to enable
440 // parms.cachedir = cachedir;
442 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
448 if (COM_CheckParm("-nostdout"))
452 fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) | FNDELAY);
453 printf ("Linux DarkPlaces -- Version %0.3f\n", VERSION);
456 oldtime = Sys_FloatTime () - 0.1;
459 // find time spent rendering last frame
460 newtime = Sys_FloatTime ();
461 time = newtime - oldtime;
463 if (cls.state == ca_dedicated)
464 { // play vcrfiles at max speed
465 if (time < sys_ticrate.value && (vcrFile == -1 || recording) )
468 continue; // not time to run a server only tic yet
470 time = sys_ticrate.value;
473 if (time > sys_ticrate.value*2)
480 // graphic debugging aids
481 if (sys_linerefresh.value)
490 Sys_MakeCodeWriteable
493 void Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
498 int psize = getpagesize();
500 addr = (startaddr & ~(psize-1)) - psize;
502 // fprintf(stderr, "writable code %lx(%lx)-%lx, length=%lx\n", startaddr,
503 // addr, startaddr+length, length);
505 r = mprotect((char*)addr, length + startaddr - addr + psize, 7);
508 Sys_Error("Protection change failed\n");