ref: f21a753a80c4034db22926835af88117e021eff0
parent: a1e3f3526b7ec899b58e9f4e2e1662ea254e5805
author: qwx <>
date: Sat Jan 12 18:25:05 EST 2019
add most missing functions
--- a/code/mkfile
+++ b/code/mkfile
@@ -35,7 +35,6 @@
game/q_shared.$O\
unix/qk3ded.$O\
unix/sys.$O\
- unix/linux_common.$O\
unix/unix_net.$O\
unix/unix_shared.$O\
--- a/code/qcommon/vm_x86.c
+++ b/code/qcommon/vm_x86.c
@@ -21,15 +21,8 @@
*/
// vm_x86.c -- load time compiler and execution environment for x86
-#include "vm_local.h"
-
-#ifdef __FreeBSD__ // rb0101023
-#include <sys/types.h>
-#endif
-
-#ifndef _WIN32
-#include <sys/mman.h> // for PROT_ stuff
-#endif
+#include "../game/q_shared.h"
+#include "qcommon.h"
/*
--- a/code/unix/linux_common.c
+++ /dev/null
@@ -1,41 +1,0 @@
-/*
-===========================================================================
-Copyright (C) 1999-2005 Id Software, Inc.
-
-This file is part of Quake III Arena source code.
-
-Quake III Arena source code 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.
-
-Quake III Arena source code 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 Foobar; if not, write to the Free Software
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-===========================================================================
-*/
-/**
- * GAS syntax equivalents of the MSVC asm memory calls in common.c
- *
- * The following changes have been made to the asm:
- * 1. Registers are loaded by the inline asm arguments when possible
- * 2. Labels have been changed to local label format (0,1,etc.) to allow inlining
- *
- * HISTORY:
- * AH - Created on 08 Dec 2000
- */
-
-#include "../game/q_shared.h"
-
-void Com_Memcpy (void* dest, const void* src, const size_t count) {
- memcpy(dest, src, count);
-}
-
-void Com_Memset (void* dest, const int val, const size_t count) {
- memset(dest, val, count);
-}
--- a/code/unix/snapvector.nasm
+++ /dev/null
@@ -1,95 +1,0 @@
-;===========================================================================
-;Copyright (C) 1999-2005 Id Software, Inc.
-;
-;This file is part of Quake III Arena source code.
-;
-;Quake III Arena source code 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.
-;
-;Quake III Arena source code 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 Foobar; if not, write to the Free Software
-;Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-;===========================================================================
-
-;
-; Sys_SnapVector NASM code (Andrew Henderson)
-; See win32/win_shared.c for the Win32 equivalent
-; This code is provided to ensure that the
-; rounding behavior (and, if necessary, the
-; precision) of DLL and QVM code are identical
-; e.g. for network-visible operations.
-; See ftol.nasm for operations on a single float,
-; as used in compiled VM and DLL code that does
-; not use this system trap.
-;
-
-
-segment .data
-
-fpucw dd 0
-cw037F dd 0x037F ; Rounding to nearest (even).
-
-segment .text
-
-; void Sys_SnapVector( float *v )
-global Sys_SnapVector
-Sys_SnapVector:
- push eax
- push ebp
- mov ebp, esp
-
- fnstcw [fpucw]
- mov eax, dword [ebp + 12]
- fldcw [cw037F]
- fld dword [eax]
- fistp dword [eax]
- fild dword [eax]
- fstp dword [eax]
- fld dword [eax + 4]
- fistp dword [eax + 4]
- fild dword [eax + 4]
- fstp dword [eax + 4]
- fld dword [eax + 8]
- fistp dword [eax + 8]
- fild dword [eax + 8]
- fstp dword [eax + 8]
- fldcw [fpucw]
-
- pop ebp
- pop eax
- ret
-
-; void Sys_SnapVectorCW( float *v, unsigned short int cw )
-global Sys_SnapVectorCW
-Sys_SnapVector_cw:
- push eax
- push ebp
- mov ebp, esp
-
- fnstcw [fpucw]
- mov eax, dword [ebp + 12]
- fldcw [ebp + 16]
- fld dword [eax]
- fistp dword [eax]
- fild dword [eax]
- fstp dword [eax]
- fld dword [eax + 4]
- fistp dword [eax + 4]
- fild dword [eax + 4]
- fstp dword [eax + 4]
- fld dword [eax + 8]
- fistp dword [eax + 8]
- fild dword [eax + 8]
- fstp dword [eax + 8]
- fldcw [fpucw]
-
- pop ebp
- pop eax
- ret
\ No newline at end of file
--- a/code/unix/sys.c
+++ b/code/unix/sys.c
@@ -1,5 +1,105 @@
#include "../game/q_shared.h"
#include "../qcommon/qcommon.h"
+#include "linux_local.h"
+
+#include <thread.h>
+
+void
+Sys_SnapVector(float *v)
+{
+ ulong fcr;
+
+ fcr = getfcr();
+ setfcr(fcr & ~FPRMASK | FPRNR);
+ v[0] = (long)v[0];
+ v[1] = (long)v[1];
+ v[2] = (long)v[2];
+ setfcr(fcr);
+}
+
+void
+Sys_UnloadDll(void *)
+{
+}
+
+void *
+Sys_LoadDll(char *, char *, int (**)(int, ...), int (*)(int, ...))
+{
+ sysfatal("Sys_LoadDll: NOPE");
+ return nil;
+}
+
+qboolean
+Sys_CheckCD(void)
+{
+ return qtrue;
+}
+
+void
+Sys_InitStreamThread(void)
+{
+}
+
+void
+Sys_ShutdownStreamThread(void)
+{
+}
+
+void
+Sys_BeginStreamedFile(fileHandle_t, int)
+{
+}
+
+void
+Sys_EndStreamedFile(fileHandle_t)
+{
+}
+
+int
+Sys_StreamedRead(void *buffer, int size, int count, fileHandle_t f)
+{
+ return FS_Read(buffer, size * count, f);
+}
+
+void Sys_StreamSeek(fileHandle_t f, int offset, int origin)
+{
+ FS_Seek(f, offset, origin);
+}
+
+void
+Sys_Error(char *error, ...)
+{
+ va_list argptr;
+ char string[1024];
+
+ CL_Shutdown();
+ va_start(argptr, error);
+ vsprintf(string, error, argptr);
+ va_end(argptr);
+ fprint(2, "Sys_Error: %s\n", string);
+ sysfatal(string);
+}
+
+void
+Sys_Quit(void)
+{
+ CL_Shutdown();
+ threadexitsall(nil);
+}
+
+void
+Sys_Init(void)
+{
+ Cvar_Set("arch", "plan 9");
+ Cvar_Set("username", Sys_GetCurrentUser());
+ IN_Init();
+}
+
+void
+Sys_Print(char *s)
+{
+ write(2, s, strlen(s));
+}
int
Sys_Milliseconds(void)
--- a/code/unix/unix_main.c
+++ b/code/unix/unix_main.c
@@ -111,19 +111,6 @@
void Sys_BeginProfiling( void ) {
}
-/*
-=================
-Sys_In_Restart_f
-
-Restart the input subsystem
-=================
-*/
-void Sys_In_Restart_f( void )
-{
- IN_Shutdown();
- IN_Init();
-}
-
// =============================================================
// tty console routines
// NOTE: if the user is editing a line when something gets printed to the early console then it won't look good
@@ -261,130 +248,7 @@
// general sys routines
// =============================================================
-#if 0
-// NOTE TTimo this is not used .. looks interesting though? protection against buffer overflow kind of stuff?
-void Sys_Printf (char *fmt, ...)
-{
- va_list argptr;
- char text[1024];
- unsigned char *p;
- va_start (argptr,fmt);
- vsprintf (text,fmt,argptr);
- va_end (argptr);
-
- if (strlen(text) > sizeof(text))
- Sys_Error("memory overwrite in Sys_Printf");
-
- for (p = (unsigned char *)text; *p; p++)
- {
- *p &= 0x7f;
- if ((*p > 128 || *p < 32) && *p != 10 && *p != 13 && *p != 9)
- printf("[%02x]", *p);
- else
- putc(*p, stdout);
- }
-}
-#endif
-
-// single exit point (regular exit or in case of signal fault)
-void Sys_Exit( int ex ) {
- Sys_ConsoleInputShutdown();
-
-#ifdef NDEBUG // regular behavior
-
- // We can't do this
- // as long as GL DLL's keep installing with atexit...
- //exit(ex);
- _exit(ex);
-#else
-
- // Give me a backtrace on error exits.
- assert( ex == 0 );
- exit(ex);
-#endif
-}
-
-
-void Sys_Quit (void) {
- CL_Shutdown ();
- fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
- Sys_Exit(0);
-}
-
-void Sys_Init(void)
-{
- Cmd_AddCommand ("in_restart", Sys_In_Restart_f);
-
-#if defined __linux__
-#if defined __i386__
- Cvar_Set( "arch", "linux i386" );
-#elif defined __alpha__
- Cvar_Set( "arch", "linux alpha" );
-#elif defined __sparc__
- Cvar_Set( "arch", "linux sparc" );
-#elif defined __FreeBSD__
-
-#if defined __i386__ // FreeBSD
- Cvar_Set( "arch", "freebsd i386" );
-#elif defined __alpha__
- Cvar_Set( "arch", "freebsd alpha" );
-#else
- Cvar_Set( "arch", "freebsd unknown" );
-#endif // FreeBSD
-
-#else
- Cvar_Set( "arch", "linux unknown" );
-#endif
-#elif defined __sun__
-#if defined __i386__
- Cvar_Set( "arch", "solaris x86" );
-#elif defined __sparc__
- Cvar_Set( "arch", "solaris sparc" );
-#else
- Cvar_Set( "arch", "solaris unknown" );
-#endif
-#elif defined __sgi__
-#if defined __mips__
- Cvar_Set( "arch", "sgi mips" );
-#else
- Cvar_Set( "arch", "sgi unknown" );
-#endif
-#else
- Cvar_Set( "arch", "unknown" );
-#endif
-
- Cvar_Set( "username", Sys_GetCurrentUser() );
-
- IN_Init();
-
-}
-
-void Sys_Error( const char *error, ...)
-{
- va_list argptr;
- char string[1024];
-
- // change stdin to non blocking
- // NOTE TTimo not sure how well that goes with tty console mode
- fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);
-
- // don't bother do a show on this one heh
- if (ttycon_on)
- {
- tty_Hide();
- }
-
- CL_Shutdown ();
-
- va_start (argptr,error);
- vsprintf (string,error,argptr);
- va_end (argptr);
- fprintf(stderr, "Sys_Error: %s\n", string);
-
- Sys_Exit( 1 ); // bk010104 - use single exit point.
-}
-
void Sys_Warn (char *warning, ...)
{
va_list argptr;
@@ -770,212 +634,6 @@
if ( libHandle ) Q_strncpyz ( fqpath , fn , MAX_QPATH ) ; // added 7/20/02 by T.Ray
return libHandle;
}
-
-/*
-========================================================================
-
-BACKGROUND FILE STREAMING
-
-========================================================================
-*/
-
-#if 1
-
-void Sys_InitStreamThread( void ) {
-}
-
-void Sys_ShutdownStreamThread( void ) {
-}
-
-void Sys_BeginStreamedFile( fileHandle_t f, int readAhead ) {
-}
-
-void Sys_EndStreamedFile( fileHandle_t f ) {
-}
-
-int Sys_StreamedRead( void *buffer, int size, int count, fileHandle_t f ) {
- return FS_Read( buffer, size * count, f );
-}
-
-void Sys_StreamSeek( fileHandle_t f, int offset, int origin ) {
- FS_Seek( f, offset, origin );
-}
-
-#else
-
-typedef struct
-{
- fileHandle_t file;
- byte *buffer;
- qboolean eof;
- int bufferSize;
- int streamPosition; // next byte to be returned by Sys_StreamRead
- int threadPosition; // next byte to be read from file
-} streamState_t;
-
-streamState_t stream;
-
-/*
-===============
-Sys_StreamThread
-
-A thread will be sitting in this loop forever
-================
-*/
-void Sys_StreamThread( void )
-{
- int buffer;
- int count;
- int readCount;
- int bufferPoint;
- int r;
-
- // if there is any space left in the buffer, fill it up
- if ( !stream.eof )
- {
- count = stream.bufferSize - (stream.threadPosition - stream.streamPosition);
- if ( count )
- {
- bufferPoint = stream.threadPosition % stream.bufferSize;
- buffer = stream.bufferSize - bufferPoint;
- readCount = buffer < count ? buffer : count;
- r = FS_Read ( stream.buffer + bufferPoint, readCount, stream.file );
- stream.threadPosition += r;
-
- if ( r != readCount )
- stream.eof = qtrue;
- }
- }
-}
-
-/*
-===============
-Sys_InitStreamThread
-
-================
-*/
-void Sys_InitStreamThread( void )
-{
-}
-
-/*
-===============
-Sys_ShutdownStreamThread
-
-================
-*/
-void Sys_ShutdownStreamThread( void )
-{
-}
-
-
-/*
-===============
-Sys_BeginStreamedFile
-
-================
-*/
-void Sys_BeginStreamedFile( fileHandle_t f, int readAhead )
-{
- if ( stream.file )
- {
- Com_Error( ERR_FATAL, "Sys_BeginStreamedFile: unclosed stream");
- }
-
- stream.file = f;
- stream.buffer = Z_Malloc( readAhead );
- stream.bufferSize = readAhead;
- stream.streamPosition = 0;
- stream.threadPosition = 0;
- stream.eof = qfalse;
-}
-
-/*
-===============
-Sys_EndStreamedFile
-
-================
-*/
-void Sys_EndStreamedFile( fileHandle_t f )
-{
- if ( f != stream.file )
- {
- Com_Error( ERR_FATAL, "Sys_EndStreamedFile: wrong file");
- }
-
- stream.file = 0;
- Z_Free( stream.buffer );
-}
-
-
-/*
-===============
-Sys_StreamedRead
-
-================
-*/
-int Sys_StreamedRead( void *buffer, int size, int count, fileHandle_t f )
-{
- int available;
- int remaining;
- int sleepCount;
- int copy;
- int bufferCount;
- int bufferPoint;
- byte *dest;
-
- dest = (byte *)buffer;
- remaining = size * count;
-
- if ( remaining <= 0 )
- {
- Com_Error( ERR_FATAL, "Streamed read with non-positive size" );
- }
-
- sleepCount = 0;
- while ( remaining > 0 )
- {
- available = stream.threadPosition - stream.streamPosition;
- if ( !available )
- {
- if (stream.eof)
- break;
- Sys_StreamThread();
- continue;
- }
-
- bufferPoint = stream.streamPosition % stream.bufferSize;
- bufferCount = stream.bufferSize - bufferPoint;
-
- copy = available < bufferCount ? available : bufferCount;
- if ( copy > remaining )
- {
- copy = remaining;
- }
- memcpy( dest, stream.buffer + bufferPoint, copy );
- stream.streamPosition += copy;
- dest += copy;
- remaining -= copy;
- }
-
- return(count * size - remaining) / size;
-}
-
-/*
-===============
-Sys_StreamSeek
-
-================
-*/
-void Sys_StreamSeek( fileHandle_t f, int offset, int origin ) {
- // clear to that point
- FS_Seek( f, offset, origin );
- stream.streamPosition = 0;
- stream.threadPosition = 0;
- stream.eof = qfalse;
-}
-
-#endif
/*
========================================================================