summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/plugins/CATEGORIES1
-rw-r--r--apps/plugins/SOURCES1
-rw-r--r--apps/plugins/SUBDIRS6
-rw-r--r--apps/plugins/lib/stdio_compat.h2
-rw-r--r--apps/plugins/quake.c31
-rw-r--r--apps/plugins/sdl/SOURCES.quake77
-rw-r--r--apps/plugins/sdl/include/SDL_config_rockbox.h17
-rw-r--r--apps/plugins/sdl/include/SDL_platform.h1
-rw-r--r--apps/plugins/sdl/main.c11
-rw-r--r--apps/plugins/sdl/progs/quake/Makefile.linuxi3861242
-rw-r--r--apps/plugins/sdl/progs/quake/adivtab.h1077
-rw-r--r--apps/plugins/sdl/progs/quake/anorm_dots.h37
-rw-r--r--apps/plugins/sdl/progs/quake/anorms.h181
-rw-r--r--apps/plugins/sdl/progs/quake/asm_draw.h151
-rw-r--r--apps/plugins/sdl/progs/quake/asm_i386.h97
-rw-r--r--apps/plugins/sdl/progs/quake/block16.h142
-rw-r--r--apps/plugins/sdl/progs/quake/block8.h143
-rw-r--r--apps/plugins/sdl/progs/quake/bspfile.h324
-rw-r--r--apps/plugins/sdl/progs/quake/cd_linux.c416
-rw-r--r--apps/plugins/sdl/progs/quake/cd_null.c55
-rw-r--r--apps/plugins/sdl/progs/quake/cd_sdl.c223
-rw-r--r--apps/plugins/sdl/progs/quake/cdaudio.h27
-rw-r--r--apps/plugins/sdl/progs/quake/chase.c92
-rw-r--r--apps/plugins/sdl/progs/quake/cl_demo.c367
-rw-r--r--apps/plugins/sdl/progs/quake/cl_input.c448
-rw-r--r--apps/plugins/sdl/progs/quake/cl_main.c757
-rw-r--r--apps/plugins/sdl/progs/quake/cl_parse.c963
-rw-r--r--apps/plugins/sdl/progs/quake/cl_tent.c394
-rw-r--r--apps/plugins/sdl/progs/quake/clean.bat18
-rw-r--r--apps/plugins/sdl/progs/quake/client.h376
-rw-r--r--apps/plugins/sdl/progs/quake/cmd.c721
-rw-r--r--apps/plugins/sdl/progs/quake/cmd.h123
-rw-r--r--apps/plugins/sdl/progs/quake/common.c1856
-rw-r--r--apps/plugins/sdl/progs/quake/common.h184
-rw-r--r--apps/plugins/sdl/progs/quake/conproc.h37
-rw-r--r--apps/plugins/sdl/progs/quake/console.c644
-rw-r--r--apps/plugins/sdl/progs/quake/console.h46
-rw-r--r--apps/plugins/sdl/progs/quake/crc.c81
-rw-r--r--apps/plugins/sdl/progs/quake/crc.h24
-rw-r--r--apps/plugins/sdl/progs/quake/cvar.c224
-rw-r--r--apps/plugins/sdl/progs/quake/cvar.h97
-rw-r--r--apps/plugins/sdl/progs/quake/d_copy.S149
-rw-r--r--apps/plugins/sdl/progs/quake/d_edge.c331
-rw-r--r--apps/plugins/sdl/progs/quake/d_fill.c88
-rw-r--r--apps/plugins/sdl/progs/quake/d_iface.h231
-rw-r--r--apps/plugins/sdl/progs/quake/d_ifacea.h98
-rw-r--r--apps/plugins/sdl/progs/quake/d_init.c173
-rw-r--r--apps/plugins/sdl/progs/quake/d_local.h111
-rw-r--r--apps/plugins/sdl/progs/quake/d_modech.c107
-rw-r--r--apps/plugins/sdl/progs/quake/d_part.c207
-rw-r--r--apps/plugins/sdl/progs/quake/d_polyse.c1111
-rw-r--r--apps/plugins/sdl/progs/quake/d_scan.c449
-rw-r--r--apps/plugins/sdl/progs/quake/d_sky.c138
-rw-r--r--apps/plugins/sdl/progs/quake/d_sprite.c442
-rw-r--r--apps/plugins/sdl/progs/quake/d_surf.c335
-rw-r--r--apps/plugins/sdl/progs/quake/d_vars.c50
-rw-r--r--apps/plugins/sdl/progs/quake/d_zpoint.c47
-rw-r--r--apps/plugins/sdl/progs/quake/dosasm.S77
-rw-r--r--apps/plugins/sdl/progs/quake/dosisms.h100
-rw-r--r--apps/plugins/sdl/progs/quake/draw.c890
-rw-r--r--apps/plugins/sdl/progs/quake/draw.h40
-rw-r--r--apps/plugins/sdl/progs/quake/gl_vidlinux.c866
-rw-r--r--apps/plugins/sdl/progs/quake/gl_vidlinuxglx.c997
-rw-r--r--apps/plugins/sdl/progs/quake/host.c977
-rw-r--r--apps/plugins/sdl/progs/quake/host_cmd.c1931
-rw-r--r--apps/plugins/sdl/progs/quake/in_null.c39
-rw-r--r--apps/plugins/sdl/progs/quake/input.h34
-rw-r--r--apps/plugins/sdl/progs/quake/keys.c804
-rw-r--r--apps/plugins/sdl/progs/quake/keys.h134
-rw-r--r--apps/plugins/sdl/progs/quake/mathlib.c550
-rw-r--r--apps/plugins/sdl/progs/quake/mathlib.h154
-rw-r--r--apps/plugins/sdl/progs/quake/menu.c3234
-rw-r--r--apps/plugins/sdl/progs/quake/menu.h38
-rw-r--r--apps/plugins/sdl/progs/quake/model.c1874
-rw-r--r--apps/plugins/sdl/progs/quake/model.h383
-rw-r--r--apps/plugins/sdl/progs/quake/modelgen.h137
-rw-r--r--apps/plugins/sdl/progs/quake/mpdosock.h797
-rw-r--r--apps/plugins/sdl/progs/quake/net.h337
-rw-r--r--apps/plugins/sdl/progs/quake/net_bsd.c93
-rw-r--r--apps/plugins/sdl/progs/quake/net_bw.h39
-rw-r--r--apps/plugins/sdl/progs/quake/net_dgrm.c1390
-rw-r--r--apps/plugins/sdl/progs/quake/net_dgrm.h34
-rw-r--r--apps/plugins/sdl/progs/quake/net_loop.c245
-rw-r--r--apps/plugins/sdl/progs/quake/net_loop.h33
-rw-r--r--apps/plugins/sdl/progs/quake/net_main.c997
-rw-r--r--apps/plugins/sdl/progs/quake/net_none.c46
-rw-r--r--apps/plugins/sdl/progs/quake/net_udp.c415
-rw-r--r--apps/plugins/sdl/progs/quake/net_udp.h39
-rw-r--r--apps/plugins/sdl/progs/quake/net_vcr.c167
-rw-r--r--apps/plugins/sdl/progs/quake/net_vcr.h37
-rw-r--r--apps/plugins/sdl/progs/quake/net_wso.c0
-rw-r--r--apps/plugins/sdl/progs/quake/nonintel.c64
-rw-r--r--apps/plugins/sdl/progs/quake/pr_cmds.c1936
-rw-r--r--apps/plugins/sdl/progs/quake/pr_comp.h180
-rw-r--r--apps/plugins/sdl/progs/quake/pr_edict.c1113
-rw-r--r--apps/plugins/sdl/progs/quake/pr_exec.c668
-rw-r--r--apps/plugins/sdl/progs/quake/progdefs.h24
-rw-r--r--apps/plugins/sdl/progs/quake/progdefs.q1143
-rw-r--r--apps/plugins/sdl/progs/quake/progdefs.q2158
-rw-r--r--apps/plugins/sdl/progs/quake/progs.h134
-rw-r--r--apps/plugins/sdl/progs/quake/protocol.h167
-rw-r--r--apps/plugins/sdl/progs/quake/quakeasm.h280
-rw-r--r--apps/plugins/sdl/progs/quake/quakedef.h333
-rw-r--r--apps/plugins/sdl/progs/quake/quakesound.h177
-rw-r--r--apps/plugins/sdl/progs/quake/r_aclip.c350
-rw-r--r--apps/plugins/sdl/progs/quake/r_alias.c753
-rw-r--r--apps/plugins/sdl/progs/quake/r_bsp.c675
-rw-r--r--apps/plugins/sdl/progs/quake/r_draw.c908
-rw-r--r--apps/plugins/sdl/progs/quake/r_edge.c775
-rw-r--r--apps/plugins/sdl/progs/quake/r_efrag.c276
-rw-r--r--apps/plugins/sdl/progs/quake/r_light.c260
-rw-r--r--apps/plugins/sdl/progs/quake/r_local.h316
-rw-r--r--apps/plugins/sdl/progs/quake/r_main.c1089
-rw-r--r--apps/plugins/sdl/progs/quake/r_misc.c523
-rw-r--r--apps/plugins/sdl/progs/quake/r_part.c802
-rw-r--r--apps/plugins/sdl/progs/quake/r_shared.h157
-rw-r--r--apps/plugins/sdl/progs/quake/r_sky.c280
-rw-r--r--apps/plugins/sdl/progs/quake/r_sprite.c401
-rw-r--r--apps/plugins/sdl/progs/quake/r_surf.c678
-rw-r--r--apps/plugins/sdl/progs/quake/r_vars.c39
-rw-r--r--apps/plugins/sdl/progs/quake/r_varsa.S64
-rw-r--r--apps/plugins/sdl/progs/quake/render.h158
-rw-r--r--apps/plugins/sdl/progs/quake/resource.h20
-rw-r--r--apps/plugins/sdl/progs/quake/sbar.c1323
-rw-r--r--apps/plugins/sdl/progs/quake/sbar.h39
-rw-r--r--apps/plugins/sdl/progs/quake/screen.c994
-rw-r--r--apps/plugins/sdl/progs/quake/screen.h57
-rw-r--r--apps/plugins/sdl/progs/quake/server.h258
-rw-r--r--apps/plugins/sdl/progs/quake/snd_dma.c1021
-rw-r--r--apps/plugins/sdl/progs/quake/snd_linux.c269
-rw-r--r--apps/plugins/sdl/progs/quake/snd_mem.c341
-rw-r--r--apps/plugins/sdl/progs/quake/snd_mix.c132
-rw-r--r--apps/plugins/sdl/progs/quake/snd_mix_arm.S129
-rw-r--r--apps/plugins/sdl/progs/quake/snd_mix_generic.c69
-rw-r--r--apps/plugins/sdl/progs/quake/snd_mix_generic_annotated.s191
-rw-r--r--apps/plugins/sdl/progs/quake/snd_null.c97
-rw-r--r--apps/plugins/sdl/progs/quake/snd_sdl.c113
-rw-r--r--apps/plugins/sdl/progs/quake/spritegn.h114
-rw-r--r--apps/plugins/sdl/progs/quake/sv_main.c1209
-rw-r--r--apps/plugins/sdl/progs/quake/sv_move.c427
-rw-r--r--apps/plugins/sdl/progs/quake/sv_phys.c1617
-rw-r--r--apps/plugins/sdl/progs/quake/sv_user.c629
-rw-r--r--apps/plugins/sdl/progs/quake/sys.h74
-rw-r--r--apps/plugins/sdl/progs/quake/sys_linux.c457
-rw-r--r--apps/plugins/sdl/progs/quake/sys_null.c232
-rw-r--r--apps/plugins/sdl/progs/quake/sys_sdl.c436
-rw-r--r--apps/plugins/sdl/progs/quake/vgamodes.h599
-rw-r--r--apps/plugins/sdl/progs/quake/vid.h85
-rw-r--r--apps/plugins/sdl/progs/quake/vid_null.c87
-rw-r--r--apps/plugins/sdl/progs/quake/vid_sdl.c389
-rw-r--r--apps/plugins/sdl/progs/quake/vid_svgalib.c1003
-rw-r--r--apps/plugins/sdl/progs/quake/vid_vga.c478
-rw-r--r--apps/plugins/sdl/progs/quake/view.c1113
-rw-r--r--apps/plugins/sdl/progs/quake/view.h35
-rw-r--r--apps/plugins/sdl/progs/quake/wad.c158
-rw-r--r--apps/plugins/sdl/progs/quake/wad.h75
-rw-r--r--apps/plugins/sdl/progs/quake/winquake.h115
-rw-r--r--apps/plugins/sdl/progs/quake/world.c962
-rw-r--r--apps/plugins/sdl/progs/quake/world.h78
-rw-r--r--apps/plugins/sdl/progs/quake/zone.c935
-rw-r--r--apps/plugins/sdl/progs/quake/zone.h131
-rw-r--r--apps/plugins/sdl/sdl.make40
-rw-r--r--apps/plugins/sdl/src/audio/SDL_audio.c1
-rw-r--r--apps/plugins/sdl/src/audio/rockbox/SDL_rockboxaudio.c19
-rw-r--r--apps/plugins/sdl/src/thread/rockbox/SDL_systhread.c4
-rw-r--r--apps/plugins/sdl/src/timer/rockbox/SDL_systimer.c1
-rw-r--r--apps/plugins/sdl/src/video/rockbox/SDL_rockboxvideo.c2
-rw-r--r--apps/plugins/sdl/wrappers.c122
-rw-r--r--docs/CREDITS1
-rw-r--r--manual/plugins/main.tex2
-rw-r--r--manual/plugins/quake.tex15
171 files changed, 64268 insertions, 20 deletions
diff --git a/apps/plugins/CATEGORIES b/apps/plugins/CATEGORIES
index a0527c87e2..ad99f3959f 100644
--- a/apps/plugins/CATEGORIES
+++ b/apps/plugins/CATEGORIES
@@ -80,6 +80,7 @@ gif,viewers
pong,games
ppm,viewers
properties,viewers
+quake,games
random_folder_advance_config,apps
remote_control,apps
resistor,apps
diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES
index 0ff6eb9c76..c3e56af254 100644
--- a/apps/plugins/SOURCES
+++ b/apps/plugins/SOURCES
@@ -78,6 +78,7 @@ iriverify.c
(!defined(LCD_STRIDEFORMAT) || (LCD_STRIDEFORMAT != VERTICAL_STRIDE))
#if (PLUGIN_BUFFER_SIZE > 0x14000) && defined(CPU_ARM)
duke3d.c
+quake.c
wolf3d.c
#endif
#endif
diff --git a/apps/plugins/SUBDIRS b/apps/plugins/SUBDIRS
index 04c3d763b2..93cf8297b5 100644
--- a/apps/plugins/SUBDIRS
+++ b/apps/plugins/SUBDIRS
@@ -16,11 +16,11 @@ clock
(!defined(LCD_STRIDEFORMAT) || (LCD_STRIDEFORMAT != VERTICAL_STRIDE))
xworld
-/* for duke, etc. */
-#if (CONFIG_PLATFORM & PLATFORM_NATIVE) && (PLUGIN_BUFFER_SIZE > 0x14000) && \
- defined(CPU_ARM)
+/* for duke3d, wolf3d and quake */
+#if (PLUGIN_BUFFER_SIZE > 0x14000) && (CONFIG_PLATFORM & PLATFORM_NATIVE) && defined(CPU_ARM)
sdl
#endif
+
puzzles
#endif
diff --git a/apps/plugins/lib/stdio_compat.h b/apps/plugins/lib/stdio_compat.h
index b9056fae04..bce21ea203 100644
--- a/apps/plugins/lib/stdio_compat.h
+++ b/apps/plugins/lib/stdio_compat.h
@@ -50,6 +50,8 @@
#undef stderr
#define stderr _stderr_
+#define getc fgetc
+
typedef struct {
int fd;
int unget_char;
diff --git a/apps/plugins/quake.c b/apps/plugins/quake.c
new file mode 100644
index 0000000000..d3abd43cc8
--- /dev/null
+++ b/apps/plugins/quake.c
@@ -0,0 +1,31 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2017 Franklin Wei
+ *
+ * Duke3D stub loader.
+ *
+ * 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#include "plugin.h"
+
+#include "lib/overlay.h"
+
+/* this is the plugin entry point */
+enum plugin_status plugin_start(const void* parameter)
+{
+ return run_overlay(parameter, PLUGIN_GAMES_DIR "/quake.ovl", "Quake!");
+}
diff --git a/apps/plugins/sdl/SOURCES.quake b/apps/plugins/sdl/SOURCES.quake
new file mode 100644
index 0000000000..10a53a38a5
--- /dev/null
+++ b/apps/plugins/sdl/SOURCES.quake
@@ -0,0 +1,77 @@
+progs/quake/cd_null.c
+progs/quake/chase.c
+progs/quake/cl_demo.c
+progs/quake/cl_input.c
+progs/quake/cl_main.c
+progs/quake/cl_parse.c
+progs/quake/cl_tent.c
+progs/quake/cmd.c
+progs/quake/common.c
+progs/quake/console.c
+progs/quake/crc.c
+progs/quake/cvar.c
+progs/quake/d_edge.c
+progs/quake/d_fill.c
+progs/quake/d_init.c
+progs/quake/d_modech.c
+progs/quake/d_part.c
+progs/quake/d_polyse.c
+progs/quake/draw.c
+progs/quake/d_scan.c
+progs/quake/d_sky.c
+progs/quake/d_sprite.c
+progs/quake/d_surf.c
+progs/quake/d_vars.c
+progs/quake/d_zpoint.c
+progs/quake/host.c
+progs/quake/host_cmd.c
+progs/quake/keys.c
+progs/quake/mathlib.c
+progs/quake/menu.c
+progs/quake/model.c
+progs/quake/net_loop.c
+progs/quake/net_main.c
+progs/quake/net_none.c
+progs/quake/net_vcr.c
+progs/quake/nonintel.c
+progs/quake/pr_cmds.c
+progs/quake/pr_edict.c
+progs/quake/pr_exec.c
+progs/quake/r_aclip.c
+progs/quake/r_alias.c
+progs/quake/r_bsp.c
+progs/quake/r_draw.c
+progs/quake/r_edge.c
+progs/quake/r_efrag.c
+progs/quake/r_light.c
+progs/quake/r_main.c
+progs/quake/r_misc.c
+progs/quake/r_part.c
+progs/quake/r_sky.c
+progs/quake/r_sprite.c
+progs/quake/r_surf.c
+progs/quake/r_vars.c
+progs/quake/sbar.c
+progs/quake/screen.c
+progs/quake/snd_dma.c
+progs/quake/snd_mem.c
+progs/quake/snd_mix.c
+
+#ifdef __ARM_ARCH__5TEJ__
+progs/quake/snd_mix_arm.S
+#endif
+
+/* we still need generic no matter what */
+progs/quake/snd_mix_generic.c
+
+progs/quake/snd_sdl.c
+progs/quake/sv_main.c
+progs/quake/sv_move.c
+progs/quake/sv_phys.c
+progs/quake/sv_user.c
+progs/quake/sys_sdl.c
+progs/quake/vid_sdl.c
+progs/quake/view.c
+progs/quake/wad.c
+progs/quake/world.c
+progs/quake/zone.c
diff --git a/apps/plugins/sdl/include/SDL_config_rockbox.h b/apps/plugins/sdl/include/SDL_config_rockbox.h
index e268a73a8b..2b7f9a6793 100644
--- a/apps/plugins/sdl/include/SDL_config_rockbox.h
+++ b/apps/plugins/sdl/include/SDL_config_rockbox.h
@@ -38,7 +38,8 @@
//#define COMBINED_SDL
-/* games will use this sample rate */
+/* "recommended" sample rate for Rockbox. Games should use this by
+ * default unless necessary to do otherwise. */
#ifdef SIMULATOR
#define RB_SAMPR SAMPR_44
#else
@@ -57,6 +58,7 @@
/* woot */
#define SDL_AUDIO_DRIVER_ROCKBOX 1
#define SDL_THREAD_ROCKBOX 1
+#undef SDL_THREAD_PTHREAD
#define SDL_TIMER_ROCKBOX 1
#define SDL_VIDEO_DRIVER_ROCKBOX 1
@@ -78,6 +80,10 @@
#define HAVE_FREE 1
#define HAVE_REALLOC 1
#define HAVE_QSORT 1
+#define HAVE_STRLEN 1
+#define HAVE_STRLCPY 1
+#define HAVE_STRCMP 1
+#define HAVE_STRNCMP 1
#undef strdup
@@ -116,6 +122,7 @@
#define floor floor_wrapper
#define fmod fmod_wrapper
#define free tlsf_free
+#define fscanf fscanf_wrapper
#define getchar() rb->sleep(2*HZ)
#define getenv SDL_getenv
#define log rb_log
@@ -146,6 +153,7 @@
#define strcpy strcpy_wrapper
#define strdup strdup_wrapper
#define strerror(x) "error"
+#define strlcpy rb->strlcpy
#define strlen rb->strlen
#define strncasecmp rb->strncasecmp
#define strncat rb->strlcat /* hack */
@@ -163,8 +171,12 @@
#define vsnprintf rb->vsnprintf
#define vsprintf vsprintf_wrapper
+// use Rockbox's string routines
+#define SDL_memcpy memcpy
+#define SDL_memcmp memcmp
+
#define M_PI 3.14159265358979323846
-#define EOF 0xff
+#define EOF (-1)
#define LOAD_XPM
#define MID_MUSIC
@@ -194,6 +206,7 @@ int vprintf(const char *fmt, va_list ap);
void fatal(char *fmt, ...);
void rb_exit(int rc);
void rbsdl_atexit(void (*)(void));
+float atof_wrapper (char *str);
/* speed */
static inline uint16_t readLE16(void *addr)
diff --git a/apps/plugins/sdl/include/SDL_platform.h b/apps/plugins/sdl/include/SDL_platform.h
index 22c320118b..40df082205 100644
--- a/apps/plugins/sdl/include/SDL_platform.h
+++ b/apps/plugins/sdl/include/SDL_platform.h
@@ -108,6 +108,7 @@
#endif
#if defined(ROCKBOX)
#undef __ROCKBOX__
+#undef __LINUX__ /* maybe sim */
#define __ROCKBOX__ 1
#endif
diff --git a/apps/plugins/sdl/main.c b/apps/plugins/sdl/main.c
index 478debc1ad..cefc1565d0 100644
--- a/apps/plugins/sdl/main.c
+++ b/apps/plugins/sdl/main.c
@@ -72,7 +72,7 @@ void cleanup(void)
}
/* 256KB */
-static long main_stack[1024 * 1024 / 4];
+static long main_stack[1024 * 1024 / 2];
int (*main_fn)(int argc, char *argv[]);
int prog_idx;
static void main_thread(void)
@@ -176,7 +176,7 @@ enum plugin_status plugin_start(const void *param)
#if defined(CPU_ARM) && !defined(SIMULATOR)
/* (don't) set alignment trap. Will generate a data abort
* exception on ARM. */
- //set_cr(get_cr() | CR_A);
+ set_cr(get_cr() | CR_A);
#endif
#if 0
@@ -222,8 +222,11 @@ enum plugin_status plugin_start(const void *param)
#undef rb_atexit
rb_atexit(cleanup);
- /* make a new thread to use a bigger stack than otherwise accessible */
- sdl_thread_id = rb->create_thread(main_thread, main_stack, sizeof(main_stack), 0, "sdl_main" IF_PRIO(, PRIORITY_USER_INTERFACE) IF_COP(, CPU));
+ /* make a new thread to use a bigger stack and higher priority than otherwise accessible */
+ sdl_thread_id = rb->create_thread(main_thread, main_stack,
+ sizeof(main_stack), 0, "sdl_main"
+ IF_PRIO(, PRIORITY_USER_INTERFACE) // we need other threads still
+ IF_COP(, CPU));
rb->thread_wait(sdl_thread_id);
rb->sleep(HZ); /* wait a second in case there's an error message on screen */
diff --git a/apps/plugins/sdl/progs/quake/Makefile.linuxi386 b/apps/plugins/sdl/progs/quake/Makefile.linuxi386
new file mode 100644
index 0000000000..e0750d1e78
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/Makefile.linuxi386
@@ -0,0 +1,1242 @@
+#
+# Quake Makefile for Linux 2.0
+#
+# Aug '98 by Zoid <zoid@idsoftware.com>
+#
+# ELF only
+#
+
+BASEVERSION=1.09
+VERSION=$(BASEVERSION)$(GLIBC)
+
+# RPM release number
+RPM_RELEASE=5
+
+ifneq (,$(findstring libc6,$(shell if [ -e /lib/libc.so.6 ];then echo libc6;fi)))
+GLIBC=-glibc
+else
+GLIBC=
+endif
+
+ifneq (,$(findstring alpha,$(shell uname -m)))
+ARCH=axp
+else
+ARCH=i386
+endif
+NOARCH=noarch
+
+#MOUNT_DIR=/grog/Projects/WinQuake
+MOUNT_DIR := $(shell pwd)
+MASTER_DIR=/grog/Projects/QuakeMaster
+MESA_DIR=/usr/local/src/Mesa-2.6
+TDFXGL_DIR = /home/zoid/3dfxgl
+
+BUILD_DEBUG_DIR=debug$(ARCH)$(GLIBC)
+BUILD_RELEASE_DIR=release$(ARCH)$(GLIBC)
+
+#EGCS=/usr/local/egcs-1.1.2/bin/gcc
+#CC=$(EGCS)
+
+BASE_CFLAGS=-Dstricmp=strcasecmp
+RELEASE_CFLAGS=$(BASE_CFLAGS) -g -mpentiumpro -O6 -ffast-math -funroll-loops \
+ -fomit-frame-pointer -fexpensive-optimizations
+DEBUG_CFLAGS=$(BASE_CFLAGS) -g
+LDFLAGS=-lm
+SVGALDFLAGS=-lvga
+XLDFLAGS=-L/usr/X11R6/lib -lX11 -lXext -lXxf86dga
+XCFLAGS=-DX11
+
+MESAGLLDFLAGS=-L/usr/X11/lib -L/usr/local/lib -L$(MESA_DIR)/lib -lMesaGL -lglide2x -lX11 -lXext -ldl
+TDFXGLLDFLAGS=-L$(TDFXGL_DIR)/release$(ARCH)$(GLIBC) -l3dfxgl -lglide2x -ldl
+GLLDFLAGS=-L/usr/X11/lib -L/usr/local/lib -lGL -lX11 -lXext -ldl -lXxf86dga -lXxf86vm -lm
+GLCFLAGS=-DGLQUAKE -I$(MESA_DIR)/include -I/usr/include/glide
+
+DO_CC=$(CC) $(CFLAGS) -o $@ -c $<
+DO_DEBUG_CC=$(CC) $(DEBUG_CFLAGS) -o $@ -c $<
+DO_GL_CC=$(CC) $(CFLAGS) $(GLCFLAGS) -o $@ -c $<
+DO_GL_DEBUG_CC=$(CC) $(DEBUG_CFLAGS) $(GLCFLAGS) -o $@ -c $<
+DO_X11_CC=$(CC) $(CFLAGS) $(XCFLAGS) -o $@ -c $<
+DO_X11_DEBUG_CC=$(CC) $(DEBUG_CFLAGS) $(XCFLAGS) -o $@ -c $<
+DO_O_CC=$(CC) -O $(CFLAGS) -o $@ -c $<
+#DO_AS=$(CC) $(CFLAGS) -DELF -x assembler-with-cpp -o $@ -c $<
+DO_AS=$(CC) $(CFLAGS) -DELF -o $@ -c $<
+DO_GL_AS=$(CC) $(CFLAGS) $(GLCFLAGS) -DELF -x assembler-with-cpp -o $@ -c $<
+
+#############################################################################
+# SETUP AND BUILD
+#############################################################################
+
+TARGETS=$(BUILDDIR)/bin/quake.x11\
+ $(BUILDDIR)/bin/squake \
+ $(BUILDDIR)/bin/glquake \
+ $(BUILDDIR)/bin/glquake.glx \
+ $(BUILDDIR)/bin/glquake.3dfxgl \
+ # $(BUILDDIR)/bin/unixded
+
+build_debug:
+ @-mkdir $(BUILD_DEBUG_DIR) \
+ $(BUILD_DEBUG_DIR)/bin \
+ $(BUILD_DEBUG_DIR)/glquake \
+ $(BUILD_DEBUG_DIR)/squake \
+ $(BUILD_DEBUG_DIR)/unixded \
+ $(BUILD_DEBUG_DIR)/x11
+ $(MAKE) targets BUILDDIR=$(BUILD_DEBUG_DIR) CFLAGS="$(DEBUG_CFLAGS)"
+
+build_release:
+ @-mkdir $(BUILD_RELEASE_DIR) \
+ $(BUILD_RELEASE_DIR)/bin \
+ $(BUILD_RELEASE_DIR)/glquake \
+ $(BUILD_RELEASE_DIR)/squake \
+ $(BUILD_RELEASE_DIR)/unixded \
+ $(BUILD_RELEASE_DIR)/x11
+ $(MAKE) targets BUILDDIR=$(BUILD_RELEASE_DIR) CFLAGS="$(RELEASE_CFLAGS)"
+
+all: build_debug build_release
+
+targets: $(TARGETS)
+
+#############################################################################
+# SVGALIB Quake
+#############################################################################
+
+SQUAKE_OBJS = \
+ $(BUILDDIR)/squake/cl_demo.o \
+ $(BUILDDIR)/squake/cl_input.o \
+ $(BUILDDIR)/squake/cl_main.o \
+ $(BUILDDIR)/squake/cl_parse.o \
+ $(BUILDDIR)/squake/cl_tent.o \
+ $(BUILDDIR)/squake/chase.o \
+ $(BUILDDIR)/squake/cmd.o \
+ $(BUILDDIR)/squake/common.o \
+ $(BUILDDIR)/squake/console.o \
+ $(BUILDDIR)/squake/crc.o \
+ $(BUILDDIR)/squake/cvar.o \
+ $(BUILDDIR)/squake/draw.o \
+ $(BUILDDIR)/squake/d_edge.o \
+ $(BUILDDIR)/squake/d_fill.o \
+ $(BUILDDIR)/squake/d_init.o \
+ $(BUILDDIR)/squake/d_modech.o \
+ $(BUILDDIR)/squake/d_part.o \
+ $(BUILDDIR)/squake/d_polyse.o \
+ $(BUILDDIR)/squake/d_scan.o \
+ $(BUILDDIR)/squake/d_sky.o \
+ $(BUILDDIR)/squake/d_sprite.o \
+ $(BUILDDIR)/squake/d_surf.o \
+ $(BUILDDIR)/squake/d_vars.o \
+ $(BUILDDIR)/squake/d_zpoint.o \
+ $(BUILDDIR)/squake/host.o \
+ $(BUILDDIR)/squake/host_cmd.o \
+ $(BUILDDIR)/squake/keys.o \
+ $(BUILDDIR)/squake/menu.o \
+ $(BUILDDIR)/squake/mathlib.o \
+ $(BUILDDIR)/squake/model.o \
+ $(BUILDDIR)/squake/net_dgrm.o \
+ $(BUILDDIR)/squake/net_loop.o \
+ $(BUILDDIR)/squake/net_main.o \
+ $(BUILDDIR)/squake/net_vcr.o \
+ $(BUILDDIR)/squake/net_udp.o \
+ $(BUILDDIR)/squake/net_bsd.o \
+ $(BUILDDIR)/squake/nonintel.o \
+ $(BUILDDIR)/squake/pr_cmds.o \
+ $(BUILDDIR)/squake/pr_edict.o \
+ $(BUILDDIR)/squake/pr_exec.o \
+ $(BUILDDIR)/squake/r_aclip.o \
+ $(BUILDDIR)/squake/r_alias.o \
+ $(BUILDDIR)/squake/r_bsp.o \
+ $(BUILDDIR)/squake/r_light.o \
+ $(BUILDDIR)/squake/r_draw.o \
+ $(BUILDDIR)/squake/r_efrag.o \
+ $(BUILDDIR)/squake/r_edge.o \
+ $(BUILDDIR)/squake/r_misc.o \
+ $(BUILDDIR)/squake/r_main.o \
+ $(BUILDDIR)/squake/r_sky.o \
+ $(BUILDDIR)/squake/r_sprite.o \
+ $(BUILDDIR)/squake/r_surf.o \
+ $(BUILDDIR)/squake/r_part.o \
+ $(BUILDDIR)/squake/r_vars.o \
+ $(BUILDDIR)/squake/screen.o \
+ $(BUILDDIR)/squake/sbar.o \
+ $(BUILDDIR)/squake/sv_main.o \
+ $(BUILDDIR)/squake/sv_phys.o \
+ $(BUILDDIR)/squake/sv_move.o \
+ $(BUILDDIR)/squake/sv_user.o \
+ $(BUILDDIR)/squake/zone.o \
+ $(BUILDDIR)/squake/view.o \
+ $(BUILDDIR)/squake/wad.o \
+ $(BUILDDIR)/squake/world.o \
+ $(BUILDDIR)/squake/cd_linux.o \
+ $(BUILDDIR)/squake/sys_linux.o \
+ $(BUILDDIR)/squake/vid_svgalib.o \
+ $(BUILDDIR)/squake/snd_dma.o \
+ $(BUILDDIR)/squake/snd_mem.o \
+ $(BUILDDIR)/squake/snd_mix.o \
+ $(BUILDDIR)/squake/snd_linux.o \
+ \
+ $(BUILDDIR)/squake/d_copy.o \
+ $(BUILDDIR)/squake/d_draw.o \
+ $(BUILDDIR)/squake/d_draw16.o \
+ $(BUILDDIR)/squake/d_parta.o \
+ $(BUILDDIR)/squake/d_polysa.o \
+ $(BUILDDIR)/squake/d_scana.o \
+ $(BUILDDIR)/squake/d_spr8.o \
+ $(BUILDDIR)/squake/d_varsa.o \
+ $(BUILDDIR)/squake/math.o \
+ $(BUILDDIR)/squake/r_aliasa.o \
+ $(BUILDDIR)/squake/r_drawa.o \
+ $(BUILDDIR)/squake/r_edgea.o \
+ $(BUILDDIR)/squake/r_varsa.o \
+ $(BUILDDIR)/squake/surf16.o \
+ $(BUILDDIR)/squake/surf8.o \
+ $(BUILDDIR)/squake/worlda.o \
+ $(BUILDDIR)/squake/r_aclipa.o \
+ $(BUILDDIR)/squake/snd_mixa.o \
+ $(BUILDDIR)/squake/sys_dosa.o
+
+$(BUILDDIR)/bin/squake : $(SQUAKE_OBJS)
+ $(CC) $(CFLAGS) -o $@ $(SQUAKE_OBJS) $(SVGALDFLAGS) $(LDFLAGS)
+
+####
+
+$(BUILDDIR)/squake/cl_demo.o : $(MOUNT_DIR)/cl_demo.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/cl_input.o : $(MOUNT_DIR)/cl_input.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/cl_main.o : $(MOUNT_DIR)/cl_main.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/cl_parse.o : $(MOUNT_DIR)/cl_parse.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/cl_tent.o : $(MOUNT_DIR)/cl_tent.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/chase.o : $(MOUNT_DIR)/chase.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/cmd.o : $(MOUNT_DIR)/cmd.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/common.o : $(MOUNT_DIR)/common.c
+ $(DO_DEBUG_CC)
+
+$(BUILDDIR)/squake/console.o : $(MOUNT_DIR)/console.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/crc.o : $(MOUNT_DIR)/crc.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/cvar.o : $(MOUNT_DIR)/cvar.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/draw.o : $(MOUNT_DIR)/draw.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/d_edge.o : $(MOUNT_DIR)/d_edge.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/d_fill.o : $(MOUNT_DIR)/d_fill.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/d_init.o : $(MOUNT_DIR)/d_init.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/d_modech.o : $(MOUNT_DIR)/d_modech.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/d_part.o : $(MOUNT_DIR)/d_part.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/d_polyse.o : $(MOUNT_DIR)/d_polyse.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/d_scan.o : $(MOUNT_DIR)/d_scan.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/d_sky.o : $(MOUNT_DIR)/d_sky.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/d_sprite.o : $(MOUNT_DIR)/d_sprite.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/d_surf.o : $(MOUNT_DIR)/d_surf.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/d_vars.o : $(MOUNT_DIR)/d_vars.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/d_zpoint.o : $(MOUNT_DIR)/d_zpoint.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/host.o : $(MOUNT_DIR)/host.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/host_cmd.o : $(MOUNT_DIR)/host_cmd.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/keys.o : $(MOUNT_DIR)/keys.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/menu.o : $(MOUNT_DIR)/menu.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/mathlib.o : $(MOUNT_DIR)/mathlib.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/model.o : $(MOUNT_DIR)/model.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/net_dgrm.o : $(MOUNT_DIR)/net_dgrm.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/net_loop.o : $(MOUNT_DIR)/net_loop.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/net_main.o : $(MOUNT_DIR)/net_main.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/net_vcr.o : $(MOUNT_DIR)/net_vcr.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/net_udp.o : $(MOUNT_DIR)/net_udp.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/net_bsd.o : $(MOUNT_DIR)/net_bsd.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/nonintel.o : $(MOUNT_DIR)/nonintel.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/pr_cmds.o : $(MOUNT_DIR)/pr_cmds.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/pr_edict.o : $(MOUNT_DIR)/pr_edict.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/pr_exec.o : $(MOUNT_DIR)/pr_exec.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/r_aclip.o : $(MOUNT_DIR)/r_aclip.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/r_alias.o : $(MOUNT_DIR)/r_alias.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/r_bsp.o : $(MOUNT_DIR)/r_bsp.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/r_light.o : $(MOUNT_DIR)/r_light.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/r_draw.o : $(MOUNT_DIR)/r_draw.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/r_efrag.o : $(MOUNT_DIR)/r_efrag.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/r_edge.o : $(MOUNT_DIR)/r_edge.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/r_misc.o : $(MOUNT_DIR)/r_misc.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/r_main.o : $(MOUNT_DIR)/r_main.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/r_sky.o : $(MOUNT_DIR)/r_sky.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/r_sprite.o : $(MOUNT_DIR)/r_sprite.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/r_surf.o : $(MOUNT_DIR)/r_surf.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/r_part.o : $(MOUNT_DIR)/r_part.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/r_vars.o : $(MOUNT_DIR)/r_vars.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/screen.o : $(MOUNT_DIR)/screen.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/sbar.o : $(MOUNT_DIR)/sbar.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/sv_main.o : $(MOUNT_DIR)/sv_main.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/sv_phys.o : $(MOUNT_DIR)/sv_phys.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/sv_move.o : $(MOUNT_DIR)/sv_move.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/sv_user.o : $(MOUNT_DIR)/sv_user.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/zone.o : $(MOUNT_DIR)/zone.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/view.o : $(MOUNT_DIR)/view.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/wad.o : $(MOUNT_DIR)/wad.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/world.o : $(MOUNT_DIR)/world.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/cd_linux.o : $(MOUNT_DIR)/cd_linux.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/sys_linux.o :$(MOUNT_DIR)/sys_linux.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/vid_svgalib.o:$(MOUNT_DIR)/vid_svgalib.c
+ $(DO_O_CC)
+
+$(BUILDDIR)/squake/snd_dma.o : $(MOUNT_DIR)/snd_dma.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/snd_mem.o : $(MOUNT_DIR)/snd_mem.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/snd_mix.o : $(MOUNT_DIR)/snd_mix.c
+ $(DO_CC)
+
+$(BUILDDIR)/squake/snd_linux.o :$(MOUNT_DIR)/snd_linux.c
+ $(DO_CC)
+
+#####
+
+$(BUILDDIR)/squake/d_copy.o : $(MOUNT_DIR)/d_copy.S
+ $(DO_AS)
+
+$(BUILDDIR)/squake/d_draw.o : $(MOUNT_DIR)/d_draw.S
+ $(DO_AS)
+
+$(BUILDDIR)/squake/d_draw16.o : $(MOUNT_DIR)/d_draw16.S
+ $(DO_AS)
+
+$(BUILDDIR)/squake/d_parta.o : $(MOUNT_DIR)/d_parta.S
+ $(DO_AS)
+
+$(BUILDDIR)/squake/d_polysa.o : $(MOUNT_DIR)/d_polysa.S
+ $(DO_AS)
+
+$(BUILDDIR)/squake/d_scana.o : $(MOUNT_DIR)/d_scana.S
+ $(DO_AS)
+
+$(BUILDDIR)/squake/d_spr8.o : $(MOUNT_DIR)/d_spr8.S
+ $(DO_AS)
+
+$(BUILDDIR)/squake/d_varsa.o : $(MOUNT_DIR)/d_varsa.S
+ $(DO_AS)
+
+$(BUILDDIR)/squake/math.o : $(MOUNT_DIR)/math.S
+ $(DO_AS)
+
+$(BUILDDIR)/squake/r_aliasa.o : $(MOUNT_DIR)/r_aliasa.S
+ $(DO_AS)
+
+$(BUILDDIR)/squake/r_drawa.o : $(MOUNT_DIR)/r_drawa.S
+ $(DO_AS)
+
+$(BUILDDIR)/squake/r_edgea.o : $(MOUNT_DIR)/r_edgea.S
+ $(DO_AS)
+
+$(BUILDDIR)/squake/r_varsa.o : $(MOUNT_DIR)/r_varsa.S
+ $(DO_AS)
+
+$(BUILDDIR)/squake/surf16.o : $(MOUNT_DIR)/surf16.S
+ $(DO_AS)
+
+$(BUILDDIR)/squake/surf8.o : $(MOUNT_DIR)/surf8.S
+ $(DO_AS)
+
+$(BUILDDIR)/squake/worlda.o : $(MOUNT_DIR)/worlda.S
+ $(DO_AS)
+
+$(BUILDDIR)/squake/r_aclipa.o : $(MOUNT_DIR)/r_aclipa.S
+ $(DO_AS)
+
+$(BUILDDIR)/squake/snd_mixa.o : $(MOUNT_DIR)/snd_mixa.S
+ $(DO_AS)
+
+$(BUILDDIR)/squake/sys_dosa.o : $(MOUNT_DIR)/sys_dosa.S
+ $(DO_AS)
+
+#############################################################################
+# X11 Quake
+#############################################################################
+
+X11_OBJS = \
+ $(BUILDDIR)/x11/cl_demo.o \
+ $(BUILDDIR)/x11/cl_input.o \
+ $(BUILDDIR)/x11/cl_main.o \
+ $(BUILDDIR)/x11/cl_parse.o \
+ $(BUILDDIR)/x11/cl_tent.o \
+ $(BUILDDIR)/x11/chase.o \
+ $(BUILDDIR)/x11/cmd.o \
+ $(BUILDDIR)/x11/common.o \
+ $(BUILDDIR)/x11/console.o \
+ $(BUILDDIR)/x11/crc.o \
+ $(BUILDDIR)/x11/cvar.o \
+ $(BUILDDIR)/x11/draw.o \
+ $(BUILDDIR)/x11/d_edge.o \
+ $(BUILDDIR)/x11/d_fill.o \
+ $(BUILDDIR)/x11/d_init.o \
+ $(BUILDDIR)/x11/d_modech.o \
+ $(BUILDDIR)/x11/d_part.o \
+ $(BUILDDIR)/x11/d_polyse.o \
+ $(BUILDDIR)/x11/d_scan.o \
+ $(BUILDDIR)/x11/d_sky.o \
+ $(BUILDDIR)/x11/d_sprite.o \
+ $(BUILDDIR)/x11/d_surf.o \
+ $(BUILDDIR)/x11/d_vars.o \
+ $(BUILDDIR)/x11/d_zpoint.o \
+ $(BUILDDIR)/x11/host.o \
+ $(BUILDDIR)/x11/host_cmd.o \
+ $(BUILDDIR)/x11/keys.o \
+ $(BUILDDIR)/x11/menu.o \
+ $(BUILDDIR)/x11/mathlib.o \
+ $(BUILDDIR)/x11/model.o \
+ $(BUILDDIR)/x11/net_dgrm.o \
+ $(BUILDDIR)/x11/net_loop.o \
+ $(BUILDDIR)/x11/net_main.o \
+ $(BUILDDIR)/x11/net_vcr.o \
+ $(BUILDDIR)/x11/net_udp.o \
+ $(BUILDDIR)/x11/net_bsd.o \
+ $(BUILDDIR)/x11/nonintel.o \
+ $(BUILDDIR)/x11/pr_cmds.o \
+ $(BUILDDIR)/x11/pr_edict.o \
+ $(BUILDDIR)/x11/pr_exec.o \
+ $(BUILDDIR)/x11/r_aclip.o \
+ $(BUILDDIR)/x11/r_alias.o \
+ $(BUILDDIR)/x11/r_bsp.o \
+ $(BUILDDIR)/x11/r_light.o \
+ $(BUILDDIR)/x11/r_draw.o \
+ $(BUILDDIR)/x11/r_efrag.o \
+ $(BUILDDIR)/x11/r_edge.o \
+ $(BUILDDIR)/x11/r_misc.o \
+ $(BUILDDIR)/x11/r_main.o \
+ $(BUILDDIR)/x11/r_sky.o \
+ $(BUILDDIR)/x11/r_sprite.o \
+ $(BUILDDIR)/x11/r_surf.o \
+ $(BUILDDIR)/x11/r_part.o \
+ $(BUILDDIR)/x11/r_vars.o \
+ $(BUILDDIR)/x11/screen.o \
+ $(BUILDDIR)/x11/sbar.o \
+ $(BUILDDIR)/x11/sv_main.o \
+ $(BUILDDIR)/x11/sv_phys.o \
+ $(BUILDDIR)/x11/sv_move.o \
+ $(BUILDDIR)/x11/sv_user.o \
+ $(BUILDDIR)/x11/zone.o \
+ $(BUILDDIR)/x11/view.o \
+ $(BUILDDIR)/x11/wad.o \
+ $(BUILDDIR)/x11/world.o \
+ $(BUILDDIR)/x11/cd_linux.o \
+ $(BUILDDIR)/x11/sys_linux.o \
+ $(BUILDDIR)/x11/vid_x.o \
+ $(BUILDDIR)/x11/snd_dma.o \
+ $(BUILDDIR)/x11/snd_mem.o \
+ $(BUILDDIR)/x11/snd_mix.o \
+ $(BUILDDIR)/x11/snd_linux.o \
+ \
+ $(BUILDDIR)/x11/d_draw.o \
+ $(BUILDDIR)/x11/d_draw16.o \
+ $(BUILDDIR)/x11/d_parta.o \
+ $(BUILDDIR)/x11/d_polysa.o \
+ $(BUILDDIR)/x11/d_scana.o \
+ $(BUILDDIR)/x11/d_spr8.o \
+ $(BUILDDIR)/x11/d_varsa.o \
+ $(BUILDDIR)/x11/math.o \
+ $(BUILDDIR)/x11/r_aliasa.o \
+ $(BUILDDIR)/x11/r_drawa.o \
+ $(BUILDDIR)/x11/r_edgea.o \
+ $(BUILDDIR)/x11/r_varsa.o \
+ $(BUILDDIR)/x11/surf16.o \
+ $(BUILDDIR)/x11/surf8.o \
+ $(BUILDDIR)/x11/worlda.o \
+ $(BUILDDIR)/x11/r_aclipa.o \
+ $(BUILDDIR)/x11/snd_mixa.o \
+ $(BUILDDIR)/x11/sys_dosa.o
+
+$(BUILDDIR)/bin/quake.x11 : $(X11_OBJS)
+ $(CC) $(CFLAGS) -o $@ $(X11_OBJS) $(XLDFLAGS) $(LDFLAGS)
+
+####
+
+$(BUILDDIR)/x11/cl_demo.o : $(MOUNT_DIR)/cl_demo.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/cl_input.o : $(MOUNT_DIR)/cl_input.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/cl_main.o : $(MOUNT_DIR)/cl_main.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/cl_parse.o : $(MOUNT_DIR)/cl_parse.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/cl_tent.o : $(MOUNT_DIR)/cl_tent.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/chase.o : $(MOUNT_DIR)/chase.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/cmd.o : $(MOUNT_DIR)/cmd.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/common.o : $(MOUNT_DIR)/common.c
+ $(DO_X11_DEBUG_CC)
+
+$(BUILDDIR)/x11/console.o : $(MOUNT_DIR)/console.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/crc.o : $(MOUNT_DIR)/crc.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/cvar.o : $(MOUNT_DIR)/cvar.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/draw.o : $(MOUNT_DIR)/draw.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/d_edge.o : $(MOUNT_DIR)/d_edge.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/d_fill.o : $(MOUNT_DIR)/d_fill.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/d_init.o : $(MOUNT_DIR)/d_init.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/d_modech.o : $(MOUNT_DIR)/d_modech.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/d_part.o : $(MOUNT_DIR)/d_part.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/d_polyse.o : $(MOUNT_DIR)/d_polyse.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/d_scan.o : $(MOUNT_DIR)/d_scan.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/d_sky.o : $(MOUNT_DIR)/d_sky.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/d_sprite.o : $(MOUNT_DIR)/d_sprite.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/d_surf.o : $(MOUNT_DIR)/d_surf.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/d_vars.o : $(MOUNT_DIR)/d_vars.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/d_zpoint.o : $(MOUNT_DIR)/d_zpoint.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/host.o : $(MOUNT_DIR)/host.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/host_cmd.o : $(MOUNT_DIR)/host_cmd.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/keys.o : $(MOUNT_DIR)/keys.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/menu.o : $(MOUNT_DIR)/menu.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/mathlib.o : $(MOUNT_DIR)/mathlib.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/model.o : $(MOUNT_DIR)/model.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/net_dgrm.o : $(MOUNT_DIR)/net_dgrm.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/net_loop.o : $(MOUNT_DIR)/net_loop.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/net_main.o : $(MOUNT_DIR)/net_main.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/net_vcr.o : $(MOUNT_DIR)/net_vcr.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/net_udp.o : $(MOUNT_DIR)/net_udp.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/net_bsd.o : $(MOUNT_DIR)/net_bsd.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/nonintel.o : $(MOUNT_DIR)/nonintel.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/pr_cmds.o : $(MOUNT_DIR)/pr_cmds.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/pr_edict.o : $(MOUNT_DIR)/pr_edict.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/pr_exec.o : $(MOUNT_DIR)/pr_exec.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/r_aclip.o : $(MOUNT_DIR)/r_aclip.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/r_alias.o : $(MOUNT_DIR)/r_alias.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/r_bsp.o : $(MOUNT_DIR)/r_bsp.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/r_light.o : $(MOUNT_DIR)/r_light.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/r_draw.o : $(MOUNT_DIR)/r_draw.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/r_efrag.o : $(MOUNT_DIR)/r_efrag.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/r_edge.o : $(MOUNT_DIR)/r_edge.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/r_misc.o : $(MOUNT_DIR)/r_misc.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/r_main.o : $(MOUNT_DIR)/r_main.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/r_sky.o : $(MOUNT_DIR)/r_sky.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/r_sprite.o : $(MOUNT_DIR)/r_sprite.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/r_surf.o : $(MOUNT_DIR)/r_surf.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/r_part.o : $(MOUNT_DIR)/r_part.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/r_vars.o : $(MOUNT_DIR)/r_vars.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/screen.o : $(MOUNT_DIR)/screen.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/sbar.o : $(MOUNT_DIR)/sbar.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/sv_main.o : $(MOUNT_DIR)/sv_main.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/sv_phys.o : $(MOUNT_DIR)/sv_phys.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/sv_move.o : $(MOUNT_DIR)/sv_move.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/sv_user.o : $(MOUNT_DIR)/sv_user.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/zone.o : $(MOUNT_DIR)/zone.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/view.o : $(MOUNT_DIR)/view.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/wad.o : $(MOUNT_DIR)/wad.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/world.o : $(MOUNT_DIR)/world.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/cd_linux.o : $(MOUNT_DIR)/cd_linux.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/sys_linux.o :$(MOUNT_DIR)/sys_linux.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/vid_x.o: $(MOUNT_DIR)/vid_x.c
+ $(DO_O_CC)
+
+$(BUILDDIR)/x11/snd_dma.o : $(MOUNT_DIR)/snd_dma.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/snd_mem.o : $(MOUNT_DIR)/snd_mem.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/snd_mix.o : $(MOUNT_DIR)/snd_mix.c
+ $(DO_X11_CC)
+
+$(BUILDDIR)/x11/snd_linux.o :$(MOUNT_DIR)/snd_linux.c
+ $(DO_X11_CC)
+
+#####
+
+$(BUILDDIR)/x11/d_copy.o : $(MOUNT_DIR)/d_copy.S
+ $(DO_AS)
+
+$(BUILDDIR)/x11/d_draw.o : $(MOUNT_DIR)/d_draw.S
+ $(DO_AS)
+
+$(BUILDDIR)/x11/d_draw16.o : $(MOUNT_DIR)/d_draw16.S
+ $(DO_AS)
+
+$(BUILDDIR)/x11/d_parta.o : $(MOUNT_DIR)/d_parta.S
+ $(DO_AS)
+
+$(BUILDDIR)/x11/d_polysa.o : $(MOUNT_DIR)/d_polysa.S
+ $(DO_AS)
+
+$(BUILDDIR)/x11/d_scana.o : $(MOUNT_DIR)/d_scana.S
+ $(DO_AS)
+
+$(BUILDDIR)/x11/d_spr8.o : $(MOUNT_DIR)/d_spr8.S
+ $(DO_AS)
+
+$(BUILDDIR)/x11/d_varsa.o : $(MOUNT_DIR)/d_varsa.S
+ $(DO_AS)
+
+$(BUILDDIR)/x11/math.o : $(MOUNT_DIR)/math.S
+ $(DO_AS)
+
+$(BUILDDIR)/x11/r_aliasa.o : $(MOUNT_DIR)/r_aliasa.S
+ $(DO_AS)
+
+$(BUILDDIR)/x11/r_drawa.o : $(MOUNT_DIR)/r_drawa.S
+ $(DO_AS)
+
+$(BUILDDIR)/x11/r_edgea.o : $(MOUNT_DIR)/r_edgea.S
+ $(DO_AS)
+
+$(BUILDDIR)/x11/r_varsa.o : $(MOUNT_DIR)/r_varsa.S
+ $(DO_AS)
+
+$(BUILDDIR)/x11/surf16.o : $(MOUNT_DIR)/surf16.S
+ $(DO_AS)
+
+$(BUILDDIR)/x11/surf8.o : $(MOUNT_DIR)/surf8.S
+ $(DO_AS)
+
+$(BUILDDIR)/x11/worlda.o : $(MOUNT_DIR)/worlda.S
+ $(DO_AS)
+
+$(BUILDDIR)/x11/r_aclipa.o : $(MOUNT_DIR)/r_aclipa.S
+ $(DO_AS)
+
+$(BUILDDIR)/x11/snd_mixa.o : $(MOUNT_DIR)/snd_mixa.S
+ $(DO_AS)
+
+$(BUILDDIR)/x11/sys_dosa.o : $(MOUNT_DIR)/sys_dosa.S
+ $(DO_AS)
+
+#############################################################################
+# GLQuake
+#############################################################################
+
+GLQUAKE_OBJS= \
+ $(BUILDDIR)/glquake/cl_demo.o \
+ $(BUILDDIR)/glquake/cl_input.o \
+ $(BUILDDIR)/glquake/cl_main.o \
+ $(BUILDDIR)/glquake/cl_parse.o \
+ $(BUILDDIR)/glquake/cl_tent.o \
+ $(BUILDDIR)/glquake/chase.o \
+ $(BUILDDIR)/glquake/cmd.o \
+ $(BUILDDIR)/glquake/common.o \
+ $(BUILDDIR)/glquake/console.o \
+ $(BUILDDIR)/glquake/crc.o \
+ $(BUILDDIR)/glquake/cvar.o \
+ \
+ $(BUILDDIR)/glquake/gl_draw.o \
+ $(BUILDDIR)/glquake/gl_mesh.o \
+ $(BUILDDIR)/glquake/gl_model.o \
+ $(BUILDDIR)/glquake/gl_refrag.o \
+ $(BUILDDIR)/glquake/gl_rlight.o \
+ $(BUILDDIR)/glquake/gl_rmain.o \
+ $(BUILDDIR)/glquake/gl_rmisc.o \
+ $(BUILDDIR)/glquake/gl_rsurf.o \
+ $(BUILDDIR)/glquake/gl_screen.o \
+ $(BUILDDIR)/glquake/gl_test.o \
+ $(BUILDDIR)/glquake/gl_warp.o \
+ \
+ $(BUILDDIR)/glquake/host.o \
+ $(BUILDDIR)/glquake/host_cmd.o \
+ $(BUILDDIR)/glquake/keys.o \
+ $(BUILDDIR)/glquake/menu.o \
+ $(BUILDDIR)/glquake/mathlib.o \
+ $(BUILDDIR)/glquake/net_dgrm.o \
+ $(BUILDDIR)/glquake/net_loop.o \
+ $(BUILDDIR)/glquake/net_main.o \
+ $(BUILDDIR)/glquake/net_vcr.o \
+ $(BUILDDIR)/glquake/net_udp.o \
+ $(BUILDDIR)/glquake/net_bsd.o \
+ $(BUILDDIR)/glquake/pr_cmds.o \
+ $(BUILDDIR)/glquake/pr_edict.o \
+ $(BUILDDIR)/glquake/pr_exec.o \
+ $(BUILDDIR)/glquake/r_part.o \
+ $(BUILDDIR)/glquake/sbar.o \
+ $(BUILDDIR)/glquake/sv_main.o \
+ $(BUILDDIR)/glquake/sv_phys.o \
+ $(BUILDDIR)/glquake/sv_move.o \
+ $(BUILDDIR)/glquake/sv_user.o \
+ $(BUILDDIR)/glquake/zone.o \
+ $(BUILDDIR)/glquake/view.o \
+ $(BUILDDIR)/glquake/wad.o \
+ $(BUILDDIR)/glquake/world.o \
+ $(BUILDDIR)/glquake/cd_linux.o \
+ $(BUILDDIR)/glquake/sys_linux.o \
+ $(BUILDDIR)/glquake/snd_dma.o \
+ $(BUILDDIR)/glquake/snd_mem.o \
+ $(BUILDDIR)/glquake/snd_mix.o \
+ $(BUILDDIR)/glquake/snd_linux.o \
+ \
+ $(BUILDDIR)/glquake/math.o \
+ $(BUILDDIR)/glquake/worlda.o \
+ $(BUILDDIR)/glquake/snd_mixa.o \
+ $(BUILDDIR)/glquake/sys_dosa.o
+
+GLSVGA_OBJS=$(BUILDDIR)/glquake/gl_vidlinux.o
+
+GLX_OBJS=$(BUILDDIR)/glquake/gl_vidlinuxglx.o
+
+$(BUILDDIR)/bin/glquake : $(GLQUAKE_OBJS) $(GLSVGA_OBJS)
+ $(CC) $(CFLAGS) -o $@ $(GLQUAKE_OBJS) $(GLSVGA_OBJS) $(MESAGLLDFLAGS) $(SVGALDFLAGS) $(LDFLAGS)
+
+$(BUILDDIR)/bin/glquake.glx : $(GLQUAKE_OBJS) $(GLX_OBJS)
+ $(CC) $(CFLAGS) -o $@ $(GLQUAKE_OBJS) $(GLX_OBJS) $(GLLDFLAGS) $(LDFLAGS)
+
+$(BUILDDIR)/bin/glquake.3dfxgl : $(GLQUAKE_OBJS) $(GLSVGA_OBJS)
+ $(CC) $(CFLAGS) -o $@ $(GLQUAKE_OBJS) $(GLSVGA_OBJS) $(TDFXGLLDFLAGS) $(SVGALDFLAGS) $(LDFLAGS)
+
+$(BUILDDIR)/glquake/cl_demo.o : $(MOUNT_DIR)/cl_demo.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/cl_input.o : $(MOUNT_DIR)/cl_input.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/cl_main.o : $(MOUNT_DIR)/cl_main.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/cl_parse.o : $(MOUNT_DIR)/cl_parse.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/cl_tent.o : $(MOUNT_DIR)/cl_tent.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/chase.o : $(MOUNT_DIR)/chase.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/cmd.o : $(MOUNT_DIR)/cmd.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/common.o : $(MOUNT_DIR)/common.c
+ $(DO_GL_DEBUG_CC)
+
+$(BUILDDIR)/glquake/console.o : $(MOUNT_DIR)/console.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/crc.o : $(MOUNT_DIR)/crc.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/cvar.o : $(MOUNT_DIR)/cvar.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/gl_draw.o : $(MOUNT_DIR)/gl_draw.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/gl_mesh.o : $(MOUNT_DIR)/gl_mesh.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/gl_model.o : $(MOUNT_DIR)/gl_model.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/gl_refrag.o : $(MOUNT_DIR)/gl_refrag.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/gl_rlight.o : $(MOUNT_DIR)/gl_rlight.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/gl_rmain.o : $(MOUNT_DIR)/gl_rmain.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/gl_rmisc.o : $(MOUNT_DIR)/gl_rmisc.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/gl_rsurf.o : $(MOUNT_DIR)/gl_rsurf.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/gl_screen.o : $(MOUNT_DIR)/gl_screen.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/gl_test.o : $(MOUNT_DIR)/gl_test.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/gl_vidlinux.o : $(MOUNT_DIR)/gl_vidlinux.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/gl_vidlinuxglx.o : $(MOUNT_DIR)/gl_vidlinuxglx.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/gl_warp.o : $(MOUNT_DIR)/gl_warp.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/host.o : $(MOUNT_DIR)/host.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/host_cmd.o : $(MOUNT_DIR)/host_cmd.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/keys.o : $(MOUNT_DIR)/keys.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/menu.o : $(MOUNT_DIR)/menu.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/mathlib.o : $(MOUNT_DIR)/mathlib.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/net_dgrm.o : $(MOUNT_DIR)/net_dgrm.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/net_loop.o : $(MOUNT_DIR)/net_loop.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/net_main.o : $(MOUNT_DIR)/net_main.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/net_vcr.o : $(MOUNT_DIR)/net_vcr.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/net_udp.o : $(MOUNT_DIR)/net_udp.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/net_bsd.o : $(MOUNT_DIR)/net_bsd.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/pr_cmds.o : $(MOUNT_DIR)/pr_cmds.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/pr_edict.o : $(MOUNT_DIR)/pr_edict.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/pr_exec.o : $(MOUNT_DIR)/pr_exec.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/r_part.o : $(MOUNT_DIR)/r_part.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/sbar.o : $(MOUNT_DIR)/sbar.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/sv_main.o : $(MOUNT_DIR)/sv_main.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/sv_phys.o : $(MOUNT_DIR)/sv_phys.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/sv_move.o : $(MOUNT_DIR)/sv_move.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/sv_user.o : $(MOUNT_DIR)/sv_user.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/zone.o : $(MOUNT_DIR)/zone.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/view.o : $(MOUNT_DIR)/view.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/wad.o : $(MOUNT_DIR)/wad.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/world.o : $(MOUNT_DIR)/world.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/cd_linux.o : $(MOUNT_DIR)/cd_linux.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/sys_linux.o : $(MOUNT_DIR)/sys_linux.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/snd_dma.o : $(MOUNT_DIR)/snd_dma.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/snd_mem.o : $(MOUNT_DIR)/snd_mem.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/snd_mix.o : $(MOUNT_DIR)/snd_mix.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/snd_linux.o : $(MOUNT_DIR)/snd_linux.c
+ $(DO_GL_CC)
+
+$(BUILDDIR)/glquake/math.o : $(MOUNT_DIR)/math.S
+ $(DO_GL_AS)
+
+$(BUILDDIR)/glquake/worlda.o : $(MOUNT_DIR)/worlda.S
+ $(DO_GL_AS)
+
+$(BUILDDIR)/glquake/snd_mixa.o : $(MOUNT_DIR)/snd_mixa.S
+ $(DO_GL_AS)
+
+$(BUILDDIR)/glquake/sys_dosa.o : $(MOUNT_DIR)/sys_dosa.S
+ $(DO_GL_AS)
+
+#############################################################################
+# RPM
+#############################################################################
+
+# Make RPMs. You need to be root to make this work
+RPMROOT=/usr/src/redhat
+RPM = rpm
+RPMFLAGS = -bb
+INSTALLDIR = /usr/local/games/quake
+TMPDIR = /var/tmp
+RPMDIR = $(TMPDIR)/quake-$(VERSION)
+BASERPMDIR = $(TMPDIR)/quake-$(BASEVERSION)
+
+rpm: rpm-quake rpm-quake-data rpm-hipnotic rpm-rogue
+
+rpm-quake: quake.spec \
+ $(BUILD_RELEASE_DIR)/bin/squake \
+ $(BUILD_RELEASE_DIR)/bin/quake.x11 \
+ $(BUILD_RELEASE_DIR)/bin/glquake \
+ $(BUILD_RELEASE_DIR)/bin/glquake.glx \
+ $(BUILD_RELEASE_DIR)/bin/glquake.3dfxgl
+ touch $(RPMROOT)/SOURCES/quake-$(VERSION).tar.gz
+ if [ ! -d RPMS ];then mkdir RPMS;fi
+ cp $(MOUNT_DIR)/quake.gif $(RPMROOT)/SOURCES/quake.gif
+
+ # basic binaries rpm
+ -mkdirhier $(RPMDIR)/$(INSTALLDIR)
+ cp $(MOUNT_DIR)/docs/README $(RPMDIR)/$(INSTALLDIR)/.
+ cp $(BUILD_RELEASE_DIR)/bin/squake $(RPMDIR)/$(INSTALLDIR)/squake
+ strip $(RPMDIR)/$(INSTALLDIR)/squake
+ cp $(BUILD_RELEASE_DIR)/bin/quake.x11 $(RPMDIR)/$(INSTALLDIR)/quake.x11
+ strip $(RPMDIR)/$(INSTALLDIR)/quake.x11
+ cp $(BUILD_RELEASE_DIR)/bin/glquake $(RPMDIR)/$(INSTALLDIR)/glquake
+ strip $(RPMDIR)/$(INSTALLDIR)/glquake
+ cp $(BUILD_RELEASE_DIR)/bin/glquake.glx $(RPMDIR)/$(INSTALLDIR)/glquake.glx
+ strip $(RPMDIR)/$(INSTALLDIR)/glquake.glx
+ cp $(BUILD_RELEASE_DIR)/bin/glquake.3dfxgl $(RPMDIR)/$(INSTALLDIR)/glquake.3dfxgl
+ strip $(RPMDIR)/$(INSTALLDIR)/glquake.3dfxgl
+ -mkdirhier $(RPMDIR)/usr/lib
+ cp $(TDFXGL_DIR)/release$(ARCH)$(GLIBC)/lib3dfxgl.so $(RPMDIR)/usr/lib/lib3dfxgl.so
+ cp $(MESA_DIR)/lib/libMesaGL.so.2.6 $(RPMDIR)/usr/lib/libMesaGL.so.2.6
+
+ cp quake.spec $(RPMROOT)/SPECS/.
+ cd $(RPMROOT)/SPECS; $(RPM) $(RPMFLAGS) quake.spec
+ rm -rf $(RPMDIR)
+ rm -f $(RPMROOT)/SOURCES/quake-$(VERSION).tar.gz
+
+ mv $(RPMROOT)/RPMS/$(ARCH)/quake-$(VERSION)-$(RPM_RELEASE).$(ARCH).rpm RPMS/.
+
+QUAKEDATADIR=$(TMPDIR)/quake-data-$(BASEVERSION)
+rpm-quake-data: quake-data.spec
+ # data rpm
+ touch $(RPMROOT)/SOURCES/quake-$(BASEVERSION)-data.tar.gz
+
+ -mkdirhier $(QUAKEDATADIR)/$(INSTALLDIR)/id1
+ cp $(MASTER_DIR)/id1/pak0.pak $(QUAKEDATADIR)/$(INSTALLDIR)/id1/.
+ cp $(MASTER_DIR)/id1/pak1.pak $(QUAKEDATADIR)/$(INSTALLDIR)/id1/.
+ cp $(MOUNT_DIR)/docs/README $(QUAKEDATADIR)/$(INSTALLDIR)/.
+ cp $(MOUNT_DIR)/data/comexp.txt $(QUAKEDATADIR)/$(INSTALLDIR)/.
+ cp $(MOUNT_DIR)/data/help.txt $(QUAKEDATADIR)/$(INSTALLDIR)/.
+ cp $(MOUNT_DIR)/data/licinfo.txt $(QUAKEDATADIR)/$(INSTALLDIR)/.
+ cp $(MOUNT_DIR)/data/manual.txt $(QUAKEDATADIR)/$(INSTALLDIR)/.
+ cp $(MOUNT_DIR)/data/readme.txt $(QUAKEDATADIR)/$(INSTALLDIR)/.
+ cp $(MOUNT_DIR)/data/rlicnse.txt $(QUAKEDATADIR)/$(INSTALLDIR)/.
+ cp $(MOUNT_DIR)/data/slicnse.txt $(QUAKEDATADIR)/$(INSTALLDIR)/.
+ cp $(MOUNT_DIR)/data/techinfo.txt $(QUAKEDATADIR)/$(INSTALLDIR)/.
+ cp quake-data.spec $(RPMROOT)/SPECS/.
+ cd $(RPMROOT)/SPECS; $(RPM) $(RPMFLAGS) quake-data.spec
+ rm -rf $(QUAKEDATADIR)
+ rm -f $(RPMROOT)/SOURCES/quake-$(BASEVERSION)-data.tar.gz
+
+ mv $(RPMROOT)/RPMS/$(NOARCH)/quake-data-$(BASEVERSION)-$(RPM_RELEASE).$(NOARCH).rpm RPMS/.
+
+RPMHIPNOTICDIR=$(TMPDIR)/quake-hipnotic-$(BASEVERSION)
+rpm-hipnotic: quake-hipnotic.spec
+ touch $(RPMROOT)/SOURCES/quake-hipnotic-$(BASEVERSION).tar.gz
+ if [ ! -d RPMS ];then mkdir RPMS;fi
+ cp $(MOUNT_DIR)/quake.gif $(RPMROOT)/SOURCES/quake.gif
+ -mkdirhier $(RPMHIPNOTICDIR)/$(INSTALLDIR)/hipnotic/docs
+ cp $(MASTER_DIR)/hipnotic/pak0.pak $(RPMHIPNOTICDIR)/$(INSTALLDIR)/hipnotic/.
+ cp $(MASTER_DIR)/hipnotic/config.cfg $(RPMHIPNOTICDIR)/$(INSTALLDIR)/hipnotic/.
+ cp $(MASTER_DIR)/hipnotic/docs/manual.doc $(RPMHIPNOTICDIR)/$(INSTALLDIR)/hipnotic/docs/.
+ cp $(MASTER_DIR)/hipnotic/docs/manual.htm $(RPMHIPNOTICDIR)/$(INSTALLDIR)/hipnotic/docs/.
+ cp $(MASTER_DIR)/hipnotic/docs/manual.txt $(RPMHIPNOTICDIR)/$(INSTALLDIR)/hipnotic/docs/.
+ cp $(MASTER_DIR)/hipnotic/docs/readme.doc $(RPMHIPNOTICDIR)/$(INSTALLDIR)/hipnotic/docs/.
+ cp $(MASTER_DIR)/hipnotic/docs/readme.htm $(RPMHIPNOTICDIR)/$(INSTALLDIR)/hipnotic/docs/.
+ cp $(MASTER_DIR)/hipnotic/docs/readme.txt $(RPMHIPNOTICDIR)/$(INSTALLDIR)/hipnotic/docs/.
+ cp quake-hipnotic.spec $(RPMROOT)/SPECS/.
+ cd $(RPMROOT)/SPECS; $(RPM) $(RPMFLAGS) quake-hipnotic.spec
+ rm -rf $(RPMHIPNOTICDIR)
+ rm -f $(RPMROOT)/SOURCES/quake-hipnotic-$(BASEVERSION).tar.gz
+
+ mv $(RPMROOT)/RPMS/$(NOARCH)/quake-hipnotic-$(BASEVERSION)-$(RPM_RELEASE).$(NOARCH).rpm RPMS/.
+
+RPMROGUEDIR=$(TMPDIR)/quake-rogue-$(BASEVERSION)
+rpm-rogue: quake-rogue.spec
+ touch $(RPMROOT)/SOURCES/quake-rogue-$(BASEVERSION).tar.gz
+ if [ ! -d RPMS ];then mkdir RPMS;fi
+ cp $(MOUNT_DIR)/quake.gif $(RPMROOT)/SOURCES/quake.gif
+ -mkdirhier $(RPMROGUEDIR)/$(INSTALLDIR)/rogue/docs
+ cp $(MASTER_DIR)/rogue/pak0.pak $(RPMROGUEDIR)/$(INSTALLDIR)/rogue/.
+ cp $(MASTER_DIR)/rogue/docs/manual.doc $(RPMROGUEDIR)/$(INSTALLDIR)/rogue/docs/.
+ cp $(MASTER_DIR)/rogue/docs/manual.htm $(RPMROGUEDIR)/$(INSTALLDIR)/rogue/docs/.
+ cp $(MASTER_DIR)/rogue/docs/manual.txt $(RPMROGUEDIR)/$(INSTALLDIR)/rogue/docs/.
+ cp $(MASTER_DIR)/rogue/docs/readme.doc $(RPMROGUEDIR)/$(INSTALLDIR)/rogue/docs/.
+ cp $(MASTER_DIR)/rogue/docs/readme.htm $(RPMROGUEDIR)/$(INSTALLDIR)/rogue/docs/.
+ cp $(MASTER_DIR)/rogue/docs/readme.txt $(RPMROGUEDIR)/$(INSTALLDIR)/rogue/docs/.
+ cp $(MASTER_DIR)/rogue/docs/ctf.doc $(RPMROGUEDIR)/$(INSTALLDIR)/rogue/docs/.
+ cp $(MASTER_DIR)/rogue/docs/ctf.htm $(RPMROGUEDIR)/$(INSTALLDIR)/rogue/docs/.
+ cp $(MASTER_DIR)/rogue/docs/ctf.txt $(RPMROGUEDIR)/$(INSTALLDIR)/rogue/docs/.
+ cp quake-rogue.spec $(RPMROOT)/SPECS/.
+ cd $(RPMROOT)/SPECS; $(RPM) $(RPMFLAGS) quake-rogue.spec
+ rm -rf $(RPMROGUEDIR)
+ rm -f $(RPMROOT)/SOURCES/quake-rogue-$(BASEVERSION).tar.gz
+
+ mv $(RPMROOT)/RPMS/$(NOARCH)/quake-rogue-$(BASEVERSION)-$(RPM_RELEASE).$(NOARCH).rpm RPMS/.
+
+quake.spec : $(MOUNT_DIR)/quake.spec.sh
+ sh $< $(VERSION) $(RPM_RELEASE) $(INSTALLDIR) > $@
+
+quake-data.spec : $(MOUNT_DIR)/quake-data.spec.sh
+ sh $< $(BASEVERSION) $(RPM_RELEASE) $(INSTALLDIR) > $@
+
+quake-hipnotic.spec : $(MOUNT_DIR)/quake-hipnotic.spec.sh
+ sh $< $(BASEVERSION) $(RPM_RELEASE) $(INSTALLDIR) > $@
+
+quake-rogue.spec : $(MOUNT_DIR)/quake-rogue.spec.sh
+ sh $< $(BASEVERSION) $(RPM_RELEASE) $(INSTALLDIR) > $@
+
+#############################################################################
+# MISC
+#############################################################################
+
+clean: clean-debug clean-release
+ rm -f squake.spec glquake.spec quake.x11.spec
+
+clean-debug:
+ $(MAKE) clean2 BUILDDIR=$(BUILD_DEBUG_DIR) CFLAGS="$(DEBUG_CFLAGS)"
+
+clean-release:
+ $(MAKE) clean2 BUILDDIR=$(BUILD_RELEASE_DIR) CFLAGS="$(DEBUG_CFLAGS)"
+
+clean2:
+ -rm -f $(SQUAKE_OBJS) $(X11_OBJS) $(GLQUAKE_OBJS) $(GLSVGA_OBJS) \
+ $(GLX_OBJS)
+
diff --git a/apps/plugins/sdl/progs/quake/adivtab.h b/apps/plugins/sdl/progs/quake/adivtab.h
new file mode 100644
index 0000000000..238df5c052
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/adivtab.h
@@ -0,0 +1,1077 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// table of quotients and remainders for [-15...16] / [-15...16]
+
+// numerator = -15
+{1, 0},
+{1, -1},
+{1, -2},
+{1, -3},
+{1, -4},
+{1, -5},
+{1, -6},
+{1, -7},
+{2, -1},
+{2, -3},
+{3, 0},
+{3, -3},
+{5, 0},
+{7, -1},
+{15, 0},
+{0, 0},
+{-15, 0},
+{-8, 1},
+{-5, 0},
+{-4, 1},
+{-3, 0},
+{-3, 3},
+{-3, 6},
+{-2, 1},
+{-2, 3},
+{-2, 5},
+{-2, 7},
+{-2, 9},
+{-2, 11},
+{-2, 13},
+{-1, 0},
+{-1, 1},
+// numerator = -14
+{0, -14},
+{1, 0},
+{1, -1},
+{1, -2},
+{1, -3},
+{1, -4},
+{1, -5},
+{1, -6},
+{2, 0},
+{2, -2},
+{2, -4},
+{3, -2},
+{4, -2},
+{7, 0},
+{14, 0},
+{0, 0},
+{-14, 0},
+{-7, 0},
+{-5, 1},
+{-4, 2},
+{-3, 1},
+{-3, 4},
+{-2, 0},
+{-2, 2},
+{-2, 4},
+{-2, 6},
+{-2, 8},
+{-2, 10},
+{-2, 12},
+{-1, 0},
+{-1, 1},
+{-1, 2},
+// numerator = -13
+{0, -13},
+{0, -13},
+{1, 0},
+{1, -1},
+{1, -2},
+{1, -3},
+{1, -4},
+{1, -5},
+{1, -6},
+{2, -1},
+{2, -3},
+{3, -1},
+{4, -1},
+{6, -1},
+{13, 0},
+{0, 0},
+{-13, 0},
+{-7, 1},
+{-5, 2},
+{-4, 3},
+{-3, 2},
+{-3, 5},
+{-2, 1},
+{-2, 3},
+{-2, 5},
+{-2, 7},
+{-2, 9},
+{-2, 11},
+{-1, 0},
+{-1, 1},
+{-1, 2},
+{-1, 3},
+// numerator = -12
+{0, -12},
+{0, -12},
+{0, -12},
+{1, 0},
+{1, -1},
+{1, -2},
+{1, -3},
+{1, -4},
+{1, -5},
+{2, 0},
+{2, -2},
+{3, 0},
+{4, 0},
+{6, 0},
+{12, 0},
+{0, 0},
+{-12, 0},
+{-6, 0},
+{-4, 0},
+{-3, 0},
+{-3, 3},
+{-2, 0},
+{-2, 2},
+{-2, 4},
+{-2, 6},
+{-2, 8},
+{-2, 10},
+{-1, 0},
+{-1, 1},
+{-1, 2},
+{-1, 3},
+{-1, 4},
+// numerator = -11
+{0, -11},
+{0, -11},
+{0, -11},
+{0, -11},
+{1, 0},
+{1, -1},
+{1, -2},
+{1, -3},
+{1, -4},
+{1, -5},
+{2, -1},
+{2, -3},
+{3, -2},
+{5, -1},
+{11, 0},
+{0, 0},
+{-11, 0},
+{-6, 1},
+{-4, 1},
+{-3, 1},
+{-3, 4},
+{-2, 1},
+{-2, 3},
+{-2, 5},
+{-2, 7},
+{-2, 9},
+{-1, 0},
+{-1, 1},
+{-1, 2},
+{-1, 3},
+{-1, 4},
+{-1, 5},
+// numerator = -10
+{0, -10},
+{0, -10},
+{0, -10},
+{0, -10},
+{0, -10},
+{1, 0},
+{1, -1},
+{1, -2},
+{1, -3},
+{1, -4},
+{2, 0},
+{2, -2},
+{3, -1},
+{5, 0},
+{10, 0},
+{0, 0},
+{-10, 0},
+{-5, 0},
+{-4, 2},
+{-3, 2},
+{-2, 0},
+{-2, 2},
+{-2, 4},
+{-2, 6},
+{-2, 8},
+{-1, 0},
+{-1, 1},
+{-1, 2},
+{-1, 3},
+{-1, 4},
+{-1, 5},
+{-1, 6},
+// numerator = -9
+{0, -9},
+{0, -9},
+{0, -9},
+{0, -9},
+{0, -9},
+{0, -9},
+{1, 0},
+{1, -1},
+{1, -2},
+{1, -3},
+{1, -4},
+{2, -1},
+{3, 0},
+{4, -1},
+{9, 0},
+{0, 0},
+{-9, 0},
+{-5, 1},
+{-3, 0},
+{-3, 3},
+{-2, 1},
+{-2, 3},
+{-2, 5},
+{-2, 7},
+{-1, 0},
+{-1, 1},
+{-1, 2},
+{-1, 3},
+{-1, 4},
+{-1, 5},
+{-1, 6},
+{-1, 7},
+// numerator = -8
+{0, -8},
+{0, -8},
+{0, -8},
+{0, -8},
+{0, -8},
+{0, -8},
+{0, -8},
+{1, 0},
+{1, -1},
+{1, -2},
+{1, -3},
+{2, 0},
+{2, -2},
+{4, 0},
+{8, 0},
+{0, 0},
+{-8, 0},
+{-4, 0},
+{-3, 1},
+{-2, 0},
+{-2, 2},
+{-2, 4},
+{-2, 6},
+{-1, 0},
+{-1, 1},
+{-1, 2},
+{-1, 3},
+{-1, 4},
+{-1, 5},
+{-1, 6},
+{-1, 7},
+{-1, 8},
+// numerator = -7
+{0, -7},
+{0, -7},
+{0, -7},
+{0, -7},
+{0, -7},
+{0, -7},
+{0, -7},
+{0, -7},
+{1, 0},
+{1, -1},
+{1, -2},
+{1, -3},
+{2, -1},
+{3, -1},
+{7, 0},
+{0, 0},
+{-7, 0},
+{-4, 1},
+{-3, 2},
+{-2, 1},
+{-2, 3},
+{-2, 5},
+{-1, 0},
+{-1, 1},
+{-1, 2},
+{-1, 3},
+{-1, 4},
+{-1, 5},
+{-1, 6},
+{-1, 7},
+{-1, 8},
+{-1, 9},
+// numerator = -6
+{0, -6},
+{0, -6},
+{0, -6},
+{0, -6},
+{0, -6},
+{0, -6},
+{0, -6},
+{0, -6},
+{0, -6},
+{1, 0},
+{1, -1},
+{1, -2},
+{2, 0},
+{3, 0},
+{6, 0},
+{0, 0},
+{-6, 0},
+{-3, 0},
+{-2, 0},
+{-2, 2},
+{-2, 4},
+{-1, 0},
+{-1, 1},
+{-1, 2},
+{-1, 3},
+{-1, 4},
+{-1, 5},
+{-1, 6},
+{-1, 7},
+{-1, 8},
+{-1, 9},
+{-1, 10},
+// numerator = -5
+{0, -5},
+{0, -5},
+{0, -5},
+{0, -5},
+{0, -5},
+{0, -5},
+{0, -5},
+{0, -5},
+{0, -5},
+{0, -5},
+{1, 0},
+{1, -1},
+{1, -2},
+{2, -1},
+{5, 0},
+{0, 0},
+{-5, 0},
+{-3, 1},
+{-2, 1},
+{-2, 3},
+{-1, 0},
+{-1, 1},
+{-1, 2},
+{-1, 3},
+{-1, 4},
+{-1, 5},
+{-1, 6},
+{-1, 7},
+{-1, 8},
+{-1, 9},
+{-1, 10},
+{-1, 11},
+// numerator = -4
+{0, -4},
+{0, -4},
+{0, -4},
+{0, -4},
+{0, -4},
+{0, -4},
+{0, -4},
+{0, -4},
+{0, -4},
+{0, -4},
+{0, -4},
+{1, 0},
+{1, -1},
+{2, 0},
+{4, 0},
+{0, 0},
+{-4, 0},
+{-2, 0},
+{-2, 2},
+{-1, 0},
+{-1, 1},
+{-1, 2},
+{-1, 3},
+{-1, 4},
+{-1, 5},
+{-1, 6},
+{-1, 7},
+{-1, 8},
+{-1, 9},
+{-1, 10},
+{-1, 11},
+{-1, 12},
+// numerator = -3
+{0, -3},
+{0, -3},
+{0, -3},
+{0, -3},
+{0, -3},
+{0, -3},
+{0, -3},
+{0, -3},
+{0, -3},
+{0, -3},
+{0, -3},
+{0, -3},
+{1, 0},
+{1, -1},
+{3, 0},
+{0, 0},
+{-3, 0},
+{-2, 1},
+{-1, 0},
+{-1, 1},
+{-1, 2},
+{-1, 3},
+{-1, 4},
+{-1, 5},
+{-1, 6},
+{-1, 7},
+{-1, 8},
+{-1, 9},
+{-1, 10},
+{-1, 11},
+{-1, 12},
+{-1, 13},
+// numerator = -2
+{0, -2},
+{0, -2},
+{0, -2},
+{0, -2},
+{0, -2},
+{0, -2},
+{0, -2},
+{0, -2},
+{0, -2},
+{0, -2},
+{0, -2},
+{0, -2},
+{0, -2},
+{1, 0},
+{2, 0},
+{0, 0},
+{-2, 0},
+{-1, 0},
+{-1, 1},
+{-1, 2},
+{-1, 3},
+{-1, 4},
+{-1, 5},
+{-1, 6},
+{-1, 7},
+{-1, 8},
+{-1, 9},
+{-1, 10},
+{-1, 11},
+{-1, 12},
+{-1, 13},
+{-1, 14},
+// numerator = -1
+{0, -1},
+{0, -1},
+{0, -1},
+{0, -1},
+{0, -1},
+{0, -1},
+{0, -1},
+{0, -1},
+{0, -1},
+{0, -1},
+{0, -1},
+{0, -1},
+{0, -1},
+{0, -1},
+{1, 0},
+{0, 0},
+{-1, 0},
+{-1, 1},
+{-1, 2},
+{-1, 3},
+{-1, 4},
+{-1, 5},
+{-1, 6},
+{-1, 7},
+{-1, 8},
+{-1, 9},
+{-1, 10},
+{-1, 11},
+{-1, 12},
+{-1, 13},
+{-1, 14},
+{-1, 15},
+// numerator = 0
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+{0, 0},
+// numerator = 1
+{-1, -14},
+{-1, -13},
+{-1, -12},
+{-1, -11},
+{-1, -10},
+{-1, -9},
+{-1, -8},
+{-1, -7},
+{-1, -6},
+{-1, -5},
+{-1, -4},
+{-1, -3},
+{-1, -2},
+{-1, -1},
+{-1, 0},
+{0, 0},
+{1, 0},
+{0, 1},
+{0, 1},
+{0, 1},
+{0, 1},
+{0, 1},
+{0, 1},
+{0, 1},
+{0, 1},
+{0, 1},
+{0, 1},
+{0, 1},
+{0, 1},
+{0, 1},
+{0, 1},
+{0, 1},
+// numerator = 2
+{-1, -13},
+{-1, -12},
+{-1, -11},
+{-1, -10},
+{-1, -9},
+{-1, -8},
+{-1, -7},
+{-1, -6},
+{-1, -5},
+{-1, -4},
+{-1, -3},
+{-1, -2},
+{-1, -1},
+{-1, 0},
+{-2, 0},
+{0, 0},
+{2, 0},
+{1, 0},
+{0, 2},
+{0, 2},
+{0, 2},
+{0, 2},
+{0, 2},
+{0, 2},
+{0, 2},
+{0, 2},
+{0, 2},
+{0, 2},
+{0, 2},
+{0, 2},
+{0, 2},
+{0, 2},
+// numerator = 3
+{-1, -12},
+{-1, -11},
+{-1, -10},
+{-1, -9},
+{-1, -8},
+{-1, -7},
+{-1, -6},
+{-1, -5},
+{-1, -4},
+{-1, -3},
+{-1, -2},
+{-1, -1},
+{-1, 0},
+{-2, -1},
+{-3, 0},
+{0, 0},
+{3, 0},
+{1, 1},
+{1, 0},
+{0, 3},
+{0, 3},
+{0, 3},
+{0, 3},
+{0, 3},
+{0, 3},
+{0, 3},
+{0, 3},
+{0, 3},
+{0, 3},
+{0, 3},
+{0, 3},
+{0, 3},
+// numerator = 4
+{-1, -11},
+{-1, -10},
+{-1, -9},
+{-1, -8},
+{-1, -7},
+{-1, -6},
+{-1, -5},
+{-1, -4},
+{-1, -3},
+{-1, -2},
+{-1, -1},
+{-1, 0},
+{-2, -2},
+{-2, 0},
+{-4, 0},
+{0, 0},
+{4, 0},
+{2, 0},
+{1, 1},
+{1, 0},
+{0, 4},
+{0, 4},
+{0, 4},
+{0, 4},
+{0, 4},
+{0, 4},
+{0, 4},
+{0, 4},
+{0, 4},
+{0, 4},
+{0, 4},
+{0, 4},
+// numerator = 5
+{-1, -10},
+{-1, -9},
+{-1, -8},
+{-1, -7},
+{-1, -6},
+{-1, -5},
+{-1, -4},
+{-1, -3},
+{-1, -2},
+{-1, -1},
+{-1, 0},
+{-2, -3},
+{-2, -1},
+{-3, -1},
+{-5, 0},
+{0, 0},
+{5, 0},
+{2, 1},
+{1, 2},
+{1, 1},
+{1, 0},
+{0, 5},
+{0, 5},
+{0, 5},
+{0, 5},
+{0, 5},
+{0, 5},
+{0, 5},
+{0, 5},
+{0, 5},
+{0, 5},
+{0, 5},
+// numerator = 6
+{-1, -9},
+{-1, -8},
+{-1, -7},
+{-1, -6},
+{-1, -5},
+{-1, -4},
+{-1, -3},
+{-1, -2},
+{-1, -1},
+{-1, 0},
+{-2, -4},
+{-2, -2},
+{-2, 0},
+{-3, 0},
+{-6, 0},
+{0, 0},
+{6, 0},
+{3, 0},
+{2, 0},
+{1, 2},
+{1, 1},
+{1, 0},
+{0, 6},
+{0, 6},
+{0, 6},
+{0, 6},
+{0, 6},
+{0, 6},
+{0, 6},
+{0, 6},
+{0, 6},
+{0, 6},
+// numerator = 7
+{-1, -8},
+{-1, -7},
+{-1, -6},
+{-1, -5},
+{-1, -4},
+{-1, -3},
+{-1, -2},
+{-1, -1},
+{-1, 0},
+{-2, -5},
+{-2, -3},
+{-2, -1},
+{-3, -2},
+{-4, -1},
+{-7, 0},
+{0, 0},
+{7, 0},
+{3, 1},
+{2, 1},
+{1, 3},
+{1, 2},
+{1, 1},
+{1, 0},
+{0, 7},
+{0, 7},
+{0, 7},
+{0, 7},
+{0, 7},
+{0, 7},
+{0, 7},
+{0, 7},
+{0, 7},
+// numerator = 8
+{-1, -7},
+{-1, -6},
+{-1, -5},
+{-1, -4},
+{-1, -3},
+{-1, -2},
+{-1, -1},
+{-1, 0},
+{-2, -6},
+{-2, -4},
+{-2, -2},
+{-2, 0},
+{-3, -1},
+{-4, 0},
+{-8, 0},
+{0, 0},
+{8, 0},
+{4, 0},
+{2, 2},
+{2, 0},
+{1, 3},
+{1, 2},
+{1, 1},
+{1, 0},
+{0, 8},
+{0, 8},
+{0, 8},
+{0, 8},
+{0, 8},
+{0, 8},
+{0, 8},
+{0, 8},
+// numerator = 9
+{-1, -6},
+{-1, -5},
+{-1, -4},
+{-1, -3},
+{-1, -2},
+{-1, -1},
+{-1, 0},
+{-2, -7},
+{-2, -5},
+{-2, -3},
+{-2, -1},
+{-3, -3},
+{-3, 0},
+{-5, -1},
+{-9, 0},
+{0, 0},
+{9, 0},
+{4, 1},
+{3, 0},
+{2, 1},
+{1, 4},
+{1, 3},
+{1, 2},
+{1, 1},
+{1, 0},
+{0, 9},
+{0, 9},
+{0, 9},
+{0, 9},
+{0, 9},
+{0, 9},
+{0, 9},
+// numerator = 10
+{-1, -5},
+{-1, -4},
+{-1, -3},
+{-1, -2},
+{-1, -1},
+{-1, 0},
+{-2, -8},
+{-2, -6},
+{-2, -4},
+{-2, -2},
+{-2, 0},
+{-3, -2},
+{-4, -2},
+{-5, 0},
+{-10, 0},
+{0, 0},
+{10, 0},
+{5, 0},
+{3, 1},
+{2, 2},
+{2, 0},
+{1, 4},
+{1, 3},
+{1, 2},
+{1, 1},
+{1, 0},
+{0, 10},
+{0, 10},
+{0, 10},
+{0, 10},
+{0, 10},
+{0, 10},
+// numerator = 11
+{-1, -4},
+{-1, -3},
+{-1, -2},
+{-1, -1},
+{-1, 0},
+{-2, -9},
+{-2, -7},
+{-2, -5},
+{-2, -3},
+{-2, -1},
+{-3, -4},
+{-3, -1},
+{-4, -1},
+{-6, -1},
+{-11, 0},
+{0, 0},
+{11, 0},
+{5, 1},
+{3, 2},
+{2, 3},
+{2, 1},
+{1, 5},
+{1, 4},
+{1, 3},
+{1, 2},
+{1, 1},
+{1, 0},
+{0, 11},
+{0, 11},
+{0, 11},
+{0, 11},
+{0, 11},
+// numerator = 12
+{-1, -3},
+{-1, -2},
+{-1, -1},
+{-1, 0},
+{-2, -10},
+{-2, -8},
+{-2, -6},
+{-2, -4},
+{-2, -2},
+{-2, 0},
+{-3, -3},
+{-3, 0},
+{-4, 0},
+{-6, 0},
+{-12, 0},
+{0, 0},
+{12, 0},
+{6, 0},
+{4, 0},
+{3, 0},
+{2, 2},
+{2, 0},
+{1, 5},
+{1, 4},
+{1, 3},
+{1, 2},
+{1, 1},
+{1, 0},
+{0, 12},
+{0, 12},
+{0, 12},
+{0, 12},
+// numerator = 13
+{-1, -2},
+{-1, -1},
+{-1, 0},
+{-2, -11},
+{-2, -9},
+{-2, -7},
+{-2, -5},
+{-2, -3},
+{-2, -1},
+{-3, -5},
+{-3, -2},
+{-4, -3},
+{-5, -2},
+{-7, -1},
+{-13, 0},
+{0, 0},
+{13, 0},
+{6, 1},
+{4, 1},
+{3, 1},
+{2, 3},
+{2, 1},
+{1, 6},
+{1, 5},
+{1, 4},
+{1, 3},
+{1, 2},
+{1, 1},
+{1, 0},
+{0, 13},
+{0, 13},
+{0, 13},
+// numerator = 14
+{-1, -1},
+{-1, 0},
+{-2, -12},
+{-2, -10},
+{-2, -8},
+{-2, -6},
+{-2, -4},
+{-2, -2},
+{-2, 0},
+{-3, -4},
+{-3, -1},
+{-4, -2},
+{-5, -1},
+{-7, 0},
+{-14, 0},
+{0, 0},
+{14, 0},
+{7, 0},
+{4, 2},
+{3, 2},
+{2, 4},
+{2, 2},
+{2, 0},
+{1, 6},
+{1, 5},
+{1, 4},
+{1, 3},
+{1, 2},
+{1, 1},
+{1, 0},
+{0, 14},
+{0, 14},
+// numerator = 15
+{-1, 0},
+{-2, -13},
+{-2, -11},
+{-2, -9},
+{-2, -7},
+{-2, -5},
+{-2, -3},
+{-2, -1},
+{-3, -6},
+{-3, -3},
+{-3, 0},
+{-4, -1},
+{-5, 0},
+{-8, -1},
+{-15, 0},
+{0, 0},
+{15, 0},
+{7, 1},
+{5, 0},
+{3, 3},
+{3, 0},
+{2, 3},
+{2, 1},
+{1, 7},
+{1, 6},
+{1, 5},
+{1, 4},
+{1, 3},
+{1, 2},
+{1, 1},
+{1, 0},
+{0, 15},
+// numerator = 16
+{-2, -14},
+{-2, -12},
+{-2, -10},
+{-2, -8},
+{-2, -6},
+{-2, -4},
+{-2, -2},
+{-2, 0},
+{-3, -5},
+{-3, -2},
+{-4, -4},
+{-4, 0},
+{-6, -2},
+{-8, 0},
+{-16, 0},
+{0, 0},
+{16, 0},
+{8, 0},
+{5, 1},
+{4, 0},
+{3, 1},
+{2, 4},
+{2, 2},
+{2, 0},
+{1, 7},
+{1, 6},
+{1, 5},
+{1, 4},
+{1, 3},
+{1, 2},
+{1, 1},
+{1, 0},
diff --git a/apps/plugins/sdl/progs/quake/anorm_dots.h b/apps/plugins/sdl/progs/quake/anorm_dots.h
new file mode 100644
index 0000000000..2845fa20ee
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/anorm_dots.h
@@ -0,0 +1,37 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+{
+{1.23,1.30,1.47,1.35,1.56,1.71,1.37,1.38,1.59,1.60,1.79,1.97,1.88,1.92,1.79,1.02,0.93,1.07,0.82,0.87,0.88,0.94,0.96,1.14,1.11,0.82,0.83,0.89,0.89,0.86,0.94,0.91,1.00,1.21,0.98,1.48,1.30,1.57,0.96,1.07,1.14,1.60,1.61,1.40,1.37,1.72,1.78,1.79,1.93,1.99,1.90,1.68,1.71,1.86,1.60,1.68,1.78,1.86,1.93,1.99,1.97,1.44,1.22,1.49,0.93,0.99,0.99,1.23,1.22,1.44,1.49,0.89,0.89,0.97,0.91,0.98,1.19,0.82,0.76,0.82,0.71,0.72,0.73,0.76,0.79,0.86,0.83,0.72,0.76,0.76,0.89,0.82,0.89,0.82,0.89,0.91,0.83,0.96,1.14,0.97,1.40,1.19,0.98,0.94,1.00,1.07,1.37,1.21,1.48,1.30,1.57,1.61,1.37,0.86,0.83,0.91,0.82,0.82,0.88,0.89,0.96,1.14,0.98,0.87,0.93,0.94,1.02,1.30,1.07,1.35,1.38,1.11,1.56,1.92,1.79,1.79,1.59,1.60,1.72,1.90,1.79,0.80,0.85,0.79,0.93,0.80,0.85,0.77,0.74,0.72,0.77,0.74,0.72,0.70,0.70,0.71,0.76,0.73,0.79,0.79,0.73,0.76,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00},
+{1.26,1.26,1.48,1.23,1.50,1.71,1.14,1.19,1.38,1.46,1.64,1.94,1.87,1.84,1.71,1.02,0.92,1.00,0.79,0.85,0.84,0.91,0.90,0.98,0.99,0.77,0.77,0.83,0.82,0.79,0.86,0.84,0.92,0.99,0.91,1.24,1.03,1.33,0.88,0.94,0.97,1.41,1.39,1.18,1.11,1.51,1.61,1.59,1.80,1.91,1.76,1.54,1.65,1.76,1.70,1.70,1.85,1.85,1.97,1.99,1.93,1.28,1.09,1.39,0.92,0.97,0.99,1.18,1.26,1.52,1.48,0.83,0.85,0.90,0.88,0.93,1.00,0.77,0.73,0.78,0.72,0.71,0.74,0.75,0.79,0.86,0.81,0.75,0.81,0.79,0.96,0.88,0.94,0.86,0.93,0.92,0.85,1.08,1.33,1.05,1.55,1.31,1.01,1.05,1.27,1.31,1.60,1.47,1.70,1.54,1.76,1.76,1.57,0.93,0.90,0.99,0.88,0.88,0.95,0.97,1.11,1.39,1.20,0.92,0.97,1.01,1.10,1.39,1.22,1.51,1.58,1.32,1.64,1.97,1.85,1.91,1.77,1.74,1.88,1.99,1.91,0.79,0.86,0.80,0.94,0.84,0.88,0.74,0.74,0.71,0.82,0.77,0.76,0.70,0.73,0.72,0.73,0.70,0.74,0.85,0.77,0.82,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00},
+{1.34,1.27,1.53,1.17,1.46,1.71,0.98,1.05,1.20,1.34,1.48,1.86,1.82,1.71,1.62,1.09,0.94,0.99,0.79,0.85,0.82,0.90,0.87,0.93,0.96,0.76,0.74,0.79,0.76,0.74,0.79,0.78,0.85,0.92,0.85,1.00,0.93,1.06,0.81,0.86,0.89,1.16,1.12,0.97,0.95,1.28,1.38,1.35,1.60,1.77,1.57,1.33,1.50,1.58,1.69,1.63,1.82,1.74,1.91,1.92,1.80,1.04,0.97,1.21,0.90,0.93,0.97,1.05,1.21,1.48,1.37,0.77,0.80,0.84,0.85,0.88,0.92,0.73,0.71,0.74,0.74,0.71,0.75,0.73,0.79,0.84,0.78,0.79,0.86,0.81,1.05,0.94,0.99,0.90,0.95,0.92,0.86,1.24,1.44,1.14,1.59,1.34,1.02,1.27,1.50,1.49,1.80,1.69,1.86,1.72,1.87,1.80,1.69,1.00,0.98,1.23,0.95,0.96,1.09,1.16,1.37,1.63,1.46,0.99,1.10,1.25,1.24,1.51,1.41,1.67,1.77,1.55,1.72,1.95,1.89,1.98,1.91,1.86,1.97,1.99,1.94,0.81,0.89,0.85,0.98,0.90,0.94,0.75,0.78,0.73,0.89,0.83,0.82,0.72,0.77,0.76,0.72,0.70,0.71,0.91,0.83,0.89,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00},
+{1.46,1.34,1.60,1.16,1.46,1.71,0.94,0.99,1.05,1.26,1.33,1.74,1.76,1.57,1.54,1.23,0.98,1.05,0.83,0.89,0.84,0.92,0.87,0.91,0.96,0.78,0.74,0.79,0.72,0.72,0.75,0.76,0.80,0.88,0.83,0.94,0.87,0.95,0.76,0.80,0.82,0.97,0.96,0.89,0.88,1.08,1.11,1.10,1.37,1.59,1.37,1.07,1.27,1.34,1.57,1.45,1.69,1.55,1.77,1.79,1.60,0.93,0.90,0.99,0.86,0.87,0.93,0.96,1.07,1.35,1.18,0.73,0.76,0.77,0.81,0.82,0.85,0.70,0.71,0.72,0.78,0.73,0.77,0.73,0.79,0.82,0.76,0.83,0.90,0.84,1.18,0.98,1.03,0.92,0.95,0.90,0.86,1.32,1.45,1.15,1.53,1.27,0.99,1.42,1.65,1.58,1.93,1.83,1.94,1.81,1.88,1.74,1.70,1.19,1.17,1.44,1.11,1.15,1.36,1.41,1.61,1.81,1.67,1.22,1.34,1.50,1.42,1.65,1.61,1.82,1.91,1.75,1.80,1.89,1.89,1.98,1.99,1.94,1.98,1.92,1.87,0.86,0.95,0.92,1.14,0.98,1.03,0.79,0.84,0.77,0.97,0.90,0.89,0.76,0.82,0.82,0.74,0.72,0.71,0.98,0.89,0.97,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00},
+{1.60,1.44,1.68,1.22,1.49,1.71,0.93,0.99,0.99,1.23,1.22,1.60,1.68,1.44,1.49,1.40,1.14,1.19,0.89,0.96,0.89,0.97,0.89,0.91,0.98,0.82,0.76,0.82,0.71,0.72,0.73,0.76,0.79,0.86,0.83,0.91,0.83,0.89,0.72,0.76,0.76,0.89,0.89,0.82,0.82,0.98,0.96,0.97,1.14,1.40,1.19,0.94,1.00,1.07,1.37,1.21,1.48,1.30,1.57,1.61,1.37,0.86,0.83,0.91,0.82,0.82,0.88,0.89,0.96,1.14,0.98,0.70,0.72,0.73,0.77,0.76,0.79,0.70,0.72,0.71,0.82,0.77,0.80,0.74,0.79,0.80,0.74,0.87,0.93,0.85,1.23,1.02,1.02,0.93,0.93,0.87,0.85,1.30,1.35,1.07,1.38,1.11,0.94,1.47,1.71,1.56,1.97,1.88,1.92,1.79,1.79,1.59,1.60,1.30,1.35,1.56,1.37,1.38,1.59,1.60,1.79,1.92,1.79,1.48,1.57,1.72,1.61,1.78,1.79,1.93,1.99,1.90,1.86,1.78,1.86,1.93,1.99,1.97,1.90,1.79,1.72,0.94,1.07,1.00,1.37,1.21,1.30,0.86,0.91,0.83,1.14,0.98,0.96,0.82,0.88,0.89,0.79,0.76,0.73,1.07,0.94,1.11,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00},
+{1.74,1.57,1.76,1.33,1.54,1.71,0.94,1.05,0.99,1.26,1.16,1.46,1.60,1.34,1.46,1.59,1.37,1.37,0.97,1.11,0.96,1.10,0.95,0.94,1.08,0.89,0.82,0.88,0.72,0.76,0.75,0.80,0.80,0.88,0.87,0.91,0.83,0.87,0.72,0.76,0.74,0.83,0.84,0.78,0.79,0.96,0.89,0.92,0.98,1.23,1.05,0.86,0.92,0.95,1.11,0.98,1.22,1.03,1.34,1.42,1.14,0.79,0.77,0.84,0.78,0.76,0.82,0.82,0.89,0.97,0.90,0.70,0.71,0.71,0.73,0.72,0.74,0.73,0.76,0.72,0.86,0.81,0.82,0.76,0.79,0.77,0.73,0.90,0.95,0.86,1.18,1.03,0.98,0.92,0.90,0.83,0.84,1.19,1.17,0.98,1.15,0.97,0.89,1.42,1.65,1.44,1.93,1.83,1.81,1.67,1.61,1.36,1.41,1.32,1.45,1.58,1.57,1.53,1.74,1.70,1.88,1.94,1.81,1.69,1.77,1.87,1.79,1.89,1.92,1.98,1.99,1.98,1.89,1.65,1.80,1.82,1.91,1.94,1.75,1.61,1.50,1.07,1.34,1.27,1.60,1.45,1.55,0.93,0.99,0.90,1.35,1.18,1.07,0.87,0.93,0.96,0.85,0.82,0.77,1.15,0.99,1.27,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00},
+{1.86,1.71,1.82,1.48,1.62,1.71,0.98,1.20,1.05,1.34,1.17,1.34,1.53,1.27,1.46,1.77,1.60,1.57,1.16,1.38,1.12,1.35,1.06,1.00,1.28,0.97,0.89,0.95,0.76,0.81,0.79,0.86,0.85,0.92,0.93,0.93,0.85,0.87,0.74,0.78,0.74,0.79,0.82,0.76,0.79,0.96,0.85,0.90,0.94,1.09,0.99,0.81,0.85,0.89,0.95,0.90,0.99,0.94,1.10,1.24,0.98,0.75,0.73,0.78,0.74,0.72,0.77,0.76,0.82,0.89,0.83,0.73,0.71,0.71,0.71,0.70,0.72,0.77,0.80,0.74,0.90,0.85,0.84,0.78,0.79,0.75,0.73,0.92,0.95,0.86,1.05,0.99,0.94,0.90,0.86,0.79,0.81,1.00,0.98,0.91,0.96,0.89,0.83,1.27,1.50,1.23,1.80,1.69,1.63,1.46,1.37,1.09,1.16,1.24,1.44,1.49,1.69,1.59,1.80,1.69,1.87,1.86,1.72,1.82,1.91,1.94,1.92,1.95,1.99,1.98,1.91,1.97,1.89,1.51,1.72,1.67,1.77,1.86,1.55,1.41,1.25,1.33,1.58,1.50,1.80,1.63,1.74,1.04,1.21,0.97,1.48,1.37,1.21,0.93,0.97,1.05,0.92,0.88,0.84,1.14,1.02,1.34,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00},
+{1.94,1.84,1.87,1.64,1.71,1.71,1.14,1.38,1.19,1.46,1.23,1.26,1.48,1.26,1.50,1.91,1.80,1.76,1.41,1.61,1.39,1.59,1.33,1.24,1.51,1.18,0.97,1.11,0.82,0.88,0.86,0.94,0.92,0.99,1.03,0.98,0.91,0.90,0.79,0.84,0.77,0.79,0.84,0.77,0.83,0.99,0.85,0.91,0.92,1.02,1.00,0.79,0.80,0.86,0.88,0.84,0.92,0.88,0.97,1.10,0.94,0.74,0.71,0.74,0.72,0.70,0.73,0.72,0.76,0.82,0.77,0.77,0.73,0.74,0.71,0.70,0.73,0.83,0.85,0.78,0.92,0.88,0.86,0.81,0.79,0.74,0.75,0.92,0.93,0.85,0.96,0.94,0.88,0.86,0.81,0.75,0.79,0.93,0.90,0.85,0.88,0.82,0.77,1.05,1.27,0.99,1.60,1.47,1.39,1.20,1.11,0.95,0.97,1.08,1.33,1.31,1.70,1.55,1.76,1.57,1.76,1.70,1.54,1.85,1.97,1.91,1.99,1.97,1.99,1.91,1.77,1.88,1.85,1.39,1.64,1.51,1.58,1.74,1.32,1.22,1.01,1.54,1.76,1.65,1.93,1.70,1.85,1.28,1.39,1.09,1.52,1.48,1.26,0.97,0.99,1.18,1.00,0.93,0.90,1.05,1.01,1.31,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00},
+{1.97,1.92,1.88,1.79,1.79,1.71,1.37,1.59,1.38,1.60,1.35,1.23,1.47,1.30,1.56,1.99,1.93,1.90,1.60,1.78,1.61,1.79,1.57,1.48,1.72,1.40,1.14,1.37,0.89,0.96,0.94,1.07,1.00,1.21,1.30,1.14,0.98,0.96,0.86,0.91,0.83,0.82,0.88,0.82,0.89,1.11,0.87,0.94,0.93,1.02,1.07,0.80,0.79,0.85,0.82,0.80,0.87,0.85,0.93,1.02,0.93,0.77,0.72,0.74,0.71,0.70,0.70,0.71,0.72,0.77,0.74,0.82,0.76,0.79,0.72,0.73,0.76,0.89,0.89,0.82,0.93,0.91,0.86,0.83,0.79,0.73,0.76,0.91,0.89,0.83,0.89,0.89,0.82,0.82,0.76,0.72,0.76,0.86,0.83,0.79,0.82,0.76,0.73,0.94,1.00,0.91,1.37,1.21,1.14,0.98,0.96,0.88,0.89,0.96,1.14,1.07,1.60,1.40,1.61,1.37,1.57,1.48,1.30,1.78,1.93,1.79,1.99,1.92,1.90,1.79,1.59,1.72,1.79,1.30,1.56,1.35,1.38,1.60,1.11,1.07,0.94,1.68,1.86,1.71,1.97,1.68,1.86,1.44,1.49,1.22,1.44,1.49,1.22,0.99,0.99,1.23,1.19,0.98,0.97,0.97,0.98,1.19,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00},
+{1.94,1.97,1.87,1.91,1.85,1.71,1.60,1.77,1.58,1.74,1.51,1.26,1.48,1.39,1.64,1.99,1.97,1.99,1.70,1.85,1.76,1.91,1.76,1.70,1.88,1.55,1.33,1.57,0.96,1.08,1.05,1.31,1.27,1.47,1.54,1.39,1.20,1.11,0.93,0.99,0.90,0.88,0.95,0.88,0.97,1.32,0.92,1.01,0.97,1.10,1.22,0.84,0.80,0.88,0.79,0.79,0.85,0.86,0.92,1.02,0.94,0.82,0.76,0.77,0.72,0.73,0.70,0.72,0.71,0.74,0.74,0.88,0.81,0.85,0.75,0.77,0.82,0.94,0.93,0.86,0.92,0.92,0.86,0.85,0.79,0.74,0.79,0.88,0.85,0.81,0.82,0.83,0.77,0.78,0.73,0.71,0.75,0.79,0.77,0.74,0.77,0.73,0.70,0.86,0.92,0.84,1.14,0.99,0.98,0.91,0.90,0.84,0.83,0.88,0.97,0.94,1.41,1.18,1.39,1.11,1.33,1.24,1.03,1.61,1.80,1.59,1.91,1.84,1.76,1.64,1.38,1.51,1.71,1.26,1.50,1.23,1.19,1.46,0.99,1.00,0.91,1.70,1.85,1.65,1.93,1.54,1.76,1.52,1.48,1.26,1.28,1.39,1.09,0.99,0.97,1.18,1.31,1.01,1.05,0.90,0.93,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00},
+{1.86,1.95,1.82,1.98,1.89,1.71,1.80,1.91,1.77,1.86,1.67,1.34,1.53,1.51,1.72,1.92,1.91,1.99,1.69,1.82,1.80,1.94,1.87,1.86,1.97,1.59,1.44,1.69,1.05,1.24,1.27,1.49,1.50,1.69,1.72,1.63,1.46,1.37,1.00,1.23,0.98,0.95,1.09,0.96,1.16,1.55,0.99,1.25,1.10,1.24,1.41,0.90,0.85,0.94,0.79,0.81,0.85,0.89,0.94,1.09,0.98,0.89,0.82,0.83,0.74,0.77,0.72,0.76,0.73,0.75,0.78,0.94,0.86,0.91,0.79,0.83,0.89,0.99,0.95,0.90,0.90,0.92,0.84,0.86,0.79,0.75,0.81,0.85,0.80,0.78,0.76,0.77,0.73,0.74,0.71,0.71,0.73,0.74,0.74,0.71,0.76,0.72,0.70,0.79,0.85,0.78,0.98,0.92,0.93,0.85,0.87,0.82,0.79,0.81,0.89,0.86,1.16,0.97,1.12,0.95,1.06,1.00,0.93,1.38,1.60,1.35,1.77,1.71,1.57,1.48,1.20,1.28,1.62,1.27,1.46,1.17,1.05,1.34,0.96,0.99,0.90,1.63,1.74,1.50,1.80,1.33,1.58,1.48,1.37,1.21,1.04,1.21,0.97,0.97,0.93,1.05,1.34,1.02,1.14,0.84,0.88,0.92,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00},
+{1.74,1.89,1.76,1.98,1.89,1.71,1.93,1.99,1.91,1.94,1.82,1.46,1.60,1.65,1.80,1.79,1.77,1.92,1.57,1.69,1.74,1.87,1.88,1.94,1.98,1.53,1.45,1.70,1.18,1.32,1.42,1.58,1.65,1.83,1.81,1.81,1.67,1.61,1.19,1.44,1.17,1.11,1.36,1.15,1.41,1.75,1.22,1.50,1.34,1.42,1.61,0.98,0.92,1.03,0.83,0.86,0.89,0.95,0.98,1.23,1.14,0.97,0.89,0.90,0.78,0.82,0.76,0.82,0.77,0.79,0.84,0.98,0.90,0.98,0.83,0.89,0.97,1.03,0.95,0.92,0.86,0.90,0.82,0.86,0.79,0.77,0.84,0.81,0.76,0.76,0.72,0.73,0.70,0.72,0.71,0.73,0.73,0.72,0.74,0.71,0.78,0.74,0.72,0.75,0.80,0.76,0.94,0.88,0.91,0.83,0.87,0.84,0.79,0.76,0.82,0.80,0.97,0.89,0.96,0.88,0.95,0.94,0.87,1.11,1.37,1.10,1.59,1.57,1.37,1.33,1.05,1.08,1.54,1.34,1.46,1.16,0.99,1.26,0.96,1.05,0.92,1.45,1.55,1.27,1.60,1.07,1.34,1.35,1.18,1.07,0.93,0.99,0.90,0.93,0.87,0.96,1.27,0.99,1.15,0.77,0.82,0.85,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00},
+{1.60,1.78,1.68,1.93,1.86,1.71,1.97,1.99,1.99,1.97,1.93,1.60,1.68,1.78,1.86,1.61,1.57,1.79,1.37,1.48,1.59,1.72,1.79,1.92,1.90,1.38,1.35,1.60,1.23,1.30,1.47,1.56,1.71,1.88,1.79,1.92,1.79,1.79,1.30,1.56,1.35,1.37,1.59,1.38,1.60,1.90,1.48,1.72,1.57,1.61,1.79,1.21,1.00,1.30,0.89,0.94,0.96,1.07,1.14,1.40,1.37,1.14,0.96,0.98,0.82,0.88,0.82,0.89,0.83,0.86,0.91,1.02,0.93,1.07,0.87,0.94,1.11,1.02,0.93,0.93,0.82,0.87,0.80,0.85,0.79,0.80,0.85,0.77,0.72,0.74,0.71,0.70,0.70,0.71,0.72,0.77,0.74,0.72,0.76,0.73,0.82,0.79,0.76,0.73,0.79,0.76,0.93,0.86,0.91,0.83,0.89,0.89,0.82,0.72,0.76,0.76,0.89,0.82,0.89,0.82,0.89,0.91,0.83,0.96,1.14,0.97,1.40,1.44,1.19,1.22,0.99,0.98,1.49,1.44,1.49,1.22,0.99,1.23,0.98,1.19,0.97,1.21,1.30,1.00,1.37,0.94,1.07,1.14,0.98,0.96,0.86,0.91,0.83,0.88,0.82,0.89,1.11,0.94,1.07,0.73,0.76,0.79,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00},
+{1.46,1.65,1.60,1.82,1.80,1.71,1.93,1.91,1.99,1.94,1.98,1.74,1.76,1.89,1.89,1.42,1.34,1.61,1.11,1.22,1.36,1.50,1.61,1.81,1.75,1.15,1.17,1.41,1.18,1.19,1.42,1.44,1.65,1.83,1.67,1.94,1.81,1.88,1.32,1.58,1.45,1.57,1.74,1.53,1.70,1.98,1.69,1.87,1.77,1.79,1.92,1.45,1.27,1.55,0.97,1.07,1.11,1.34,1.37,1.59,1.60,1.35,1.07,1.18,0.86,0.93,0.87,0.96,0.90,0.93,0.99,1.03,0.95,1.15,0.90,0.99,1.27,0.98,0.90,0.92,0.78,0.83,0.77,0.84,0.79,0.82,0.86,0.73,0.71,0.73,0.72,0.70,0.73,0.72,0.76,0.81,0.76,0.76,0.82,0.77,0.89,0.85,0.82,0.75,0.80,0.80,0.94,0.88,0.94,0.87,0.95,0.96,0.88,0.72,0.74,0.76,0.83,0.78,0.84,0.79,0.87,0.91,0.83,0.89,0.98,0.92,1.23,1.34,1.05,1.16,0.99,0.96,1.46,1.57,1.54,1.33,1.05,1.26,1.08,1.37,1.10,0.98,1.03,0.92,1.14,0.86,0.95,0.97,0.90,0.89,0.79,0.84,0.77,0.82,0.76,0.82,0.97,0.89,0.98,0.71,0.72,0.74,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00},
+{1.34,1.51,1.53,1.67,1.72,1.71,1.80,1.77,1.91,1.86,1.98,1.86,1.82,1.95,1.89,1.24,1.10,1.41,0.95,0.99,1.09,1.25,1.37,1.63,1.55,0.96,0.98,1.16,1.05,1.00,1.27,1.23,1.50,1.69,1.46,1.86,1.72,1.87,1.24,1.49,1.44,1.69,1.80,1.59,1.69,1.97,1.82,1.94,1.91,1.92,1.99,1.63,1.50,1.74,1.16,1.33,1.38,1.58,1.60,1.77,1.80,1.48,1.21,1.37,0.90,0.97,0.93,1.05,0.97,1.04,1.21,0.99,0.95,1.14,0.92,1.02,1.34,0.94,0.86,0.90,0.74,0.79,0.75,0.81,0.79,0.84,0.86,0.71,0.71,0.73,0.76,0.73,0.77,0.74,0.80,0.85,0.78,0.81,0.89,0.84,0.97,0.92,0.88,0.79,0.85,0.86,0.98,0.92,1.00,0.93,1.06,1.12,0.95,0.74,0.74,0.78,0.79,0.76,0.82,0.79,0.87,0.93,0.85,0.85,0.94,0.90,1.09,1.27,0.99,1.17,1.05,0.96,1.46,1.71,1.62,1.48,1.20,1.34,1.28,1.57,1.35,0.90,0.94,0.85,0.98,0.81,0.89,0.89,0.83,0.82,0.75,0.78,0.73,0.77,0.72,0.76,0.89,0.83,0.91,0.71,0.70,0.72,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00},
+{1.26,1.39,1.48,1.51,1.64,1.71,1.60,1.58,1.77,1.74,1.91,1.94,1.87,1.97,1.85,1.10,0.97,1.22,0.88,0.92,0.95,1.01,1.11,1.39,1.32,0.88,0.90,0.97,0.96,0.93,1.05,0.99,1.27,1.47,1.20,1.70,1.54,1.76,1.08,1.31,1.33,1.70,1.76,1.55,1.57,1.88,1.85,1.91,1.97,1.99,1.99,1.70,1.65,1.85,1.41,1.54,1.61,1.76,1.80,1.91,1.93,1.52,1.26,1.48,0.92,0.99,0.97,1.18,1.09,1.28,1.39,0.94,0.93,1.05,0.92,1.01,1.31,0.88,0.81,0.86,0.72,0.75,0.74,0.79,0.79,0.86,0.85,0.71,0.73,0.75,0.82,0.77,0.83,0.78,0.85,0.88,0.81,0.88,0.97,0.90,1.18,1.00,0.93,0.86,0.92,0.94,1.14,0.99,1.24,1.03,1.33,1.39,1.11,0.79,0.77,0.84,0.79,0.77,0.84,0.83,0.90,0.98,0.91,0.85,0.92,0.91,1.02,1.26,1.00,1.23,1.19,0.99,1.50,1.84,1.71,1.64,1.38,1.46,1.51,1.76,1.59,0.84,0.88,0.80,0.94,0.79,0.86,0.82,0.77,0.76,0.74,0.74,0.71,0.73,0.70,0.72,0.82,0.77,0.85,0.74,0.70,0.73,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00,1.00}
+}
diff --git a/apps/plugins/sdl/progs/quake/anorms.h b/apps/plugins/sdl/progs/quake/anorms.h
new file mode 100644
index 0000000000..11a9007e88
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/anorms.h
@@ -0,0 +1,181 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+{-0.525731, 0.000000, 0.850651},
+{-0.442863, 0.238856, 0.864188},
+{-0.295242, 0.000000, 0.955423},
+{-0.309017, 0.500000, 0.809017},
+{-0.162460, 0.262866, 0.951056},
+{0.000000, 0.000000, 1.000000},
+{0.000000, 0.850651, 0.525731},
+{-0.147621, 0.716567, 0.681718},
+{0.147621, 0.716567, 0.681718},
+{0.000000, 0.525731, 0.850651},
+{0.309017, 0.500000, 0.809017},
+{0.525731, 0.000000, 0.850651},
+{0.295242, 0.000000, 0.955423},
+{0.442863, 0.238856, 0.864188},
+{0.162460, 0.262866, 0.951056},
+{-0.681718, 0.147621, 0.716567},
+{-0.809017, 0.309017, 0.500000},
+{-0.587785, 0.425325, 0.688191},
+{-0.850651, 0.525731, 0.000000},
+{-0.864188, 0.442863, 0.238856},
+{-0.716567, 0.681718, 0.147621},
+{-0.688191, 0.587785, 0.425325},
+{-0.500000, 0.809017, 0.309017},
+{-0.238856, 0.864188, 0.442863},
+{-0.425325, 0.688191, 0.587785},
+{-0.716567, 0.681718, -0.147621},
+{-0.500000, 0.809017, -0.309017},
+{-0.525731, 0.850651, 0.000000},
+{0.000000, 0.850651, -0.525731},
+{-0.238856, 0.864188, -0.442863},
+{0.000000, 0.955423, -0.295242},
+{-0.262866, 0.951056, -0.162460},
+{0.000000, 1.000000, 0.000000},
+{0.000000, 0.955423, 0.295242},
+{-0.262866, 0.951056, 0.162460},
+{0.238856, 0.864188, 0.442863},
+{0.262866, 0.951056, 0.162460},
+{0.500000, 0.809017, 0.309017},
+{0.238856, 0.864188, -0.442863},
+{0.262866, 0.951056, -0.162460},
+{0.500000, 0.809017, -0.309017},
+{0.850651, 0.525731, 0.000000},
+{0.716567, 0.681718, 0.147621},
+{0.716567, 0.681718, -0.147621},
+{0.525731, 0.850651, 0.000000},
+{0.425325, 0.688191, 0.587785},
+{0.864188, 0.442863, 0.238856},
+{0.688191, 0.587785, 0.425325},
+{0.809017, 0.309017, 0.500000},
+{0.681718, 0.147621, 0.716567},
+{0.587785, 0.425325, 0.688191},
+{0.955423, 0.295242, 0.000000},
+{1.000000, 0.000000, 0.000000},
+{0.951056, 0.162460, 0.262866},
+{0.850651, -0.525731, 0.000000},
+{0.955423, -0.295242, 0.000000},
+{0.864188, -0.442863, 0.238856},
+{0.951056, -0.162460, 0.262866},
+{0.809017, -0.309017, 0.500000},
+{0.681718, -0.147621, 0.716567},
+{0.850651, 0.000000, 0.525731},
+{0.864188, 0.442863, -0.238856},
+{0.809017, 0.309017, -0.500000},
+{0.951056, 0.162460, -0.262866},
+{0.525731, 0.000000, -0.850651},
+{0.681718, 0.147621, -0.716567},
+{0.681718, -0.147621, -0.716567},
+{0.850651, 0.000000, -0.525731},
+{0.809017, -0.309017, -0.500000},
+{0.864188, -0.442863, -0.238856},
+{0.951056, -0.162460, -0.262866},
+{0.147621, 0.716567, -0.681718},
+{0.309017, 0.500000, -0.809017},
+{0.425325, 0.688191, -0.587785},
+{0.442863, 0.238856, -0.864188},
+{0.587785, 0.425325, -0.688191},
+{0.688191, 0.587785, -0.425325},
+{-0.147621, 0.716567, -0.681718},
+{-0.309017, 0.500000, -0.809017},
+{0.000000, 0.525731, -0.850651},
+{-0.525731, 0.000000, -0.850651},
+{-0.442863, 0.238856, -0.864188},
+{-0.295242, 0.000000, -0.955423},
+{-0.162460, 0.262866, -0.951056},
+{0.000000, 0.000000, -1.000000},
+{0.295242, 0.000000, -0.955423},
+{0.162460, 0.262866, -0.951056},
+{-0.442863, -0.238856, -0.864188},
+{-0.309017, -0.500000, -0.809017},
+{-0.162460, -0.262866, -0.951056},
+{0.000000, -0.850651, -0.525731},
+{-0.147621, -0.716567, -0.681718},
+{0.147621, -0.716567, -0.681718},
+{0.000000, -0.525731, -0.850651},
+{0.309017, -0.500000, -0.809017},
+{0.442863, -0.238856, -0.864188},
+{0.162460, -0.262866, -0.951056},
+{0.238856, -0.864188, -0.442863},
+{0.500000, -0.809017, -0.309017},
+{0.425325, -0.688191, -0.587785},
+{0.716567, -0.681718, -0.147621},
+{0.688191, -0.587785, -0.425325},
+{0.587785, -0.425325, -0.688191},
+{0.000000, -0.955423, -0.295242},
+{0.000000, -1.000000, 0.000000},
+{0.262866, -0.951056, -0.162460},
+{0.000000, -0.850651, 0.525731},
+{0.000000, -0.955423, 0.295242},
+{0.238856, -0.864188, 0.442863},
+{0.262866, -0.951056, 0.162460},
+{0.500000, -0.809017, 0.309017},
+{0.716567, -0.681718, 0.147621},
+{0.525731, -0.850651, 0.000000},
+{-0.238856, -0.864188, -0.442863},
+{-0.500000, -0.809017, -0.309017},
+{-0.262866, -0.951056, -0.162460},
+{-0.850651, -0.525731, 0.000000},
+{-0.716567, -0.681718, -0.147621},
+{-0.716567, -0.681718, 0.147621},
+{-0.525731, -0.850651, 0.000000},
+{-0.500000, -0.809017, 0.309017},
+{-0.238856, -0.864188, 0.442863},
+{-0.262866, -0.951056, 0.162460},
+{-0.864188, -0.442863, 0.238856},
+{-0.809017, -0.309017, 0.500000},
+{-0.688191, -0.587785, 0.425325},
+{-0.681718, -0.147621, 0.716567},
+{-0.442863, -0.238856, 0.864188},
+{-0.587785, -0.425325, 0.688191},
+{-0.309017, -0.500000, 0.809017},
+{-0.147621, -0.716567, 0.681718},
+{-0.425325, -0.688191, 0.587785},
+{-0.162460, -0.262866, 0.951056},
+{0.442863, -0.238856, 0.864188},
+{0.162460, -0.262866, 0.951056},
+{0.309017, -0.500000, 0.809017},
+{0.147621, -0.716567, 0.681718},
+{0.000000, -0.525731, 0.850651},
+{0.425325, -0.688191, 0.587785},
+{0.587785, -0.425325, 0.688191},
+{0.688191, -0.587785, 0.425325},
+{-0.955423, 0.295242, 0.000000},
+{-0.951056, 0.162460, 0.262866},
+{-1.000000, 0.000000, 0.000000},
+{-0.850651, 0.000000, 0.525731},
+{-0.955423, -0.295242, 0.000000},
+{-0.951056, -0.162460, 0.262866},
+{-0.864188, 0.442863, -0.238856},
+{-0.951056, 0.162460, -0.262866},
+{-0.809017, 0.309017, -0.500000},
+{-0.864188, -0.442863, -0.238856},
+{-0.951056, -0.162460, -0.262866},
+{-0.809017, -0.309017, -0.500000},
+{-0.681718, 0.147621, -0.716567},
+{-0.681718, -0.147621, -0.716567},
+{-0.850651, 0.000000, -0.525731},
+{-0.688191, 0.587785, -0.425325},
+{-0.587785, 0.425325, -0.688191},
+{-0.425325, 0.688191, -0.587785},
+{-0.425325, -0.688191, -0.587785},
+{-0.587785, -0.425325, -0.688191},
+{-0.688191, -0.587785, -0.425325},
diff --git a/apps/plugins/sdl/progs/quake/asm_draw.h b/apps/plugins/sdl/progs/quake/asm_draw.h
new file mode 100644
index 0000000000..5534ab63c7
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/asm_draw.h
@@ -0,0 +1,151 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+//
+// asm_draw.h
+//
+// Include file for asm drawing routines.
+//
+
+//
+// !!! note that this file must match the corresponding C structures at all
+// times !!!
+//
+
+// !!! if this is changed, it must be changed in r_local.h too !!!
+#define NEAR_CLIP 0.01
+
+// !!! if this is changed, it must be changed in r_local.h too !!!
+#define CYCLE 128
+
+// espan_t structure
+// !!! if this is changed, it must be changed in r_shared.h too !!!
+#define espan_t_u 0
+#define espan_t_v 4
+#define espan_t_count 8
+#define espan_t_pnext 12
+#define espan_t_size 16
+
+// sspan_t structure
+// !!! if this is changed, it must be changed in d_local.h too !!!
+#define sspan_t_u 0
+#define sspan_t_v 4
+#define sspan_t_count 8
+#define sspan_t_size 12
+
+// spanpackage_t structure
+// !!! if this is changed, it must be changed in d_polyset.c too !!!
+#define spanpackage_t_pdest 0
+#define spanpackage_t_pz 4
+#define spanpackage_t_count 8
+#define spanpackage_t_ptex 12
+#define spanpackage_t_sfrac 16
+#define spanpackage_t_tfrac 20
+#define spanpackage_t_light 24
+#define spanpackage_t_zi 28
+#define spanpackage_t_size 32
+
+// edge_t structure
+// !!! if this is changed, it must be changed in r_shared.h too !!!
+#define et_u 0
+#define et_u_step 4
+#define et_prev 8
+#define et_next 12
+#define et_surfs 16
+#define et_nextremove 20
+#define et_nearzi 24
+#define et_owner 28
+#define et_size 32
+
+// surf_t structure
+// !!! if this is changed, it must be changed in r_shared.h too !!!
+#define SURF_T_SHIFT 6
+#define st_next 0
+#define st_prev 4
+#define st_spans 8
+#define st_key 12
+#define st_last_u 16
+#define st_spanstate 20
+#define st_flags 24
+#define st_data 28
+#define st_entity 32
+#define st_nearzi 36
+#define st_insubmodel 40
+#define st_d_ziorigin 44
+#define st_d_zistepu 48
+#define st_d_zistepv 52
+#define st_pad 56
+#define st_size 64
+
+// clipplane_t structure
+// !!! if this is changed, it must be changed in r_local.h too !!!
+#define cp_normal 0
+#define cp_dist 12
+#define cp_next 16
+#define cp_leftedge 20
+#define cp_rightedge 21
+#define cp_reserved 22
+#define cp_size 24
+
+// medge_t structure
+// !!! if this is changed, it must be changed in model.h too !!!
+#define me_v 0
+#define me_cachededgeoffset 4
+#define me_size 8
+
+// mvertex_t structure
+// !!! if this is changed, it must be changed in model.h too !!!
+#define mv_position 0
+#define mv_size 12
+
+// refdef_t structure
+// !!! if this is changed, it must be changed in render.h too !!!
+#define rd_vrect 0
+#define rd_aliasvrect 20
+#define rd_vrectright 40
+#define rd_vrectbottom 44
+#define rd_aliasvrectright 48
+#define rd_aliasvrectbottom 52
+#define rd_vrectrightedge 56
+#define rd_fvrectx 60
+#define rd_fvrecty 64
+#define rd_fvrectx_adj 68
+#define rd_fvrecty_adj 72
+#define rd_vrect_x_adj_shift20 76
+#define rd_vrectright_adj_shift20 80
+#define rd_fvrectright_adj 84
+#define rd_fvrectbottom_adj 88
+#define rd_fvrectright 92
+#define rd_fvrectbottom 96
+#define rd_horizontalFieldOfView 100
+#define rd_xOrigin 104
+#define rd_yOrigin 108
+#define rd_vieworg 112
+#define rd_viewangles 124
+#define rd_ambientlight 136
+#define rd_size 140
+
+// mtriangle_t structure
+// !!! if this is changed, it must be changed in model.h too !!!
+#define mtri_facesfront 0
+#define mtri_vertindex 4
+#define mtri_size 16 // !!! if this changes, array indexing in !!!
+ // !!! d_polysa.s must be changed to match !!!
+#define mtri_shift 4
+
diff --git a/apps/plugins/sdl/progs/quake/asm_i386.h b/apps/plugins/sdl/progs/quake/asm_i386.h
new file mode 100644
index 0000000000..03dc2aae8a
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/asm_i386.h
@@ -0,0 +1,97 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+
+#ifndef __ASM_I386__
+#define __ASM_I386__
+
+#ifdef ELF
+#define C(label) label
+#else
+#define C(label) _##label
+#endif
+
+//
+// !!! note that this file must match the corresponding C structures at all
+// times !!!
+//
+
+// plane_t structure
+// !!! if this is changed, it must be changed in model.h too !!!
+// !!! if the size of this is changed, the array lookup in SV_HullPointContents
+// must be changed too !!!
+#define pl_normal 0
+#define pl_dist 12
+#define pl_type 16
+#define pl_signbits 17
+#define pl_pad 18
+#define pl_size 20
+
+// hull_t structure
+// !!! if this is changed, it must be changed in model.h too !!!
+#define hu_clipnodes 0
+#define hu_planes 4
+#define hu_firstclipnode 8
+#define hu_lastclipnode 12
+#define hu_clip_mins 16
+#define hu_clip_maxs 28
+#define hu_size 40
+
+// dnode_t structure
+// !!! if this is changed, it must be changed in bspfile.h too !!!
+#define nd_planenum 0
+#define nd_children 4
+#define nd_mins 8
+#define nd_maxs 20
+#define nd_firstface 32
+#define nd_numfaces 36
+#define nd_size 40
+
+// sfxcache_t structure
+// !!! if this is changed, it much be changed in sound.h too !!!
+#define sfxc_length 0
+#define sfxc_loopstart 4
+#define sfxc_speed 8
+#define sfxc_width 12
+#define sfxc_stereo 16
+#define sfxc_data 20
+
+// channel_t structure
+// !!! if this is changed, it much be changed in sound.h too !!!
+#define ch_sfx 0
+#define ch_leftvol 4
+#define ch_rightvol 8
+#define ch_end 12
+#define ch_pos 16
+#define ch_looping 20
+#define ch_entnum 24
+#define ch_entchannel 28
+#define ch_origin 32
+#define ch_dist_mult 44
+#define ch_master_vol 48
+#define ch_size 52
+
+// portable_samplepair_t structure
+// !!! if this is changed, it much be changed in sound.h too !!!
+#define psp_left 0
+#define psp_right 4
+#define psp_size 8
+
+#endif
+
diff --git a/apps/plugins/sdl/progs/quake/block16.h b/apps/plugins/sdl/progs/quake/block16.h
new file mode 100644
index 0000000000..96f222e188
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/block16.h
@@ -0,0 +1,142 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+LEnter16_16:
+ movb (%esi),%al
+ movb (%esi,%ebx,),%cl
+ movb %dh,%ah
+ addl %ebp,%edx
+ movb %dh,%ch
+ leal (%esi,%ebx,2),%esi
+ movw 0x12345678(,%eax,2),%ax
+LBPatch0:
+ addl %ebp,%edx
+ movw %ax,(%edi)
+ movw 0x12345678(,%ecx,2),%cx
+LBPatch1:
+ movw %cx,2(%edi)
+ addl $0x4,%edi
+
+ movb (%esi),%al
+ movb (%esi,%ebx,),%cl
+ movb %dh,%ah
+ addl %ebp,%edx
+ movb %dh,%ch
+ leal (%esi,%ebx,2),%esi
+ movw 0x12345678(,%eax,2),%ax
+LBPatch2:
+ addl %ebp,%edx
+ movw %ax,(%edi)
+ movw 0x12345678(,%ecx,2),%cx
+LBPatch3:
+ movw %cx,2(%edi)
+ addl $0x4,%edi
+
+ movb (%esi),%al
+ movb (%esi,%ebx,),%cl
+ movb %dh,%ah
+ addl %ebp,%edx
+ movb %dh,%ch
+ leal (%esi,%ebx,2),%esi
+ movw 0x12345678(,%eax,2),%ax
+LBPatch4:
+ addl %ebp,%edx
+ movw %ax,(%edi)
+ movw 0x12345678(,%ecx,2),%cx
+LBPatch5:
+ movw %cx,2(%edi)
+ addl $0x4,%edi
+
+ movb (%esi),%al
+ movb (%esi,%ebx,),%cl
+ movb %dh,%ah
+ addl %ebp,%edx
+ movb %dh,%ch
+ leal (%esi,%ebx,2),%esi
+ movw 0x12345678(,%eax,2),%ax
+LBPatch6:
+ addl %ebp,%edx
+ movw %ax,(%edi)
+ movw 0x12345678(,%ecx,2),%cx
+LBPatch7:
+ movw %cx,2(%edi)
+ addl $0x4,%edi
+
+LEnter8_16:
+ movb (%esi),%al
+ movb (%esi,%ebx,),%cl
+ movb %dh,%ah
+ addl %ebp,%edx
+ movb %dh,%ch
+ leal (%esi,%ebx,2),%esi
+ movw 0x12345678(,%eax,2),%ax
+LBPatch8:
+ addl %ebp,%edx
+ movw %ax,(%edi)
+ movw 0x12345678(,%ecx,2),%cx
+LBPatch9:
+ movw %cx,2(%edi)
+ addl $0x4,%edi
+
+ movb (%esi),%al
+ movb (%esi,%ebx,),%cl
+ movb %dh,%ah
+ addl %ebp,%edx
+ movb %dh,%ch
+ leal (%esi,%ebx,2),%esi
+ movw 0x12345678(,%eax,2),%ax
+LBPatch10:
+ addl %ebp,%edx
+ movw %ax,(%edi)
+ movw 0x12345678(,%ecx,2),%cx
+LBPatch11:
+ movw %cx,2(%edi)
+ addl $0x4,%edi
+
+LEnter4_16:
+ movb (%esi),%al
+ movb (%esi,%ebx,),%cl
+ movb %dh,%ah
+ addl %ebp,%edx
+ movb %dh,%ch
+ leal (%esi,%ebx,2),%esi
+ movw 0x12345678(,%eax,2),%ax
+LBPatch12:
+ addl %ebp,%edx
+ movw %ax,(%edi)
+ movw 0x12345678(,%ecx,2),%cx
+LBPatch13:
+ movw %cx,2(%edi)
+ addl $0x4,%edi
+
+LEnter2_16:
+ movb (%esi),%al
+ movb (%esi,%ebx,),%cl
+ movb %dh,%ah
+ addl %ebp,%edx
+ movb %dh,%ch
+ leal (%esi,%ebx,2),%esi
+ movw 0x12345678(,%eax,2),%ax
+LBPatch14:
+ addl %ebp,%edx
+ movw %ax,(%edi)
+ movw 0x12345678(,%ecx,2),%cx
+LBPatch15:
+ movw %cx,2(%edi)
+ addl $0x4,%edi
diff --git a/apps/plugins/sdl/progs/quake/block8.h b/apps/plugins/sdl/progs/quake/block8.h
new file mode 100644
index 0000000000..eb9b03c3af
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/block8.h
@@ -0,0 +1,143 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+LEnter16_8:
+ movb (%esi),%al
+ movb (%esi,%ebx,),%cl
+ movb %dh,%ah
+ addl %ebp,%edx
+ movb %dh,%ch
+ leal (%esi,%ebx,2),%esi
+ movb 0x12345678(%eax),%al
+LBPatch0:
+ addl %ebp,%edx
+ movb %al,(%edi)
+ movb 0x12345678(%ecx),%cl
+LBPatch1:
+ movb %cl,1(%edi)
+ addl $0x2,%edi
+
+ movb (%esi),%al
+ movb (%esi,%ebx,),%cl
+ movb %dh,%ah
+ addl %ebp,%edx
+ movb %dh,%ch
+ leal (%esi,%ebx,2),%esi
+ movb 0x12345678(%eax),%al
+LBPatch2:
+ addl %ebp,%edx
+ movb %al,(%edi)
+ movb 0x12345678(%ecx),%cl
+LBPatch3:
+ movb %cl,1(%edi)
+ addl $0x2,%edi
+
+ movb (%esi),%al
+ movb (%esi,%ebx,),%cl
+ movb %dh,%ah
+ addl %ebp,%edx
+ movb %dh,%ch
+ leal (%esi,%ebx,2),%esi
+ movb 0x12345678(%eax),%al
+LBPatch4:
+ addl %ebp,%edx
+ movb %al,(%edi)
+ movb 0x12345678(%ecx),%cl
+LBPatch5:
+ movb %cl,1(%edi)
+ addl $0x2,%edi
+
+ movb (%esi),%al
+ movb (%esi,%ebx,),%cl
+ movb %dh,%ah
+ addl %ebp,%edx
+ movb %dh,%ch
+ leal (%esi,%ebx,2),%esi
+ movb 0x12345678(%eax),%al
+LBPatch6:
+ addl %ebp,%edx
+ movb %al,(%edi)
+ movb 0x12345678(%ecx),%cl
+LBPatch7:
+ movb %cl,1(%edi)
+ addl $0x2,%edi
+
+LEnter8_8:
+ movb (%esi),%al
+ movb (%esi,%ebx,),%cl
+ movb %dh,%ah
+ addl %ebp,%edx
+ movb %dh,%ch
+ leal (%esi,%ebx,2),%esi
+ movb 0x12345678(%eax),%al
+LBPatch8:
+ addl %ebp,%edx
+ movb %al,(%edi)
+ movb 0x12345678(%ecx),%cl
+LBPatch9:
+ movb %cl,1(%edi)
+ addl $0x2,%edi
+
+ movb (%esi),%al
+ movb (%esi,%ebx,),%cl
+ movb %dh,%ah
+ addl %ebp,%edx
+ movb %dh,%ch
+ leal (%esi,%ebx,2),%esi
+ movb 0x12345678(%eax),%al
+LBPatch10:
+ addl %ebp,%edx
+ movb %al,(%edi)
+ movb 0x12345678(%ecx),%cl
+LBPatch11:
+ movb %cl,1(%edi)
+ addl $0x2,%edi
+
+LEnter4_8:
+ movb (%esi),%al
+ movb (%esi,%ebx,),%cl
+ movb %dh,%ah
+ addl %ebp,%edx
+ movb %dh,%ch
+ leal (%esi,%ebx,2),%esi
+ movb 0x12345678(%eax),%al
+LBPatch12:
+ addl %ebp,%edx
+ movb %al,(%edi)
+ movb 0x12345678(%ecx),%cl
+LBPatch13:
+ movb %cl,1(%edi)
+ addl $0x2,%edi
+
+LEnter2_8:
+ movb (%esi),%al
+ movb (%esi,%ebx,),%cl
+ movb %dh,%ah
+ addl %ebp,%edx
+ movb %dh,%ch
+ leal (%esi,%ebx,2),%esi
+ movb 0x12345678(%eax),%al
+LBPatch14:
+ addl %ebp,%edx
+ movb %al,(%edi)
+ movb 0x12345678(%ecx),%cl
+LBPatch15:
+ movb %cl,1(%edi)
+ addl $0x2,%edi
+
diff --git a/apps/plugins/sdl/progs/quake/bspfile.h b/apps/plugins/sdl/progs/quake/bspfile.h
new file mode 100644
index 0000000000..308902632b
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/bspfile.h
@@ -0,0 +1,324 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+
+
+// upper design bounds
+
+#define MAX_MAP_HULLS 4
+
+#define MAX_MAP_MODELS 256
+#define MAX_MAP_BRUSHES 4096
+#define MAX_MAP_ENTITIES 1024
+#define MAX_MAP_ENTSTRING 65536
+
+#define MAX_MAP_PLANES 32767
+#define MAX_MAP_NODES 32767 // because negative shorts are contents
+#define MAX_MAP_CLIPNODES 32767 //
+#define MAX_MAP_LEAFS 8192
+#define MAX_MAP_VERTS 65535
+#define MAX_MAP_FACES 65535
+#define MAX_MAP_MARKSURFACES 65535
+#define MAX_MAP_TEXINFO 4096
+#define MAX_MAP_EDGES 256000
+#define MAX_MAP_SURFEDGES 512000
+#define MAX_MAP_TEXTURES 512
+#define MAX_MAP_MIPTEX 0x200000
+#define MAX_MAP_LIGHTING 0x100000
+#define MAX_MAP_VISIBILITY 0x100000
+
+#define MAX_MAP_PORTALS 65536
+
+// key / value pair sizes
+
+#define MAX_KEY 32
+#define MAX_VALUE 1024
+
+//=============================================================================
+
+
+#define BSPVERSION 29
+#define TOOLVERSION 2
+
+typedef struct
+{
+ int fileofs, filelen;
+} lump_t;
+
+#define LUMP_ENTITIES 0
+#define LUMP_PLANES 1
+#define LUMP_TEXTURES 2
+#define LUMP_VERTEXES 3
+#define LUMP_VISIBILITY 4
+#define LUMP_NODES 5
+#define LUMP_TEXINFO 6
+#define LUMP_FACES 7
+#define LUMP_LIGHTING 8
+#define LUMP_CLIPNODES 9
+#define LUMP_LEAFS 10
+#define LUMP_MARKSURFACES 11
+#define LUMP_EDGES 12
+#define LUMP_SURFEDGES 13
+#define LUMP_MODELS 14
+
+#define HEADER_LUMPS 15
+
+typedef struct
+{
+ float mins[3], maxs[3];
+ float origin[3];
+ int headnode[MAX_MAP_HULLS];
+ int visleafs; // not including the solid leaf 0
+ int firstface, numfaces;
+} dmodel_t;
+
+typedef struct
+{
+ int version;
+ lump_t lumps[HEADER_LUMPS];
+} dheader_t;
+
+typedef struct
+{
+ int nummiptex;
+ int dataofs[4]; // [nummiptex]
+} dmiptexlump_t;
+
+#define MIPLEVELS 4
+typedef struct miptex_s
+{
+ char name[16];
+ unsigned width, height;
+ unsigned offsets[MIPLEVELS]; // four mip maps stored
+} miptex_t;
+
+
+typedef struct
+{
+ float point[3];
+} dvertex_t;
+
+
+// 0-2 are axial planes
+#define PLANE_X 0
+#define PLANE_Y 1
+#define PLANE_Z 2
+
+// 3-5 are non-axial planes snapped to the nearest
+#define PLANE_ANYX 3
+#define PLANE_ANYY 4
+#define PLANE_ANYZ 5
+
+typedef struct
+{
+ float normal[3];
+ float dist;
+ int type; // PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate
+} dplane_t;
+
+
+
+#define CONTENTS_EMPTY -1
+#define CONTENTS_SOLID -2
+#define CONTENTS_WATER -3
+#define CONTENTS_SLIME -4
+#define CONTENTS_LAVA -5
+#define CONTENTS_SKY -6
+#define CONTENTS_ORIGIN -7 // removed at csg time
+#define CONTENTS_CLIP -8 // changed to contents_solid
+
+#define CONTENTS_CURRENT_0 -9
+#define CONTENTS_CURRENT_90 -10
+#define CONTENTS_CURRENT_180 -11
+#define CONTENTS_CURRENT_270 -12
+#define CONTENTS_CURRENT_UP -13
+#define CONTENTS_CURRENT_DOWN -14
+
+
+// !!! if this is changed, it must be changed in asm_i386.h too !!!
+typedef struct
+{
+ int planenum;
+ short children[2]; // negative numbers are -(leafs+1), not nodes
+ short mins[3]; // for sphere culling
+ short maxs[3];
+ unsigned short firstface;
+ unsigned short numfaces; // counting both sides
+} dnode_t;
+
+typedef struct
+{
+ int planenum;
+ short children[2]; // negative numbers are contents
+} dclipnode_t;
+
+
+typedef struct texinfo_s
+{
+ float vecs[2][4]; // [s/t][xyz offset]
+ int miptex;
+ int flags;
+} texinfo_t;
+#define TEX_SPECIAL 1 // sky or slime, no lightmap or 256 subdivision
+
+// note that edge 0 is never used, because negative edge nums are used for
+// counterclockwise use of the edge in a face
+typedef struct
+{
+ unsigned short v[2]; // vertex numbers
+} dedge_t;
+
+#define MAXLIGHTMAPS 4
+typedef struct
+{
+ short planenum;
+ short side;
+
+ int firstedge; // we must support > 64k edges
+ short numedges;
+ short texinfo;
+
+// lighting info
+ byte styles[MAXLIGHTMAPS];
+ int lightofs; // start of [numstyles*surfsize] samples
+} dface_t;
+
+
+
+#define AMBIENT_WATER 0
+#define AMBIENT_SKY 1
+#define AMBIENT_SLIME 2
+#define AMBIENT_LAVA 3
+
+#define NUM_AMBIENTS 4 // automatic ambient sounds
+
+// leaf 0 is the generic CONTENTS_SOLID leaf, used for all solid areas
+// all other leafs need visibility info
+typedef struct
+{
+ int contents;
+ int visofs; // -1 = no visibility info
+
+ short mins[3]; // for frustum culling
+ short maxs[3];
+
+ unsigned short firstmarksurface;
+ unsigned short nummarksurfaces;
+
+ byte ambient_level[NUM_AMBIENTS];
+} dleaf_t;
+
+
+//============================================================================
+
+#ifndef QUAKE_GAME
+
+#define ANGLE_UP -1
+#define ANGLE_DOWN -2
+
+
+// the utilities get to be lazy and just use large static arrays
+
+extern int nummodels;
+extern dmodel_t dmodels[MAX_MAP_MODELS];
+
+extern int visdatasize;
+extern byte dvisdata[MAX_MAP_VISIBILITY];
+
+extern int lightdatasize;
+extern byte dlightdata[MAX_MAP_LIGHTING];
+
+extern int texdatasize;
+extern byte dtexdata[MAX_MAP_MIPTEX]; // (dmiptexlump_t)
+
+extern int entdatasize;
+extern char dentdata[MAX_MAP_ENTSTRING];
+
+extern int numleafs;
+extern dleaf_t dleafs[MAX_MAP_LEAFS];
+
+extern int numplanes;
+extern dplane_t dplanes[MAX_MAP_PLANES];
+
+extern int numvertexes;
+extern dvertex_t dvertexes[MAX_MAP_VERTS];
+
+extern int numnodes;
+extern dnode_t dnodes[MAX_MAP_NODES];
+
+extern int numtexinfo;
+extern texinfo_t texinfo[MAX_MAP_TEXINFO];
+
+extern int numfaces;
+extern dface_t dfaces[MAX_MAP_FACES];
+
+extern int numclipnodes;
+extern dclipnode_t dclipnodes[MAX_MAP_CLIPNODES];
+
+extern int numedges;
+extern dedge_t dedges[MAX_MAP_EDGES];
+
+extern int nummarksurfaces;
+extern unsigned short dmarksurfaces[MAX_MAP_MARKSURFACES];
+
+extern int numsurfedges;
+extern int dsurfedges[MAX_MAP_SURFEDGES];
+
+
+void DecompressVis (byte *in, byte *decompressed);
+int CompressVis (byte *vis, byte *dest);
+
+void LoadBSPFile (char *filename);
+void WriteBSPFile (char *filename);
+void PrintBSPFileSizes (void);
+
+//===============
+
+
+typedef struct epair_s
+{
+ struct epair_s *next;
+ char *key;
+ char *value;
+} epair_t;
+
+typedef struct
+{
+ vec3_t origin;
+ int firstbrush;
+ int numbrushes;
+ epair_t *epairs;
+} entity_t;
+
+extern int num_entities;
+extern entity_t entities[MAX_MAP_ENTITIES];
+
+void ParseEntities (void);
+void UnparseEntities (void);
+
+void SetKeyValue (entity_t *ent, char *key, char *value);
+char *ValueForKey (entity_t *ent, char *key);
+// will return "" if not present
+
+vec_t FloatForKey (entity_t *ent, char *key);
+void GetVectorForKey (entity_t *ent, char *key, vec3_t vec);
+
+epair_t *ParseEpair (void);
+
+#endif
diff --git a/apps/plugins/sdl/progs/quake/cd_linux.c b/apps/plugins/sdl/progs/quake/cd_linux.c
new file mode 100644
index 0000000000..0e23d96035
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/cd_linux.c
@@ -0,0 +1,416 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// Quake is a trademark of Id Software, Inc., (c) 1996 Id Software, Inc. All
+// rights reserved.
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <sys/file.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <string.h>
+#include <time.h>
+#include <errno.h>
+
+#include <linux/cdrom.h>
+
+#include "quakedef.h"
+
+static qboolean cdValid = false;
+static qboolean playing = false;
+static qboolean wasPlaying = false;
+static qboolean initialized = false;
+static qboolean enabled = true;
+static qboolean playLooping = false;
+static float cdvolume;
+static byte remap[100];
+static byte playTrack;
+static byte maxTrack;
+
+static int cdfile = -1;
+static char cd_dev[64] = "/dev/cdrom";
+
+static void CDAudio_Eject(void)
+{
+ if (cdfile == -1 || !enabled)
+ return; // no cd init'd
+
+ if ( ioctl(cdfile, CDROMEJECT) == -1 )
+ Con_DPrintf("ioctl cdromeject failed\n");
+}
+
+
+static void CDAudio_CloseDoor(void)
+{
+ if (cdfile == -1 || !enabled)
+ return; // no cd init'd
+
+ if ( ioctl(cdfile, CDROMCLOSETRAY) == -1 )
+ Con_DPrintf("ioctl cdromclosetray failed\n");
+}
+
+static int CDAudio_GetAudioDiskInfo(void)
+{
+ struct cdrom_tochdr tochdr;
+
+ cdValid = false;
+
+ if ( ioctl(cdfile, CDROMREADTOCHDR, &tochdr) == -1 )
+ {
+ Con_DPrintf("ioctl cdromreadtochdr failed\n");
+ return -1;
+ }
+
+ if (tochdr.cdth_trk0 < 1)
+ {
+ Con_DPrintf("CDAudio: no music tracks\n");
+ return -1;
+ }
+
+ cdValid = true;
+ maxTrack = tochdr.cdth_trk1;
+
+ return 0;
+}
+
+
+void CDAudio_Play(byte track, qboolean looping)
+{
+ struct cdrom_tocentry entry;
+ struct cdrom_ti ti;
+
+ if (cdfile == -1 || !enabled)
+ return;
+
+ if (!cdValid)
+ {
+ CDAudio_GetAudioDiskInfo();
+ if (!cdValid)
+ return;
+ }
+
+ track = remap[track];
+
+ if (track < 1 || track > maxTrack)
+ {
+ Con_DPrintf("CDAudio: Bad track number %u.\n", track);
+ return;
+ }
+
+ // don't try to play a non-audio track
+ entry.cdte_track = track;
+ entry.cdte_format = CDROM_MSF;
+ if ( ioctl(cdfile, CDROMREADTOCENTRY, &entry) == -1 )
+ {
+ Con_DPrintf("ioctl cdromreadtocentry failed\n");
+ return;
+ }
+ if (entry.cdte_ctrl == CDROM_DATA_TRACK)
+ {
+ Con_Printf("CDAudio: track %i is not audio\n", track);
+ return;
+ }
+
+ if (playing)
+ {
+ if (playTrack == track)
+ return;
+ CDAudio_Stop();
+ }
+
+ ti.cdti_trk0 = track;
+ ti.cdti_trk1 = track;
+ ti.cdti_ind0 = 1;
+ ti.cdti_ind1 = 99;
+
+ if ( ioctl(cdfile, CDROMPLAYTRKIND, &ti) == -1 )
+ {
+ Con_DPrintf("ioctl cdromplaytrkind failed\n");
+ return;
+ }
+
+ if ( ioctl(cdfile, CDROMRESUME) == -1 )
+ Con_DPrintf("ioctl cdromresume failed\n");
+
+ playLooping = looping;
+ playTrack = track;
+ playing = true;
+
+ if (cdvolume == 0.0)
+ CDAudio_Pause ();
+}
+
+
+void CDAudio_Stop(void)
+{
+ if (cdfile == -1 || !enabled)
+ return;
+
+ if (!playing)
+ return;
+
+ if ( ioctl(cdfile, CDROMSTOP) == -1 )
+ Con_DPrintf("ioctl cdromstop failed (%d)\n", errno);
+
+ wasPlaying = false;
+ playing = false;
+}
+
+void CDAudio_Pause(void)
+{
+ if (cdfile == -1 || !enabled)
+ return;
+
+ if (!playing)
+ return;
+
+ if ( ioctl(cdfile, CDROMPAUSE) == -1 )
+ Con_DPrintf("ioctl cdrompause failed\n");
+
+ wasPlaying = playing;
+ playing = false;
+}
+
+
+void CDAudio_Resume(void)
+{
+ if (cdfile == -1 || !enabled)
+ return;
+
+ if (!cdValid)
+ return;
+
+ if (!wasPlaying)
+ return;
+
+ if ( ioctl(cdfile, CDROMRESUME) == -1 )
+ Con_DPrintf("ioctl cdromresume failed\n");
+ playing = true;
+}
+
+static void CD_f (void)
+{
+ char *command;
+ int ret;
+ int n;
+
+ if (Cmd_Argc() < 2)
+ return;
+
+ command = Cmd_Argv (1);
+
+ if (Q_strcasecmp(command, "on") == 0)
+ {
+ enabled = true;
+ return;
+ }
+
+ if (Q_strcasecmp(command, "off") == 0)
+ {
+ if (playing)
+ CDAudio_Stop();
+ enabled = false;
+ return;
+ }
+
+ if (Q_strcasecmp(command, "reset") == 0)
+ {
+ enabled = true;
+ if (playing)
+ CDAudio_Stop();
+ for (n = 0; n < 100; n++)
+ remap[n] = n;
+ CDAudio_GetAudioDiskInfo();
+ return;
+ }
+
+ if (Q_strcasecmp(command, "remap") == 0)
+ {
+ ret = Cmd_Argc() - 2;
+ if (ret <= 0)
+ {
+ for (n = 1; n < 100; n++)
+ if (remap[n] != n)
+ Con_Printf(" %u -> %u\n", n, remap[n]);
+ return;
+ }
+ for (n = 1; n <= ret; n++)
+ remap[n] = Q_atoi(Cmd_Argv (n+1));
+ return;
+ }
+
+ if (Q_strcasecmp(command, "close") == 0)
+ {
+ CDAudio_CloseDoor();
+ return;
+ }
+
+ if (!cdValid)
+ {
+ CDAudio_GetAudioDiskInfo();
+ if (!cdValid)
+ {
+ Con_Printf("No CD in player.\n");
+ return;
+ }
+ }
+
+ if (Q_strcasecmp(command, "play") == 0)
+ {
+ CDAudio_Play((byte)Q_atoi(Cmd_Argv (2)), false);
+ return;
+ }
+
+ if (Q_strcasecmp(command, "loop") == 0)
+ {
+ CDAudio_Play((byte)Q_atoi(Cmd_Argv (2)), true);
+ return;
+ }
+
+ if (Q_strcasecmp(command, "stop") == 0)
+ {
+ CDAudio_Stop();
+ return;
+ }
+
+ if (Q_strcasecmp(command, "pause") == 0)
+ {
+ CDAudio_Pause();
+ return;
+ }
+
+ if (Q_strcasecmp(command, "resume") == 0)
+ {
+ CDAudio_Resume();
+ return;
+ }
+
+ if (Q_strcasecmp(command, "eject") == 0)
+ {
+ if (playing)
+ CDAudio_Stop();
+ CDAudio_Eject();
+ cdValid = false;
+ return;
+ }
+
+ if (Q_strcasecmp(command, "info") == 0)
+ {
+ Con_Printf("%u tracks\n", maxTrack);
+ if (playing)
+ Con_Printf("Currently %s track %u\n", playLooping ? "looping" : "playing", playTrack);
+ else if (wasPlaying)
+ Con_Printf("Paused %s track %u\n", playLooping ? "looping" : "playing", playTrack);
+ Con_Printf("Volume is %f\n", cdvolume);
+ return;
+ }
+}
+
+void CDAudio_Update(void)
+{
+ struct cdrom_subchnl subchnl;
+ static time_t lastchk;
+
+ if (!enabled)
+ return;
+
+ if (bgmvolume.value != cdvolume)
+ {
+ if (cdvolume)
+ {
+ Cvar_SetValue ("bgmvolume", 0.0);
+ cdvolume = bgmvolume.value;
+ CDAudio_Pause ();
+ }
+ else
+ {
+ Cvar_SetValue ("bgmvolume", 1.0);
+ cdvolume = bgmvolume.value;
+ CDAudio_Resume ();
+ }
+ }
+
+ if (playing && lastchk < time(NULL)) {
+ lastchk = time(NULL) + 2; //two seconds between chks
+ subchnl.cdsc_format = CDROM_MSF;
+ if (ioctl(cdfile, CDROMSUBCHNL, &subchnl) == -1 ) {
+ Con_DPrintf("ioctl cdromsubchnl failed\n");
+ playing = false;
+ return;
+ }
+ if (subchnl.cdsc_audiostatus != CDROM_AUDIO_PLAY &&
+ subchnl.cdsc_audiostatus != CDROM_AUDIO_PAUSED) {
+ playing = false;
+ if (playLooping)
+ CDAudio_Play(playTrack, true);
+ }
+ }
+}
+
+int CDAudio_Init(void)
+{
+ int i;
+
+ if (cls.state == ca_dedicated)
+ return -1;
+
+ if (COM_CheckParm("-nocdaudio"))
+ return -1;
+
+ if ((i = COM_CheckParm("-cddev")) != 0 && i < com_argc - 1) {
+ strncpy(cd_dev, com_argv[i + 1], sizeof(cd_dev));
+ cd_dev[sizeof(cd_dev) - 1] = 0;
+ }
+
+ if ((cdfile = open(cd_dev, O_RDONLY)) == -1) {
+ Con_Printf("CDAudio_Init: open of \"%s\" failed (%i)\n", cd_dev, errno);
+ cdfile = -1;
+ return -1;
+ }
+
+ for (i = 0; i < 100; i++)
+ remap[i] = i;
+ initialized = true;
+ enabled = true;
+
+ if (CDAudio_GetAudioDiskInfo())
+ {
+ Con_Printf("CDAudio_Init: No CD in player.\n");
+ cdValid = false;
+ }
+
+ Cmd_AddCommand ("cd", CD_f);
+
+ Con_Printf("CD Audio Initialized\n");
+
+ return 0;
+}
+
+
+void CDAudio_Shutdown(void)
+{
+ if (!initialized)
+ return;
+ CDAudio_Stop();
+ close(cdfile);
+ cdfile = -1;
+}
diff --git a/apps/plugins/sdl/progs/quake/cd_null.c b/apps/plugins/sdl/progs/quake/cd_null.c
new file mode 100644
index 0000000000..d5eeec8ad2
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/cd_null.c
@@ -0,0 +1,55 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+#include "quakedef.h"
+
+void CDAudio_Play(byte track, qboolean looping)
+{
+}
+
+
+void CDAudio_Stop(void)
+{
+}
+
+
+void CDAudio_Pause(void)
+{
+}
+
+
+void CDAudio_Resume(void)
+{
+}
+
+
+void CDAudio_Update(void)
+{
+}
+
+
+int CDAudio_Init(void)
+{
+ return 0;
+}
+
+
+void CDAudio_Shutdown(void)
+{
+} \ No newline at end of file
diff --git a/apps/plugins/sdl/progs/quake/cd_sdl.c b/apps/plugins/sdl/progs/quake/cd_sdl.c
new file mode 100644
index 0000000000..46b2aa2835
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/cd_sdl.c
@@ -0,0 +1,223 @@
+/*
+ Some of this may not work. I'm not overly familiar with SDL, I just sort
+ of podged this together from the SDL headers, and the other cd-rom code.
+
+ Mark Baker <homer1@together.net>
+*/
+
+#include <SDL.h>
+
+#include "quakedef.h"
+
+static qboolean cdValid = false;
+static qboolean initialized = false;
+static qboolean enabled = true;
+static qboolean playLooping = false;
+static SDL_CD *cd_id;
+static float cdvolume = 1.0;
+
+static void CD_f();
+
+static void CDAudio_Eject()
+{
+ if(!cd_id || !enabled) return;
+
+ if(SDL_CDEject(cd_id))
+ Con_DPrintf("Unable to eject CD-ROM tray.\n");
+}
+
+void CDAudio_Play(byte track, qboolean looping)
+{
+ CDstatus cd_stat;
+ if(!cd_id || !enabled) return;
+
+ if(!cdValid)
+ {
+ if(!CD_INDRIVE(cd_stat=SDL_CDStatus(cd_id)) ||(!cd_id->numtracks)) return;
+ cdValid = true;
+ }
+
+ if((track < 1) || (track >= cd_id->numtracks))
+ {
+ Con_DPrintf("CDAudio: Bad track number: %d\n",track);
+ return;
+ }
+ track--; /* Convert track from person to SDL value */
+ if(cd_stat == CD_PLAYING)
+ {
+ if(cd_id->cur_track == track) return;
+ CDAudio_Stop();
+ }
+
+ if(SDL_CDPlay(cd_id,cd_id->track[track].offset,
+ cd_id->track[track].length))
+ {
+ Con_DPrintf("CDAudio_Play: Unable to play track: %d\n",track+1);
+ return;
+ }
+ playLooping = looping;
+}
+
+
+void CDAudio_Stop()
+{
+ int cdstate;
+ if(!cd_id || !enabled) return;
+ cdstate = SDL_CDStatus(cd_id);
+ if((cdstate != CD_PLAYING) && (cdstate != CD_PAUSED)) return;
+
+ if(SDL_CDStop(cd_id))
+ Con_DPrintf("CDAudio_Stop: Failed to stop track.\n");
+}
+
+void CDAudio_Pause()
+{
+ if(!cd_id || !enabled) return;
+ if(SDL_CDStatus(cd_id) != CD_PLAYING) return;
+
+ if(SDL_CDPause(cd_id))
+ Con_DPrintf("CDAudio_Pause: Failed to pause track.\n");
+}
+
+
+void CDAudio_Resume()
+{
+ if(!cd_id || !enabled) return;
+ if(SDL_CDStatus(cd_id) != CD_PAUSED) return;
+
+ if(SDL_CDResume(cd_id))
+ Con_DPrintf("CDAudio_Resume: Failed tp resume track.\n");
+}
+
+void CDAudio_Update()
+{
+ if(!cd_id || !enabled) return;
+ if(bgmvolume.value != cdvolume)
+ {
+ if(cdvolume)
+ {
+ Cvar_SetValue("bgmvolume",0.0);
+ CDAudio_Pause();
+ }
+ else
+ {
+ Cvar_SetValue("bgmvolume",1.0);
+ CDAudio_Resume();
+ }
+ cdvolume = bgmvolume.value;
+ return;
+ }
+ if(playLooping && (SDL_CDStatus(cd_id) != CD_PLAYING)
+ && (SDL_CDStatus(cd_id) != CD_PAUSED))
+ CDAudio_Play(cd_id->cur_track+1,true);
+}
+
+int CDAudio_Init()
+{
+ if((cls.state == ca_dedicated) || COM_CheckParm("-nocdaudio"))
+ return -1;
+
+ cd_id = SDL_CDOpen(0);
+ if(!cd_id)
+ {
+ Con_Printf("CDAudio_Init: Unable to open default CD-ROM drive: %s\n",
+ SDL_GetError());
+ return -1;
+ }
+
+ initialized = true;
+ enabled = true;
+ cdValid = true;
+
+ if(!CD_INDRIVE(SDL_CDStatus(cd_id)))
+ {
+ Con_Printf("CDAudio_Init: No CD in drive.\n");
+ cdValid = false;
+ }
+ if(!cd_id->numtracks)
+ {
+ Con_Printf("CDAudio_Init: CD contains no audio tracks.\n");
+ cdValid = false;
+ }
+ Cmd_AddCommand("cd",CD_f);
+ Con_Printf("CD Audio Initialized.\n");
+ return 0;
+}
+
+
+void CDAudio_Shutdown()
+{
+ if(!cd_id) return;
+ CDAudio_Stop();
+ SDL_CDClose(cd_id);
+ cd_id = NULL;
+}
+
+static void CD_f()
+{
+ char *command;
+ int cdstate;
+ if(Cmd_Argc() < 2) return;
+
+ command = Cmd_Argv(1);
+ if(!Q_strcasecmp(command,"on"))
+ {
+ enabled = true;
+ }
+ if(!Q_strcasecmp(command,"off"))
+ {
+ if(!cd_id) return;
+ cdstate = SDL_CDStatus(cd_id);
+ if((cdstate == CD_PLAYING) || (cdstate == CD_PAUSED))
+ CDAudio_Stop();
+ enabled = false;
+ return;
+ }
+ if(!Q_strcasecmp(command,"play"))
+ {
+ CDAudio_Play(Q_atoi(Cmd_Argv(2)),false);
+ return;
+ }
+ if(!Q_strcasecmp(command,"loop"))
+ {
+ CDAudio_Play(Q_atoi(Cmd_Argv(2)),true);
+ return;
+ }
+ if(!Q_strcasecmp(command,"stop"))
+ {
+ CDAudio_Stop();
+ return;
+ }
+ if(!Q_strcasecmp(command,"pause"))
+ {
+ CDAudio_Pause();
+ return;
+ }
+ if(!Q_strcasecmp(command,"resume"))
+ {
+ CDAudio_Resume();
+ return;
+ }
+ if(!Q_strcasecmp(command,"eject"))
+ {
+ CDAudio_Eject();
+ return;
+ }
+ if(!Q_strcasecmp(command,"info"))
+ {
+ if(!cd_id) return;
+ cdstate = SDL_CDStatus(cd_id);
+ Con_Printf("%d tracks\n",cd_id->numtracks);
+ if(cdstate == CD_PLAYING)
+ Con_Printf("Currently %s track %d\n",
+ playLooping ? "looping" : "playing",
+ cd_id->cur_track+1);
+ else
+ if(cdstate == CD_PAUSED)
+ Con_Printf("Paused %s track %d\n",
+ playLooping ? "looping" : "playing",
+ cd_id->cur_track+1);
+ return;
+ }
+}
+
diff --git a/apps/plugins/sdl/progs/quake/cdaudio.h b/apps/plugins/sdl/progs/quake/cdaudio.h
new file mode 100644
index 0000000000..80e975be23
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/cdaudio.h
@@ -0,0 +1,27 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+
+int CDAudio_Init(void);
+void CDAudio_Play(byte track, qboolean looping);
+void CDAudio_Stop(void);
+void CDAudio_Pause(void);
+void CDAudio_Resume(void);
+void CDAudio_Shutdown(void);
+void CDAudio_Update(void);
diff --git a/apps/plugins/sdl/progs/quake/chase.c b/apps/plugins/sdl/progs/quake/chase.c
new file mode 100644
index 0000000000..23061e341a
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/chase.c
@@ -0,0 +1,92 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// chase.c -- chase camera code
+
+#include "quakedef.h"
+
+cvar_t chase_back = {"chase_back", "100"};
+cvar_t chase_up = {"chase_up", "16"};
+cvar_t chase_right = {"chase_right", "0"};
+cvar_t chase_active = {"chase_active", "0"};
+
+vec3_t chase_pos;
+vec3_t chase_angles;
+
+vec3_t chase_dest;
+vec3_t chase_dest_angles;
+
+
+void Chase_Init (void)
+{
+ Cvar_RegisterVariable (&chase_back);
+ Cvar_RegisterVariable (&chase_up);
+ Cvar_RegisterVariable (&chase_right);
+ Cvar_RegisterVariable (&chase_active);
+}
+
+void Chase_Reset (void)
+{
+ // for respawning and teleporting
+// start position 12 units behind head
+}
+
+void TraceLine (vec3_t start, vec3_t end, vec3_t impact)
+{
+ trace_t trace;
+
+ memset (&trace, 0, sizeof(trace));
+ SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1, start, end, &trace);
+
+ VectorCopy (trace.endpos, impact);
+}
+
+void Chase_Update (void)
+{
+ int i;
+ float dist;
+ vec3_t forward, up, right;
+ vec3_t dest, stop;
+
+
+ // if can't see player, reset
+ AngleVectors (cl.viewangles, forward, right, up);
+
+ // calc exact destination
+ for (i=0 ; i<3 ; i++)
+ chase_dest[i] = r_refdef.vieworg[i]
+ - forward[i]*chase_back.value
+ - right[i]*chase_right.value;
+ chase_dest[2] = r_refdef.vieworg[2] + chase_up.value;
+
+ // find the spot the player is looking at
+ VectorMA (r_refdef.vieworg, 4096, forward, dest);
+ TraceLine (r_refdef.vieworg, dest, stop);
+
+ // calculate pitch to look at the same spot from camera
+ VectorSubtract (stop, r_refdef.vieworg, stop);
+ dist = DotProduct (stop, forward);
+ if (dist < 1)
+ dist = 1;
+ r_refdef.viewangles[PITCH] = -atan(stop[2] / dist) / M_PI * 180;
+
+ // move towards destination
+ VectorCopy (chase_dest, r_refdef.vieworg);
+}
+
diff --git a/apps/plugins/sdl/progs/quake/cl_demo.c b/apps/plugins/sdl/progs/quake/cl_demo.c
new file mode 100644
index 0000000000..45ddef3139
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/cl_demo.c
@@ -0,0 +1,367 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+
+#include "quakedef.h"
+
+void CL_FinishTimeDemo (void);
+
+/*
+==============================================================================
+
+DEMO CODE
+
+When a demo is playing back, all NET_SendMessages are skipped, and
+NET_GetMessages are read from the demo file.
+
+Whenever cl.time gets past the last received message, another message is
+read from the demo file.
+==============================================================================
+*/
+
+/*
+==============
+CL_StopPlayback
+
+Called when a demo file runs out, or the user starts a game
+==============
+*/
+void CL_StopPlayback (void)
+{
+ if (!cls.demoplayback)
+ return;
+
+ fclose (cls.demofile);
+ cls.demoplayback = false;
+ cls.demofile = NULL;
+ cls.state = ca_disconnected;
+
+ if (cls.timedemo)
+ CL_FinishTimeDemo ();
+}
+
+/*
+====================
+CL_WriteDemoMessage
+
+Dumps the current net message, prefixed by the length and view angles
+====================
+*/
+void CL_WriteDemoMessage (void)
+{
+ int len;
+ int i;
+ float f;
+
+ len = LittleLong (net_message.cursize);
+ fwrite (&len, 4, 1, cls.demofile);
+ for (i=0 ; i<3 ; i++)
+ {
+ f = LittleFloat (cl.viewangles[i]);
+ fwrite (&f, 4, 1, cls.demofile);
+ }
+ fwrite (net_message.data, net_message.cursize, 1, cls.demofile);
+ fflush (cls.demofile);
+}
+
+/*
+====================
+CL_GetMessage
+
+Handles recording and playback of demos, on top of NET_ code
+====================
+*/
+int CL_GetMessage (void)
+{
+ int r, i;
+ float f;
+
+ if (cls.demoplayback)
+ {
+ // decide if it is time to grab the next message
+ if (cls.signon == SIGNONS) // allways grab until fully connected
+ {
+ if (cls.timedemo)
+ {
+ if (host_framecount == cls.td_lastframe)
+ return 0; // allready read this frame's message
+ cls.td_lastframe = host_framecount;
+ // if this is the second frame, grab the real td_starttime
+ // so the bogus time on the first frame doesn't count
+ if (host_framecount == cls.td_startframe + 1)
+ cls.td_starttime = realtime;
+ }
+ else if ( /* cl.time > 0 && */ cl.time <= cl.mtime[0])
+ {
+ return 0; // don't need another message yet
+ }
+ }
+
+ // get the next message
+ fread (&net_message.cursize, 4, 1, cls.demofile);
+ VectorCopy (cl.mviewangles[0], cl.mviewangles[1]);
+ for (i=0 ; i<3 ; i++)
+ {
+ r = fread (&f, 4, 1, cls.demofile);
+ cl.mviewangles[0][i] = LittleFloat (f);
+ }
+
+ net_message.cursize = LittleLong (net_message.cursize);
+ if (net_message.cursize > MAX_MSGLEN)
+ Sys_Error ("Demo message > MAX_MSGLEN");
+ r = fread (net_message.data, net_message.cursize, 1, cls.demofile);
+ if (r != 1)
+ {
+ CL_StopPlayback ();
+ return 0;
+ }
+
+ return 1;
+ }
+
+ while (1)
+ {
+ r = NET_GetMessage (cls.netcon);
+
+ if (r != 1 && r != 2)
+ return r;
+
+ // discard nop keepalive message
+ if (net_message.cursize == 1 && net_message.data[0] == svc_nop)
+ Con_Printf ("<-- server to client keepalive\n");
+ else
+ break;
+ }
+
+ if (cls.demorecording)
+ CL_WriteDemoMessage ();
+
+ return r;
+}
+
+
+/*
+====================
+CL_Stop_f
+
+stop recording a demo
+====================
+*/
+void CL_Stop_f (void)
+{
+ if (cmd_source != src_command)
+ return;
+
+ if (!cls.demorecording)
+ {
+ Con_Printf ("Not recording a demo.\n");
+ return;
+ }
+
+// write a disconnect message to the demo file
+ SZ_Clear (&net_message);
+ MSG_WriteByte (&net_message, svc_disconnect);
+ CL_WriteDemoMessage ();
+
+// finish up
+ fclose (cls.demofile);
+ cls.demofile = NULL;
+ cls.demorecording = false;
+ Con_Printf ("Completed demo\n");
+}
+
+/*
+====================
+CL_Record_f
+
+record <demoname> <map> [cd track]
+====================
+*/
+void CL_Record_f (void)
+{
+ int c;
+ char name[MAX_OSPATH];
+ int track;
+
+ if (cmd_source != src_command)
+ return;
+
+ c = Cmd_Argc();
+ if (c != 2 && c != 3 && c != 4)
+ {
+ Con_Printf ("record <demoname> [<map> [cd track]]\n");
+ return;
+ }
+
+ if (strstr(Cmd_Argv(1), ".."))
+ {
+ Con_Printf ("Relative pathnames are not allowed.\n");
+ return;
+ }
+
+ if (c == 2 && cls.state == ca_connected)
+ {
+ Con_Printf("Can not record - already connected to server\nClient demo recording must be started before connecting\n");
+ return;
+ }
+
+// write the forced cd track number, or -1
+ if (c == 4)
+ {
+ track = atoi(Cmd_Argv(3));
+ Con_Printf ("Forcing CD track to %i\n", cls.forcetrack);
+ }
+ else
+ track = -1;
+
+ sprintf (name, "%s/%s", com_gamedir, Cmd_Argv(1));
+
+//
+// start the map up
+//
+ if (c > 2)
+ Cmd_ExecuteString ( va("map %s", Cmd_Argv(2)), src_command);
+
+//
+// open the demo file
+//
+ COM_DefaultExtension (name, ".dem");
+
+ Con_Printf ("recording to %s.\n", name);
+ cls.demofile = fopen (name, "wb");
+ if (!cls.demofile)
+ {
+ Con_Printf ("ERROR: couldn't open.\n");
+ return;
+ }
+
+ cls.forcetrack = track;
+ fprintf (cls.demofile, "%i\n", cls.forcetrack);
+
+ cls.demorecording = true;
+}
+
+
+/*
+====================
+CL_PlayDemo_f
+
+play [demoname]
+====================
+*/
+void CL_PlayDemo_f (void)
+{
+ char name[256];
+ int c;
+ qboolean neg = false;
+
+ if (cmd_source != src_command)
+ return;
+
+ if (Cmd_Argc() != 2)
+ {
+ Con_Printf ("play <demoname> : plays a demo\n");
+ return;
+ }
+
+//
+// disconnect from server
+//
+ CL_Disconnect ();
+
+//
+// open the demo file
+//
+ strcpy (name, Cmd_Argv(1));
+ COM_DefaultExtension (name, ".dem");
+
+ Con_Printf ("Playing demo from %s.\n", name);
+ COM_FOpenFile (name, &cls.demofile);
+ if (!cls.demofile)
+ {
+ Con_Printf ("ERROR: couldn't open.\n");
+ cls.demonum = -1; // stop demo loop
+ return;
+ }
+
+ cls.demoplayback = true;
+ cls.state = ca_connected;
+ cls.forcetrack = 0;
+
+ while ((c = getc(cls.demofile)) != '\n')
+ if (c == '-')
+ neg = true;
+ else
+ cls.forcetrack = cls.forcetrack * 10 + (c - '0');
+
+ if (neg)
+ cls.forcetrack = -cls.forcetrack;
+// ZOID, fscanf is evil
+ //fscanf (cls.demofile, "%i\n", &cls.forcetrack);
+}
+
+/*
+====================
+CL_FinishTimeDemo
+
+====================
+*/
+void CL_FinishTimeDemo (void)
+{
+ int frames;
+ float time;
+
+ cls.timedemo = false;
+
+// the first frame didn't count
+ frames = (host_framecount - cls.td_startframe) - 1;
+ time = realtime - cls.td_starttime;
+ if (!time)
+ time = 1;
+ Con_Printf ("%i frames %5.1f seconds %5.1f fps\n", frames, time, frames/time);
+}
+
+/*
+====================
+CL_TimeDemo_f
+
+timedemo [demoname]
+====================
+*/
+void CL_TimeDemo_f (void)
+{
+ if (cmd_source != src_command)
+ return;
+
+ if (Cmd_Argc() != 2)
+ {
+ Con_Printf ("timedemo <demoname> : gets demo speeds\n");
+ return;
+ }
+
+ CL_PlayDemo_f ();
+
+// cls.td_starttime will be grabbed at the second frame of the demo, so
+// all the loading time doesn't get counted
+
+ cls.timedemo = true;
+ cls.td_startframe = host_framecount;
+ cls.td_lastframe = -1; // get a new message this frame
+}
+
diff --git a/apps/plugins/sdl/progs/quake/cl_input.c b/apps/plugins/sdl/progs/quake/cl_input.c
new file mode 100644
index 0000000000..5327b7363e
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/cl_input.c
@@ -0,0 +1,448 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// cl.input.c -- builds an intended movement command to send to the server
+
+// Quake is a trademark of Id Software, Inc., (c) 1996 Id Software, Inc. All
+// rights reserved.
+
+#include "quakedef.h"
+
+/*
+===============================================================================
+
+KEY BUTTONS
+
+Continuous button event tracking is complicated by the fact that two different
+input sources (say, mouse button 1 and the control key) can both press the
+same button, but the button should only be released when both of the
+pressing key have been released.
+
+When a key event issues a button command (+forward, +attack, etc), it appends
+its key number as a parameter to the command so it can be matched up with
+the release.
+
+state bit 0 is the current state of the key
+state bit 1 is edge triggered on the up to down transition
+state bit 2 is edge triggered on the down to up transition
+
+===============================================================================
+*/
+
+
+kbutton_t in_mlook, in_klook;
+kbutton_t in_left, in_right, in_forward, in_back;
+kbutton_t in_lookup, in_lookdown, in_moveleft, in_moveright;
+kbutton_t in_strafe, in_speed, in_use, in_jump, in_attack;
+kbutton_t in_up, in_down;
+
+int in_impulse;
+
+
+void KeyDown (kbutton_t *b)
+{
+ int k;
+ char *c;
+
+ c = Cmd_Argv(1);
+ if (c[0])
+ k = atoi(c);
+ else
+ k = -1; // typed manually at the console for continuous down
+
+ if (k == b->down[0] || k == b->down[1])
+ return; // repeating key
+
+ if (!b->down[0])
+ b->down[0] = k;
+ else if (!b->down[1])
+ b->down[1] = k;
+ else
+ {
+ Con_Printf ("Three keys down for a button!\n");
+ return;
+ }
+
+ if (b->state & 1)
+ return; // still down
+ b->state |= 1 + 2; // down + impulse down
+}
+
+void KeyUp (kbutton_t *b)
+{
+ int k;
+ char *c;
+
+ c = Cmd_Argv(1);
+ if (c[0])
+ k = atoi(c);
+ else
+ { // typed manually at the console, assume for unsticking, so clear all
+ b->down[0] = b->down[1] = 0;
+ b->state = 4; // impulse up
+ return;
+ }
+
+ if (b->down[0] == k)
+ b->down[0] = 0;
+ else if (b->down[1] == k)
+ b->down[1] = 0;
+ else
+ return; // key up without coresponding down (menu pass through)
+ if (b->down[0] || b->down[1])
+ return; // some other key is still holding it down
+
+ if (!(b->state & 1))
+ return; // still up (this should not happen)
+ b->state &= ~1; // now up
+ b->state |= 4; // impulse up
+}
+
+void IN_KLookDown (void) {KeyDown(&in_klook);}
+void IN_KLookUp (void) {KeyUp(&in_klook);}
+void IN_MLookDown (void) {KeyDown(&in_mlook);}
+void IN_MLookUp (void) {
+KeyUp(&in_mlook);
+if ( !(in_mlook.state&1) && lookspring.value)
+ V_StartPitchDrift();
+}
+void IN_UpDown(void) {KeyDown(&in_up);}
+void IN_UpUp(void) {KeyUp(&in_up);}
+void IN_DownDown(void) {KeyDown(&in_down);}
+void IN_DownUp(void) {KeyUp(&in_down);}
+void IN_LeftDown(void) {KeyDown(&in_left);}
+void IN_LeftUp(void) {KeyUp(&in_left);}
+void IN_RightDown(void) {KeyDown(&in_right);}
+void IN_RightUp(void) {KeyUp(&in_right);}
+void IN_ForwardDown(void) {KeyDown(&in_forward);}
+void IN_ForwardUp(void) {KeyUp(&in_forward);}
+void IN_BackDown(void) {KeyDown(&in_back);}
+void IN_BackUp(void) {KeyUp(&in_back);}
+void IN_LookupDown(void) {KeyDown(&in_lookup);}
+void IN_LookupUp(void) {KeyUp(&in_lookup);}
+void IN_LookdownDown(void) {KeyDown(&in_lookdown);}
+void IN_LookdownUp(void) {KeyUp(&in_lookdown);}
+void IN_MoveleftDown(void) {KeyDown(&in_moveleft);}
+void IN_MoveleftUp(void) {KeyUp(&in_moveleft);}
+void IN_MoverightDown(void) {KeyDown(&in_moveright);}
+void IN_MoverightUp(void) {KeyUp(&in_moveright);}
+
+void IN_SpeedDown(void) {KeyDown(&in_speed);}
+void IN_SpeedUp(void) {KeyUp(&in_speed);}
+void IN_StrafeDown(void) {KeyDown(&in_strafe);}
+void IN_StrafeUp(void) {KeyUp(&in_strafe);}
+
+void IN_AttackDown(void) {KeyDown(&in_attack);}
+void IN_AttackUp(void) {KeyUp(&in_attack);}
+
+void IN_UseDown (void) {KeyDown(&in_use);}
+void IN_UseUp (void) {KeyUp(&in_use);}
+void IN_JumpDown (void) {KeyDown(&in_jump);}
+void IN_JumpUp (void) {KeyUp(&in_jump);}
+
+void IN_Impulse (void) {in_impulse=Q_atoi(Cmd_Argv(1));}
+
+/*
+===============
+CL_KeyState
+
+Returns 0.25 if a key was pressed and released during the frame,
+0.5 if it was pressed and held
+0 if held then released, and
+1.0 if held for the entire time
+===============
+*/
+float CL_KeyState (kbutton_t *key)
+{
+ float val;
+ qboolean impulsedown, impulseup, down;
+
+ impulsedown = key->state & 2;
+ impulseup = key->state & 4;
+ down = key->state & 1;
+ val = 0;
+
+ if (impulsedown && !impulseup)
+ if (down)
+ val = 0.5; // pressed and held this frame
+ else
+ val = 0; // I_Error ();
+ if (impulseup && !impulsedown)
+ if (down)
+ val = 0; // I_Error ();
+ else
+ val = 0; // released this frame
+ if (!impulsedown && !impulseup)
+ if (down)
+ val = 1.0; // held the entire frame
+ else
+ val = 0; // up the entire frame
+ if (impulsedown && impulseup)
+ if (down)
+ val = 0.75; // released and re-pressed this frame
+ else
+ val = 0.25; // pressed and released this frame
+
+ key->state &= 1; // clear impulses
+
+ return val;
+}
+
+
+
+
+//==========================================================================
+
+cvar_t cl_upspeed = {"cl_upspeed","200"};
+cvar_t cl_forwardspeed = {"cl_forwardspeed","200", true};
+cvar_t cl_backspeed = {"cl_backspeed","200", true};
+cvar_t cl_sidespeed = {"cl_sidespeed","350"};
+
+cvar_t cl_movespeedkey = {"cl_movespeedkey","2.0"};
+
+cvar_t cl_yawspeed = {"cl_yawspeed","140"};
+cvar_t cl_pitchspeed = {"cl_pitchspeed","150"};
+
+cvar_t cl_anglespeedkey = {"cl_anglespeedkey","1.5"};
+
+
+/*
+================
+CL_AdjustAngles
+
+Moves the local angle positions
+================
+*/
+void CL_AdjustAngles (void)
+{
+ float speed;
+ float up, down;
+
+ if (in_speed.state & 1)
+ speed = host_frametime * cl_anglespeedkey.value;
+ else
+ speed = host_frametime;
+
+ if (!(in_strafe.state & 1))
+ {
+ cl.viewangles[YAW] -= speed*cl_yawspeed.value*CL_KeyState (&in_right);
+ cl.viewangles[YAW] += speed*cl_yawspeed.value*CL_KeyState (&in_left);
+ cl.viewangles[YAW] = anglemod(cl.viewangles[YAW]);
+ }
+ if (in_klook.state & 1)
+ {
+ V_StopPitchDrift ();
+ cl.viewangles[PITCH] -= speed*cl_pitchspeed.value * CL_KeyState (&in_forward);
+ cl.viewangles[PITCH] += speed*cl_pitchspeed.value * CL_KeyState (&in_back);
+ }
+
+ up = CL_KeyState (&in_lookup);
+ down = CL_KeyState(&in_lookdown);
+
+ cl.viewangles[PITCH] -= speed*cl_pitchspeed.value * up;
+ cl.viewangles[PITCH] += speed*cl_pitchspeed.value * down;
+
+ if (up || down)
+ V_StopPitchDrift ();
+
+ if (cl.viewangles[PITCH] > 80)
+ cl.viewangles[PITCH] = 80;
+ if (cl.viewangles[PITCH] < -70)
+ cl.viewangles[PITCH] = -70;
+
+ if (cl.viewangles[ROLL] > 50)
+ cl.viewangles[ROLL] = 50;
+ if (cl.viewangles[ROLL] < -50)
+ cl.viewangles[ROLL] = -50;
+
+}
+
+/*
+================
+CL_BaseMove
+
+Send the intended movement message to the server
+================
+*/
+void CL_BaseMove (usercmd_t *cmd)
+{
+ if (cls.signon != SIGNONS)
+ return;
+
+ CL_AdjustAngles ();
+
+ Q_memset (cmd, 0, sizeof(*cmd));
+
+ if (in_strafe.state & 1)
+ {
+ cmd->sidemove += cl_sidespeed.value * CL_KeyState (&in_right);
+ cmd->sidemove -= cl_sidespeed.value * CL_KeyState (&in_left);
+ }
+
+ cmd->sidemove += cl_sidespeed.value * CL_KeyState (&in_moveright);
+ cmd->sidemove -= cl_sidespeed.value * CL_KeyState (&in_moveleft);
+
+ cmd->upmove += cl_upspeed.value * CL_KeyState (&in_up);
+ cmd->upmove -= cl_upspeed.value * CL_KeyState (&in_down);
+
+ if (! (in_klook.state & 1) )
+ {
+ cmd->forwardmove += cl_forwardspeed.value * CL_KeyState (&in_forward);
+ cmd->forwardmove -= cl_backspeed.value * CL_KeyState (&in_back);
+ }
+
+//
+// adjust for speed key
+//
+ if (in_speed.state & 1)
+ {
+ cmd->forwardmove *= cl_movespeedkey.value;
+ cmd->sidemove *= cl_movespeedkey.value;
+ cmd->upmove *= cl_movespeedkey.value;
+ }
+
+#ifdef QUAKE2
+ cmd->lightlevel = cl.light_level;
+#endif
+}
+
+
+
+/*
+==============
+CL_SendMove
+==============
+*/
+void CL_SendMove (usercmd_t *cmd)
+{
+ int i;
+ int bits;
+ sizebuf_t buf;
+ byte data[128];
+
+ buf.maxsize = 128;
+ buf.cursize = 0;
+ buf.data = data;
+
+ cl.cmd = *cmd;
+
+//
+// send the movement message
+//
+ MSG_WriteByte (&buf, clc_move);
+
+ MSG_WriteFloat (&buf, cl.mtime[0]); // so server can get ping times
+
+ for (i=0 ; i<3 ; i++)
+ MSG_WriteAngle (&buf, cl.viewangles[i]);
+
+ MSG_WriteShort (&buf, cmd->forwardmove);
+ MSG_WriteShort (&buf, cmd->sidemove);
+ MSG_WriteShort (&buf, cmd->upmove);
+
+//
+// send button bits
+//
+ bits = 0;
+
+ if ( in_attack.state & 3 )
+ bits |= 1;
+ in_attack.state &= ~2;
+
+ if (in_jump.state & 3)
+ bits |= 2;
+ in_jump.state &= ~2;
+
+ MSG_WriteByte (&buf, bits);
+
+ MSG_WriteByte (&buf, in_impulse);
+ in_impulse = 0;
+
+#ifdef QUAKE2
+//
+// light level
+//
+ MSG_WriteByte (&buf, cmd->lightlevel);
+#endif
+
+//
+// deliver the message
+//
+ if (cls.demoplayback)
+ return;
+
+//
+// allways dump the first two message, because it may contain leftover inputs
+// from the last level
+//
+ if (++cl.movemessages <= 2)
+ return;
+
+ if (NET_SendUnreliableMessage (cls.netcon, &buf) == -1)
+ {
+ Con_Printf ("CL_SendMove: lost server connection\n");
+ CL_Disconnect ();
+ }
+}
+
+/*
+============
+CL_InitInput
+============
+*/
+void CL_InitInput (void)
+{
+ Cmd_AddCommand ("+moveup",IN_UpDown);
+ Cmd_AddCommand ("-moveup",IN_UpUp);
+ Cmd_AddCommand ("+movedown",IN_DownDown);
+ Cmd_AddCommand ("-movedown",IN_DownUp);
+ Cmd_AddCommand ("+left",IN_LeftDown);
+ Cmd_AddCommand ("-left",IN_LeftUp);
+ Cmd_AddCommand ("+right",IN_RightDown);
+ Cmd_AddCommand ("-right",IN_RightUp);
+ Cmd_AddCommand ("+forward",IN_ForwardDown);
+ Cmd_AddCommand ("-forward",IN_ForwardUp);
+ Cmd_AddCommand ("+back",IN_BackDown);
+ Cmd_AddCommand ("-back",IN_BackUp);
+ Cmd_AddCommand ("+lookup", IN_LookupDown);
+ Cmd_AddCommand ("-lookup", IN_LookupUp);
+ Cmd_AddCommand ("+lookdown", IN_LookdownDown);
+ Cmd_AddCommand ("-lookdown", IN_LookdownUp);
+ Cmd_AddCommand ("+strafe", IN_StrafeDown);
+ Cmd_AddCommand ("-strafe", IN_StrafeUp);
+ Cmd_AddCommand ("+moveleft", IN_MoveleftDown);
+ Cmd_AddCommand ("-moveleft", IN_MoveleftUp);
+ Cmd_AddCommand ("+moveright", IN_MoverightDown);
+ Cmd_AddCommand ("-moveright", IN_MoverightUp);
+ Cmd_AddCommand ("+speed", IN_SpeedDown);
+ Cmd_AddCommand ("-speed", IN_SpeedUp);
+ Cmd_AddCommand ("+attack", IN_AttackDown);
+ Cmd_AddCommand ("-attack", IN_AttackUp);
+ Cmd_AddCommand ("+use", IN_UseDown);
+ Cmd_AddCommand ("-use", IN_UseUp);
+ Cmd_AddCommand ("+jump", IN_JumpDown);
+ Cmd_AddCommand ("-jump", IN_JumpUp);
+ Cmd_AddCommand ("impulse", IN_Impulse);
+ Cmd_AddCommand ("+klook", IN_KLookDown);
+ Cmd_AddCommand ("-klook", IN_KLookUp);
+ Cmd_AddCommand ("+mlook", IN_MLookDown);
+ Cmd_AddCommand ("-mlook", IN_MLookUp);
+
+}
+
diff --git a/apps/plugins/sdl/progs/quake/cl_main.c b/apps/plugins/sdl/progs/quake/cl_main.c
new file mode 100644
index 0000000000..58121434bc
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/cl_main.c
@@ -0,0 +1,757 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// cl_main.c -- client main loop
+
+#include "quakedef.h"
+
+// we need to declare some mouse variables here, because the menu system
+// references them even when on a unix system.
+
+// these two are not intended to be set directly
+cvar_t cl_name = {"_cl_name", "player", true};
+cvar_t cl_color = {"_cl_color", "0", true};
+
+cvar_t cl_shownet = {"cl_shownet","0"}; // can be 0, 1, or 2
+cvar_t cl_nolerp = {"cl_nolerp","0"};
+
+cvar_t lookspring = {"lookspring","0", true};
+cvar_t lookstrafe = {"lookstrafe","0", true};
+cvar_t sensitivity = {"sensitivity","3", true};
+
+cvar_t m_pitch = {"m_pitch","0.022", true};
+cvar_t m_yaw = {"m_yaw","0.022", true};
+cvar_t m_forward = {"m_forward","1", true};
+cvar_t m_side = {"m_side","0.8", true};
+
+
+client_static_t cls;
+client_state_t cl;
+// FIXME: put these on hunk?
+efrag_t cl_efrags[MAX_EFRAGS];
+entity_t cl_entities[MAX_EDICTS];
+entity_t cl_static_entities[MAX_STATIC_ENTITIES];
+lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES];
+dlight_t cl_dlights[MAX_DLIGHTS];
+
+int cl_numvisedicts;
+entity_t *cl_visedicts[MAX_VISEDICTS];
+
+/*
+=====================
+CL_ClearState
+
+=====================
+*/
+void CL_ClearState (void)
+{
+ int i;
+
+ if (!sv.active)
+ Host_ClearMemory ();
+
+// wipe the entire cl structure
+ memset (&cl, 0, sizeof(cl));
+
+ SZ_Clear (&cls.message);
+
+// clear other arrays
+ memset (cl_efrags, 0, sizeof(cl_efrags));
+ memset (cl_entities, 0, sizeof(cl_entities));
+ memset (cl_dlights, 0, sizeof(cl_dlights));
+ memset (cl_lightstyle, 0, sizeof(cl_lightstyle));
+ memset (cl_temp_entities, 0, sizeof(cl_temp_entities));
+ memset (cl_beams, 0, sizeof(cl_beams));
+
+//
+// allocate the efrags and chain together into a free list
+//
+ cl.free_efrags = cl_efrags;
+ for (i=0 ; i<MAX_EFRAGS-1 ; i++)
+ cl.free_efrags[i].entnext = &cl.free_efrags[i+1];
+ cl.free_efrags[i].entnext = NULL;
+}
+
+/*
+=====================
+CL_Disconnect
+
+Sends a disconnect message to the server
+This is also called on Host_Error, so it shouldn't cause any errors
+=====================
+*/
+void CL_Disconnect (void)
+{
+// stop sounds (especially looping!)
+ S_StopAllSounds (true);
+
+// bring the console down and fade the colors back to normal
+// SCR_BringDownConsole ();
+
+// if running a local server, shut it down
+ if (cls.demoplayback)
+ CL_StopPlayback ();
+ else if (cls.state == ca_connected)
+ {
+ if (cls.demorecording)
+ CL_Stop_f ();
+
+ Con_DPrintf ("Sending clc_disconnect\n");
+ SZ_Clear (&cls.message);
+ MSG_WriteByte (&cls.message, clc_disconnect);
+ NET_SendUnreliableMessage (cls.netcon, &cls.message);
+ SZ_Clear (&cls.message);
+ NET_Close (cls.netcon);
+
+ cls.state = ca_disconnected;
+ if (sv.active)
+ Host_ShutdownServer(false);
+ }
+
+ cls.demoplayback = cls.timedemo = false;
+ cls.signon = 0;
+}
+
+void CL_Disconnect_f (void)
+{
+ CL_Disconnect ();
+ if (sv.active)
+ Host_ShutdownServer (false);
+}
+
+
+
+
+/*
+=====================
+CL_EstablishConnection
+
+Host should be either "local" or a net address to be passed on
+=====================
+*/
+void CL_EstablishConnection (char *host)
+{
+ if (cls.state == ca_dedicated)
+ return;
+
+ if (cls.demoplayback)
+ return;
+
+ CL_Disconnect ();
+
+ cls.netcon = NET_Connect (host);
+ if (!cls.netcon)
+ Host_Error ("CL_Connect: connect failed\n");
+ Con_DPrintf ("CL_EstablishConnection: connected to %s\n", host);
+
+ cls.demonum = -1; // not in the demo loop now
+ cls.state = ca_connected;
+ cls.signon = 0; // need all the signon messages before playing
+}
+
+/*
+=====================
+CL_SignonReply
+
+An svc_signonnum has been received, perform a client side setup
+=====================
+*/
+void CL_SignonReply (void)
+{
+ char str[8192];
+
+Con_DPrintf ("CL_SignonReply: %i\n", cls.signon);
+
+ switch (cls.signon)
+ {
+ case 1:
+ MSG_WriteByte (&cls.message, clc_stringcmd);
+ MSG_WriteString (&cls.message, "prespawn");
+ break;
+
+ case 2:
+ MSG_WriteByte (&cls.message, clc_stringcmd);
+ MSG_WriteString (&cls.message, va("name \"%s\"\n", cl_name.string));
+
+ MSG_WriteByte (&cls.message, clc_stringcmd);
+ MSG_WriteString (&cls.message, va("color %i %i\n", ((int)cl_color.value)>>4, ((int)cl_color.value)&15));
+
+ MSG_WriteByte (&cls.message, clc_stringcmd);
+ sprintf (str, "spawn %s", cls.spawnparms);
+ MSG_WriteString (&cls.message, str);
+ break;
+
+ case 3:
+ MSG_WriteByte (&cls.message, clc_stringcmd);
+ MSG_WriteString (&cls.message, "begin");
+ Cache_Report (); // print remaining memory
+ break;
+
+ case 4:
+ SCR_EndLoadingPlaque (); // allow normal screen updates
+ break;
+ }
+}
+
+/*
+=====================
+CL_NextDemo
+
+Called to play the next demo in the demo loop
+=====================
+*/
+void CL_NextDemo (void)
+{
+ char str[1024];
+
+ if (cls.demonum == -1)
+ return; // don't play demos
+
+ SCR_BeginLoadingPlaque ();
+
+ if (!cls.demos[cls.demonum][0] || cls.demonum == MAX_DEMOS)
+ {
+ cls.demonum = 0;
+ if (!cls.demos[cls.demonum][0])
+ {
+ Con_Printf ("No demos listed with startdemos\n");
+ cls.demonum = -1;
+ return;
+ }
+ }
+
+ sprintf (str,"playdemo %s\n", cls.demos[cls.demonum]);
+ Cbuf_InsertText (str);
+ cls.demonum++;
+}
+
+/*
+==============
+CL_PrintEntities_f
+==============
+*/
+void CL_PrintEntities_f (void)
+{
+ entity_t *ent;
+ int i;
+
+ for (i=0,ent=cl_entities ; i<cl.num_entities ; i++,ent++)
+ {
+ Con_Printf ("%3i:",i);
+ if (!ent->model)
+ {
+ Con_Printf ("EMPTY\n");
+ continue;
+ }
+ Con_Printf ("%s:%2i (%5.1f,%5.1f,%5.1f) [%5.1f %5.1f %5.1f]\n"
+ ,ent->model->name,ent->frame, ent->origin[0], ent->origin[1], ent->origin[2], ent->angles[0], ent->angles[1], ent->angles[2]);
+ }
+}
+
+
+/*
+===============
+SetPal
+
+Debugging tool, just flashes the screen
+===============
+*/
+void SetPal (int i)
+{
+#if 0
+ static int old;
+ byte pal[768];
+ int c;
+
+ if (i == old)
+ return;
+ old = i;
+
+ if (i==0)
+ VID_SetPalette (host_basepal);
+ else if (i==1)
+ {
+ for (c=0 ; c<768 ; c+=3)
+ {
+ pal[c] = 0;
+ pal[c+1] = 255;
+ pal[c+2] = 0;
+ }
+ VID_SetPalette (pal);
+ }
+ else
+ {
+ for (c=0 ; c<768 ; c+=3)
+ {
+ pal[c] = 0;
+ pal[c+1] = 0;
+ pal[c+2] = 255;
+ }
+ VID_SetPalette (pal);
+ }
+#endif
+}
+
+/*
+===============
+CL_AllocDlight
+
+===============
+*/
+dlight_t *CL_AllocDlight (int key)
+{
+ int i;
+ dlight_t *dl;
+
+// first look for an exact key match
+ if (key)
+ {
+ dl = cl_dlights;
+ for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
+ {
+ if (dl->key == key)
+ {
+ memset (dl, 0, sizeof(*dl));
+ dl->key = key;
+ return dl;
+ }
+ }
+ }
+
+// then look for anything else
+ dl = cl_dlights;
+ for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
+ {
+ if (dl->die < cl.time)
+ {
+ memset (dl, 0, sizeof(*dl));
+ dl->key = key;
+ return dl;
+ }
+ }
+
+ dl = &cl_dlights[0];
+ memset (dl, 0, sizeof(*dl));
+ dl->key = key;
+ return dl;
+}
+
+
+/*
+===============
+CL_DecayLights
+
+===============
+*/
+void CL_DecayLights (void)
+{
+ int i;
+ dlight_t *dl;
+ float time;
+
+ time = cl.time - cl.oldtime;
+
+ dl = cl_dlights;
+ for (i=0 ; i<MAX_DLIGHTS ; i++, dl++)
+ {
+ if (dl->die < cl.time || !dl->radius)
+ continue;
+
+ dl->radius -= time*dl->decay;
+ if (dl->radius < 0)
+ dl->radius = 0;
+ }
+}
+
+
+/*
+===============
+CL_LerpPoint
+
+Determines the fraction between the last two messages that the objects
+should be put at.
+===============
+*/
+float CL_LerpPoint (void)
+{
+ float f, frac;
+
+ f = cl.mtime[0] - cl.mtime[1];
+
+ if (!f || cl_nolerp.value || cls.timedemo || sv.active)
+ {
+ cl.time = cl.mtime[0];
+ return 1;
+ }
+
+ if (f > 0.1)
+ { // dropped packet, or start of demo
+ cl.mtime[1] = cl.mtime[0] - 0.1;
+ f = 0.1;
+ }
+ frac = (cl.time - cl.mtime[1]) / f;
+//Con_Printf ("frac: %f\n",frac);
+ if (frac < 0)
+ {
+ if (frac < -0.01)
+ {
+SetPal(1);
+ cl.time = cl.mtime[1];
+// Con_Printf ("low frac\n");
+ }
+ frac = 0;
+ }
+ else if (frac > 1)
+ {
+ if (frac > 1.01)
+ {
+SetPal(2);
+ cl.time = cl.mtime[0];
+// Con_Printf ("high frac\n");
+ }
+ frac = 1;
+ }
+ else
+ SetPal(0);
+
+ return frac;
+}
+
+
+/*
+===============
+CL_RelinkEntities
+===============
+*/
+void CL_RelinkEntities (void)
+{
+ entity_t *ent;
+ int i, j;
+ float frac, f, d;
+ vec3_t delta;
+ float bobjrotate;
+ vec3_t oldorg;
+ dlight_t *dl;
+
+// determine partial update time
+ frac = CL_LerpPoint ();
+
+ cl_numvisedicts = 0;
+
+//
+// interpolate player info
+//
+ for (i=0 ; i<3 ; i++)
+ cl.velocity[i] = cl.mvelocity[1][i] +
+ frac * (cl.mvelocity[0][i] - cl.mvelocity[1][i]);
+
+ if (cls.demoplayback)
+ {
+ // interpolate the angles
+ for (j=0 ; j<3 ; j++)
+ {
+ d = cl.mviewangles[0][j] - cl.mviewangles[1][j];
+ if (d > 180)
+ d -= 360;
+ else if (d < -180)
+ d += 360;
+ cl.viewangles[j] = cl.mviewangles[1][j] + frac*d;
+ }
+ }
+
+ bobjrotate = anglemod(100*cl.time);
+
+// start on the entity after the world
+ for (i=1,ent=cl_entities+1 ; i<cl.num_entities ; i++,ent++)
+ {
+ if (!ent->model)
+ { // empty slot
+ if (ent->forcelink)
+ R_RemoveEfrags (ent); // just became empty
+ continue;
+ }
+
+// if the object wasn't included in the last packet, remove it
+ if (ent->msgtime != cl.mtime[0])
+ {
+ ent->model = NULL;
+ continue;
+ }
+
+ VectorCopy (ent->origin, oldorg);
+
+ if (ent->forcelink)
+ { // the entity was not updated in the last message
+ // so move to the final spot
+ VectorCopy (ent->msg_origins[0], ent->origin);
+ VectorCopy (ent->msg_angles[0], ent->angles);
+ }
+ else
+ { // if the delta is large, assume a teleport and don't lerp
+ f = frac;
+ for (j=0 ; j<3 ; j++)
+ {
+ delta[j] = ent->msg_origins[0][j] - ent->msg_origins[1][j];
+ if (delta[j] > 100 || delta[j] < -100)
+ f = 1; // assume a teleportation, not a motion
+ }
+
+ // interpolate the origin and angles
+ for (j=0 ; j<3 ; j++)
+ {
+ ent->origin[j] = ent->msg_origins[1][j] + f*delta[j];
+
+ d = ent->msg_angles[0][j] - ent->msg_angles[1][j];
+ if (d > 180)
+ d -= 360;
+ else if (d < -180)
+ d += 360;
+ ent->angles[j] = ent->msg_angles[1][j] + f*d;
+ }
+
+ }
+
+// rotate binary objects locally
+ if (ent->model->flags & EF_ROTATE)
+ ent->angles[1] = bobjrotate;
+
+ if (ent->effects & EF_BRIGHTFIELD)
+ R_EntityParticles (ent);
+#ifdef QUAKE2
+ if (ent->effects & EF_DARKFIELD)
+ R_DarkFieldParticles (ent);
+#endif
+ if (ent->effects & EF_MUZZLEFLASH)
+ {
+ vec3_t fv, rv, uv;
+
+ dl = CL_AllocDlight (i);
+ VectorCopy (ent->origin, dl->origin);
+ dl->origin[2] += 16;
+ AngleVectors (ent->angles, fv, rv, uv);
+
+ VectorMA (dl->origin, 18, fv, dl->origin);
+ dl->radius = 200 + (rand()&31);
+ dl->minlight = 32;
+ dl->die = cl.time + 0.1;
+ }
+ if (ent->effects & EF_BRIGHTLIGHT)
+ {
+ dl = CL_AllocDlight (i);
+ VectorCopy (ent->origin, dl->origin);
+ dl->origin[2] += 16;
+ dl->radius = 400 + (rand()&31);
+ dl->die = cl.time + 0.001;
+ }
+ if (ent->effects & EF_DIMLIGHT)
+ {
+ dl = CL_AllocDlight (i);
+ VectorCopy (ent->origin, dl->origin);
+ dl->radius = 200 + (rand()&31);
+ dl->die = cl.time + 0.001;
+ }
+#ifdef QUAKE2
+ if (ent->effects & EF_DARKLIGHT)
+ {
+ dl = CL_AllocDlight (i);
+ VectorCopy (ent->origin, dl->origin);
+ dl->radius = 200.0 + (rand()&31);
+ dl->die = cl.time + 0.001;
+ dl->dark = true;
+ }
+ if (ent->effects & EF_LIGHT)
+ {
+ dl = CL_AllocDlight (i);
+ VectorCopy (ent->origin, dl->origin);
+ dl->radius = 200;
+ dl->die = cl.time + 0.001;
+ }
+#endif
+
+ if (ent->model->flags & EF_GIB)
+ R_RocketTrail (oldorg, ent->origin, 2);
+ else if (ent->model->flags & EF_ZOMGIB)
+ R_RocketTrail (oldorg, ent->origin, 4);
+ else if (ent->model->flags & EF_TRACER)
+ R_RocketTrail (oldorg, ent->origin, 3);
+ else if (ent->model->flags & EF_TRACER2)
+ R_RocketTrail (oldorg, ent->origin, 5);
+ else if (ent->model->flags & EF_ROCKET)
+ {
+ R_RocketTrail (oldorg, ent->origin, 0);
+ dl = CL_AllocDlight (i);
+ VectorCopy (ent->origin, dl->origin);
+ dl->radius = 200;
+ dl->die = cl.time + 0.01;
+ }
+ else if (ent->model->flags & EF_GRENADE)
+ R_RocketTrail (oldorg, ent->origin, 1);
+ else if (ent->model->flags & EF_TRACER3)
+ R_RocketTrail (oldorg, ent->origin, 6);
+
+ ent->forcelink = false;
+
+ if (i == cl.viewentity && !chase_active.value)
+ continue;
+
+#ifdef QUAKE2
+ if ( ent->effects & EF_NODRAW )
+ continue;
+#endif
+ if (cl_numvisedicts < MAX_VISEDICTS)
+ {
+ cl_visedicts[cl_numvisedicts] = ent;
+ cl_numvisedicts++;
+ }
+ }
+
+}
+
+
+/*
+===============
+CL_ReadFromServer
+
+Read all incoming data from the server
+===============
+*/
+int CL_ReadFromServer (void)
+{
+ int ret;
+
+ cl.oldtime = cl.time;
+ cl.time += host_frametime;
+
+ do
+ {
+ ret = CL_GetMessage ();
+ if (ret == -1)
+ Host_Error ("CL_ReadFromServer: lost server connection");
+ if (!ret)
+ break;
+
+ cl.last_received_message = realtime;
+ CL_ParseServerMessage ();
+ } while (ret && cls.state == ca_connected);
+
+ if (cl_shownet.value)
+ Con_Printf ("\n");
+
+ CL_RelinkEntities ();
+ CL_UpdateTEnts ();
+
+//
+// bring the links up to date
+//
+ return 0;
+}
+
+/*
+=================
+CL_SendCmd
+=================
+*/
+void CL_SendCmd (void)
+{
+ usercmd_t cmd;
+
+ if (cls.state != ca_connected)
+ return;
+
+ if (cls.signon == SIGNONS)
+ {
+ // get basic movement from keyboard
+ CL_BaseMove (&cmd);
+
+ // allow mice or other external controllers to add to the move
+ IN_Move (&cmd);
+
+ // send the unreliable message
+ CL_SendMove (&cmd);
+
+ }
+
+ if (cls.demoplayback)
+ {
+ SZ_Clear (&cls.message);
+ return;
+ }
+
+// send the reliable message
+ if (!cls.message.cursize)
+ return; // no message at all
+
+ if (!NET_CanSendMessage (cls.netcon))
+ {
+ Con_DPrintf ("CL_WriteToServer: can't send\n");
+ return;
+ }
+
+ if (NET_SendMessage (cls.netcon, &cls.message) == -1)
+ Host_Error ("CL_WriteToServer: lost server connection");
+
+ SZ_Clear (&cls.message);
+}
+
+/*
+=================
+CL_Init
+=================
+*/
+void CL_Init (void)
+{
+ SZ_Alloc (&cls.message, 1024);
+
+ CL_InitInput ();
+ CL_InitTEnts ();
+
+//
+// register our commands
+//
+ Cvar_RegisterVariable (&cl_name);
+ Cvar_RegisterVariable (&cl_color);
+ Cvar_RegisterVariable (&cl_upspeed);
+ Cvar_RegisterVariable (&cl_forwardspeed);
+ Cvar_RegisterVariable (&cl_backspeed);
+ Cvar_RegisterVariable (&cl_sidespeed);
+ Cvar_RegisterVariable (&cl_movespeedkey);
+ Cvar_RegisterVariable (&cl_yawspeed);
+ Cvar_RegisterVariable (&cl_pitchspeed);
+ Cvar_RegisterVariable (&cl_anglespeedkey);
+ Cvar_RegisterVariable (&cl_shownet);
+ Cvar_RegisterVariable (&cl_nolerp);
+ Cvar_RegisterVariable (&lookspring);
+ Cvar_RegisterVariable (&lookstrafe);
+ Cvar_RegisterVariable (&sensitivity);
+
+ Cvar_RegisterVariable (&m_pitch);
+ Cvar_RegisterVariable (&m_yaw);
+ Cvar_RegisterVariable (&m_forward);
+ Cvar_RegisterVariable (&m_side);
+
+// Cvar_RegisterVariable (&cl_autofire);
+
+ Cmd_AddCommand ("entities", CL_PrintEntities_f);
+ Cmd_AddCommand ("disconnect", CL_Disconnect_f);
+ Cmd_AddCommand ("record", CL_Record_f);
+ Cmd_AddCommand ("stop", CL_Stop_f);
+ Cmd_AddCommand ("playdemo", CL_PlayDemo_f);
+ Cmd_AddCommand ("timedemo", CL_TimeDemo_f);
+}
+
diff --git a/apps/plugins/sdl/progs/quake/cl_parse.c b/apps/plugins/sdl/progs/quake/cl_parse.c
new file mode 100644
index 0000000000..c79ca47545
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/cl_parse.c
@@ -0,0 +1,963 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// cl_parse.c -- parse a message received from the server
+
+#include "quakedef.h"
+
+char *svc_strings[] =
+{
+ "svc_bad",
+ "svc_nop",
+ "svc_disconnect",
+ "svc_updatestat",
+ "svc_version", // [long] server version
+ "svc_setview", // [short] entity number
+ "svc_sound", // <see code>
+ "svc_time", // [float] server time
+ "svc_print", // [string] null terminated string
+ "svc_stufftext", // [string] stuffed into client's console buffer
+ // the string should be \n terminated
+ "svc_setangle", // [vec3] set the view angle to this absolute value
+
+ "svc_serverinfo", // [long] version
+ // [string] signon string
+ // [string]..[0]model cache [string]...[0]sounds cache
+ // [string]..[0]item cache
+ "svc_lightstyle", // [byte] [string]
+ "svc_updatename", // [byte] [string]
+ "svc_updatefrags", // [byte] [short]
+ "svc_clientdata", // <shortbits + data>
+ "svc_stopsound", // <see code>
+ "svc_updatecolors", // [byte] [byte]
+ "svc_particle", // [vec3] <variable>
+ "svc_damage", // [byte] impact [byte] blood [vec3] from
+
+ "svc_spawnstatic",
+ "OBSOLETE svc_spawnbinary",
+ "svc_spawnbaseline",
+
+ "svc_temp_entity", // <variable>
+ "svc_setpause",
+ "svc_signonnum",
+ "svc_centerprint",
+ "svc_killedmonster",
+ "svc_foundsecret",
+ "svc_spawnstaticsound",
+ "svc_intermission",
+ "svc_finale", // [string] music [string] text
+ "svc_cdtrack", // [byte] track [byte] looptrack
+ "svc_sellscreen",
+ "svc_cutscene"
+};
+
+//=============================================================================
+
+/*
+===============
+CL_EntityNum
+
+This error checks and tracks the total number of entities
+===============
+*/
+entity_t *CL_EntityNum (int num)
+{
+ if (num >= cl.num_entities)
+ {
+ if (num >= MAX_EDICTS)
+ Host_Error ("CL_EntityNum: %i is an invalid number",num);
+ while (cl.num_entities<=num)
+ {
+ cl_entities[cl.num_entities].colormap = vid.colormap;
+ cl.num_entities++;
+ }
+ }
+
+ return &cl_entities[num];
+}
+
+
+/*
+==================
+CL_ParseStartSoundPacket
+==================
+*/
+void CL_ParseStartSoundPacket(void)
+{
+ vec3_t pos;
+ int channel, ent;
+ int sound_num;
+ int volume;
+ int field_mask;
+ float attenuation;
+ int i;
+
+ field_mask = MSG_ReadByte();
+
+ if (field_mask & SND_VOLUME)
+ volume = MSG_ReadByte ();
+ else
+ volume = DEFAULT_SOUND_PACKET_VOLUME;
+
+ if (field_mask & SND_ATTENUATION)
+ attenuation = MSG_ReadByte () / 64.0;
+ else
+ attenuation = DEFAULT_SOUND_PACKET_ATTENUATION;
+
+ channel = MSG_ReadShort ();
+ sound_num = MSG_ReadByte ();
+
+ ent = channel >> 3;
+ channel &= 7;
+
+ if (ent > MAX_EDICTS)
+ Host_Error ("CL_ParseStartSoundPacket: ent = %i", ent);
+
+ for (i=0 ; i<3 ; i++)
+ pos[i] = MSG_ReadCoord ();
+
+ S_StartSound (ent, channel, cl.sound_precache[sound_num], pos, volume/255.0, attenuation);
+}
+
+/*
+==================
+CL_KeepaliveMessage
+
+When the client is taking a long time to load stuff, send keepalive messages
+so the server doesn't disconnect.
+==================
+*/
+void CL_KeepaliveMessage (void)
+{
+ float time;
+ static float lastmsg;
+ int ret;
+ sizebuf_t old;
+ byte olddata[8192];
+
+ if (sv.active)
+ return; // no need if server is local
+ if (cls.demoplayback)
+ return;
+
+// read messages from server, should just be nops
+ old = net_message;
+ memcpy (olddata, net_message.data, net_message.cursize);
+
+ do
+ {
+ ret = CL_GetMessage ();
+ switch (ret)
+ {
+ default:
+ Host_Error ("CL_KeepaliveMessage: CL_GetMessage failed");
+ case 0:
+ break; // nothing waiting
+ case 1:
+ Host_Error ("CL_KeepaliveMessage: received a message");
+ break;
+ case 2:
+ if (MSG_ReadByte() != svc_nop)
+ Host_Error ("CL_KeepaliveMessage: datagram wasn't a nop");
+ break;
+ }
+ } while (ret);
+
+ net_message = old;
+ memcpy (net_message.data, olddata, net_message.cursize);
+
+// check time
+ time = Sys_FloatTime ();
+ if (time - lastmsg < 5)
+ return;
+ lastmsg = time;
+
+// write out a nop
+ Con_Printf ("--> client to server keepalive\n");
+
+ MSG_WriteByte (&cls.message, clc_nop);
+ NET_SendMessage (cls.netcon, &cls.message);
+ SZ_Clear (&cls.message);
+}
+
+/*
+==================
+CL_ParseServerInfo
+==================
+*/
+void CL_ParseServerInfo (void)
+{
+ char *str;
+ int i;
+ int nummodels, numsounds;
+ char model_precache[MAX_MODELS][MAX_QPATH];
+ char sound_precache[MAX_SOUNDS][MAX_QPATH];
+
+ Con_DPrintf ("Serverinfo packet received.\n");
+//
+// wipe the client_state_t struct
+//
+ CL_ClearState ();
+
+// parse protocol version number
+ i = MSG_ReadLong ();
+ if (i != PROTOCOL_VERSION)
+ {
+ Con_Printf ("Server returned version %i, not %i", i, PROTOCOL_VERSION);
+ return;
+ }
+
+// parse maxclients
+ cl.maxclients = MSG_ReadByte ();
+ if (cl.maxclients < 1 || cl.maxclients > MAX_SCOREBOARD)
+ {
+ Con_Printf("Bad maxclients (%u) from server\n", cl.maxclients);
+ return;
+ }
+ cl.scores = Hunk_AllocName (cl.maxclients*sizeof(*cl.scores), "scores");
+
+// parse gametype
+ cl.gametype = MSG_ReadByte ();
+
+// parse signon message
+ str = MSG_ReadString ();
+ strncpy (cl.levelname, str, sizeof(cl.levelname)-1);
+
+// seperate the printfs so the server message can have a color
+ Con_Printf("\n\n\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\37\n\n");
+ Con_Printf ("%c%s\n", 2, str);
+
+//
+// first we go through and touch all of the precache data that still
+// happens to be in the cache, so precaching something else doesn't
+// needlessly purge it
+//
+
+// precache models
+ memset (cl.model_precache, 0, sizeof(cl.model_precache));
+ for (nummodels=1 ; ; nummodels++)
+ {
+ str = MSG_ReadString ();
+ if (!str[0])
+ break;
+ if (nummodels==MAX_MODELS)
+ {
+ Con_Printf ("Server sent too many model precaches\n");
+ return;
+ }
+ strcpy (model_precache[nummodels], str);
+ Mod_TouchModel (str);
+ }
+
+// precache sounds
+ memset (cl.sound_precache, 0, sizeof(cl.sound_precache));
+ for (numsounds=1 ; ; numsounds++)
+ {
+ str = MSG_ReadString ();
+ if (!str[0])
+ break;
+ if (numsounds==MAX_SOUNDS)
+ {
+ Con_Printf ("Server sent too many sound precaches\n");
+ return;
+ }
+ strcpy (sound_precache[numsounds], str);
+ S_TouchSound (str);
+ }
+
+//
+// now we try to load everything else until a cache allocation fails
+//
+
+ for (i=1 ; i<nummodels ; i++)
+ {
+ cl.model_precache[i] = Mod_ForName (model_precache[i], false);
+ if (cl.model_precache[i] == NULL)
+ {
+ Con_Printf("Model %s not found\n", model_precache[i]);
+ return;
+ }
+ CL_KeepaliveMessage ();
+ }
+
+ S_BeginPrecaching ();
+ for (i=1 ; i<numsounds ; i++)
+ {
+ cl.sound_precache[i] = S_PrecacheSound (sound_precache[i]);
+ CL_KeepaliveMessage ();
+ }
+ S_EndPrecaching ();
+
+
+// local state
+ cl_entities[0].model = cl.worldmodel = cl.model_precache[1];
+
+ R_NewMap ();
+
+ Hunk_Check (); // make sure nothing is hurt
+
+ noclip_anglehack = false; // noclip is turned off at start
+}
+
+
+/*
+==================
+CL_ParseUpdate
+
+Parse an entity update message from the server
+If an entities model or origin changes from frame to frame, it must be
+relinked. Other attributes can change without relinking.
+==================
+*/
+int bitcounts[16];
+
+void CL_ParseUpdate (int bits)
+{
+ int i;
+ model_t *model;
+ int modnum;
+ qboolean forcelink;
+ entity_t *ent;
+ int num;
+ int skin;
+
+ if (cls.signon == SIGNONS - 1)
+ { // first update is the final signon stage
+ cls.signon = SIGNONS;
+ CL_SignonReply ();
+ }
+
+ if (bits & U_MOREBITS)
+ {
+ i = MSG_ReadByte ();
+ bits |= (i<<8);
+ }
+
+ if (bits & U_LONGENTITY)
+ num = MSG_ReadShort ();
+ else
+ num = MSG_ReadByte ();
+
+ ent = CL_EntityNum (num);
+
+for (i=0 ; i<16 ; i++)
+if (bits&(1<<i))
+ bitcounts[i]++;
+
+ if (ent->msgtime != cl.mtime[1])
+ forcelink = true; // no previous frame to lerp from
+ else
+ forcelink = false;
+
+ ent->msgtime = cl.mtime[0];
+
+ if (bits & U_MODEL)
+ {
+ modnum = MSG_ReadByte ();
+ if (modnum >= MAX_MODELS)
+ Host_Error ("CL_ParseModel: bad modnum");
+ }
+ else
+ modnum = ent->baseline.modelindex;
+
+ model = cl.model_precache[modnum];
+ if (model != ent->model)
+ {
+ ent->model = model;
+ // automatic animation (torches, etc) can be either all together
+ // or randomized
+ if (model)
+ {
+ if (model->synctype == ST_RAND)
+ ent->syncbase = (float)(rand()&0x7fff) / 0x7fff;
+ else
+ ent->syncbase = 0.0;
+ }
+ else
+ forcelink = true; // hack to make null model players work
+#ifdef GLQUAKE
+ if (num > 0 && num <= cl.maxclients)
+ R_TranslatePlayerSkin (num - 1);
+#endif
+ }
+
+ if (bits & U_FRAME)
+ ent->frame = MSG_ReadByte ();
+ else
+ ent->frame = ent->baseline.frame;
+
+ if (bits & U_COLORMAP)
+ i = MSG_ReadByte();
+ else
+ i = ent->baseline.colormap;
+ if (!i)
+ ent->colormap = vid.colormap;
+ else
+ {
+ if (i > cl.maxclients)
+ Sys_Error ("i >= cl.maxclients");
+ ent->colormap = cl.scores[i-1].translations;
+ }
+
+#ifdef GLQUAKE
+ if (bits & U_SKIN)
+ skin = MSG_ReadByte();
+ else
+ skin = ent->baseline.skin;
+ if (skin != ent->skinnum) {
+ ent->skinnum = skin;
+ if (num > 0 && num <= cl.maxclients)
+ R_TranslatePlayerSkin (num - 1);
+ }
+
+#else
+
+ if (bits & U_SKIN)
+ ent->skinnum = MSG_ReadByte();
+ else
+ ent->skinnum = ent->baseline.skin;
+#endif
+
+ if (bits & U_EFFECTS)
+ ent->effects = MSG_ReadByte();
+ else
+ ent->effects = ent->baseline.effects;
+
+// shift the known values for interpolation
+ VectorCopy (ent->msg_origins[0], ent->msg_origins[1]);
+ VectorCopy (ent->msg_angles[0], ent->msg_angles[1]);
+
+ if (bits & U_ORIGIN1)
+ ent->msg_origins[0][0] = MSG_ReadCoord ();
+ else
+ ent->msg_origins[0][0] = ent->baseline.origin[0];
+ if (bits & U_ANGLE1)
+ ent->msg_angles[0][0] = MSG_ReadAngle();
+ else
+ ent->msg_angles[0][0] = ent->baseline.angles[0];
+
+ if (bits & U_ORIGIN2)
+ ent->msg_origins[0][1] = MSG_ReadCoord ();
+ else
+ ent->msg_origins[0][1] = ent->baseline.origin[1];
+ if (bits & U_ANGLE2)
+ ent->msg_angles[0][1] = MSG_ReadAngle();
+ else
+ ent->msg_angles[0][1] = ent->baseline.angles[1];
+
+ if (bits & U_ORIGIN3)
+ ent->msg_origins[0][2] = MSG_ReadCoord ();
+ else
+ ent->msg_origins[0][2] = ent->baseline.origin[2];
+ if (bits & U_ANGLE3)
+ ent->msg_angles[0][2] = MSG_ReadAngle();
+ else
+ ent->msg_angles[0][2] = ent->baseline.angles[2];
+
+ if ( bits & U_NOLERP )
+ ent->forcelink = true;
+
+ if ( forcelink )
+ { // didn't have an update last message
+ VectorCopy (ent->msg_origins[0], ent->msg_origins[1]);
+ VectorCopy (ent->msg_origins[0], ent->origin);
+ VectorCopy (ent->msg_angles[0], ent->msg_angles[1]);
+ VectorCopy (ent->msg_angles[0], ent->angles);
+ ent->forcelink = true;
+ }
+}
+
+/*
+==================
+CL_ParseBaseline
+==================
+*/
+void CL_ParseBaseline (entity_t *ent)
+{
+ int i;
+
+ ent->baseline.modelindex = MSG_ReadByte ();
+ ent->baseline.frame = MSG_ReadByte ();
+ ent->baseline.colormap = MSG_ReadByte();
+ ent->baseline.skin = MSG_ReadByte();
+ for (i=0 ; i<3 ; i++)
+ {
+ ent->baseline.origin[i] = MSG_ReadCoord ();
+ ent->baseline.angles[i] = MSG_ReadAngle ();
+ }
+}
+
+
+/*
+==================
+CL_ParseClientdata
+
+Server information pertaining to this client only
+==================
+*/
+void CL_ParseClientdata (int bits)
+{
+ int i, j;
+
+ if (bits & SU_VIEWHEIGHT)
+ cl.viewheight = MSG_ReadChar ();
+ else
+ cl.viewheight = DEFAULT_VIEWHEIGHT;
+
+ if (bits & SU_IDEALPITCH)
+ cl.idealpitch = MSG_ReadChar ();
+ else
+ cl.idealpitch = 0;
+
+ VectorCopy (cl.mvelocity[0], cl.mvelocity[1]);
+ for (i=0 ; i<3 ; i++)
+ {
+ if (bits & (SU_PUNCH1<<i) )
+ cl.punchangle[i] = MSG_ReadChar();
+ else
+ cl.punchangle[i] = 0;
+ if (bits & (SU_VELOCITY1<<i) )
+ cl.mvelocity[0][i] = MSG_ReadChar()*16;
+ else
+ cl.mvelocity[0][i] = 0;
+ }
+
+// [always sent] if (bits & SU_ITEMS)
+ i = MSG_ReadLong ();
+
+ if (cl.items != i)
+ { // set flash times
+ Sbar_Changed ();
+ for (j=0 ; j<32 ; j++)
+ if ( (i & (1<<j)) && !(cl.items & (1<<j)))
+ cl.item_gettime[j] = cl.time;
+ cl.items = i;
+ }
+
+ cl.onground = (bits & SU_ONGROUND) != 0;
+ cl.inwater = (bits & SU_INWATER) != 0;
+
+ if (bits & SU_WEAPONFRAME)
+ cl.stats[STAT_WEAPONFRAME] = MSG_ReadByte ();
+ else
+ cl.stats[STAT_WEAPONFRAME] = 0;
+
+ if (bits & SU_ARMOR)
+ i = MSG_ReadByte ();
+ else
+ i = 0;
+ if (cl.stats[STAT_ARMOR] != i)
+ {
+ cl.stats[STAT_ARMOR] = i;
+ Sbar_Changed ();
+ }
+
+ if (bits & SU_WEAPON)
+ i = MSG_ReadByte ();
+ else
+ i = 0;
+ if (cl.stats[STAT_WEAPON] != i)
+ {
+ cl.stats[STAT_WEAPON] = i;
+ Sbar_Changed ();
+ }
+
+ i = MSG_ReadShort ();
+ if (cl.stats[STAT_HEALTH] != i)
+ {
+ cl.stats[STAT_HEALTH] = i;
+ Sbar_Changed ();
+ }
+
+ i = MSG_ReadByte ();
+ if (cl.stats[STAT_AMMO] != i)
+ {
+ cl.stats[STAT_AMMO] = i;
+ Sbar_Changed ();
+ }
+
+ for (i=0 ; i<4 ; i++)
+ {
+ j = MSG_ReadByte ();
+ if (cl.stats[STAT_SHELLS+i] != j)
+ {
+ cl.stats[STAT_SHELLS+i] = j;
+ Sbar_Changed ();
+ }
+ }
+
+ i = MSG_ReadByte ();
+
+ if (standard_quake)
+ {
+ if (cl.stats[STAT_ACTIVEWEAPON] != i)
+ {
+ cl.stats[STAT_ACTIVEWEAPON] = i;
+ Sbar_Changed ();
+ }
+ }
+ else
+ {
+ if (cl.stats[STAT_ACTIVEWEAPON] != (1<<i))
+ {
+ cl.stats[STAT_ACTIVEWEAPON] = (1<<i);
+ Sbar_Changed ();
+ }
+ }
+}
+
+/*
+=====================
+CL_NewTranslation
+=====================
+*/
+void CL_NewTranslation (int slot)
+{
+ int i, j;
+ int top, bottom;
+ byte *dest, *source;
+
+ if (slot > cl.maxclients)
+ Sys_Error ("CL_NewTranslation: slot > cl.maxclients");
+ dest = cl.scores[slot].translations;
+ source = vid.colormap;
+ memcpy (dest, vid.colormap, sizeof(cl.scores[slot].translations));
+ top = cl.scores[slot].colors & 0xf0;
+ bottom = (cl.scores[slot].colors &15)<<4;
+#ifdef GLQUAKE
+ R_TranslatePlayerSkin (slot);
+#endif
+
+ for (i=0 ; i<VID_GRADES ; i++, dest += 256, source+=256)
+ {
+ if (top < 128) // the artists made some backwards ranges. sigh.
+ memcpy (dest + TOP_RANGE, source + top, 16);
+ else
+ for (j=0 ; j<16 ; j++)
+ dest[TOP_RANGE+j] = source[top+15-j];
+
+ if (bottom < 128)
+ memcpy (dest + BOTTOM_RANGE, source + bottom, 16);
+ else
+ for (j=0 ; j<16 ; j++)
+ dest[BOTTOM_RANGE+j] = source[bottom+15-j];
+ }
+}
+
+/*
+=====================
+CL_ParseStatic
+=====================
+*/
+void CL_ParseStatic (void)
+{
+ entity_t *ent;
+ int i;
+
+ i = cl.num_statics;
+ if (i >= MAX_STATIC_ENTITIES)
+ Host_Error ("Too many static entities");
+ ent = &cl_static_entities[i];
+ cl.num_statics++;
+ CL_ParseBaseline (ent);
+
+// copy it to the current state
+ ent->model = cl.model_precache[ent->baseline.modelindex];
+ ent->frame = ent->baseline.frame;
+ ent->colormap = vid.colormap;
+ ent->skinnum = ent->baseline.skin;
+ ent->effects = ent->baseline.effects;
+
+ VectorCopy (ent->baseline.origin, ent->origin);
+ VectorCopy (ent->baseline.angles, ent->angles);
+ R_AddEfrags (ent);
+}
+
+/*
+===================
+CL_ParseStaticSound
+===================
+*/
+void CL_ParseStaticSound (void)
+{
+ vec3_t org;
+ int sound_num, vol, atten;
+ int i;
+
+ for (i=0 ; i<3 ; i++)
+ org[i] = MSG_ReadCoord ();
+ sound_num = MSG_ReadByte ();
+ vol = MSG_ReadByte ();
+ atten = MSG_ReadByte ();
+
+ S_StaticSound (cl.sound_precache[sound_num], org, vol, atten);
+}
+
+
+#define SHOWNET(x) if(cl_shownet.value==2)Con_Printf ("%3i:%s\n", msg_readcount-1, x);
+
+/*
+=====================
+CL_ParseServerMessage
+=====================
+*/
+void CL_ParseServerMessage (void)
+{
+ int cmd;
+ int i;
+
+//
+// if recording demos, copy the message out
+//
+ if (cl_shownet.value == 1)
+ Con_Printf ("%i ",net_message.cursize);
+ else if (cl_shownet.value == 2)
+ Con_Printf ("------------------\n");
+
+ cl.onground = false; // unless the server says otherwise
+//
+// parse the message
+//
+ MSG_BeginReading ();
+
+ while (1)
+ {
+ if (msg_badread)
+ Host_Error ("CL_ParseServerMessage: Bad server message");
+
+ cmd = MSG_ReadByte ();
+
+ if (cmd == -1)
+ {
+ SHOWNET("END OF MESSAGE");
+ return; // end of message
+ }
+
+ // if the high bit of the command byte is set, it is a fast update
+ if (cmd & 128)
+ {
+ SHOWNET("fast update");
+ CL_ParseUpdate (cmd&127);
+ continue;
+ }
+
+ SHOWNET(svc_strings[cmd]);
+
+ // other commands
+ switch (cmd)
+ {
+ default:
+ Host_Error ("CL_ParseServerMessage: Illegible server message\n");
+ break;
+
+ case svc_nop:
+// Con_Printf ("svc_nop\n");
+ break;
+
+ case svc_time:
+ cl.mtime[1] = cl.mtime[0];
+ cl.mtime[0] = MSG_ReadFloat ();
+ break;
+
+ case svc_clientdata:
+ i = MSG_ReadShort ();
+ CL_ParseClientdata (i);
+ break;
+
+ case svc_version:
+ i = MSG_ReadLong ();
+ if (i != PROTOCOL_VERSION)
+ Host_Error ("CL_ParseServerMessage: Server is protocol %i instead of %i\n", i, PROTOCOL_VERSION);
+ break;
+
+ case svc_disconnect:
+ Host_EndGame ("Server disconnected\n");
+
+ case svc_print:
+ Con_Printf ("%s", MSG_ReadString ());
+ break;
+
+ case svc_centerprint:
+ SCR_CenterPrint (MSG_ReadString ());
+ break;
+
+ case svc_stufftext:
+ Cbuf_AddText (MSG_ReadString ());
+ break;
+
+ case svc_damage:
+ V_ParseDamage ();
+ break;
+
+ case svc_serverinfo:
+ CL_ParseServerInfo ();
+ vid.recalc_refdef = true; // leave intermission full screen
+ break;
+
+ case svc_setangle:
+ for (i=0 ; i<3 ; i++)
+ cl.viewangles[i] = MSG_ReadAngle ();
+ break;
+
+ case svc_setview:
+ cl.viewentity = MSG_ReadShort ();
+ break;
+
+ case svc_lightstyle:
+ i = MSG_ReadByte ();
+ if (i >= MAX_LIGHTSTYLES)
+ Sys_Error ("svc_lightstyle > MAX_LIGHTSTYLES");
+ Q_strcpy (cl_lightstyle[i].map, MSG_ReadString());
+ cl_lightstyle[i].length = Q_strlen(cl_lightstyle[i].map);
+ break;
+
+ case svc_sound:
+ CL_ParseStartSoundPacket();
+ break;
+
+ case svc_stopsound:
+ i = MSG_ReadShort();
+ S_StopSound(i>>3, i&7);
+ break;
+
+ case svc_updatename:
+ Sbar_Changed ();
+ i = MSG_ReadByte ();
+ if (i >= cl.maxclients)
+ Host_Error ("CL_ParseServerMessage: svc_updatename > MAX_SCOREBOARD");
+ strcpy (cl.scores[i].name, MSG_ReadString ());
+ break;
+
+ case svc_updatefrags:
+ Sbar_Changed ();
+ i = MSG_ReadByte ();
+ if (i >= cl.maxclients)
+ Host_Error ("CL_ParseServerMessage: svc_updatefrags > MAX_SCOREBOARD");
+ cl.scores[i].frags = MSG_ReadShort ();
+ break;
+
+ case svc_updatecolors:
+ Sbar_Changed ();
+ i = MSG_ReadByte ();
+ if (i >= cl.maxclients)
+ Host_Error ("CL_ParseServerMessage: svc_updatecolors > MAX_SCOREBOARD");
+ cl.scores[i].colors = MSG_ReadByte ();
+ CL_NewTranslation (i);
+ break;
+
+ case svc_particle:
+ R_ParseParticleEffect ();
+ break;
+
+ case svc_spawnbaseline:
+ i = MSG_ReadShort ();
+ // must use CL_EntityNum() to force cl.num_entities up
+ CL_ParseBaseline (CL_EntityNum(i));
+ break;
+ case svc_spawnstatic:
+ CL_ParseStatic ();
+ break;
+ case svc_temp_entity:
+ CL_ParseTEnt ();
+ break;
+
+ case svc_setpause:
+ {
+ cl.paused = MSG_ReadByte ();
+
+ if (cl.paused)
+ {
+ CDAudio_Pause ();
+#ifdef _WIN32
+ VID_HandlePause (true);
+#endif
+ }
+ else
+ {
+ CDAudio_Resume ();
+#ifdef _WIN32
+ VID_HandlePause (false);
+#endif
+ }
+ }
+ break;
+
+ case svc_signonnum:
+ i = MSG_ReadByte ();
+ if (i <= cls.signon)
+ Host_Error ("Received signon %i when at %i", i, cls.signon);
+ cls.signon = i;
+ CL_SignonReply ();
+ break;
+
+ case svc_killedmonster:
+ cl.stats[STAT_MONSTERS]++;
+ break;
+
+ case svc_foundsecret:
+ cl.stats[STAT_SECRETS]++;
+ break;
+
+ case svc_updatestat:
+ i = MSG_ReadByte ();
+ if (i < 0 || i >= MAX_CL_STATS)
+ Sys_Error ("svc_updatestat: %i is invalid", i);
+ cl.stats[i] = MSG_ReadLong ();;
+ break;
+
+ case svc_spawnstaticsound:
+ CL_ParseStaticSound ();
+ break;
+
+ case svc_cdtrack:
+ cl.cdtrack = MSG_ReadByte ();
+ cl.looptrack = MSG_ReadByte ();
+ if ( (cls.demoplayback || cls.demorecording) && (cls.forcetrack != -1) )
+ CDAudio_Play ((byte)cls.forcetrack, true);
+ else
+ CDAudio_Play ((byte)cl.cdtrack, true);
+ break;
+
+ case svc_intermission:
+ cl.intermission = 1;
+ cl.completed_time = cl.time;
+ vid.recalc_refdef = true; // go to full screen
+ break;
+
+ case svc_finale:
+ cl.intermission = 2;
+ cl.completed_time = cl.time;
+ vid.recalc_refdef = true; // go to full screen
+ SCR_CenterPrint (MSG_ReadString ());
+ break;
+
+ case svc_cutscene:
+ cl.intermission = 3;
+ cl.completed_time = cl.time;
+ vid.recalc_refdef = true; // go to full screen
+ SCR_CenterPrint (MSG_ReadString ());
+ break;
+
+ case svc_sellscreen:
+ Cmd_ExecuteString ("help", src_command);
+ break;
+ }
+ }
+}
+
diff --git a/apps/plugins/sdl/progs/quake/cl_tent.c b/apps/plugins/sdl/progs/quake/cl_tent.c
new file mode 100644
index 0000000000..546e832f8b
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/cl_tent.c
@@ -0,0 +1,394 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// cl_tent.c -- client side temporary entities
+
+#include "quakedef.h"
+
+int num_temp_entities;
+entity_t cl_temp_entities[MAX_TEMP_ENTITIES];
+beam_t cl_beams[MAX_BEAMS];
+
+sfx_t *cl_sfx_wizhit;
+sfx_t *cl_sfx_knighthit;
+sfx_t *cl_sfx_tink1;
+sfx_t *cl_sfx_ric1;
+sfx_t *cl_sfx_ric2;
+sfx_t *cl_sfx_ric3;
+sfx_t *cl_sfx_r_exp3;
+#ifdef QUAKE2
+sfx_t *cl_sfx_imp;
+sfx_t *cl_sfx_rail;
+#endif
+
+/*
+=================
+CL_ParseTEnt
+=================
+*/
+void CL_InitTEnts (void)
+{
+ cl_sfx_wizhit = S_PrecacheSound ("wizard/hit.wav");
+ cl_sfx_knighthit = S_PrecacheSound ("hknight/hit.wav");
+ cl_sfx_tink1 = S_PrecacheSound ("weapons/tink1.wav");
+ cl_sfx_ric1 = S_PrecacheSound ("weapons/ric1.wav");
+ cl_sfx_ric2 = S_PrecacheSound ("weapons/ric2.wav");
+ cl_sfx_ric3 = S_PrecacheSound ("weapons/ric3.wav");
+ cl_sfx_r_exp3 = S_PrecacheSound ("weapons/r_exp3.wav");
+#ifdef QUAKE2
+ cl_sfx_imp = S_PrecacheSound ("shambler/sattck1.wav");
+ cl_sfx_rail = S_PrecacheSound ("weapons/lstart.wav");
+#endif
+}
+
+/*
+=================
+CL_ParseBeam
+=================
+*/
+void CL_ParseBeam (model_t *m)
+{
+ int ent;
+ vec3_t start, end;
+ beam_t *b;
+ int i;
+
+ ent = MSG_ReadShort ();
+
+ start[0] = MSG_ReadCoord ();
+ start[1] = MSG_ReadCoord ();
+ start[2] = MSG_ReadCoord ();
+
+ end[0] = MSG_ReadCoord ();
+ end[1] = MSG_ReadCoord ();
+ end[2] = MSG_ReadCoord ();
+
+// override any beam with the same entity
+ for (i=0, b=cl_beams ; i< MAX_BEAMS ; i++, b++)
+ if (b->entity == ent)
+ {
+ b->entity = ent;
+ b->model = m;
+ b->endtime = cl.time + 0.2;
+ VectorCopy (start, b->start);
+ VectorCopy (end, b->end);
+ return;
+ }
+
+// find a free beam
+ for (i=0, b=cl_beams ; i< MAX_BEAMS ; i++, b++)
+ {
+ if (!b->model || b->endtime < cl.time)
+ {
+ b->entity = ent;
+ b->model = m;
+ b->endtime = cl.time + 0.2;
+ VectorCopy (start, b->start);
+ VectorCopy (end, b->end);
+ return;
+ }
+ }
+ Con_Printf ("beam list overflow!\n");
+}
+
+/*
+=================
+CL_ParseTEnt
+=================
+*/
+void CL_ParseTEnt (void)
+{
+ int type;
+ vec3_t pos;
+#ifdef QUAKE2
+ vec3_t endpos;
+#endif
+ dlight_t *dl;
+ int rnd;
+ int colorStart, colorLength;
+
+ type = MSG_ReadByte ();
+ switch (type)
+ {
+ case TE_WIZSPIKE: // spike hitting wall
+ pos[0] = MSG_ReadCoord ();
+ pos[1] = MSG_ReadCoord ();
+ pos[2] = MSG_ReadCoord ();
+ R_RunParticleEffect (pos, vec3_origin, 20, 30);
+ S_StartSound (-1, 0, cl_sfx_wizhit, pos, 1, 1);
+ break;
+
+ case TE_KNIGHTSPIKE: // spike hitting wall
+ pos[0] = MSG_ReadCoord ();
+ pos[1] = MSG_ReadCoord ();
+ pos[2] = MSG_ReadCoord ();
+ R_RunParticleEffect (pos, vec3_origin, 226, 20);
+ S_StartSound (-1, 0, cl_sfx_knighthit, pos, 1, 1);
+ break;
+
+ case TE_SPIKE: // spike hitting wall
+ pos[0] = MSG_ReadCoord ();
+ pos[1] = MSG_ReadCoord ();
+ pos[2] = MSG_ReadCoord ();
+#ifdef GLTEST
+ Test_Spawn (pos);
+#else
+ R_RunParticleEffect (pos, vec3_origin, 0, 10);
+#endif
+ if ( rand() % 5 )
+ S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
+ else
+ {
+ rnd = rand() & 3;
+ if (rnd == 1)
+ S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
+ else if (rnd == 2)
+ S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
+ else
+ S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
+ }
+ break;
+ case TE_SUPERSPIKE: // super spike hitting wall
+ pos[0] = MSG_ReadCoord ();
+ pos[1] = MSG_ReadCoord ();
+ pos[2] = MSG_ReadCoord ();
+ R_RunParticleEffect (pos, vec3_origin, 0, 20);
+
+ if ( rand() % 5 )
+ S_StartSound (-1, 0, cl_sfx_tink1, pos, 1, 1);
+ else
+ {
+ rnd = rand() & 3;
+ if (rnd == 1)
+ S_StartSound (-1, 0, cl_sfx_ric1, pos, 1, 1);
+ else if (rnd == 2)
+ S_StartSound (-1, 0, cl_sfx_ric2, pos, 1, 1);
+ else
+ S_StartSound (-1, 0, cl_sfx_ric3, pos, 1, 1);
+ }
+ break;
+
+ case TE_GUNSHOT: // bullet hitting wall
+ pos[0] = MSG_ReadCoord ();
+ pos[1] = MSG_ReadCoord ();
+ pos[2] = MSG_ReadCoord ();
+ R_RunParticleEffect (pos, vec3_origin, 0, 20);
+ break;
+
+ case TE_EXPLOSION: // rocket explosion
+ pos[0] = MSG_ReadCoord ();
+ pos[1] = MSG_ReadCoord ();
+ pos[2] = MSG_ReadCoord ();
+ R_ParticleExplosion (pos);
+ dl = CL_AllocDlight (0);
+ VectorCopy (pos, dl->origin);
+ dl->radius = 350;
+ dl->die = cl.time + 0.5;
+ dl->decay = 300;
+ S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
+ break;
+
+ case TE_TAREXPLOSION: // tarbaby explosion
+ pos[0] = MSG_ReadCoord ();
+ pos[1] = MSG_ReadCoord ();
+ pos[2] = MSG_ReadCoord ();
+ R_BlobExplosion (pos);
+
+ S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
+ break;
+
+ case TE_LIGHTNING1: // lightning bolts
+ CL_ParseBeam (Mod_ForName("progs/bolt.mdl", true));
+ break;
+
+ case TE_LIGHTNING2: // lightning bolts
+ CL_ParseBeam (Mod_ForName("progs/bolt2.mdl", true));
+ break;
+
+ case TE_LIGHTNING3: // lightning bolts
+ CL_ParseBeam (Mod_ForName("progs/bolt3.mdl", true));
+ break;
+
+// PGM 01/21/97
+ case TE_BEAM: // grappling hook beam
+ CL_ParseBeam (Mod_ForName("progs/beam.mdl", true));
+ break;
+// PGM 01/21/97
+
+ case TE_LAVASPLASH:
+ pos[0] = MSG_ReadCoord ();
+ pos[1] = MSG_ReadCoord ();
+ pos[2] = MSG_ReadCoord ();
+ R_LavaSplash (pos);
+ break;
+
+ case TE_TELEPORT:
+ pos[0] = MSG_ReadCoord ();
+ pos[1] = MSG_ReadCoord ();
+ pos[2] = MSG_ReadCoord ();
+ R_TeleportSplash (pos);
+ break;
+
+ case TE_EXPLOSION2: // color mapped explosion
+ pos[0] = MSG_ReadCoord ();
+ pos[1] = MSG_ReadCoord ();
+ pos[2] = MSG_ReadCoord ();
+ colorStart = MSG_ReadByte ();
+ colorLength = MSG_ReadByte ();
+ R_ParticleExplosion2 (pos, colorStart, colorLength);
+ dl = CL_AllocDlight (0);
+ VectorCopy (pos, dl->origin);
+ dl->radius = 350;
+ dl->die = cl.time + 0.5;
+ dl->decay = 300;
+ S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
+ break;
+
+#ifdef QUAKE2
+ case TE_IMPLOSION:
+ pos[0] = MSG_ReadCoord ();
+ pos[1] = MSG_ReadCoord ();
+ pos[2] = MSG_ReadCoord ();
+ S_StartSound (-1, 0, cl_sfx_imp, pos, 1, 1);
+ break;
+
+ case TE_RAILTRAIL:
+ pos[0] = MSG_ReadCoord ();
+ pos[1] = MSG_ReadCoord ();
+ pos[2] = MSG_ReadCoord ();
+ endpos[0] = MSG_ReadCoord ();
+ endpos[1] = MSG_ReadCoord ();
+ endpos[2] = MSG_ReadCoord ();
+ S_StartSound (-1, 0, cl_sfx_rail, pos, 1, 1);
+ S_StartSound (-1, 1, cl_sfx_r_exp3, endpos, 1, 1);
+ R_RocketTrail (pos, endpos, 0+128);
+ R_ParticleExplosion (endpos);
+ dl = CL_AllocDlight (-1);
+ VectorCopy (endpos, dl->origin);
+ dl->radius = 350;
+ dl->die = cl.time + 0.5;
+ dl->decay = 300;
+ break;
+#endif
+
+ default:
+ Sys_Error ("CL_ParseTEnt: bad type");
+ }
+}
+
+
+/*
+=================
+CL_NewTempEntity
+=================
+*/
+entity_t *CL_NewTempEntity (void)
+{
+ entity_t *ent;
+
+ if (cl_numvisedicts == MAX_VISEDICTS)
+ return NULL;
+ if (num_temp_entities == MAX_TEMP_ENTITIES)
+ return NULL;
+ ent = &cl_temp_entities[num_temp_entities];
+ memset (ent, 0, sizeof(*ent));
+ num_temp_entities++;
+ cl_visedicts[cl_numvisedicts] = ent;
+ cl_numvisedicts++;
+
+ ent->colormap = vid.colormap;
+ return ent;
+}
+
+
+/*
+=================
+CL_UpdateTEnts
+=================
+*/
+void CL_UpdateTEnts (void)
+{
+ int i;
+ beam_t *b;
+ vec3_t dist, org;
+ float d;
+ entity_t *ent;
+ float yaw, pitch;
+ float forward;
+
+ num_temp_entities = 0;
+
+// update lightning
+ for (i=0, b=cl_beams ; i< MAX_BEAMS ; i++, b++)
+ {
+ if (!b->model || b->endtime < cl.time)
+ continue;
+
+ // if coming from the player, update the start position
+ if (b->entity == cl.viewentity)
+ {
+ VectorCopy (cl_entities[cl.viewentity].origin, b->start);
+ }
+
+ // calculate pitch and yaw
+ VectorSubtract (b->end, b->start, dist);
+
+ if (dist[1] == 0 && dist[0] == 0)
+ {
+ yaw = 0;
+ if (dist[2] > 0)
+ pitch = 90;
+ else
+ pitch = 270;
+ }
+ else
+ {
+ yaw = (int) (atan2(dist[1], dist[0]) * 180 / M_PI);
+ if (yaw < 0)
+ yaw += 360;
+
+ forward = sqrt (dist[0]*dist[0] + dist[1]*dist[1]);
+ pitch = (int) (atan2(dist[2], forward) * 180 / M_PI);
+ if (pitch < 0)
+ pitch += 360;
+ }
+
+ // add new entities for the lightning
+ VectorCopy (b->start, org);
+ d = VectorNormalize(dist);
+ while (d > 0)
+ {
+ ent = CL_NewTempEntity ();
+ if (!ent)
+ return;
+ VectorCopy (org, ent->origin);
+ ent->model = b->model;
+ ent->angles[0] = pitch;
+ ent->angles[1] = yaw;
+ ent->angles[2] = rand()%360;
+
+ for (i=0 ; i<3 ; i++)
+ org[i] += dist[i]*30;
+ d -= 30;
+ }
+ }
+
+}
+
+
diff --git a/apps/plugins/sdl/progs/quake/clean.bat b/apps/plugins/sdl/progs/quake/clean.bat
new file mode 100644
index 0000000000..8a5aad4867
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/clean.bat
@@ -0,0 +1,18 @@
+rmdir /s /q debug
+rmdir /s /q release
+rmdir /s /q debug_gl
+rmdir /s /q release_gl
+
+rmdir /s /q gas2masm\debug
+rmdir /s /q gas2masm\release
+
+del gas2masm\gas2masm.opt
+del gas2masm\gas2masm.plg
+del gas2masm\gas2masm.ncb
+del gas2masm\gas2masm.stt
+
+del WinQuake.opt
+del WinQuake.plg
+del WinQuake.ncb
+del WinQuake.stt
+
diff --git a/apps/plugins/sdl/progs/quake/client.h b/apps/plugins/sdl/progs/quake/client.h
new file mode 100644
index 0000000000..4d52bf907e
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/client.h
@@ -0,0 +1,376 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// client.h
+
+typedef struct
+{
+ vec3_t viewangles;
+
+// intended velocities
+ float forwardmove;
+ float sidemove;
+ float upmove;
+#ifdef QUAKE2
+ byte lightlevel;
+#endif
+} usercmd_t;
+
+typedef struct
+{
+ int length;
+ char map[MAX_STYLESTRING];
+} lightstyle_t;
+
+typedef struct
+{
+ char name[MAX_SCOREBOARDNAME];
+ float entertime;
+ int frags;
+ int colors; // two 4 bit fields
+ byte translations[VID_GRADES*256];
+} scoreboard_t;
+
+typedef struct
+{
+ int destcolor[3];
+ int percent; // 0-256
+} cshift_t;
+
+#define CSHIFT_CONTENTS 0
+#define CSHIFT_DAMAGE 1
+#define CSHIFT_BONUS 2
+#define CSHIFT_POWERUP 3
+#define NUM_CSHIFTS 4
+
+#define NAME_LENGTH 64
+
+
+//
+// client_state_t should hold all pieces of the client state
+//
+
+#define SIGNONS 4 // signon messages to receive before connected
+
+#define MAX_DLIGHTS 32
+typedef struct
+{
+ vec3_t origin;
+ float radius;
+ float die; // stop lighting after this time
+ float decay; // drop this each second
+ float minlight; // don't add when contributing less
+ int key;
+#ifdef QUAKE2
+ qboolean dark; // subtracts light instead of adding
+#endif
+} dlight_t;
+
+
+#define MAX_BEAMS 24
+typedef struct
+{
+ int entity;
+ struct model_s *model;
+ float endtime;
+ vec3_t start, end;
+} beam_t;
+
+#define MAX_EFRAGS 640
+
+#define MAX_MAPSTRING 2048
+#define MAX_DEMOS 8
+#define MAX_DEMONAME 16
+
+typedef int cactive_t;
+enum {
+ca_dedicated, // a dedicated server with no ability to start a client
+ca_disconnected, // full screen console with no connection
+ca_connected // valid netcon, talking to a server
+};
+
+//
+// the client_static_t structure is persistant through an arbitrary number
+// of server connections
+//
+typedef struct
+{
+ cactive_t state;
+
+// personalization data sent to server
+ char mapstring[MAX_QPATH];
+ char spawnparms[MAX_MAPSTRING]; // to restart a level
+
+// demo loop control
+ int demonum; // -1 = don't play demos
+ char demos[MAX_DEMOS][MAX_DEMONAME]; // when not playing
+
+// demo recording info must be here, because record is started before
+// entering a map (and clearing client_state_t)
+ qboolean demorecording;
+ qboolean demoplayback;
+ qboolean timedemo;
+ int forcetrack; // -1 = use normal cd track
+ FILE *demofile;
+ int td_lastframe; // to meter out one message a frame
+ int td_startframe; // host_framecount at start
+ float td_starttime; // realtime at second frame of timedemo
+
+
+// connection information
+ int signon; // 0 to SIGNONS
+ struct qsocket_s *netcon;
+ sizebuf_t message; // writing buffer to send to server
+
+} client_static_t;
+
+extern client_static_t cls;
+
+//
+// the client_state_t structure is wiped completely at every
+// server signon
+//
+typedef struct
+{
+ int movemessages; // since connecting to this server
+ // throw out the first couple, so the player
+ // doesn't accidentally do something the
+ // first frame
+ usercmd_t cmd; // last command sent to the server
+
+// information for local display
+ int stats[MAX_CL_STATS]; // health, etc
+ int items; // inventory bit flags
+ float item_gettime[32]; // cl.time of aquiring item, for blinking
+ float faceanimtime; // use anim frame if cl.time < this
+
+ cshift_t cshifts[NUM_CSHIFTS]; // color shifts for damage, powerups
+ cshift_t prev_cshifts[NUM_CSHIFTS]; // and content types
+
+// the client maintains its own idea of view angles, which are
+// sent to the server each frame. The server sets punchangle when
+// the view is temporarliy offset, and an angle reset commands at the start
+// of each level and after teleporting.
+ vec3_t mviewangles[2]; // during demo playback viewangles is lerped
+ // between these
+ vec3_t viewangles;
+
+ vec3_t mvelocity[2]; // update by server, used for lean+bob
+ // (0 is newest)
+ vec3_t velocity; // lerped between mvelocity[0] and [1]
+
+ vec3_t punchangle; // temporary offset
+
+// pitch drifting vars
+ float idealpitch;
+ float pitchvel;
+ qboolean nodrift;
+ float driftmove;
+ double laststop;
+
+ float viewheight;
+ float crouch; // local amount for smoothing stepups
+
+ qboolean paused; // send over by server
+ qboolean onground;
+ qboolean inwater;
+
+ int intermission; // don't change view angle, full screen, etc
+ int completed_time; // latched at intermission start
+
+ double mtime[2]; // the timestamp of last two messages
+ double time; // clients view of time, should be between
+ // servertime and oldservertime to generate
+ // a lerp point for other data
+ double oldtime; // previous cl.time, time-oldtime is used
+ // to decay light values and smooth step ups
+
+
+ float last_received_message; // (realtime) for net trouble icon
+
+//
+// information that is static for the entire time connected to a server
+//
+ struct model_s *model_precache[MAX_MODELS];
+ struct sfx_s *sound_precache[MAX_SOUNDS];
+
+ char levelname[40]; // for display on solo scoreboard
+ int viewentity; // cl_entitites[cl.viewentity] = player
+ int maxclients;
+ int gametype;
+
+// refresh related state
+ struct model_s *worldmodel; // cl_entitites[0].model
+ struct efrag_s *free_efrags;
+ int num_entities; // held in cl_entities array
+ int num_statics; // held in cl_staticentities array
+ entity_t viewent; // the gun model
+
+ int cdtrack, looptrack; // cd audio
+
+// frag scoreboard
+ scoreboard_t *scores; // [cl.maxclients]
+
+#ifdef QUAKE2
+// light level at player's position including dlights
+// this is sent back to the server each frame
+// architectually ugly but it works
+ int light_level;
+#endif
+} client_state_t;
+
+
+//
+// cvars
+//
+extern cvar_t cl_name;
+extern cvar_t cl_color;
+
+extern cvar_t cl_upspeed;
+extern cvar_t cl_forwardspeed;
+extern cvar_t cl_backspeed;
+extern cvar_t cl_sidespeed;
+
+extern cvar_t cl_movespeedkey;
+
+extern cvar_t cl_yawspeed;
+extern cvar_t cl_pitchspeed;
+
+extern cvar_t cl_anglespeedkey;
+
+extern cvar_t cl_autofire;
+
+extern cvar_t cl_shownet;
+extern cvar_t cl_nolerp;
+
+extern cvar_t cl_pitchdriftspeed;
+extern cvar_t lookspring;
+extern cvar_t lookstrafe;
+extern cvar_t sensitivity;
+
+extern cvar_t m_pitch;
+extern cvar_t m_yaw;
+extern cvar_t m_forward;
+extern cvar_t m_side;
+
+
+#define MAX_TEMP_ENTITIES 64 // lightning bolts, etc
+#define MAX_STATIC_ENTITIES 128 // torches, etc
+
+extern client_state_t cl;
+
+// FIXME, allocate dynamically
+extern efrag_t cl_efrags[MAX_EFRAGS];
+extern entity_t cl_entities[MAX_EDICTS];
+extern entity_t cl_static_entities[MAX_STATIC_ENTITIES];
+extern lightstyle_t cl_lightstyle[MAX_LIGHTSTYLES];
+extern dlight_t cl_dlights[MAX_DLIGHTS];
+extern entity_t cl_temp_entities[MAX_TEMP_ENTITIES];
+extern beam_t cl_beams[MAX_BEAMS];
+
+//=============================================================================
+
+//
+// cl_main
+//
+dlight_t *CL_AllocDlight (int key);
+void CL_DecayLights (void);
+
+void CL_Init (void);
+
+void CL_EstablishConnection (char *host);
+void CL_Signon1 (void);
+void CL_Signon2 (void);
+void CL_Signon3 (void);
+void CL_Signon4 (void);
+
+void CL_Disconnect (void);
+void CL_Disconnect_f (void);
+void CL_NextDemo (void);
+
+#define MAX_VISEDICTS 256
+extern int cl_numvisedicts;
+extern entity_t *cl_visedicts[MAX_VISEDICTS];
+
+//
+// cl_input
+//
+typedef struct
+{
+ int down[2]; // key nums holding it down
+ int state; // low bit is down state
+} kbutton_t;
+
+extern kbutton_t in_mlook, in_klook;
+extern kbutton_t in_strafe;
+extern kbutton_t in_speed;
+
+void CL_InitInput (void);
+void CL_SendCmd (void);
+void CL_SendMove (usercmd_t *cmd);
+
+void CL_ParseTEnt (void);
+void CL_UpdateTEnts (void);
+
+void CL_ClearState (void);
+
+
+int CL_ReadFromServer (void);
+void CL_WriteToServer (usercmd_t *cmd);
+void CL_BaseMove (usercmd_t *cmd);
+
+
+float CL_KeyState (kbutton_t *key);
+char *Key_KeynumToString (int keynum);
+
+//
+// cl_demo.c
+//
+void CL_StopPlayback (void);
+int CL_GetMessage (void);
+
+void CL_Stop_f (void);
+void CL_Record_f (void);
+void CL_PlayDemo_f (void);
+void CL_TimeDemo_f (void);
+
+//
+// cl_parse.c
+//
+void CL_ParseServerMessage (void);
+void CL_NewTranslation (int slot);
+
+//
+// view
+//
+void V_StartPitchDrift (void);
+void V_StopPitchDrift (void);
+
+void V_RenderView (void);
+void V_UpdatePalette (void);
+void V_Register (void);
+void V_ParseDamage (void);
+void V_SetContentsColor (int contents);
+
+
+//
+// cl_tent
+//
+void CL_InitTEnts (void);
+void CL_SignonReply (void);
diff --git a/apps/plugins/sdl/progs/quake/cmd.c b/apps/plugins/sdl/progs/quake/cmd.c
new file mode 100644
index 0000000000..95807065d3
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/cmd.c
@@ -0,0 +1,721 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// cmd.c -- Quake script command processing module
+
+#include "quakedef.h"
+
+void Cmd_ForwardToServer (void);
+
+#define MAX_ALIAS_NAME 32
+
+typedef struct cmdalias_s
+{
+ struct cmdalias_s *next;
+ char name[MAX_ALIAS_NAME];
+ char *value;
+} cmdalias_t;
+
+cmdalias_t *cmd_alias;
+
+int trashtest;
+int *trashspot;
+
+qboolean cmd_wait;
+
+//=============================================================================
+
+/*
+============
+Cmd_Wait_f
+
+Causes execution of the remainder of the command buffer to be delayed until
+next frame. This allows commands like:
+bind g "impulse 5 ; +attack ; wait ; -attack ; impulse 2"
+============
+*/
+void Cmd_Wait_f (void)
+{
+ cmd_wait = true;
+}
+
+/*
+=============================================================================
+
+ COMMAND BUFFER
+
+=============================================================================
+*/
+
+sizebuf_t cmd_text;
+
+/*
+============
+Cbuf_Init
+============
+*/
+void Cbuf_Init (void)
+{
+ SZ_Alloc (&cmd_text, 8192); // space for commands and script files
+}
+
+
+/*
+============
+Cbuf_AddText
+
+Adds command text at the end of the buffer
+============
+*/
+void Cbuf_AddText (char *text)
+{
+ int l;
+
+ l = Q_strlen (text);
+
+ if (cmd_text.cursize + l >= cmd_text.maxsize)
+ {
+ Con_Printf ("Cbuf_AddText: overflow\n");
+ return;
+ }
+
+ SZ_Write (&cmd_text, text, Q_strlen (text));
+}
+
+
+/*
+============
+Cbuf_InsertText
+
+FW19: before???
+
+Adds command text immediately after the current command
+Adds a \n to the text
+FIXME: actually change the command buffer to do less copying
+============
+*/
+void Cbuf_InsertText (char *text)
+{
+ char *temp;
+ int templen;
+
+// copy off any commands still remaining in the exec buffer
+ templen = cmd_text.cursize;
+ if (templen)
+ {
+ temp = Z_Malloc (templen);
+ Q_memcpy (temp, cmd_text.data, templen);
+ SZ_Clear (&cmd_text);
+ }
+ else
+ temp = NULL; // shut up compiler
+
+// add the entire text of the file
+ Cbuf_AddText (text);
+
+// add the copied off data
+ if (templen)
+ {
+ SZ_Write (&cmd_text, temp, templen);
+ Z_Free (temp);
+ }
+}
+
+/*
+============
+Cbuf_Execute
+============
+*/
+void Cbuf_Execute (void)
+{
+ int i;
+ char *text;
+ char line[1024];
+ int quotes;
+
+ while (cmd_text.cursize)
+ {
+// find a \n or ; line break
+ text = (char *)cmd_text.data;
+
+ quotes = 0;
+ for (i=0 ; i< cmd_text.cursize ; i++)
+ {
+ if (text[i] == '"')
+ quotes++;
+ if ( !(quotes&1) && text[i] == ';')
+ break; // don't break if inside a quoted string
+ if (text[i] == '\n')
+ break;
+ }
+
+
+ memcpy (line, text, i);
+ line[i] = 0;
+
+// delete the text from the command buffer and move remaining commands down
+// this is necessary because commands (exec, alias) can insert data at the
+// beginning of the text buffer
+
+ if (i == cmd_text.cursize)
+ cmd_text.cursize = 0;
+ else
+ {
+ i++;
+ cmd_text.cursize -= i;
+ Q_memcpy (text, text+i, cmd_text.cursize);
+ }
+
+// execute the command line
+ Cmd_ExecuteString (line, src_command);
+
+ if (cmd_wait)
+ { // skip out while text still remains in buffer, leaving it
+ // for next frame
+ cmd_wait = false;
+ break;
+ }
+ }
+}
+
+/*
+==============================================================================
+
+ SCRIPT COMMANDS
+
+==============================================================================
+*/
+
+/*
+===============
+Cmd_StuffCmds_f
+
+Adds command line parameters as script statements
+Commands lead with a +, and continue until a - or another +
+quake +prog jctest.qp +cmd amlev1
+quake -nosound +cmd amlev1
+===============
+*/
+void Cmd_StuffCmds_f (void)
+{
+ int i, j;
+ int s;
+ char *text, *build, c;
+
+ if (Cmd_Argc () != 1)
+ {
+ Con_Printf ("stuffcmds : execute command line parameters\n");
+ return;
+ }
+
+// build the combined string to parse from
+ s = 0;
+ for (i=1 ; i<com_argc ; i++)
+ {
+ if (!com_argv[i])
+ continue; // NEXTSTEP nulls out -NXHost
+ s += Q_strlen (com_argv[i]) + 1;
+ }
+ if (!s)
+ return;
+
+ text = Z_Malloc (s+1);
+ text[0] = 0;
+ for (i=1 ; i<com_argc ; i++)
+ {
+ if (!com_argv[i])
+ continue; // NEXTSTEP nulls out -NXHost
+ Q_strcat (text,com_argv[i]);
+ if (i != com_argc-1)
+ Q_strcat (text, " ");
+ }
+
+// pull out the commands
+ build = Z_Malloc (s+1);
+ build[0] = 0;
+
+ for (i=0 ; i<s-1 ; i++)
+ {
+ if (text[i] == '+')
+ {
+ i++;
+
+ for (j=i ; (text[j] != '+') && (text[j] != '-') && (text[j] != 0) ; j++)
+ ;
+
+ c = text[j];
+ text[j] = 0;
+
+ Q_strcat (build, text+i);
+ Q_strcat (build, "\n");
+ text[j] = c;
+ i = j-1;
+ }
+ }
+
+ if (build[0])
+ Cbuf_InsertText (build);
+
+ Z_Free (text);
+ Z_Free (build);
+}
+
+extern int bind_nooverride;
+
+/*
+===============
+Cmd_Exec_f
+===============
+*/
+void Cmd_Exec_f (void)
+{
+ char *f;
+ int mark;
+
+ if (Cmd_Argc () != 2)
+ {
+ Con_Printf ("exec <filename> : execute a script file\n");
+ return;
+ }
+
+
+ mark = Hunk_LowMark ();
+ f = (char *)COM_LoadHunkFile (Cmd_Argv(1));
+ if (!f)
+ {
+ Con_Printf ("couldn't exec %s\n",Cmd_Argv(1));
+ return;
+ }
+ Con_Printf ("execing %s\n",Cmd_Argv(1));
+
+ Cbuf_InsertText (f); // insert to next space in buffer
+ Hunk_FreeToLowMark (mark);
+
+ // if we are running config, tell bind not to override defaults (see keys.c)
+ if(!strcmp(Cmd_Argv(1), "config.cfg"))
+ {
+ // force binds to continue
+ bind_nooverride = 1;
+ }
+ else if(!strcmp(Cmd_Argv(1), "default.cfg"))
+ {
+ // allow override
+ bind_nooverride = 0;
+ }
+}
+
+
+/*
+===============
+Cmd_Echo_f
+
+Just prints the rest of the line to the console
+===============
+*/
+void Cmd_Echo_f (void)
+{
+ int i;
+
+ for (i=1 ; i<Cmd_Argc() ; i++)
+ Con_Printf ("%s ",Cmd_Argv(i));
+ Con_Printf ("\n");
+}
+
+/*
+===============
+Cmd_Alias_f
+
+Creates a new command that executes a command string (possibly ; seperated)
+===============
+*/
+
+char *CopyString (char *in)
+{
+ char *out;
+
+ out = Z_Malloc (strlen(in)+1);
+ strcpy (out, in);
+ return out;
+}
+
+void Cmd_Alias_f (void)
+{
+ cmdalias_t *a;
+ char cmd[1024];
+ int i, c;
+ char *s;
+
+ if (Cmd_Argc() == 1)
+ {
+ Con_Printf ("Current alias commands:\n");
+ for (a = cmd_alias ; a ; a=a->next)
+ Con_Printf ("%s : %s\n", a->name, a->value);
+ return;
+ }
+
+ s = Cmd_Argv(1);
+ if (strlen(s) >= MAX_ALIAS_NAME)
+ {
+ Con_Printf ("Alias name is too long\n");
+ return;
+ }
+
+ // if the alias allready exists, reuse it
+ for (a = cmd_alias ; a ; a=a->next)
+ {
+ if (!strcmp(s, a->name))
+ {
+ Z_Free (a->value);
+ break;
+ }
+ }
+
+ if (!a)
+ {
+ a = Z_Malloc (sizeof(cmdalias_t));
+ a->next = cmd_alias;
+ cmd_alias = a;
+ }
+ strcpy (a->name, s);
+
+// copy the rest of the command line
+ cmd[0] = 0; // start out with a null string
+ c = Cmd_Argc();
+ for (i=2 ; i< c ; i++)
+ {
+ strcat (cmd, Cmd_Argv(i));
+ if (i != c)
+ strcat (cmd, " ");
+ }
+ strcat (cmd, "\n");
+
+ a->value = CopyString (cmd);
+}
+
+/*
+=============================================================================
+
+ COMMAND EXECUTION
+
+=============================================================================
+*/
+
+typedef struct cmd_function_s
+{
+ struct cmd_function_s *next;
+ char *name;
+ xcommand_t function;
+} cmd_function_t;
+
+
+#define MAX_ARGS 80
+
+static int cmd_argc;
+static char *cmd_argv[MAX_ARGS];
+static char *cmd_null_string = "";
+static char *cmd_args = NULL;
+
+cmd_source_t cmd_source;
+
+
+static cmd_function_t *cmd_functions; // possible commands to execute
+
+/*
+============
+Cmd_Init
+============
+*/
+void Cmd_Init (void)
+{
+//
+// register our commands
+//
+ Cmd_AddCommand ("stuffcmds",Cmd_StuffCmds_f);
+ Cmd_AddCommand ("exec",Cmd_Exec_f);
+ Cmd_AddCommand ("echo",Cmd_Echo_f);
+ Cmd_AddCommand ("alias",Cmd_Alias_f);
+ Cmd_AddCommand ("cmd", Cmd_ForwardToServer);
+ Cmd_AddCommand ("wait", Cmd_Wait_f);
+}
+
+/*
+============
+Cmd_Argc
+============
+*/
+int Cmd_Argc (void)
+{
+ return cmd_argc;
+}
+
+/*
+============
+Cmd_Argv
+============
+*/
+char *Cmd_Argv (int arg)
+{
+ if ( (unsigned)arg >= cmd_argc )
+ return cmd_null_string;
+ return cmd_argv[arg];
+}
+
+/*
+============
+Cmd_Args
+============
+*/
+char *Cmd_Args (void)
+{
+ return cmd_args;
+}
+
+
+/*
+============
+Cmd_TokenizeString
+
+Parses the given string into command line tokens.
+============
+*/
+void Cmd_TokenizeString (char *text)
+{
+ int i;
+
+// clear the args from the last string
+ for (i=0 ; i<cmd_argc ; i++)
+ Z_Free (cmd_argv[i]);
+
+ cmd_argc = 0;
+ cmd_args = NULL;
+
+ while (1)
+ {
+// skip whitespace up to a /n
+ while (*text && *text <= ' ' && *text != '\n')
+ {
+ text++;
+ }
+
+ if (*text == '\n')
+ { // a newline seperates commands in the buffer
+ text++;
+ break;
+ }
+
+ if (!*text)
+ return;
+
+ if (cmd_argc == 1)
+ cmd_args = text;
+
+ text = COM_Parse (text);
+ if (!text)
+ return;
+
+ if (cmd_argc < MAX_ARGS)
+ {
+ cmd_argv[cmd_argc] = Z_Malloc (Q_strlen(com_token)+1);
+ Q_strcpy (cmd_argv[cmd_argc], com_token);
+ cmd_argc++;
+ }
+ }
+
+}
+
+
+/*
+============
+Cmd_AddCommand
+============
+*/
+void Cmd_AddCommand (char *cmd_name, xcommand_t function)
+{
+ cmd_function_t *cmd;
+
+ if (host_initialized) // because hunk allocation would get stomped
+ Sys_Error ("Cmd_AddCommand after host_initialized");
+
+// fail if the command is a variable name
+ if (Cvar_VariableString(cmd_name)[0])
+ {
+ Con_Printf ("Cmd_AddCommand: %s already defined as a var\n", cmd_name);
+ return;
+ }
+
+// fail if the command already exists
+ for (cmd=cmd_functions ; cmd ; cmd=cmd->next)
+ {
+ if (!Q_strcmp (cmd_name, cmd->name))
+ {
+ Con_Printf ("Cmd_AddCommand: %s already defined\n", cmd_name);
+ return;
+ }
+ }
+
+ cmd = Hunk_Alloc (sizeof(cmd_function_t));
+ cmd->name = cmd_name;
+ cmd->function = function;
+ cmd->next = cmd_functions;
+ cmd_functions = cmd;
+}
+
+/*
+============
+Cmd_Exists
+============
+*/
+qboolean Cmd_Exists (char *cmd_name)
+{
+ cmd_function_t *cmd;
+
+ for (cmd=cmd_functions ; cmd ; cmd=cmd->next)
+ {
+ if (!Q_strcmp (cmd_name,cmd->name))
+ return true;
+ }
+
+ return false;
+}
+
+
+
+/*
+============
+Cmd_CompleteCommand
+============
+*/
+char *Cmd_CompleteCommand (char *partial)
+{
+ cmd_function_t *cmd;
+ int len;
+
+ len = Q_strlen(partial);
+
+ if (!len)
+ return NULL;
+
+// check functions
+ for (cmd=cmd_functions ; cmd ; cmd=cmd->next)
+ if (!Q_strncmp (partial,cmd->name, len))
+ return cmd->name;
+
+ return NULL;
+}
+
+/*
+============
+Cmd_ExecuteString
+
+A complete command line has been parsed, so try to execute it
+FIXME: lookupnoadd the token to speed search?
+============
+*/
+void Cmd_ExecuteString (char *text, cmd_source_t src)
+{
+ cmd_function_t *cmd;
+ cmdalias_t *a;
+
+ cmd_source = src;
+ Cmd_TokenizeString (text);
+
+// execute the command line
+ if (!Cmd_Argc())
+ return; // no tokens
+
+// check functions
+ for (cmd=cmd_functions ; cmd ; cmd=cmd->next)
+ {
+ if (!Q_strcasecmp (cmd_argv[0],cmd->name))
+ {
+ cmd->function ();
+ return;
+ }
+ }
+
+// check alias
+ for (a=cmd_alias ; a ; a=a->next)
+ {
+ if (!Q_strcasecmp (cmd_argv[0], a->name))
+ {
+ Cbuf_InsertText (a->value);
+ return;
+ }
+ }
+
+// check cvars
+ if (!Cvar_Command ())
+ Con_Printf ("Unknown command \"%s\"\n", Cmd_Argv(0));
+
+}
+
+
+/*
+===================
+Cmd_ForwardToServer
+
+Sends the entire command line over to the server
+===================
+*/
+void Cmd_ForwardToServer (void)
+{
+ if (cls.state != ca_connected)
+ {
+ Con_Printf ("Can't \"%s\", not connected\n", Cmd_Argv(0));
+ return;
+ }
+
+ if (cls.demoplayback)
+ return; // not really connected
+
+ MSG_WriteByte (&cls.message, clc_stringcmd);
+ if (Q_strcasecmp(Cmd_Argv(0), "cmd") != 0)
+ {
+ SZ_Print (&cls.message, Cmd_Argv(0));
+ SZ_Print (&cls.message, " ");
+ }
+ if (Cmd_Argc() > 1)
+ SZ_Print (&cls.message, Cmd_Args());
+ else
+ SZ_Print (&cls.message, "\n");
+}
+
+
+/*
+================
+Cmd_CheckParm
+
+Returns the position (1 to argc-1) in the command's argument list
+where the given parameter apears, or 0 if not present
+================
+*/
+
+int Cmd_CheckParm (char *parm)
+{
+ int i;
+
+ if (!parm)
+ Sys_Error ("Cmd_CheckParm: NULL");
+
+ for (i = 1; i < Cmd_Argc (); i++)
+ if (! Q_strcasecmp (parm, Cmd_Argv (i)))
+ return i;
+
+ return 0;
+}
diff --git a/apps/plugins/sdl/progs/quake/cmd.h b/apps/plugins/sdl/progs/quake/cmd.h
new file mode 100644
index 0000000000..d4a0dd9b63
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/cmd.h
@@ -0,0 +1,123 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+
+// cmd.h -- Command buffer and command execution
+
+//===========================================================================
+
+/*
+
+Any number of commands can be added in a frame, from several different sources.
+Most commands come from either keybindings or console line input, but remote
+servers can also send across commands and entire text files can be execed.
+
+The + command line options are also added to the command buffer.
+
+The game starts with a Cbuf_AddText ("exec quake.rc\n"); Cbuf_Execute ();
+
+*/
+
+
+void Cbuf_Init (void);
+// allocates an initial text buffer that will grow as needed
+
+void Cbuf_AddText (char *text);
+// as new commands are generated from the console or keybindings,
+// the text is added to the end of the command buffer.
+
+void Cbuf_InsertText (char *text);
+// when a command wants to issue other commands immediately, the text is
+// inserted at the beginning of the buffer, before any remaining unexecuted
+// commands.
+
+void Cbuf_Execute (void);
+// Pulls off \n terminated lines of text from the command buffer and sends
+// them through Cmd_ExecuteString. Stops when the buffer is empty.
+// Normally called once per frame, but may be explicitly invoked.
+// Do not call inside a command function!
+
+//===========================================================================
+
+/*
+
+Command execution takes a null terminated string, breaks it into tokens,
+then searches for a command or variable that matches the first token.
+
+Commands can come from three sources, but the handler functions may choose
+to dissallow the action or forward it to a remote server if the source is
+not apropriate.
+
+*/
+
+typedef void (*xcommand_t) (void);
+
+typedef int cmd_source_t;
+
+enum
+{
+ src_client, // came in over a net connection as a clc_stringcmd
+ // host_client will be valid during this state.
+ src_command // from the command buffer
+};
+
+extern cmd_source_t cmd_source;
+
+void Cmd_Init (void);
+
+void Cmd_AddCommand (char *cmd_name, xcommand_t function);
+// called by the init functions of other parts of the program to
+// register commands and functions to call for them.
+// The cmd_name is referenced later, so it should not be in temp memory
+
+qboolean Cmd_Exists (char *cmd_name);
+// used by the cvar code to check for cvar / command name overlap
+
+char *Cmd_CompleteCommand (char *partial);
+// attempts to match a partial command for automatic command line completion
+// returns NULL if nothing fits
+
+int Cmd_Argc (void);
+char *Cmd_Argv (int arg);
+char *Cmd_Args (void);
+// The functions that execute commands get their parameters with these
+// functions. Cmd_Argv () will return an empty string, not a NULL
+// if arg > argc, so string operations are allways safe.
+
+int Cmd_CheckParm (char *parm);
+// Returns the position (1 to argc-1) in the command's argument list
+// where the given parameter apears, or 0 if not present
+
+void Cmd_TokenizeString (char *text);
+// Takes a null terminated string. Does not need to be /n terminated.
+// breaks the string up into arg tokens.
+
+void Cmd_ExecuteString (char *text, cmd_source_t src);
+// Parses a single line of text into arguments and tries to execute it.
+// The text can come from the command buffer, a remote client, or stdin.
+
+void Cmd_ForwardToServer (void);
+// adds the current command line as a clc_stringcmd to the client message.
+// things like godmode, noclip, etc, are commands directed to the server,
+// so when they are typed in at the console, they will need to be forwarded.
+
+void Cmd_Print (char *text);
+// used by command functions to send output to either the graphics console or
+// passed as a print message to the client
+
diff --git a/apps/plugins/sdl/progs/quake/common.c b/apps/plugins/sdl/progs/quake/common.c
new file mode 100644
index 0000000000..11be234834
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/common.c
@@ -0,0 +1,1856 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// common.c -- misc functions used in client and server
+
+#include "quakedef.h"
+
+#define NUM_SAFE_ARGVS 7
+
+static char *largv[MAX_NUM_ARGVS + NUM_SAFE_ARGVS + 1];
+static char *argvdummy = " ";
+
+static char *safeargvs[NUM_SAFE_ARGVS] =
+ {"-stdvid", "-nolan", "-nosound", "-nocdaudio", "-nojoy", "-nomouse", "-dibonly"};
+
+cvar_t registered = {"registered","0"};
+cvar_t cmdline = {"cmdline","0", false, true};
+
+qboolean com_modified; // set true if using non-id files
+
+qboolean proghack;
+
+int static_registered = 1; // only for startup check, then set
+
+qboolean msg_suppress_1 = 0;
+
+void COM_InitFilesystem (void);
+
+// if a packfile directory differs from this, it is assumed to be hacked
+#define PAK0_COUNT 339
+#define PAK0_CRC 32981
+
+char com_token[1024];
+int com_argc;
+char **com_argv;
+
+#define CMDLINE_LENGTH 256
+char com_cmdline[CMDLINE_LENGTH];
+
+qboolean standard_quake = true, rogue, hipnotic;
+
+// this graphic needs to be in the pak file to use registered features
+unsigned short pop[] =
+{
+ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
+,0x0000,0x0000,0x6600,0x0000,0x0000,0x0000,0x6600,0x0000
+,0x0000,0x0066,0x0000,0x0000,0x0000,0x0000,0x0067,0x0000
+,0x0000,0x6665,0x0000,0x0000,0x0000,0x0000,0x0065,0x6600
+,0x0063,0x6561,0x0000,0x0000,0x0000,0x0000,0x0061,0x6563
+,0x0064,0x6561,0x0000,0x0000,0x0000,0x0000,0x0061,0x6564
+,0x0064,0x6564,0x0000,0x6469,0x6969,0x6400,0x0064,0x6564
+,0x0063,0x6568,0x6200,0x0064,0x6864,0x0000,0x6268,0x6563
+,0x0000,0x6567,0x6963,0x0064,0x6764,0x0063,0x6967,0x6500
+,0x0000,0x6266,0x6769,0x6a68,0x6768,0x6a69,0x6766,0x6200
+,0x0000,0x0062,0x6566,0x6666,0x6666,0x6666,0x6562,0x0000
+,0x0000,0x0000,0x0062,0x6364,0x6664,0x6362,0x0000,0x0000
+,0x0000,0x0000,0x0000,0x0062,0x6662,0x0000,0x0000,0x0000
+,0x0000,0x0000,0x0000,0x0061,0x6661,0x0000,0x0000,0x0000
+,0x0000,0x0000,0x0000,0x0000,0x6500,0x0000,0x0000,0x0000
+,0x0000,0x0000,0x0000,0x0000,0x6400,0x0000,0x0000,0x0000
+};
+
+/*
+
+
+All of Quake's data access is through a hierchal file system, but the contents of the file system can be transparently merged from several sources.
+
+The "base directory" is the path to the directory holding the quake.exe and all game directories. The sys_* files pass this to host_init in quakeparms_t->basedir. This can be overridden with the "-basedir" command line parm to allow code debugging in a different directory. The base directory is
+only used during filesystem initialization.
+
+The "game directory" is the first tree on the search path and directory that all generated files (savegames, screenshots, demos, config files) will be saved to. This can be overridden with the "-game" command line parameter. The game directory can never be changed while quake is executing. This is a precacution against having a malicious server instruct clients to write files over areas they shouldn't.
+
+The "cache directory" is only used during development to save network bandwidth, especially over ISDN / T1 lines. If there is a cache directory
+specified, when a file is found by the normal search path, it will be mirrored
+into the cache directory, then opened there.
+
+
+
+FIXME:
+The file "parms.txt" will be read out of the game directory and appended to the current command line arguments to allow different games to initialize startup parms differently. This could be used to add a "-sspeed 22050" for the high quality sound edition. Because they are added at the end, they will not override an explicit setting on the original command line.
+
+*/
+
+//============================================================================
+
+
+// ClearLink is used for new headnodes
+void ClearLink (link_t *l)
+{
+ l->prev = l->next = l;
+}
+
+void RemoveLink (link_t *l)
+{
+ l->next->prev = l->prev;
+ l->prev->next = l->next;
+}
+
+void InsertLinkBefore (link_t *l, link_t *before)
+{
+ l->next = before;
+ l->prev = before->prev;
+ l->prev->next = l;
+ l->next->prev = l;
+}
+void InsertLinkAfter (link_t *l, link_t *after)
+{
+ l->next = after->next;
+ l->prev = after;
+ l->prev->next = l;
+ l->next->prev = l;
+}
+
+/*
+============================================================================
+
+ LIBRARY REPLACEMENT FUNCTIONS
+
+============================================================================
+*/
+
+void Q_memset (void *dest, int fill, int count)
+{
+ int i;
+
+ if ( (((long)dest | count) & 3) == 0)
+ {
+ count >>= 2;
+ fill = fill | (fill<<8) | (fill<<16) | (fill<<24);
+ for (i=0 ; i<count ; i++)
+ ((int *)dest)[i] = fill;
+ }
+ else
+ for (i=0 ; i<count ; i++)
+ ((byte *)dest)[i] = fill;
+}
+
+void Q_memcpy (void *dest, void *src, int count)
+{
+ int i;
+
+ if (( ( (long)dest | (long)src | count) & 3) == 0 )
+ {
+ count>>=2;
+ for (i=0 ; i<count ; i++)
+ ((int *)dest)[i] = ((int *)src)[i];
+ }
+ else
+ for (i=0 ; i<count ; i++)
+ ((byte *)dest)[i] = ((byte *)src)[i];
+}
+
+int Q_memcmp (void *m1, void *m2, int count)
+{
+ while(count)
+ {
+ count--;
+ if (((byte *)m1)[count] != ((byte *)m2)[count])
+ return -1;
+ }
+ return 0;
+}
+
+void Q_strcpy (char *dest, char *src)
+{
+ while (*src)
+ {
+ *dest++ = *src++;
+ }
+ *dest++ = 0;
+}
+
+void Q_strncpy (char *dest, char *src, int count)
+{
+ while (*src && count--)
+ {
+ *dest++ = *src++;
+ }
+ if (count)
+ *dest++ = 0;
+}
+
+int Q_strlen (char *str)
+{
+ int count;
+
+ count = 0;
+ while (str[count])
+ count++;
+
+ return count;
+}
+
+char *Q_strrchr(char *s, char c)
+{
+ int len = Q_strlen(s);
+ s += len;
+ while (len--)
+ if (*--s == c) return s;
+ return 0;
+}
+
+void Q_strcat (char *dest, char *src)
+{
+ dest += Q_strlen(dest);
+ Q_strcpy (dest, src);
+}
+
+int Q_strcmp (char *s1, char *s2)
+{
+ while (1)
+ {
+ if (*s1 != *s2)
+ return -1; // strings not equal
+ if (!*s1)
+ return 0; // strings are equal
+ s1++;
+ s2++;
+ }
+
+ return -1;
+}
+
+int Q_strncmp (char *s1, char *s2, int count)
+{
+ while (1)
+ {
+ if (!count--)
+ return 0;
+ if (*s1 != *s2)
+ return -1; // strings not equal
+ if (!*s1)
+ return 0; // strings are equal
+ s1++;
+ s2++;
+ }
+
+ return -1;
+}
+
+int Q_strncasecmp (char *s1, char *s2, int n)
+{
+ int c1, c2;
+
+ while (1)
+ {
+ c1 = *s1++;
+ c2 = *s2++;
+
+ if (!n--)
+ return 0; // strings are equal until end point
+
+ if (c1 != c2)
+ {
+ if (c1 >= 'a' && c1 <= 'z')
+ c1 -= ('a' - 'A');
+ if (c2 >= 'a' && c2 <= 'z')
+ c2 -= ('a' - 'A');
+ if (c1 != c2)
+ return -1; // strings not equal
+ }
+ if (!c1)
+ return 0; // strings are equal
+// s1++;
+// s2++;
+ }
+
+ return -1;
+}
+
+int Q_strcasecmp (char *s1, char *s2)
+{
+ return Q_strncasecmp (s1, s2, 99999);
+}
+
+int Q_atoi (char *str)
+{
+ int val;
+ int sign;
+ int c;
+
+ if (*str == '-')
+ {
+ sign = -1;
+ str++;
+ }
+ else
+ sign = 1;
+
+ val = 0;
+
+//
+// check for hex
+//
+ if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X') )
+ {
+ str += 2;
+ while (1)
+ {
+ c = *str++;
+ if (c >= '0' && c <= '9')
+ val = (val<<4) + c - '0';
+ else if (c >= 'a' && c <= 'f')
+ val = (val<<4) + c - 'a' + 10;
+ else if (c >= 'A' && c <= 'F')
+ val = (val<<4) + c - 'A' + 10;
+ else
+ return val*sign;
+ }
+ }
+
+//
+// check for character
+//
+ if (str[0] == '\'')
+ {
+ return sign * str[1];
+ }
+
+//
+// assume decimal
+//
+ while (1)
+ {
+ c = *str++;
+ if (c <'0' || c > '9')
+ return val*sign;
+ val = val*10 + c - '0';
+ }
+
+ return 0;
+}
+
+
+float Q_atof (char *str)
+{
+ double val;
+ int sign;
+ int c;
+ int decimal, total;
+
+ if (*str == '-')
+ {
+ sign = -1;
+ str++;
+ }
+ else
+ sign = 1;
+
+ val = 0;
+
+//
+// check for hex
+//
+ if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X') )
+ {
+ str += 2;
+ while (1)
+ {
+ c = *str++;
+ if (c >= '0' && c <= '9')
+ val = (val*16) + c - '0';
+ else if (c >= 'a' && c <= 'f')
+ val = (val*16) + c - 'a' + 10;
+ else if (c >= 'A' && c <= 'F')
+ val = (val*16) + c - 'A' + 10;
+ else
+ return val*sign;
+ }
+ }
+
+//
+// check for character
+//
+ if (str[0] == '\'')
+ {
+ return sign * str[1];
+ }
+
+//
+// assume decimal
+//
+ decimal = -1;
+ total = 0;
+ while (1)
+ {
+ c = *str++;
+ if (c == '.')
+ {
+ decimal = total;
+ continue;
+ }
+ if (c <'0' || c > '9')
+ break;
+ val = val*10 + c - '0';
+ total++;
+ }
+
+ if (decimal == -1)
+ return val*sign;
+ while (total > decimal)
+ {
+ val /= 10;
+ total--;
+ }
+
+ return val*sign;
+}
+
+/*
+============================================================================
+
+ BYTE ORDER FUNCTIONS
+
+============================================================================
+*/
+
+#ifdef SDL
+#include "SDL_byteorder.h"
+#endif
+
+qboolean bigendien;
+
+short (*BigShort) (short l);
+short (*LittleShort) (short l);
+int (*BigLong) (int l);
+int (*LittleLong) (int l);
+float (*BigFloat) (float l);
+float (*LittleFloat) (float l);
+
+short ShortSwap (short l)
+{
+ byte b1,b2;
+
+ b1 = l&255;
+ b2 = (l>>8)&255;
+
+ return (b1<<8) + b2;
+}
+
+short ShortNoSwap (short l)
+{
+ return l;
+}
+
+int LongSwap (int l)
+{
+ byte b1,b2,b3,b4;
+
+ b1 = l&255;
+ b2 = (l>>8)&255;
+ b3 = (l>>16)&255;
+ b4 = (l>>24)&255;
+
+ return ((int)b1<<24) + ((int)b2<<16) + ((int)b3<<8) + b4;
+}
+
+int LongNoSwap (int l)
+{
+ return l;
+}
+
+float FloatSwap (float f)
+{
+ union
+ {
+ float f;
+ byte b[4];
+ } dat1, dat2;
+
+
+ dat1.f = f;
+ dat2.b[0] = dat1.b[3];
+ dat2.b[1] = dat1.b[2];
+ dat2.b[2] = dat1.b[1];
+ dat2.b[3] = dat1.b[0];
+ return dat2.f;
+}
+
+float FloatNoSwap (float f)
+{
+ return f;
+}
+
+/*
+==============================================================================
+
+ MESSAGE IO FUNCTIONS
+
+Handles byte ordering and avoids alignment errors
+==============================================================================
+*/
+
+//
+// writing functions
+//
+
+void MSG_WriteChar (sizebuf_t *sb, int c)
+{
+ byte *buf;
+
+#ifdef PARANOID
+ if (c < -128 || c > 127)
+ Sys_Error ("MSG_WriteChar: range error");
+#endif
+
+ buf = SZ_GetSpace (sb, 1);
+ buf[0] = c;
+}
+
+void MSG_WriteByte (sizebuf_t *sb, int c)
+{
+ byte *buf;
+
+#ifdef PARANOID
+ if (c < 0 || c > 255)
+ Sys_Error ("MSG_WriteByte: range error");
+#endif
+
+ buf = SZ_GetSpace (sb, 1);
+ buf[0] = c;
+}
+
+void MSG_WriteShort (sizebuf_t *sb, int c)
+{
+ byte *buf;
+
+#ifdef PARANOID
+ if (c < ((short)0x8000) || c > (short)0x7fff)
+ Sys_Error ("MSG_WriteShort: range error");
+#endif
+
+ buf = SZ_GetSpace (sb, 2);
+ buf[0] = c&0xff;
+ buf[1] = c>>8;
+}
+
+void MSG_WriteLong (sizebuf_t *sb, int c)
+{
+ byte *buf;
+
+ buf = SZ_GetSpace (sb, 4);
+ buf[0] = c&0xff;
+ buf[1] = (c>>8)&0xff;
+ buf[2] = (c>>16)&0xff;
+ buf[3] = c>>24;
+}
+
+void MSG_WriteFloat (sizebuf_t *sb, float f)
+{
+ union
+ {
+ float f;
+ int l;
+ } dat;
+
+
+ dat.f = f;
+ dat.l = LittleLong (dat.l);
+
+ SZ_Write (sb, &dat.l, 4);
+}
+
+void MSG_WriteString (sizebuf_t *sb, char *s)
+{
+ if (!s)
+ SZ_Write (sb, "", 1);
+ else
+ SZ_Write (sb, s, Q_strlen(s)+1);
+}
+
+void MSG_WriteCoord (sizebuf_t *sb, float f)
+{
+ MSG_WriteShort (sb, (int)(f*8));
+}
+
+void MSG_WriteAngle (sizebuf_t *sb, float f)
+{
+ MSG_WriteByte (sb, ((int)f*256/360) & 255);
+}
+
+//
+// reading functions
+//
+int msg_readcount;
+qboolean msg_badread;
+
+void MSG_BeginReading (void)
+{
+ msg_readcount = 0;
+ msg_badread = false;
+}
+
+// returns -1 and sets msg_badread if no more characters are available
+int MSG_ReadChar (void)
+{
+ int c;
+
+ if (msg_readcount+1 > net_message.cursize)
+ {
+ msg_badread = true;
+ return -1;
+ }
+
+ c = (signed char)net_message.data[msg_readcount];
+ msg_readcount++;
+
+ return c;
+}
+
+int MSG_ReadByte (void)
+{
+ int c;
+
+ if (msg_readcount+1 > net_message.cursize)
+ {
+ msg_badread = true;
+ return -1;
+ }
+
+ c = (unsigned char)net_message.data[msg_readcount];
+ msg_readcount++;
+
+ return c;
+}
+
+int MSG_ReadShort (void)
+{
+ int c;
+
+ if (msg_readcount+2 > net_message.cursize)
+ {
+ msg_badread = true;
+ return -1;
+ }
+
+ c = (short)(net_message.data[msg_readcount]
+ + (net_message.data[msg_readcount+1]<<8));
+
+ msg_readcount += 2;
+
+ return c;
+}
+
+int MSG_ReadLong (void)
+{
+ int c;
+
+ if (msg_readcount+4 > net_message.cursize)
+ {
+ msg_badread = true;
+ return -1;
+ }
+
+ c = net_message.data[msg_readcount]
+ + (net_message.data[msg_readcount+1]<<8)
+ + (net_message.data[msg_readcount+2]<<16)
+ + (net_message.data[msg_readcount+3]<<24);
+
+ msg_readcount += 4;
+
+ return c;
+}
+
+float MSG_ReadFloat (void)
+{
+ union
+ {
+ byte b[4];
+ float f;
+ int l;
+ } dat;
+
+ dat.b[0] = net_message.data[msg_readcount];
+ dat.b[1] = net_message.data[msg_readcount+1];
+ dat.b[2] = net_message.data[msg_readcount+2];
+ dat.b[3] = net_message.data[msg_readcount+3];
+ msg_readcount += 4;
+
+ dat.l = LittleLong (dat.l);
+
+ return dat.f;
+}
+
+char *MSG_ReadString (void)
+{
+ static char string[2048];
+ int l,c;
+
+ l = 0;
+ do
+ {
+ c = MSG_ReadChar ();
+ if (c == -1 || c == 0)
+ break;
+ string[l] = c;
+ l++;
+ } while (l < sizeof(string)-1);
+
+ string[l] = 0;
+
+ return string;
+}
+
+float MSG_ReadCoord (void)
+{
+ return MSG_ReadShort() * (1.0/8);
+}
+
+float MSG_ReadAngle (void)
+{
+ return MSG_ReadChar() * (360.0/256);
+}
+
+
+
+//===========================================================================
+
+void SZ_Alloc (sizebuf_t *buf, int startsize)
+{
+ if (startsize < 256)
+ startsize = 256;
+ buf->data = Hunk_AllocName (startsize, "sizebuf");
+ buf->maxsize = startsize;
+ buf->cursize = 0;
+}
+
+
+void SZ_Free (sizebuf_t *buf)
+{
+// Z_Free (buf->data);
+// buf->data = NULL;
+// buf->maxsize = 0;
+ buf->cursize = 0;
+}
+
+void SZ_Clear (sizebuf_t *buf)
+{
+ buf->cursize = 0;
+}
+
+void *SZ_GetSpace (sizebuf_t *buf, int length)
+{
+ void *data;
+
+ if (buf->cursize + length > buf->maxsize)
+ {
+ if (!buf->allowoverflow)
+ Sys_Error ("SZ_GetSpace: overflow without allowoverflow set");
+
+ if (length > buf->maxsize)
+ Sys_Error ("SZ_GetSpace: %i is > full buffer size", length);
+
+ buf->overflowed = true;
+ Con_Printf ("SZ_GetSpace: overflow");
+ SZ_Clear (buf);
+ }
+
+ data = buf->data + buf->cursize;
+ buf->cursize += length;
+
+ return data;
+}
+
+void SZ_Write (sizebuf_t *buf, void *data, int length)
+{
+ Q_memcpy (SZ_GetSpace(buf,length),data,length);
+}
+
+void SZ_Print (sizebuf_t *buf, char *data)
+{
+ int len;
+
+ len = Q_strlen(data)+1;
+
+// byte * cast to keep VC++ happy
+ if (buf->data[buf->cursize-1])
+ Q_memcpy ((byte *)SZ_GetSpace(buf, len),data,len); // no trailing 0
+ else
+ Q_memcpy ((byte *)SZ_GetSpace(buf, len-1)-1,data,len); // write over trailing 0
+}
+
+
+//============================================================================
+
+
+/*
+============
+COM_SkipPath
+============
+*/
+char *COM_SkipPath (char *pathname)
+{
+ char *last;
+
+ last = pathname;
+ while (*pathname)
+ {
+ if (*pathname=='/')
+ last = pathname+1;
+ pathname++;
+ }
+ return last;
+}
+
+/*
+============
+COM_StripExtension
+============
+*/
+void COM_StripExtension (char *in, char *out)
+{
+ while (*in && *in != '.')
+ *out++ = *in++;
+ *out = 0;
+}
+
+/*
+============
+COM_FileExtension
+============
+*/
+char *COM_FileExtension (char *in)
+{
+ static char exten[8];
+ int i;
+
+ while (*in && *in != '.')
+ in++;
+ if (!*in)
+ return "";
+ in++;
+ for (i=0 ; i<7 && *in ; i++,in++)
+ exten[i] = *in;
+ exten[i] = 0;
+ return exten;
+}
+
+/*
+============
+COM_FileBase
+============
+*/
+int *check_ptr = NULL;
+
+void COM_FileBase (char *in, char *out)
+{
+ char *s, *s2;
+
+ s = in + strlen(in) - 1;
+
+ while (s != in && *s != '.')
+ s--;
+
+ for (s2 = s ; *s2 && *s2 != '/' && s2 != in; s2--)
+ ;
+
+ if (s-s2 < 2)
+ {
+ strcpy (out,"?model?");
+ }
+ else
+ {
+ /* BUG */
+ s--;
+ //printf("writing %d bytes to outbuf", s-s2);
+ Q_strncpy (out,s2+1, s-s2);
+ out[s-s2] = 0;
+ }
+}
+
+
+/*
+==================
+COM_DefaultExtension
+==================
+*/
+void COM_DefaultExtension (char *path, char *extension)
+{
+ char *src;
+//
+// if path doesn't have a .EXT, append extension
+// (extension should include the .)
+//
+ src = path + strlen(path) - 1;
+
+ while (*src != '/' && src != path)
+ {
+ if (*src == '.')
+ return; // it has an extension
+ src--;
+ }
+
+ strcat (path, extension);
+}
+
+
+/*
+==============
+COM_Parse
+
+Parse a token out of a string
+==============
+*/
+char *COM_Parse (char *data)
+{
+ int c;
+ int len;
+
+ len = 0;
+ com_token[0] = 0;
+
+ if (!data)
+ return NULL;
+
+// skip whitespace
+skipwhite:
+ while ( (c = *data) <= ' ')
+ {
+ if (c == 0)
+ return NULL; // end of file;
+ data++;
+ }
+
+// skip // comments
+ if (c=='/' && data[1] == '/')
+ {
+ while (*data && *data != '\n')
+ data++;
+ goto skipwhite;
+ }
+
+
+// handle quoted strings specially
+ if (c == '\"')
+ {
+ data++;
+ while (1)
+ {
+ c = *data++;
+ if (c=='\"' || !c)
+ {
+ com_token[len] = 0;
+ return data;
+ }
+ com_token[len] = c;
+ len++;
+ }
+ }
+
+// parse single characters
+ if (c=='{' || c=='}'|| c==')'|| c=='(' || c=='\'' || c==':')
+ {
+ com_token[len] = c;
+ len++;
+ com_token[len] = 0;
+ return data+1;
+ }
+
+// parse a regular word
+ do
+ {
+ com_token[len] = c;
+ data++;
+ len++;
+ c = *data;
+ if (c=='{' || c=='}'|| c==')'|| c=='(' || c=='\'' || c==':')
+ break;
+ } while (c>32);
+
+ com_token[len] = 0;
+ return data;
+}
+
+
+/*
+================
+COM_CheckParm
+
+Returns the position (1 to argc-1) in the program's argument list
+where the given parameter apears, or 0 if not present
+================
+*/
+int COM_CheckParm (char *parm)
+{
+ int i;
+
+ for (i=1 ; i<com_argc ; i++)
+ {
+ if (!com_argv[i])
+ continue; // NEXTSTEP sometimes clears appkit vars.
+ if (!Q_strcmp (parm,com_argv[i]))
+ return i;
+ }
+
+ return 0;
+}
+
+/*
+================
+COM_CheckRegistered
+
+Looks for the pop.txt file and verifies it.
+Sets the "registered" cvar.
+Immediately exits out if an alternate game was attempted to be started without
+being registered.
+================
+*/
+void COM_CheckRegistered (void)
+{
+ int h;
+ unsigned short check[128];
+ int i;
+
+ COM_OpenFile("gfx/pop.lmp", &h);
+ static_registered = 0;
+
+ if (h == -1)
+ {
+#if WINDED
+ Sys_Error ("This dedicated server requires a full registered copy of Quake");
+#endif
+ Con_Printf ("Playing shareware version.\n");
+ if (com_modified)
+ Sys_Error ("You must have the registered version to use modified games");
+ return;
+ }
+
+ Sys_FileRead (h, check, sizeof(check));
+ COM_CloseFile (h);
+
+ for (i=0 ; i<128 ; i++)
+ if (pop[i] != (unsigned short)BigShort (check[i]))
+ Sys_Error ("Corrupted data file.");
+
+ Cvar_Set ("cmdline", com_cmdline);
+ Cvar_Set ("registered", "1");
+ static_registered = 1;
+ Con_Printf ("Playing registered version.\n");
+}
+
+
+void COM_Path_f (void);
+
+
+/*
+================
+COM_InitArgv
+================
+*/
+void COM_InitArgv (int argc, char **argv)
+{
+ qboolean safe;
+ int i, j, n;
+
+// reconstitute the command line for the cmdline externally visible cvar
+ n = 0;
+
+ for (j=0 ; (j<MAX_NUM_ARGVS) && (j< argc) ; j++)
+ {
+ i = 0;
+
+ while ((n < (CMDLINE_LENGTH - 1)) && argv[j][i])
+ {
+ com_cmdline[n++] = argv[j][i++];
+ }
+
+ if (n < (CMDLINE_LENGTH - 1))
+ com_cmdline[n++] = ' ';
+ else
+ break;
+ }
+
+ com_cmdline[n] = 0;
+
+ safe = false;
+
+ for (com_argc=0 ; (com_argc<MAX_NUM_ARGVS) && (com_argc < argc) ;
+ com_argc++)
+ {
+ largv[com_argc] = argv[com_argc];
+ if (!Q_strcmp ("-safe", argv[com_argc]))
+ safe = true;
+ }
+
+ if (safe)
+ {
+ // force all the safe-mode switches. Note that we reserved extra space in
+ // case we need to add these, so we don't need an overflow check
+ for (i=0 ; i<NUM_SAFE_ARGVS ; i++)
+ {
+ largv[com_argc] = safeargvs[i];
+ com_argc++;
+ }
+ }
+
+ largv[com_argc] = argvdummy;
+ com_argv = largv;
+
+ if (COM_CheckParm ("-rogue"))
+ {
+ rogue = true;
+ standard_quake = false;
+ }
+
+ if (COM_CheckParm ("-hipnotic"))
+ {
+ hipnotic = true;
+ standard_quake = false;
+ }
+}
+
+
+/*
+================
+COM_Init
+================
+*/
+void COM_Init (char *basedir)
+{
+ byte swaptest[2] = {1,0};
+
+// set the byte swapping variables in a portable manner
+#ifdef SDL
+ // This is necessary because egcs 1.1.1 mis-compiles swaptest with -O2
+ if ( SDL_BYTEORDER == SDL_LIL_ENDIAN )
+#else
+ if ( *(short *)swaptest == 1)
+#endif
+ {
+ bigendien = false;
+ BigShort = ShortSwap;
+ LittleShort = ShortNoSwap;
+ BigLong = LongSwap;
+ LittleLong = LongNoSwap;
+ BigFloat = FloatSwap;
+ LittleFloat = FloatNoSwap;
+ }
+ else
+ {
+ bigendien = true;
+ BigShort = ShortNoSwap;
+ LittleShort = ShortSwap;
+ BigLong = LongNoSwap;
+ LittleLong = LongSwap;
+ BigFloat = FloatNoSwap;
+ LittleFloat = FloatSwap;
+ }
+
+ Cvar_RegisterVariable (&registered);
+ Cvar_RegisterVariable (&cmdline);
+ Cmd_AddCommand ("path", COM_Path_f);
+
+ COM_InitFilesystem ();
+ COM_CheckRegistered ();
+}
+
+
+/*
+============
+va
+
+does a varargs printf into a temp buffer, so I don't need to have
+varargs versions of all text functions.
+FIXME: make this buffer size safe someday
+============
+*/
+char *va(char *format, ...)
+{
+ va_list argptr;
+ static char string[1024];
+
+ va_start (argptr, format);
+ vsprintf (string, format,argptr);
+ va_end (argptr);
+
+ return string;
+}
+
+
+/// just for debugging
+int memsearch (byte *start, int count, int search)
+{
+ int i;
+
+ for (i=0 ; i<count ; i++)
+ if (start[i] == search)
+ return i;
+ return -1;
+}
+
+/*
+=============================================================================
+
+QUAKE FILESYSTEM
+
+=============================================================================
+*/
+
+int com_filesize;
+
+
+//
+// in memory
+//
+
+typedef struct
+{
+ char name[MAX_QPATH];
+ int filepos, filelen;
+} packfile_t;
+
+typedef struct pack_s
+{
+ char filename[MAX_OSPATH];
+ int handle;
+ int numfiles;
+ packfile_t *files;
+} pack_t;
+
+//
+// on disk
+//
+typedef struct
+{
+ char name[56];
+ int filepos, filelen;
+} dpackfile_t;
+
+typedef struct
+{
+ char id[4];
+ int dirofs;
+ int dirlen;
+} dpackheader_t;
+
+#define MAX_FILES_IN_PACK 2048
+
+char com_cachedir[MAX_OSPATH];
+char com_gamedir[MAX_OSPATH];
+
+typedef struct searchpath_s
+{
+ char filename[MAX_OSPATH];
+ pack_t *pack; // only one of filename / pack will be used
+ struct searchpath_s *next;
+} searchpath_t;
+
+searchpath_t *com_searchpaths;
+
+/*
+============
+COM_Path_f
+
+============
+*/
+void COM_Path_f (void)
+{
+ searchpath_t *s;
+
+ Con_Printf ("Current search path:\n");
+ for (s=com_searchpaths ; s ; s=s->next)
+ {
+ if (s->pack)
+ {
+ Con_Printf ("%s (%i files)\n", s->pack->filename, s->pack->numfiles);
+ }
+ else
+ Con_Printf ("%s\n", s->filename);
+ }
+}
+
+/*
+============
+COM_WriteFile
+
+The filename will be prefixed by the current game directory
+============
+*/
+void COM_WriteFile (char *filename, void *data, int len)
+{
+ int handle;
+ char name[MAX_OSPATH];
+
+ sprintf (name, "%s/%s", com_gamedir, filename);
+
+ handle = Sys_FileOpenWrite (name);
+ if (handle == -1)
+ {
+ Sys_Printf ("COM_WriteFile: failed on %s\n", name);
+ return;
+ }
+
+ Sys_Printf ("COM_WriteFile: %s\n", name);
+ Sys_FileWrite (handle, data, len);
+ Sys_FileClose (handle);
+}
+
+
+/*
+============
+COM_CreatePath
+
+Only used for CopyFile
+============
+*/
+void COM_CreatePath (char *path)
+{
+ char *ofs;
+
+ for (ofs = path+1 ; *ofs ; ofs++)
+ {
+ if (*ofs == '/')
+ { // create the directory
+ *ofs = 0;
+ Sys_mkdir (path);
+ *ofs = '/';
+ }
+ }
+}
+
+
+/*
+===========
+COM_CopyFile
+
+Copies a file over from the net to the local cache, creating any directories
+needed. This is for the convenience of developers using ISDN from home.
+===========
+*/
+void COM_CopyFile (char *netpath, char *cachepath)
+{
+ int in, out;
+ int remaining, count;
+ char buf[4096];
+
+ remaining = Sys_FileOpenRead (netpath, &in);
+ COM_CreatePath (cachepath); // create directories up to the cache file
+ out = Sys_FileOpenWrite (cachepath);
+
+ while (remaining)
+ {
+ if (remaining < sizeof(buf))
+ count = remaining;
+ else
+ count = sizeof(buf);
+ Sys_FileRead (in, buf, count);
+ Sys_FileWrite (out, buf, count);
+ remaining -= count;
+ }
+
+ Sys_FileClose (in);
+ Sys_FileClose (out);
+}
+
+/*
+===========
+COM_FindFile
+
+Finds the file in the search path.
+Sets com_filesize and one of handle or file
+===========
+*/
+int COM_FindFile (char *filename, int *handle, FILE **file)
+{
+ searchpath_t *search;
+ char netpath[MAX_OSPATH];
+ char cachepath[MAX_OSPATH];
+ pack_t *pak;
+ int i;
+ int findtime, cachetime;
+
+ if (file && handle)
+ Sys_Error ("COM_FindFile: both handle and file set");
+ if (!file && !handle)
+ Sys_Error ("COM_FindFile: neither handle or file set");
+
+//
+// search through the path, one element at a time
+//
+ search = com_searchpaths;
+ if (proghack)
+ { // gross hack to use quake 1 progs with quake 2 maps
+ if (!strcmp(filename, "progs.dat"))
+ search = search->next;
+ }
+
+ for ( ; search ; search = search->next)
+ {
+ // is the element a pak file?
+ if (search->pack)
+ {
+ // look through all the pak file elements
+ pak = search->pack;
+ for (i=0 ; i<pak->numfiles ; i++)
+ if (!strcmp (pak->files[i].name, filename))
+ { // found it!
+ Con_DPrintf ("PackFile: %s : %s\n",pak->filename, filename);
+ if (handle)
+ {
+ *handle = pak->handle;
+ Sys_FileSeek (pak->handle, pak->files[i].filepos);
+ //if(*handle != 1)
+ //rb->splashf(HZ, "handle found: %d", *handle);
+ }
+ else
+ { // open a new file on the pakfile
+ *file = fopen (pak->filename, "rb");
+ if (*file)
+ fseek (*file, pak->files[i].filepos, SEEK_SET);
+ else
+ {
+ Sys_Error("open failed: %d", 0);
+ }
+ }
+ com_filesize = pak->files[i].filelen;
+ return com_filesize;
+ }
+ }
+ else
+ {
+ // check a file in the directory tree
+ if (!static_registered)
+ { // if not a registered version, don't ever go beyond base
+ if ( strchr (filename, '/') || strchr (filename,'\\'))
+ continue;
+ }
+
+ sprintf (netpath, "%s/%s",search->filename, filename);
+
+ findtime = Sys_FileTime (netpath);
+ if (findtime == -1)
+ continue;
+
+ // see if the file needs to be updated in the cache
+ if (!com_cachedir[0])
+ strcpy (cachepath, netpath);
+ else
+ {
+#if defined(_WIN32)
+ if ((strlen(netpath) < 2) || (netpath[1] != ':'))
+ sprintf (cachepath,"%s%s", com_cachedir, netpath);
+ else
+ sprintf (cachepath,"%s%s", com_cachedir, netpath+2);
+#else
+ sprintf (cachepath,"%s/%s", com_cachedir, netpath);
+#endif
+
+ cachetime = Sys_FileTime (cachepath);
+
+ if (cachetime < findtime)
+ COM_CopyFile (netpath, cachepath);
+ strcpy (netpath, cachepath);
+ }
+
+ Sys_Printf ("FindFile: %s\n",netpath);
+ com_filesize = Sys_FileOpenRead (netpath, &i);
+ if (handle)
+ *handle = i;
+ else
+ {
+ Sys_FileClose (i);
+ *file = fopen (netpath, "rb");
+ }
+ return com_filesize;
+ }
+
+ }
+
+ Sys_Printf ("FindFile: can't find %s\n", filename);
+
+ if (handle)
+ *handle = -1;
+ else
+ *file = NULL;
+ com_filesize = -1;
+ return -1;
+}
+
+
+/*
+===========
+COM_OpenFile
+
+filename never has a leading slash, but may contain directory walks
+returns a handle and a length
+it may actually be inside a pak file
+===========
+*/
+int COM_OpenFile (char *filename, int *handle)
+{
+ return COM_FindFile (filename, handle, NULL);
+}
+
+/*
+===========
+COM_FOpenFile
+
+If the requested file is inside a packfile, a new FILE * will be opened
+into the file.
+===========
+*/
+int COM_FOpenFile (char *filename, FILE **file)
+{
+ return COM_FindFile (filename, NULL, file);
+}
+
+/*
+============
+COM_CloseFile
+
+If it is a pak file handle, don't really close it
+============
+*/
+void COM_CloseFile (int h)
+{
+ searchpath_t *s;
+
+ for (s = com_searchpaths ; s ; s=s->next)
+ if (s->pack && s->pack->handle == h)
+ return;
+
+ Sys_FileClose (h);
+}
+
+
+/*
+============
+COM_LoadFile
+
+Filename are reletive to the quake directory.
+Allways appends a 0 byte.
+============
+*/
+cache_user_t *loadcache;
+byte *loadbuf;
+int loadsize;
+byte *COM_LoadFile (char *path, int usehunk)
+{
+ //printf("COM_LoadFile(%s)", path);
+ int h;
+ byte *buf;
+ char base[32];
+ int len;
+
+ buf = NULL; // quiet compiler warning
+
+// look for it in the filesystem or pack files
+ len = COM_OpenFile (path, &h);
+ if (h == -1)
+ return NULL;
+
+ check_ptr = &h;
+
+ //printf("handle %d", h);
+// extract the filename base name for hunk tag
+ /* BUG IS HERE */
+ COM_FileBase (path, base);
+
+ //printf("handle %d base \"%s\"", h, base);
+ //printf("");
+
+ if (usehunk == 1)
+ buf = Hunk_AllocName (len+1, base);
+ else if (usehunk == 2)
+ buf = Hunk_TempAlloc (len+1);
+ else if (usehunk == 0)
+ buf = Z_Malloc (len+1);
+ else if (usehunk == 3)
+ buf = Cache_Alloc (loadcache, len+1, base);
+ else if (usehunk == 4)
+ {
+ if (len+1 > loadsize)
+ buf = Hunk_TempAlloc (len+1);
+ else
+ buf = loadbuf;
+ }
+ else
+ Sys_Error ("COM_LoadFile: bad usehunk");
+
+ if (!buf)
+ Sys_Error ("COM_LoadFile: not enough space for %s", path);
+
+ ((byte *)buf)[len] = 0;
+
+ Draw_BeginDisc ();
+ Sys_FileRead (h, buf, len);
+ COM_CloseFile (h);
+ Draw_EndDisc ();
+
+ return buf;
+}
+
+byte *COM_LoadHunkFile (char *path)
+{
+ return COM_LoadFile (path, 1);
+}
+
+byte *COM_LoadTempFile (char *path)
+{
+ return COM_LoadFile (path, 2);
+}
+
+void COM_LoadCacheFile (char *path, struct cache_user_s *cu)
+{
+ loadcache = cu;
+ COM_LoadFile (path, 3);
+}
+
+// uses temp hunk if larger than bufsize
+byte *COM_LoadStackFile (char *path, void *buffer, int bufsize)
+{
+ byte *buf;
+
+ loadbuf = (byte *)buffer;
+ loadsize = bufsize;
+ buf = COM_LoadFile (path, 4);
+
+ return buf;
+}
+
+/*
+=================
+COM_LoadPackFile
+
+Takes an explicit (not game tree related) path to a pak file.
+
+Loads the header and directory, adding the files at the beginning
+of the list so they override previous pack files.
+=================
+*/
+pack_t *COM_LoadPackFile (char *packfile)
+{
+ dpackheader_t header;
+ int i;
+ packfile_t *newfiles;
+ int numpackfiles;
+ pack_t *pack;
+ int packhandle;
+ dpackfile_t info[MAX_FILES_IN_PACK];
+ unsigned short crc;
+
+ if (Sys_FileOpenRead (packfile, &packhandle) == -1)
+ {
+// Con_Printf ("Couldn't open %s\n", packfile);
+ return NULL;
+ }
+ Sys_FileRead (packhandle, (void *)&header, sizeof(header));
+ if (header.id[0] != 'P' || header.id[1] != 'A'
+ || header.id[2] != 'C' || header.id[3] != 'K')
+ Sys_Error ("%s is not a packfile", packfile);
+ header.dirofs = LittleLong (header.dirofs);
+ header.dirlen = LittleLong (header.dirlen);
+
+ numpackfiles = header.dirlen / sizeof(dpackfile_t);
+
+ if (numpackfiles > MAX_FILES_IN_PACK)
+ Sys_Error ("%s has %i files", packfile, numpackfiles);
+
+ if (numpackfiles != PAK0_COUNT)
+ com_modified = true; // not the original file
+
+ newfiles = Hunk_AllocName (numpackfiles * sizeof(packfile_t), "packfile");
+
+ Sys_FileSeek (packhandle, header.dirofs);
+ Sys_FileRead (packhandle, (void *)info, header.dirlen);
+
+// crc the directory to check for modifications
+ CRC_Init (&crc);
+ for (i=0 ; i<header.dirlen ; i++)
+ CRC_ProcessByte (&crc, ((byte *)info)[i]);
+ if (crc != PAK0_CRC)
+ com_modified = true;
+
+// parse the directory
+ for (i=0 ; i<numpackfiles ; i++)
+ {
+ strcpy (newfiles[i].name, info[i].name);
+ newfiles[i].filepos = LittleLong(info[i].filepos);
+ newfiles[i].filelen = LittleLong(info[i].filelen);
+ }
+
+ pack = Hunk_Alloc (sizeof (pack_t));
+ strcpy (pack->filename, packfile);
+ pack->handle = packhandle;
+ pack->numfiles = numpackfiles;
+ pack->files = newfiles;
+
+ Con_Printf ("Added packfile %s (%i files)\n", packfile, numpackfiles);
+ return pack;
+}
+
+
+/*
+================
+COM_AddGameDirectory
+
+Sets com_gamedir, adds the directory to the head of the path,
+then loads and adds pak1.pak pak2.pak ...
+================
+*/
+void COM_AddGameDirectory (char *dir)
+{
+ int i;
+ searchpath_t *search;
+ pack_t *pak;
+ char pakfile[MAX_OSPATH];
+
+ strcpy (com_gamedir, dir);
+
+//
+// add the directory to the search path
+//
+ search = Hunk_Alloc (sizeof(searchpath_t));
+ strcpy (search->filename, dir);
+ search->next = com_searchpaths;
+ com_searchpaths = search;
+
+//
+// add any pak files in the format pak0.pak pak1.pak, ...
+//
+ for (i=0 ; ; i++)
+ {
+ sprintf (pakfile, "%s/pak%i.pak", dir, i);
+ pak = COM_LoadPackFile (pakfile);
+ if (!pak)
+ break;
+ search = Hunk_Alloc (sizeof(searchpath_t));
+ search->pack = pak;
+ search->next = com_searchpaths;
+ com_searchpaths = search;
+ }
+
+//
+// add the contents of the parms.txt file to the end of the command line
+//
+
+}
+
+/*
+================
+COM_InitFilesystem
+================
+*/
+void COM_InitFilesystem (void)
+{
+ int i, j;
+ char basedir[MAX_OSPATH];
+ searchpath_t *search;
+
+//
+// -basedir <path>
+// Overrides the system supplied base directory (under GAMENAME)
+//
+ i = COM_CheckParm ("-basedir");
+ if (i && i < com_argc-1)
+ strcpy (basedir, com_argv[i+1]);
+ else
+ strcpy (basedir, host_parms.basedir);
+
+ j = strlen (basedir);
+
+ if (j > 0)
+ {
+ if ((basedir[j-1] == '\\') || (basedir[j-1] == '/'))
+ basedir[j-1] = 0;
+ }
+
+//
+// -cachedir <path>
+// Overrides the system supplied cache directory (NULL or /qcache)
+// -cachedir - will disable caching.
+//
+ i = COM_CheckParm ("-cachedir");
+ if (i && i < com_argc-1)
+ {
+ if (com_argv[i+1][0] == '-')
+ com_cachedir[0] = 0;
+ else
+ strcpy (com_cachedir, com_argv[i+1]);
+ }
+ else if (host_parms.cachedir)
+ strcpy (com_cachedir, host_parms.cachedir);
+ else
+ com_cachedir[0] = 0;
+
+//
+// start up with GAMENAME by default (id1)
+//
+ COM_AddGameDirectory (va("%s/"GAMENAME, basedir) );
+
+ if (COM_CheckParm ("-rogue"))
+ COM_AddGameDirectory (va("%s/rogue", basedir) );
+ if (COM_CheckParm ("-hipnotic"))
+ COM_AddGameDirectory (va("%s/hipnotic", basedir) );
+
+//
+// -game <gamedir>
+// Adds basedir/gamedir as an override game
+//
+ i = COM_CheckParm ("-game");
+ if (i && i < com_argc-1)
+ {
+ com_modified = true;
+ COM_AddGameDirectory (va("%s/%s", basedir, com_argv[i+1]));
+ }
+
+//
+// -path <dir or packfile> [<dir or packfile>] ...
+// Fully specifies the exact serach path, overriding the generated one
+//
+ i = COM_CheckParm ("-path");
+ if (i)
+ {
+ com_modified = true;
+ com_searchpaths = NULL;
+ while (++i < com_argc)
+ {
+ if (!com_argv[i] || com_argv[i][0] == '+' || com_argv[i][0] == '-')
+ break;
+
+ search = Hunk_Alloc (sizeof(searchpath_t));
+ if ( !strcmp(COM_FileExtension(com_argv[i]), "pak") )
+ {
+ search->pack = COM_LoadPackFile (com_argv[i]);
+ if (!search->pack)
+ Sys_Error ("Couldn't load packfile: %s", com_argv[i]);
+ }
+ else
+ strcpy (search->filename, com_argv[i]);
+ search->next = com_searchpaths;
+ com_searchpaths = search;
+ }
+ }
+
+ if (COM_CheckParm ("-proghack"))
+ proghack = true;
+}
+
+
diff --git a/apps/plugins/sdl/progs/quake/common.h b/apps/plugins/sdl/progs/quake/common.h
new file mode 100644
index 0000000000..a1ac227aff
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/common.h
@@ -0,0 +1,184 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// comndef.h -- general definitions
+
+#if !defined BYTE_DEFINED
+typedef unsigned char byte;
+#define BYTE_DEFINED 1
+#endif
+
+#undef true
+#undef false
+
+typedef int qboolean;
+enum {false, true};
+
+//============================================================================
+
+typedef struct sizebuf_s
+{
+ qboolean allowoverflow; // if false, do a Sys_Error
+ qboolean overflowed; // set to true if the buffer size failed
+ byte *data;
+ int maxsize;
+ int cursize;
+} sizebuf_t;
+
+void SZ_Alloc (sizebuf_t *buf, int startsize);
+void SZ_Free (sizebuf_t *buf);
+void SZ_Clear (sizebuf_t *buf);
+void *SZ_GetSpace (sizebuf_t *buf, int length);
+void SZ_Write (sizebuf_t *buf, void *data, int length);
+void SZ_Print (sizebuf_t *buf, char *data); // strcats onto the sizebuf
+
+//============================================================================
+
+typedef struct link_s
+{
+ struct link_s *prev, *next;
+} link_t;
+
+
+void ClearLink (link_t *l);
+void RemoveLink (link_t *l);
+void InsertLinkBefore (link_t *l, link_t *before);
+void InsertLinkAfter (link_t *l, link_t *after);
+
+// (type *)STRUCT_FROM_LINK(link_t *link, type, member)
+// ent = STRUCT_FROM_LINK(link,entity_t,order)
+// FIXME: remove this mess!
+#define STRUCT_FROM_LINK(l,t,m) ((t *)((byte *)l - (int)&(((t *)0)->m)))
+
+//============================================================================
+
+#ifndef NULL
+#define NULL ((void *)0)
+#endif
+
+#define Q_MAXCHAR ((char)0x7f)
+#define Q_MAXSHORT ((short)0x7fff)
+#define Q_MAXINT ((int)0x7fffffff)
+#define Q_MAXLONG ((int)0x7fffffff)
+#define Q_MAXFLOAT ((int)0x7fffffff)
+
+#define Q_MINCHAR ((char)0x80)
+#define Q_MINSHORT ((short)0x8000)
+#define Q_MININT ((int)0x80000000)
+#define Q_MINLONG ((int)0x80000000)
+#define Q_MINFLOAT ((int)0x7fffffff)
+
+//============================================================================
+
+extern qboolean bigendien;
+
+extern short (*BigShort) (short l);
+extern short (*LittleShort) (short l);
+extern int (*BigLong) (int l);
+extern int (*LittleLong) (int l);
+extern float (*BigFloat) (float l);
+extern float (*LittleFloat) (float l);
+
+//============================================================================
+
+void MSG_WriteChar (sizebuf_t *sb, int c);
+void MSG_WriteByte (sizebuf_t *sb, int c);
+void MSG_WriteShort (sizebuf_t *sb, int c);
+void MSG_WriteLong (sizebuf_t *sb, int c);
+void MSG_WriteFloat (sizebuf_t *sb, float f);
+void MSG_WriteString (sizebuf_t *sb, char *s);
+void MSG_WriteCoord (sizebuf_t *sb, float f);
+void MSG_WriteAngle (sizebuf_t *sb, float f);
+
+extern int msg_readcount;
+extern qboolean msg_badread; // set if a read goes beyond end of message
+
+void MSG_BeginReading (void);
+int MSG_ReadChar (void);
+int MSG_ReadByte (void);
+int MSG_ReadShort (void);
+int MSG_ReadLong (void);
+float MSG_ReadFloat (void);
+char *MSG_ReadString (void);
+
+float MSG_ReadCoord (void);
+float MSG_ReadAngle (void);
+
+//============================================================================
+
+void Q_memset (void *dest, int fill, int count);
+void Q_memcpy (void *dest, void *src, int count);
+int Q_memcmp (void *m1, void *m2, int count);
+void Q_strcpy (char *dest, char *src);
+void Q_strncpy (char *dest, char *src, int count);
+int Q_strlen (char *str);
+char *Q_strrchr (char *s, char c);
+void Q_strcat (char *dest, char *src);
+int Q_strcmp (char *s1, char *s2);
+int Q_strncmp (char *s1, char *s2, int count);
+int Q_strcasecmp (char *s1, char *s2);
+int Q_strncasecmp (char *s1, char *s2, int n);
+int Q_atoi (char *str);
+float Q_atof (char *str);
+
+//============================================================================
+
+extern char com_token[1024];
+extern qboolean com_eof;
+
+char *COM_Parse (char *data);
+
+
+extern int com_argc;
+extern char **com_argv;
+
+int COM_CheckParm (char *parm);
+void COM_Init (char *path);
+void COM_InitArgv (int argc, char **argv);
+
+char *COM_SkipPath (char *pathname);
+void COM_StripExtension (char *in, char *out);
+void COM_FileBase (char *in, char *out);
+void COM_DefaultExtension (char *path, char *extension);
+
+char *va(char *format, ...);
+// does a varargs printf into a temp buffer
+
+
+//============================================================================
+
+extern int com_filesize;
+struct cache_user_s;
+
+extern char com_gamedir[MAX_OSPATH];
+
+void COM_WriteFile (char *filename, void *data, int len);
+int COM_OpenFile (char *filename, int *hndl);
+int COM_FOpenFile (char *filename, FILE **file);
+void COM_CloseFile (int h);
+
+byte *COM_LoadStackFile (char *path, void *buffer, int bufsize);
+byte *COM_LoadTempFile (char *path);
+byte *COM_LoadHunkFile (char *path);
+void COM_LoadCacheFile (char *path, struct cache_user_s *cu);
+
+
+extern struct cvar_s registered;
+
+extern qboolean standard_quake, rogue, hipnotic;
diff --git a/apps/plugins/sdl/progs/quake/conproc.h b/apps/plugins/sdl/progs/quake/conproc.h
new file mode 100644
index 0000000000..743526f878
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/conproc.h
@@ -0,0 +1,37 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// conproc.h
+
+#define CCOM_WRITE_TEXT 0x2
+// Param1 : Text
+
+#define CCOM_GET_TEXT 0x3
+// Param1 : Begin line
+// Param2 : End line
+
+#define CCOM_GET_SCR_LINES 0x4
+// No params
+
+#define CCOM_SET_SCR_LINES 0x5
+// Param1 : Number of lines
+
+void InitConProc (HANDLE hFile, HANDLE heventParent, HANDLE heventChild);
+void DeinitConProc (void);
+
diff --git a/apps/plugins/sdl/progs/quake/console.c b/apps/plugins/sdl/progs/quake/console.c
new file mode 100644
index 0000000000..59c7de368c
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/console.c
@@ -0,0 +1,644 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// console.c
+
+#include "quakedef.h"
+
+int con_linewidth;
+
+float con_cursorspeed = 4;
+
+#define CON_TEXTSIZE 16384
+
+qboolean con_forcedup; // because no entities to refresh
+
+int con_totallines; // total lines in console scrollback
+int con_backscroll; // lines up from bottom to display
+int con_current; // where next message will be printed
+int con_x; // offset in current line for next print
+char *con_text=0;
+
+cvar_t con_notifytime = {"con_notifytime","3"}; //seconds
+
+#define NUM_CON_TIMES 4
+float con_times[NUM_CON_TIMES]; // realtime time the line was generated
+ // for transparent notify lines
+
+int con_vislines;
+
+qboolean con_debuglog;
+
+#define MAXCMDLINE 256
+extern char key_lines[32][MAXCMDLINE];
+extern int edit_line;
+extern int key_linepos;
+
+
+qboolean con_initialized;
+
+int con_notifylines; // scan lines to clear for notify lines
+
+extern void M_Menu_Main_f (void);
+
+/*
+================
+Con_ToggleConsole_f
+================
+*/
+void Con_ToggleConsole_f (void)
+{
+ if (key_dest == key_console)
+ {
+ if (cls.state == ca_connected)
+ {
+ key_dest = key_game;
+ key_lines[edit_line][1] = 0; // clear any typing
+ key_linepos = 1;
+ }
+ else
+ {
+ M_Menu_Main_f ();
+ }
+ }
+ else
+ key_dest = key_console;
+
+ SCR_EndLoadingPlaque ();
+ memset (con_times, 0, sizeof(con_times));
+}
+
+/*
+================
+Con_Clear_f
+================
+*/
+void Con_Clear_f (void)
+{
+ if (con_text)
+ Q_memset (con_text, ' ', CON_TEXTSIZE);
+}
+
+
+/*
+================
+Con_ClearNotify
+================
+*/
+void Con_ClearNotify (void)
+{
+ int i;
+
+ for (i=0 ; i<NUM_CON_TIMES ; i++)
+ con_times[i] = 0;
+}
+
+
+/*
+================
+Con_MessageMode_f
+================
+*/
+extern qboolean team_message;
+
+void Con_MessageMode_f (void)
+{
+ key_dest = key_message;
+ team_message = false;
+}
+
+
+/*
+================
+Con_MessageMode2_f
+================
+*/
+void Con_MessageMode2_f (void)
+{
+ key_dest = key_message;
+ team_message = true;
+}
+
+
+/*
+================
+Con_CheckResize
+
+If the line width has changed, reformat the buffer.
+================
+*/
+void Con_CheckResize (void)
+{
+ int i, j, width, oldwidth, oldtotallines, numlines, numchars;
+ char tbuf[CON_TEXTSIZE];
+
+ width = (vid.width >> 3) - 2;
+
+ if (width == con_linewidth)
+ return;
+
+ if (width < 1) // video hasn't been initialized yet
+ {
+ width = 38;
+ con_linewidth = width;
+ con_totallines = CON_TEXTSIZE / con_linewidth;
+ Q_memset (con_text, ' ', CON_TEXTSIZE);
+ }
+ else
+ {
+ oldwidth = con_linewidth;
+ con_linewidth = width;
+ oldtotallines = con_totallines;
+ con_totallines = CON_TEXTSIZE / con_linewidth;
+ numlines = oldtotallines;
+
+ if (con_totallines < numlines)
+ numlines = con_totallines;
+
+ numchars = oldwidth;
+
+ if (con_linewidth < numchars)
+ numchars = con_linewidth;
+
+ Q_memcpy (tbuf, con_text, CON_TEXTSIZE);
+ Q_memset (con_text, ' ', CON_TEXTSIZE);
+
+ for (i=0 ; i<numlines ; i++)
+ {
+ for (j=0 ; j<numchars ; j++)
+ {
+ con_text[(con_totallines - 1 - i) * con_linewidth + j] =
+ tbuf[((con_current - i + oldtotallines) %
+ oldtotallines) * oldwidth + j];
+ }
+ }
+
+ Con_ClearNotify ();
+ }
+
+ con_backscroll = 0;
+ con_current = con_totallines - 1;
+}
+
+
+/*
+================
+Con_Init
+================
+*/
+void Con_Init (void)
+{
+#define MAXGAMEDIRLEN 1000
+ char temp[MAXGAMEDIRLEN+1];
+ char *t2 = "/qconsole.log";
+
+ con_debuglog = COM_CheckParm("-condebug");
+
+ if (con_debuglog)
+ {
+ if (strlen (com_gamedir) < (MAXGAMEDIRLEN - strlen (t2)))
+ {
+ sprintf (temp, "%s%s", com_gamedir, t2);
+ unlink (temp);
+ }
+ }
+
+ con_text = Hunk_AllocName (CON_TEXTSIZE, "context");
+ Q_memset (con_text, ' ', CON_TEXTSIZE);
+ con_linewidth = -1;
+ Con_CheckResize ();
+
+ Con_Printf ("Console initialized.\n");
+
+//
+// register our commands
+//
+ Cvar_RegisterVariable (&con_notifytime);
+
+ Cmd_AddCommand ("toggleconsole", Con_ToggleConsole_f);
+ Cmd_AddCommand ("messagemode", Con_MessageMode_f);
+ Cmd_AddCommand ("messagemode2", Con_MessageMode2_f);
+ Cmd_AddCommand ("clear", Con_Clear_f);
+ con_initialized = true;
+}
+
+
+/*
+===============
+Con_Linefeed
+===============
+*/
+void Con_Linefeed (void)
+{
+ if ( ! con_initialized ) return;
+ con_x = 0;
+ con_current++;
+ Q_memset (&con_text[(con_current%con_totallines)*con_linewidth]
+ , ' ', con_linewidth);
+}
+
+/*
+================
+Con_Print
+
+Handles cursor positioning, line wrapping, etc
+All console printing must go through this in order to be logged to disk
+If no console is visible, the notify window will pop up.
+================
+*/
+void Con_Print (char *txt)
+{
+ int y;
+ int c, l;
+ static int cr;
+ int mask;
+
+ if ( ! con_initialized ) return;
+ con_backscroll = 0;
+
+ if (txt[0] == 1)
+ {
+ mask = 128; // go to colored text
+ S_LocalSound ("misc/talk.wav");
+ // play talk wav
+ txt++;
+ }
+ else if (txt[0] == 2)
+ {
+ mask = 128; // go to colored text
+ txt++;
+ }
+ else
+ mask = 0;
+
+
+ while ( (c = *txt) )
+ {
+ // count word length
+ for (l=0 ; l< con_linewidth ; l++)
+ if ( txt[l] <= ' ')
+ break;
+
+ // word wrap
+ if (l != con_linewidth && (con_x + l > con_linewidth) )
+ con_x = 0;
+
+ txt++;
+
+ if (cr)
+ {
+ con_current--;
+ cr = false;
+ }
+
+
+ if (!con_x)
+ {
+ Con_Linefeed ();
+ // mark time for transparent overlay
+ if (con_current >= 0)
+ con_times[con_current % NUM_CON_TIMES] = realtime;
+ }
+
+ switch (c)
+ {
+ case '\n':
+ con_x = 0;
+ break;
+
+ case '\r':
+ con_x = 0;
+ cr = 1;
+ break;
+
+ default: // display character and advance
+ y = con_current % con_totallines;
+ con_text[y*con_linewidth+con_x] = c | mask;
+ con_x++;
+ if (con_x >= con_linewidth)
+ con_x = 0;
+ break;
+ }
+
+ }
+}
+
+
+/*
+================
+Con_DebugLog
+================
+*/
+void Con_DebugLog(char *file, char *fmt, ...)
+{
+ va_list argptr;
+ static char data[1024];
+ int fd;
+
+ va_start(argptr, fmt);
+ vsprintf(data, fmt, argptr);
+ va_end(argptr);
+ fd = rb->open(file, O_WRONLY | O_CREAT | O_APPEND, 0666);
+ rb->write(fd, data, strlen(data));
+ rb->close(fd);
+}
+
+
+/*
+================
+Con_Printf
+
+Handles cursor positioning, line wrapping, etc
+================
+*/
+#define MAXPRINTMSG 4096
+// FIXME: make a buffer size safe vsprintf?
+void Con_Printf (char *fmt, ...)
+{
+ va_list argptr;
+ char msg[MAXPRINTMSG];
+ static qboolean inupdate;
+
+ va_start (argptr,fmt);
+ vsprintf (msg,fmt,argptr);
+ va_end (argptr);
+
+// also echo to debugging console
+ Sys_Printf ("%s", msg); // also echo to debugging console
+
+// log all messages to file
+ if (con_debuglog)
+ Con_DebugLog(va("%s/qconsole.log",com_gamedir), "%s", msg);
+
+ if (!con_initialized)
+ return;
+
+ if (cls.state == ca_dedicated)
+ return; // no graphics mode
+
+// write it to the scrollable buffer
+ Con_Print (msg);
+
+// update the screen if the console is displayed
+ if (cls.signon != SIGNONS && !scr_disabled_for_loading )
+ {
+ // protect against infinite loop if something in SCR_UpdateScreen calls
+ // Con_Printd
+ if (!inupdate)
+ {
+ inupdate = true;
+ SCR_UpdateScreen ();
+ inupdate = false;
+ }
+ }
+}
+
+/*
+================
+Con_DPrintf
+
+A Con_Printf that only shows up if the "developer" cvar is set
+================
+*/
+void Con_DPrintf (char *fmt, ...)
+{
+ va_list argptr;
+ char msg[MAXPRINTMSG];
+
+ if (!developer.value)
+ return; // don't confuse non-developers with techie stuff...
+
+ va_start (argptr,fmt);
+ vsprintf (msg,fmt,argptr);
+ va_end (argptr);
+
+ Con_Printf ("%s", msg);
+}
+
+
+/*
+==================
+Con_SafePrintf
+
+Okay to call even when the screen can't be updated
+==================
+*/
+void Con_SafePrintf (char *fmt, ...)
+{
+ va_list argptr;
+ char msg[1024];
+ int temp;
+
+ va_start (argptr,fmt);
+ vsprintf (msg,fmt,argptr);
+ va_end (argptr);
+
+ temp = scr_disabled_for_loading;
+ scr_disabled_for_loading = true;
+ Con_Printf ("%s", msg);
+ scr_disabled_for_loading = temp;
+}
+
+
+/*
+==============================================================================
+
+DRAWING
+
+==============================================================================
+*/
+
+
+/*
+================
+Con_DrawInput
+
+The input line scrolls horizontally if typing goes beyond the right edge
+================
+*/
+void Con_DrawInput (void)
+{
+ int y;
+ int i;
+ char *text;
+
+ if (key_dest != key_console && !con_forcedup)
+ return; // don't draw anything
+
+ text = key_lines[edit_line];
+
+// add the cursor frame
+ text[key_linepos] = 10+((int)(realtime*con_cursorspeed)&1);
+
+// fill out remainder with spaces
+ for (i=key_linepos+1 ; i< con_linewidth ; i++)
+ text[i] = ' ';
+
+// prestep if horizontally scrolling
+ if (key_linepos >= con_linewidth)
+ text += 1 + key_linepos - con_linewidth;
+
+// draw it
+ y = con_vislines-16;
+
+ for (i=0 ; i<con_linewidth ; i++)
+ Draw_Character ( (i+1)<<3, con_vislines - 16, text[i]);
+
+// remove cursor
+ key_lines[edit_line][key_linepos] = 0;
+}
+
+
+/*
+================
+Con_DrawNotify
+
+Draws the last few lines of output transparently over the game top
+================
+*/
+void Con_DrawNotify (void)
+{
+ int x, v;
+ char *text;
+ int i;
+ float time;
+ extern char chat_buffer[];
+
+ v = 0;
+ for (i= con_current-NUM_CON_TIMES+1 ; i<=con_current ; i++)
+ {
+ if (i < 0)
+ continue;
+ time = con_times[i % NUM_CON_TIMES];
+ if (time == 0)
+ continue;
+ time = realtime - time;
+ if (time > con_notifytime.value)
+ continue;
+ text = con_text + (i % con_totallines)*con_linewidth;
+
+ clearnotify = 0;
+ scr_copytop = 1;
+
+ for (x = 0 ; x < con_linewidth ; x++)
+ Draw_Character ( (x+1)<<3, v, text[x]);
+
+ v += 8;
+ }
+
+
+ if (key_dest == key_message)
+ {
+ clearnotify = 0;
+ scr_copytop = 1;
+
+ x = 0;
+
+ Draw_String (8, v, "say:");
+ while(chat_buffer[x])
+ {
+ Draw_Character ( (x+5)<<3, v, chat_buffer[x]);
+ x++;
+ }
+ Draw_Character ( (x+5)<<3, v, 10+((int)(realtime*con_cursorspeed)&1));
+ v += 8;
+ }
+
+ if (v > con_notifylines)
+ con_notifylines = v;
+}
+
+/*
+================
+Con_DrawConsole
+
+Draws the console with the solid background
+The typing input line at the bottom should only be drawn if typing is allowed
+================
+*/
+void Con_DrawConsole (int lines, qboolean drawinput)
+{
+ int i, x, y;
+ int rows;
+ char *text;
+ int j;
+
+ if (lines <= 0)
+ return;
+
+// draw the background
+ Draw_ConsoleBackground (lines);
+
+// draw the text
+ con_vislines = lines;
+
+ rows = (lines-16)>>3; // rows of text to draw
+ y = lines - 16 - (rows<<3); // may start slightly negative
+
+ for (i= con_current - rows + 1 ; i<=con_current ; i++, y+=8 )
+ {
+ j = i - con_backscroll;
+ if (j<0)
+ j = 0;
+ text = con_text + (j % con_totallines)*con_linewidth;
+
+ for (x=0 ; x<con_linewidth ; x++)
+ Draw_Character ( (x+1)<<3, y, text[x]);
+ }
+
+// draw the input prompt, user text, and cursor if desired
+ if (drawinput)
+ Con_DrawInput ();
+}
+
+
+/*
+==================
+Con_NotifyBox
+==================
+*/
+void Con_NotifyBox (char *text)
+{
+ double t1, t2;
+
+// during startup for sound / cd warnings
+ Con_Printf("\n\n\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\37\n");
+
+ Con_Printf (text);
+
+ Con_Printf ("Press a key.\n");
+ Con_Printf("\35\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\36\37\n");
+
+ key_count = -2; // wait for a key down and up
+ key_dest = key_console;
+
+ do
+ {
+ t1 = Sys_FloatTime ();
+ SCR_UpdateScreen ();
+ Sys_SendKeyEvents ();
+ t2 = Sys_FloatTime ();
+ realtime += t2-t1; // make the cursor blink
+ } while (key_count < 0);
+
+ Con_Printf ("\n");
+ key_dest = key_game;
+ realtime = 0; // put the cursor back to invisible
+}
+
diff --git a/apps/plugins/sdl/progs/quake/console.h b/apps/plugins/sdl/progs/quake/console.h
new file mode 100644
index 0000000000..ef01f008ad
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/console.h
@@ -0,0 +1,46 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+
+//
+// console
+//
+extern int con_totallines;
+extern int con_backscroll;
+extern qboolean con_forcedup; // because no entities to refresh
+extern qboolean con_initialized;
+extern byte *con_chars;
+extern int con_notifylines; // scan lines to clear for notify lines
+
+void Con_DrawCharacter (int cx, int line, int num);
+
+void Con_CheckResize (void);
+void Con_Init (void);
+void Con_DrawConsole (int lines, qboolean drawinput);
+void Con_Print (char *txt);
+void Con_Printf (char *fmt, ...);
+void Con_DPrintf (char *fmt, ...);
+void Con_SafePrintf (char *fmt, ...);
+void Con_Clear_f (void);
+void Con_DrawNotify (void);
+void Con_ClearNotify (void);
+void Con_ToggleConsole_f (void);
+
+void Con_NotifyBox (char *text); // during startup for sound / cd warnings
+
diff --git a/apps/plugins/sdl/progs/quake/crc.c b/apps/plugins/sdl/progs/quake/crc.c
new file mode 100644
index 0000000000..ed4880cea9
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/crc.c
@@ -0,0 +1,81 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+/* crc.c */
+
+#include "quakedef.h"
+#include "crc.h"
+
+// this is a 16 bit, non-reflected CRC using the polynomial 0x1021
+// and the initial and final xor values shown below... in other words, the
+// CCITT standard CRC used by XMODEM
+
+#define CRC_INIT_VALUE 0xffff
+#define CRC_XOR_VALUE 0x0000
+
+static unsigned short crctable[256] =
+{
+ 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
+ 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
+ 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
+ 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
+ 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
+ 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
+ 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
+ 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
+ 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
+ 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
+ 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
+ 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
+ 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
+ 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
+ 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
+ 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
+ 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
+ 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
+ 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
+ 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
+ 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
+ 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
+ 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
+ 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
+ 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
+ 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
+ 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
+ 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
+ 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
+ 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
+ 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
+ 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
+};
+
+void CRC_Init(unsigned short *crcvalue)
+{
+ *crcvalue = CRC_INIT_VALUE;
+}
+
+void CRC_ProcessByte(unsigned short *crcvalue, byte data)
+{
+ *crcvalue = (*crcvalue << 8) ^ crctable[(*crcvalue >> 8) ^ data];
+}
+
+unsigned short CRC_Value(unsigned short crcvalue)
+{
+ return crcvalue ^ CRC_XOR_VALUE;
+} \ No newline at end of file
diff --git a/apps/plugins/sdl/progs/quake/crc.h b/apps/plugins/sdl/progs/quake/crc.h
new file mode 100644
index 0000000000..cad97725b2
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/crc.h
@@ -0,0 +1,24 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+/* crc.h */
+
+void CRC_Init(unsigned short *crcvalue);
+void CRC_ProcessByte(unsigned short *crcvalue, byte data);
+unsigned short CRC_Value(unsigned short crcvalue);
diff --git a/apps/plugins/sdl/progs/quake/cvar.c b/apps/plugins/sdl/progs/quake/cvar.c
new file mode 100644
index 0000000000..07a761a332
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/cvar.c
@@ -0,0 +1,224 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// cvar.c -- dynamic variable tracking
+
+#include "quakedef.h"
+
+cvar_t *cvar_vars;
+char *cvar_null_string = "";
+
+/*
+============
+Cvar_FindVar
+============
+*/
+cvar_t *Cvar_FindVar (char *var_name)
+{
+ cvar_t *var;
+
+ for (var=cvar_vars ; var ; var=var->next)
+ if (!Q_strcmp (var_name, var->name))
+ return var;
+
+ return NULL;
+}
+
+/*
+============
+Cvar_VariableValue
+============
+*/
+float Cvar_VariableValue (char *var_name)
+{
+ cvar_t *var;
+
+ var = Cvar_FindVar (var_name);
+ if (!var)
+ return 0;
+ return Q_atof (var->string);
+}
+
+
+/*
+============
+Cvar_VariableString
+============
+*/
+char *Cvar_VariableString (char *var_name)
+{
+ cvar_t *var;
+
+ var = Cvar_FindVar (var_name);
+ if (!var)
+ return cvar_null_string;
+ return var->string;
+}
+
+
+/*
+============
+Cvar_CompleteVariable
+============
+*/
+char *Cvar_CompleteVariable (char *partial)
+{
+ cvar_t *cvar;
+ int len;
+
+ len = Q_strlen(partial);
+
+ if (!len)
+ return NULL;
+
+// check functions
+ for (cvar=cvar_vars ; cvar ; cvar=cvar->next)
+ if (!Q_strncmp (partial,cvar->name, len))
+ return cvar->name;
+
+ return NULL;
+}
+
+
+/*
+============
+Cvar_Set
+============
+*/
+void Cvar_Set (char *var_name, char *value)
+{
+ cvar_t *var;
+ qboolean changed;
+
+ var = Cvar_FindVar (var_name);
+ if (!var)
+ { // there is an error in C code if this happens
+ Con_Printf ("Cvar_Set: variable %s not found\n", var_name);
+ return;
+ }
+
+ changed = Q_strcmp(var->string, value);
+
+ Z_Free (var->string); // free the old value string
+
+ var->string = Z_Malloc (Q_strlen(value)+1);
+ Q_strcpy (var->string, value);
+ var->value = Q_atof (var->string);
+ if (var->server && changed)
+ {
+ if (sv.active)
+ SV_BroadcastPrintf ("\"%s\" changed to \"%s\"\n", var->name, var->string);
+ }
+}
+
+/*
+============
+Cvar_SetValue
+============
+*/
+void Cvar_SetValue (char *var_name, float value)
+{
+ char val[32];
+
+ sprintf (val, "%f",value);
+ Cvar_Set (var_name, val);
+}
+
+
+/*
+============
+Cvar_RegisterVariable
+
+Adds a freestanding variable to the variable list.
+============
+*/
+void Cvar_RegisterVariable (cvar_t *variable)
+{
+ char *oldstr;
+
+// first check to see if it has allready been defined
+ if (Cvar_FindVar (variable->name))
+ {
+ Con_Printf ("Can't register variable %s, allready defined\n", variable->name);
+ return;
+ }
+
+// check for overlap with a command
+ if (Cmd_Exists (variable->name))
+ {
+ Con_Printf ("Cvar_RegisterVariable: %s is a command\n", variable->name);
+ return;
+ }
+
+// copy the value off, because future sets will Z_Free it
+ oldstr = variable->string;
+ variable->string = Z_Malloc (Q_strlen(variable->string)+1);
+ Q_strcpy (variable->string, oldstr);
+ variable->value = Q_atof (variable->string);
+
+// link the variable in
+ variable->next = cvar_vars;
+ cvar_vars = variable;
+}
+
+/*
+============
+Cvar_Command
+
+Handles variable inspection and changing from the console
+============
+*/
+qboolean Cvar_Command (void)
+{
+ cvar_t *v;
+
+// check variables
+ v = Cvar_FindVar (Cmd_Argv(0));
+ if (!v)
+ return false;
+
+// perform a variable print or set
+ if (Cmd_Argc() == 1)
+ {
+ Con_Printf ("\"%s\" is \"%s\"\n", v->name, v->string);
+ return true;
+ }
+
+ Cvar_Set (v->name, Cmd_Argv(1));
+ return true;
+}
+
+
+/*
+============
+Cvar_WriteVariables
+
+Writes lines containing "set variable value" for all variables
+with the archive flag set to true.
+============
+*/
+void Cvar_WriteVariables (FILE *f)
+{
+ cvar_t *var;
+
+ for (var = cvar_vars ; var ; var = var->next)
+ if (var->archive)
+ fprintf (f, "%s \"%s\"\n", var->name, var->string);
+}
+
diff --git a/apps/plugins/sdl/progs/quake/cvar.h b/apps/plugins/sdl/progs/quake/cvar.h
new file mode 100644
index 0000000000..009b74783f
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/cvar.h
@@ -0,0 +1,97 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// cvar.h
+
+/*
+
+cvar_t variables are used to hold scalar or string variables that can be changed or displayed at the console or prog code as well as accessed directly
+in C code.
+
+it is sufficient to initialize a cvar_t with just the first two fields, or
+you can add a ,true flag for variables that you want saved to the configuration
+file when the game is quit:
+
+cvar_t r_draworder = {"r_draworder","1"};
+cvar_t scr_screensize = {"screensize","1",true};
+
+Cvars must be registered before use, or they will have a 0 value instead of the float interpretation of the string. Generally, all cvar_t declarations should be registered in the apropriate init function before any console commands are executed:
+Cvar_RegisterVariable (&host_framerate);
+
+
+C code usually just references a cvar in place:
+if ( r_draworder.value )
+
+It could optionally ask for the value to be looked up for a string name:
+if (Cvar_VariableValue ("r_draworder"))
+
+Interpreted prog code can access cvars with the cvar(name) or
+cvar_set (name, value) internal functions:
+teamplay = cvar("teamplay");
+cvar_set ("registered", "1");
+
+The user can access cvars from the console in two ways:
+r_draworder prints the current value
+r_draworder 0 sets the current value to 0
+Cvars are restricted from having the same names as commands to keep this
+interface from being ambiguous.
+*/
+
+typedef struct cvar_s
+{
+ char *name;
+ char *string;
+ qboolean archive; // set to true to cause it to be saved to vars.rc
+ qboolean server; // notifies players when changed
+ float value;
+ struct cvar_s *next;
+} cvar_t;
+
+void Cvar_RegisterVariable (cvar_t *variable);
+// registers a cvar that allready has the name, string, and optionally the
+// archive elements set.
+
+void Cvar_Set (char *var_name, char *value);
+// equivelant to "<name> <variable>" typed at the console
+
+void Cvar_SetValue (char *var_name, float value);
+// expands value to a string and calls Cvar_Set
+
+float Cvar_VariableValue (char *var_name);
+// returns 0 if not defined or non numeric
+
+char *Cvar_VariableString (char *var_name);
+// returns an empty string if not defined
+
+char *Cvar_CompleteVariable (char *partial);
+// attempts to match a partial variable name for command line completion
+// returns NULL if nothing fits
+
+qboolean Cvar_Command (void);
+// called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known
+// command. Returns true if the command was a variable reference that
+// was handled. (print or change)
+
+void Cvar_WriteVariables (FILE *f);
+// Writes lines containing "set variable value" for all variables
+// with the archive flag set to true.
+
+cvar_t *Cvar_FindVar (char *var_name);
+
+extern cvar_t *cvar_vars;
diff --git a/apps/plugins/sdl/progs/quake/d_copy.S b/apps/plugins/sdl/progs/quake/d_copy.S
new file mode 100644
index 0000000000..92e414a1bf
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/d_copy.S
@@ -0,0 +1,149 @@
+//
+// d_copy.s
+// x86 assembly-language screen copying code.
+//
+
+#include "asm_i386.h"
+#include "quakeasm.h"
+#include "asm_draw.h"
+
+ .data
+
+LCopyWidth: .long 0
+LBlockSrcStep: .long 0
+LBlockDestStep: .long 0
+LSrcDelta: .long 0
+LDestDelta: .long 0
+
+#define bufptr 4+16
+
+// copies 16 rows per plane at a pop; idea is that 16*512 = 8k, and since
+// no Mode X mode is wider than 360, all the data should fit in the cache for
+// the passes for the next 3 planes
+
+ .text
+
+.globl C(VGA_UpdatePlanarScreen)
+C(VGA_UpdatePlanarScreen):
+ pushl %ebp // preserve caller's stack frame
+ pushl %edi
+ pushl %esi // preserve register variables
+ pushl %ebx
+
+ movl C(VGA_bufferrowbytes),%eax
+ shll $1,%eax
+ movl %eax,LBlockSrcStep
+ movl C(VGA_rowbytes),%eax
+ shll $1,%eax
+ movl %eax,LBlockDestStep
+
+ movl $0x3C4,%edx
+ movb $2,%al
+ outb %al,%dx // point the SC to the Map Mask
+ incl %edx
+
+ movl bufptr(%esp),%esi
+ movl C(VGA_pagebase),%edi
+ movl C(VGA_height),%ebp
+ shrl $1,%ebp
+
+ movl C(VGA_width),%ecx
+ movl C(VGA_bufferrowbytes),%eax
+ subl %ecx,%eax
+ movl %eax,LSrcDelta
+ movl C(VGA_rowbytes),%eax
+ shll $2,%eax
+ subl %ecx,%eax
+ movl %eax,LDestDelta
+ shrl $4,%ecx
+ movl %ecx,LCopyWidth
+
+LRowLoop:
+ movb $1,%al
+
+LPlaneLoop:
+ outb %al,%dx
+ movb $2,%ah
+
+ pushl %esi
+ pushl %edi
+LRowSetLoop:
+ movl LCopyWidth,%ecx
+LColumnLoop:
+ movb 12(%esi),%bh
+ movb 8(%esi),%bl
+ shll $16,%ebx
+ movb 4(%esi),%bh
+ movb (%esi),%bl
+ movl %ebx,(%edi)
+ addl $16,%esi
+ addl $4,%edi
+ decl %ecx
+ jnz LColumnLoop
+
+ addl LDestDelta,%edi
+ addl LSrcDelta,%esi
+ decb %ah
+ jnz LRowSetLoop
+
+ popl %edi
+ popl %esi
+ incl %esi
+
+ shlb $1,%al
+ cmpb $16,%al
+ jnz LPlaneLoop
+
+ subl $4,%esi
+ addl LBlockSrcStep,%esi
+ addl LBlockDestStep,%edi
+ decl %ebp
+ jnz LRowLoop
+
+ popl %ebx // restore register variables
+ popl %esi
+ popl %edi
+ popl %ebp // restore the caller's stack frame
+
+ ret
+
+
+#define srcptr 4+16
+#define destptr 8+16
+#define width 12+16
+#define height 16+16
+#define srcrowbytes 20+16
+#define destrowbytes 24+16
+
+.globl C(VGA_UpdateLinearScreen)
+C(VGA_UpdateLinearScreen):
+ pushl %ebp // preserve caller's stack frame
+ pushl %edi
+ pushl %esi // preserve register variables
+ pushl %ebx
+
+ cld
+ movl srcptr(%esp),%esi
+ movl destptr(%esp),%edi
+ movl width(%esp),%ebx
+ movl srcrowbytes(%esp),%eax
+ subl %ebx,%eax
+ movl destrowbytes(%esp),%edx
+ subl %ebx,%edx
+ shrl $2,%ebx
+ movl height(%esp),%ebp
+LLRowLoop:
+ movl %ebx,%ecx
+ rep/movsl (%esi),(%edi)
+ addl %eax,%esi
+ addl %edx,%edi
+ decl %ebp
+ jnz LLRowLoop
+
+ popl %ebx // restore register variables
+ popl %esi
+ popl %edi
+ popl %ebp // restore the caller's stack frame
+
+ ret
+
diff --git a/apps/plugins/sdl/progs/quake/d_edge.c b/apps/plugins/sdl/progs/quake/d_edge.c
new file mode 100644
index 0000000000..52cc8eb276
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/d_edge.c
@@ -0,0 +1,331 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// d_edge.c
+
+#include "quakedef.h"
+#include "d_local.h"
+
+static int miplevel;
+
+float scale_for_mip;
+int screenwidth;
+int ubasestep, errorterm, erroradjustup, erroradjustdown;
+int vstartscan;
+
+// FIXME: should go away
+extern void R_RotateBmodel (void);
+extern void R_TransformFrustum (void);
+
+vec3_t transformed_modelorg;
+
+/*
+==============
+D_DrawPoly
+
+==============
+*/
+void D_DrawPoly (void)
+{
+// this driver takes spans, not polygons
+}
+
+
+/*
+=============
+D_MipLevelForScale
+=============
+*/
+int D_MipLevelForScale (float scale)
+{
+ int lmiplevel;
+
+ if (scale >= d_scalemip[0] )
+ lmiplevel = 0;
+ else if (scale >= d_scalemip[1] )
+ lmiplevel = 1;
+ else if (scale >= d_scalemip[2] )
+ lmiplevel = 2;
+ else
+ lmiplevel = 3;
+
+ if (lmiplevel < d_minmip)
+ lmiplevel = d_minmip;
+
+ return lmiplevel;
+}
+
+
+/*
+==============
+D_DrawSolidSurface
+==============
+*/
+
+// FIXME: clean this up
+
+void D_DrawSolidSurface (surf_t *surf, int color)
+{
+ espan_t *span;
+ byte *pdest;
+ int u, u2, pix;
+
+ pix = (color<<24) | (color<<16) | (color<<8) | color;
+ for (span=surf->spans ; span ; span=span->pnext)
+ {
+ pdest = (byte *)d_viewbuffer + screenwidth*span->v;
+ u = span->u;
+ u2 = span->u + span->count - 1;
+ ((byte *)pdest)[u] = pix;
+
+ if (u2 - u < 8)
+ {
+ for (u++ ; u <= u2 ; u++)
+ ((byte *)pdest)[u] = pix;
+ }
+ else
+ {
+ for (u++ ; u & 3 ; u++)
+ ((byte *)pdest)[u] = pix;
+
+ u2 -= 4;
+ for ( ; u <= u2 ; u+=4)
+ *(int *)((byte *)pdest + u) = pix;
+ u2 += 4;
+ for ( ; u <= u2 ; u++)
+ ((byte *)pdest)[u] = pix;
+ }
+ }
+}
+
+
+/*
+==============
+D_CalcGradients
+==============
+*/
+void D_CalcGradients (msurface_t *pface)
+{
+ mplane_t *pplane;
+ float mipscale;
+ vec3_t p_temp1;
+ vec3_t p_saxis, p_taxis;
+ float t;
+
+ pplane = pface->plane;
+
+ mipscale = 1.0 / (float)(1 << miplevel);
+
+ TransformVector (pface->texinfo->vecs[0], p_saxis);
+ TransformVector (pface->texinfo->vecs[1], p_taxis);
+
+ t = xscaleinv * mipscale;
+ d_sdivzstepu = p_saxis[0] * t;
+ d_tdivzstepu = p_taxis[0] * t;
+
+ t = yscaleinv * mipscale;
+ d_sdivzstepv = -p_saxis[1] * t;
+ d_tdivzstepv = -p_taxis[1] * t;
+
+ d_sdivzorigin = p_saxis[2] * mipscale - xcenter * d_sdivzstepu -
+ ycenter * d_sdivzstepv;
+ d_tdivzorigin = p_taxis[2] * mipscale - xcenter * d_tdivzstepu -
+ ycenter * d_tdivzstepv;
+
+ VectorScale (transformed_modelorg, mipscale, p_temp1);
+
+ t = 0x10000*mipscale;
+ sadjust = ((fixed16_t)(DotProduct (p_temp1, p_saxis) * 0x10000 + 0.5)) -
+ ((pface->texturemins[0] << 16) >> miplevel)
+ + pface->texinfo->vecs[0][3]*t;
+ tadjust = ((fixed16_t)(DotProduct (p_temp1, p_taxis) * 0x10000 + 0.5)) -
+ ((pface->texturemins[1] << 16) >> miplevel)
+ + pface->texinfo->vecs[1][3]*t;
+
+//
+// -1 (-epsilon) so we never wander off the edge of the texture
+//
+ bbextents = ((pface->extents[0] << 16) >> miplevel) - 1;
+ bbextentt = ((pface->extents[1] << 16) >> miplevel) - 1;
+}
+
+
+/*
+==============
+D_DrawSurfaces
+==============
+*/
+void D_DrawSurfaces (void)
+{
+ surf_t *s;
+ msurface_t *pface;
+ surfcache_t *pcurrentcache;
+ vec3_t world_transformed_modelorg;
+ vec3_t local_modelorg;
+
+ currententity = &cl_entities[0];
+ TransformVector (modelorg, transformed_modelorg);
+ VectorCopy (transformed_modelorg, world_transformed_modelorg);
+
+// TODO: could preset a lot of this at mode set time
+ if (r_drawflat.value)
+ {
+ for (s = &surfaces[1] ; s<surface_p ; s++)
+ {
+ if (!s->spans)
+ continue;
+
+ d_zistepu = s->d_zistepu;
+ d_zistepv = s->d_zistepv;
+ d_ziorigin = s->d_ziorigin;
+
+ D_DrawSolidSurface (s, (int)s->data & 0xFF);
+ D_DrawZSpans (s->spans);
+ }
+ }
+ else
+ {
+ for (s = &surfaces[1] ; s<surface_p ; s++)
+ {
+ if (!s->spans)
+ continue;
+
+ r_drawnpolycount++;
+
+ d_zistepu = s->d_zistepu;
+ d_zistepv = s->d_zistepv;
+ d_ziorigin = s->d_ziorigin;
+
+ if (s->flags & SURF_DRAWSKY)
+ {
+ if (!r_skymade)
+ {
+ R_MakeSky ();
+ }
+
+ D_DrawSkyScans8 (s->spans);
+ D_DrawZSpans (s->spans);
+ }
+ else if (s->flags & SURF_DRAWBACKGROUND)
+ {
+ // set up a gradient for the background surface that places it
+ // effectively at infinity distance from the viewpoint
+ d_zistepu = 0;
+ d_zistepv = 0;
+ d_ziorigin = -0.9;
+
+ D_DrawSolidSurface (s, (int)r_clearcolor.value & 0xFF);
+ D_DrawZSpans (s->spans);
+ }
+ else if (s->flags & SURF_DRAWTURB)
+ {
+ pface = s->data;
+ miplevel = 0;
+ cacheblock = (pixel_t *)
+ ((byte *)pface->texinfo->texture +
+ pface->texinfo->texture->offsets[0]);
+ cachewidth = 64;
+
+ if (s->insubmodel)
+ {
+ // FIXME: we don't want to do all this for every polygon!
+ // TODO: store once at start of frame
+ currententity = s->entity; //FIXME: make this passed in to
+ // R_RotateBmodel ()
+ VectorSubtract (r_origin, currententity->origin,
+ local_modelorg);
+ TransformVector (local_modelorg, transformed_modelorg);
+
+ R_RotateBmodel (); // FIXME: don't mess with the frustum,
+ // make entity passed in
+ }
+
+ D_CalcGradients (pface);
+ Turbulent8 (s->spans);
+ D_DrawZSpans (s->spans);
+
+ if (s->insubmodel)
+ {
+ //
+ // restore the old drawing state
+ // FIXME: we don't want to do this every time!
+ // TODO: speed up
+ //
+ currententity = &cl_entities[0];
+ VectorCopy (world_transformed_modelorg,
+ transformed_modelorg);
+ VectorCopy (base_vpn, vpn);
+ VectorCopy (base_vup, vup);
+ VectorCopy (base_vright, vright);
+ VectorCopy (base_modelorg, modelorg);
+ R_TransformFrustum ();
+ }
+ }
+ else
+ {
+ if (s->insubmodel)
+ {
+ // FIXME: we don't want to do all this for every polygon!
+ // TODO: store once at start of frame
+ currententity = s->entity; //FIXME: make this passed in to
+ // R_RotateBmodel ()
+ VectorSubtract (r_origin, currententity->origin, local_modelorg);
+ TransformVector (local_modelorg, transformed_modelorg);
+
+ R_RotateBmodel (); // FIXME: don't mess with the frustum,
+ // make entity passed in
+ }
+
+ pface = s->data;
+ miplevel = D_MipLevelForScale (s->nearzi * scale_for_mip
+ * pface->texinfo->mipadjust);
+
+ // FIXME: make this passed in to D_CacheSurface
+ pcurrentcache = D_CacheSurface (pface, miplevel);
+
+ cacheblock = (pixel_t *)pcurrentcache->data;
+ cachewidth = pcurrentcache->width;
+
+ D_CalcGradients (pface);
+
+ (*d_drawspans) (s->spans);
+
+ D_DrawZSpans (s->spans);
+
+ if (s->insubmodel)
+ {
+ //
+ // restore the old drawing state
+ // FIXME: we don't want to do this every time!
+ // TODO: speed up
+ //
+ currententity = &cl_entities[0];
+ VectorCopy (world_transformed_modelorg,
+ transformed_modelorg);
+ VectorCopy (base_vpn, vpn);
+ VectorCopy (base_vup, vup);
+ VectorCopy (base_vright, vright);
+ VectorCopy (base_modelorg, modelorg);
+ R_TransformFrustum ();
+ }
+ }
+ }
+ }
+}
+
diff --git a/apps/plugins/sdl/progs/quake/d_fill.c b/apps/plugins/sdl/progs/quake/d_fill.c
new file mode 100644
index 0000000000..e6c14733b4
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/d_fill.c
@@ -0,0 +1,88 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// d_clear: clears a specified rectangle to the specified color
+
+#include "quakedef.h"
+
+
+/*
+================
+D_FillRect
+================
+*/
+void D_FillRect (vrect_t *rect, int color)
+{
+ int rx, ry, rwidth, rheight;
+ unsigned char *dest;
+ unsigned *ldest;
+
+ rx = rect->x;
+ ry = rect->y;
+ rwidth = rect->width;
+ rheight = rect->height;
+
+ if (rx < 0)
+ {
+ rwidth += rx;
+ rx = 0;
+ }
+ if (ry < 0)
+ {
+ rheight += ry;
+ ry = 0;
+ }
+ if (rx+rwidth > vid.width)
+ rwidth = vid.width - rx;
+ if (ry+rheight > vid.height)
+ rheight = vid.height - rx;
+
+ if (rwidth < 1 || rheight < 1)
+ return;
+
+ dest = ((byte *)vid.buffer + ry*vid.rowbytes + rx);
+
+ if (((rwidth & 0x03) == 0) && (((long)dest & 0x03) == 0))
+ {
+ // faster aligned dword clear
+ ldest = (unsigned *)dest;
+ color += color << 16;
+
+ rwidth >>= 2;
+ color += color << 8;
+
+ for (ry=0 ; ry<rheight ; ry++)
+ {
+ for (rx=0 ; rx<rwidth ; rx++)
+ ldest[rx] = color;
+ ldest = (unsigned *)((byte*)ldest + vid.rowbytes);
+ }
+ }
+ else
+ {
+ // slower byte-by-byte clear for unaligned cases
+ for (ry=0 ; ry<rheight ; ry++)
+ {
+ for (rx=0 ; rx<rwidth ; rx++)
+ dest[rx] = color;
+ dest += vid.rowbytes;
+ }
+ }
+}
+
diff --git a/apps/plugins/sdl/progs/quake/d_iface.h b/apps/plugins/sdl/progs/quake/d_iface.h
new file mode 100644
index 0000000000..8dc5ce94bc
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/d_iface.h
@@ -0,0 +1,231 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// d_iface.h: interface header file for rasterization driver modules
+
+#define WARP_WIDTH 320
+#define WARP_HEIGHT 200
+
+#define MAX_LBM_HEIGHT 480
+
+typedef struct
+{
+ float u, v;
+ float s, t;
+ float zi;
+} emitpoint_t;
+
+typedef int ptype_t;
+
+enum {
+ pt_static, pt_grav, pt_slowgrav, pt_fire, pt_explode, pt_explode2, pt_blob, pt_blob2
+};
+
+// !!! if this is changed, it must be changed in d_ifacea.h too !!!
+typedef struct particle_s
+{
+// driver-usable fields
+ vec3_t org;
+ float color;
+// drivers never touch the following fields
+ struct particle_s *next;
+ vec3_t vel;
+ float ramp;
+ float die;
+ ptype_t type;
+} particle_t;
+
+#define PARTICLE_Z_CLIP 8.0
+
+typedef struct polyvert_s {
+ float u, v, zi, s, t;
+} polyvert_t;
+
+typedef struct polydesc_s {
+ int numverts;
+ float nearzi;
+ msurface_t *pcurrentface;
+ polyvert_t *pverts;
+} polydesc_t;
+
+// !!! if this is changed, it must be changed in d_ifacea.h too !!!
+typedef struct finalvert_s {
+ int v[6]; // u, v, s, t, l, 1/z
+ int flags;
+ float reserved;
+} finalvert_t;
+
+// !!! if this is changed, it must be changed in d_ifacea.h too !!!
+typedef struct
+{
+ void *pskin;
+ maliasskindesc_t *pskindesc;
+ int skinwidth;
+ int skinheight;
+ mtriangle_t *ptriangles;
+ finalvert_t *pfinalverts;
+ int numtriangles;
+ int drawtype;
+ int seamfixupX16;
+} affinetridesc_t;
+
+// !!! if this is changed, it must be changed in d_ifacea.h too !!!
+typedef struct {
+ float u, v, zi, color;
+} screenpart_t;
+
+typedef struct
+{
+ int nump;
+ emitpoint_t *pverts; // there's room for an extra element at [nump],
+ // if the driver wants to duplicate element [0] at
+ // element [nump] to avoid dealing with wrapping
+ mspriteframe_t *pspriteframe;
+ vec3_t vup, vright, vpn; // in worldspace
+ float nearzi;
+} spritedesc_t;
+
+typedef struct
+{
+ int u, v;
+ float zi;
+ int color;
+} zpointdesc_t;
+
+extern cvar_t r_drawflat;
+extern int d_spanpixcount;
+extern int r_framecount; // sequence # of current frame since Quake
+ // started
+extern qboolean r_drawpolys; // 1 if driver wants clipped polygons
+ // rather than a span list
+extern qboolean r_drawculledpolys; // 1 if driver wants clipped polygons that
+ // have been culled by the edge list
+extern qboolean r_worldpolysbacktofront; // 1 if driver wants polygons
+ // delivered back to front rather
+ // than front to back
+extern qboolean r_recursiveaffinetriangles; // true if a driver wants to use
+ // recursive triangular subdivison
+ // and vertex drawing via
+ // D_PolysetDrawFinalVerts() past
+ // a certain distance (normally
+ // only used by the software
+ // driver)
+extern float r_aliasuvscale; // scale-up factor for screen u and v
+ // on Alias vertices passed to driver
+extern int r_pixbytes;
+extern qboolean r_dowarp;
+
+extern affinetridesc_t r_affinetridesc;
+extern spritedesc_t r_spritedesc;
+extern zpointdesc_t r_zpointdesc;
+extern polydesc_t r_polydesc;
+
+extern int d_con_indirect; // if 0, Quake will draw console directly
+ // to vid.buffer; if 1, Quake will
+ // draw console via D_DrawRect. Must be
+ // defined by driver
+
+extern vec3_t r_pright, r_pup, r_ppn;
+
+
+void D_Aff8Patch (void *pcolormap);
+void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height);
+void D_DisableBackBufferAccess (void);
+void D_EndDirectRect (int x, int y, int width, int height);
+void D_PolysetDraw (void);
+void D_PolysetDrawFinalVerts (finalvert_t *fv, int numverts);
+void D_DrawParticle (particle_t *pparticle);
+void D_DrawPoly (void);
+void D_DrawSprite (void);
+void D_DrawSurfaces (void);
+void D_DrawZPoint (void);
+void D_EnableBackBufferAccess (void);
+void D_EndParticles (void);
+void D_Init (void);
+void D_ViewChanged (void);
+void D_SetupFrame (void);
+void D_StartParticles (void);
+void D_TurnZOn (void);
+void D_WarpScreen (void);
+
+void D_FillRect (vrect_t *vrect, int color);
+void D_DrawRect (void);
+void D_UpdateRects (vrect_t *prect);
+
+// currently for internal use only, and should be a do-nothing function in
+// hardware drivers
+// FIXME: this should go away
+void D_PolysetUpdateTables (void);
+
+// these are currently for internal use only, and should not be used by drivers
+extern int r_skydirect;
+extern byte *r_skysource;
+
+// transparency types for D_DrawRect ()
+#define DR_SOLID 0
+#define DR_TRANSPARENT 1
+
+// !!! must be kept the same as in quakeasm.h !!!
+#define TRANSPARENT_COLOR 0xFF
+
+extern void *acolormap; // FIXME: should go away
+
+//=======================================================================//
+
+// callbacks to Quake
+
+typedef struct
+{
+ pixel_t *surfdat; // destination for generated surface
+ int rowbytes; // destination logical width in bytes
+ msurface_t *surf; // description for surface to generate
+ fixed8_t lightadj[MAXLIGHTMAPS];
+ // adjust for lightmap levels for dynamic lighting
+ texture_t *texture; // corrected for animating textures
+ int surfmip; // mipmapped ratio of surface texels / world pixels
+ int surfwidth; // in mipmapped texels
+ int surfheight; // in mipmapped texels
+} drawsurf_t;
+
+extern drawsurf_t r_drawsurf;
+
+void R_DrawSurface (void);
+void R_GenTile (msurface_t *psurf, void *pdest);
+
+
+// !!! if this is changed, it must be changed in d_ifacea.h too !!!
+#define TURB_TEX_SIZE 64 // base turbulent texture size
+
+// !!! if this is changed, it must be changed in d_ifacea.h too !!!
+#define CYCLE 128 // turbulent cycle size
+
+#define TILE_SIZE 128 // size of textures generated by R_GenTiledSurf
+
+#define SKYSHIFT 7
+#define SKYSIZE (1 << SKYSHIFT)
+#define SKYMASK (SKYSIZE - 1)
+
+extern float skyspeed, skyspeed2;
+extern float skytime;
+
+extern int c_surf;
+extern vrect_t scr_vrect;
+
+extern byte *r_warpbuffer;
+
diff --git a/apps/plugins/sdl/progs/quake/d_ifacea.h b/apps/plugins/sdl/progs/quake/d_ifacea.h
new file mode 100644
index 0000000000..241952af6f
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/d_ifacea.h
@@ -0,0 +1,98 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+//
+// d_ifacea.h
+//
+// Include file for asm driver interface.
+//
+
+//
+// !!! note that this file must match the corresponding C structures in
+// d_iface.h at all times !!!
+//
+
+// !!! if this is changed, it must be changed in r_shared.h too !!!
+#define ALIAS_ONSEAM 0x0020
+
+// !!! if this is changed, it must be changed in d_iface.h too !!!
+#define TURB_TEX_SIZE 64 // base turbulent texture size
+
+// !!! if this is changed, it must be changed in d_iface.h too !!!
+#define CYCLE 128
+
+// !!! if this is changed, it must be changed in r_shared.h too !!!
+#define MAXHEIGHT 1024
+
+// !!! if this is changed, it must be changed in quakedef.h too !!!
+#define CACHE_SIZE 32 // used to align key data structures
+
+// particle_t structure
+// !!! if this is changed, it must be changed in d_iface.h too !!!
+// driver-usable fields
+#define pt_org 0
+#define pt_color 12
+// drivers never touch the following fields
+#define pt_next 16
+#define pt_vel 20
+#define pt_ramp 32
+#define pt_die 36
+#define pt_type 40
+#define pt_size 44
+
+#define PARTICLE_Z_CLIP 8.0
+
+// finalvert_t structure
+// !!! if this is changed, it must be changed in d_iface.h too !!!
+#define fv_v 0 // !!! if this is moved, cases where the !!!
+ // !!! address of this field is pushed in !!!
+ // !!! d_polysa.s must be changed !!!
+#define fv_flags 24
+#define fv_reserved 28
+#define fv_size 32
+#define fv_shift 5
+
+
+// stvert_t structure
+// !!! if this is changed, it must be changed in modelgen.h too !!!
+#define stv_onseam 0
+#define stv_s 4
+#define stv_t 8
+#define stv_size 12
+
+
+// trivertx_t structure
+// !!! if this is changed, it must be changed in modelgen.h too !!!
+#define tv_v 0
+#define tv_lightnormalindex 3
+#define tv_size 4
+
+// affinetridesc_t structure
+// !!! if this is changed, it must be changed in d_iface.h too !!!
+#define atd_pskin 0
+#define atd_pskindesc 4
+#define atd_skinwidth 8
+#define atd_skinheight 12
+#define atd_ptriangles 16
+#define atd_pfinalverts 20
+#define atd_numtriangles 24
+#define atd_drawtype 28
+#define atd_seamfixupX16 32
+#define atd_size 36
+
diff --git a/apps/plugins/sdl/progs/quake/d_init.c b/apps/plugins/sdl/progs/quake/d_init.c
new file mode 100644
index 0000000000..4c360fa1af
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/d_init.c
@@ -0,0 +1,173 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// d_init.c: rasterization driver initialization
+
+#include "quakedef.h"
+#include "d_local.h"
+
+#define NUM_MIPS 4
+
+cvar_t d_subdiv16 = {"d_subdiv16", "1"};
+cvar_t d_mipcap = {"d_mipcap", "0"};
+cvar_t d_mipscale = {"d_mipscale", "1"};
+
+surfcache_t *d_initial_rover;
+qboolean d_roverwrapped;
+int d_minmip;
+float d_scalemip[NUM_MIPS-1];
+
+static float basemip[NUM_MIPS-1] = {1.0, 0.5*0.8, 0.25*0.8};
+
+extern int d_aflatcolor;
+
+void (*d_drawspans) (espan_t *pspan);
+
+
+/*
+===============
+D_Init
+===============
+*/
+void D_Init (void)
+{
+
+ r_skydirect = 1;
+
+ Cvar_RegisterVariable (&d_subdiv16);
+ Cvar_RegisterVariable (&d_mipcap);
+ Cvar_RegisterVariable (&d_mipscale);
+
+ r_drawpolys = false;
+ r_worldpolysbacktofront = false;
+ r_recursiveaffinetriangles = true;
+ r_pixbytes = 1;
+ r_aliasuvscale = 1.0;
+}
+
+
+/*
+===============
+D_CopyRects
+===============
+*/
+void D_CopyRects (vrect_t *prects, int transparent)
+{
+
+// this function is only required if the CPU doesn't have direct access to the
+// back buffer, and there's some driver interface function that the driver
+// doesn't support and requires Quake to do in software (such as drawing the
+// console); Quake will then draw into wherever the driver points vid.buffer
+// and will call this function before swapping buffers
+
+ UNUSED(prects);
+ UNUSED(transparent);
+}
+
+
+/*
+===============
+D_EnableBackBufferAccess
+===============
+*/
+void D_EnableBackBufferAccess (void)
+{
+ VID_LockBuffer ();
+}
+
+
+/*
+===============
+D_TurnZOn
+===============
+*/
+void D_TurnZOn (void)
+{
+// not needed for software version
+}
+
+
+/*
+===============
+D_DisableBackBufferAccess
+===============
+*/
+void D_DisableBackBufferAccess (void)
+{
+ VID_UnlockBuffer ();
+}
+
+
+/*
+===============
+D_SetupFrame
+===============
+*/
+void D_SetupFrame (void)
+{
+ int i;
+
+ if (r_dowarp)
+ d_viewbuffer = r_warpbuffer;
+ else
+ d_viewbuffer = (void *)(byte *)vid.buffer;
+
+ if (r_dowarp)
+ screenwidth = WARP_WIDTH;
+ else
+ screenwidth = vid.rowbytes;
+
+ d_roverwrapped = false;
+ d_initial_rover = sc_rover;
+
+ d_minmip = d_mipcap.value;
+ if (d_minmip > 3)
+ d_minmip = 3;
+ else if (d_minmip < 0)
+ d_minmip = 0;
+
+ for (i=0 ; i<(NUM_MIPS-1) ; i++)
+ d_scalemip[i] = basemip[i] * d_mipscale.value;
+
+#if id386
+ if (d_subdiv16.value)
+ d_drawspans = D_DrawSpans16;
+ else
+ d_drawspans = D_DrawSpans8;
+#else
+ d_drawspans = D_DrawSpans8;
+#endif
+
+ d_aflatcolor = 0;
+}
+
+
+/*
+===============
+D_UpdateRects
+===============
+*/
+void D_UpdateRects (vrect_t *prect)
+{
+
+// the software driver draws these directly to the vid buffer
+
+ UNUSED(prect);
+}
+
diff --git a/apps/plugins/sdl/progs/quake/d_local.h b/apps/plugins/sdl/progs/quake/d_local.h
new file mode 100644
index 0000000000..af924899e5
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/d_local.h
@@ -0,0 +1,111 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// d_local.h: private rasterization driver defs
+
+#include "r_shared.h"
+
+//
+// TODO: fine-tune this; it's based on providing some overage even if there
+// is a 2k-wide scan, with subdivision every 8, for 256 spans of 12 bytes each
+//
+#define SCANBUFFERPAD 0x1000
+
+#define R_SKY_SMASK 0x007F0000
+#define R_SKY_TMASK 0x007F0000
+
+#define DS_SPAN_LIST_END -128
+
+#define SURFCACHE_SIZE_AT_320X200 600*1024
+
+typedef struct surfcache_s
+{
+ struct surfcache_s *next;
+ struct surfcache_s **owner; // NULL is an empty chunk of memory
+ int lightadj[MAXLIGHTMAPS]; // checked for strobe flush
+ int dlight;
+ int size; // including header
+ unsigned width;
+ unsigned height; // DEBUG only needed for debug
+ float mipscale;
+ struct texture_s *texture; // checked for animating textures
+ byte data[4]; // width*height elements
+} surfcache_t;
+
+// !!! if this is changed, it must be changed in asm_draw.h too !!!
+typedef struct sspan_s
+{
+ int u, v, count;
+} sspan_t;
+
+extern cvar_t d_subdiv16;
+
+extern float scale_for_mip;
+
+extern qboolean d_roverwrapped;
+extern surfcache_t *sc_rover;
+extern surfcache_t *d_initial_rover;
+
+extern float d_sdivzstepu, d_tdivzstepu, d_zistepu;
+extern float d_sdivzstepv, d_tdivzstepv, d_zistepv;
+extern float d_sdivzorigin, d_tdivzorigin, d_ziorigin;
+
+fixed16_t sadjust, tadjust;
+fixed16_t bbextents, bbextentt;
+
+
+void D_DrawSpans8 (espan_t *pspans);
+void D_DrawSpans16 (espan_t *pspans);
+void D_DrawZSpans (espan_t *pspans);
+void Turbulent8 (espan_t *pspan);
+void D_SpriteDrawSpans (sspan_t *pspan);
+
+void D_DrawSkyScans8 (espan_t *pspan);
+void D_DrawSkyScans16 (espan_t *pspan);
+
+void R_ShowSubDiv (void);
+void (*prealspandrawer)(void);
+surfcache_t *D_CacheSurface (msurface_t *surface, int miplevel);
+
+extern int D_MipLevelForScale (float scale);
+
+#if id386
+extern void D_PolysetAff8Start (void);
+extern void D_PolysetAff8End (void);
+#endif
+
+extern short *d_pzbuffer;
+extern unsigned int d_zrowbytes, d_zwidth;
+
+extern int *d_pscantable;
+extern int d_scantable[MAXHEIGHT];
+
+extern int d_vrectx, d_vrecty, d_vrectright_particle, d_vrectbottom_particle;
+
+extern int d_y_aspect_shift, d_pix_min, d_pix_max, d_pix_shift;
+
+extern pixel_t *d_viewbuffer;
+
+extern short *zspantable[MAXHEIGHT];
+
+extern int d_minmip;
+extern float d_scalemip[3];
+
+extern void (*d_drawspans) (espan_t *pspan);
+
diff --git a/apps/plugins/sdl/progs/quake/d_modech.c b/apps/plugins/sdl/progs/quake/d_modech.c
new file mode 100644
index 0000000000..75c188e362
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/d_modech.c
@@ -0,0 +1,107 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// d_modech.c: called when mode has just changed
+
+#include "quakedef.h"
+#include "d_local.h"
+
+int d_vrectx, d_vrecty, d_vrectright_particle, d_vrectbottom_particle;
+
+int d_y_aspect_shift, d_pix_min, d_pix_max, d_pix_shift;
+
+int d_scantable[MAXHEIGHT];
+short *zspantable[MAXHEIGHT];
+
+/*
+================
+D_Patch
+================
+*/
+void D_Patch (void)
+{
+#if id386
+
+ static qboolean protectset8 = false;
+
+ if (!protectset8)
+ {
+ Sys_MakeCodeWriteable ((int)D_PolysetAff8Start,
+ (int)D_PolysetAff8End - (int)D_PolysetAff8Start);
+ protectset8 = true;
+ }
+
+#endif // id386
+}
+
+
+/*
+================
+D_ViewChanged
+================
+*/
+void D_ViewChanged (void)
+{
+ int rowbytes;
+
+ if (r_dowarp)
+ rowbytes = WARP_WIDTH;
+ else
+ rowbytes = vid.rowbytes;
+
+ scale_for_mip = xscale;
+ if (yscale > xscale)
+ scale_for_mip = yscale;
+
+ d_zrowbytes = vid.width * 2;
+ d_zwidth = vid.width;
+
+ d_pix_min = r_refdef.vrect.width / 320;
+ if (d_pix_min < 1)
+ d_pix_min = 1;
+
+ d_pix_max = (int)((float)r_refdef.vrect.width / (320.0 / 4.0) + 0.5);
+ d_pix_shift = 8 - (int)((float)r_refdef.vrect.width / 320.0 + 0.5);
+ if (d_pix_max < 1)
+ d_pix_max = 1;
+
+ if (pixelAspect > 1.4)
+ d_y_aspect_shift = 1;
+ else
+ d_y_aspect_shift = 0;
+
+ d_vrectx = r_refdef.vrect.x;
+ d_vrecty = r_refdef.vrect.y;
+ d_vrectright_particle = r_refdef.vrectright - d_pix_max;
+ d_vrectbottom_particle =
+ r_refdef.vrectbottom - (d_pix_max << d_y_aspect_shift);
+
+ {
+ int i;
+
+ for (i=0 ; i<vid.height; i++)
+ {
+ d_scantable[i] = i*rowbytes;
+ zspantable[i] = d_pzbuffer + i*d_zwidth;
+ }
+ }
+
+ D_Patch ();
+}
+
diff --git a/apps/plugins/sdl/progs/quake/d_part.c b/apps/plugins/sdl/progs/quake/d_part.c
new file mode 100644
index 0000000000..176b76beab
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/d_part.c
@@ -0,0 +1,207 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// d_part.c: software driver module for drawing particles
+
+#include "quakedef.h"
+#include "d_local.h"
+
+
+/*
+==============
+D_EndParticles
+==============
+*/
+void D_EndParticles (void)
+{
+// not used by software driver
+}
+
+
+/*
+==============
+D_StartParticles
+==============
+*/
+void D_StartParticles (void)
+{
+// not used by software driver
+}
+
+
+#if !id386
+
+/*
+==============
+D_DrawParticle
+==============
+*/
+void D_DrawParticle (particle_t *pparticle)
+{
+ vec3_t local, transformed;
+ float zi;
+ byte *pdest;
+ short *pz;
+ int i, izi, pix, count, u, v;
+
+// transform point
+ VectorSubtract (pparticle->org, r_origin, local);
+
+ transformed[0] = DotProduct(local, r_pright);
+ transformed[1] = DotProduct(local, r_pup);
+ transformed[2] = DotProduct(local, r_ppn);
+
+ if (transformed[2] < PARTICLE_Z_CLIP)
+ return;
+
+// project the point
+// FIXME: preadjust xcenter and ycenter
+ zi = 1.0 / transformed[2];
+ u = (int)(xcenter + zi * transformed[0] + 0.5);
+ v = (int)(ycenter - zi * transformed[1] + 0.5);
+
+ if ((v > d_vrectbottom_particle) ||
+ (u > d_vrectright_particle) ||
+ (v < d_vrecty) ||
+ (u < d_vrectx))
+ {
+ return;
+ }
+
+ pz = d_pzbuffer + (d_zwidth * v) + u;
+ pdest = d_viewbuffer + d_scantable[v] + u;
+ izi = (int)(zi * 0x8000);
+
+ pix = izi >> d_pix_shift;
+
+ if (pix < d_pix_min)
+ pix = d_pix_min;
+ else if (pix > d_pix_max)
+ pix = d_pix_max;
+
+ switch (pix)
+ {
+ case 1:
+ count = 1 << d_y_aspect_shift;
+
+ for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
+ {
+ if (pz[0] <= izi)
+ {
+ pz[0] = izi;
+ pdest[0] = pparticle->color;
+ }
+ }
+ break;
+
+ case 2:
+ count = 2 << d_y_aspect_shift;
+
+ for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
+ {
+ if (pz[0] <= izi)
+ {
+ pz[0] = izi;
+ pdest[0] = pparticle->color;
+ }
+
+ if (pz[1] <= izi)
+ {
+ pz[1] = izi;
+ pdest[1] = pparticle->color;
+ }
+ }
+ break;
+
+ case 3:
+ count = 3 << d_y_aspect_shift;
+
+ for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
+ {
+ if (pz[0] <= izi)
+ {
+ pz[0] = izi;
+ pdest[0] = pparticle->color;
+ }
+
+ if (pz[1] <= izi)
+ {
+ pz[1] = izi;
+ pdest[1] = pparticle->color;
+ }
+
+ if (pz[2] <= izi)
+ {
+ pz[2] = izi;
+ pdest[2] = pparticle->color;
+ }
+ }
+ break;
+
+ case 4:
+ count = 4 << d_y_aspect_shift;
+
+ for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
+ {
+ if (pz[0] <= izi)
+ {
+ pz[0] = izi;
+ pdest[0] = pparticle->color;
+ }
+
+ if (pz[1] <= izi)
+ {
+ pz[1] = izi;
+ pdest[1] = pparticle->color;
+ }
+
+ if (pz[2] <= izi)
+ {
+ pz[2] = izi;
+ pdest[2] = pparticle->color;
+ }
+
+ if (pz[3] <= izi)
+ {
+ pz[3] = izi;
+ pdest[3] = pparticle->color;
+ }
+ }
+ break;
+
+ default:
+ count = pix << d_y_aspect_shift;
+
+ for ( ; count ; count--, pz += d_zwidth, pdest += screenwidth)
+ {
+ for (i=0 ; i<pix ; i++)
+ {
+ if (pz[i] <= izi)
+ {
+ pz[i] = izi;
+ pdest[i] = pparticle->color;
+ }
+ }
+ }
+ break;
+ }
+}
+
+#endif // !id386
+
diff --git a/apps/plugins/sdl/progs/quake/d_polyse.c b/apps/plugins/sdl/progs/quake/d_polyse.c
new file mode 100644
index 0000000000..9acd34b102
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/d_polyse.c
@@ -0,0 +1,1111 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// d_polyset.c: routines for drawing sets of polygons sharing the same
+// texture (used for Alias models)
+
+#include "quakedef.h"
+#include "r_local.h"
+#include "d_local.h"
+
+// TODO: put in span spilling to shrink list size
+// !!! if this is changed, it must be changed in d_polysa.s too !!!
+#define DPS_MAXSPANS MAXHEIGHT+1
+ // 1 extra for spanpackage that marks end
+
+// !!! if this is changed, it must be changed in asm_draw.h too !!!
+typedef struct {
+ void *pdest;
+ short *pz;
+ int count;
+ byte *ptex;
+ int sfrac, tfrac, light, zi;
+} spanpackage_t;
+
+typedef struct {
+ int isflattop;
+ int numleftedges;
+ int *pleftedgevert0;
+ int *pleftedgevert1;
+ int *pleftedgevert2;
+ int numrightedges;
+ int *prightedgevert0;
+ int *prightedgevert1;
+ int *prightedgevert2;
+} edgetable;
+
+int r_p0[6], r_p1[6], r_p2[6];
+
+byte *d_pcolormap;
+
+int d_aflatcolor;
+int d_xdenom;
+
+edgetable *pedgetable;
+
+edgetable edgetables[12] = {
+ {0, 1, r_p0, r_p2, NULL, 2, r_p0, r_p1, r_p2 },
+ {0, 2, r_p1, r_p0, r_p2, 1, r_p1, r_p2, NULL},
+ {1, 1, r_p0, r_p2, NULL, 1, r_p1, r_p2, NULL},
+ {0, 1, r_p1, r_p0, NULL, 2, r_p1, r_p2, r_p0 },
+ {0, 2, r_p0, r_p2, r_p1, 1, r_p0, r_p1, NULL},
+ {0, 1, r_p2, r_p1, NULL, 1, r_p2, r_p0, NULL},
+ {0, 1, r_p2, r_p1, NULL, 2, r_p2, r_p0, r_p1 },
+ {0, 2, r_p2, r_p1, r_p0, 1, r_p2, r_p0, NULL},
+ {0, 1, r_p1, r_p0, NULL, 1, r_p1, r_p2, NULL},
+ {1, 1, r_p2, r_p1, NULL, 1, r_p0, r_p1, NULL},
+ {1, 1, r_p1, r_p0, NULL, 1, r_p2, r_p0, NULL},
+ {0, 1, r_p0, r_p2, NULL, 1, r_p0, r_p1, NULL},
+};
+
+// FIXME: some of these can become statics
+int a_sstepxfrac, a_tstepxfrac, r_lstepx, a_ststepxwhole;
+int r_sstepx, r_tstepx, r_lstepy, r_sstepy, r_tstepy;
+int r_zistepx, r_zistepy;
+int d_aspancount, d_countextrastep;
+
+spanpackage_t *a_spans;
+spanpackage_t *d_pedgespanpackage;
+static int ystart;
+byte *d_pdest, *d_ptex;
+short *d_pz;
+int d_sfrac, d_tfrac, d_light, d_zi;
+int d_ptexextrastep, d_sfracextrastep;
+int d_tfracextrastep, d_lightextrastep, d_pdestextrastep;
+int d_lightbasestep, d_pdestbasestep, d_ptexbasestep;
+int d_sfracbasestep, d_tfracbasestep;
+int d_ziextrastep, d_zibasestep;
+int d_pzextrastep, d_pzbasestep;
+
+typedef struct {
+ int quotient;
+ int remainder;
+} adivtab_t;
+
+static adivtab_t adivtab[32*32] = {
+#include "adivtab.h"
+};
+
+byte *skintable[MAX_LBM_HEIGHT];
+int skinwidth;
+byte *skinstart;
+
+void D_PolysetDrawSpans8 (spanpackage_t *pspanpackage);
+void D_PolysetCalcGradients (int skinwidth);
+void D_DrawSubdiv (void);
+void D_DrawNonSubdiv (void);
+void D_PolysetRecursiveTriangle (int *p1, int *p2, int *p3);
+void D_PolysetSetEdgeTable (void);
+void D_RasterizeAliasPolySmooth (void);
+void D_PolysetScanLeftEdge (int height);
+
+#if !id386
+
+/*
+================
+D_PolysetDraw
+================
+*/
+void D_PolysetDraw (void)
+{
+ spanpackage_t spans[DPS_MAXSPANS + 1 +
+ ((CACHE_SIZE - 1) / sizeof(spanpackage_t)) + 1];
+ // one extra because of cache line pretouching
+
+ a_spans = (spanpackage_t *)
+ (((long)&spans[0] + CACHE_SIZE - 1) & ~(CACHE_SIZE - 1));
+
+ if (r_affinetridesc.drawtype)
+ {
+ D_DrawSubdiv ();
+ }
+ else
+ {
+ D_DrawNonSubdiv ();
+ }
+}
+
+
+/*
+================
+D_PolysetDrawFinalVerts
+================
+*/
+void D_PolysetDrawFinalVerts (finalvert_t *fv, int numverts)
+{
+ int i, z;
+ short *zbuf;
+
+ for (i=0 ; i<numverts ; i++, fv++)
+ {
+ // valid triangle coordinates for filling can include the bottom and
+ // right clip edges, due to the fill rule; these shouldn't be drawn
+ if ((fv->v[0] < r_refdef.vrectright) &&
+ (fv->v[1] < r_refdef.vrectbottom))
+ {
+ z = fv->v[5]>>16;
+ zbuf = zspantable[fv->v[1]] + fv->v[0];
+ if (z >= *zbuf)
+ {
+ int pix;
+
+ *zbuf = z;
+ pix = skintable[fv->v[3]>>16][fv->v[2]>>16];
+ pix = ((byte *)acolormap)[pix + (fv->v[4] & 0xFF00) ];
+ d_viewbuffer[d_scantable[fv->v[1]] + fv->v[0]] = pix;
+ }
+ }
+ }
+}
+
+
+/*
+================
+D_DrawSubdiv
+================
+*/
+void D_DrawSubdiv (void)
+{
+ mtriangle_t *ptri;
+ finalvert_t *pfv, *index0, *index1, *index2;
+ int i;
+ int lnumtriangles;
+
+ pfv = r_affinetridesc.pfinalverts;
+ ptri = r_affinetridesc.ptriangles;
+ lnumtriangles = r_affinetridesc.numtriangles;
+
+ for (i=0 ; i<lnumtriangles ; i++)
+ {
+ index0 = pfv + ptri[i].vertindex[0];
+ index1 = pfv + ptri[i].vertindex[1];
+ index2 = pfv + ptri[i].vertindex[2];
+
+ if (((index0->v[1]-index1->v[1]) *
+ (index0->v[0]-index2->v[0]) -
+ (index0->v[0]-index1->v[0]) *
+ (index0->v[1]-index2->v[1])) >= 0)
+ {
+ continue;
+ }
+
+ d_pcolormap = &((byte *)acolormap)[index0->v[4] & 0xFF00];
+
+ if (ptri[i].facesfront)
+ {
+ D_PolysetRecursiveTriangle(index0->v, index1->v, index2->v);
+ }
+ else
+ {
+ int s0, s1, s2;
+
+ s0 = index0->v[2];
+ s1 = index1->v[2];
+ s2 = index2->v[2];
+
+ if (index0->flags & ALIAS_ONSEAM)
+ index0->v[2] += r_affinetridesc.seamfixupX16;
+ if (index1->flags & ALIAS_ONSEAM)
+ index1->v[2] += r_affinetridesc.seamfixupX16;
+ if (index2->flags & ALIAS_ONSEAM)
+ index2->v[2] += r_affinetridesc.seamfixupX16;
+
+ D_PolysetRecursiveTriangle(index0->v, index1->v, index2->v);
+
+ index0->v[2] = s0;
+ index1->v[2] = s1;
+ index2->v[2] = s2;
+ }
+ }
+}
+
+
+/*
+================
+D_DrawNonSubdiv
+================
+*/
+void D_DrawNonSubdiv (void)
+{
+ mtriangle_t *ptri;
+ finalvert_t *pfv, *index0, *index1, *index2;
+ int i;
+ int lnumtriangles;
+
+ pfv = r_affinetridesc.pfinalverts;
+ ptri = r_affinetridesc.ptriangles;
+ lnumtriangles = r_affinetridesc.numtriangles;
+
+ for (i=0 ; i<lnumtriangles ; i++, ptri++)
+ {
+ index0 = pfv + ptri->vertindex[0];
+ index1 = pfv + ptri->vertindex[1];
+ index2 = pfv + ptri->vertindex[2];
+
+ d_xdenom = (index0->v[1]-index1->v[1]) *
+ (index0->v[0]-index2->v[0]) -
+ (index0->v[0]-index1->v[0])*(index0->v[1]-index2->v[1]);
+
+ if (d_xdenom >= 0)
+ {
+ continue;
+ }
+
+ r_p0[0] = index0->v[0]; // u
+ r_p0[1] = index0->v[1]; // v
+ r_p0[2] = index0->v[2]; // s
+ r_p0[3] = index0->v[3]; // t
+ r_p0[4] = index0->v[4]; // light
+ r_p0[5] = index0->v[5]; // iz
+
+ r_p1[0] = index1->v[0];
+ r_p1[1] = index1->v[1];
+ r_p1[2] = index1->v[2];
+ r_p1[3] = index1->v[3];
+ r_p1[4] = index1->v[4];
+ r_p1[5] = index1->v[5];
+
+ r_p2[0] = index2->v[0];
+ r_p2[1] = index2->v[1];
+ r_p2[2] = index2->v[2];
+ r_p2[3] = index2->v[3];
+ r_p2[4] = index2->v[4];
+ r_p2[5] = index2->v[5];
+
+ if (!ptri->facesfront)
+ {
+ if (index0->flags & ALIAS_ONSEAM)
+ r_p0[2] += r_affinetridesc.seamfixupX16;
+ if (index1->flags & ALIAS_ONSEAM)
+ r_p1[2] += r_affinetridesc.seamfixupX16;
+ if (index2->flags & ALIAS_ONSEAM)
+ r_p2[2] += r_affinetridesc.seamfixupX16;
+ }
+
+ D_PolysetSetEdgeTable ();
+ D_RasterizeAliasPolySmooth ();
+ }
+}
+
+
+/*
+================
+D_PolysetRecursiveTriangle
+================
+*/
+void D_PolysetRecursiveTriangle (int *lp1, int *lp2, int *lp3)
+{
+ int *temp;
+ int d;
+ int new[6];
+ int z;
+ short *zbuf;
+
+ d = lp2[0] - lp1[0];
+ if (d < -1 || d > 1)
+ goto split;
+ d = lp2[1] - lp1[1];
+ if (d < -1 || d > 1)
+ goto split;
+
+ d = lp3[0] - lp2[0];
+ if (d < -1 || d > 1)
+ goto split2;
+ d = lp3[1] - lp2[1];
+ if (d < -1 || d > 1)
+ goto split2;
+
+ d = lp1[0] - lp3[0];
+ if (d < -1 || d > 1)
+ goto split3;
+ d = lp1[1] - lp3[1];
+ if (d < -1 || d > 1)
+ {
+split3:
+ temp = lp1;
+ lp1 = lp3;
+ lp3 = lp2;
+ lp2 = temp;
+
+ goto split;
+ }
+
+ return; // entire tri is filled
+
+split2:
+ temp = lp1;
+ lp1 = lp2;
+ lp2 = lp3;
+ lp3 = temp;
+
+split:
+// split this edge
+ new[0] = (lp1[0] + lp2[0]) >> 1;
+ new[1] = (lp1[1] + lp2[1]) >> 1;
+ new[2] = (lp1[2] + lp2[2]) >> 1;
+ new[3] = (lp1[3] + lp2[3]) >> 1;
+ new[5] = (lp1[5] + lp2[5]) >> 1;
+
+// draw the point if splitting a leading edge
+ if (lp2[1] > lp1[1])
+ goto nodraw;
+ if ((lp2[1] == lp1[1]) && (lp2[0] < lp1[0]))
+ goto nodraw;
+
+
+ z = new[5]>>16;
+ zbuf = zspantable[new[1]] + new[0];
+ if (z >= *zbuf)
+ {
+ int pix;
+
+ *zbuf = z;
+ pix = d_pcolormap[skintable[new[3]>>16][new[2]>>16]];
+ d_viewbuffer[d_scantable[new[1]] + new[0]] = pix;
+ }
+
+nodraw:
+// recursively continue
+ D_PolysetRecursiveTriangle (lp3, lp1, new);
+ D_PolysetRecursiveTriangle (lp3, new, lp2);
+}
+
+#endif // !id386
+
+
+/*
+================
+D_PolysetUpdateTables
+================
+*/
+void D_PolysetUpdateTables (void)
+{
+ int i;
+ byte *s;
+
+ if (r_affinetridesc.skinwidth != skinwidth ||
+ r_affinetridesc.pskin != skinstart)
+ {
+ skinwidth = r_affinetridesc.skinwidth;
+ skinstart = r_affinetridesc.pskin;
+ s = skinstart;
+ for (i=0 ; i<MAX_LBM_HEIGHT ; i++, s+=skinwidth)
+ skintable[i] = s;
+ }
+}
+
+
+#if !id386
+
+/*
+===================
+D_PolysetScanLeftEdge
+====================
+*/
+void D_PolysetScanLeftEdge (int height)
+{
+
+ do
+ {
+ d_pedgespanpackage->pdest = d_pdest;
+ d_pedgespanpackage->pz = d_pz;
+ d_pedgespanpackage->count = d_aspancount;
+ d_pedgespanpackage->ptex = d_ptex;
+
+ d_pedgespanpackage->sfrac = d_sfrac;
+ d_pedgespanpackage->tfrac = d_tfrac;
+
+ // FIXME: need to clamp l, s, t, at both ends?
+ d_pedgespanpackage->light = d_light;
+ d_pedgespanpackage->zi = d_zi;
+
+ d_pedgespanpackage++;
+
+ errorterm += erroradjustup;
+ if (errorterm >= 0)
+ {
+ d_pdest += d_pdestextrastep;
+ d_pz += d_pzextrastep;
+ d_aspancount += d_countextrastep;
+ d_ptex += d_ptexextrastep;
+ d_sfrac += d_sfracextrastep;
+ d_ptex += d_sfrac >> 16;
+
+ d_sfrac &= 0xFFFF;
+ d_tfrac += d_tfracextrastep;
+ if (d_tfrac & 0x10000)
+ {
+ d_ptex += r_affinetridesc.skinwidth;
+ d_tfrac &= 0xFFFF;
+ }
+ d_light += d_lightextrastep;
+ d_zi += d_ziextrastep;
+ errorterm -= erroradjustdown;
+ }
+ else
+ {
+ d_pdest += d_pdestbasestep;
+ d_pz += d_pzbasestep;
+ d_aspancount += ubasestep;
+ d_ptex += d_ptexbasestep;
+ d_sfrac += d_sfracbasestep;
+ d_ptex += d_sfrac >> 16;
+ d_sfrac &= 0xFFFF;
+ d_tfrac += d_tfracbasestep;
+ if (d_tfrac & 0x10000)
+ {
+ d_ptex += r_affinetridesc.skinwidth;
+ d_tfrac &= 0xFFFF;
+ }
+ d_light += d_lightbasestep;
+ d_zi += d_zibasestep;
+ }
+ } while (--height);
+}
+
+#endif // !id386
+
+
+/*
+===================
+D_PolysetSetUpForLineScan
+====================
+*/
+void D_PolysetSetUpForLineScan(fixed8_t startvertu, fixed8_t startvertv,
+ fixed8_t endvertu, fixed8_t endvertv)
+{
+ double dm, dn;
+ int tm, tn;
+ adivtab_t *ptemp;
+
+// TODO: implement x86 version
+
+ errorterm = -1;
+
+ tm = endvertu - startvertu;
+ tn = endvertv - startvertv;
+
+ if (((tm <= 16) && (tm >= -15)) &&
+ ((tn <= 16) && (tn >= -15)))
+ {
+ ptemp = &adivtab[((tm+15) << 5) + (tn+15)];
+ ubasestep = ptemp->quotient;
+ erroradjustup = ptemp->remainder;
+ erroradjustdown = tn;
+ }
+ else
+ {
+ dm = (double)tm;
+ dn = (double)tn;
+
+ FloorDivMod (dm, dn, &ubasestep, &erroradjustup);
+
+ erroradjustdown = dn;
+ }
+}
+
+
+#if !id386
+
+/*
+================
+D_PolysetCalcGradients
+================
+*/
+void D_PolysetCalcGradients (int skinwidth)
+{
+ float xstepdenominv, ystepdenominv, t0, t1;
+ float p01_minus_p21, p11_minus_p21, p00_minus_p20, p10_minus_p20;
+
+ p00_minus_p20 = r_p0[0] - r_p2[0];
+ p01_minus_p21 = r_p0[1] - r_p2[1];
+ p10_minus_p20 = r_p1[0] - r_p2[0];
+ p11_minus_p21 = r_p1[1] - r_p2[1];
+
+ xstepdenominv = 1.0 / (float)d_xdenom;
+
+ ystepdenominv = -xstepdenominv;
+
+// ceil () for light so positive steps are exaggerated, negative steps
+// diminished, pushing us away from underflow toward overflow. Underflow is
+// very visible, overflow is very unlikely, because of ambient lighting
+ t0 = r_p0[4] - r_p2[4];
+ t1 = r_p1[4] - r_p2[4];
+ r_lstepx = (int)
+ ceil((t1 * p01_minus_p21 - t0 * p11_minus_p21) * xstepdenominv);
+ r_lstepy = (int)
+ ceil((t1 * p00_minus_p20 - t0 * p10_minus_p20) * ystepdenominv);
+
+ t0 = r_p0[2] - r_p2[2];
+ t1 = r_p1[2] - r_p2[2];
+ r_sstepx = (int)((t1 * p01_minus_p21 - t0 * p11_minus_p21) *
+ xstepdenominv);
+ r_sstepy = (int)((t1 * p00_minus_p20 - t0* p10_minus_p20) *
+ ystepdenominv);
+
+ t0 = r_p0[3] - r_p2[3];
+ t1 = r_p1[3] - r_p2[3];
+ r_tstepx = (int)((t1 * p01_minus_p21 - t0 * p11_minus_p21) *
+ xstepdenominv);
+ r_tstepy = (int)((t1 * p00_minus_p20 - t0 * p10_minus_p20) *
+ ystepdenominv);
+
+ t0 = r_p0[5] - r_p2[5];
+ t1 = r_p1[5] - r_p2[5];
+ r_zistepx = (int)((t1 * p01_minus_p21 - t0 * p11_minus_p21) *
+ xstepdenominv);
+ r_zistepy = (int)((t1 * p00_minus_p20 - t0 * p10_minus_p20) *
+ ystepdenominv);
+
+#if id386
+ a_sstepxfrac = r_sstepx << 16;
+ a_tstepxfrac = r_tstepx << 16;
+#else
+ a_sstepxfrac = r_sstepx & 0xFFFF;
+ a_tstepxfrac = r_tstepx & 0xFFFF;
+#endif
+
+ a_ststepxwhole = skinwidth * (r_tstepx >> 16) + (r_sstepx >> 16);
+}
+
+#endif // !id386
+
+
+#if 0
+byte gelmap[256];
+void InitGel (byte *palette)
+{
+ int i;
+ int r;
+
+ for (i=0 ; i<256 ; i++)
+ {
+// r = (palette[i*3]>>4);
+ r = (palette[i*3] + palette[i*3+1] + palette[i*3+2])/(16*3);
+ gelmap[i] = /* 64 */ 0 + r;
+ }
+}
+#endif
+
+
+#if !id386
+
+/*
+================
+D_PolysetDrawSpans8
+================
+*/
+void D_PolysetDrawSpans8 (spanpackage_t *pspanpackage)
+{
+ int lcount;
+ byte *lpdest;
+ byte *lptex;
+ int lsfrac, ltfrac;
+ int llight;
+ int lzi;
+ short *lpz;
+
+ do
+ {
+ lcount = d_aspancount - pspanpackage->count;
+
+ errorterm += erroradjustup;
+ if (errorterm >= 0)
+ {
+ d_aspancount += d_countextrastep;
+ errorterm -= erroradjustdown;
+ }
+ else
+ {
+ d_aspancount += ubasestep;
+ }
+
+ if (lcount)
+ {
+ lpdest = pspanpackage->pdest;
+ lptex = pspanpackage->ptex;
+ lpz = pspanpackage->pz;
+ lsfrac = pspanpackage->sfrac;
+ ltfrac = pspanpackage->tfrac;
+ llight = pspanpackage->light;
+ lzi = pspanpackage->zi;
+
+ do
+ {
+ if ((lzi >> 16) >= *lpz)
+ {
+ *lpdest = ((byte *)acolormap)[*lptex + (llight & 0xFF00)];
+// gel mapping *lpdest = gelmap[*lpdest];
+ *lpz = lzi >> 16;
+ }
+ lpdest++;
+ lzi += r_zistepx;
+ lpz++;
+ llight += r_lstepx;
+ lptex += a_ststepxwhole;
+ lsfrac += a_sstepxfrac;
+ lptex += lsfrac >> 16;
+ lsfrac &= 0xFFFF;
+ ltfrac += a_tstepxfrac;
+ if (ltfrac & 0x10000)
+ {
+ lptex += r_affinetridesc.skinwidth;
+ ltfrac &= 0xFFFF;
+ }
+ } while (--lcount);
+ }
+
+ pspanpackage++;
+ } while (pspanpackage->count != -999999);
+}
+#endif // !id386
+
+
+/*
+================
+D_PolysetFillSpans8
+================
+*/
+void D_PolysetFillSpans8 (spanpackage_t *pspanpackage)
+{
+ int color;
+
+// FIXME: do z buffering
+
+ color = d_aflatcolor++;
+
+ while (1)
+ {
+ int lcount;
+ byte *lpdest;
+
+ lcount = pspanpackage->count;
+
+ if (lcount == -1)
+ return;
+
+ if (lcount)
+ {
+ lpdest = pspanpackage->pdest;
+
+ do
+ {
+ *lpdest++ = color;
+ } while (--lcount);
+ }
+
+ pspanpackage++;
+ }
+}
+
+/*
+================
+D_RasterizeAliasPolySmooth
+================
+*/
+void D_RasterizeAliasPolySmooth (void)
+{
+ int initialleftheight, initialrightheight;
+ int *plefttop, *prighttop, *pleftbottom, *prightbottom;
+ int working_lstepx, originalcount;
+
+ plefttop = pedgetable->pleftedgevert0;
+ prighttop = pedgetable->prightedgevert0;
+
+ pleftbottom = pedgetable->pleftedgevert1;
+ prightbottom = pedgetable->prightedgevert1;
+
+ initialleftheight = pleftbottom[1] - plefttop[1];
+ initialrightheight = prightbottom[1] - prighttop[1];
+
+//
+// set the s, t, and light gradients, which are consistent across the triangle
+// because being a triangle, things are affine
+//
+ D_PolysetCalcGradients (r_affinetridesc.skinwidth);
+
+//
+// rasterize the polygon
+//
+
+//
+// scan out the top (and possibly only) part of the left edge
+//
+ d_pedgespanpackage = a_spans;
+
+ ystart = plefttop[1];
+ d_aspancount = plefttop[0] - prighttop[0];
+
+ d_ptex = (byte *)r_affinetridesc.pskin + (plefttop[2] >> 16) +
+ (plefttop[3] >> 16) * r_affinetridesc.skinwidth;
+#if id386
+ d_sfrac = (plefttop[2] & 0xFFFF) << 16;
+ d_tfrac = (plefttop[3] & 0xFFFF) << 16;
+#else
+ d_sfrac = plefttop[2] & 0xFFFF;
+ d_tfrac = plefttop[3] & 0xFFFF;
+#endif
+ d_light = plefttop[4];
+ d_zi = plefttop[5];
+
+ d_pdest = (byte *)d_viewbuffer +
+ ystart * screenwidth + plefttop[0];
+ d_pz = d_pzbuffer + ystart * d_zwidth + plefttop[0];
+
+ if (initialleftheight == 1)
+ {
+ d_pedgespanpackage->pdest = d_pdest;
+ d_pedgespanpackage->pz = d_pz;
+ d_pedgespanpackage->count = d_aspancount;
+ d_pedgespanpackage->ptex = d_ptex;
+
+ d_pedgespanpackage->sfrac = d_sfrac;
+ d_pedgespanpackage->tfrac = d_tfrac;
+
+ // FIXME: need to clamp l, s, t, at both ends?
+ d_pedgespanpackage->light = d_light;
+ d_pedgespanpackage->zi = d_zi;
+
+ d_pedgespanpackage++;
+ }
+ else
+ {
+ D_PolysetSetUpForLineScan(plefttop[0], plefttop[1],
+ pleftbottom[0], pleftbottom[1]);
+
+ #if id386
+ d_pzbasestep = (d_zwidth + ubasestep) << 1;
+ d_pzextrastep = d_pzbasestep + 2;
+ #else
+ d_pzbasestep = d_zwidth + ubasestep;
+ d_pzextrastep = d_pzbasestep + 1;
+ #endif
+
+ d_pdestbasestep = screenwidth + ubasestep;
+ d_pdestextrastep = d_pdestbasestep + 1;
+
+ // TODO: can reuse partial expressions here
+
+ // for negative steps in x along left edge, bias toward overflow rather than
+ // underflow (sort of turning the floor () we did in the gradient calcs into
+ // ceil (), but plus a little bit)
+ if (ubasestep < 0)
+ working_lstepx = r_lstepx - 1;
+ else
+ working_lstepx = r_lstepx;
+
+ d_countextrastep = ubasestep + 1;
+ d_ptexbasestep = ((r_sstepy + r_sstepx * ubasestep) >> 16) +
+ ((r_tstepy + r_tstepx * ubasestep) >> 16) *
+ r_affinetridesc.skinwidth;
+ #if id386
+ d_sfracbasestep = (r_sstepy + r_sstepx * ubasestep) << 16;
+ d_tfracbasestep = (r_tstepy + r_tstepx * ubasestep) << 16;
+ #else
+ d_sfracbasestep = (r_sstepy + r_sstepx * ubasestep) & 0xFFFF;
+ d_tfracbasestep = (r_tstepy + r_tstepx * ubasestep) & 0xFFFF;
+ #endif
+ d_lightbasestep = r_lstepy + working_lstepx * ubasestep;
+ d_zibasestep = r_zistepy + r_zistepx * ubasestep;
+
+ d_ptexextrastep = ((r_sstepy + r_sstepx * d_countextrastep) >> 16) +
+ ((r_tstepy + r_tstepx * d_countextrastep) >> 16) *
+ r_affinetridesc.skinwidth;
+ #if id386
+ d_sfracextrastep = (r_sstepy + r_sstepx*d_countextrastep) << 16;
+ d_tfracextrastep = (r_tstepy + r_tstepx*d_countextrastep) << 16;
+ #else
+ d_sfracextrastep = (r_sstepy + r_sstepx*d_countextrastep) & 0xFFFF;
+ d_tfracextrastep = (r_tstepy + r_tstepx*d_countextrastep) & 0xFFFF;
+ #endif
+ d_lightextrastep = d_lightbasestep + working_lstepx;
+ d_ziextrastep = d_zibasestep + r_zistepx;
+
+ D_PolysetScanLeftEdge (initialleftheight);
+ }
+
+//
+// scan out the bottom part of the left edge, if it exists
+//
+ if (pedgetable->numleftedges == 2)
+ {
+ int height;
+
+ plefttop = pleftbottom;
+ pleftbottom = pedgetable->pleftedgevert2;
+
+ height = pleftbottom[1] - plefttop[1];
+
+// TODO: make this a function; modularize this function in general
+
+ ystart = plefttop[1];
+ d_aspancount = plefttop[0] - prighttop[0];
+ d_ptex = (byte *)r_affinetridesc.pskin + (plefttop[2] >> 16) +
+ (plefttop[3] >> 16) * r_affinetridesc.skinwidth;
+ d_sfrac = 0;
+ d_tfrac = 0;
+ d_light = plefttop[4];
+ d_zi = plefttop[5];
+
+ d_pdest = (byte *)d_viewbuffer + ystart * screenwidth + plefttop[0];
+ d_pz = d_pzbuffer + ystart * d_zwidth + plefttop[0];
+
+ if (height == 1)
+ {
+ d_pedgespanpackage->pdest = d_pdest;
+ d_pedgespanpackage->pz = d_pz;
+ d_pedgespanpackage->count = d_aspancount;
+ d_pedgespanpackage->ptex = d_ptex;
+
+ d_pedgespanpackage->sfrac = d_sfrac;
+ d_pedgespanpackage->tfrac = d_tfrac;
+
+ // FIXME: need to clamp l, s, t, at both ends?
+ d_pedgespanpackage->light = d_light;
+ d_pedgespanpackage->zi = d_zi;
+
+ d_pedgespanpackage++;
+ }
+ else
+ {
+ D_PolysetSetUpForLineScan(plefttop[0], plefttop[1],
+ pleftbottom[0], pleftbottom[1]);
+
+ d_pdestbasestep = screenwidth + ubasestep;
+ d_pdestextrastep = d_pdestbasestep + 1;
+
+ #if id386
+ d_pzbasestep = (d_zwidth + ubasestep) << 1;
+ d_pzextrastep = d_pzbasestep + 2;
+ #else
+ d_pzbasestep = d_zwidth + ubasestep;
+ d_pzextrastep = d_pzbasestep + 1;
+ #endif
+
+ if (ubasestep < 0)
+ working_lstepx = r_lstepx - 1;
+ else
+ working_lstepx = r_lstepx;
+
+ d_countextrastep = ubasestep + 1;
+ d_ptexbasestep = ((r_sstepy + r_sstepx * ubasestep) >> 16) +
+ ((r_tstepy + r_tstepx * ubasestep) >> 16) *
+ r_affinetridesc.skinwidth;
+ #if id386
+ d_sfracbasestep = (r_sstepy + r_sstepx * ubasestep) << 16;
+ d_tfracbasestep = (r_tstepy + r_tstepx * ubasestep) << 16;
+ #else
+ d_sfracbasestep = (r_sstepy + r_sstepx * ubasestep) & 0xFFFF;
+ d_tfracbasestep = (r_tstepy + r_tstepx * ubasestep) & 0xFFFF;
+ #endif
+ d_lightbasestep = r_lstepy + working_lstepx * ubasestep;
+ d_zibasestep = r_zistepy + r_zistepx * ubasestep;
+
+ d_ptexextrastep = ((r_sstepy + r_sstepx * d_countextrastep) >> 16) +
+ ((r_tstepy + r_tstepx * d_countextrastep) >> 16) *
+ r_affinetridesc.skinwidth;
+ #if id386
+ d_sfracextrastep = ((r_sstepy+r_sstepx*d_countextrastep) & 0xFFFF)<<16;
+ d_tfracextrastep = ((r_tstepy+r_tstepx*d_countextrastep) & 0xFFFF)<<16;
+ #else
+ d_sfracextrastep = (r_sstepy+r_sstepx*d_countextrastep) & 0xFFFF;
+ d_tfracextrastep = (r_tstepy+r_tstepx*d_countextrastep) & 0xFFFF;
+ #endif
+ d_lightextrastep = d_lightbasestep + working_lstepx;
+ d_ziextrastep = d_zibasestep + r_zistepx;
+
+ D_PolysetScanLeftEdge (height);
+ }
+ }
+
+// scan out the top (and possibly only) part of the right edge, updating the
+// count field
+ d_pedgespanpackage = a_spans;
+
+ D_PolysetSetUpForLineScan(prighttop[0], prighttop[1],
+ prightbottom[0], prightbottom[1]);
+ d_aspancount = 0;
+ d_countextrastep = ubasestep + 1;
+ originalcount = a_spans[initialrightheight].count;
+ a_spans[initialrightheight].count = -999999; // mark end of the spanpackages
+ D_PolysetDrawSpans8 (a_spans);
+
+// scan out the bottom part of the right edge, if it exists
+ if (pedgetable->numrightedges == 2)
+ {
+ int height;
+ spanpackage_t *pstart;
+
+ pstart = a_spans + initialrightheight;
+ pstart->count = originalcount;
+
+ d_aspancount = prightbottom[0] - prighttop[0];
+
+ prighttop = prightbottom;
+ prightbottom = pedgetable->prightedgevert2;
+
+ height = prightbottom[1] - prighttop[1];
+
+ D_PolysetSetUpForLineScan(prighttop[0], prighttop[1],
+ prightbottom[0], prightbottom[1]);
+
+ d_countextrastep = ubasestep + 1;
+ a_spans[initialrightheight + height].count = -999999;
+ // mark end of the spanpackages
+ D_PolysetDrawSpans8 (pstart);
+ }
+}
+
+
+/*
+================
+D_PolysetSetEdgeTable
+================
+*/
+void D_PolysetSetEdgeTable (void)
+{
+ int edgetableindex;
+
+ edgetableindex = 0; // assume the vertices are already in
+ // top to bottom order
+
+//
+// determine which edges are right & left, and the order in which
+// to rasterize them
+//
+ if (r_p0[1] >= r_p1[1])
+ {
+ if (r_p0[1] == r_p1[1])
+ {
+ if (r_p0[1] < r_p2[1])
+ pedgetable = &edgetables[2];
+ else
+ pedgetable = &edgetables[5];
+
+ return;
+ }
+ else
+ {
+ edgetableindex = 1;
+ }
+ }
+
+ if (r_p0[1] == r_p2[1])
+ {
+ if (edgetableindex)
+ pedgetable = &edgetables[8];
+ else
+ pedgetable = &edgetables[9];
+
+ return;
+ }
+ else if (r_p1[1] == r_p2[1])
+ {
+ if (edgetableindex)
+ pedgetable = &edgetables[10];
+ else
+ pedgetable = &edgetables[11];
+
+ return;
+ }
+
+ if (r_p0[1] > r_p2[1])
+ edgetableindex += 2;
+
+ if (r_p1[1] > r_p2[1])
+ edgetableindex += 4;
+
+ pedgetable = &edgetables[edgetableindex];
+}
+
+
+#if 0
+
+void D_PolysetRecursiveDrawLine (int *lp1, int *lp2)
+{
+ int d;
+ int new[6];
+ int ofs;
+
+ d = lp2[0] - lp1[0];
+ if (d < -1 || d > 1)
+ goto split;
+ d = lp2[1] - lp1[1];
+ if (d < -1 || d > 1)
+ goto split;
+
+ return; // line is completed
+
+split:
+// split this edge
+ new[0] = (lp1[0] + lp2[0]) >> 1;
+ new[1] = (lp1[1] + lp2[1]) >> 1;
+ new[5] = (lp1[5] + lp2[5]) >> 1;
+ new[2] = (lp1[2] + lp2[2]) >> 1;
+ new[3] = (lp1[3] + lp2[3]) >> 1;
+ new[4] = (lp1[4] + lp2[4]) >> 1;
+
+// draw the point
+ ofs = d_scantable[new[1]] + new[0];
+ if (new[5] > d_pzbuffer[ofs])
+ {
+ int pix;
+
+ d_pzbuffer[ofs] = new[5];
+ pix = skintable[new[3]>>16][new[2]>>16];
+// pix = ((byte *)acolormap)[pix + (new[4] & 0xFF00)];
+ d_viewbuffer[ofs] = pix;
+ }
+
+// recursively continue
+ D_PolysetRecursiveDrawLine (lp1, new);
+ D_PolysetRecursiveDrawLine (new, lp2);
+}
+
+void D_PolysetRecursiveTriangle2 (int *lp1, int *lp2, int *lp3)
+{
+ int d;
+ int new[4];
+
+ d = lp2[0] - lp1[0];
+ if (d < -1 || d > 1)
+ goto split;
+ d = lp2[1] - lp1[1];
+ if (d < -1 || d > 1)
+ goto split;
+ return;
+
+split:
+// split this edge
+ new[0] = (lp1[0] + lp2[0]) >> 1;
+ new[1] = (lp1[1] + lp2[1]) >> 1;
+ new[5] = (lp1[5] + lp2[5]) >> 1;
+ new[2] = (lp1[2] + lp2[2]) >> 1;
+ new[3] = (lp1[3] + lp2[3]) >> 1;
+ new[4] = (lp1[4] + lp2[4]) >> 1;
+
+ D_PolysetRecursiveDrawLine (new, lp3);
+
+// recursively continue
+ D_PolysetRecursiveTriangle (lp1, new, lp3);
+ D_PolysetRecursiveTriangle (new, lp2, lp3);
+}
+
+#endif
+
diff --git a/apps/plugins/sdl/progs/quake/d_scan.c b/apps/plugins/sdl/progs/quake/d_scan.c
new file mode 100644
index 0000000000..008c783be6
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/d_scan.c
@@ -0,0 +1,449 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// d_scan.c
+//
+// Portable C scan-level rasterization code, all pixel depths.
+
+#include "quakedef.h"
+#include "r_local.h"
+#include "d_local.h"
+
+unsigned char *r_turb_pbase, *r_turb_pdest;
+fixed16_t r_turb_s, r_turb_t, r_turb_sstep, r_turb_tstep;
+int *r_turb_turb;
+int r_turb_spancount;
+
+void D_DrawTurbulent8Span (void);
+
+
+/*
+=============
+D_WarpScreen
+
+// this performs a slight compression of the screen at the same time as
+// the sine warp, to keep the edges from wrapping
+=============
+*/
+void D_WarpScreen (void)
+{
+ int w, h;
+ int u,v;
+ byte *dest;
+ int *turb;
+ int *col;
+ byte **row;
+ byte *rowptr[MAXHEIGHT+(AMP2*2)];
+ int column[MAXWIDTH+(AMP2*2)];
+ float wratio, hratio;
+
+ w = r_refdef.vrect.width;
+ h = r_refdef.vrect.height;
+
+ wratio = w / (float)scr_vrect.width;
+ hratio = h / (float)scr_vrect.height;
+
+ for (v=0 ; v<scr_vrect.height+AMP2*2 ; v++)
+ {
+ rowptr[v] = d_viewbuffer + (r_refdef.vrect.y * screenwidth) +
+ (screenwidth * (int)((float)v * hratio * h / (h + AMP2 * 2)));
+ }
+
+ for (u=0 ; u<scr_vrect.width+AMP2*2 ; u++)
+ {
+ column[u] = r_refdef.vrect.x +
+ (int)((float)u * wratio * w / (w + AMP2 * 2));
+ }
+
+ turb = intsintable + ((int)(cl.time*SPEED)&(CYCLE-1));
+ dest = vid.buffer + scr_vrect.y * vid.rowbytes + scr_vrect.x;
+
+ for (v=0 ; v<scr_vrect.height ; v++, dest += vid.rowbytes)
+ {
+ col = &column[turb[v]];
+ row = &rowptr[v];
+
+ for (u=0 ; u<scr_vrect.width ; u+=4)
+ {
+ dest[u+0] = row[turb[u+0]][col[u+0]];
+ dest[u+1] = row[turb[u+1]][col[u+1]];
+ dest[u+2] = row[turb[u+2]][col[u+2]];
+ dest[u+3] = row[turb[u+3]][col[u+3]];
+ }
+ }
+}
+
+
+#if !id386
+
+/*
+=============
+D_DrawTurbulent8Span
+=============
+*/
+void D_DrawTurbulent8Span (void)
+{
+ int sturb, tturb;
+
+ do
+ {
+ sturb = ((r_turb_s + r_turb_turb[(r_turb_t>>16)&(CYCLE-1)])>>16)&63;
+ tturb = ((r_turb_t + r_turb_turb[(r_turb_s>>16)&(CYCLE-1)])>>16)&63;
+ *r_turb_pdest++ = *(r_turb_pbase + (tturb<<6) + sturb);
+ r_turb_s += r_turb_sstep;
+ r_turb_t += r_turb_tstep;
+ } while (--r_turb_spancount > 0);
+}
+
+#endif // !id386
+
+
+/*
+=============
+Turbulent8
+=============
+*/
+void Turbulent8 (espan_t *pspan)
+{
+ int count;
+ fixed16_t snext, tnext;
+ float sdivz, tdivz, zi, z, du, dv, spancountminus1;
+ float sdivz16stepu, tdivz16stepu, zi16stepu;
+
+ r_turb_turb = sintable + ((int)(cl.time*SPEED)&(CYCLE-1));
+
+ r_turb_sstep = 0; // keep compiler happy
+ r_turb_tstep = 0; // ditto
+
+ r_turb_pbase = (unsigned char *)cacheblock;
+
+ sdivz16stepu = d_sdivzstepu * 16;
+ tdivz16stepu = d_tdivzstepu * 16;
+ zi16stepu = d_zistepu * 16;
+
+ do
+ {
+ r_turb_pdest = (unsigned char *)((byte *)d_viewbuffer +
+ (screenwidth * pspan->v) + pspan->u);
+
+ count = pspan->count;
+
+ // calculate the initial s/z, t/z, 1/z, s, and t and clamp
+ du = (float)pspan->u;
+ dv = (float)pspan->v;
+
+ sdivz = d_sdivzorigin + dv*d_sdivzstepv + du*d_sdivzstepu;
+ tdivz = d_tdivzorigin + dv*d_tdivzstepv + du*d_tdivzstepu;
+ zi = d_ziorigin + dv*d_zistepv + du*d_zistepu;
+ z = (float)0x10000 / zi; // prescale to 16.16 fixed-point
+
+ r_turb_s = (int)(sdivz * z) + sadjust;
+ if (r_turb_s > bbextents)
+ r_turb_s = bbextents;
+ else if (r_turb_s < 0)
+ r_turb_s = 0;
+
+ r_turb_t = (int)(tdivz * z) + tadjust;
+ if (r_turb_t > bbextentt)
+ r_turb_t = bbextentt;
+ else if (r_turb_t < 0)
+ r_turb_t = 0;
+
+ do
+ {
+ // calculate s and t at the far end of the span
+ if (count >= 16)
+ r_turb_spancount = 16;
+ else
+ r_turb_spancount = count;
+
+ count -= r_turb_spancount;
+
+ if (count)
+ {
+ // calculate s/z, t/z, zi->fixed s and t at far end of span,
+ // calculate s and t steps across span by shifting
+ sdivz += sdivz16stepu;
+ tdivz += tdivz16stepu;
+ zi += zi16stepu;
+ z = (float)0x10000 / zi; // prescale to 16.16 fixed-point
+
+ snext = (int)(sdivz * z) + sadjust;
+ if (snext > bbextents)
+ snext = bbextents;
+ else if (snext < 16)
+ snext = 16; // prevent round-off error on <0 steps from
+ // from causing overstepping & running off the
+ // edge of the texture
+
+ tnext = (int)(tdivz * z) + tadjust;
+ if (tnext > bbextentt)
+ tnext = bbextentt;
+ else if (tnext < 16)
+ tnext = 16; // guard against round-off error on <0 steps
+
+ r_turb_sstep = (snext - r_turb_s) >> 4;
+ r_turb_tstep = (tnext - r_turb_t) >> 4;
+ }
+ else
+ {
+ // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so
+ // can't step off polygon), clamp, calculate s and t steps across
+ // span by division, biasing steps low so we don't run off the
+ // texture
+ spancountminus1 = (float)(r_turb_spancount - 1);
+ sdivz += d_sdivzstepu * spancountminus1;
+ tdivz += d_tdivzstepu * spancountminus1;
+ zi += d_zistepu * spancountminus1;
+ z = (float)0x10000 / zi; // prescale to 16.16 fixed-point
+ snext = (int)(sdivz * z) + sadjust;
+ if (snext > bbextents)
+ snext = bbextents;
+ else if (snext < 16)
+ snext = 16; // prevent round-off error on <0 steps from
+ // from causing overstepping & running off the
+ // edge of the texture
+
+ tnext = (int)(tdivz * z) + tadjust;
+ if (tnext > bbextentt)
+ tnext = bbextentt;
+ else if (tnext < 16)
+ tnext = 16; // guard against round-off error on <0 steps
+
+ if (r_turb_spancount > 1)
+ {
+ r_turb_sstep = (snext - r_turb_s) / (r_turb_spancount - 1);
+ r_turb_tstep = (tnext - r_turb_t) / (r_turb_spancount - 1);
+ }
+ }
+
+ r_turb_s = r_turb_s & ((CYCLE<<16)-1);
+ r_turb_t = r_turb_t & ((CYCLE<<16)-1);
+
+ D_DrawTurbulent8Span ();
+
+ r_turb_s = snext;
+ r_turb_t = tnext;
+
+ } while (count > 0);
+
+ } while ((pspan = pspan->pnext) != NULL);
+}
+
+
+#if !id386
+
+/*
+=============
+D_DrawSpans8
+=============
+*/
+void D_DrawSpans8 (espan_t *pspan)
+{
+ int count, spancount;
+ unsigned char *pbase, *pdest;
+ fixed16_t s, t, snext, tnext, sstep, tstep;
+ float sdivz, tdivz, zi, z, du, dv, spancountminus1;
+ float sdivz8stepu, tdivz8stepu, zi8stepu;
+
+ sstep = 0; // keep compiler happy
+ tstep = 0; // ditto
+
+ pbase = (unsigned char *)cacheblock;
+
+ sdivz8stepu = d_sdivzstepu * 8;
+ tdivz8stepu = d_tdivzstepu * 8;
+ zi8stepu = d_zistepu * 8;
+
+ do
+ {
+ pdest = (unsigned char *)((byte *)d_viewbuffer +
+ (screenwidth * pspan->v) + pspan->u);
+
+ count = pspan->count;
+
+ // calculate the initial s/z, t/z, 1/z, s, and t and clamp
+ du = (float)pspan->u;
+ dv = (float)pspan->v;
+
+ sdivz = d_sdivzorigin + dv*d_sdivzstepv + du*d_sdivzstepu;
+ tdivz = d_tdivzorigin + dv*d_tdivzstepv + du*d_tdivzstepu;
+ zi = d_ziorigin + dv*d_zistepv + du*d_zistepu;
+ z = (float)0x10000 / zi; // prescale to 16.16 fixed-point
+
+ s = (int)(sdivz * z) + sadjust;
+ if (s > bbextents)
+ s = bbextents;
+ else if (s < 0)
+ s = 0;
+
+ t = (int)(tdivz * z) + tadjust;
+ if (t > bbextentt)
+ t = bbextentt;
+ else if (t < 0)
+ t = 0;
+
+ do
+ {
+ // calculate s and t at the far end of the span
+ if (count >= 8)
+ spancount = 8;
+ else
+ spancount = count;
+
+ count -= spancount;
+
+ if (count)
+ {
+ // calculate s/z, t/z, zi->fixed s and t at far end of span,
+ // calculate s and t steps across span by shifting
+ sdivz += sdivz8stepu;
+ tdivz += tdivz8stepu;
+ zi += zi8stepu;
+ z = (float)0x10000 / zi; // prescale to 16.16 fixed-point
+
+ snext = (int)(sdivz * z) + sadjust;
+ if (snext > bbextents)
+ snext = bbextents;
+ else if (snext < 8)
+ snext = 8; // prevent round-off error on <0 steps from
+ // from causing overstepping & running off the
+ // edge of the texture
+
+ tnext = (int)(tdivz * z) + tadjust;
+ if (tnext > bbextentt)
+ tnext = bbextentt;
+ else if (tnext < 8)
+ tnext = 8; // guard against round-off error on <0 steps
+
+ sstep = (snext - s) >> 3;
+ tstep = (tnext - t) >> 3;
+ }
+ else
+ {
+ // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so
+ // can't step off polygon), clamp, calculate s and t steps across
+ // span by division, biasing steps low so we don't run off the
+ // texture
+ spancountminus1 = (float)(spancount - 1);
+ sdivz += d_sdivzstepu * spancountminus1;
+ tdivz += d_tdivzstepu * spancountminus1;
+ zi += d_zistepu * spancountminus1;
+ z = (float)0x10000 / zi; // prescale to 16.16 fixed-point
+ snext = (int)(sdivz * z) + sadjust;
+ if (snext > bbextents)
+ snext = bbextents;
+ else if (snext < 8)
+ snext = 8; // prevent round-off error on <0 steps from
+ // from causing overstepping & running off the
+ // edge of the texture
+
+ tnext = (int)(tdivz * z) + tadjust;
+ if (tnext > bbextentt)
+ tnext = bbextentt;
+ else if (tnext < 8)
+ tnext = 8; // guard against round-off error on <0 steps
+
+ if (spancount > 1)
+ {
+ sstep = (snext - s) / (spancount - 1);
+ tstep = (tnext - t) / (spancount - 1);
+ }
+ }
+
+ do
+ {
+ *pdest++ = *(pbase + (s >> 16) + (t >> 16) * cachewidth);
+ s += sstep;
+ t += tstep;
+ } while (--spancount > 0);
+
+ s = snext;
+ t = tnext;
+
+ } while (count > 0);
+
+ } while ((pspan = pspan->pnext) != NULL);
+}
+
+#endif
+
+
+#if !id386
+
+/*
+=============
+D_DrawZSpans
+=============
+*/
+void D_DrawZSpans (espan_t *pspan)
+{
+ int count, doublecount, izistep;
+ int izi;
+ short *pdest;
+ unsigned ltemp;
+ double zi;
+ float du, dv;
+
+// FIXME: check for clamping/range problems
+// we count on FP exceptions being turned off to avoid range problems
+ izistep = (int)(d_zistepu * 0x8000 * 0x10000);
+
+ do
+ {
+ pdest = d_pzbuffer + (d_zwidth * pspan->v) + pspan->u;
+
+ count = pspan->count;
+
+ // calculate the initial 1/z
+ du = (float)pspan->u;
+ dv = (float)pspan->v;
+
+ zi = d_ziorigin + dv*d_zistepv + du*d_zistepu;
+ // we count on FP exceptions being turned off to avoid range problems
+ izi = (int)(zi * 0x8000 * 0x10000);
+
+ if ((long)pdest & 0x02)
+ {
+ *pdest++ = (short)(izi >> 16);
+ izi += izistep;
+ count--;
+ }
+
+ if ((doublecount = count >> 1) > 0)
+ {
+ do
+ {
+ ltemp = izi >> 16;
+ izi += izistep;
+ ltemp |= izi & 0xFFFF0000;
+ izi += izistep;
+ *(int *)pdest = ltemp;
+ pdest += 2;
+ } while (--doublecount > 0);
+ }
+
+ if (count & 1)
+ *pdest = (short)(izi >> 16);
+
+ } while ((pspan = pspan->pnext) != NULL);
+}
+
+#endif
+
diff --git a/apps/plugins/sdl/progs/quake/d_sky.c b/apps/plugins/sdl/progs/quake/d_sky.c
new file mode 100644
index 0000000000..9e28a8e576
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/d_sky.c
@@ -0,0 +1,138 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// d_sky.c
+
+#include "quakedef.h"
+#include "r_local.h"
+#include "d_local.h"
+
+#define SKY_SPAN_SHIFT 5
+#define SKY_SPAN_MAX (1 << SKY_SPAN_SHIFT)
+
+
+/*
+=================
+D_Sky_uv_To_st
+=================
+*/
+void D_Sky_uv_To_st (int u, int v, fixed16_t *s, fixed16_t *t)
+{
+ float wu, wv, temp;
+ vec3_t end;
+
+ if (r_refdef.vrect.width >= r_refdef.vrect.height)
+ temp = (float)r_refdef.vrect.width;
+ else
+ temp = (float)r_refdef.vrect.height;
+
+ wu = 8192.0 * (float)(u-((int)vid.width>>1)) / temp;
+ wv = 8192.0 * (float)(((int)vid.height>>1)-v) / temp;
+
+ end[0] = 4096*vpn[0] + wu*vright[0] + wv*vup[0];
+ end[1] = 4096*vpn[1] + wu*vright[1] + wv*vup[1];
+ end[2] = 4096*vpn[2] + wu*vright[2] + wv*vup[2];
+ end[2] *= 3;
+ VectorNormalizeNoRet (end);
+
+ temp = skytime*skyspeed; // TODO: add D_SetupFrame & set this there
+ *s = (int)((temp + 6*(SKYSIZE/2-1)*end[0]) * 0x10000);
+ *t = (int)((temp + 6*(SKYSIZE/2-1)*end[1]) * 0x10000);
+}
+
+
+/*
+=================
+D_DrawSkyScans8
+=================
+*/
+void D_DrawSkyScans8 (espan_t *pspan)
+{
+ int count, spancount, u, v;
+ unsigned char *pdest;
+ fixed16_t s, t, snext, tnext, sstep, tstep;
+ int spancountminus1;
+
+ sstep = 0; // keep compiler happy
+ tstep = 0; // ditto
+
+ do
+ {
+ pdest = (unsigned char *)((byte *)d_viewbuffer +
+ (screenwidth * pspan->v) + pspan->u);
+
+ count = pspan->count;
+
+ // calculate the initial s & t
+ u = pspan->u;
+ v = pspan->v;
+ D_Sky_uv_To_st (u, v, &s, &t);
+
+ do
+ {
+ if (count >= SKY_SPAN_MAX)
+ spancount = SKY_SPAN_MAX;
+ else
+ spancount = count;
+
+ count -= spancount;
+
+ if (count)
+ {
+ u += spancount;
+
+ // calculate s and t at far end of span,
+ // calculate s and t steps across span by shifting
+ D_Sky_uv_To_st (u, v, &snext, &tnext);
+
+ sstep = (snext - s) >> SKY_SPAN_SHIFT;
+ tstep = (tnext - t) >> SKY_SPAN_SHIFT;
+ }
+ else
+ {
+ // calculate s and t at last pixel in span,
+ // calculate s and t steps across span by division
+ spancountminus1 = (float)(spancount - 1);
+
+ if (spancountminus1 > 0)
+ {
+ u += spancountminus1;
+ D_Sky_uv_To_st (u, v, &snext, &tnext);
+
+ sstep = (snext - s) / spancountminus1;
+ tstep = (tnext - t) / spancountminus1;
+ }
+ }
+
+ do
+ {
+ *pdest++ = r_skysource[((t & R_SKY_TMASK) >> 8) +
+ ((s & R_SKY_SMASK) >> 16)];
+ s += sstep;
+ t += tstep;
+ } while (--spancount > 0);
+
+ s = snext;
+ t = tnext;
+
+ } while (count > 0);
+
+ } while ((pspan = pspan->pnext) != NULL);
+}
+
diff --git a/apps/plugins/sdl/progs/quake/d_sprite.c b/apps/plugins/sdl/progs/quake/d_sprite.c
new file mode 100644
index 0000000000..2f02ad2c64
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/d_sprite.c
@@ -0,0 +1,442 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// d_sprite.c: software top-level rasterization driver module for drawing
+// sprites
+
+#include "quakedef.h"
+#include "d_local.h"
+
+static int sprite_height;
+static int minindex, maxindex;
+static sspan_t *sprite_spans;
+
+#if !id386
+
+/*
+=====================
+D_SpriteDrawSpans
+=====================
+*/
+void D_SpriteDrawSpans (sspan_t *pspan)
+{
+ int count, spancount, izistep;
+ int izi;
+ byte *pbase, *pdest;
+ fixed16_t s, t, snext, tnext, sstep, tstep;
+ float sdivz, tdivz, zi, z, du, dv, spancountminus1;
+ float sdivz8stepu, tdivz8stepu, zi8stepu;
+ byte btemp;
+ short *pz;
+
+ sstep = 0; // keep compiler happy
+ tstep = 0; // ditto
+
+ pbase = cacheblock;
+
+ sdivz8stepu = d_sdivzstepu * 8;
+ tdivz8stepu = d_tdivzstepu * 8;
+ zi8stepu = d_zistepu * 8;
+
+// we count on FP exceptions being turned off to avoid range problems
+ izistep = (int)(d_zistepu * 0x8000 * 0x10000);
+
+ do
+ {
+ pdest = (byte *)d_viewbuffer + (screenwidth * pspan->v) + pspan->u;
+ pz = d_pzbuffer + (d_zwidth * pspan->v) + pspan->u;
+
+ count = pspan->count;
+
+ if (count <= 0)
+ goto NextSpan;
+
+ // calculate the initial s/z, t/z, 1/z, s, and t and clamp
+ du = (float)pspan->u;
+ dv = (float)pspan->v;
+
+ sdivz = d_sdivzorigin + dv*d_sdivzstepv + du*d_sdivzstepu;
+ tdivz = d_tdivzorigin + dv*d_tdivzstepv + du*d_tdivzstepu;
+ zi = d_ziorigin + dv*d_zistepv + du*d_zistepu;
+ z = (float)0x10000 / zi; // prescale to 16.16 fixed-point
+ // we count on FP exceptions being turned off to avoid range problems
+ izi = (int)(zi * 0x8000 * 0x10000);
+
+ s = (int)(sdivz * z) + sadjust;
+ if (s > bbextents)
+ s = bbextents;
+ else if (s < 0)
+ s = 0;
+
+ t = (int)(tdivz * z) + tadjust;
+ if (t > bbextentt)
+ t = bbextentt;
+ else if (t < 0)
+ t = 0;
+
+ do
+ {
+ // calculate s and t at the far end of the span
+ if (count >= 8)
+ spancount = 8;
+ else
+ spancount = count;
+
+ count -= spancount;
+
+ if (count)
+ {
+ // calculate s/z, t/z, zi->fixed s and t at far end of span,
+ // calculate s and t steps across span by shifting
+ sdivz += sdivz8stepu;
+ tdivz += tdivz8stepu;
+ zi += zi8stepu;
+ z = (float)0x10000 / zi; // prescale to 16.16 fixed-point
+
+ snext = (int)(sdivz * z) + sadjust;
+ if (snext > bbextents)
+ snext = bbextents;
+ else if (snext < 8)
+ snext = 8; // prevent round-off error on <0 steps from
+ // from causing overstepping & running off the
+ // edge of the texture
+
+ tnext = (int)(tdivz * z) + tadjust;
+ if (tnext > bbextentt)
+ tnext = bbextentt;
+ else if (tnext < 8)
+ tnext = 8; // guard against round-off error on <0 steps
+
+ sstep = (snext - s) >> 3;
+ tstep = (tnext - t) >> 3;
+ }
+ else
+ {
+ // calculate s/z, t/z, zi->fixed s and t at last pixel in span (so
+ // can't step off polygon), clamp, calculate s and t steps across
+ // span by division, biasing steps low so we don't run off the
+ // texture
+ spancountminus1 = (float)(spancount - 1);
+ sdivz += d_sdivzstepu * spancountminus1;
+ tdivz += d_tdivzstepu * spancountminus1;
+ zi += d_zistepu * spancountminus1;
+ z = (float)0x10000 / zi; // prescale to 16.16 fixed-point
+ snext = (int)(sdivz * z) + sadjust;
+ if (snext > bbextents)
+ snext = bbextents;
+ else if (snext < 8)
+ snext = 8; // prevent round-off error on <0 steps from
+ // from causing overstepping & running off the
+ // edge of the texture
+
+ tnext = (int)(tdivz * z) + tadjust;
+ if (tnext > bbextentt)
+ tnext = bbextentt;
+ else if (tnext < 8)
+ tnext = 8; // guard against round-off error on <0 steps
+
+ if (spancount > 1)
+ {
+ sstep = (snext - s) / (spancount - 1);
+ tstep = (tnext - t) / (spancount - 1);
+ }
+ }
+
+ do
+ {
+ btemp = *(pbase + (s >> 16) + (t >> 16) * cachewidth);
+ if (btemp != 255)
+ {
+ if (*pz <= (izi >> 16))
+ {
+ *pz = izi >> 16;
+ *pdest = btemp;
+ }
+ }
+
+ izi += izistep;
+ pdest++;
+ pz++;
+ s += sstep;
+ t += tstep;
+ } while (--spancount > 0);
+
+ s = snext;
+ t = tnext;
+
+ } while (count > 0);
+
+NextSpan:
+ pspan++;
+
+ } while (pspan->count != DS_SPAN_LIST_END);
+}
+
+#endif
+
+
+/*
+=====================
+D_SpriteScanLeftEdge
+=====================
+*/
+void D_SpriteScanLeftEdge (void)
+{
+ int i, v, itop, ibottom, lmaxindex;
+ emitpoint_t *pvert, *pnext;
+ sspan_t *pspan;
+ float du, dv, vtop, vbottom, slope;
+ fixed16_t u, u_step;
+
+ pspan = sprite_spans;
+ i = minindex;
+ if (i == 0)
+ i = r_spritedesc.nump;
+
+ lmaxindex = maxindex;
+ if (lmaxindex == 0)
+ lmaxindex = r_spritedesc.nump;
+
+ vtop = ceil (r_spritedesc.pverts[i].v);
+
+ do
+ {
+ pvert = &r_spritedesc.pverts[i];
+ pnext = pvert - 1;
+
+ vbottom = ceil (pnext->v);
+
+ if (vtop < vbottom)
+ {
+ du = pnext->u - pvert->u;
+ dv = pnext->v - pvert->v;
+ slope = du / dv;
+ u_step = (int)(slope * 0x10000);
+ // adjust u to ceil the integer portion
+ u = (int)((pvert->u + (slope * (vtop - pvert->v))) * 0x10000) +
+ (0x10000 - 1);
+ itop = (int)vtop;
+ ibottom = (int)vbottom;
+
+ for (v=itop ; v<ibottom ; v++)
+ {
+ pspan->u = u >> 16;
+ pspan->v = v;
+ u += u_step;
+ pspan++;
+ }
+ }
+
+ vtop = vbottom;
+
+ i--;
+ if (i == 0)
+ i = r_spritedesc.nump;
+
+ } while (i != lmaxindex);
+}
+
+
+/*
+=====================
+D_SpriteScanRightEdge
+=====================
+*/
+void D_SpriteScanRightEdge (void)
+{
+ int i, v, itop, ibottom;
+ emitpoint_t *pvert, *pnext;
+ sspan_t *pspan;
+ float du, dv, vtop, vbottom, slope, uvert, unext, vvert, vnext;
+ fixed16_t u, u_step;
+
+ pspan = sprite_spans;
+ i = minindex;
+
+ vvert = r_spritedesc.pverts[i].v;
+ if (vvert < r_refdef.fvrecty_adj)
+ vvert = r_refdef.fvrecty_adj;
+ if (vvert > r_refdef.fvrectbottom_adj)
+ vvert = r_refdef.fvrectbottom_adj;
+
+ vtop = ceil (vvert);
+
+ do
+ {
+ pvert = &r_spritedesc.pverts[i];
+ pnext = pvert + 1;
+
+ vnext = pnext->v;
+ if (vnext < r_refdef.fvrecty_adj)
+ vnext = r_refdef.fvrecty_adj;
+ if (vnext > r_refdef.fvrectbottom_adj)
+ vnext = r_refdef.fvrectbottom_adj;
+
+ vbottom = ceil (vnext);
+
+ if (vtop < vbottom)
+ {
+ uvert = pvert->u;
+ if (uvert < r_refdef.fvrectx_adj)
+ uvert = r_refdef.fvrectx_adj;
+ if (uvert > r_refdef.fvrectright_adj)
+ uvert = r_refdef.fvrectright_adj;
+
+ unext = pnext->u;
+ if (unext < r_refdef.fvrectx_adj)
+ unext = r_refdef.fvrectx_adj;
+ if (unext > r_refdef.fvrectright_adj)
+ unext = r_refdef.fvrectright_adj;
+
+ du = unext - uvert;
+ dv = vnext - vvert;
+ slope = du / dv;
+ u_step = (int)(slope * 0x10000);
+ // adjust u to ceil the integer portion
+ u = (int)((uvert + (slope * (vtop - vvert))) * 0x10000) +
+ (0x10000 - 1);
+ itop = (int)vtop;
+ ibottom = (int)vbottom;
+
+ for (v=itop ; v<ibottom ; v++)
+ {
+ pspan->count = (u >> 16) - pspan->u;
+ u += u_step;
+ pspan++;
+ }
+ }
+
+ vtop = vbottom;
+ vvert = vnext;
+
+ i++;
+ if (i == r_spritedesc.nump)
+ i = 0;
+
+ } while (i != maxindex);
+
+ pspan->count = DS_SPAN_LIST_END; // mark the end of the span list
+}
+
+
+/*
+=====================
+D_SpriteCalculateGradients
+=====================
+*/
+void D_SpriteCalculateGradients (void)
+{
+ vec3_t p_normal, p_saxis, p_taxis, p_temp1;
+ float distinv;
+
+ TransformVector (r_spritedesc.vpn, p_normal);
+ TransformVector (r_spritedesc.vright, p_saxis);
+ TransformVector (r_spritedesc.vup, p_taxis);
+ VectorInverse (p_taxis);
+
+ distinv = 1.0 / (-DotProduct (modelorg, r_spritedesc.vpn));
+
+ d_sdivzstepu = p_saxis[0] * xscaleinv;
+ d_tdivzstepu = p_taxis[0] * xscaleinv;
+
+ d_sdivzstepv = -p_saxis[1] * yscaleinv;
+ d_tdivzstepv = -p_taxis[1] * yscaleinv;
+
+ d_zistepu = p_normal[0] * xscaleinv * distinv;
+ d_zistepv = -p_normal[1] * yscaleinv * distinv;
+
+ d_sdivzorigin = p_saxis[2] - xcenter * d_sdivzstepu -
+ ycenter * d_sdivzstepv;
+ d_tdivzorigin = p_taxis[2] - xcenter * d_tdivzstepu -
+ ycenter * d_tdivzstepv;
+ d_ziorigin = p_normal[2] * distinv - xcenter * d_zistepu -
+ ycenter * d_zistepv;
+
+ TransformVector (modelorg, p_temp1);
+
+ sadjust = ((fixed16_t)(DotProduct (p_temp1, p_saxis) * 0x10000 + 0.5)) -
+ (-(cachewidth >> 1) << 16);
+ tadjust = ((fixed16_t)(DotProduct (p_temp1, p_taxis) * 0x10000 + 0.5)) -
+ (-(sprite_height >> 1) << 16);
+
+// -1 (-epsilon) so we never wander off the edge of the texture
+ bbextents = (cachewidth << 16) - 1;
+ bbextentt = (sprite_height << 16) - 1;
+}
+
+
+/*
+=====================
+D_DrawSprite
+=====================
+*/
+void D_DrawSprite (void)
+{
+ int i, nump;
+ float ymin, ymax;
+ emitpoint_t *pverts;
+ sspan_t spans[MAXHEIGHT+1];
+
+ sprite_spans = spans;
+
+// find the top and bottom vertices, and make sure there's at least one scan to
+// draw
+ ymin = 999999.9;
+ ymax = -999999.9;
+ pverts = r_spritedesc.pverts;
+
+ for (i=0 ; i<r_spritedesc.nump ; i++)
+ {
+ if (pverts->v < ymin)
+ {
+ ymin = pverts->v;
+ minindex = i;
+ }
+
+ if (pverts->v > ymax)
+ {
+ ymax = pverts->v;
+ maxindex = i;
+ }
+
+ pverts++;
+ }
+
+ ymin = ceil (ymin);
+ ymax = ceil (ymax);
+
+ if (ymin >= ymax)
+ return; // doesn't cross any scans at all
+
+ cachewidth = r_spritedesc.pspriteframe->width;
+ sprite_height = r_spritedesc.pspriteframe->height;
+ cacheblock = (byte *)&r_spritedesc.pspriteframe->pixels[0];
+
+// copy the first vertex to the last vertex, so we don't have to deal with
+// wrapping
+ nump = r_spritedesc.nump;
+ pverts = r_spritedesc.pverts;
+ pverts[nump] = pverts[0];
+
+ D_SpriteCalculateGradients ();
+ D_SpriteScanLeftEdge ();
+ D_SpriteScanRightEdge ();
+ D_SpriteDrawSpans (sprite_spans);
+}
+
diff --git a/apps/plugins/sdl/progs/quake/d_surf.c b/apps/plugins/sdl/progs/quake/d_surf.c
new file mode 100644
index 0000000000..b09c5f896e
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/d_surf.c
@@ -0,0 +1,335 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// d_surf.c: rasterization driver surface heap manager
+
+#include "quakedef.h"
+#include "d_local.h"
+#include "r_local.h"
+
+float surfscale;
+qboolean r_cache_thrash; // set if surface cache is thrashing
+
+int sc_size;
+surfcache_t *sc_rover, *sc_base;
+
+#define GUARDSIZE 4
+
+
+int D_SurfaceCacheForRes (int width, int height)
+{
+ int size, pix;
+
+ if (COM_CheckParm ("-surfcachesize"))
+ {
+ size = Q_atoi(com_argv[COM_CheckParm("-surfcachesize")+1]) * 1024;
+ return size;
+ }
+
+ size = SURFCACHE_SIZE_AT_320X200;
+
+ pix = width*height;
+ if (pix > 64000)
+ size += (pix-64000)*3;
+
+
+ return size;
+}
+
+void D_CheckCacheGuard (void)
+{
+ byte *s;
+ int i;
+
+ s = (byte *)sc_base + sc_size;
+ for (i=0 ; i<GUARDSIZE ; i++)
+ if (s[i] != (byte)i)
+ Sys_Error ("D_CheckCacheGuard: failed");
+}
+
+void D_ClearCacheGuard (void)
+{
+ byte *s;
+ int i;
+
+ s = (byte *)sc_base + sc_size;
+ for (i=0 ; i<GUARDSIZE ; i++)
+ s[i] = (byte)i;
+}
+
+
+/*
+================
+D_InitCaches
+
+================
+*/
+void D_InitCaches (void *buffer, int size)
+{
+
+ if (!msg_suppress_1)
+ Con_Printf ("%ik surface cache\n", size/1024);
+
+ sc_size = size - GUARDSIZE;
+ sc_base = (surfcache_t *)buffer;
+ sc_rover = sc_base;
+
+ sc_base->next = NULL;
+ sc_base->owner = NULL;
+ sc_base->size = sc_size;
+
+ D_ClearCacheGuard ();
+}
+
+
+/*
+==================
+D_FlushCaches
+==================
+*/
+void D_FlushCaches (void)
+{
+ surfcache_t *c;
+
+ if (!sc_base)
+ return;
+
+ for (c = sc_base ; c ; c = c->next)
+ {
+ if (c->owner)
+ *c->owner = NULL;
+ }
+
+ sc_rover = sc_base;
+ sc_base->next = NULL;
+ sc_base->owner = NULL;
+ sc_base->size = sc_size;
+}
+
+/*
+=================
+D_SCAlloc
+=================
+*/
+surfcache_t *D_SCAlloc (int width, int size)
+{
+ surfcache_t *new;
+ qboolean wrapped_this_time;
+
+ if ((width < 0) || (width > 256))
+ Sys_Error ("D_SCAlloc: bad cache width %d\n", width);
+
+ if ((size <= 0) || (size > 0x10000))
+ Sys_Error ("D_SCAlloc: bad cache size %d\n", size);
+
+ size = (int)&((surfcache_t *)0)->data[size];
+ size = (size + 3) & ~3;
+ if (size > sc_size)
+ Sys_Error ("D_SCAlloc: %i > cache size",size);
+
+// if there is not size bytes after the rover, reset to the start
+ wrapped_this_time = false;
+
+ if ( !sc_rover || (byte *)sc_rover - (byte *)sc_base > sc_size - size)
+ {
+ if (sc_rover)
+ {
+ wrapped_this_time = true;
+ }
+ sc_rover = sc_base;
+ }
+
+// colect and free surfcache_t blocks until the rover block is large enough
+ new = sc_rover;
+ if (sc_rover->owner)
+ *sc_rover->owner = NULL;
+
+ while (new->size < size)
+ {
+ // free another
+ sc_rover = sc_rover->next;
+ if (!sc_rover)
+ Sys_Error ("D_SCAlloc: hit the end of memory");
+ if (sc_rover->owner)
+ *sc_rover->owner = NULL;
+
+ new->size += sc_rover->size;
+ new->next = sc_rover->next;
+ }
+
+// create a fragment out of any leftovers
+ if (new->size - size > 256)
+ {
+ sc_rover = (surfcache_t *)( (byte *)new + size);
+ sc_rover->size = new->size - size;
+ sc_rover->next = new->next;
+ sc_rover->width = 0;
+ sc_rover->owner = NULL;
+ new->next = sc_rover;
+ new->size = size;
+ }
+ else
+ sc_rover = new->next;
+
+ new->width = width;
+// DEBUG
+ if (width > 0)
+ new->height = (size - sizeof(*new) + sizeof(new->data)) / width;
+
+ new->owner = NULL; // should be set properly after return
+
+ if (d_roverwrapped)
+ {
+ if (wrapped_this_time || (sc_rover >= d_initial_rover))
+ r_cache_thrash = true;
+ }
+ else if (wrapped_this_time)
+ {
+ d_roverwrapped = true;
+ }
+
+D_CheckCacheGuard (); // DEBUG
+ return new;
+}
+
+
+/*
+=================
+D_SCDump
+=================
+*/
+void D_SCDump (void)
+{
+ surfcache_t *test;
+
+ for (test = sc_base ; test ; test = test->next)
+ {
+ if (test == sc_rover)
+ Sys_Printf ("ROVER:\n");
+ printf ("%p : %i bytes %i width\n",test, test->size, test->width);
+ }
+}
+
+//=============================================================================
+
+// if the num is not a power of 2, assume it will not repeat
+
+int MaskForNum (int num)
+{
+ if (num==128)
+ return 127;
+ if (num==64)
+ return 63;
+ if (num==32)
+ return 31;
+ if (num==16)
+ return 15;
+ return 255;
+}
+
+int D_log2 (int num)
+{
+ int c;
+
+ c = 0;
+
+ while (num>>=1)
+ c++;
+ return c;
+}
+
+//=============================================================================
+
+/*
+================
+D_CacheSurface
+================
+*/
+surfcache_t *D_CacheSurface (msurface_t *surface, int miplevel)
+{
+ surfcache_t *cache;
+
+//
+// if the surface is animating or flashing, flush the cache
+//
+ r_drawsurf.texture = R_TextureAnimation (surface->texinfo->texture);
+ r_drawsurf.lightadj[0] = d_lightstylevalue[surface->styles[0]];
+ r_drawsurf.lightadj[1] = d_lightstylevalue[surface->styles[1]];
+ r_drawsurf.lightadj[2] = d_lightstylevalue[surface->styles[2]];
+ r_drawsurf.lightadj[3] = d_lightstylevalue[surface->styles[3]];
+
+//
+// see if the cache holds apropriate data
+//
+ cache = surface->cachespots[miplevel];
+
+ if (cache && !cache->dlight && surface->dlightframe != r_framecount
+ && cache->texture == r_drawsurf.texture
+ && cache->lightadj[0] == r_drawsurf.lightadj[0]
+ && cache->lightadj[1] == r_drawsurf.lightadj[1]
+ && cache->lightadj[2] == r_drawsurf.lightadj[2]
+ && cache->lightadj[3] == r_drawsurf.lightadj[3] )
+ return cache;
+
+//
+// determine shape of surface
+//
+ surfscale = 1.0 / (1<<miplevel);
+ r_drawsurf.surfmip = miplevel;
+ r_drawsurf.surfwidth = surface->extents[0] >> miplevel;
+ r_drawsurf.rowbytes = r_drawsurf.surfwidth;
+ r_drawsurf.surfheight = surface->extents[1] >> miplevel;
+
+//
+// allocate memory if needed
+//
+ if (!cache) // if a texture just animated, don't reallocate it
+ {
+ cache = D_SCAlloc (r_drawsurf.surfwidth,
+ r_drawsurf.surfwidth * r_drawsurf.surfheight);
+ surface->cachespots[miplevel] = cache;
+ cache->owner = &surface->cachespots[miplevel];
+ cache->mipscale = surfscale;
+ }
+
+ if (surface->dlightframe == r_framecount)
+ cache->dlight = 1;
+ else
+ cache->dlight = 0;
+
+ r_drawsurf.surfdat = (pixel_t *)cache->data;
+
+ cache->texture = r_drawsurf.texture;
+ cache->lightadj[0] = r_drawsurf.lightadj[0];
+ cache->lightadj[1] = r_drawsurf.lightadj[1];
+ cache->lightadj[2] = r_drawsurf.lightadj[2];
+ cache->lightadj[3] = r_drawsurf.lightadj[3];
+
+//
+// draw and light the surface texture
+//
+ r_drawsurf.surf = surface;
+
+ c_surf++;
+ R_DrawSurface ();
+
+ return surface->cachespots[miplevel];
+}
+
+
diff --git a/apps/plugins/sdl/progs/quake/d_vars.c b/apps/plugins/sdl/progs/quake/d_vars.c
new file mode 100644
index 0000000000..88cc841ab8
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/d_vars.c
@@ -0,0 +1,50 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// r_vars.c: global refresh variables
+
+#include "quakedef.h"
+
+#if !id386
+
+// all global and static refresh variables are collected in a contiguous block
+// to avoid cache conflicts.
+
+//-------------------------------------------------------
+// global refresh variables
+//-------------------------------------------------------
+
+// FIXME: make into one big structure, like cl or sv
+// FIXME: do separately for refresh engine and driver
+
+float d_sdivzstepu, d_tdivzstepu, d_zistepu;
+float d_sdivzstepv, d_tdivzstepv, d_zistepv;
+float d_sdivzorigin, d_tdivzorigin, d_ziorigin;
+
+fixed16_t sadjust, tadjust, bbextents, bbextentt;
+
+pixel_t *cacheblock;
+int cachewidth;
+pixel_t *d_viewbuffer;
+short *d_pzbuffer;
+unsigned int d_zrowbytes;
+unsigned int d_zwidth;
+
+#endif // !id386
+
diff --git a/apps/plugins/sdl/progs/quake/d_zpoint.c b/apps/plugins/sdl/progs/quake/d_zpoint.c
new file mode 100644
index 0000000000..909f25013f
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/d_zpoint.c
@@ -0,0 +1,47 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// d_zpoint.c: software driver module for drawing z-buffered points
+
+#include "quakedef.h"
+#include "d_local.h"
+
+
+/*
+=====================
+D_DrawZPoint
+=====================
+*/
+void D_DrawZPoint (void)
+{
+ byte *pdest;
+ short *pz;
+ int izi;
+
+ pz = d_pzbuffer + (d_zwidth * r_zpointdesc.v) + r_zpointdesc.u;
+ pdest = d_viewbuffer + d_scantable[r_zpointdesc.v] + r_zpointdesc.u;
+ izi = (int)(r_zpointdesc.zi * 0x8000);
+
+ if (*pz <= izi)
+ {
+ *pz = izi;
+ *pdest = r_zpointdesc.color;
+ }
+}
+
diff --git a/apps/plugins/sdl/progs/quake/dosasm.S b/apps/plugins/sdl/progs/quake/dosasm.S
new file mode 100644
index 0000000000..2633be9617
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/dosasm.S
@@ -0,0 +1,77 @@
+#include "asm_i386.h"
+
+.data
+fpenv: .long 0, 0, 0, 0, 0, 0, 0, 0
+
+.text
+.globl C(StartMSRInterval)
+C(StartMSRInterval):
+ movl $0x11,%ecx // read the CESR
+ .byte 0x0F
+ .byte 0x32 // RDMSR
+
+ andl $0xFE3FFE3F,%eax // stop both counters
+ .byte 0x0F
+ .byte 0x30 // WRMSR
+
+ movl 4(%esp),%eax // point counter 0 to desired event, with counters
+ andl $0x3F,%eax // still stopped
+ movl $0x11,%ecx
+ .byte 0x0F
+ .byte 0x30 // WRMSR
+
+ movl $0x12,%ecx // set counter 0 to the value 0
+ subl %eax,%eax
+ subl %edx,%edx
+ .byte 0x0F
+ .byte 0x30 // WRMSR
+
+ movl 4(%esp),%eax // restart counter 0 with selected event
+ andl $0x3F,%eax
+ subl %edx,%edx
+ orl $0xC0,%eax
+ movl $0x11,%ecx // control and event select
+ .byte 0x0F
+ .byte 0x30 // WRMSR
+
+ ret
+
+.globl C(EndMSRInterval)
+C(EndMSRInterval):
+ movl $0x12,%ecx // counter 0
+ .byte 0x0F
+ .byte 0x32 // RDMSR
+
+ ret // lower 32 bits of count in %eax
+
+#if 0
+ .data
+Lxxx: .long 0
+
+ .text
+
+.globl C(setstackcheck)
+C(setstackcheck):
+
+ movl %esp,%eax
+ subl $0x38000,%eax
+ movl $0x5A5A5A5A,(%eax)
+ movl %eax,Lxxx
+
+ ret
+
+
+.globl C(dostackcheck)
+C(dostackcheck):
+
+ movl Lxxx,%edx
+ movl $0,%eax
+
+ cmpl $0x5A5A5A5A,(%edx)
+ jz qqq
+ incl %eax
+qqq:
+
+ ret
+#endif
+
diff --git a/apps/plugins/sdl/progs/quake/dosisms.h b/apps/plugins/sdl/progs/quake/dosisms.h
new file mode 100644
index 0000000000..7f12268a2c
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/dosisms.h
@@ -0,0 +1,100 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+
+//
+// dosisms.h: I'd call it dos.h, but the name's taken
+//
+
+#ifndef _DOSISMS_H_
+#define _DOSISMS_H_
+
+int dos_lockmem(void *addr, int size);
+int dos_unlockmem(void *addr, int size);
+
+typedef union {
+ struct {
+ unsigned long edi;
+ unsigned long esi;
+ unsigned long ebp;
+ unsigned long res;
+ unsigned long ebx;
+ unsigned long edx;
+ unsigned long ecx;
+ unsigned long eax;
+ } d;
+ struct {
+ unsigned short di, di_hi;
+ unsigned short si, si_hi;
+ unsigned short bp, bp_hi;
+ unsigned short res, res_hi;
+ unsigned short bx, bx_hi;
+ unsigned short dx, dx_hi;
+ unsigned short cx, cx_hi;
+ unsigned short ax, ax_hi;
+ unsigned short flags;
+ unsigned short es;
+ unsigned short ds;
+ unsigned short fs;
+ unsigned short gs;
+ unsigned short ip;
+ unsigned short cs;
+ unsigned short sp;
+ unsigned short ss;
+ } x;
+ struct {
+ unsigned char edi[4];
+ unsigned char esi[4];
+ unsigned char ebp[4];
+ unsigned char res[4];
+ unsigned char bl, bh, ebx_b2, ebx_b3;
+ unsigned char dl, dh, edx_b2, edx_b3;
+ unsigned char cl, ch, ecx_b2, ecx_b3;
+ unsigned char al, ah, eax_b2, eax_b3;
+ } h;
+} regs_t;
+
+unsigned int ptr2real(void *ptr);
+void *real2ptr(unsigned int real);
+void *far2ptr(unsigned int farptr);
+unsigned int ptr2far(void *ptr);
+
+int dos_inportb(int port);
+int dos_inportw(int port);
+void dos_outportb(int port, int val);
+void dos_outportw(int port, int val);
+
+void dos_irqenable(void);
+void dos_irqdisable(void);
+void dos_registerintr(int intr, void (*handler)(void));
+void dos_restoreintr(int intr);
+
+int dos_int86(int vec);
+
+void *dos_getmemory(int size);
+void dos_freememory(void *ptr);
+
+void dos_usleep(int usecs);
+
+int dos_getheapsize(void);
+
+extern regs_t regs;
+
+#endif // _DOSISMS_H_
+
diff --git a/apps/plugins/sdl/progs/quake/draw.c b/apps/plugins/sdl/progs/quake/draw.c
new file mode 100644
index 0000000000..2a2f65bf4c
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/draw.c
@@ -0,0 +1,890 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+
+// draw.c -- this is the only file outside the refresh that touches the
+// vid buffer
+
+#include "quakedef.h"
+
+typedef struct {
+ vrect_t rect;
+ int width;
+ int height;
+ byte *ptexbytes;
+ int rowbytes;
+} rectdesc_t;
+
+static rectdesc_t r_rectdesc;
+
+byte *draw_chars; // 8*8 graphic characters
+qpic_t *draw_disc;
+qpic_t *draw_backtile;
+
+//=============================================================================
+/* Support Routines */
+
+typedef struct cachepic_s
+{
+ char name[MAX_QPATH];
+ cache_user_t cache;
+} cachepic_t;
+
+#define MAX_CACHED_PICS 128
+cachepic_t menu_cachepics[MAX_CACHED_PICS];
+int menu_numcachepics;
+
+
+qpic_t *Draw_PicFromWad (char *name)
+{
+ return W_GetLumpName (name);
+}
+
+/*
+================
+Draw_CachePic
+================
+*/
+qpic_t *Draw_CachePic (char *path)
+{
+ cachepic_t *pic;
+ int i;
+ qpic_t *dat;
+
+ for (pic=menu_cachepics, i=0 ; i<menu_numcachepics ; pic++, i++)
+ if (!strcmp (path, pic->name))
+ break;
+
+ if (i == menu_numcachepics)
+ {
+ if (menu_numcachepics == MAX_CACHED_PICS)
+ Sys_Error ("menu_numcachepics == MAX_CACHED_PICS");
+ menu_numcachepics++;
+ strcpy (pic->name, path);
+ }
+
+ dat = Cache_Check (&pic->cache);
+
+ if (dat)
+ return dat;
+
+//
+// load the pic from disk
+//
+ COM_LoadCacheFile (path, &pic->cache);
+
+ dat = (qpic_t *)pic->cache.data;
+ if (!dat)
+ {
+ Sys_Error ("Draw_CachePic: failed to load %s", path);
+ }
+
+ SwapPic (dat);
+
+ return dat;
+}
+
+
+
+/*
+===============
+Draw_Init
+===============
+*/
+void Draw_Init (void)
+{
+ int i;
+
+ draw_chars = W_GetLumpName ("conchars");
+ draw_disc = W_GetLumpName ("disc");
+ draw_backtile = W_GetLumpName ("backtile");
+
+ r_rectdesc.width = draw_backtile->width;
+ r_rectdesc.height = draw_backtile->height;
+ r_rectdesc.ptexbytes = draw_backtile->data;
+ r_rectdesc.rowbytes = draw_backtile->width;
+}
+
+
+
+/*
+================
+Draw_Character
+
+Draws one 8*8 graphics character with 0 being transparent.
+It can be clipped to the top of the screen to allow the console to be
+smoothly scrolled off.
+================
+*/
+void Draw_Character (int x, int y, int num)
+{
+ byte *dest;
+ byte *source;
+ unsigned short *pusdest;
+ int drawline;
+ int row, col;
+
+ num &= 255;
+
+ if (y <= -8)
+ return; // totally off screen
+
+#ifdef PARANOID
+ if (y > vid.height - 8 || x < 0 || x > vid.width - 8)
+ Sys_Error ("Con_DrawCharacter: (%i, %i)", x, y);
+ if (num < 0 || num > 255)
+ Sys_Error ("Con_DrawCharacter: char %i", num);
+#endif
+
+ row = num>>4;
+ col = num&15;
+ source = draw_chars + (row<<10) + (col<<3);
+
+ if (y < 0)
+ { // clipped
+ drawline = 8 + y;
+ source -= 128*y;
+ y = 0;
+ }
+ else
+ drawline = 8;
+
+
+ if (r_pixbytes == 1)
+ {
+ dest = vid.conbuffer + y*vid.conrowbytes + x;
+
+ while (drawline--)
+ {
+ if (source[0])
+ dest[0] = source[0];
+ if (source[1])
+ dest[1] = source[1];
+ if (source[2])
+ dest[2] = source[2];
+ if (source[3])
+ dest[3] = source[3];
+ if (source[4])
+ dest[4] = source[4];
+ if (source[5])
+ dest[5] = source[5];
+ if (source[6])
+ dest[6] = source[6];
+ if (source[7])
+ dest[7] = source[7];
+ source += 128;
+ dest += vid.conrowbytes;
+ }
+ }
+ else
+ {
+ // FIXME: pre-expand to native format?
+ pusdest = (unsigned short *)
+ ((byte *)vid.conbuffer + y*vid.conrowbytes + (x<<1));
+
+ while (drawline--)
+ {
+ if (source[0])
+ pusdest[0] = d_8to16table[source[0]];
+ if (source[1])
+ pusdest[1] = d_8to16table[source[1]];
+ if (source[2])
+ pusdest[2] = d_8to16table[source[2]];
+ if (source[3])
+ pusdest[3] = d_8to16table[source[3]];
+ if (source[4])
+ pusdest[4] = d_8to16table[source[4]];
+ if (source[5])
+ pusdest[5] = d_8to16table[source[5]];
+ if (source[6])
+ pusdest[6] = d_8to16table[source[6]];
+ if (source[7])
+ pusdest[7] = d_8to16table[source[7]];
+
+ source += 128;
+ pusdest += (vid.conrowbytes >> 1);
+ }
+ }
+}
+
+/*
+================
+Draw_String
+================
+*/
+void Draw_String (int x, int y, char *str)
+{
+ while (*str)
+ {
+ Draw_Character (x, y, *str);
+ str++;
+ x += 8;
+ }
+}
+
+/*
+================
+Draw_DebugChar
+
+Draws a single character directly to the upper right corner of the screen.
+This is for debugging lockups by drawing different chars in different parts
+of the code.
+================
+*/
+void Draw_DebugChar (char num)
+{
+ byte *dest;
+ byte *source;
+ int drawline;
+ extern byte *draw_chars;
+ int row, col;
+
+ if (!vid.direct)
+ return; // don't have direct FB access, so no debugchars...
+
+ drawline = 8;
+
+ row = num>>4;
+ col = num&15;
+ source = draw_chars + (row<<10) + (col<<3);
+
+ dest = vid.direct + 312;
+
+ while (drawline--)
+ {
+ dest[0] = source[0];
+ dest[1] = source[1];
+ dest[2] = source[2];
+ dest[3] = source[3];
+ dest[4] = source[4];
+ dest[5] = source[5];
+ dest[6] = source[6];
+ dest[7] = source[7];
+ source += 128;
+ dest += 320;
+ }
+}
+
+/*
+=============
+Draw_Pic
+=============
+*/
+void Draw_Pic (int x, int y, qpic_t *pic)
+{
+ byte *dest, *source;
+ unsigned short *pusdest;
+ int v, u;
+
+ if ((x < 0) ||
+ (x + pic->width > vid.width) ||
+ (y < 0) ||
+ (y + pic->height > vid.height))
+ {
+ Sys_Error ("Draw_Pic: bad coordinates");
+ }
+
+ source = pic->data;
+
+ if (r_pixbytes == 1)
+ {
+ dest = vid.buffer + y * vid.rowbytes + x;
+
+ for (v=0 ; v<pic->height ; v++)
+ {
+ Q_memcpy (dest, source, pic->width);
+ dest += vid.rowbytes;
+ source += pic->width;
+ }
+ }
+ else
+ {
+ // FIXME: pretranslate at load time?
+ pusdest = (unsigned short *)vid.buffer + y * (vid.rowbytes >> 1) + x;
+
+ for (v=0 ; v<pic->height ; v++)
+ {
+ for (u=0 ; u<pic->width ; u++)
+ {
+ pusdest[u] = d_8to16table[source[u]];
+ }
+
+ pusdest += vid.rowbytes >> 1;
+ source += pic->width;
+ }
+ }
+}
+
+
+/*
+=============
+Draw_TransPic
+=============
+*/
+void Draw_TransPic (int x, int y, qpic_t *pic)
+{
+ byte *dest, *source, tbyte;
+ unsigned short *pusdest;
+ int v, u;
+
+ if (x < 0 || (unsigned)(x + pic->width) > vid.width || y < 0 ||
+ (unsigned)(y + pic->height) > vid.height)
+ {
+ Sys_Error ("Draw_TransPic: bad coordinates");
+ }
+
+ source = pic->data;
+
+ if (r_pixbytes == 1)
+ {
+ dest = vid.buffer + y * vid.rowbytes + x;
+
+ if (pic->width & 7)
+ { // general
+ for (v=0 ; v<pic->height ; v++)
+ {
+ for (u=0 ; u<pic->width ; u++)
+ if ( (tbyte=source[u]) != TRANSPARENT_COLOR)
+ dest[u] = tbyte;
+
+ dest += vid.rowbytes;
+ source += pic->width;
+ }
+ }
+ else
+ { // unwound
+ for (v=0 ; v<pic->height ; v++)
+ {
+ for (u=0 ; u<pic->width ; u+=8)
+ {
+ if ( (tbyte=source[u]) != TRANSPARENT_COLOR)
+ dest[u] = tbyte;
+ if ( (tbyte=source[u+1]) != TRANSPARENT_COLOR)
+ dest[u+1] = tbyte;
+ if ( (tbyte=source[u+2]) != TRANSPARENT_COLOR)
+ dest[u+2] = tbyte;
+ if ( (tbyte=source[u+3]) != TRANSPARENT_COLOR)
+ dest[u+3] = tbyte;
+ if ( (tbyte=source[u+4]) != TRANSPARENT_COLOR)
+ dest[u+4] = tbyte;
+ if ( (tbyte=source[u+5]) != TRANSPARENT_COLOR)
+ dest[u+5] = tbyte;
+ if ( (tbyte=source[u+6]) != TRANSPARENT_COLOR)
+ dest[u+6] = tbyte;
+ if ( (tbyte=source[u+7]) != TRANSPARENT_COLOR)
+ dest[u+7] = tbyte;
+ }
+ dest += vid.rowbytes;
+ source += pic->width;
+ }
+ }
+ }
+ else
+ {
+ // FIXME: pretranslate at load time?
+ pusdest = (unsigned short *)vid.buffer + y * (vid.rowbytes >> 1) + x;
+
+ for (v=0 ; v<pic->height ; v++)
+ {
+ for (u=0 ; u<pic->width ; u++)
+ {
+ tbyte = source[u];
+
+ if (tbyte != TRANSPARENT_COLOR)
+ {
+ pusdest[u] = d_8to16table[tbyte];
+ }
+ }
+
+ pusdest += vid.rowbytes >> 1;
+ source += pic->width;
+ }
+ }
+}
+
+
+/*
+=============
+Draw_TransPicTranslate
+=============
+*/
+void Draw_TransPicTranslate (int x, int y, qpic_t *pic, byte *translation)
+{
+ byte *dest, *source, tbyte;
+ unsigned short *pusdest;
+ int v, u;
+
+ if (x < 0 || (unsigned)(x + pic->width) > vid.width || y < 0 ||
+ (unsigned)(y + pic->height) > vid.height)
+ {
+ Sys_Error ("Draw_TransPic: bad coordinates");
+ }
+
+ source = pic->data;
+
+ if (r_pixbytes == 1)
+ {
+ dest = vid.buffer + y * vid.rowbytes + x;
+
+ if (pic->width & 7)
+ { // general
+ for (v=0 ; v<pic->height ; v++)
+ {
+ for (u=0 ; u<pic->width ; u++)
+ if ( (tbyte=source[u]) != TRANSPARENT_COLOR)
+ dest[u] = translation[tbyte];
+
+ dest += vid.rowbytes;
+ source += pic->width;
+ }
+ }
+ else
+ { // unwound
+ for (v=0 ; v<pic->height ; v++)
+ {
+ for (u=0 ; u<pic->width ; u+=8)
+ {
+ if ( (tbyte=source[u]) != TRANSPARENT_COLOR)
+ dest[u] = translation[tbyte];
+ if ( (tbyte=source[u+1]) != TRANSPARENT_COLOR)
+ dest[u+1] = translation[tbyte];
+ if ( (tbyte=source[u+2]) != TRANSPARENT_COLOR)
+ dest[u+2] = translation[tbyte];
+ if ( (tbyte=source[u+3]) != TRANSPARENT_COLOR)
+ dest[u+3] = translation[tbyte];
+ if ( (tbyte=source[u+4]) != TRANSPARENT_COLOR)
+ dest[u+4] = translation[tbyte];
+ if ( (tbyte=source[u+5]) != TRANSPARENT_COLOR)
+ dest[u+5] = translation[tbyte];
+ if ( (tbyte=source[u+6]) != TRANSPARENT_COLOR)
+ dest[u+6] = translation[tbyte];
+ if ( (tbyte=source[u+7]) != TRANSPARENT_COLOR)
+ dest[u+7] = translation[tbyte];
+ }
+ dest += vid.rowbytes;
+ source += pic->width;
+ }
+ }
+ }
+ else
+ {
+ // FIXME: pretranslate at load time?
+ pusdest = (unsigned short *)vid.buffer + y * (vid.rowbytes >> 1) + x;
+
+ for (v=0 ; v<pic->height ; v++)
+ {
+ for (u=0 ; u<pic->width ; u++)
+ {
+ tbyte = source[u];
+
+ if (tbyte != TRANSPARENT_COLOR)
+ {
+ pusdest[u] = d_8to16table[tbyte];
+ }
+ }
+
+ pusdest += vid.rowbytes >> 1;
+ source += pic->width;
+ }
+ }
+}
+
+
+void Draw_CharToConback (int num, byte *dest)
+{
+ int row, col;
+ byte *source;
+ int drawline;
+ int x;
+
+ row = num>>4;
+ col = num&15;
+ source = draw_chars + (row<<10) + (col<<3);
+
+ drawline = 8;
+
+ while (drawline--)
+ {
+ for (x=0 ; x<8 ; x++)
+ if (source[x])
+ dest[x] = 0x60 + source[x];
+ source += 128;
+ dest += 320;
+ }
+
+}
+
+/*
+================
+Draw_ConsoleBackground
+
+================
+*/
+void Draw_ConsoleBackground (int lines)
+{
+ int x, y, v;
+ byte *src, *dest;
+ unsigned short *pusdest;
+ int f, fstep;
+ qpic_t *conback;
+ char ver[100];
+
+ conback = Draw_CachePic ("gfx/conback.lmp");
+
+ dest = conback->data + 320 - 43 + 320*186;
+ sprintf (ver, "%.2f", (float)VERSION);
+
+ for (x=0 ; x<strlen(ver) ; x++)
+ Draw_CharToConback (ver[x], dest+(x<<3));
+
+// draw the pic
+ if (r_pixbytes == 1)
+ {
+ dest = vid.conbuffer;
+
+ for (y=0 ; y<lines ; y++, dest += vid.conrowbytes)
+ {
+ v = (vid.conheight - lines + y)*200/vid.conheight;
+ src = conback->data + v*320;
+ if (vid.conwidth == 320)
+ memcpy (dest, src, vid.conwidth);
+ else
+ {
+ f = 0;
+ fstep = 320*0x10000/vid.conwidth;
+ for (x=0 ; x<vid.conwidth ; x+=4)
+ {
+ dest[x] = src[f>>16];
+ f += fstep;
+ dest[x+1] = src[f>>16];
+ f += fstep;
+ dest[x+2] = src[f>>16];
+ f += fstep;
+ dest[x+3] = src[f>>16];
+ f += fstep;
+ }
+ }
+ }
+ }
+ else
+ {
+ pusdest = (unsigned short *)vid.conbuffer;
+
+ for (y=0 ; y<lines ; y++, pusdest += (vid.conrowbytes >> 1))
+ {
+ // FIXME: pre-expand to native format?
+ // FIXME: does the endian switching go away in production?
+ v = (vid.conheight - lines + y)*200/vid.conheight;
+ src = conback->data + v*320;
+ f = 0;
+ fstep = 320*0x10000/vid.conwidth;
+ for (x=0 ; x<vid.conwidth ; x+=4)
+ {
+ pusdest[x] = d_8to16table[src[f>>16]];
+ f += fstep;
+ pusdest[x+1] = d_8to16table[src[f>>16]];
+ f += fstep;
+ pusdest[x+2] = d_8to16table[src[f>>16]];
+ f += fstep;
+ pusdest[x+3] = d_8to16table[src[f>>16]];
+ f += fstep;
+ }
+ }
+ }
+}
+
+
+/*
+==============
+R_DrawRect8
+==============
+*/
+void R_DrawRect8 (vrect_t *prect, int rowbytes, byte *psrc,
+ int transparent)
+{
+ byte t;
+ int i, j, srcdelta, destdelta;
+ byte *pdest;
+
+ pdest = vid.buffer + (prect->y * vid.rowbytes) + prect->x;
+
+ srcdelta = rowbytes - prect->width;
+ destdelta = vid.rowbytes - prect->width;
+
+ if (transparent)
+ {
+ for (i=0 ; i<prect->height ; i++)
+ {
+ for (j=0 ; j<prect->width ; j++)
+ {
+ t = *psrc;
+ if (t != TRANSPARENT_COLOR)
+ {
+ *pdest = t;
+ }
+
+ psrc++;
+ pdest++;
+ }
+
+ psrc += srcdelta;
+ pdest += destdelta;
+ }
+ }
+ else
+ {
+ for (i=0 ; i<prect->height ; i++)
+ {
+ memcpy (pdest, psrc, prect->width);
+ psrc += rowbytes;
+ pdest += vid.rowbytes;
+ }
+ }
+}
+
+
+/*
+==============
+R_DrawRect16
+==============
+*/
+void R_DrawRect16 (vrect_t *prect, int rowbytes, byte *psrc,
+ int transparent)
+{
+ byte t;
+ int i, j, srcdelta, destdelta;
+ unsigned short *pdest;
+
+// FIXME: would it be better to pre-expand native-format versions?
+
+ pdest = (unsigned short *)vid.buffer +
+ (prect->y * (vid.rowbytes >> 1)) + prect->x;
+
+ srcdelta = rowbytes - prect->width;
+ destdelta = (vid.rowbytes >> 1) - prect->width;
+
+ if (transparent)
+ {
+ for (i=0 ; i<prect->height ; i++)
+ {
+ for (j=0 ; j<prect->width ; j++)
+ {
+ t = *psrc;
+ if (t != TRANSPARENT_COLOR)
+ {
+ *pdest = d_8to16table[t];
+ }
+
+ psrc++;
+ pdest++;
+ }
+
+ psrc += srcdelta;
+ pdest += destdelta;
+ }
+ }
+ else
+ {
+ for (i=0 ; i<prect->height ; i++)
+ {
+ for (j=0 ; j<prect->width ; j++)
+ {
+ *pdest = d_8to16table[*psrc];
+ psrc++;
+ pdest++;
+ }
+
+ psrc += srcdelta;
+ pdest += destdelta;
+ }
+ }
+}
+
+
+/*
+=============
+Draw_TileClear
+
+This repeats a 64*64 tile graphic to fill the screen around a sized down
+refresh window.
+=============
+*/
+void Draw_TileClear (int x, int y, int w, int h)
+{
+ int width, height, tileoffsetx, tileoffsety;
+ byte *psrc;
+ vrect_t vr;
+
+ r_rectdesc.rect.x = x;
+ r_rectdesc.rect.y = y;
+ r_rectdesc.rect.width = w;
+ r_rectdesc.rect.height = h;
+
+ vr.y = r_rectdesc.rect.y;
+ height = r_rectdesc.rect.height;
+
+ tileoffsety = vr.y % r_rectdesc.height;
+
+ while (height > 0)
+ {
+ vr.x = r_rectdesc.rect.x;
+ width = r_rectdesc.rect.width;
+
+ if (tileoffsety != 0)
+ vr.height = r_rectdesc.height - tileoffsety;
+ else
+ vr.height = r_rectdesc.height;
+
+ if (vr.height > height)
+ vr.height = height;
+
+ tileoffsetx = vr.x % r_rectdesc.width;
+
+ while (width > 0)
+ {
+ if (tileoffsetx != 0)
+ vr.width = r_rectdesc.width - tileoffsetx;
+ else
+ vr.width = r_rectdesc.width;
+
+ if (vr.width > width)
+ vr.width = width;
+
+ psrc = r_rectdesc.ptexbytes +
+ (tileoffsety * r_rectdesc.rowbytes) + tileoffsetx;
+
+ if (r_pixbytes == 1)
+ {
+ R_DrawRect8 (&vr, r_rectdesc.rowbytes, psrc, 0);
+ }
+ else
+ {
+ R_DrawRect16 (&vr, r_rectdesc.rowbytes, psrc, 0);
+ }
+
+ vr.x += vr.width;
+ width -= vr.width;
+ tileoffsetx = 0; // only the left tile can be left-clipped
+ }
+
+ vr.y += vr.height;
+ height -= vr.height;
+ tileoffsety = 0; // only the top tile can be top-clipped
+ }
+}
+
+
+/*
+=============
+Draw_Fill
+
+Fills a box of pixels with a single color
+=============
+*/
+void Draw_Fill (int x, int y, int w, int h, int c)
+{
+ byte *dest;
+ unsigned short *pusdest;
+ unsigned uc;
+ int u, v;
+
+ if (r_pixbytes == 1)
+ {
+ dest = vid.buffer + y*vid.rowbytes + x;
+ for (v=0 ; v<h ; v++, dest += vid.rowbytes)
+ for (u=0 ; u<w ; u++)
+ dest[u] = c;
+ }
+ else
+ {
+ uc = d_8to16table[c];
+
+ pusdest = (unsigned short *)vid.buffer + y * (vid.rowbytes >> 1) + x;
+ for (v=0 ; v<h ; v++, pusdest += (vid.rowbytes >> 1))
+ for (u=0 ; u<w ; u++)
+ pusdest[u] = uc;
+ }
+}
+//=============================================================================
+
+/*
+================
+Draw_FadeScreen
+
+================
+*/
+void Draw_FadeScreen (void)
+{
+ int x,y;
+ byte *pbuf;
+
+ VID_UnlockBuffer ();
+ S_ExtraUpdate ();
+ VID_LockBuffer ();
+
+ for (y=0 ; y<vid.height ; y++)
+ {
+ int t;
+
+ pbuf = (byte *)(vid.buffer + vid.rowbytes*y);
+ t = (y & 1) << 1;
+
+ for (x=0 ; x<vid.width ; x++)
+ {
+ if ((x & 3) != t)
+ pbuf[x] = 0;
+ }
+ }
+
+ VID_UnlockBuffer ();
+ S_ExtraUpdate ();
+ VID_LockBuffer ();
+}
+
+//=============================================================================
+
+/*
+================
+Draw_BeginDisc
+
+Draws the little blue disc in the corner of the screen.
+Call before beginning any disc IO.
+================
+*/
+void Draw_BeginDisc (void)
+{
+
+ D_BeginDirectRect (vid.width - 24, 0, draw_disc->data, 24, 24);
+}
+
+
+/*
+================
+Draw_EndDisc
+
+Erases the disc icon.
+Call after completing any disc IO
+================
+*/
+void Draw_EndDisc (void)
+{
+
+ D_EndDirectRect (vid.width - 24, 0, 24, 24);
+}
+
diff --git a/apps/plugins/sdl/progs/quake/draw.h b/apps/plugins/sdl/progs/quake/draw.h
new file mode 100644
index 0000000000..5055b659c8
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/draw.h
@@ -0,0 +1,40 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+
+// draw.h -- these are the only functions outside the refresh allowed
+// to touch the vid buffer
+
+extern qpic_t *draw_disc; // also used on sbar
+
+void Draw_Init (void);
+void Draw_Character (int x, int y, int num);
+void Draw_DebugChar (char num);
+void Draw_Pic (int x, int y, qpic_t *pic);
+void Draw_TransPic (int x, int y, qpic_t *pic);
+void Draw_TransPicTranslate (int x, int y, qpic_t *pic, byte *translation);
+void Draw_ConsoleBackground (int lines);
+void Draw_BeginDisc (void);
+void Draw_EndDisc (void);
+void Draw_TileClear (int x, int y, int w, int h);
+void Draw_Fill (int x, int y, int w, int h, int c);
+void Draw_FadeScreen (void);
+void Draw_String (int x, int y, char *str);
+qpic_t *Draw_PicFromWad (char *name);
+qpic_t *Draw_CachePic (char *path);
diff --git a/apps/plugins/sdl/progs/quake/gl_vidlinux.c b/apps/plugins/sdl/progs/quake/gl_vidlinux.c
new file mode 100644
index 0000000000..c29f0423a3
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/gl_vidlinux.c
@@ -0,0 +1,866 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+#include <termios.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/vt.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <signal.h>
+
+#include <asm/io.h>
+#include <dlfcn.h>
+
+/*#include "vga.h" */
+#include "vgakeyboard.h"
+#include "vgamouse.h"
+
+#include "quakedef.h"
+#include "GL/fxmesa.h"
+
+#define WARP_WIDTH 320
+#define WARP_HEIGHT 200
+
+static fxMesaContext fc = NULL;
+#define stringify(m) { #m, m }
+
+unsigned short d_8to16table[256];
+unsigned d_8to24table[256];
+unsigned char d_15to8table[65536];
+
+int num_shades=32;
+
+struct
+{
+ char *name;
+ int num;
+} mice[] =
+{
+ stringify(MOUSE_MICROSOFT),
+ stringify(MOUSE_MOUSESYSTEMS),
+ stringify(MOUSE_MMSERIES),
+ stringify(MOUSE_LOGITECH),
+ stringify(MOUSE_BUSMOUSE),
+ stringify(MOUSE_PS2),
+};
+
+static unsigned char scantokey[128];
+
+int num_mice = sizeof (mice) / sizeof(mice[0]);
+
+int d_con_indirect = 0;
+
+int svgalib_inited=0;
+int UseMouse = 1;
+int UseKeyboard = 1;
+
+int mouserate = MOUSE_DEFAULTSAMPLERATE;
+
+cvar_t vid_mode = {"vid_mode","5",false};
+cvar_t vid_redrawfull = {"vid_redrawfull","0",false};
+cvar_t vid_waitforrefresh = {"vid_waitforrefresh","0",true};
+
+char *framebuffer_ptr;
+
+cvar_t mouse_button_commands[3] =
+{
+ {"mouse1","+attack"},
+ {"mouse2","+strafe"},
+ {"mouse3","+forward"},
+};
+
+int mouse_buttons;
+int mouse_buttonstate;
+int mouse_oldbuttonstate;
+float mouse_x, mouse_y;
+float old_mouse_x, old_mouse_y;
+int mx, my;
+
+cvar_t m_filter = {"m_filter","1"};
+
+int scr_width, scr_height;
+
+/*-----------------------------------------------------------------------*/
+
+//int texture_mode = GL_NEAREST;
+//int texture_mode = GL_NEAREST_MIPMAP_NEAREST;
+//int texture_mode = GL_NEAREST_MIPMAP_LINEAR;
+int texture_mode = GL_LINEAR;
+//int texture_mode = GL_LINEAR_MIPMAP_NEAREST;
+//int texture_mode = GL_LINEAR_MIPMAP_LINEAR;
+
+int texture_extension_number = 1;
+
+float gldepthmin, gldepthmax;
+
+cvar_t gl_ztrick = {"gl_ztrick","1"};
+
+const char *gl_vendor;
+const char *gl_renderer;
+const char *gl_version;
+const char *gl_extensions;
+
+void (*qgl3DfxSetPaletteEXT) (GLuint *);
+void (*qglColorTableEXT) (int, int, int, int, int, const void *);
+
+static float vid_gamma = 1.0;
+
+qboolean is8bit = false;
+qboolean isPermedia = false;
+qboolean gl_mtexable = false;
+
+/*-----------------------------------------------------------------------*/
+void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
+{
+}
+
+void D_EndDirectRect (int x, int y, int width, int height)
+{
+}
+
+int matchmouse(int mouse, char *name)
+{
+ int i;
+ for (i=0 ; i<num_mice ; i++)
+ if (!strcmp(mice[i].name, name))
+ return i;
+ return mouse;
+}
+
+#if 0
+
+void vtswitch(int newconsole)
+{
+
+ int fd;
+ struct vt_stat x;
+
+// switch consoles and wait until reactivated
+ fd = open("/dev/console", O_RDONLY);
+ ioctl(fd, VT_GETSTATE, &x);
+ ioctl(fd, VT_ACTIVATE, newconsole);
+ ioctl(fd, VT_WAITACTIVE, x.v_active);
+ close(fd);
+
+}
+
+#endif
+
+void keyhandler(int scancode, int state)
+{
+
+ int sc;
+
+ sc = scancode & 0x7f;
+
+ Key_Event(scantokey[sc], state == KEY_EVENTPRESS);
+
+}
+
+void VID_Shutdown(void)
+{
+ if (!fc)
+ return;
+
+ fxMesaDestroyContext(fc);
+
+ if (UseKeyboard)
+ keyboard_close();
+}
+
+void signal_handler(int sig)
+{
+ printf("Received signal %d, exiting...\n", sig);
+ Sys_Quit();
+ exit(0);
+}
+
+void InitSig(void)
+{
+ signal(SIGHUP, signal_handler);
+ signal(SIGINT, signal_handler);
+ signal(SIGQUIT, signal_handler);
+ signal(SIGILL, signal_handler);
+ signal(SIGTRAP, signal_handler);
+ signal(SIGIOT, signal_handler);
+ signal(SIGBUS, signal_handler);
+ signal(SIGFPE, signal_handler);
+ signal(SIGSEGV, signal_handler);
+ signal(SIGTERM, signal_handler);
+}
+
+void VID_ShiftPalette(unsigned char *p)
+{
+// VID_SetPalette(p);
+}
+
+void VID_SetPalette (unsigned char *palette)
+{
+ byte *pal;
+ unsigned r,g,b;
+ unsigned v;
+ int r1,g1,b1;
+ int j,k,l,m;
+ unsigned short i;
+ unsigned *table;
+ FILE *f;
+ char s[255];
+ int dist, bestdist;
+ static qboolean palflag = false;
+
+//
+// 8 8 8 encoding
+//
+ pal = palette;
+ table = d_8to24table;
+ for (i=0 ; i<256 ; i++)
+ {
+ r = pal[0];
+ g = pal[1];
+ b = pal[2];
+ pal += 3;
+
+ v = (255<<24) + (r<<0) + (g<<8) + (b<<16);
+ *table++ = v;
+ }
+ d_8to24table[255] &= 0xffffff; // 255 is transparent
+
+ // JACK: 3D distance calcs - k is last closest, l is the distance.
+ for (i=0; i < (1<<15); i++) {
+ /* Maps
+ 000000000000000
+ 000000000011111 = Red = 0x1F
+ 000001111100000 = Blue = 0x03E0
+ 111110000000000 = Grn = 0x7C00
+ */
+ r = ((i & 0x1F) << 3)+4;
+ g = ((i & 0x03E0) >> 2)+4;
+ b = ((i & 0x7C00) >> 7)+4;
+ pal = (unsigned char *)d_8to24table;
+ for (v=0,k=0,bestdist=10000*10000; v<256; v++,pal+=4) {
+ r1 = (int)r - (int)pal[0];
+ g1 = (int)g - (int)pal[1];
+ b1 = (int)b - (int)pal[2];
+ dist = (r1*r1)+(g1*g1)+(b1*b1);
+ if (dist < bestdist) {
+ k=v;
+ bestdist = dist;
+ }
+ }
+ d_15to8table[i]=k;
+ }
+}
+
+void CheckMultiTextureExtensions(void)
+{
+ void *prjobj;
+
+ if (strstr(gl_extensions, "GL_SGIS_multitexture ") && !COM_CheckParm("-nomtex")) {
+ Con_Printf("Found GL_SGIS_multitexture...\n");
+
+ if ((prjobj = dlopen(NULL, RTLD_LAZY)) == NULL) {
+ Con_Printf("Unable to open symbol list for main program.\n");
+ return;
+ }
+
+ qglMTexCoord2fSGIS = (void *) dlsym(prjobj, "glMTexCoord2fSGIS");
+ qglSelectTextureSGIS = (void *) dlsym(prjobj, "glSelectTextureSGIS");
+
+ if (qglMTexCoord2fSGIS && qglSelectTextureSGIS) {
+ Con_Printf("Multitexture extensions found.\n");
+ gl_mtexable = true;
+ } else
+ Con_Printf("Symbol not found, disabled.\n");
+
+ dlclose(prjobj);
+ }
+}
+
+/*
+===============
+GL_Init
+===============
+*/
+void GL_Init (void)
+{
+ gl_vendor = glGetString (GL_VENDOR);
+ Con_Printf ("GL_VENDOR: %s\n", gl_vendor);
+ gl_renderer = glGetString (GL_RENDERER);
+ Con_Printf ("GL_RENDERER: %s\n", gl_renderer);
+
+ gl_version = glGetString (GL_VERSION);
+ Con_Printf ("GL_VERSION: %s\n", gl_version);
+ gl_extensions = glGetString (GL_EXTENSIONS);
+ Con_Printf ("GL_EXTENSIONS: %s\n", gl_extensions);
+
+// Con_Printf ("%s %s\n", gl_renderer, gl_version);
+
+ CheckMultiTextureExtensions ();
+
+ glClearColor (1,0,0,0);
+ glCullFace(GL_FRONT);
+ glEnable(GL_TEXTURE_2D);
+
+ glEnable(GL_ALPHA_TEST);
+ glAlphaFunc(GL_GREATER, 0.666);
+
+ glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
+ glShadeModel (GL_FLAT);
+
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+
+ glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+// glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+}
+
+/*
+=================
+GL_BeginRendering
+
+=================
+*/
+void GL_BeginRendering (int *x, int *y, int *width, int *height)
+{
+ extern cvar_t gl_clear;
+
+ *x = *y = 0;
+ *width = scr_width;
+ *height = scr_height;
+
+// if (!wglMakeCurrent( maindc, baseRC ))
+// Sys_Error ("wglMakeCurrent failed");
+
+// glViewport (*x, *y, *width, *height);
+}
+
+
+void GL_EndRendering (void)
+{
+ glFlush();
+ fxMesaSwapBuffers();
+}
+
+void Init_KBD(void)
+{
+ int i;
+
+ if (COM_CheckParm("-nokbd")) UseKeyboard = 0;
+
+ if (UseKeyboard)
+ {
+ for (i=0 ; i<128 ; i++)
+ scantokey[i] = ' ';
+
+ scantokey[42] = K_SHIFT;
+ scantokey[54] = K_SHIFT;
+ scantokey[72] = K_UPARROW;
+ scantokey[103] = K_UPARROW;
+ scantokey[80] = K_DOWNARROW;
+ scantokey[108] = K_DOWNARROW;
+ scantokey[75] = K_LEFTARROW;
+ scantokey[105] = K_LEFTARROW;
+ scantokey[77] = K_RIGHTARROW;
+ scantokey[106] = K_RIGHTARROW;
+ scantokey[29] = K_CTRL;
+ scantokey[97] = K_CTRL;
+ scantokey[56] = K_ALT;
+ scantokey[100] = K_ALT;
+// scantokey[58] = JK_CAPS;
+// scantokey[69] = JK_NUM_LOCK;
+ scantokey[71] = K_HOME;
+ scantokey[73] = K_PGUP;
+ scantokey[79] = K_END;
+ scantokey[81] = K_PGDN;
+ scantokey[82] = K_INS;
+ scantokey[83] = K_DEL;
+ scantokey[1 ] = K_ESCAPE;
+ scantokey[28] = K_ENTER;
+ scantokey[15] = K_TAB;
+ scantokey[14] = K_BACKSPACE;
+ scantokey[119] = K_PAUSE;
+ scantokey[57] = ' ';
+
+ scantokey[102] = K_HOME;
+ scantokey[104] = K_PGUP;
+ scantokey[107] = K_END;
+ scantokey[109] = K_PGDN;
+ scantokey[110] = K_INS;
+ scantokey[111] = K_DEL;
+
+ scantokey[2] = '1';
+ scantokey[3] = '2';
+ scantokey[4] = '3';
+ scantokey[5] = '4';
+ scantokey[6] = '5';
+ scantokey[7] = '6';
+ scantokey[8] = '7';
+ scantokey[9] = '8';
+ scantokey[10] = '9';
+ scantokey[11] = '0';
+ scantokey[12] = '-';
+ scantokey[13] = '=';
+ scantokey[41] = '`';
+ scantokey[26] = '[';
+ scantokey[27] = ']';
+ scantokey[39] = ';';
+ scantokey[40] = '\'';
+ scantokey[51] = ',';
+ scantokey[52] = '.';
+ scantokey[53] = '/';
+ scantokey[43] = '\\';
+
+ scantokey[59] = K_F1;
+ scantokey[60] = K_F2;
+ scantokey[61] = K_F3;
+ scantokey[62] = K_F4;
+ scantokey[63] = K_F5;
+ scantokey[64] = K_F6;
+ scantokey[65] = K_F7;
+ scantokey[66] = K_F8;
+ scantokey[67] = K_F9;
+ scantokey[68] = K_F10;
+ scantokey[87] = K_F11;
+ scantokey[88] = K_F12;
+ scantokey[30] = 'a';
+ scantokey[48] = 'b';
+ scantokey[46] = 'c';
+ scantokey[32] = 'd';
+ scantokey[18] = 'e';
+ scantokey[33] = 'f';
+ scantokey[34] = 'g';
+ scantokey[35] = 'h';
+ scantokey[23] = 'i';
+ scantokey[36] = 'j';
+ scantokey[37] = 'k';
+ scantokey[38] = 'l';
+ scantokey[50] = 'm';
+ scantokey[49] = 'n';
+ scantokey[24] = 'o';
+ scantokey[25] = 'p';
+ scantokey[16] = 'q';
+ scantokey[19] = 'r';
+ scantokey[31] = 's';
+ scantokey[20] = 't';
+ scantokey[22] = 'u';
+ scantokey[47] = 'v';
+ scantokey[17] = 'w';
+ scantokey[45] = 'x';
+ scantokey[21] = 'y';
+ scantokey[44] = 'z';
+
+ scantokey[78] = '+';
+ scantokey[74] = '-';
+
+ if (keyboard_init())
+ Sys_Error("keyboard_init() failed");
+ keyboard_seteventhandler(keyhandler);
+ }
+}
+
+#define NUM_RESOLUTIONS 16
+
+static int resolutions[NUM_RESOLUTIONS][3]={
+ 320,200, GR_RESOLUTION_320x200,
+ 320,240, GR_RESOLUTION_320x240,
+ 400,256, GR_RESOLUTION_400x256,
+ 400,300, GR_RESOLUTION_400x300,
+ 512,384, GR_RESOLUTION_512x384,
+ 640,200, GR_RESOLUTION_640x200,
+ 640,350, GR_RESOLUTION_640x350,
+ 640,400, GR_RESOLUTION_640x400,
+ 640,480, GR_RESOLUTION_640x480,
+ 800,600, GR_RESOLUTION_800x600,
+ 960,720, GR_RESOLUTION_960x720,
+ 856,480, GR_RESOLUTION_856x480,
+ 512,256, GR_RESOLUTION_512x256,
+ 1024,768, GR_RESOLUTION_1024x768,
+ 1280,1024,GR_RESOLUTION_1280x1024,
+ 1600,1200,GR_RESOLUTION_1600x1200
+};
+
+int findres(int *width, int *height)
+{
+ int i;
+
+ for(i=0;i<NUM_RESOLUTIONS;i++)
+ if((*width<=resolutions[i][0]) && (*height<=resolutions[i][1])) {
+ *width = resolutions[i][0];
+ *height = resolutions[i][1];
+ return resolutions[i][2];
+ }
+
+ *width = 640;
+ *height = 480;
+ return GR_RESOLUTION_640x480;
+}
+
+qboolean VID_Is8bit(void)
+{
+ return is8bit;
+}
+
+void VID_Init8bitPalette(void)
+{
+ // Check for 8bit Extensions and initialize them.
+ int i;
+ void *prjobj;
+
+ if (COM_CheckParm("-no8bit"))
+ return;
+
+ if ((prjobj = dlopen(NULL, RTLD_LAZY)) == NULL) {
+ Con_Printf("Unable to open symbol list for main program.\n");
+ return;
+ }
+
+ if (strstr(gl_extensions, "3DFX_set_global_palette") &&
+ (qgl3DfxSetPaletteEXT = dlsym(prjobj, "gl3DfxSetPaletteEXT")) != NULL) {
+ GLubyte table[256][4];
+ char *oldpal;
+
+ Con_SafePrintf("... Using 3DFX_set_global_palette\n");
+ glEnable( GL_SHARED_TEXTURE_PALETTE_EXT );
+ oldpal = (char *) d_8to24table; //d_8to24table3dfx;
+ for (i=0;i<256;i++) {
+ table[i][2] = *oldpal++;
+ table[i][1] = *oldpal++;
+ table[i][0] = *oldpal++;
+ table[i][3] = 255;
+ oldpal++;
+ }
+ qgl3DfxSetPaletteEXT((GLuint *)table);
+ is8bit = true;
+
+ } else if (strstr(gl_extensions, "GL_EXT_shared_texture_palette") &&
+ (qglColorTableEXT = dlsym(prjobj, "glColorTableEXT")) != NULL) {
+ char thePalette[256*3];
+ char *oldPalette, *newPalette;
+
+ Con_SafePrintf("... Using GL_EXT_shared_texture_palette\n");
+ glEnable( GL_SHARED_TEXTURE_PALETTE_EXT );
+ oldPalette = (char *) d_8to24table; //d_8to24table3dfx;
+ newPalette = thePalette;
+ for (i=0;i<256;i++) {
+ *newPalette++ = *oldPalette++;
+ *newPalette++ = *oldPalette++;
+ *newPalette++ = *oldPalette++;
+ oldPalette++;
+ }
+ qglColorTableEXT(GL_SHARED_TEXTURE_PALETTE_EXT, GL_RGB, 256, GL_RGB, GL_UNSIGNED_BYTE, (void *) thePalette);
+ is8bit = true;
+
+ }
+
+ dlclose(prjobj);
+}
+
+static void Check_Gamma (unsigned char *pal)
+{
+ float f, inf;
+ unsigned char palette[768];
+ int i;
+
+ if ((i = COM_CheckParm("-gamma")) == 0) {
+ if ((gl_renderer && strstr(gl_renderer, "Voodoo")) ||
+ (gl_vendor && strstr(gl_vendor, "3Dfx")))
+ vid_gamma = 1;
+ else
+ vid_gamma = 0.7; // default to 0.7 on non-3dfx hardware
+ } else
+ vid_gamma = Q_atof(com_argv[i+1]);
+
+ for (i=0 ; i<768 ; i++)
+ {
+ f = pow ( (pal[i]+1)/256.0 , vid_gamma );
+ inf = f*255 + 0.5;
+ if (inf < 0)
+ inf = 0;
+ if (inf > 255)
+ inf = 255;
+ palette[i] = inf;
+ }
+
+ memcpy (pal, palette, sizeof(palette));
+}
+
+void VID_Init(unsigned char *palette)
+{
+ int i;
+ GLint attribs[32];
+ char gldir[MAX_OSPATH];
+ int width = 640, height = 480;
+
+ Init_KBD();
+
+ Cvar_RegisterVariable (&vid_mode);
+ Cvar_RegisterVariable (&vid_redrawfull);
+ Cvar_RegisterVariable (&vid_waitforrefresh);
+ Cvar_RegisterVariable (&gl_ztrick);
+
+ vid.maxwarpwidth = WARP_WIDTH;
+ vid.maxwarpheight = WARP_HEIGHT;
+ vid.colormap = host_colormap;
+ vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048));
+
+// interpret command-line params
+
+// set vid parameters
+ attribs[0] = FXMESA_DOUBLEBUFFER;
+ attribs[1] = FXMESA_ALPHA_SIZE;
+ attribs[2] = 1;
+ attribs[3] = FXMESA_DEPTH_SIZE;
+ attribs[4] = 1;
+ attribs[5] = FXMESA_NONE;
+
+ if ((i = COM_CheckParm("-width")) != 0)
+ width = atoi(com_argv[i+1]);
+ if ((i = COM_CheckParm("-height")) != 0)
+ height = atoi(com_argv[i+1]);
+
+ if ((i = COM_CheckParm("-conwidth")) != 0)
+ vid.conwidth = Q_atoi(com_argv[i+1]);
+ else
+ vid.conwidth = 640;
+
+ vid.conwidth &= 0xfff8; // make it a multiple of eight
+
+ if (vid.conwidth < 320)
+ vid.conwidth = 320;
+
+ // pick a conheight that matches with correct aspect
+ vid.conheight = vid.conwidth*3 / 4;
+
+ if ((i = COM_CheckParm("-conheight")) != 0)
+ vid.conheight = Q_atoi(com_argv[i+1]);
+ if (vid.conheight < 200)
+ vid.conheight = 200;
+
+ fc = fxMesaCreateContext(0, findres(&width, &height), GR_REFRESH_75Hz,
+ attribs);
+ if (!fc)
+ Sys_Error("Unable to create 3DFX context.\n");
+
+ InitSig(); // trap evil signals
+
+ scr_width = width;
+ scr_height = height;
+
+ fxMesaMakeCurrent(fc);
+
+ if (vid.conheight > height)
+ vid.conheight = height;
+ if (vid.conwidth > width)
+ vid.conwidth = width;
+ vid.width = vid.conwidth;
+ vid.height = vid.conheight;
+
+ vid.aspect = ((float)vid.height / (float)vid.width) *
+ (320.0 / 240.0);
+ vid.numpages = 2;
+
+ GL_Init();
+
+ sprintf (gldir, "%s/glquake", com_gamedir);
+ Sys_mkdir (gldir);
+
+ Check_Gamma(palette);
+ VID_SetPalette(palette);
+
+ // Check for 3DFX Extensions and initialize them.
+ VID_Init8bitPalette();
+
+ Con_SafePrintf ("Video mode %dx%d initialized.\n", width, height);
+
+ vid.recalc_refdef = 1; // force a surface cache flush
+}
+
+void Sys_SendKeyEvents(void)
+{
+ if (UseKeyboard)
+ while (keyboard_update());
+}
+
+void Force_CenterView_f (void)
+{
+ cl.viewangles[PITCH] = 0;
+}
+
+
+void mousehandler(int buttonstate, int dx, int dy)
+{
+ mouse_buttonstate = buttonstate;
+ mx += dx;
+ my += dy;
+}
+
+void IN_Init(void)
+{
+
+ int mtype;
+ char *mousedev;
+ int mouserate;
+
+ if (UseMouse)
+ {
+
+ Cvar_RegisterVariable (&mouse_button_commands[0]);
+ Cvar_RegisterVariable (&mouse_button_commands[1]);
+ Cvar_RegisterVariable (&mouse_button_commands[2]);
+ Cmd_AddCommand ("force_centerview", Force_CenterView_f);
+
+ mouse_buttons = 3;
+
+ mtype = vga_getmousetype();
+
+ mousedev = "/dev/mouse";
+ if (getenv("MOUSEDEV")) mousedev = getenv("MOUSEDEV");
+ if (COM_CheckParm("-mdev"))
+ mousedev = com_argv[COM_CheckParm("-mdev")+1];
+
+ mouserate = 1200;
+ if (getenv("MOUSERATE")) mouserate = atoi(getenv("MOUSERATE"));
+ if (COM_CheckParm("-mrate"))
+ mouserate = atoi(com_argv[COM_CheckParm("-mrate")+1]);
+
+ if (mouse_init(mousedev, mtype, mouserate))
+ {
+ Con_Printf("No mouse found\n");
+ UseMouse = 0;
+ }
+ else
+ mouse_seteventhandler(mousehandler);
+
+ }
+
+}
+
+void IN_Shutdown(void)
+{
+ if (UseMouse)
+ mouse_close();
+}
+
+/*
+===========
+IN_Commands
+===========
+*/
+void IN_Commands (void)
+{
+ if (UseMouse && cls.state != ca_dedicated)
+ {
+ // poll mouse values
+ while (mouse_update())
+ ;
+
+ // perform button actions
+ if ((mouse_buttonstate & MOUSE_LEFTBUTTON) &&
+ !(mouse_oldbuttonstate & MOUSE_LEFTBUTTON))
+ Key_Event (K_MOUSE1, true);
+ else if (!(mouse_buttonstate & MOUSE_LEFTBUTTON) &&
+ (mouse_oldbuttonstate & MOUSE_LEFTBUTTON))
+ Key_Event (K_MOUSE1, false);
+
+ if ((mouse_buttonstate & MOUSE_RIGHTBUTTON) &&
+ !(mouse_oldbuttonstate & MOUSE_RIGHTBUTTON))
+ Key_Event (K_MOUSE2, true);
+ else if (!(mouse_buttonstate & MOUSE_RIGHTBUTTON) &&
+ (mouse_oldbuttonstate & MOUSE_RIGHTBUTTON))
+ Key_Event (K_MOUSE2, false);
+
+ if ((mouse_buttonstate & MOUSE_MIDDLEBUTTON) &&
+ !(mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON))
+ Key_Event (K_MOUSE3, true);
+ else if (!(mouse_buttonstate & MOUSE_MIDDLEBUTTON) &&
+ (mouse_oldbuttonstate & MOUSE_MIDDLEBUTTON))
+ Key_Event (K_MOUSE3, false);
+
+ mouse_oldbuttonstate = mouse_buttonstate;
+ }
+}
+
+/*
+===========
+IN_Move
+===========
+*/
+void IN_MouseMove (usercmd_t *cmd)
+{
+ if (!UseMouse)
+ return;
+
+ // poll mouse values
+ while (mouse_update())
+ ;
+
+ if (m_filter.value)
+ {
+ mouse_x = (mx + old_mouse_x) * 0.5;
+ mouse_y = (my + old_mouse_y) * 0.5;
+ }
+ else
+ {
+ mouse_x = mx;
+ mouse_y = my;
+ }
+ old_mouse_x = mx;
+ old_mouse_y = my;
+ mx = my = 0; // clear for next update
+
+ mouse_x *= sensitivity.value;
+ mouse_y *= sensitivity.value;
+
+// add mouse X/Y movement to cmd
+ if ( (in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1) ))
+ cmd->sidemove += m_side.value * mouse_x;
+ else
+ cl.viewangles[YAW] -= m_yaw.value * mouse_x;
+
+ if (in_mlook.state & 1)
+ V_StopPitchDrift ();
+
+ if ( (in_mlook.state & 1) && !(in_strafe.state & 1))
+ {
+ cl.viewangles[PITCH] += m_pitch.value * mouse_y;
+ if (cl.viewangles[PITCH] > 80)
+ cl.viewangles[PITCH] = 80;
+ if (cl.viewangles[PITCH] < -70)
+ cl.viewangles[PITCH] = -70;
+ }
+ else
+ {
+ if ((in_strafe.state & 1) && noclip_anglehack)
+ cmd->upmove -= m_forward.value * mouse_y;
+ else
+ cmd->forwardmove -= m_forward.value * mouse_y;
+ }
+}
+
+void IN_Move (usercmd_t *cmd)
+{
+ IN_MouseMove(cmd);
+}
+
+
diff --git a/apps/plugins/sdl/progs/quake/gl_vidlinuxglx.c b/apps/plugins/sdl/progs/quake/gl_vidlinuxglx.c
new file mode 100644
index 0000000000..400adb4678
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/gl_vidlinuxglx.c
@@ -0,0 +1,997 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+#include <termios.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/vt.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <signal.h>
+
+#include <dlfcn.h>
+
+#include "quakedef.h"
+
+#include <GL/glx.h>
+
+#include <X11/keysym.h>
+#include <X11/cursorfont.h>
+
+#include <X11/extensions/xf86dga.h>
+#include <X11/extensions/xf86vmode.h>
+
+#define WARP_WIDTH 320
+#define WARP_HEIGHT 200
+
+static Display *dpy = NULL;
+static int scrnum;
+static Window win;
+static GLXContext ctx = NULL;
+
+#define KEY_MASK (KeyPressMask | KeyReleaseMask)
+#define MOUSE_MASK (ButtonPressMask | ButtonReleaseMask | \
+ PointerMotionMask | ButtonMotionMask )
+#define X_MASK (KEY_MASK | MOUSE_MASK | VisibilityChangeMask | StructureNotifyMask )
+
+
+unsigned short d_8to16table[256];
+unsigned d_8to24table[256];
+unsigned char d_15to8table[65536];
+
+cvar_t vid_mode = {"vid_mode","0",false};
+
+static qboolean mouse_avail;
+static qboolean mouse_active;
+static int mx, my;
+static int old_mouse_x, old_mouse_y;
+
+static cvar_t in_mouse = {"in_mouse", "1", false};
+static cvar_t in_dgamouse = {"in_dgamouse", "1", false};
+static cvar_t m_filter = {"m_filter", "0"};
+
+qboolean dgamouse = false;
+qboolean vidmode_ext = false;
+
+static int win_x, win_y;
+
+static int scr_width, scr_height;
+
+static XF86VidModeModeInfo **vidmodes;
+static int default_dotclock_vidmode;
+static int num_vidmodes;
+static qboolean vidmode_active = false;
+
+/*-----------------------------------------------------------------------*/
+
+//int texture_mode = GL_NEAREST;
+//int texture_mode = GL_NEAREST_MIPMAP_NEAREST;
+//int texture_mode = GL_NEAREST_MIPMAP_LINEAR;
+int texture_mode = GL_LINEAR;
+//int texture_mode = GL_LINEAR_MIPMAP_NEAREST;
+//int texture_mode = GL_LINEAR_MIPMAP_LINEAR;
+
+int texture_extension_number = 1;
+
+float gldepthmin, gldepthmax;
+
+cvar_t gl_ztrick = {"gl_ztrick","1"};
+
+const char *gl_vendor;
+const char *gl_renderer;
+const char *gl_version;
+const char *gl_extensions;
+
+void (*qglColorTableEXT) (int, int, int, int, int, const void*);
+void (*qgl3DfxSetPaletteEXT) (GLuint *);
+
+static float vid_gamma = 1.0;
+
+qboolean is8bit = false;
+qboolean isPermedia = false;
+qboolean gl_mtexable = false;
+
+/*-----------------------------------------------------------------------*/
+void D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
+{
+}
+
+void D_EndDirectRect (int x, int y, int width, int height)
+{
+}
+
+static int XLateKey(XKeyEvent *ev)
+{
+
+ int key;
+ char buf[64];
+ KeySym keysym;
+
+ key = 0;
+
+ XLookupString(ev, buf, sizeof buf, &keysym, 0);
+
+ switch(keysym)
+ {
+ case XK_KP_Page_Up:
+ case XK_Page_Up: key = K_PGUP; break;
+
+ case XK_KP_Page_Down:
+ case XK_Page_Down: key = K_PGDN; break;
+
+ case XK_KP_Home:
+ case XK_Home: key = K_HOME; break;
+
+ case XK_KP_End:
+ case XK_End: key = K_END; break;
+
+ case XK_KP_Left:
+ case XK_Left: key = K_LEFTARROW; break;
+
+ case XK_KP_Right:
+ case XK_Right: key = K_RIGHTARROW; break;
+
+ case XK_KP_Down:
+ case XK_Down: key = K_DOWNARROW; break;
+
+ case XK_KP_Up:
+ case XK_Up: key = K_UPARROW; break;
+
+ case XK_Escape: key = K_ESCAPE; break;
+
+ case XK_KP_Enter:
+ case XK_Return: key = K_ENTER; break;
+
+ case XK_Tab: key = K_TAB; break;
+
+ case XK_F1: key = K_F1; break;
+
+ case XK_F2: key = K_F2; break;
+
+ case XK_F3: key = K_F3; break;
+
+ case XK_F4: key = K_F4; break;
+
+ case XK_F5: key = K_F5; break;
+
+ case XK_F6: key = K_F6; break;
+
+ case XK_F7: key = K_F7; break;
+
+ case XK_F8: key = K_F8; break;
+
+ case XK_F9: key = K_F9; break;
+
+ case XK_F10: key = K_F10; break;
+
+ case XK_F11: key = K_F11; break;
+
+ case XK_F12: key = K_F12; break;
+
+ case XK_BackSpace: key = K_BACKSPACE; break;
+
+ case XK_KP_Delete:
+ case XK_Delete: key = K_DEL; break;
+
+ case XK_Pause: key = K_PAUSE; break;
+
+ case XK_Shift_L:
+ case XK_Shift_R: key = K_SHIFT; break;
+
+ case XK_Execute:
+ case XK_Control_L:
+ case XK_Control_R: key = K_CTRL; break;
+
+ case XK_Alt_L:
+ case XK_Meta_L:
+ case XK_Alt_R:
+ case XK_Meta_R: key = K_ALT; break;
+
+ case XK_KP_Begin: key = '5'; break;
+
+ case XK_KP_Insert:
+ case XK_Insert:key = K_INS; break;
+
+ case XK_KP_Multiply: key = '*'; break;
+ case XK_KP_Add: key = '+'; break;
+ case XK_KP_Subtract: key = '-'; break;
+ case XK_KP_Divide: key = '/'; break;
+
+#if 0
+ case 0x021: key = '1';break;/* [!] */
+ case 0x040: key = '2';break;/* [@] */
+ case 0x023: key = '3';break;/* [#] */
+ case 0x024: key = '4';break;/* [$] */
+ case 0x025: key = '5';break;/* [%] */
+ case 0x05e: key = '6';break;/* [^] */
+ case 0x026: key = '7';break;/* [&] */
+ case 0x02a: key = '8';break;/* [*] */
+ case 0x028: key = '9';;break;/* [(] */
+ case 0x029: key = '0';break;/* [)] */
+ case 0x05f: key = '-';break;/* [_] */
+ case 0x02b: key = '=';break;/* [+] */
+ case 0x07c: key = '\'';break;/* [|] */
+ case 0x07d: key = '[';break;/* [}] */
+ case 0x07b: key = ']';break;/* [{] */
+ case 0x022: key = '\'';break;/* ["] */
+ case 0x03a: key = ';';break;/* [:] */
+ case 0x03f: key = '/';break;/* [?] */
+ case 0x03e: key = '.';break;/* [>] */
+ case 0x03c: key = ',';break;/* [<] */
+#endif
+
+ default:
+ key = *(unsigned char*)buf;
+ if (key >= 'A' && key <= 'Z')
+ key = key - 'A' + 'a';
+ break;
+ }
+
+ return key;
+}
+
+static Cursor CreateNullCursor(Display *display, Window root)
+{
+ Pixmap cursormask;
+ XGCValues xgc;
+ GC gc;
+ XColor dummycolour;
+ Cursor cursor;
+
+ cursormask = XCreatePixmap(display, root, 1, 1, 1/*depth*/);
+ xgc.function = GXclear;
+ gc = XCreateGC(display, cursormask, GCFunction, &xgc);
+ XFillRectangle(display, cursormask, gc, 0, 0, 1, 1);
+ dummycolour.pixel = 0;
+ dummycolour.red = 0;
+ dummycolour.flags = 04;
+ cursor = XCreatePixmapCursor(display, cursormask, cursormask,
+ &dummycolour,&dummycolour, 0,0);
+ XFreePixmap(display,cursormask);
+ XFreeGC(display,gc);
+ return cursor;
+}
+
+static void install_grabs(void)
+{
+
+// inviso cursor
+ XDefineCursor(dpy, win, CreateNullCursor(dpy, win));
+
+ XGrabPointer(dpy, win,
+ True,
+ 0,
+ GrabModeAsync, GrabModeAsync,
+ win,
+ None,
+ CurrentTime);
+
+ if (in_dgamouse.value) {
+ int MajorVersion, MinorVersion;
+
+ if (!XF86DGAQueryVersion(dpy, &MajorVersion, &MinorVersion)) {
+ // unable to query, probalby not supported
+ Con_Printf( "Failed to detect XF86DGA Mouse\n" );
+ in_dgamouse.value = 0;
+ } else {
+ dgamouse = true;
+ XF86DGADirectVideo(dpy, DefaultScreen(dpy), XF86DGADirectMouse);
+ XWarpPointer(dpy, None, win, 0, 0, 0, 0, 0, 0);
+ }
+ } else {
+ XWarpPointer(dpy, None, win,
+ 0, 0, 0, 0,
+ vid.width / 2, vid.height / 2);
+ }
+
+ XGrabKeyboard(dpy, win,
+ False,
+ GrabModeAsync, GrabModeAsync,
+ CurrentTime);
+
+ mouse_active = true;
+
+// XSync(dpy, True);
+}
+
+static void uninstall_grabs(void)
+{
+ if (!dpy || !win)
+ return;
+
+ if (dgamouse) {
+ dgamouse = false;
+ XF86DGADirectVideo(dpy, DefaultScreen(dpy), 0);
+ }
+
+ XUngrabPointer(dpy, CurrentTime);
+ XUngrabKeyboard(dpy, CurrentTime);
+
+// inviso cursor
+ XUndefineCursor(dpy, win);
+
+ mouse_active = false;
+}
+
+static void HandleEvents(void)
+{
+ XEvent event;
+ KeySym ks;
+ int b;
+ qboolean dowarp = false;
+ int mwx = vid.width/2;
+ int mwy = vid.height/2;
+
+ if (!dpy)
+ return;
+
+ while (XPending(dpy)) {
+ XNextEvent(dpy, &event);
+
+ switch (event.type) {
+ case KeyPress:
+ case KeyRelease:
+ Key_Event(XLateKey(&event.xkey), event.type == KeyPress);
+ break;
+
+ case MotionNotify:
+ if (mouse_active) {
+ if (dgamouse) {
+ mx += (event.xmotion.x + win_x) * 2;
+ my += (event.xmotion.y + win_y) * 2;
+ }
+ else
+ {
+ mx += ((int)event.xmotion.x - mwx) * 2;
+ my += ((int)event.xmotion.y - mwy) * 2;
+ mwx = event.xmotion.x;
+ mwy = event.xmotion.y;
+
+ if (mx || my)
+ dowarp = true;
+ }
+ }
+ break;
+
+ break;
+
+ case ButtonPress:
+ b=-1;
+ if (event.xbutton.button == 1)
+ b = 0;
+ else if (event.xbutton.button == 2)
+ b = 2;
+ else if (event.xbutton.button == 3)
+ b = 1;
+ if (b>=0)
+ Key_Event(K_MOUSE1 + b, true);
+ break;
+
+ case ButtonRelease:
+ b=-1;
+ if (event.xbutton.button == 1)
+ b = 0;
+ else if (event.xbutton.button == 2)
+ b = 2;
+ else if (event.xbutton.button == 3)
+ b = 1;
+ if (b>=0)
+ Key_Event(K_MOUSE1 + b, false);
+ break;
+
+ case CreateNotify :
+ win_x = event.xcreatewindow.x;
+ win_y = event.xcreatewindow.y;
+ break;
+
+ case ConfigureNotify :
+ win_x = event.xconfigure.x;
+ win_y = event.xconfigure.y;
+ break;
+ }
+ }
+
+ if (dowarp) {
+ /* move the mouse to the window center again */
+ XWarpPointer(dpy, None, win, 0, 0, 0, 0, vid.width / 2, vid.height / 2);
+ }
+
+}
+
+static void IN_DeactivateMouse( void )
+{
+ if (!mouse_avail || !dpy || !win)
+ return;
+
+ if (mouse_active) {
+ uninstall_grabs();
+ mouse_active = false;
+ }
+}
+
+static void IN_ActivateMouse( void )
+{
+ if (!mouse_avail || !dpy || !win)
+ return;
+
+ if (!mouse_active) {
+ mx = my = 0; // don't spazz
+ install_grabs();
+ mouse_active = true;
+ }
+}
+
+
+void VID_Shutdown(void)
+{
+ if (!ctx || !dpy)
+ return;
+ IN_DeactivateMouse();
+ if (dpy) {
+ if (ctx)
+ glXDestroyContext(dpy, ctx);
+ if (win)
+ XDestroyWindow(dpy, win);
+ if (vidmode_active)
+ XF86VidModeSwitchToMode(dpy, scrnum, vidmodes[0]);
+ XCloseDisplay(dpy);
+ }
+ vidmode_active = false;
+ dpy = NULL;
+ win = 0;
+ ctx = NULL;
+}
+
+void signal_handler(int sig)
+{
+ printf("Received signal %d, exiting...\n", sig);
+ Sys_Quit();
+ exit(0);
+}
+
+void InitSig(void)
+{
+ signal(SIGHUP, signal_handler);
+ signal(SIGINT, signal_handler);
+ signal(SIGQUIT, signal_handler);
+ signal(SIGILL, signal_handler);
+ signal(SIGTRAP, signal_handler);
+ signal(SIGIOT, signal_handler);
+ signal(SIGBUS, signal_handler);
+ signal(SIGFPE, signal_handler);
+ signal(SIGSEGV, signal_handler);
+ signal(SIGTERM, signal_handler);
+}
+
+void VID_ShiftPalette(unsigned char *p)
+{
+// VID_SetPalette(p);
+}
+
+void VID_SetPalette (unsigned char *palette)
+{
+ byte *pal;
+ unsigned r,g,b;
+ unsigned v;
+ int r1,g1,b1;
+ int j,k,l,m;
+ unsigned short i;
+ unsigned *table;
+ FILE *f;
+ char s[255];
+ int dist, bestdist;
+
+//
+// 8 8 8 encoding
+//
+ pal = palette;
+ table = d_8to24table;
+ for (i=0 ; i<256 ; i++)
+ {
+ r = pal[0];
+ g = pal[1];
+ b = pal[2];
+ pal += 3;
+
+ v = (255<<24) + (r<<0) + (g<<8) + (b<<16);
+ *table++ = v;
+ }
+ d_8to24table[255] &= 0xffffff; // 255 is transparent
+
+ for (i=0; i < (1<<15); i++) {
+ /* Maps
+ 000000000000000
+ 000000000011111 = Red = 0x1F
+ 000001111100000 = Blue = 0x03E0
+ 111110000000000 = Grn = 0x7C00
+ */
+ r = ((i & 0x1F) << 3)+4;
+ g = ((i & 0x03E0) >> 2)+4;
+ b = ((i & 0x7C00) >> 7)+4;
+ pal = (unsigned char *)d_8to24table;
+ for (v=0,k=0,bestdist=10000*10000; v<256; v++,pal+=4) {
+ r1 = (int)r - (int)pal[0];
+ g1 = (int)g - (int)pal[1];
+ b1 = (int)b - (int)pal[2];
+ dist = (r1*r1)+(g1*g1)+(b1*b1);
+ if (dist < bestdist) {
+ k=v;
+ bestdist = dist;
+ }
+ }
+ d_15to8table[i]=k;
+ }
+}
+
+void CheckMultiTextureExtensions(void)
+{
+ void *prjobj;
+
+ if (strstr(gl_extensions, "GL_SGIS_multitexture ") && !COM_CheckParm("-nomtex")) {
+ Con_Printf("Found GL_SGIS_multitexture...\n");
+
+ if ((prjobj = dlopen(NULL, RTLD_LAZY)) == NULL) {
+ Con_Printf("Unable to open symbol list for main program.\n");
+ return;
+ }
+
+ qglMTexCoord2fSGIS = (void *) dlsym(prjobj, "glMTexCoord2fSGIS");
+ qglSelectTextureSGIS = (void *) dlsym(prjobj, "glSelectTextureSGIS");
+
+ if (qglMTexCoord2fSGIS && qglSelectTextureSGIS) {
+ Con_Printf("Multitexture extensions found.\n");
+ gl_mtexable = true;
+ } else
+ Con_Printf("Symbol not found, disabled.\n");
+
+ dlclose(prjobj);
+ }
+}
+
+/*
+===============
+GL_Init
+===============
+*/
+void GL_Init (void)
+{
+ gl_vendor = glGetString (GL_VENDOR);
+ Con_Printf ("GL_VENDOR: %s\n", gl_vendor);
+ gl_renderer = glGetString (GL_RENDERER);
+ Con_Printf ("GL_RENDERER: %s\n", gl_renderer);
+
+ gl_version = glGetString (GL_VERSION);
+ Con_Printf ("GL_VERSION: %s\n", gl_version);
+ gl_extensions = glGetString (GL_EXTENSIONS);
+ Con_Printf ("GL_EXTENSIONS: %s\n", gl_extensions);
+
+// Con_Printf ("%s %s\n", gl_renderer, gl_version);
+
+ CheckMultiTextureExtensions ();
+
+ glClearColor (1,0,0,0);
+ glCullFace(GL_FRONT);
+ glEnable(GL_TEXTURE_2D);
+
+ glEnable(GL_ALPHA_TEST);
+ glAlphaFunc(GL_GREATER, 0.666);
+
+ glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
+ glShadeModel (GL_FLAT);
+
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+
+ glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+// glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+}
+
+/*
+=================
+GL_BeginRendering
+
+=================
+*/
+void GL_BeginRendering (int *x, int *y, int *width, int *height)
+{
+ extern cvar_t gl_clear;
+
+ *x = *y = 0;
+ *width = scr_width;
+ *height = scr_height;
+
+// if (!wglMakeCurrent( maindc, baseRC ))
+// Sys_Error ("wglMakeCurrent failed");
+
+// glViewport (*x, *y, *width, *height);
+}
+
+
+void GL_EndRendering (void)
+{
+ glFlush();
+ glXSwapBuffers(dpy, win);
+}
+
+qboolean VID_Is8bit(void)
+{
+ return is8bit;
+}
+
+void VID_Init8bitPalette(void)
+{
+ // Check for 8bit Extensions and initialize them.
+ int i;
+ void *prjobj;
+
+ if ((prjobj = dlopen(NULL, RTLD_LAZY)) == NULL) {
+ Con_Printf("Unable to open symbol list for main program.\n");
+ return;
+ }
+
+ if (strstr(gl_extensions, "3DFX_set_global_palette") &&
+ (qgl3DfxSetPaletteEXT = dlsym(prjobj, "gl3DfxSetPaletteEXT")) != NULL) {
+ GLubyte table[256][4];
+ char *oldpal;
+
+ Con_SafePrintf("8-bit GL extensions enabled.\n");
+ glEnable( GL_SHARED_TEXTURE_PALETTE_EXT );
+ oldpal = (char *) d_8to24table; //d_8to24table3dfx;
+ for (i=0;i<256;i++) {
+ table[i][2] = *oldpal++;
+ table[i][1] = *oldpal++;
+ table[i][0] = *oldpal++;
+ table[i][3] = 255;
+ oldpal++;
+ }
+ qgl3DfxSetPaletteEXT((GLuint *)table);
+ is8bit = true;
+
+ } else if (strstr(gl_extensions, "GL_EXT_shared_texture_palette") &&
+ (qglColorTableEXT = dlsym(prjobj, "glColorTableEXT")) != NULL) {
+ char thePalette[256*3];
+ char *oldPalette, *newPalette;
+
+ Con_SafePrintf("8-bit GL extensions enabled.\n");
+ glEnable( GL_SHARED_TEXTURE_PALETTE_EXT );
+ oldPalette = (char *) d_8to24table; //d_8to24table3dfx;
+ newPalette = thePalette;
+ for (i=0;i<256;i++) {
+ *newPalette++ = *oldPalette++;
+ *newPalette++ = *oldPalette++;
+ *newPalette++ = *oldPalette++;
+ oldPalette++;
+ }
+ qglColorTableEXT(GL_SHARED_TEXTURE_PALETTE_EXT, GL_RGB, 256, GL_RGB, GL_UNSIGNED_BYTE, (void *) thePalette);
+ is8bit = true;
+ }
+
+ dlclose(prjobj);
+}
+
+static void Check_Gamma (unsigned char *pal)
+{
+ float f, inf;
+ unsigned char palette[768];
+ int i;
+
+ if ((i = COM_CheckParm("-gamma")) == 0) {
+ if ((gl_renderer && strstr(gl_renderer, "Voodoo")) ||
+ (gl_vendor && strstr(gl_vendor, "3Dfx")))
+ vid_gamma = 1;
+ else
+ vid_gamma = 0.7; // default to 0.7 on non-3dfx hardware
+ } else
+ vid_gamma = Q_atof(com_argv[i+1]);
+
+ for (i=0 ; i<768 ; i++)
+ {
+ f = pow ( (pal[i]+1)/256.0 , vid_gamma );
+ inf = f*255 + 0.5;
+ if (inf < 0)
+ inf = 0;
+ if (inf > 255)
+ inf = 255;
+ palette[i] = inf;
+ }
+
+ memcpy (pal, palette, sizeof(palette));
+}
+
+void VID_Init(unsigned char *palette)
+{
+ int i;
+ int attrib[] = {
+ GLX_RGBA,
+ GLX_RED_SIZE, 1,
+ GLX_GREEN_SIZE, 1,
+ GLX_BLUE_SIZE, 1,
+ GLX_DOUBLEBUFFER,
+ GLX_DEPTH_SIZE, 1,
+ None
+ };
+ char gldir[MAX_OSPATH];
+ int width = 640, height = 480;
+ XSetWindowAttributes attr;
+ unsigned long mask;
+ Window root;
+ XVisualInfo *visinfo;
+ qboolean fullscreen = true;
+ int MajorVersion, MinorVersion;
+ int actualWidth, actualHeight;
+
+ Cvar_RegisterVariable (&vid_mode);
+ Cvar_RegisterVariable (&in_mouse);
+ Cvar_RegisterVariable (&in_dgamouse);
+ Cvar_RegisterVariable (&m_filter);
+ Cvar_RegisterVariable (&gl_ztrick);
+
+ vid.maxwarpwidth = WARP_WIDTH;
+ vid.maxwarpheight = WARP_HEIGHT;
+ vid.colormap = host_colormap;
+ vid.fullbright = 256 - LittleLong (*((int *)vid.colormap + 2048));
+
+// interpret command-line params
+
+// set vid parameters
+ if ((i = COM_CheckParm("-window")) != 0)
+ fullscreen = false;
+
+ if ((i = COM_CheckParm("-width")) != 0)
+ width = atoi(com_argv[i+1]);
+
+ if ((i = COM_CheckParm("-height")) != 0)
+ height = atoi(com_argv[i+1]);
+
+ if ((i = COM_CheckParm("-conwidth")) != 0)
+ vid.conwidth = Q_atoi(com_argv[i+1]);
+ else
+ vid.conwidth = 640;
+
+ vid.conwidth &= 0xfff8; // make it a multiple of eight
+
+ if (vid.conwidth < 320)
+ vid.conwidth = 320;
+
+ // pick a conheight that matches with correct aspect
+ vid.conheight = vid.conwidth*3 / 4;
+
+ if ((i = COM_CheckParm("-conheight")) != 0)
+ vid.conheight = Q_atoi(com_argv[i+1]);
+ if (vid.conheight < 200)
+ vid.conheight = 200;
+
+ if (!(dpy = XOpenDisplay(NULL))) {
+ fprintf(stderr, "Error couldn't open the X display\n");
+ exit(1);
+ }
+
+ scrnum = DefaultScreen(dpy);
+ root = RootWindow(dpy, scrnum);
+
+ // Get video mode list
+ MajorVersion = MinorVersion = 0;
+ if (!XF86VidModeQueryVersion(dpy, &MajorVersion, &MinorVersion)) {
+ vidmode_ext = false;
+ } else {
+ Con_Printf("Using XFree86-VidModeExtension Version %d.%d\n", MajorVersion, MinorVersion);
+ vidmode_ext = true;
+ }
+
+ visinfo = glXChooseVisual(dpy, scrnum, attrib);
+ if (!visinfo) {
+ fprintf(stderr, "qkHack: Error couldn't get an RGB, Double-buffered, Depth visual\n");
+ exit(1);
+ }
+
+ if (vidmode_ext) {
+ int best_fit, best_dist, dist, x, y;
+
+ XF86VidModeGetAllModeLines(dpy, scrnum, &num_vidmodes, &vidmodes);
+
+ // Are we going fullscreen? If so, let's change video mode
+ if (fullscreen) {
+ best_dist = 9999999;
+ best_fit = -1;
+
+ for (i = 0; i < num_vidmodes; i++) {
+ if (width > vidmodes[i]->hdisplay ||
+ height > vidmodes[i]->vdisplay)
+ continue;
+
+ x = width - vidmodes[i]->hdisplay;
+ y = height - vidmodes[i]->vdisplay;
+ dist = (x * x) + (y * y);
+ if (dist < best_dist) {
+ best_dist = dist;
+ best_fit = i;
+ }
+ }
+
+ if (best_fit != -1) {
+ actualWidth = vidmodes[best_fit]->hdisplay;
+ actualHeight = vidmodes[best_fit]->vdisplay;
+
+ // change to the mode
+ XF86VidModeSwitchToMode(dpy, scrnum, vidmodes[best_fit]);
+ vidmode_active = true;
+
+ // Move the viewport to top left
+ XF86VidModeSetViewPort(dpy, scrnum, 0, 0);
+ } else
+ fullscreen = 0;
+ }
+ }
+
+ /* window attributes */
+ attr.background_pixel = 0;
+ attr.border_pixel = 0;
+ attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
+ attr.event_mask = X_MASK;
+ if (vidmode_active) {
+ mask = CWBackPixel | CWColormap | CWSaveUnder | CWBackingStore |
+ CWEventMask | CWOverrideRedirect;
+ attr.override_redirect = True;
+ attr.backing_store = NotUseful;
+ attr.save_under = False;
+ } else
+ mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
+
+ win = XCreateWindow(dpy, root, 0, 0, width, height,
+ 0, visinfo->depth, InputOutput,
+ visinfo->visual, mask, &attr);
+ XMapWindow(dpy, win);
+
+ if (vidmode_active) {
+ XMoveWindow(dpy, win, 0, 0);
+ XRaiseWindow(dpy, win);
+ XWarpPointer(dpy, None, win, 0, 0, 0, 0, 0, 0);
+ XFlush(dpy);
+ // Move the viewport to top left
+ XF86VidModeSetViewPort(dpy, scrnum, 0, 0);
+ }
+
+ XFlush(dpy);
+
+ ctx = glXCreateContext(dpy, visinfo, NULL, True);
+
+ glXMakeCurrent(dpy, win, ctx);
+
+ scr_width = width;
+ scr_height = height;
+
+ if (vid.conheight > height)
+ vid.conheight = height;
+ if (vid.conwidth > width)
+ vid.conwidth = width;
+ vid.width = vid.conwidth;
+ vid.height = vid.conheight;
+
+ vid.aspect = ((float)vid.height / (float)vid.width) * (320.0 / 240.0);
+ vid.numpages = 2;
+
+ InitSig(); // trap evil signals
+
+ GL_Init();
+
+ sprintf (gldir, "%s/glquake", com_gamedir);
+ Sys_mkdir (gldir);
+
+ VID_SetPalette(palette);
+
+ // Check for 3DFX Extensions and initialize them.
+ VID_Init8bitPalette();
+
+ Con_SafePrintf ("Video mode %dx%d initialized.\n", width, height);
+
+ vid.recalc_refdef = 1; // force a surface cache flush
+}
+
+void Sys_SendKeyEvents(void)
+{
+ HandleEvents();
+}
+
+void Force_CenterView_f (void)
+{
+ cl.viewangles[PITCH] = 0;
+}
+
+void IN_Init(void)
+{
+}
+
+void IN_Shutdown(void)
+{
+}
+
+/*
+===========
+IN_Commands
+===========
+*/
+void IN_Commands (void)
+{
+ if (!dpy || !win)
+ return;
+
+ if (vidmode_active || key_dest == key_game)
+ IN_ActivateMouse();
+ else
+ IN_DeactivateMouse ();
+}
+
+/*
+===========
+IN_Move
+===========
+*/
+void IN_MouseMove (usercmd_t *cmd)
+{
+ if (!mouse_avail)
+ return;
+
+ if (m_filter.value)
+ {
+ mx = (mx + old_mouse_x) * 0.5;
+ my = (my + old_mouse_y) * 0.5;
+ }
+ old_mouse_x = mx;
+ old_mouse_y = my;
+
+ mx *= sensitivity.value;
+ my *= sensitivity.value;
+
+// add mouse X/Y movement to cmd
+ if ( (in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1) ))
+ cmd->sidemove += m_side.value * mx;
+ else
+ cl.viewangles[YAW] -= m_yaw.value * mx;
+
+ if (in_mlook.state & 1)
+ V_StopPitchDrift ();
+
+ if ( (in_mlook.state & 1) && !(in_strafe.state & 1))
+ {
+ cl.viewangles[PITCH] += m_pitch.value * my;
+ if (cl.viewangles[PITCH] > 80)
+ cl.viewangles[PITCH] = 80;
+ if (cl.viewangles[PITCH] < -70)
+ cl.viewangles[PITCH] = -70;
+ }
+ else
+ {
+ if ((in_strafe.state & 1) && noclip_anglehack)
+ cmd->upmove -= m_forward.value * my;
+ else
+ cmd->forwardmove -= m_forward.value * my;
+ }
+ mx = my = 0;
+}
+
+void IN_Move (usercmd_t *cmd)
+{
+ IN_MouseMove(cmd);
+}
+
+
diff --git a/apps/plugins/sdl/progs/quake/host.c b/apps/plugins/sdl/progs/quake/host.c
new file mode 100644
index 0000000000..9a5f7c29d6
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/host.c
@@ -0,0 +1,977 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+// host.c -- coordinates spawning and killing of local servers
+
+#include "quakedef.h"
+#include "r_local.h"
+
+/*
+
+A server can allways be started, even if the system started out as a client
+to a remote system.
+
+A client can NOT be started if the system started as a dedicated server.
+
+Memory is cleared / released when a server or client begins, not when they end.
+
+*/
+
+quakeparms_t host_parms;
+
+qboolean host_initialized; // true if into command execution
+
+double host_frametime;
+double host_time;
+double realtime; // without any filtering or bounding
+double oldrealtime; // last frame run
+int host_framecount;
+
+int host_hunklevel;
+
+int minimum_memory;
+
+client_t *host_client; // current client
+
+jmp_buf host_abortserver;
+
+byte *host_basepal;
+byte *host_colormap;
+
+cvar_t host_framerate = {"host_framerate","0"}; // set for slow motion
+cvar_t host_speeds = {"host_speeds","0"}; // set for running times
+
+cvar_t sys_ticrate = {"sys_ticrate","0.05"};
+cvar_t serverprofile = {"serverprofile","0"};
+
+cvar_t fraglimit = {"fraglimit","0",false,true};
+cvar_t timelimit = {"timelimit","0",false,true};
+cvar_t teamplay = {"teamplay","0",false,true};
+
+cvar_t samelevel = {"samelevel","0"};
+cvar_t noexit = {"noexit","0",false,true};
+
+#ifdef QUAKE2
+cvar_t developer = {"developer","1"}; // should be 0 for release!
+#else
+cvar_t developer = {"developer","0"};
+#endif
+
+cvar_t skill = {"skill","1"}; // 0 - 3
+cvar_t deathmatch = {"deathmatch","0"}; // 0, 1, or 2
+cvar_t coop = {"coop","0"}; // 0 or 1
+
+cvar_t pausable = {"pausable","1"};
+
+cvar_t temp1 = {"temp1","0"};
+
+
+/*
+================
+Host_EndGame
+================
+*/
+void Host_EndGame (char *message, ...)
+{
+ va_list argptr;
+ char string[1024];
+
+ va_start (argptr,message);
+ vsprintf (string,message,argptr);
+ va_end (argptr);
+ Con_DPrintf ("Host_EndGame: %s\n",string);
+
+ if (sv.active)
+ Host_ShutdownServer (false);
+
+ if (cls.state == ca_dedicated)
+ Sys_Error ("Host_EndGame: %s\n",string); // dedicated servers exit
+
+ if (cls.demonum != -1)
+ CL_NextDemo ();
+ else
+ CL_Disconnect ();
+
+ longjmp (host_abortserver, 1);
+}
+
+/*
+================
+Host_Error
+
+This shuts down both the client and server
+================
+*/
+void Host_Error (char *error, ...)
+{
+ va_list argptr;
+ char string[1024];
+ static qboolean inerror = false;
+
+ if (inerror)
+ Sys_Error ("Host_Error: recursively entered");
+ inerror = true;
+
+ SCR_EndLoadingPlaque (); // reenable screen updates
+
+ va_start (argptr,error);
+ vsprintf (string,error,argptr);
+ va_end (argptr);
+ Con_Printf ("Host_Error: %s\n",string);
+
+ if (sv.active)
+ Host_ShutdownServer (false);
+
+ if (cls.state == ca_dedicated)
+ Sys_Error ("Host_Error: %s\n",string); // dedicated servers exit
+
+ CL_Disconnect ();
+ cls.demonum = -1;
+
+ inerror = false;
+
+ longjmp (host_abortserver, 1);
+}
+
+/*
+================
+Host_FindMaxClients
+================
+*/
+void Host_FindMaxClients (void)
+{
+ int i;
+
+ svs.maxclients = 1;
+
+ i = COM_CheckParm ("-dedicated");
+ if (i)
+ {
+ cls.state = ca_dedicated;
+ if (i != (com_argc - 1))
+ {
+ svs.maxclients = Q_atoi (com_argv[i+1]);
+ }
+ else
+ svs.maxclients = 8;
+ }
+ else
+ cls.state = ca_disconnected;
+
+ i = COM_CheckParm ("-listen");
+ if (i)
+ {
+ if (cls.state == ca_dedicated)
+ Sys_Error ("Only one of -dedicated or -listen can be specified");
+ if (i != (com_argc - 1))
+ svs.maxclients = Q_atoi (com_argv[i+1]);
+ else
+ svs.maxclients = 8;
+ }
+ if (svs.maxclients < 1)
+ svs.maxclients = 8;
+ else if (svs.maxclients > MAX_SCOREBOARD)
+ svs.maxclients = MAX_SCOREBOARD;
+
+ svs.maxclientslimit = svs.maxclients;
+ if (svs.maxclientslimit < 4)
+ svs.maxclientslimit = 4;
+ svs.clients = Hunk_AllocName (svs.maxclientslimit*sizeof(client_t), "clients");
+
+ if (svs.maxclients > 1)
+ Cvar_SetValue ("deathmatch", 1.0);
+ else
+ Cvar_SetValue ("deathmatch", 0.0);
+}
+
+
+/*
+=======================
+Host_InitLocal
+======================
+*/
+void Host_InitLocal (void)
+{
+ Host_InitCommands ();
+
+ Cvar_RegisterVariable (&host_framerate);
+ Cvar_RegisterVariable (&host_speeds);
+
+ Cvar_RegisterVariable (&sys_ticrate);
+ Cvar_RegisterVariable (&serverprofile);
+
+ Cvar_RegisterVariable (&fraglimit);
+ Cvar_RegisterVariable (&timelimit);
+ Cvar_RegisterVariable (&teamplay);
+ Cvar_RegisterVariable (&samelevel);
+ Cvar_RegisterVariable (&noexit);
+ Cvar_RegisterVariable (&skill);
+ Cvar_RegisterVariable (&developer);
+ Cvar_RegisterVariable (&deathmatch);
+ Cvar_RegisterVariable (&coop);
+
+ Cvar_RegisterVariable (&pausable);
+
+ Cvar_RegisterVariable (&temp1);
+
+ Host_FindMaxClients ();
+
+ host_time = 1.0; // so a think at time 0 won't get called
+}
+
+
+/*
+===============
+Host_WriteConfiguration
+
+Writes key bindings and archived cvars to config.cfg
+===============
+*/
+void Host_WriteConfiguration (void)
+{
+ FILE *f;
+
+// dedicated servers initialize the host but don't parse and set the
+// config.cfg cvars
+ if (host_initialized & !isDedicated)
+ {
+ f = fopen (va("%s/config.cfg",com_gamedir), "w");
+ if (!f)
+ {
+ Con_Printf ("Couldn't write config.cfg.\n");
+ return;
+ }
+
+ Key_WriteBindings (f);
+ Cvar_WriteVariables (f);
+
+ fclose (f);
+ }
+}
+
+
+/*
+=================
+SV_ClientPrintf
+
+Sends text across to be displayed
+FIXME: make this just a stuffed echo?
+=================
+*/
+void SV_ClientPrintf (char *fmt, ...)
+{
+ va_list argptr;
+ char string[1024];
+
+ va_start (argptr,fmt);
+ vsprintf (string, fmt,argptr);
+ va_end (argptr);
+
+ MSG_WriteByte (&host_client->message, svc_print);
+ MSG_WriteString (&host_client->message, string);
+}
+
+/*
+=================
+SV_BroadcastPrintf
+
+Sends text to all active clients
+=================
+*/
+void SV_BroadcastPrintf (char *fmt, ...)
+{
+ va_list argptr;
+ char string[1024];
+ int i;
+
+ va_start (argptr,fmt);
+ vsprintf (string, fmt,argptr);
+ va_end (argptr);
+
+ for (i=0 ; i<svs.maxclients ; i++)
+ if (svs.clients[i].active && svs.clients[i].spawned)
+ {
+ MSG_WriteByte (&svs.clients[i].message, svc_print);
+ MSG_WriteString (&svs.clients[i].message, string);
+ }
+}
+
+/*
+=================
+Host_ClientCommands
+
+Send text over to the client to be executed
+=================
+*/
+void Host_ClientCommands (char *fmt, ...)
+{
+ va_list argptr;
+ char string[1024];
+
+ va_start (argptr,fmt);
+ vsprintf (string, fmt,argptr);
+ va_end (argptr);
+
+ MSG_WriteByte (&host_client->message, svc_stufftext);
+ MSG_WriteString (&host_client->message, string);
+}
+
+/*
+=====================
+SV_DropClient
+
+Called when the player is getting totally kicked off the host
+if (crash = true), don't bother sending signofs
+=====================
+*/
+void SV_DropClient (qboolean crash)
+{
+ int saveSelf;
+ int i;
+ client_t *client;
+
+ if (!crash)
+ {
+ // send any final messages (don't check for errors)
+ if (NET_CanSendMessage (host_client->netconnection))
+ {
+ MSG_WriteByte (&host_client->message, svc_disconnect);
+ NET_SendMessage (host_client->netconnection, &host_client->message);
+ }
+
+ if (host_client->edict && host_client->spawned)
+ {
+ // call the prog function for removing a client
+ // this will set the body to a dead frame, among other things
+ saveSelf = pr_global_struct->self;
+ pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
+ PR_ExecuteProgram (pr_global_struct->ClientDisconnect);
+ pr_global_struct->self = saveSelf;
+ }
+
+ Sys_Printf ("Client %s removed\n",host_client->name);
+ }
+
+// break the net connection
+ NET_Close (host_client->netconnection);
+ host_client->netconnection = NULL;
+
+// free the client (the body stays around)
+ host_client->active = false;
+ host_client->name[0] = 0;
+ host_client->old_frags = -999999;
+ net_activeconnections--;
+
+// send notification to all clients
+ for (i=0, client = svs.clients ; i<svs.maxclients ; i++, client++)
+ {
+ if (!client->active)
+ continue;
+ MSG_WriteByte (&client->message, svc_updatename);
+ MSG_WriteByte (&client->message, host_client - svs.clients);
+ MSG_WriteString (&client->message, "");
+ MSG_WriteByte (&client->message, svc_updatefrags);
+ MSG_WriteByte (&client->message, host_client - svs.clients);
+ MSG_WriteShort (&client->message, 0);
+ MSG_WriteByte (&client->message, svc_updatecolors);
+ MSG_WriteByte (&client->message, host_client - svs.clients);
+ MSG_WriteByte (&client->message, 0);
+ }
+}
+
+/*
+==================
+Host_ShutdownServer
+
+This only happens at the end of a game, not between levels
+==================
+*/
+void Host_ShutdownServer(qboolean crash)
+{
+ int i;
+ int count;
+ sizebuf_t buf;
+ char message[4];
+ double start;
+
+ if (!sv.active)
+ return;
+
+ sv.active = false;
+
+// stop all client sounds immediately
+ if (cls.state == ca_connected)
+ CL_Disconnect ();
+
+// flush any pending messages - like the score!!!
+ start = Sys_FloatTime();
+ do
+ {
+ count = 0;
+ for (i=0, host_client = svs.clients ; i<svs.maxclients ; i++, host_client++)
+ {
+ if (host_client->active && host_client->message.cursize)
+ {
+ if (NET_CanSendMessage (host_client->netconnection))
+ {
+ NET_SendMessage(host_client->netconnection, &host_client->message);
+ SZ_Clear (&host_client->message);
+ }
+ else
+ {
+ NET_GetMessage(host_client->netconnection);
+ count++;
+ }
+ }
+ }
+ if ((Sys_FloatTime() - start) > 3.0)
+ break;
+ }
+ while (count);
+
+// make sure all the clients know we're disconnecting
+ buf.data = message;
+ buf.maxsize = 4;
+ buf.cursize = 0;
+ MSG_WriteByte(&buf, svc_disconnect);
+ count = NET_SendToAll(&buf, 5);
+ if (count)
+ Con_Printf("Host_ShutdownServer: NET_SendToAll failed for %u clients\n", count);
+
+ for (i=0, host_client = svs.clients ; i<svs.maxclients ; i++, host_client++)
+ if (host_client->active)
+ SV_DropClient(crash);
+
+//
+// clear structures
+//
+ memset (&sv, 0, sizeof(sv));
+ memset (svs.clients, 0, svs.maxclientslimit*sizeof(client_t));
+}
+
+
+/*
+================
+Host_ClearMemory
+
+This clears all the memory used by both the client and server, but does
+not reinitialize anything.
+================
+*/
+void Host_ClearMemory (void)
+{
+ Con_DPrintf ("Clearing memory\n");
+ D_FlushCaches ();
+ Mod_ClearAll ();
+ if (host_hunklevel)
+ Hunk_FreeToLowMark (host_hunklevel);
+
+ cls.signon = 0;
+ memset (&sv, 0, sizeof(sv));
+ memset (&cl, 0, sizeof(cl));
+}
+
+
+//============================================================================
+
+
+/*
+===================
+Host_FilterTime
+
+Returns false if the time is too short to run a frame
+===================
+*/
+qboolean Host_FilterTime (float time)
+{
+ realtime += time;
+
+ if (!cls.timedemo && realtime - oldrealtime < 1.0/72.0)
+ return false; // framerate is too high
+
+ host_frametime = realtime - oldrealtime;
+ oldrealtime = realtime;
+
+ if (host_framerate.value > 0)
+ host_frametime = host_framerate.value;
+ else
+ { // don't allow really long or short frames
+ if (host_frametime > 0.1)
+ host_frametime = 0.1;
+ if (host_frametime < 0.001)
+ host_frametime = 0.001;
+ }
+
+ return true;
+}
+
+
+/*
+===================
+Host_GetConsoleCommands
+
+Add them exactly as if they had been typed at the console
+===================
+*/
+void Host_GetConsoleCommands (void)
+{
+ char *cmd;
+
+ while (1)
+ {
+ cmd = Sys_ConsoleInput ();
+ if (!cmd)
+ break;
+ Cbuf_AddText (cmd);
+ }
+}
+
+
+/*
+==================
+Host_ServerFrame
+
+==================
+*/
+#ifdef FPS_20
+
+void _Host_ServerFrame (void)
+{
+// run the world state
+ pr_global_struct->frametime = host_frametime;
+
+// read client messages
+ SV_RunClients ();
+
+// move things around and think
+// always pause in single player if in console or menus
+ if (!sv.paused && (svs.maxclients > 1 || key_dest == key_game) )
+ SV_Physics ();
+}
+
+void Host_ServerFrame (void)
+{
+ float save_host_frametime;
+ float temp_host_frametime;
+
+// run the world state
+ pr_global_struct->frametime = host_frametime;
+
+// set the time and clear the general datagram
+ SV_ClearDatagram ();
+
+// check for new clients
+ SV_CheckForNewClients ();
+
+ temp_host_frametime = save_host_frametime = host_frametime;
+ while(temp_host_frametime > (1.0/72.0))
+ {
+ if (temp_host_frametime > 0.05)
+ host_frametime = 0.05;
+ else
+ host_frametime = temp_host_frametime;
+ temp_host_frametime -= host_frametime;
+ _Host_ServerFrame ();
+ }
+ host_frametime = save_host_frametime;
+
+// send all messages to the clients
+ SV_SendClientMessages ();
+}
+
+#else
+
+void Host_ServerFrame (void)
+{
+// run the world state
+ pr_global_struct->frametime = host_frametime;
+
+// set the time and clear the general datagram
+ SV_ClearDatagram ();
+
+// check for new clients
+ SV_CheckForNewClients ();
+
+// read client messages
+ SV_RunClients ();
+
+// move things around and think
+// always pause in single player if in console or menus
+ if (!sv.paused && (svs.maxclients > 1 || key_dest == key_game) )
+ SV_Physics ();
+
+// send all messages to the clients
+ SV_SendClientMessages ();
+}
+
+#endif
+
+
+/*
+==================
+Host_Frame
+
+Runs all active servers
+==================
+*/
+void _Host_Frame (float time)
+{
+ static double time1 = 0;
+ static double time2 = 0;
+ static double time3 = 0;
+ int pass1, pass2, pass3;
+
+ if (setjmp (host_abortserver) )
+ return; // something bad happened, or the server disconnected
+
+// keep the random time dependent
+ rand ();
+
+// decide the simulation time
+ if (!Host_FilterTime (time))
+ return; // don't run too fast, or packets will flood out
+
+// get new key events
+ Sys_SendKeyEvents ();
+
+// allow mice or other external controllers to add commands
+ IN_Commands ();
+
+// process console commands
+ Cbuf_Execute ();
+
+ NET_Poll();
+
+// if running the server locally, make intentions now
+ if (sv.active)
+ CL_SendCmd ();
+
+//-------------------
+//
+// server operations
+//
+//-------------------
+
+// check for commands typed to the host
+ Host_GetConsoleCommands ();
+
+ if (sv.active)
+ Host_ServerFrame ();
+
+//-------------------
+//
+// client operations
+//
+//-------------------
+
+// if running the server remotely, send intentions now after
+// the incoming messages have been read
+ if (!sv.active)
+ CL_SendCmd ();
+
+ host_time += host_frametime;
+
+// fetch results from server
+ if (cls.state == ca_connected)
+ {
+ CL_ReadFromServer ();
+ }
+
+// update video
+ if (host_speeds.value)
+ time1 = Sys_FloatTime ();
+
+ SCR_UpdateScreen ();
+
+ if (host_speeds.value)
+ time2 = Sys_FloatTime ();
+
+// update audio
+ if (cls.signon == SIGNONS)
+ {
+ S_Update (r_origin, vpn, vright, vup);
+ CL_DecayLights ();
+ }
+ else
+ S_Update (vec3_origin, vec3_origin, vec3_origin, vec3_origin);
+
+ CDAudio_Update();
+
+ if (host_speeds.value)
+ {
+ pass1 = (time1 - time3)*1000;
+ time3 = Sys_FloatTime ();
+ pass2 = (time2 - time1)*1000;
+ pass3 = (time3 - time2)*1000;
+ Con_Printf ("%3i tot %3i server %3i gfx %3i snd\n",
+ pass1+pass2+pass3, pass1, pass2, pass3);
+ }
+
+ host_framecount++;
+}
+
+void Host_Frame (float time)
+{
+ double time1, time2;
+ static double timetotal;
+ static int timecount;
+ int i, c, m;
+
+ if (!serverprofile.value)
+ {
+ _Host_Frame (time);
+ return;
+ }
+
+ time1 = Sys_FloatTime ();
+ _Host_Frame (time);
+ time2 = Sys_FloatTime ();
+
+ timetotal += time2 - time1;
+ timecount++;
+
+ if (timecount < 1000)
+ return;
+
+ m = timetotal*1000/timecount;
+ timecount = 0;
+ timetotal = 0;
+ c = 0;
+ for (i=0 ; i<svs.maxclients ; i++)
+ {
+ if (svs.clients[i].active)
+ c++;
+ }
+
+ Con_Printf ("serverprofile: %2i clients %2i msec\n", c, m);
+}
+
+//============================================================================
+
+
+extern int vcrFile;
+#define VCR_SIGNATURE 0x56435231
+// "VCR1"
+
+void Host_InitVCR (quakeparms_t *parms)
+{
+ int i, len, n;
+ char *p;
+
+ if (COM_CheckParm("-playback"))
+ {
+ if (com_argc != 2)
+ Sys_Error("No other parameters allowed with -playback\n");
+
+ Sys_FileOpenRead("quake.vcr", &vcrFile);
+ if (vcrFile == -1)
+ Sys_Error("playback file not found\n");
+
+ Sys_FileRead (vcrFile, &i, sizeof(int));
+ if (i != VCR_SIGNATURE)
+ Sys_Error("Invalid signature in vcr file\n");
+
+ Sys_FileRead (vcrFile, &com_argc, sizeof(int));
+ com_argv = malloc(com_argc * sizeof(char *));
+ com_argv[0] = parms->argv[0];
+ for (i = 0; i < com_argc; i++)
+ {
+ Sys_FileRead (vcrFile, &len, sizeof(int));
+ p = malloc(len);
+ Sys_FileRead (vcrFile, p, len);
+ com_argv[i+1] = p;
+ }
+ com_argc++; /* add one for arg[0] */
+ parms->argc = com_argc;
+ parms->argv = com_argv;
+ }
+
+ if ( (n = COM_CheckParm("-record")) != 0)
+ {
+ vcrFile = Sys_FileOpenWrite("quake.vcr");
+
+ i = VCR_SIGNATURE;
+ Sys_FileWrite(vcrFile, &i, sizeof(int));
+ i = com_argc - 1;
+ Sys_FileWrite(vcrFile, &i, sizeof(int));
+ for (i = 1; i < com_argc; i++)
+ {
+ if (i == n)
+ {
+ len = 10;
+ Sys_FileWrite(vcrFile, &len, sizeof(int));
+ Sys_FileWrite(vcrFile, "-playback", len);
+ continue;
+ }
+ len = Q_strlen(com_argv[i]) + 1;
+ Sys_FileWrite(vcrFile, &len, sizeof(int));
+ Sys_FileWrite(vcrFile, com_argv[i], len);
+ }
+ }
+
+}
+
+/*
+====================
+Host_Init
+====================
+*/
+void Host_Init (quakeparms_t *parms)
+{
+
+ if (standard_quake)
+ minimum_memory = MINIMUM_MEMORY;
+ else
+ minimum_memory = MINIMUM_MEMORY_LEVELPAK;
+
+ if (COM_CheckParm ("-minmemory"))
+ parms->memsize = minimum_memory;
+
+ host_parms = *parms;
+
+ if (parms->memsize < minimum_memory)
+ Sys_Error ("Only %4.1f megs of memory available, can't execute game", parms->memsize / (float)0x100000);
+
+ com_argc = parms->argc;
+ com_argv = parms->argv;
+
+ //printf("init 1");
+
+ Memory_Init (parms->membase, parms->memsize);
+ //printf("init 2");
+ Cbuf_Init ();
+ //printf("init 3");
+ Cmd_Init ();
+ //printf("init 4");
+ V_Init ();
+ //printf("init 5");
+ Chase_Init ();
+ //printf("init 6");
+ Host_InitVCR (parms);
+ //printf("init 7");
+ COM_Init (parms->basedir);
+ //printf("init 8");
+ Host_InitLocal ();
+ //printf("init 9");
+ W_LoadWadFile ("gfx.wad");
+ //printf("init 10");
+ Key_Init ();
+ Con_Init ();
+ M_Init ();
+ PR_Init ();
+ Mod_Init ();
+ NET_Init ();
+ //printf("init 11");
+ SV_Init ();
+ //printf("init 12");
+
+ Con_Printf ("Exe: "__TIME__" "__DATE__"\n");
+ Con_Printf ("%4.1f megabyte heap\n",parms->memsize/ (1024*1024.0));
+
+ R_InitTextures (); // needed even for dedicated servers
+
+ //printf("init 13");
+ if (cls.state != ca_dedicated)
+ {
+ host_basepal = (byte *)COM_LoadHunkFile ("gfx/palette.lmp");
+ if (!host_basepal)
+ Sys_Error ("Couldn't load gfx/palette.lmp");
+ host_colormap = (byte *)COM_LoadHunkFile ("gfx/colormap.lmp");
+ if (!host_colormap)
+ Sys_Error ("Couldn't load gfx/colormap.lmp");
+
+#ifndef _WIN32 // on non win32, mouse comes before video for security reasons
+ IN_Init ();
+#endif
+ VID_Init (host_basepal);
+
+ Draw_Init ();
+ SCR_Init ();
+ R_Init ();
+#ifndef _WIN32
+ // on Win32, sound initialization has to come before video initialization, so we
+ // can put up a popup if the sound hardware is in use
+ S_Init ();
+#else
+
+#ifdef GLQUAKE
+ // FIXME: doesn't use the new one-window approach yet
+ S_Init ();
+#endif
+
+#endif // _WIN32
+ CDAudio_Init ();
+ Sbar_Init ();
+ CL_Init ();
+#ifdef _WIN32 // on non win32, mouse comes before video for security reasons
+ IN_Init ();
+#endif
+ }
+
+ Cbuf_InsertText ("exec quake.rc\n");
+
+ Hunk_AllocName (0, "-HOST_HUNKLEVEL-");
+ host_hunklevel = Hunk_LowMark ();
+
+ host_initialized = true;
+
+ Sys_Printf ("========Quake Initialized=========\n");
+
+ extern int enable_printf;
+ enable_printf = 0;
+}
+
+
+/*
+===============
+Host_Shutdown
+
+FIXME: this is a callback from Sys_Quit and Sys_Error. It would be better
+to run quit through here before the final handoff to the sys code.
+===============
+*/
+void Host_Shutdown(void)
+{
+ static qboolean isdown = false;
+
+ if (isdown)
+ {
+ printf ("recursive shutdown\n");
+ return;
+ }
+ isdown = true;
+
+// keep Con_Printf from trying to update the screen
+ scr_disabled_for_loading = true;
+
+ Host_WriteConfiguration ();
+
+ CDAudio_Shutdown ();
+ NET_Shutdown ();
+ S_Shutdown();
+ IN_Shutdown ();
+
+ Sys_Shutdown();
+
+ if (cls.state != ca_dedicated)
+ {
+ VID_Shutdown();
+ }
+}
+
diff --git a/apps/plugins/sdl/progs/quake/host_cmd.c b/apps/plugins/sdl/progs/quake/host_cmd.c
new file mode 100644
index 0000000000..498eec0d3a
--- /dev/null
+++ b/apps/plugins/sdl/progs/quake/host_cmd.c
@@ -0,0 +1,1931 @@
+/*
+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 the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+
+#include "quakedef.h"
+
+extern cvar_t pausable;
+
+int current_skill;
+
+void Mod_Print (void);
+
+/*
+==================
+Host_Quit_f
+==================
+*/
+
+extern void M_Menu_Quit_f (void);
+
+void Host_Quit_f (void)
+{
+ if (key_dest != key_console && cls.state != ca_dedicated)
+ {
+ M_Menu_Quit_f ();
+ return;
+ }
+ CL_Disconnect ();
+ Host_ShutdownServer(false);
+
+ Sys_Quit ();
+}
+
+
+/*
+==================
+Host_Status_f
+==================
+*/
+void Host_Status_f (void)
+{
+ client_t *client;
+ int seconds;
+ int minutes;
+ int hours = 0;
+ int j;
+ void (*print) (char *fmt, ...);
+
+ if (cmd_source == src_command)
+ {
+ if (!sv.active)
+ {
+ Cmd_ForwardToServer ();
+ return;
+ }
+ print = Con_Printf;
+ }
+ else
+ print = SV_ClientPrintf;
+
+ print ("host: %s\n", Cvar_VariableString ("hostname"));
+ print ("version: %4.2f\n", VERSION);
+ if (tcpipAvailable)
+ print ("tcp/ip: %s\n", my_tcpip_address);
+ if (ipxAvailable)
+ print ("ipx: %s\n", my_ipx_address);
+ print ("map: %s\n", sv.name);
+ print ("players: %i active (%i max)\n\n", net_activeconnections, svs.maxclients);
+ for (j=0, client = svs.clients ; j<svs.maxclients ; j++, client++)
+ {
+ if (!client->active)
+ continue;
+ seconds = (int)(net_time - client->netconnection->connecttime);
+ minutes = seconds / 60;
+ if (minutes)
+ {
+ seconds -= (minutes * 60);
+ hours = minutes / 60;
+ if (hours)
+ minutes -= (hours * 60);
+ }
+ else
+ hours = 0;
+ print ("#%-2u %-16.16s %3i %2i:%02i:%02i\n", j+1, client->name, (int)client->edict->v.frags, hours, minutes, seconds);
+ print (" %s\n", client->netconnection->address);
+ }
+}
+
+
+/*
+==================
+Host_God_f
+
+Sets client to godmode
+==================
+*/
+void Host_God_f (void)
+{
+ if (cmd_source == src_command)
+ {
+ Cmd_ForwardToServer ();
+ return;
+ }
+
+ if (pr_global_struct->deathmatch && !host_client->privileged)
+ return;
+
+ sv_player->v.flags = (int)sv_player->v.flags ^ FL_GODMODE;
+ if (!((int)sv_player->v.flags & FL_GODMODE) )
+ SV_ClientPrintf ("godmode OFF\n");
+ else
+ SV_ClientPrintf ("godmode ON\n");
+}
+
+void Host_Notarget_f (void)
+{
+ if (cmd_source == src_command)
+ {
+ Cmd_ForwardToServer ();
+ return;
+ }
+
+ if (pr_global_struct->deathmatch && !host_client->privileged)
+ return;
+
+ sv_player->v.flags = (int)sv_player->v.flags ^ FL_NOTARGET;
+ if (!((int)sv_player->v.flags & FL_NOTARGET) )
+ SV_ClientPrintf ("notarget OFF\n");
+ else
+ SV_ClientPrintf ("notarget ON\n");
+}
+
+qboolean noclip_anglehack;
+
+void Host_Noclip_f (void)
+{
+ if (cmd_source == src_command)
+ {
+ Cmd_ForwardToServer ();
+ return;
+ }
+
+ if (pr_global_struct->deathmatch && !host_client->privileged)
+ return;
+
+ if (sv_player->v.movetype != MOVETYPE_NOCLIP)
+ {
+ noclip_anglehack = true;
+ sv_player->v.movetype = MOVETYPE_NOCLIP;
+ SV_ClientPrintf ("noclip ON\n");
+ }
+ else
+ {
+ noclip_anglehack = false;
+ sv_player->v.movetype = MOVETYPE_WALK;
+ SV_ClientPrintf ("noclip OFF\n");
+ }
+}
+
+/*
+==================
+Host_Fly_f
+
+Sets client to flymode
+==================
+*/
+void Host_Fly_f (void)
+{
+ if (cmd_source == src_command)
+ {
+ Cmd_ForwardToServer ();
+ return;
+ }
+
+ if (pr_global_struct->deathmatch && !host_client->privileged)
+ return;
+
+ if (sv_player->v.movetype != MOVETYPE_FLY)
+ {
+ sv_player->v.movetype = MOVETYPE_FLY;
+ SV_ClientPrintf ("flymode ON\n");
+ }
+ else
+ {
+ sv_player->v.movetype = MOVETYPE_WALK;
+ SV_ClientPrintf ("flymode OFF\n");
+ }
+}
+
+
+/*
+==================
+Host_Ping_f
+
+==================
+*/
+void Host_Ping_f (void)
+{
+ int i, j;
+ float total;
+ client_t *client;
+
+ if (cmd_source == src_command)
+ {
+ Cmd_ForwardToServer ();
+ return;
+ }
+
+ SV_ClientPrintf ("Client ping times:\n");
+ for (i=0, client = svs.clients ; i<svs.maxclients ; i++, client++)
+ {
+ if (!client->active)
+ continue;
+ total = 0;
+ for (j=0 ; j<NUM_PING_TIMES ; j++)
+ total+=client->ping_times[j];
+ total /= NUM_PING_TIMES;
+ SV_ClientPrintf ("%4i %s\n", (int)(total*1000), client->name);
+ }
+}
+
+/*
+===============================================================================
+
+SERVER TRANSITIONS
+
+===============================================================================
+*/
+
+
+/*
+======================
+Host_Map_f
+
+handle a
+map <servername>
+command from the console. Active clients are kicked off.
+======================
+*/
+void Host_Map_f (void)
+{
+ int i;
+ char name[MAX_QPATH];
+
+ if (cmd_source != src_command)
+ return;
+
+ cls.demonum = -1; // stop demo loop in case this fails
+
+ CL_Disconnect ();
+ Host_ShutdownServer(false);
+
+ key_dest = key_game; // remove console or menu
+ SCR_BeginLoadingPlaque ();
+
+ cls.mapstring[0] = 0;
+ for (i=0 ; i<Cmd_Argc() ; i++)
+ {
+ strcat (cls.mapstring, Cmd_Argv(i));
+ strcat (cls.mapstring, " ");
+ }
+ strcat (cls.mapstring, "\n");
+
+ svs.serverflags = 0; // haven't completed an episode yet
+ strcpy (name, Cmd_Argv(1));
+#ifdef QUAKE2
+ SV_SpawnServer (name, NULL);
+#else
+ SV_SpawnServer (name);
+#endif
+ if (!sv.active)
+ return;
+
+ if (cls.state != ca_dedicated)
+ {
+ strcpy (cls.spawnparms, "");
+
+ for (i=2 ; i<Cmd_Argc() ; i++)
+ {
+ strcat (cls.spawnparms, Cmd_Argv(i));
+ strcat (cls.spawnparms, " ");
+ }
+
+ Cmd_ExecuteString ("connect local", src_command);
+ }
+}
+
+/*
+==================
+Host_Changelevel_f
+
+Goes to a new map, taking all clients along
+==================
+*/
+void Host_Changelevel_f (void)
+{
+#ifdef QUAKE2
+ char level[MAX_QPATH];
+ char _startspot[MAX_QPATH];
+ char *startspot;
+
+ if (Cmd_Argc() < 2)
+ {
+ Con_Printf ("changelevel <levelname> : continue game on a new level\n");
+ return;
+ }
+ if (!sv.active || cls.demoplayback)
+ {
+ Con_Printf ("Only the server may changelevel\n");
+ return;
+ }
+
+ strcpy (level, Cmd_Argv(1));
+ if (Cmd_Argc() == 2)
+ startspot = NULL;
+ else
+ {
+ strcpy (_startspot, Cmd_Argv(2));
+ startspot = _startspot;
+ }
+
+ SV_SaveSpawnparms ();
+ SV_SpawnServer (level, startspot);
+#else
+ char level[MAX_QPATH];
+
+ if (Cmd_Argc() != 2)
+ {
+ Con_Printf ("changelevel <levelname> : continue game on a new level\n");
+ return;
+ }
+ if (!sv.active || cls.demoplayback)
+ {
+ Con_Printf ("Only the server may changelevel\n");
+ return;
+ }
+ SV_SaveSpawnparms ();
+ strcpy (level, Cmd_Argv(1));
+ SV_SpawnServer (level);
+#endif
+}
+
+/*
+==================
+Host_Restart_f
+
+Restarts the current server for a dead player
+==================
+*/
+void Host_Restart_f (void)
+{
+ char mapname[MAX_QPATH];
+#ifdef QUAKE2
+ char startspot[MAX_QPATH];
+#endif
+
+ if (cls.demoplayback || !sv.active)
+ return;
+
+ if (cmd_source != src_command)
+ return;
+ strcpy (mapname, sv.name); // must copy out, because it gets cleared
+ // in sv_spawnserver
+#ifdef QUAKE2
+ strcpy(startspot, sv.startspot);
+ SV_SpawnServer (mapname, startspot);
+#else
+ SV_SpawnServer (mapname);
+#endif
+}
+
+/*
+==================
+Host_Reconnect_f
+
+This command causes the client to wait for the signon messages again.
+This is sent just before a server changes levels
+==================
+*/
+void Host_Reconnect_f (void)
+{
+ SCR_BeginLoadingPlaque ();
+ cls.signon = 0; // need new connection messages
+}
+
+/*
+=====================
+Host_Connect_f
+
+User command to connect to server
+=====================
+*/
+void Host_Connect_f (void)
+{
+ char name[MAX_QPATH];
+
+ cls.demonum = -1; // stop demo loop in case this fails
+ if (cls.demoplayback)
+ {
+ CL_StopPlayback ();
+ CL_Disconnect ();
+ }
+ strcpy (name, Cmd_Argv(1));
+ CL_EstablishConnection (name);
+ Host_Reconnect_f ();
+}
+
+
+/*
+===============================================================================
+
+LOAD / SAVE GAME
+
+===============================================================================
+*/
+
+#define SAVEGAME_VERSION 5
+
+/*
+===============
+Host_SavegameComment
+
+Writes a SAVEGAME_COMMENT_LENGTH character comment describing the current
+===============
+*/
+void Host_SavegameComment (char *text)
+{
+ int i;
+ char kills[20];
+
+ for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
+ text[i] = ' ';
+ memcpy (text, cl.levelname, strlen(cl.levelname));
+ sprintf (kills,"kills:%3i/%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
+ memcpy (text+22, kills, strlen(kills));
+// convert space to _ to make stdio happy
+ for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
+ if (text[i] == ' ')
+ text[i] = '_';
+ text[SAVEGAME_COMMENT_LENGTH] = '\0';
+}
+
+
+/*
+===============
+Host_Savegame_f
+===============
+*/
+void Host_Savegame_f (void)
+{
+ char name[256];
+ FILE *f;
+ int i;
+ char comment[SAVEGAME_COMMENT_LENGTH+1];
+
+ if (cmd_source != src_command)
+ return;
+
+ if (!sv.active)
+ {
+ Con_Printf ("Not playing a local game.\n");
+ return;
+ }
+
+ if (cl.intermission)
+ {
+ Con_Printf ("Can't save in intermission.\n");
+ return;
+ }
+
+ if (svs.maxclients != 1)
+ {
+ Con_Printf ("Can't save multiplayer games.\n");
+ return;
+ }
+
+ if (Cmd_Argc() != 2)
+ {
+ Con_Printf ("save <savename> : save a game\n");
+ return;
+ }
+
+ if (strstr(Cmd_Argv(1), ".."))
+ {
+ Con_Printf ("Relative pathnames are not allowed.\n");
+ return;
+ }
+
+ for (i=0 ; i<svs.maxclients ; i++)
+ {
+ if (svs.clients[i].active && (svs.clients[i].edict->v.health <= 0) )
+ {
+ Con_Printf ("Can't savegame with a dead player\n");
+ return;
+ }
+ }
+
+ sprintf (name, "%s/%s", com_gamedir, Cmd_Argv(1));
+ COM_DefaultExtension (name, ".sav");
+
+ Con_Printf ("Saving game to %s...\n", name);
+ f = fopen (name, "w");
+ if (!f)
+ {
+ Con_Printf ("ERROR: couldn't open.\n");
+ return;
+ }
+
+ fprintf (f, "%i\n", SAVEGAME_VERSION);
+ Host_SavegameComment (comment);
+ fprintf (f, "%s\n", comment);
+ for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
+ fprintf (f, "%f\n", svs.clients->spawn_parms[i]);
+ fprintf (f, "%d\n", current_skill);
+ fprintf (f, "%s\n", sv.name);
+ fprintf (f, "%f\n",sv.time);
+
+// write the light styles
+
+ for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
+ {
+ if (sv.lightstyles[i])
+ fprintf (f, "%s\n", sv.lightstyles[i]);
+ else
+ fprintf (f,"m\n");
+ }
+
+
+ ED_WriteGlobals (f);
+ for (i=0 ; i<sv.num_edicts ; i++)
+ {
+ ED_Write (f, EDICT_NUM(i));
+ fflush (f);
+ }
+ fclose (f);
+ Con_Printf ("done.\n");
+}
+
+
+/*
+===============
+Host_Loadgame_f
+===============
+*/
+void Host_Loadgame_f (void)
+{
+ char name[MAX_OSPATH];
+ FILE *f;
+ char mapname[MAX_QPATH];
+ float time, tfloat;
+ char str[32768], *start;
+ int i, r;
+ edict_t *ent;
+ int entnum;
+ int version;
+ float spawn_parms[NUM_SPAWN_PARMS];
+
+ if (cmd_source != src_command)
+ return;
+
+ if (Cmd_Argc() != 2)
+ {
+ Con_Printf ("load <savename> : load a game\n");
+ return;
+ }
+
+ cls.demonum = -1; // stop demo loop in case this fails
+
+ sprintf (name, "%s/%s", com_gamedir, Cmd_Argv(1));
+ COM_DefaultExtension (name, ".sav");
+
+// we can't call SCR_BeginLoadingPlaque, because too much stack space has
+// been used. The menu calls it before stuffing loadgame command
+// SCR_BeginLoadingPlaque ();
+
+ Con_Printf ("Loading game from %s...\n", name);
+ f = fopen (name, "r");
+ if (!f)
+ {
+ Con_Printf ("ERROR: couldn't open.\n");
+ return;
+ }
+
+ fscanf (f, "%i\n", &version);
+ if (version != SAVEGAME_VERSION)
+ {
+ fclose (f);
+ Con_Printf ("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
+ return;
+ }
+ fscanf (f, "%s\n", str);
+ for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
+ fscanf (f, "%f\n", &spawn_parms[i]);
+// this silliness is so we can load 1.06 save files, which have float skill values
+ fscanf (f, "%f\n", &tfloat);
+ current_skill = (int)(tfloat + 0.1);
+ Cvar_SetValue ("skill", (float)current_skill);
+
+#ifdef QUAKE2
+ Cvar_SetValue ("deathmatch", 0);
+ Cvar_SetValue ("coop", 0);
+ Cvar_SetValue ("teamplay", 0);
+#endif
+
+ fscanf (f, "%s\n",mapname);
+ fscanf (f, "%f\n",&time);
+
+ CL_Disconnect_f ();
+
+#ifdef QUAKE2
+ SV_SpawnServer (mapname, NULL);
+#else
+ SV_SpawnServer (mapname);
+#endif
+ if (!sv.active)
+ {
+ Con_Printf ("Couldn't load map\n");
+ return;
+ }
+ sv.paused = true; // pause until all clients connect
+ sv.loadgame = true;
+
+// load the light styles
+
+ for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
+ {
+ fscanf (f, "%s\n", str