2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
sys_dos.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 <errno.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <dir.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <dpmi.h>
|
|
|
|
#include <sys/nearptr.h>
|
|
|
|
#include <conio.h>
|
|
|
|
|
|
|
|
#include "dosisms.h"
|
|
|
|
|
|
|
|
#define MINIMUM_WIN_MEMORY 0x800000
|
|
|
|
#define MINIMUM_WIN_MEMORY_LEVELPAK (MINIMUM_WIN_MEMORY + 0x100000)
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int end_of_memory;
|
|
|
|
qboolean lockmem, lockunlockmem, unlockmem;
|
|
|
|
static int win95;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
#define STDOUT 1
|
|
|
|
|
|
|
|
#define KEYBUF_SIZE 256
|
2001-02-26 06:48:02 +00:00
|
|
|
static unsigned char keybuf[KEYBUF_SIZE];
|
|
|
|
static int keybuf_head = 0;
|
|
|
|
static int keybuf_tail = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static quakeparms_t quakeparms;
|
|
|
|
int sys_checksum;
|
|
|
|
static double curtime = 0.0;
|
|
|
|
static double lastcurtime = 0.0;
|
|
|
|
static double oldtime = 0.0;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static qboolean isDedicated;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
static int minmem;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
float fptest_temp;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
extern char start_of_memory __asm__ ("start");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
// this is totally dependent on cwsdpmi putting the stack right after tge
|
|
|
|
// global data
|
|
|
|
|
|
|
|
// This does evil things in a Win95 DOS box!!!
|
|
|
|
#if 0
|
|
|
|
extern byte end;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
#define CHECKBYTE 0xed
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Sys_InitStackCheck (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 128 * 1024; i++)
|
2001-02-19 21:15:25 +00:00
|
|
|
(&end)[i] = CHECKBYTE;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Sys_StackCheck (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 128 * 1024; i++)
|
|
|
|
if ((&end)[i] != CHECKBYTE)
|
2001-02-19 21:15:25 +00:00
|
|
|
break;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
Con_Printf ("%i undisturbed stack bytes\n", i);
|
|
|
|
if (end != CHECKBYTE)
|
|
|
|
Sys_Error ("System stack overflow!");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
byte scantokey[128] = {
|
2001-02-19 21:15:25 +00:00
|
|
|
// 0 1 2 3 4 5 6 7
|
|
|
|
// 8 9 A B C D E F
|
2001-02-26 06:48:02 +00:00
|
|
|
0, 27, '1', '2', '3', '4', '5', '6',
|
|
|
|
'7', '8', '9', '0', '-', '=', K_BACKSPACE, 9, // 0
|
|
|
|
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i',
|
|
|
|
'o', 'p', '[', ']', 13, K_CTRL, 'a', 's', // 1
|
|
|
|
'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',
|
|
|
|
'\'', '`', K_SHIFT, '\\', 'z', 'x', 'c', 'v', // 2
|
|
|
|
'b', 'n', 'm', ',', '.', '/', K_SHIFT, '*',
|
|
|
|
K_ALT, ' ', 0, K_F1, K_F2, K_F3, K_F4, K_F5, // 3
|
|
|
|
K_F6, K_F7, K_F8, K_F9, K_F10, 0, 0, K_HOME,
|
|
|
|
K_UPARROW, K_PGUP, '-', K_LEFTARROW, '5', K_RIGHTARROW, '+', K_END, // 4
|
|
|
|
K_DOWNARROW, K_PGDN, K_INS, K_DEL, 0, 0, 0, K_F11,
|
|
|
|
K_F12, 0, 0, 0, 0, 0, 0, 0, // 5
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, // 6
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0 // 7
|
|
|
|
};
|
|
|
|
|
|
|
|
byte shiftscantokey[128] = {
|
2001-02-19 21:15:25 +00:00
|
|
|
// 0 1 2 3 4 5 6 7
|
|
|
|
// 8 9 A B C D E F
|
2001-02-26 06:48:02 +00:00
|
|
|
0, 27, '!', '@', '#', '$', '%', '^',
|
|
|
|
'&', '*', '(', ')', '_', '+', K_BACKSPACE, 9, // 0
|
|
|
|
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I',
|
|
|
|
'O', 'P', '{', '}', 13, K_CTRL, 'A', 'S', // 1
|
|
|
|
'D', 'F', 'G', 'H', 'J', 'K', 'L', ':',
|
|
|
|
'"', '~', K_SHIFT, '|', 'Z', 'X', 'C', 'V', // 2
|
|
|
|
'B', 'N', 'M', '<', '>', '?', K_SHIFT, '*',
|
|
|
|
K_ALT, ' ', 0, K_F1, K_F2, K_F3, K_F4, K_F5, // 3
|
|
|
|
K_F6, K_F7, K_F8, K_F9, K_F10, 0, 0, K_HOME,
|
|
|
|
K_UPARROW, K_PGUP, '_', K_LEFTARROW, '%', K_RIGHTARROW, '+', K_END, // 4
|
|
|
|
K_DOWNARROW, K_PGDN, K_INS, K_DEL, 0, 0, 0, K_F11,
|
|
|
|
K_F12, 0, 0, 0, 0, 0, 0, 0, // 5
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, // 6
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0 // 7
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
TrapKey (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
// static int ctrl=0;
|
|
|
|
keybuf[keybuf_head] = dos_inportb (0x60);
|
|
|
|
dos_outportb (0x20, 0x20);
|
|
|
|
/*
|
|
|
|
if (scantokey[keybuf[keybuf_head]&0x7f] == K_CTRL)
|
|
|
|
ctrl=keybuf[keybuf_head]&0x80; if (ctrl &&
|
|
|
|
scantokey[keybuf[keybuf_head]&0x7f] == 'c') Sys_Error("ctrl-c hit\n");
|
|
|
|
*/
|
|
|
|
keybuf_head = (keybuf_head + 1) & (KEYBUF_SIZE - 1);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define SC_UPARROW 0x48
|
|
|
|
#define SC_DOWNARROW 0x50
|
|
|
|
#define SC_LEFTARROW 0x4b
|
|
|
|
#define SC_RIGHTARROW 0x4d
|
|
|
|
#define SC_LEFTSHIFT 0x2a
|
|
|
|
#define SC_RIGHTSHIFT 0x36
|
|
|
|
#define SC_RIGHTARROW 0x4d
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void MaskExceptions (void);
|
|
|
|
void Sys_InitFloatTime (void);
|
|
|
|
void Sys_PushFPCW_SetHigh (void);
|
|
|
|
void Sys_PopFPCW (void);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
#define LEAVE_FOR_CACHE (512*1024) // FIXME: tune
|
|
|
|
#define LOCKED_FOR_MALLOC (128*1024) // FIXME: tune
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Sys_DetectWin95 (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
__dpmi_regs r;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
r.x.ax = 0x160a; /* Get Windows Version */
|
|
|
|
__dpmi_int (0x2f, &r);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (r.x.ax || r.h.bh < 4) { /* Not windows or earlier than Win95 */
|
2001-02-19 21:15:25 +00:00
|
|
|
win95 = 0;
|
|
|
|
lockmem = true;
|
|
|
|
lockunlockmem = false;
|
|
|
|
unlockmem = true;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
win95 = 1;
|
|
|
|
lockunlockmem = COM_CheckParm ("-winlockunlock");
|
|
|
|
|
|
|
|
if (lockunlockmem)
|
|
|
|
lockmem = true;
|
|
|
|
else
|
|
|
|
lockmem = COM_CheckParm ("-winlock");
|
|
|
|
|
|
|
|
unlockmem = lockmem && !lockunlockmem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void *
|
|
|
|
dos_getmaxlockedmem (int *size)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
__dpmi_free_mem_info meminfo;
|
|
|
|
__dpmi_meminfo info;
|
|
|
|
int working_size;
|
|
|
|
void *working_memory;
|
|
|
|
int last_locked;
|
|
|
|
int extra, i, j, allocsize;
|
|
|
|
static char *msg = "Locking data...";
|
|
|
|
int m, n;
|
|
|
|
byte *x;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// first lock all the current executing image so the locked count will
|
|
|
|
// be accurate. It doesn't hurt to lock the memory multiple times
|
|
|
|
last_locked = __djgpp_selector_limit + 1;
|
|
|
|
info.size = last_locked - 4096;
|
|
|
|
info.address = __djgpp_base_address + 4096;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (lockmem) {
|
|
|
|
if (__dpmi_lock_linear_region (&info)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
Sys_Error ("Lock of current memory at 0x%lx for %ldKb failed!\n",
|
2001-02-26 06:48:02 +00:00
|
|
|
info.address, info.size / 1024);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
__dpmi_get_free_memory_information (&meminfo);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!win95) { /* Not windows or earlier than Win95 */
|
2001-02-19 21:15:25 +00:00
|
|
|
working_size = meminfo.maximum_locked_page_allocation_in_pages * 4096;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
working_size = meminfo.largest_available_free_block_in_bytes -
|
2001-02-26 06:48:02 +00:00
|
|
|
LEAVE_FOR_CACHE;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
working_size &= ~0xffff; /* Round down to 64K */
|
2001-02-19 21:15:25 +00:00
|
|
|
working_size += 0x10000;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
do {
|
2001-02-19 21:15:25 +00:00
|
|
|
working_size -= 0x10000; /* Decrease 64K and try again */
|
2001-02-26 06:48:02 +00:00
|
|
|
working_memory = sbrk (working_size);
|
|
|
|
} while (working_memory == (void *) -1);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
extra = 0xfffc - ((unsigned) sbrk (0) & 0xffff);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (extra > 0) {
|
|
|
|
sbrk (extra);
|
2001-02-19 21:15:25 +00:00
|
|
|
working_size += extra;
|
|
|
|
}
|
|
|
|
// now grab the memory
|
|
|
|
info.address = last_locked + __djgpp_base_address;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!win95) {
|
|
|
|
info.size = __djgpp_selector_limit + 1 - last_locked;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
while (info.size > 0 && __dpmi_lock_linear_region (&info)) {
|
2001-02-19 21:15:25 +00:00
|
|
|
info.size -= 0x1000;
|
|
|
|
working_size -= 0x1000;
|
2001-02-26 06:48:02 +00:00
|
|
|
sbrk (-0x1000);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
} else { /* Win95 section */
|
|
|
|
j = COM_CheckParm ("-winmem");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (standard_quake)
|
|
|
|
minmem = MINIMUM_WIN_MEMORY;
|
|
|
|
else
|
|
|
|
minmem = MINIMUM_WIN_MEMORY_LEVELPAK;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (j) {
|
|
|
|
allocsize = ((int) (Q_atoi (com_argv[j + 1]))) * 0x100000 +
|
|
|
|
LOCKED_FOR_MALLOC;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (allocsize < (minmem + LOCKED_FOR_MALLOC))
|
|
|
|
allocsize = minmem + LOCKED_FOR_MALLOC;
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
allocsize = minmem + LOCKED_FOR_MALLOC;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!lockmem) {
|
|
|
|
// we won't lock, just sbrk the memory
|
2001-02-19 21:15:25 +00:00
|
|
|
info.size = allocsize;
|
|
|
|
goto UpdateSbrk;
|
|
|
|
}
|
|
|
|
// lock the memory down
|
|
|
|
write (STDOUT, msg, strlen (msg));
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
for (j = allocsize; j > (minmem + LOCKED_FOR_MALLOC); j -= 0x100000) {
|
2001-02-19 21:15:25 +00:00
|
|
|
info.size = j;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
if (!__dpmi_lock_linear_region (&info))
|
2001-02-19 21:15:25 +00:00
|
|
|
goto Locked;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
write (STDOUT, ".", 1);
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
// finally, try with the absolute minimum amount
|
|
|
|
for (i = 0; i < 10; i++) {
|
2001-02-19 21:15:25 +00:00
|
|
|
info.size = minmem + LOCKED_FOR_MALLOC;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!__dpmi_lock_linear_region (&info))
|
2001-02-19 21:15:25 +00:00
|
|
|
goto Locked;
|
|
|
|
}
|
|
|
|
|
|
|
|
Sys_Error ("Can't lock memory; %d Mb lockable RAM required. "
|
|
|
|
"Try shrinking smartdrv.", info.size / 0x100000);
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
Locked:
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
UpdateSbrk:
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
info.address += info.size;
|
2001-02-26 06:48:02 +00:00
|
|
|
info.address -= __djgpp_base_address + 4; // ending point, malloc
|
|
|
|
// align
|
|
|
|
working_size = info.address - (int) working_memory;
|
|
|
|
sbrk (info.address - (int) sbrk (0)); // negative adjustment
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (lockunlockmem) {
|
2001-02-19 21:15:25 +00:00
|
|
|
__dpmi_unlock_linear_region (&info);
|
|
|
|
printf ("Locked and unlocked %d Mb data\n", working_size / 0x100000);
|
2001-02-26 06:48:02 +00:00
|
|
|
} else if (lockmem) {
|
2001-02-19 21:15:25 +00:00
|
|
|
printf ("Locked %d Mb data\n", working_size / 0x100000);
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
printf ("Allocated %d Mb data\n", working_size / 0x100000);
|
|
|
|
}
|
|
|
|
|
|
|
|
// touch all the memory to make sure it's there. The 16-page skip is to
|
|
|
|
// keep Win 95 from thinking we're trying to page ourselves in (we are
|
|
|
|
// doing that, of course, but there's no reason we shouldn't)
|
2001-02-26 06:48:02 +00:00
|
|
|
x = (byte *) working_memory;
|
|
|
|
|
|
|
|
for (n = 0; n < 4; n++) {
|
|
|
|
for (m = 0; m < (working_size - 16 * 0x1000); m += 4) {
|
|
|
|
sys_checksum += *(int *) &x[m];
|
|
|
|
sys_checksum += *(int *) &x[m + 16 * 0x1000];
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// give some of what we locked back for malloc before returning. Done
|
|
|
|
// by cheating and passing a negative value to sbrk
|
|
|
|
working_size -= LOCKED_FOR_MALLOC;
|
2001-02-26 06:48:02 +00:00
|
|
|
sbrk (-(LOCKED_FOR_MALLOC));
|
2001-02-19 21:15:25 +00:00
|
|
|
*size = working_size;
|
|
|
|
return working_memory;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
Sys_FileTime
|
|
|
|
|
|
|
|
returns -1 if not present
|
|
|
|
============
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
int
|
|
|
|
Sys_FileTime (char *path)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
struct stat buf;
|
|
|
|
|
|
|
|
if (stat (path, &buf) == -1)
|
2001-02-19 21:15:25 +00:00
|
|
|
return -1;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
return buf.st_mtime;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Sys_mkdir (char *path)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
mkdir (path, 0777);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Sys_Sleep (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
char *
|
|
|
|
Sys_ConsoleInput (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
static char text[256];
|
|
|
|
static int len = 0;
|
|
|
|
char ch;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!isDedicated)
|
|
|
|
return NULL;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (!kbhit ())
|
2001-02-19 21:15:25 +00:00
|
|
|
return NULL;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
ch = getche ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
switch (ch) {
|
2001-02-19 21:15:25 +00:00
|
|
|
case '\r':
|
2001-02-26 06:48:02 +00:00
|
|
|
putch ('\n');
|
|
|
|
if (len) {
|
|
|
|
text[len] = 0;
|
|
|
|
len = 0;
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
case '\b':
|
2001-02-26 06:48:02 +00:00
|
|
|
putch (' ');
|
|
|
|
if (len) {
|
|
|
|
len--;
|
|
|
|
putch ('\b');
|
|
|
|
}
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
default:
|
2001-02-26 06:48:02 +00:00
|
|
|
text[len] = ch;
|
|
|
|
len = (len + 1) & 0xff;
|
|
|
|
break;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Sys_Init (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
MaskExceptions ();
|
|
|
|
|
|
|
|
Sys_SetFPCW ();
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
dos_outportb (0x43, 0x34); // set system timer to mode 2
|
|
|
|
dos_outportb (0x40, 0); // for the Sys_DoubleTime() function
|
|
|
|
dos_outportb (0x40, 0);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Sys_InitFloatTime ();
|
|
|
|
|
|
|
|
_go32_interrupt_stack_size = 4 * 1024;;
|
|
|
|
_go32_rmcb_stack_size = 4 * 1024;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Sys_Shutdown (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
if (!isDedicated)
|
2001-02-26 06:48:02 +00:00
|
|
|
dos_restoreintr (9);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (unlockmem) {
|
2001-02-19 21:15:25 +00:00
|
|
|
dos_unlockmem (&start_of_memory,
|
2001-02-26 06:48:02 +00:00
|
|
|
end_of_memory - (int) &start_of_memory);
|
2001-02-19 21:15:25 +00:00
|
|
|
dos_unlockmem (quakeparms.membase, quakeparms.memsize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
#define SC_RSHIFT 0x36
|
|
|
|
#define SC_LSHIFT 0x2a
|
|
|
|
void
|
|
|
|
IN_SendKeyEvents (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int k, next;
|
|
|
|
int outkey;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// get key events
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
while (keybuf_head != keybuf_tail) {
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
k = keybuf[keybuf_tail++];
|
2001-02-26 06:48:02 +00:00
|
|
|
keybuf_tail &= (KEYBUF_SIZE - 1);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (k == 0xe0)
|
|
|
|
continue; // special / pause keys
|
|
|
|
next = keybuf[(keybuf_tail - 2) & (KEYBUF_SIZE - 1)];
|
2001-02-19 21:15:25 +00:00
|
|
|
if (next == 0xe1)
|
2001-02-26 06:48:02 +00:00
|
|
|
continue; // pause key bullshit
|
|
|
|
if (k == 0xc5 && next == 0x9d) {
|
2001-02-19 21:15:25 +00:00
|
|
|
Key_Event (K_PAUSE, true);
|
2001-02-26 06:48:02 +00:00
|
|
|
continue;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
// extended keyboard shift key bullshit
|
2001-02-26 06:48:02 +00:00
|
|
|
if ((k & 0x7f) == SC_LSHIFT || (k & 0x7f) == SC_RSHIFT) {
|
|
|
|
if (keybuf[(keybuf_tail - 2) & (KEYBUF_SIZE - 1)] == 0xe0)
|
|
|
|
continue;
|
|
|
|
k &= 0x80;
|
|
|
|
k |= SC_RSHIFT;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (k == 0xc5 && keybuf[(keybuf_tail - 2) & (KEYBUF_SIZE - 1)] == 0x9d)
|
|
|
|
continue; // more pause bullshit
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
outkey = scantokey[k & 0x7f];
|
|
|
|
|
|
|
|
if (k & 0x80)
|
|
|
|
Key_Event (outkey, false);
|
|
|
|
else
|
|
|
|
Key_Event (outkey, true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// =======================================================================
|
|
|
|
// General routines
|
|
|
|
// =======================================================================
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
Sys_Printf
|
|
|
|
================
|
|
|
|
*/
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Sys_Printf (char *fmt, ...)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
va_list argptr;
|
|
|
|
char text[1024];
|
|
|
|
|
|
|
|
va_start (argptr, fmt);
|
|
|
|
vsnprintf (text, sizeof (text), fmt, argptr);
|
2001-02-19 21:15:25 +00:00
|
|
|
va_end (argptr);
|
|
|
|
|
|
|
|
if (cls.state == ca_dedicated)
|
2001-02-26 06:48:02 +00:00
|
|
|
fprintf (stderr, "%s", text);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Sys_AtExit (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
// shutdown only once (so Sys_Error can call this function to shutdown, then
|
|
|
|
// print the error message, then call exit without exit calling this function
|
|
|
|
// again)
|
2001-02-26 06:48:02 +00:00
|
|
|
Sys_Shutdown ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Sys_Quit (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
byte screen[80 * 25 * 2];
|
|
|
|
byte *d;
|
|
|
|
char ver[6];
|
|
|
|
int i;
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// load the sell screen before shuting everything down
|
|
|
|
if (registered->int_val)
|
2001-02-26 06:48:02 +00:00
|
|
|
d = COM_LoadHunkFile ("end2.bin");
|
2001-02-19 21:15:25 +00:00
|
|
|
else
|
2001-02-26 06:48:02 +00:00
|
|
|
d = COM_LoadHunkFile ("end1.bin");
|
2001-02-19 21:15:25 +00:00
|
|
|
if (d)
|
2001-02-26 06:48:02 +00:00
|
|
|
memcpy (screen, d, sizeof (screen));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// write the version number directly to the end screen
|
2001-02-26 06:48:02 +00:00
|
|
|
snprintf (ver, sizeof (ver), " v%4.2f", VERSION);
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
screen[0 * 80 * 2 + 72 * 2 + i * 2] = ver[i];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
Host_Shutdown ();
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
// do the text mode sell screen
|
2001-02-26 06:48:02 +00:00
|
|
|
if (d) {
|
|
|
|
memcpy ((void *) real2ptr (0xb8000), screen, 80 * 25 * 2);
|
|
|
|
|
|
|
|
// set text pos
|
|
|
|
regs.x.ax = 0x0200;
|
|
|
|
regs.h.bh = 0;
|
|
|
|
regs.h.dl = 0;
|
2001-02-19 21:15:25 +00:00
|
|
|
regs.h.dh = 22;
|
2001-02-26 06:48:02 +00:00
|
|
|
dos_int86 (0x10);
|
|
|
|
} else
|
2001-02-19 21:15:25 +00:00
|
|
|
printf ("couldn't load endscreen.\n");
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
exit (0);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Sys_Error (char *error, ...)
|
|
|
|
{
|
|
|
|
va_list argptr;
|
|
|
|
char string[1024];
|
|
|
|
|
|
|
|
va_start (argptr, error);
|
|
|
|
vsnprintf (string, sizeof (string), error, argptr);
|
|
|
|
va_end (argptr);
|
|
|
|
|
|
|
|
Host_Shutdown ();
|
|
|
|
fprintf (stderr, "Error: %s\n", string);
|
2001-02-19 21:15:25 +00:00
|
|
|
// Sys_AtExit is called by exit to shutdown the system
|
2001-02-26 06:48:02 +00:00
|
|
|
exit (0);
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int
|
|
|
|
Sys_FileOpenRead (char *path, int *handle)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int h;
|
|
|
|
struct stat fileinfo;
|
|
|
|
|
|
|
|
h = open (path, O_RDONLY | O_BINARY, 0666);
|
2001-02-19 21:15:25 +00:00
|
|
|
*handle = h;
|
|
|
|
if (h == -1)
|
|
|
|
return -1;
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
if (fstat (h, &fileinfo) == -1)
|
2001-02-19 21:15:25 +00:00
|
|
|
Sys_Error ("Error fstating %s", path);
|
|
|
|
|
|
|
|
return fileinfo.st_size;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int
|
|
|
|
Sys_FileOpenWrite (char *path)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int handle;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
umask (0);
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
handle = open (path, O_RDWR | O_BINARY | O_CREAT | O_TRUNC, 0666);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (handle == -1)
|
2001-02-26 06:48:02 +00:00
|
|
|
Sys_Error ("Error opening %s: %s", path, strerror (errno));
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Sys_FileClose (int handle)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
close (handle);
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Sys_FileSeek (int handle, int position)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
lseek (handle, position, SEEK_SET);
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int
|
|
|
|
Sys_FileRead (int handle, void *dest, int count)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
return read (handle, dest, count);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
int
|
|
|
|
Sys_FileWrite (int handle, void *data, int count)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
return write (handle, data, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
Sys_MakeCodeWriteable
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Sys_MakeCodeWriteable (unsigned long startaddr, unsigned long length)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
// it's always writeable
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
Sys_DoubleTime
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
double
|
|
|
|
Sys_DoubleTime (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int r;
|
|
|
|
unsigned t, tick;
|
|
|
|
double ft, time;
|
|
|
|
static int sametimecount;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Sys_PushFPCW_SetHigh ();
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
//{static float t = 0; t=t+0.05; return t;} // DEBUG
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
t = *(unsigned short *) real2ptr (0x46c) * 65536;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
dos_outportb (0x43, 0); // latch time
|
|
|
|
r = dos_inportb (0x40);
|
|
|
|
r |= dos_inportb (0x40) << 8;
|
|
|
|
r = (r - 1) & 0xffff;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
tick = *(unsigned short *) real2ptr (0x46c) * 65536;
|
|
|
|
if ((tick != t) && (r & 0x8000))
|
2001-02-19 21:15:25 +00:00
|
|
|
t = tick;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
ft = (double) (t + (65536 - r)) / 1193200.0;
|
2001-02-19 21:15:25 +00:00
|
|
|
time = ft - oldtime;
|
|
|
|
oldtime = ft;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (time < 0) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (time > -3000.0)
|
|
|
|
time = 0.0;
|
|
|
|
else
|
|
|
|
time += 3600.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
curtime += time;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (curtime == lastcurtime) {
|
2001-02-19 21:15:25 +00:00
|
|
|
sametimecount++;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (sametimecount > 100000) {
|
2001-02-19 21:15:25 +00:00
|
|
|
curtime += 1.0;
|
|
|
|
sametimecount = 0;
|
|
|
|
}
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
sametimecount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
lastcurtime = curtime;
|
|
|
|
|
|
|
|
Sys_PopFPCW ();
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
return curtime;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
Sys_InitFloatTime
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Sys_InitFloatTime (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int j;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Sys_DoubleTime ();
|
|
|
|
|
|
|
|
oldtime = curtime;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
j = COM_CheckParm ("-starttime");
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (j) {
|
|
|
|
curtime = (double) (Q_atof (com_argv[j + 1]));
|
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
curtime = 0.0;
|
|
|
|
}
|
|
|
|
lastcurtime = curtime;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
Sys_GetMemory
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Sys_GetMemory (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int j, tsize;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
j = COM_CheckParm ("-mem");
|
|
|
|
if (j) {
|
|
|
|
quakeparms.memsize = (int) (Q_atof (com_argv[j + 1]) * 1024 * 1024);
|
2001-02-19 21:15:25 +00:00
|
|
|
quakeparms.membase = malloc (quakeparms.memsize);
|
2001-02-26 06:48:02 +00:00
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
quakeparms.membase = dos_getmaxlockedmem (&quakeparms.memsize);
|
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
fprintf (stderr, "malloc'd: %d\n", quakeparms.memsize);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (COM_CheckParm ("-heapsize")) {
|
|
|
|
tsize = Q_atoi (com_argv[COM_CheckParm ("-heapsize") + 1]) * 1024;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (tsize < quakeparms.memsize)
|
|
|
|
quakeparms.memsize = tsize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
Sys_PageInProgram
|
|
|
|
|
|
|
|
walks the text, data, and bss to make sure it's all paged in so that the
|
|
|
|
actual physical memory detected by Sys_GetMemory is correct.
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Sys_PageInProgram (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
int i, j;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
end_of_memory = (int) sbrk (0);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (lockmem) {
|
|
|
|
if (dos_lockmem ((void *) &start_of_memory,
|
|
|
|
end_of_memory - (int) &start_of_memory))
|
|
|
|
Sys_Error ("Couldn't lock text and data");
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (lockunlockmem) {
|
|
|
|
dos_unlockmem ((void *) &start_of_memory,
|
|
|
|
end_of_memory - (int) &start_of_memory);
|
2001-02-19 21:15:25 +00:00
|
|
|
printf ("Locked and unlocked %d Mb image\n",
|
2001-02-26 06:48:02 +00:00
|
|
|
(end_of_memory - (int) &start_of_memory) / 0x100000);
|
|
|
|
} else if (lockmem) {
|
2001-02-19 21:15:25 +00:00
|
|
|
printf ("Locked %d Mb image\n",
|
2001-02-26 06:48:02 +00:00
|
|
|
(end_of_memory - (int) &start_of_memory) / 0x100000);
|
|
|
|
} else {
|
2001-02-19 21:15:25 +00:00
|
|
|
printf ("Loaded %d Mb image\n",
|
2001-02-26 06:48:02 +00:00
|
|
|
(end_of_memory - (int) &start_of_memory) / 0x100000);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// touch the entire image, doing the 16-page skip so Win95 doesn't think we're
|
|
|
|
// trying to page ourselves in
|
2001-02-26 06:48:02 +00:00
|
|
|
for (j = 0; j < 4; j++) {
|
|
|
|
for (i = (int) &start_of_memory; i < (end_of_memory - 16 * 0x1000);
|
|
|
|
i += 4) {
|
|
|
|
sys_checksum += *(int *) i;
|
|
|
|
sys_checksum += *(int *) (i + 16 * 0x1000);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
Sys_NoFPUExceptionHandler
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Sys_NoFPUExceptionHandler (int whatever)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
printf ("\nError: Quake requires a floating-point processor\n");
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
Sys_DefaultExceptionHandler
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
void
|
|
|
|
Sys_DefaultExceptionHandler (int whatever)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
================
|
|
|
|
main
|
|
|
|
================
|
|
|
|
*/
|
2001-02-26 06:48:02 +00:00
|
|
|
int
|
|
|
|
main (int c, char **v)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-02-26 06:48:02 +00:00
|
|
|
double time, oldtime, newtime;
|
|
|
|
extern void (*dos_error_func) (char *, ...);
|
|
|
|
static char cwd[1024];
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
printf ("Quake v%4.2f\n", VERSION);
|
2001-02-26 06:48:02 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
// make sure there's an FPU
|
2001-02-26 06:48:02 +00:00
|
|
|
signal (SIGNOFP, Sys_NoFPUExceptionHandler);
|
|
|
|
signal (SIGABRT, Sys_DefaultExceptionHandler);
|
|
|
|
signal (SIGALRM, Sys_DefaultExceptionHandler);
|
|
|
|
signal (SIGKILL, Sys_DefaultExceptionHandler);
|
|
|
|
signal (SIGQUIT, Sys_DefaultExceptionHandler);
|
|
|
|
signal (SIGINT, Sys_DefaultExceptionHandler);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (fptest_temp >= 0.0)
|
|
|
|
fptest_temp += 0.1;
|
|
|
|
|
|
|
|
COM_InitArgv (c, v);
|
|
|
|
|
|
|
|
quakeparms.argc = com_argc;
|
|
|
|
quakeparms.argv = com_argv;
|
|
|
|
|
|
|
|
dos_error_func = Sys_Error;
|
|
|
|
|
|
|
|
Sys_DetectWin95 ();
|
|
|
|
Sys_PageInProgram ();
|
|
|
|
Sys_GetMemory ();
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
atexit (Sys_AtExit); // in case we crash
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
getwd (cwd);
|
2001-02-26 06:48:02 +00:00
|
|
|
if (cwd[Q_strlen (cwd) - 1] == '/')
|
|
|
|
cwd[Q_strlen (cwd) - 1] = 0;
|
|
|
|
quakeparms.basedir = cwd; // "f:/quake";
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
isDedicated = (COM_CheckParm ("-dedicated") != 0);
|
|
|
|
|
|
|
|
Sys_Init ();
|
|
|
|
|
|
|
|
if (!isDedicated)
|
2001-02-26 06:48:02 +00:00
|
|
|
dos_registerintr (9, TrapKey);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
//Sys_InitStackCheck ();
|
2001-02-26 06:48:02 +00:00
|
|
|
|
|
|
|
Host_Init (&quakeparms);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
//Sys_StackCheck ();
|
|
|
|
|
|
|
|
//Con_Printf ("Top of stack: 0x%x\n", &time);
|
|
|
|
oldtime = Sys_DoubleTime ();
|
2001-02-26 06:48:02 +00:00
|
|
|
while (1) {
|
2001-02-19 21:15:25 +00:00
|
|
|
newtime = Sys_DoubleTime ();
|
|
|
|
time = newtime - oldtime;
|
|
|
|
|
2001-02-26 06:48:02 +00:00
|
|
|
if (cls.state == ca_dedicated && (time < sys_ticrate->value))
|
2001-02-19 21:15:25 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
Host_Frame (time);
|
|
|
|
|
|
|
|
//Sys_StackCheck ();
|
|
|
|
|
|
|
|
oldtime = newtime;
|
|
|
|
}
|
|
|
|
}
|