diff options
Diffstat (limited to 'src/qcommon')
-rw-r--r-- | src/qcommon/common.c | 310 | ||||
-rw-r--r-- | src/qcommon/files.c | 92 | ||||
-rw-r--r-- | src/qcommon/md4.c | 5 | ||||
-rw-r--r-- | src/qcommon/q_shared.h | 5 | ||||
-rw-r--r-- | src/qcommon/qcommon.h | 4 |
5 files changed, 18 insertions, 398 deletions
diff --git a/src/qcommon/common.c b/src/qcommon/common.c index 231f4aa8..b0cee0d3 100644 --- a/src/qcommon/common.c +++ b/src/qcommon/common.c @@ -2714,316 +2714,6 @@ void Com_Shutdown (void) { } -#if I_WANT_A_CUSTOM_MEMCPY && !defined(_WIN32) -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); -} - -#elif I_WANT_A_CUSTOM_MEMCPY && defined(_WIN32) - -typedef enum -{ - PRE_READ, // prefetch assuming that buffer is used for reading only - PRE_WRITE, // prefetch assuming that buffer is used for writing only - PRE_READ_WRITE // prefetch assuming that buffer is used for both reading and writing -} e_prefetch; - -void Com_Prefetch (const void *s, const unsigned int bytes, e_prefetch type); - -#define EMMS_INSTRUCTION __asm emms - -void _copyDWord (unsigned int* dest, const unsigned int constant, const unsigned int count) { - __asm - { - mov edx,dest - mov eax,constant - mov ecx,count - and ecx,~7 - jz padding - sub ecx,8 - jmp loopu - align 16 -loopu: - test [edx+ecx*4 + 28],ebx // fetch next block destination to L1 cache - mov [edx+ecx*4 + 0],eax - mov [edx+ecx*4 + 4],eax - mov [edx+ecx*4 + 8],eax - mov [edx+ecx*4 + 12],eax - mov [edx+ecx*4 + 16],eax - mov [edx+ecx*4 + 20],eax - mov [edx+ecx*4 + 24],eax - mov [edx+ecx*4 + 28],eax - sub ecx,8 - jge loopu -padding: mov ecx,count - mov ebx,ecx - and ecx,7 - jz outta - and ebx,~7 - lea edx,[edx+ebx*4] // advance dest pointer - test [edx+0],eax // fetch destination to L1 cache - cmp ecx,4 - jl skip4 - mov [edx+0],eax - mov [edx+4],eax - mov [edx+8],eax - mov [edx+12],eax - add edx,16 - sub ecx,4 -skip4: cmp ecx,2 - jl skip2 - mov [edx+0],eax - mov [edx+4],eax - add edx,8 - sub ecx,2 -skip2: cmp ecx,1 - jl outta - mov [edx+0],eax -outta: - } -} - -// optimized memory copy routine that handles all alignment -// cases and block sizes efficiently -void Com_Memcpy (void* dest, const void* src, const size_t count) { - Com_Prefetch (src, count, PRE_READ); - __asm - { - push edi - push esi - mov ecx,count - cmp ecx,0 // count = 0 check (just to be on the safe side) - je outta - mov edx,dest - mov ebx,src - cmp ecx,32 // padding only? - jl padding - - mov edi,ecx - and edi,~31 // edi = count&~31 - sub edi,32 - - align 16 -loopMisAligned: - mov eax,[ebx + edi + 0 + 0*8] - mov esi,[ebx + edi + 4 + 0*8] - mov [edx+edi+0 + 0*8],eax - mov [edx+edi+4 + 0*8],esi - mov eax,[ebx + edi + 0 + 1*8] - mov esi,[ebx + edi + 4 + 1*8] - mov [edx+edi+0 + 1*8],eax - mov [edx+edi+4 + 1*8],esi - mov eax,[ebx + edi + 0 + 2*8] - mov esi,[ebx + edi + 4 + 2*8] - mov [edx+edi+0 + 2*8],eax - mov [edx+edi+4 + 2*8],esi - mov eax,[ebx + edi + 0 + 3*8] - mov esi,[ebx + edi + 4 + 3*8] - mov [edx+edi+0 + 3*8],eax - mov [edx+edi+4 + 3*8],esi - sub edi,32 - jge loopMisAligned - - mov edi,ecx - and edi,~31 - add ebx,edi // increase src pointer - add edx,edi // increase dst pointer - and ecx,31 // new count - jz outta // if count = 0, get outta here - -padding: - cmp ecx,16 - jl skip16 - mov eax,dword ptr [ebx] - mov dword ptr [edx],eax - mov eax,dword ptr [ebx+4] - mov dword ptr [edx+4],eax - mov eax,dword ptr [ebx+8] - mov dword ptr [edx+8],eax - mov eax,dword ptr [ebx+12] - mov dword ptr [edx+12],eax - sub ecx,16 - add ebx,16 - add edx,16 -skip16: - cmp ecx,8 - jl skip8 - mov eax,dword ptr [ebx] - mov dword ptr [edx],eax - mov eax,dword ptr [ebx+4] - sub ecx,8 - mov dword ptr [edx+4],eax - add ebx,8 - add edx,8 -skip8: - cmp ecx,4 - jl skip4 - mov eax,dword ptr [ebx] // here 4-7 bytes - add ebx,4 - sub ecx,4 - mov dword ptr [edx],eax - add edx,4 -skip4: // 0-3 remaining bytes - cmp ecx,2 - jl skip2 - mov ax,word ptr [ebx] // two bytes - cmp ecx,3 // less than 3? - mov word ptr [edx],ax - jl outta - mov al,byte ptr [ebx+2] // last byte - mov byte ptr [edx+2],al - jmp outta -skip2: - cmp ecx,1 - jl outta - mov al,byte ptr [ebx] - mov byte ptr [edx],al -outta: - pop esi - pop edi - } -} - -void Com_Memset (void* dest, const int val, const size_t count) -{ - unsigned int fillval; - - if (count < 8) - { - __asm - { - mov edx,dest - mov eax, val - mov ah,al - mov ebx,eax - and ebx, 0xffff - shl eax,16 - add eax,ebx // eax now contains pattern - mov ecx,count - cmp ecx,4 - jl skip4 - mov [edx],eax // copy first dword - add edx,4 - sub ecx,4 - skip4: cmp ecx,2 - jl skip2 - mov word ptr [edx],ax // copy 2 bytes - add edx,2 - sub ecx,2 - skip2: cmp ecx,0 - je skip1 - mov byte ptr [edx],al // copy single byte - skip1: - } - return; - } - - fillval = val; - - fillval = fillval|(fillval<<8); - fillval = fillval|(fillval<<16); // fill dword with 8-bit pattern - - _copyDWord ((unsigned int*)(dest),fillval, count/4); - - __asm // padding of 0-3 bytes - { - mov ecx,count - mov eax,ecx - and ecx,3 - jz skipA - and eax,~3 - mov ebx,dest - add ebx,eax - mov eax,fillval - cmp ecx,2 - jl skipB - mov word ptr [ebx],ax - cmp ecx,2 - je skipA - mov byte ptr [ebx+2],al - jmp skipA -skipB: - cmp ecx,0 - je skipA - mov byte ptr [ebx],al -skipA: - } -} - -qboolean Com_Memcmp (const void *src0, const void *src1, const unsigned int count) -{ - unsigned int i; - // MMX version anyone? - - if (count >= 16) - { - unsigned int *dw = (unsigned int*)(src0); - unsigned int *sw = (unsigned int*)(src1); - - unsigned int nm2 = count/16; - for (i = 0; i < nm2; i+=4) - { - unsigned int tmp = (dw[i+0]-sw[i+0])|(dw[i+1]-sw[i+1])| - (dw[i+2]-sw[i+2])|(dw[i+3]-sw[i+3]); - if (tmp) - return qfalse; - } - } - if (count & 15) - { - byte *d = (byte*)src0; - byte *s = (byte*)src1; - for (i = count & 0xfffffff0; i < count; i++) - if (d[i]!=s[i]) - return qfalse; - } - - return qtrue; -} - -void Com_Prefetch (const void *s, const unsigned int bytes, e_prefetch type) -{ - // write buffer prefetching is performed only if - // the processor benefits from it. Read and read/write - // prefetching is always performed. - - switch (type) - { - case PRE_WRITE : break; - case PRE_READ: - case PRE_READ_WRITE: - - __asm - { - mov ebx,s - mov ecx,bytes - cmp ecx,4096 // clamp to 4kB - jle skipClamp - mov ecx,4096 -skipClamp: - add ecx,0x1f - shr ecx,5 // number of cache lines - jz skip - jmp loopie - - align 16 - loopie: test byte ptr [ebx],al - add ebx,32 - dec ecx - jnz loopie - skip: - } - - break; - } -} -#endif //------------------------------------------------------------------------ diff --git a/src/qcommon/files.c b/src/qcommon/files.c index 1ea34cc6..4ebca39a 100644 --- a/src/qcommon/files.c +++ b/src/qcommon/files.c @@ -56,7 +56,7 @@ The "cd path" is the path to an alternate hierarchy that will be searched if a f is not located in the base path. A user can do a partial install that copies some data to a base path created on their hard drive and leave the rest on the cd. Files are never writen to the cd path. It defaults to a value set by the installer, like -"e:\quake3", but it can be overridden with "+set ds_cdpath g:\quake3". +"e:\quake3", but it can be overridden with "+set fs_cdpath g:\quake3". If a user runs the game directly from a CD, the base path would be on the CD. This should still function correctly, but all file writes will fail (harmlessly). @@ -201,7 +201,8 @@ or configs will never get loaded from disk! // every time a new demo pk3 file is built, this checksum must be updated. // the easiest way to get it is to just run the game and see what it spits out -#define DEMO_PAK_CHECKSUM 437558517u +#define DEMO_PAK0_CHECKSUM 2985612116u +#define PAK0_CHECKSUM 1566731103u // if this is defined, the executable positively won't work with any paks other // than the demo pak, even if productid is present. This is only used for our @@ -307,11 +308,6 @@ static char *fs_serverReferencedPakNames[MAX_SEARCH_PATHS]; // pk3 names char lastValidBase[MAX_OSPATH]; char lastValidGame[MAX_OSPATH]; -// productId: This file is copyright 1999 Id Software, and may not be duplicated except during a licensed installation of the full commercial version of Quake 3:Arena -static byte fs_scrambledProductId[152] = { -220, 129, 255, 108, 244, 163, 171, 55, 133, 65, 199, 36, 140, 222, 53, 99, 65, 171, 175, 232, 236, 193, 210, 250, 169, 104, 231, 231, 21, 201, 170, 208, 135, 175, 130, 136, 85, 215, 71, 23, 96, 32, 96, 83, 44, 240, 219, 138, 184, 215, 73, 27, 196, 247, 55, 139, 148, 68, 78, 203, 213, 238, 139, 23, 45, 205, 118, 186, 236, 230, 231, 107, 212, 1, 10, 98, 30, 20, 116, 180, 216, 248, 166, 35, 45, 22, 215, 229, 35, 116, 250, 167, 117, 3, 57, 55, 201, 229, 218, 222, 128, 12, 141, 149, 32, 110, 168, 215, 184, 53, 31, 147, 62, 12, 138, 67, 132, 54, 125, 6, 221, 148, 140, 4, 21, 44, 198, 3, 126, 12, 100, 236, 61, 42, 44, 251, 15, 135, 14, 134, 89, 92, 177, 246, 152, 106, 124, 78, 118, 80, 28, 42 -}; - #ifdef FS_MISSING FILE* missingFiles = NULL; #endif @@ -566,11 +562,22 @@ FS_Remove =========== */ -static void FS_Remove( const char *osPath ) { +void FS_Remove( const char *osPath ) { remove( osPath ); } /* +=========== +FS_HomeRemove + +=========== +*/ +void FS_HomeRemove( const char *homePath ) { + remove( FS_BuildOSPath( fs_homepath->string, + fs_gamedir, homePath ) ); +} + +/* ================ FS_FileExists @@ -2829,69 +2836,6 @@ static void FS_Startup( const char *gameName ) { Com_Printf( "%d files in pk3 files\n", fs_packFiles ); } - -/* -=================== -FS_SetRestrictions - -Looks for product keys and restricts media add on ability -if the full version is not found -=================== -*/ -static void FS_SetRestrictions( void ) { - searchpath_t *path; - char *productId; - - return; - -#ifndef PRE_RELEASE_DEMO - - // if fs_restrict is set, don't even look for the id file, - // which allows the demo release to be tested even if - // the full game is present - if ( !fs_restrict->integer ) { - // look for the full game id - FS_ReadFile( "productid.txt", (void **)&productId ); - if ( productId ) { - // check against the hardcoded string - int seed, i; - - seed = 5000; - for ( i = 0 ; i < sizeof( fs_scrambledProductId ) ; i++ ) { - if ( ( fs_scrambledProductId[i] ^ (seed&255) ) != productId[i] ) { - break; - } - seed = (69069 * seed + 1); - } - - FS_FreeFile( productId ); - - if ( i == sizeof( fs_scrambledProductId ) ) { - return; // no restrictions - } - Com_Error( ERR_FATAL, "Invalid product identification" ); - } - } -#endif - Cvar_Set( "fs_restrict", "1" ); - - Com_Printf( "\nRunning in restricted demo mode.\n\n" ); - - // restart the filesystem with just the demo directory - FS_Shutdown(qfalse); - FS_Startup( DEMOGAME ); - - // make sure that the pak file has the header checksum we expect - for ( path = fs_searchpaths ; path ; path = path->next ) { - if ( path->pack ) { - // a tiny attempt to keep the checksum from being scannable from the exe - if ( (path->pack->checksum ^ 0x02261994u) != (DEMO_PAK_CHECKSUM ^ 0x02261994u) ) { - Com_Error( ERR_FATAL, "Corrupted pak0.pk3: %u", path->pack->checksum ); - } - } - } -} - /* ===================== FS_GamePureChecksum @@ -3259,9 +3203,6 @@ void FS_InitFilesystem( void ) { // try to start up normally FS_Startup( BASEGAME ); - // see if we are going to allow add-ons - FS_SetRestrictions(); - // if we can't find default.cfg, assume that the paths are // busted and error out now, rather than getting an unreadable // graphics screen when the font fails to load @@ -3296,9 +3237,6 @@ void FS_Restart( int checksumFeed ) { // try to start up normally FS_Startup( BASEGAME ); - // see if we are going to allow add-ons - FS_SetRestrictions(); - // if we can't find default.cfg, assume that the paths are // busted and error out now, rather than getting an unreadable // graphics screen when the font fails to load diff --git a/src/qcommon/md4.c b/src/qcommon/md4.c index 24b79610..82c4b0d8 100644 --- a/src/qcommon/md4.c +++ b/src/qcommon/md4.c @@ -38,13 +38,8 @@ void MD4Init (MD4_CTX *); void MD4Update (MD4_CTX *, const unsigned char *, unsigned int); void MD4Final (unsigned char [16], MD4_CTX *); -#if I_WANT_A_CUSTOM_MEMCPY -void Com_Memset (void* dest, const int val, const size_t count); -void Com_Memcpy (void* dest, const void* src, const size_t count); -#else #define Com_Memset memset #define Com_Memcpy memcpy -#endif /* MD4C.C - RSA Data Security, Inc., MD4 message-digest algorithm */ /* Copyright (C) 1990-2, RSA Data Security, Inc. All rights reserved. diff --git a/src/qcommon/q_shared.h b/src/qcommon/q_shared.h index 53848aa4..537dee36 100644 --- a/src/qcommon/q_shared.h +++ b/src/qcommon/q_shared.h @@ -243,13 +243,8 @@ void Snd_Memset (void* dest, const int val, const size_t count); #define Snd_Memset Com_Memset #endif -#if I_WANT_A_CUSTOM_MEMCPY -void Com_Memset (void* dest, const int val, const size_t count); -void Com_Memcpy (void* dest, const void* src, const size_t count); -#else #define Com_Memset memset #define Com_Memcpy memcpy -#endif #define CIN_system 1 #define CIN_loop 2 diff --git a/src/qcommon/qcommon.h b/src/qcommon/qcommon.h index 843f04ef..9e9ca513 100644 --- a/src/qcommon/qcommon.h +++ b/src/qcommon/qcommon.h @@ -651,6 +651,9 @@ qboolean FS_ComparePaks( char *neededpaks, int len, qboolean dlstring ); void FS_Rename( const char *from, const char *to ); +void FS_Remove( const char *osPath ); +void FS_HomeRemove( const char *homePath ); + /* ============================================================== @@ -892,7 +895,6 @@ void S_ClearSoundBuffer( void ); void SCR_DebugGraph (float value, int color); // FIXME: move logging to common? - // // server interface // |