diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt index 45b50f89..9854ae45 100644 --- a/neo/CMakeLists.txt +++ b/neo/CMakeLists.txt @@ -1008,7 +1008,7 @@ if(MSVC) ) else() - include_directories(libs/sdl/include) + include_directories(libs/sdl2/include) link_directories(${CMAKE_CURRENT_SOURCE_DIR}/libs/sdl2/libmingw32) list(APPEND RBDOOM3_SOURCES diff --git a/neo/sys/sdl/sdl_cpu.cpp b/neo/sys/sdl/sdl_cpu.cpp index 5ec0e654..78af9ffa 100644 --- a/neo/sys/sdl/sdl_cpu.cpp +++ b/neo/sys/sdl/sdl_cpu.cpp @@ -2,10 +2,10 @@ =========================================================================== Doom 3 BFG Edition GPL Source Code -Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. +Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. Copyright (C) 2012 Robert Beckebans -This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). +This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). Doom 3 BFG Edition 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 @@ -31,7 +31,7 @@ If you have questions concerning this license or the applicable additional terms #pragma hdrstop #include "../../idlib/precompiled.h" -#include "win_local.h" +//#include "win_local.h" #pragma warning(disable:4740) // warning C4740: flow in or out of inline asm code suppresses global optimization #pragma warning(disable:4731) // warning C4731: 'XXX' : frame pointer register 'ebx' modified by inline assembly code @@ -49,13 +49,14 @@ If you have questions concerning this license or the applicable additional terms Sys_GetClockTicks ================ */ -double Sys_GetClockTicks() { - +double Sys_GetClockTicks() +{ // RB begin #if defined(_MSC_VER) unsigned long lo, hi; - - __asm { + + __asm + { push ebx xor eax, eax cpuid @@ -64,11 +65,11 @@ double Sys_GetClockTicks() { mov hi, edx pop ebx } - return (double ) lo + (double) 0xFFFFFFFF * hi; - + return ( double ) lo + ( double ) 0xFFFFFFFF * hi; + #elif defined(__GNUC__) && defined( __i386__ ) unsigned long lo, hi; - + __asm__ __volatile__( "push %%ebx\n" \ "xor %%eax,%%eax\n" \ @@ -83,8 +84,6 @@ double Sys_GetClockTicks() { #error unsupported CPU #endif // RB end - -#endif } /* @@ -92,41 +91,48 @@ double Sys_GetClockTicks() { Sys_ClockTicksPerSecond ================ */ -double Sys_ClockTicksPerSecond() { +double Sys_ClockTicksPerSecond() +{ static double ticks = 0; #if 0 - - if ( !ticks ) { + + if( !ticks ) + { LARGE_INTEGER li; QueryPerformanceFrequency( &li ); ticks = li.QuadPart; } - + #else - - if ( !ticks ) { + + if( !ticks ) + { HKEY hKey; LPBYTE ProcSpeed; DWORD buflen, ret; - - if ( !RegOpenKeyEx( HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_READ, &hKey ) ) { + + if( !RegOpenKeyEx( HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_READ, &hKey ) ) + { ProcSpeed = 0; buflen = sizeof( ProcSpeed ); - ret = RegQueryValueEx( hKey, "~MHz", NULL, NULL, (LPBYTE) &ProcSpeed, &buflen ); + ret = RegQueryValueEx( hKey, "~MHz", NULL, NULL, ( LPBYTE ) &ProcSpeed, &buflen ); // If we don't succeed, try some other spellings. - if ( ret != ERROR_SUCCESS ) { - ret = RegQueryValueEx( hKey, "~Mhz", NULL, NULL, (LPBYTE) &ProcSpeed, &buflen ); + if( ret != ERROR_SUCCESS ) + { + ret = RegQueryValueEx( hKey, "~Mhz", NULL, NULL, ( LPBYTE ) &ProcSpeed, &buflen ); } - if ( ret != ERROR_SUCCESS ) { - ret = RegQueryValueEx( hKey, "~mhz", NULL, NULL, (LPBYTE) &ProcSpeed, &buflen ); + if( ret != ERROR_SUCCESS ) + { + ret = RegQueryValueEx( hKey, "~mhz", NULL, NULL, ( LPBYTE ) &ProcSpeed, &buflen ); } RegCloseKey( hKey ); - if ( ret == ERROR_SUCCESS ) { - ticks = (double) ((unsigned long)ProcSpeed) * 1000000; + if( ret == ERROR_SUCCESS ) + { + ticks = ( double )( ( unsigned long )ProcSpeed ) * 1000000; } } } - + #endif return ticks; } @@ -140,562 +146,7 @@ double Sys_ClockTicksPerSecond() { ============================================================== */ -/* -================ -HasCPUID -================ -*/ -static bool HasCPUID() { - __asm - { - pushfd // save eflags - pop eax - test eax, 0x00200000 // check ID bit - jz set21 // bit 21 is not set, so jump to set_21 - and eax, 0xffdfffff // clear bit 21 - push eax // save new value in register - popfd // store new value in flags - pushfd - pop eax - test eax, 0x00200000 // check ID bit - jz good - jmp err // cpuid not supported -set21: - or eax, 0x00200000 // set ID bit - push eax // store new value - popfd // store new value in EFLAGS - pushfd - pop eax - test eax, 0x00200000 // if bit 21 is on - jnz good - jmp err - } -err: - return false; -good: - return true; -} - -#define _REG_EAX 0 -#define _REG_EBX 1 -#define _REG_ECX 2 -#define _REG_EDX 3 - -/* -================ -CPUID -================ -*/ -static void CPUID( int func, unsigned regs[4] ) { - unsigned regEAX, regEBX, regECX, regEDX; - - __asm pusha - __asm mov eax, func - __asm __emit 00fh - __asm __emit 0a2h - __asm mov regEAX, eax - __asm mov regEBX, ebx - __asm mov regECX, ecx - __asm mov regEDX, edx - __asm popa - - regs[_REG_EAX] = regEAX; - regs[_REG_EBX] = regEBX; - regs[_REG_ECX] = regECX; - regs[_REG_EDX] = regEDX; -} - - -/* -================ -IsAMD -================ -*/ -static bool IsAMD() { - char pstring[16]; - char processorString[13]; - - // get name of processor - CPUID( 0, ( unsigned int * ) pstring ); - processorString[0] = pstring[4]; - processorString[1] = pstring[5]; - processorString[2] = pstring[6]; - processorString[3] = pstring[7]; - processorString[4] = pstring[12]; - processorString[5] = pstring[13]; - processorString[6] = pstring[14]; - processorString[7] = pstring[15]; - processorString[8] = pstring[8]; - processorString[9] = pstring[9]; - processorString[10] = pstring[10]; - processorString[11] = pstring[11]; - processorString[12] = 0; - - if ( strcmp( processorString, "AuthenticAMD" ) == 0 ) { - return true; - } - return false; -} - -/* -================ -HasCMOV -================ -*/ -static bool HasCMOV() { - unsigned regs[4]; - - // get CPU feature bits - CPUID( 1, regs ); - - // bit 15 of EDX denotes CMOV existence - if ( regs[_REG_EDX] & ( 1 << 15 ) ) { - return true; - } - return false; -} - -/* -================ -Has3DNow -================ -*/ -static bool Has3DNow() { - unsigned regs[4]; - - // check AMD-specific functions - CPUID( 0x80000000, regs ); - if ( regs[_REG_EAX] < 0x80000000 ) { - return false; - } - - // bit 31 of EDX denotes 3DNow! support - CPUID( 0x80000001, regs ); - if ( regs[_REG_EDX] & ( 1 << 31 ) ) { - return true; - } - - return false; -} - -/* -================ -HasMMX -================ -*/ -static bool HasMMX() { - unsigned regs[4]; - - // get CPU feature bits - CPUID( 1, regs ); - - // bit 23 of EDX denotes MMX existence - if ( regs[_REG_EDX] & ( 1 << 23 ) ) { - return true; - } - return false; -} - -/* -================ -HasSSE -================ -*/ -static bool HasSSE() { - unsigned regs[4]; - - // get CPU feature bits - CPUID( 1, regs ); - - // bit 25 of EDX denotes SSE existence - if ( regs[_REG_EDX] & ( 1 << 25 ) ) { - return true; - } - return false; -} - -/* -================ -HasSSE2 -================ -*/ -static bool HasSSE2() { - unsigned regs[4]; - - // get CPU feature bits - CPUID( 1, regs ); - - // bit 26 of EDX denotes SSE2 existence - if ( regs[_REG_EDX] & ( 1 << 26 ) ) { - return true; - } - return false; -} - -/* -================ -HasSSE3 -================ -*/ -static bool HasSSE3() { - unsigned regs[4]; - - // get CPU feature bits - CPUID( 1, regs ); - - // bit 0 of ECX denotes SSE3 existence - if ( regs[_REG_ECX] & ( 1 << 0 ) ) { - return true; - } - return false; -} - -/* -================ -LogicalProcPerPhysicalProc -================ -*/ -#define NUM_LOGICAL_BITS 0x00FF0000 // EBX[23:16] Bit 16-23 in ebx contains the number of logical - // processors per physical processor when execute cpuid with - // eax set to 1 -static unsigned char LogicalProcPerPhysicalProc() { - unsigned int regebx = 0; - __asm { - mov eax, 1 - cpuid - mov regebx, ebx - } - return (unsigned char) ((regebx & NUM_LOGICAL_BITS) >> 16); -} - -/* -================ -GetAPIC_ID -================ -*/ -#define INITIAL_APIC_ID_BITS 0xFF000000 // EBX[31:24] Bits 24-31 (8 bits) return the 8-bit unique - // initial APIC ID for the processor this code is running on. - // Default value = 0xff if HT is not supported -static unsigned char GetAPIC_ID() { - unsigned int regebx = 0; - __asm { - mov eax, 1 - cpuid - mov regebx, ebx - } - return (unsigned char) ((regebx & INITIAL_APIC_ID_BITS) >> 24); -} - -/* -================ -CPUCount - - logicalNum is the number of logical CPU per physical CPU - physicalNum is the total number of physical processor - returns one of the HT_* flags -================ -*/ -#define HT_NOT_CAPABLE 0 -#define HT_ENABLED 1 -#define HT_DISABLED 2 -#define HT_SUPPORTED_NOT_ENABLED 3 -#define HT_CANNOT_DETECT 4 - -int CPUCount( int &logicalNum, int &physicalNum ) { - int statusFlag; - SYSTEM_INFO info; - - physicalNum = 1; - logicalNum = 1; - statusFlag = HT_NOT_CAPABLE; - - info.dwNumberOfProcessors = 0; - GetSystemInfo (&info); - - // Number of physical processors in a non-Intel system - // or in a 32-bit Intel system with Hyper-Threading technology disabled - physicalNum = info.dwNumberOfProcessors; - - unsigned char HT_Enabled = 0; - - logicalNum = LogicalProcPerPhysicalProc(); - - if ( logicalNum >= 1 ) { // > 1 doesn't mean HT is enabled in the BIOS - HANDLE hCurrentProcessHandle; - DWORD dwProcessAffinity; - DWORD dwSystemAffinity; - DWORD dwAffinityMask; - - // Calculate the appropriate shifts and mask based on the - // number of logical processors. - - unsigned char i = 1, PHY_ID_MASK = 0xFF, PHY_ID_SHIFT = 0; - - while( i < logicalNum ) { - i *= 2; - PHY_ID_MASK <<= 1; - PHY_ID_SHIFT++; - } - - hCurrentProcessHandle = GetCurrentProcess(); - GetProcessAffinityMask( hCurrentProcessHandle, &dwProcessAffinity, &dwSystemAffinity ); - - // Check if available process affinity mask is equal to the - // available system affinity mask - if ( dwProcessAffinity != dwSystemAffinity ) { - statusFlag = HT_CANNOT_DETECT; - physicalNum = -1; - return statusFlag; - } - - dwAffinityMask = 1; - while ( dwAffinityMask != 0 && dwAffinityMask <= dwProcessAffinity ) { - // Check if this CPU is available - if ( dwAffinityMask & dwProcessAffinity ) { - if ( SetProcessAffinityMask( hCurrentProcessHandle, dwAffinityMask ) ) { - unsigned char APIC_ID, LOG_ID, PHY_ID; - - Sleep( 0 ); // Give OS time to switch CPU - - APIC_ID = GetAPIC_ID(); - LOG_ID = APIC_ID & ~PHY_ID_MASK; - PHY_ID = APIC_ID >> PHY_ID_SHIFT; - - if ( LOG_ID != 0 ) { - HT_Enabled = 1; - } - } - } - dwAffinityMask = dwAffinityMask << 1; - } - - // Reset the processor affinity - SetProcessAffinityMask( hCurrentProcessHandle, dwProcessAffinity ); - - if ( logicalNum == 1 ) { // Normal P4 : HT is disabled in hardware - statusFlag = HT_DISABLED; - } else { - if ( HT_Enabled ) { - // Total physical processors in a Hyper-Threading enabled system. - physicalNum /= logicalNum; - statusFlag = HT_ENABLED; - } else { - statusFlag = HT_SUPPORTED_NOT_ENABLED; - } - } - } - return statusFlag; -} - -/* -================ -HasHTT -================ -*/ -static bool HasHTT() { - unsigned regs[4]; - int logicalNum, physicalNum, HTStatusFlag; - - // get CPU feature bits - CPUID( 1, regs ); - - // bit 28 of EDX denotes HTT existence - if ( !( regs[_REG_EDX] & ( 1 << 28 ) ) ) { - return false; - } - - HTStatusFlag = CPUCount( logicalNum, physicalNum ); - if ( HTStatusFlag != HT_ENABLED ) { - return false; - } - return true; -} - -/* -================ -HasHTT -================ -*/ -static bool HasDAZ() { - __declspec(align(16)) unsigned char FXSaveArea[512]; - unsigned char *FXArea = FXSaveArea; - DWORD dwMask = 0; - unsigned regs[4]; - - // get CPU feature bits - CPUID( 1, regs ); - - // bit 24 of EDX denotes support for FXSAVE - if ( !( regs[_REG_EDX] & ( 1 << 24 ) ) ) { - return false; - } - - memset( FXArea, 0, sizeof( FXSaveArea ) ); - - __asm { - mov eax, FXArea - FXSAVE [eax] - } - - dwMask = *(DWORD *)&FXArea[28]; // Read the MXCSR Mask - return ( ( dwMask & ( 1 << 6 ) ) == ( 1 << 6 ) ); // Return if the DAZ bit is set -} - -/* -================================================================================================ - - CPU - -================================================================================================ -*/ - -/* -======================== -CountSetBits -Helper function to count set bits in the processor mask. -======================== -*/ -DWORD CountSetBits( ULONG_PTR bitMask ) { - DWORD LSHIFT = sizeof( ULONG_PTR ) * 8 - 1; - DWORD bitSetCount = 0; - ULONG_PTR bitTest = (ULONG_PTR)1 << LSHIFT; - - for ( DWORD i = 0; i <= LSHIFT; i++ ) { - bitSetCount += ( ( bitMask & bitTest ) ? 1 : 0 ); - bitTest /= 2; - } - - return bitSetCount; -} - -typedef BOOL (WINAPI *LPFN_GLPI)( PSYSTEM_LOGICAL_PROCESSOR_INFORMATION, PDWORD ); - -enum LOGICAL_PROCESSOR_RELATIONSHIP_LOCAL { - localRelationProcessorCore, - localRelationNumaNode, - localRelationCache, - localRelationProcessorPackage -}; - -struct cpuInfo_t { - int processorPackageCount; - int processorCoreCount; - int logicalProcessorCount; - int numaNodeCount; - struct cacheInfo_t { - int count; - int associativity; - int lineSize; - int size; - } cacheLevel[3]; -}; - -/* -======================== -GetCPUInfo -======================== -*/ -bool GetCPUInfo( cpuInfo_t & cpuInfo ) { - PSYSTEM_LOGICAL_PROCESSOR_INFORMATION buffer = NULL; - PSYSTEM_LOGICAL_PROCESSOR_INFORMATION ptr = NULL; - PCACHE_DESCRIPTOR Cache; - LPFN_GLPI glpi; - BOOL done = FALSE; - DWORD returnLength = 0; - DWORD byteOffset = 0; - - memset( & cpuInfo, 0, sizeof( cpuInfo ) ); - - glpi = (LPFN_GLPI)GetProcAddress( GetModuleHandle(TEXT("kernel32")), "GetLogicalProcessorInformation" ); - if ( NULL == glpi ) { - idLib::Printf( "\nGetLogicalProcessorInformation is not supported.\n" ); - return 0; - } - - while ( !done ) { - DWORD rc = glpi( buffer, &returnLength ); - - if ( FALSE == rc ) { - if ( GetLastError() == ERROR_INSUFFICIENT_BUFFER ) { - if ( buffer ) { - free( buffer ); - } - - buffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)malloc( returnLength ); - } else { - idLib::Printf( "Sys_CPUCount error: %d\n", GetLastError() ); - return false; - } - } else { - done = TRUE; - } - } - - ptr = buffer; - - while ( byteOffset + sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION) <= returnLength ) { - switch ( (LOGICAL_PROCESSOR_RELATIONSHIP_LOCAL) ptr->Relationship ) { - case localRelationProcessorCore: - cpuInfo.processorCoreCount++; - - // A hyperthreaded core supplies more than one logical processor. - cpuInfo.logicalProcessorCount += CountSetBits( ptr->ProcessorMask ); - break; - - case localRelationNumaNode: - // Non-NUMA systems report a single record of this type. - cpuInfo.numaNodeCount++; - break; - - case localRelationCache: - // Cache data is in ptr->Cache, one CACHE_DESCRIPTOR structure for each cache. - Cache = &ptr->Cache; - if ( Cache->Level >= 1 && Cache->Level <= 3 ) { - int level = Cache->Level - 1; - if ( cpuInfo.cacheLevel[level].count > 0 ) { - cpuInfo.cacheLevel[level].count++; - } else { - cpuInfo.cacheLevel[level].associativity = Cache->Associativity; - cpuInfo.cacheLevel[level].lineSize = Cache->LineSize; - cpuInfo.cacheLevel[level].size = Cache->Size; - } - } - break; - - case localRelationProcessorPackage: - // Logical processors share a physical package. - cpuInfo.processorPackageCount++; - break; - - default: - idLib::Printf( "Error: Unsupported LOGICAL_PROCESSOR_RELATIONSHIP value.\n" ); - break; - } - byteOffset += sizeof( SYSTEM_LOGICAL_PROCESSOR_INFORMATION ); - ptr++; - } - - free( buffer ); - - return true; -} - -/* -======================== -Sys_GetCPUCacheSize -======================== -*/ -void Sys_GetCPUCacheSize( int level, int & count, int & size, int & lineSize ) { - assert( level >= 1 && level <= 3 ); - cpuInfo_t cpuInfo; - - GetCPUInfo( cpuInfo ); - - count = cpuInfo.cacheLevel[level - 1].count; - size = cpuInfo.cacheLevel[level - 1].size; - lineSize = cpuInfo.cacheLevel[level - 1].lineSize; -} /* ======================== @@ -706,13 +157,11 @@ numPhysicalCPUCores - the total number of cores per package numCPUPackages - the total number of packages (physical processors) ======================== */ -void Sys_CPUCount( int & numLogicalCPUCores, int & numPhysicalCPUCores, int & numCPUPackages ) { - cpuInfo_t cpuInfo; - GetCPUInfo( cpuInfo ); - - numPhysicalCPUCores = cpuInfo.processorCoreCount; - numLogicalCPUCores = cpuInfo.logicalProcessorCount; - numCPUPackages = cpuInfo.processorPackageCount; +void Sys_CPUCount( int& numLogicalCPUCores, int& numPhysicalCPUCores, int& numCPUPackages ) +{ + numPhysicalCPUCores = 1; + numLogicalCPUCores = SDL_GetCPUCount(); + numCPUPackages = 1; } /* @@ -720,62 +169,64 @@ void Sys_CPUCount( int & numLogicalCPUCores, int & numPhysicalCPUCores, int & nu Sys_GetCPUId ================ */ -cpuid_t Sys_GetCPUId() { +cpuid_t Sys_GetCPUId() +{ int flags; - - // verify we're at least a Pentium or 486 with CPUID support - if ( !HasCPUID() ) { - return CPUID_UNSUPPORTED; - } - + // check for an AMD - if ( IsAMD() ) { - flags = CPUID_AMD; - } else { - flags = CPUID_INTEL; - } - + flags = CPUID_GENERIC; + // check for Multi Media Extensions - if ( HasMMX() ) { + if( SDL_HasMMX() ) + { flags |= CPUID_MMX; } - + // check for 3DNow! - if ( Has3DNow() ) { + if( SDL_Has3DNow() ) + { flags |= CPUID_3DNOW; } - + // check for Streaming SIMD Extensions - if ( HasSSE() ) { + if( SDL_HasSSE() ) + { flags |= CPUID_SSE | CPUID_FTZ; } - + // check for Streaming SIMD Extensions 2 - if ( HasSSE2() ) { + if( SDL_HasSSE2() ) + { flags |= CPUID_SSE2; } - + // check for Streaming SIMD Extensions 3 aka Prescott's New Instructions - if ( HasSSE3() ) { + if( SDL_HasSSE3() ) + { flags |= CPUID_SSE3; } - + + /* // check for Hyper-Threading Technology - if ( HasHTT() ) { + if( HasHTT() ) + { flags |= CPUID_HTT; } - + // check for Conditional Move (CMOV) and fast floating point comparison (FCOMI) instructions - if ( HasCMOV() ) { + if( HasCMOV() ) + { flags |= CPUID_CMOV; } - + // check for Denormals-Are-Zero mode - if ( HasDAZ() ) { + if( HasDAZ() ) + { flags |= CPUID_DAZ; } - - return (cpuid_t)flags; + */ + + return ( cpuid_t )flags; } @@ -787,14 +238,16 @@ cpuid_t Sys_GetCPUId() { =============================================================================== */ -typedef struct bitFlag_s { - char * name; +typedef struct bitFlag_s +{ + char* name; int bit; } bitFlag_t; static byte fpuState[128], *statePtr = fpuState; static char fpuString[2048]; -static bitFlag_t controlWordFlags[] = { +static bitFlag_t controlWordFlags[] = +{ { "Invalid operation", 0 }, { "Denormalized operand", 1 }, { "Divide-by-zero", 2 }, @@ -804,19 +257,22 @@ static bitFlag_t controlWordFlags[] = { { "Infinity control", 12 }, { "", 0 } }; -static char *precisionControlField[] = { +static char* precisionControlField[] = +{ "Single Precision (24-bits)", "Reserved", "Double Precision (53-bits)", "Double Extended Precision (64-bits)" }; -static char *roundingControlField[] = { +static char* roundingControlField[] = +{ "Round to nearest", "Round down", "Round up", "Round toward zero" }; -static bitFlag_t statusWordFlags[] = { +static bitFlag_t statusWordFlags[] = +{ { "Invalid operation", 0 }, { "Denormalized operand", 1 }, { "Divide-by-zero", 2 }, @@ -834,33 +290,36 @@ static bitFlag_t statusWordFlags[] = { Sys_FPU_PrintStateFlags =============== */ -int Sys_FPU_PrintStateFlags( char *ptr, int ctrl, int stat, int tags, int inof, int inse, int opof, int opse ) { +int Sys_FPU_PrintStateFlags( char* ptr, int ctrl, int stat, int tags, int inof, int inse, int opof, int opse ) +{ int i, length = 0; - - length += sprintf( ptr+length, "CTRL = %08x\n" - "STAT = %08x\n" - "TAGS = %08x\n" - "INOF = %08x\n" - "INSE = %08x\n" - "OPOF = %08x\n" - "OPSE = %08x\n" - "\n", - ctrl, stat, tags, inof, inse, opof, opse ); - - length += sprintf( ptr+length, "Control Word:\n" ); - for ( i = 0; controlWordFlags[i].name[0]; i++ ) { - length += sprintf( ptr+length, " %-30s = %s\n", controlWordFlags[i].name, ( ctrl & ( 1 << controlWordFlags[i].bit ) ) ? "true" : "false" ); + + length += sprintf( ptr + length, "CTRL = %08x\n" + "STAT = %08x\n" + "TAGS = %08x\n" + "INOF = %08x\n" + "INSE = %08x\n" + "OPOF = %08x\n" + "OPSE = %08x\n" + "\n", + ctrl, stat, tags, inof, inse, opof, opse ); + + length += sprintf( ptr + length, "Control Word:\n" ); + for( i = 0; controlWordFlags[i].name[0]; i++ ) + { + length += sprintf( ptr + length, " %-30s = %s\n", controlWordFlags[i].name, ( ctrl & ( 1 << controlWordFlags[i].bit ) ) ? "true" : "false" ); } - length += sprintf( ptr+length, " %-30s = %s\n", "Precision control", precisionControlField[(ctrl>>8)&3] ); - length += sprintf( ptr+length, " %-30s = %s\n", "Rounding control", roundingControlField[(ctrl>>10)&3] ); - - length += sprintf( ptr+length, "Status Word:\n" ); - for ( i = 0; statusWordFlags[i].name[0]; i++ ) { - ptr += sprintf( ptr+length, " %-30s = %s\n", statusWordFlags[i].name, ( stat & ( 1 << statusWordFlags[i].bit ) ) ? "true" : "false" ); + length += sprintf( ptr + length, " %-30s = %s\n", "Precision control", precisionControlField[( ctrl >> 8 ) & 3] ); + length += sprintf( ptr + length, " %-30s = %s\n", "Rounding control", roundingControlField[( ctrl >> 10 ) & 3] ); + + length += sprintf( ptr + length, "Status Word:\n" ); + for( i = 0; statusWordFlags[i].name[0]; i++ ) + { + ptr += sprintf( ptr + length, " %-30s = %s\n", statusWordFlags[i].name, ( stat & ( 1 << statusWordFlags[i].bit ) ) ? "true" : "false" ); } - length += sprintf( ptr+length, " %-30s = %d%d%d%d\n", "Condition code", (stat>>8)&1, (stat>>9)&1, (stat>>10)&1, (stat>>14)&1 ); - length += sprintf( ptr+length, " %-30s = %d\n", "Top of stack pointer", (stat>>11)&7 ); - + length += sprintf( ptr + length, " %-30s = %d%d%d%d\n", "Condition code", ( stat >> 8 ) & 1, ( stat >> 9 ) & 1, ( stat >> 10 ) & 1, ( stat >> 14 ) & 1 ); + length += sprintf( ptr + length, " %-30s = %d\n", "Top of stack pointer", ( stat >> 11 ) & 7 ); + return length; } @@ -869,17 +328,9 @@ int Sys_FPU_PrintStateFlags( char *ptr, int ctrl, int stat, int tags, int inof, Sys_FPU_StackIsEmpty =============== */ -bool Sys_FPU_StackIsEmpty() { - __asm { - mov eax, statePtr - fnstenv [eax] - mov eax, [eax+8] - xor eax, 0xFFFFFFFF - and eax, 0x0000FFFF - jz empty - } - return false; -empty: +bool Sys_FPU_StackIsEmpty() +{ + // TODO return true; } @@ -888,22 +339,9 @@ empty: Sys_FPU_ClearStack =============== */ -void Sys_FPU_ClearStack() { - __asm { - mov eax, statePtr - fnstenv [eax] - mov eax, [eax+8] - xor eax, 0xFFFFFFFF - mov edx, (3<<14) - emptyStack: - mov ecx, eax - and ecx, edx - jz done - fstp st - shr edx, 2 - jmp emptyStack - done: - } +void Sys_FPU_ClearStack() +{ + // TODO } /* @@ -913,103 +351,9 @@ Sys_FPU_GetState gets the FPU state without changing the state =============== */ -const char *Sys_FPU_GetState() { - double fpuStack[8] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; - double *fpuStackPtr = fpuStack; - int i, numValues; - char *ptr; - - __asm { - mov esi, statePtr - mov edi, fpuStackPtr - fnstenv [esi] - mov esi, [esi+8] - xor esi, 0xFFFFFFFF - mov edx, (3<<14) - xor eax, eax - mov ecx, esi - and ecx, edx - jz done - fst qword ptr [edi+0] - inc eax - shr edx, 2 - mov ecx, esi - and ecx, edx - jz done - fxch st(1) - fst qword ptr [edi+8] - inc eax - fxch st(1) - shr edx, 2 - mov ecx, esi - and ecx, edx - jz done - fxch st(2) - fst qword ptr [edi+16] - inc eax - fxch st(2) - shr edx, 2 - mov ecx, esi - and ecx, edx - jz done - fxch st(3) - fst qword ptr [edi+24] - inc eax - fxch st(3) - shr edx, 2 - mov ecx, esi - and ecx, edx - jz done - fxch st(4) - fst qword ptr [edi+32] - inc eax - fxch st(4) - shr edx, 2 - mov ecx, esi - and ecx, edx - jz done - fxch st(5) - fst qword ptr [edi+40] - inc eax - fxch st(5) - shr edx, 2 - mov ecx, esi - and ecx, edx - jz done - fxch st(6) - fst qword ptr [edi+48] - inc eax - fxch st(6) - shr edx, 2 - mov ecx, esi - and ecx, edx - jz done - fxch st(7) - fst qword ptr [edi+56] - inc eax - fxch st(7) - done: - mov numValues, eax - } - - int ctrl = *(int *)&fpuState[0]; - int stat = *(int *)&fpuState[4]; - int tags = *(int *)&fpuState[8]; - int inof = *(int *)&fpuState[12]; - int inse = *(int *)&fpuState[16]; - int opof = *(int *)&fpuState[20]; - int opse = *(int *)&fpuState[24]; - - ptr = fpuString; - ptr += sprintf( ptr,"FPU State:\n" - "num values on stack = %d\n", numValues ); - for ( i = 0; i < 8; i++ ) { - ptr += sprintf( ptr, "ST%d = %1.10e\n", i, fpuStack[i] ); - } - - Sys_FPU_PrintStateFlags( ptr, ctrl, stat, tags, inof, inse, opof, opse ); - - return fpuString; +const char* Sys_FPU_GetState() +{ + return "TODO Sys_FPU_GetState()"; } /* @@ -1017,19 +361,9 @@ const char *Sys_FPU_GetState() { Sys_FPU_EnableExceptions =============== */ -void Sys_FPU_EnableExceptions( int exceptions ) { - __asm { - mov eax, statePtr - mov ecx, exceptions - and cx, 63 - not cx - fnstcw word ptr [eax] - mov bx, word ptr [eax] - or bx, 63 - and bx, cx - mov word ptr [eax], bx - fldcw word ptr [eax] - } +void Sys_FPU_EnableExceptions( int exceptions ) +{ + // TODO } /* @@ -1037,11 +371,15 @@ void Sys_FPU_EnableExceptions( int exceptions ) { Sys_FPU_SetPrecision =============== */ -void Sys_FPU_SetPrecision( int precision ) { +void Sys_FPU_SetPrecision( int precision ) +{ + // TODO + + /* short precisionBitTable[4] = { 0, 1, 3, 0 }; short precisionBits = precisionBitTable[precision & 3] << 8; short precisionMask = ~( ( 1 << 9 ) | ( 1 << 8 ) ); - + __asm { mov eax, statePtr mov cx, precisionBits @@ -1052,6 +390,7 @@ void Sys_FPU_SetPrecision( int precision ) { mov word ptr [eax], bx fldcw word ptr [eax] } + */ } /* @@ -1059,11 +398,15 @@ void Sys_FPU_SetPrecision( int precision ) { Sys_FPU_SetRounding ================ */ -void Sys_FPU_SetRounding( int rounding ) { +void Sys_FPU_SetRounding( int rounding ) +{ + // TODO + + /* short roundingBitTable[4] = { 0, 1, 2, 3 }; short roundingBits = roundingBitTable[rounding & 3] << 10; short roundingMask = ~( ( 1 << 11 ) | ( 1 << 10 ) ); - + __asm { mov eax, statePtr mov cx, roundingBits @@ -1074,6 +417,7 @@ void Sys_FPU_SetRounding( int rounding ) { mov word ptr [eax], bx fldcw word ptr [eax] } + */ } /* @@ -1081,9 +425,11 @@ void Sys_FPU_SetRounding( int rounding ) { Sys_FPU_SetDAZ ================ */ -void Sys_FPU_SetDAZ( bool enable ) { +void Sys_FPU_SetDAZ( bool enable ) +{ + /* DWORD dwData; - + _asm { movzx ecx, byte ptr enable and ecx, 1 @@ -1095,6 +441,7 @@ void Sys_FPU_SetDAZ( bool enable ) { mov dwData, eax LDMXCSR dword ptr dwData } + */ } /* @@ -1102,9 +449,11 @@ void Sys_FPU_SetDAZ( bool enable ) { Sys_FPU_SetFTZ ================ */ -void Sys_FPU_SetFTZ( bool enable ) { +void Sys_FPU_SetFTZ( bool enable ) +{ + /* DWORD dwData; - + _asm { movzx ecx, byte ptr enable and ecx, 1 @@ -1116,4 +465,5 @@ void Sys_FPU_SetFTZ( bool enable ) { mov dwData, eax LDMXCSR dword ptr dwData } + */ } diff --git a/neo/sys/sys_local.cpp b/neo/sys/sys_local.cpp index 8f632ee0..98f18de9 100644 --- a/neo/sys/sys_local.cpp +++ b/neo/sys/sys_local.cpp @@ -106,26 +106,6 @@ bool idSysLocal::UnlockMemory( void* ptr, int bytes ) return Sys_UnlockMemory( ptr, bytes ); } -void idSysLocal::GetCallStack( address_t* callStack, const int callStackSize ) -{ - Sys_GetCallStack( callStack, callStackSize ); -} - -const char* idSysLocal::GetCallStackStr( const address_t* callStack, const int callStackSize ) -{ - return Sys_GetCallStackStr( callStack, callStackSize ); -} - -const char* idSysLocal::GetCallStackCurStr( int depth ) -{ - return Sys_GetCallStackCurStr( depth ); -} - -void idSysLocal::ShutdownSymbols() -{ - Sys_ShutdownSymbols(); -} - int idSysLocal::DLL_Load( const char* dllName ) { return Sys_DLL_Load( dllName ); diff --git a/neo/sys/sys_local.h b/neo/sys/sys_local.h index ba66bbda..6b4076fa 100644 --- a/neo/sys/sys_local.h +++ b/neo/sys/sys_local.h @@ -54,11 +54,6 @@ public: virtual void FPU_EnableExceptions( int exceptions ); - virtual void GetCallStack( address_t* callStack, const int callStackSize ); - virtual const char* GetCallStackStr( const address_t* callStack, const int callStackSize ); - virtual const char* GetCallStackCurStr( int depth ); - virtual void ShutdownSymbols(); - virtual bool LockMemory( void* ptr, int bytes ); virtual bool UnlockMemory( void* ptr, int bytes ); diff --git a/neo/sys/sys_public.h b/neo/sys/sys_public.h index 474add97..9222781c 100644 --- a/neo/sys/sys_public.h +++ b/neo/sys/sys_public.h @@ -518,13 +518,6 @@ bool Sys_UnlockMemory( void* ptr, int bytes ); // set amount of physical work memory void Sys_SetPhysicalWorkMemory( int minBytes, int maxBytes ); -// allows retrieving the call stack at execution points -void Sys_GetCallStack( address_t* callStack, const int callStackSize ); -const char* Sys_GetCallStackStr( const address_t* callStack, const int callStackSize ); -const char* Sys_GetCallStackCurStr( int depth ); -const char* Sys_GetCallStackCurAddressStr( int depth ); -void Sys_ShutdownSymbols(); - // DLL loading, the path should be a fully qualified OS path to the DLL file to be loaded int Sys_DLL_Load( const char* dllName ); void* Sys_DLL_GetProcAddress( int dllHandle, const char* procName ); @@ -767,11 +760,6 @@ public: virtual bool LockMemory( void* ptr, int bytes ) = 0; virtual bool UnlockMemory( void* ptr, int bytes ) = 0; - virtual void GetCallStack( address_t* callStack, const int callStackSize ) = 0; - virtual const char* GetCallStackStr( const address_t* callStack, const int callStackSize ) = 0; - virtual const char* GetCallStackCurStr( int depth ) = 0; - virtual void ShutdownSymbols() = 0; - virtual int DLL_Load( const char* dllName ) = 0; virtual void* DLL_GetProcAddress( int dllHandle, const char* procName ) = 0; virtual void DLL_Unload( int dllHandle ) = 0; diff --git a/neo/sys/win32/win_main.cpp b/neo/sys/win32/win_main.cpp index 53fcb668..aae7ec17 100644 --- a/neo/sys/win32/win_main.cpp +++ b/neo/sys/win32/win_main.cpp @@ -3,6 +3,7 @@ Doom 3 BFG Edition GPL Source Code Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. +Copyright (C) 2012 Robert Beckebans This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). @@ -530,7 +531,15 @@ const char *Sys_DefaultSavePath() { SHGetKnownFolderPath_t SHGetKnownFolderPath = (SHGetKnownFolderPath_t)GetProcAddress( hShell, "SHGetKnownFolderPath" ); if ( SHGetKnownFolderPath ) { wchar_t * path; - if ( SUCCEEDED( SHGetKnownFolderPath( FOLDERID_SavedGames_IdTech5, CSIDL_FLAG_CREATE | CSIDL_FLAG_PER_USER_INIT, 0, &path ) ) ) { + + // RB FIXME? +#if defined(__MINGW32__) + if ( SUCCEEDED( SHGetKnownFolderPath( FOLDERID_SavedGames_IdTech5, CSIDL_FLAG_CREATE, 0, &path ) ) ) +#else + if ( SUCCEEDED( SHGetKnownFolderPath( FOLDERID_SavedGames_IdTech5, CSIDL_FLAG_CREATE | CSIDL_FLAG_PER_USER_INIT, 0, &path ) ) ) +#endif + // RB end + { if ( wcstombs( savePath, path, MAX_PATH ) > MAX_PATH ) { savePath[0] = 0; } @@ -540,8 +549,15 @@ const char *Sys_DefaultSavePath() { FreeLibrary( hShell ); } - if ( savePath[0] == 0 ) { + if ( savePath[0] == 0 ) + { + // RB: looks like a bug in the shlobj.h +#if defined(__MINGW32__) + SHGetFolderPath( NULL, CSIDL_PERSONAL | CSIDL_FLAG_CREATE, NULL, 1, savePath ); +#else SHGetFolderPath( NULL, CSIDL_PERSONAL | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, savePath ); +#endif + // RB end strcat( savePath, "\\My Games" ); } @@ -857,7 +873,8 @@ Sys_DLL_GetProcAddress ===================== */ void *Sys_DLL_GetProcAddress( int dllHandle, const char *procName ) { - return GetProcAddress( (HINSTANCE)dllHandle, procName ); + // RB: added missing cast + return ( void* ) GetProcAddress( (HINSTANCE)dllHandle, procName ); } /* @@ -1343,6 +1360,9 @@ void EmailCrashReport( LPSTR messageText ) { } } +// RB: disabled unused FPU exception debugging +#if !defined(__MINGW32__) + int Sys_FPU_PrintStateFlags( char *ptr, int ctrl, int stat, int tags, int inof, int inse, int opof, int opse ); /* @@ -1415,6 +1435,8 @@ EXCEPTION_DISPOSITION __cdecl _except_handler( struct _EXCEPTION_RECORD *Excepti // Tell the OS to restart the faulting instruction return ExceptionContinueExecution; } +#endif +// RB end #define TEST_FPU_EXCEPTIONS /* FPU_EXCEPTION_INVALID_OPERATION | */ \ /* FPU_EXCEPTION_DENORMALIZED_OPERAND | */ \ diff --git a/neo/sys/win32/win_session_local.cpp b/neo/sys/win32/win_session_local.cpp index abba8876..ba50f7ed 100644 --- a/neo/sys/win32/win_session_local.cpp +++ b/neo/sys/win32/win_session_local.cpp @@ -32,6 +32,7 @@ Global variables extern idCVar net_port; +class idLobbyToSessionCBLocal; /* ======================== diff --git a/neo/sys/win32/win_shared.cpp b/neo/sys/win32/win_shared.cpp index e1ce7ec2..89b5544a 100644 --- a/neo/sys/win32/win_shared.cpp +++ b/neo/sys/win32/win_shared.cpp @@ -42,17 +42,21 @@ If you have questions concerning this license or the applicable additional terms #undef StrCmpNI #undef StrCmpI - +// RB begin +#if !defined(__MINGW32__) #include #include #include + // RB: no with Visual C++ 2010 Express #if defined(USE_MFC_TOOLS) #include #else #include "win_nanoafx.h" #endif + +#endif // #if !defined(__MINGW32__) // RB end #pragma comment (lib, "wbemuuid.lib") @@ -147,6 +151,8 @@ returns in megabytes int Sys_GetVideoRam() { unsigned int retSize = 64; + // RB begin +#if !defined(__MINGW32__) CComPtr spLoc = NULL; HRESULT hr = CoCreateInstance( CLSID_WbemLocator, 0, CLSCTX_SERVER, IID_IWbemLocator, ( LPVOID * ) &spLoc ); if ( hr != S_OK || spLoc == NULL ) { @@ -190,6 +196,9 @@ int Sys_GetVideoRam() { } } } +#endif + // RB end + return retSize; } @@ -282,527 +291,3 @@ char *Sys_GetCurrentUser() { return s_userName; } - -/* -=============================================================================== - - Call stack - -=============================================================================== -*/ - - -#define PROLOGUE_SIGNATURE 0x00EC8B55 - -#include - -const int UNDECORATE_FLAGS = UNDNAME_NO_MS_KEYWORDS | - UNDNAME_NO_ACCESS_SPECIFIERS | - UNDNAME_NO_FUNCTION_RETURNS | - UNDNAME_NO_ALLOCATION_MODEL | - UNDNAME_NO_ALLOCATION_LANGUAGE | - UNDNAME_NO_MEMBER_TYPE; - -#if defined(_DEBUG) && 1 - -typedef struct symbol_s { - int address; - char * name; - struct symbol_s * next; -} symbol_t; - -typedef struct module_s { - int address; - char * name; - symbol_t * symbols; - struct module_s * next; -} module_t; - -module_t *modules; - -/* -================== -SkipRestOfLine -================== -*/ -void SkipRestOfLine( const char **ptr ) { - while( (**ptr) != '\0' && (**ptr) != '\n' && (**ptr) != '\r' ) { - (*ptr)++; - } - while( (**ptr) == '\n' || (**ptr) == '\r' ) { - (*ptr)++; - } -} - -/* -================== -SkipWhiteSpace -================== -*/ -void SkipWhiteSpace( const char **ptr ) { - while( (**ptr) == ' ' ) { - (*ptr)++; - } -} - -/* -================== -ParseHexNumber -================== -*/ -int ParseHexNumber( const char **ptr ) { - int n = 0; - while( (**ptr) >= '0' && (**ptr) <= '9' || (**ptr) >= 'a' && (**ptr) <= 'f' ) { - n <<= 4; - if ( **ptr >= '0' && **ptr <= '9' ) { - n |= ( (**ptr) - '0' ); - } else { - n |= 10 + ( (**ptr) - 'a' ); - } - (*ptr)++; - } - return n; -} - -/* -================== -Sym_Init -================== -*/ -void Sym_Init( long addr ) { - TCHAR moduleName[MAX_STRING_CHARS]; - MEMORY_BASIC_INFORMATION mbi; - - VirtualQuery( (void*)addr, &mbi, sizeof(mbi) ); - - GetModuleFileName( (HMODULE)mbi.AllocationBase, moduleName, sizeof( moduleName ) ); - - char *ext = moduleName + strlen( moduleName ); - while( ext > moduleName && *ext != '.' ) { - ext--; - } - if ( ext == moduleName ) { - strcat( moduleName, ".map" ); - } else { - strcpy( ext, ".map" ); - } - - module_t *module = (module_t *) malloc( sizeof( module_t ) ); - module->name = (char *) malloc( strlen( moduleName ) + 1 ); - strcpy( module->name, moduleName ); - module->address = (int)mbi.AllocationBase; - module->symbols = NULL; - module->next = modules; - modules = module; - - FILE * fp = fopen( moduleName, "rb" ); - if ( fp == NULL ) { - return; - } - - int pos = ftell( fp ); - fseek( fp, 0, SEEK_END ); - int length = ftell( fp ); - fseek( fp, pos, SEEK_SET ); - - char *text = (char *) malloc( length+1 ); - fread( text, 1, length, fp ); - text[length] = '\0'; - fclose( fp ); - - const char *ptr = text; - - // skip up to " Address" on a new line - while( *ptr != '\0' ) { - SkipWhiteSpace( &ptr ); - if ( idStr::Cmpn( ptr, "Address", 7 ) == 0 ) { - SkipRestOfLine( &ptr ); - break; - } - SkipRestOfLine( &ptr ); - } - - int symbolAddress; - int symbolLength; - char symbolName[MAX_STRING_CHARS]; - symbol_t *symbol; - - // parse symbols - while( *ptr != '\0' ) { - - SkipWhiteSpace( &ptr ); - - ParseHexNumber( &ptr ); - if ( *ptr == ':' ) { - ptr++; - } else { - break; - } - ParseHexNumber( &ptr ); - - SkipWhiteSpace( &ptr ); - - // parse symbol name - symbolLength = 0; - while( *ptr != '\0' && *ptr != ' ' ) { - symbolName[symbolLength++] = *ptr++; - if ( symbolLength >= sizeof( symbolName ) - 1 ) { - break; - } - } - symbolName[symbolLength++] = '\0'; - - SkipWhiteSpace( &ptr ); - - // parse symbol address - symbolAddress = ParseHexNumber( &ptr ); - - SkipRestOfLine( &ptr ); - - symbol = (symbol_t *) malloc( sizeof( symbol_t ) ); - symbol->name = (char *) malloc( symbolLength ); - strcpy( symbol->name, symbolName ); - symbol->address = symbolAddress; - symbol->next = module->symbols; - module->symbols = symbol; - } - - free( text ); -} - -/* -================== -Sym_Shutdown -================== -*/ -void Sym_Shutdown() { - module_t *m; - symbol_t *s; - - for ( m = modules; m != NULL; m = modules ) { - modules = m->next; - for ( s = m->symbols; s != NULL; s = m->symbols ) { - m->symbols = s->next; - free( s->name ); - free( s ); - } - free( m->name ); - free( m ); - } - modules = NULL; -} - -/* -================== -Sym_GetFuncInfo -================== -*/ -void Sym_GetFuncInfo( long addr, idStr &module, idStr &funcName ) { - MEMORY_BASIC_INFORMATION mbi; - module_t *m; - symbol_t *s; - - VirtualQuery( (void*)addr, &mbi, sizeof(mbi) ); - - for ( m = modules; m != NULL; m = m->next ) { - if ( m->address == (int) mbi.AllocationBase ) { - break; - } - } - if ( !m ) { - Sym_Init( addr ); - m = modules; - } - - for ( s = m->symbols; s != NULL; s = s->next ) { - if ( s->address == addr ) { - - char undName[MAX_STRING_CHARS]; - if ( UnDecorateSymbolName( s->name, undName, sizeof(undName), UNDECORATE_FLAGS ) ) { - funcName = undName; - } else { - funcName = s->name; - } - for ( int i = 0; i < funcName.Length(); i++ ) { - if ( funcName[i] == '(' ) { - funcName.CapLength( i ); - break; - } - } - module = m->name; - return; - } - } - - sprintf( funcName, "0x%08x", addr ); - module = ""; -} - -#elif defined(_DEBUG) - -DWORD lastAllocationBase = -1; -HANDLE processHandle; -idStr lastModule; - -/* -================== -Sym_Init -================== -*/ -void Sym_Init( long addr ) { - TCHAR moduleName[MAX_STRING_CHARS]; - TCHAR modShortNameBuf[MAX_STRING_CHARS]; - MEMORY_BASIC_INFORMATION mbi; - - if ( lastAllocationBase != -1 ) { - Sym_Shutdown(); - } - - VirtualQuery( (void*)addr, &mbi, sizeof(mbi) ); - - GetModuleFileName( (HMODULE)mbi.AllocationBase, moduleName, sizeof( moduleName ) ); - _splitpath( moduleName, NULL, NULL, modShortNameBuf, NULL ); - lastModule = modShortNameBuf; - - processHandle = GetCurrentProcess(); - if ( !SymInitialize( processHandle, NULL, FALSE ) ) { - return; - } - if ( !SymLoadModule( processHandle, NULL, moduleName, NULL, (DWORD)mbi.AllocationBase, 0 ) ) { - SymCleanup( processHandle ); - return; - } - - SymSetOptions( SymGetOptions() & ~SYMOPT_UNDNAME ); - - lastAllocationBase = (DWORD) mbi.AllocationBase; -} - -/* -================== -Sym_Shutdown -================== -*/ -void Sym_Shutdown() { - SymUnloadModule( GetCurrentProcess(), lastAllocationBase ); - SymCleanup( GetCurrentProcess() ); - lastAllocationBase = -1; -} - -/* -================== -Sym_GetFuncInfo -================== -*/ -void Sym_GetFuncInfo( long addr, idStr &module, idStr &funcName ) { - MEMORY_BASIC_INFORMATION mbi; - - VirtualQuery( (void*)addr, &mbi, sizeof(mbi) ); - - if ( (DWORD) mbi.AllocationBase != lastAllocationBase ) { - Sym_Init( addr ); - } - - BYTE symbolBuffer[ sizeof(IMAGEHLP_SYMBOL) + MAX_STRING_CHARS ]; - PIMAGEHLP_SYMBOL pSymbol = (PIMAGEHLP_SYMBOL)&symbolBuffer[0]; - pSymbol->SizeOfStruct = sizeof(symbolBuffer); - pSymbol->MaxNameLength = 1023; - pSymbol->Address = 0; - pSymbol->Flags = 0; - pSymbol->Size =0; - - DWORD symDisplacement = 0; - if ( SymGetSymFromAddr( processHandle, addr, &symDisplacement, pSymbol ) ) { - // clean up name, throwing away decorations that don't affect uniqueness - char undName[MAX_STRING_CHARS]; - if ( UnDecorateSymbolName( pSymbol->Name, undName, sizeof(undName), UNDECORATE_FLAGS ) ) { - funcName = undName; - } else { - funcName = pSymbol->Name; - } - module = lastModule; - } - else { - LPVOID lpMsgBuf; - FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language - (LPTSTR) &lpMsgBuf, - 0, - NULL - ); - LocalFree( lpMsgBuf ); - - // Couldn't retrieve symbol (no debug info?, can't load dbghelp.dll?) - sprintf( funcName, "0x%08x", addr ); - module = ""; - } -} - -#else - -/* -================== -Sym_Init -================== -*/ -void Sym_Init( long addr ) { -} - -/* -================== -Sym_Shutdown -================== -*/ -void Sym_Shutdown() { -} - -/* -================== -Sym_GetFuncInfo -================== -*/ -void Sym_GetFuncInfo( long addr, idStr &module, idStr &funcName ) { - module = ""; - sprintf( funcName, "0x%08x", addr ); -} - -#endif - -/* -================== -GetFuncAddr -================== -*/ -address_t GetFuncAddr( address_t midPtPtr ) { - long temp; - do { - temp = (long)(*(long*)midPtPtr); - if ( (temp&0x00FFFFFF) == PROLOGUE_SIGNATURE ) { - break; - } - midPtPtr--; - } while(true); - - return midPtPtr; -} - -/* -================== -GetCallerAddr -================== -*/ -address_t GetCallerAddr( long _ebp ) { - long midPtPtr; - long res = 0; - - __asm { - mov eax, _ebp - mov ecx, [eax] // check for end of stack frames list - test ecx, ecx // check for zero stack frame - jz label - mov eax, [eax+4] // get the ret address - test eax, eax // check for zero return address - jz label - mov midPtPtr, eax - } - res = GetFuncAddr( midPtPtr ); -label: - return res; -} - -/* -================== -Sys_GetCallStack - - use /Oy option -================== -*/ -void Sys_GetCallStack( address_t *callStack, const int callStackSize ) { -#if 1 //def _DEBUG - int i; - long m_ebp; - - __asm { - mov eax, ebp - mov m_ebp, eax - } - // skip last two functions - m_ebp = *((long*)m_ebp); - m_ebp = *((long*)m_ebp); - // list functions - for ( i = 0; i < callStackSize; i++ ) { - callStack[i] = GetCallerAddr( m_ebp ); - if ( callStack[i] == 0 ) { - break; - } - m_ebp = *((long*)m_ebp); - } -#else - int i = 0; -#endif - while( i < callStackSize ) { - callStack[i++] = 0; - } -} - -/* -================== -Sys_GetCallStackStr -================== -*/ -const char *Sys_GetCallStackStr( const address_t *callStack, const int callStackSize ) { - static char string[MAX_STRING_CHARS*2]; - int index, i; - idStr module, funcName; - - index = 0; - for ( i = callStackSize-1; i >= 0; i-- ) { - Sym_GetFuncInfo( callStack[i], module, funcName ); - index += sprintf( string+index, " -> %s", funcName.c_str() ); - } - return string; -} - -/* -================== -Sys_GetCallStackCurStr -================== -*/ -const char *Sys_GetCallStackCurStr( int depth ) { - address_t *callStack; - - callStack = (address_t *) _alloca( depth * sizeof( address_t ) ); - Sys_GetCallStack( callStack, depth ); - return Sys_GetCallStackStr( callStack, depth ); -} - -/* -================== -Sys_GetCallStackCurAddressStr -================== -*/ -const char *Sys_GetCallStackCurAddressStr( int depth ) { - static char string[MAX_STRING_CHARS*2]; - address_t *callStack; - int index, i; - - callStack = (address_t *) _alloca( depth * sizeof( address_t ) ); - Sys_GetCallStack( callStack, depth ); - - index = 0; - for ( i = depth-1; i >= 0; i-- ) { - index += sprintf( string+index, " -> 0x%08x", callStack[i] ); - } - return string; -} - -/* -================== -Sys_ShutdownSymbols -================== -*/ -void Sys_ShutdownSymbols() { - Sym_Shutdown(); -} diff --git a/neo/sys/win32/win_wndproc.cpp b/neo/sys/win32/win_wndproc.cpp index 663a9c27..8df0e7b5 100644 --- a/neo/sys/win32/win_wndproc.cpp +++ b/neo/sys/win32/win_wndproc.cpp @@ -3,6 +3,7 @@ Doom 3 BFG Edition GPL Source Code Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. +Copyright (C) 2012 Robert Beckebans This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). @@ -57,7 +58,13 @@ static void WIN_DisableAltTab() { BOOL old; + // RB begin +#if defined(__MINGW32__) + SystemParametersInfo( SPI_GETSCREENSAVEACTIVE, 1, &old, 0 ); +#else SystemParametersInfo( SPI_SCREENSAVERRUNNING, 1, &old, 0 ); +#endif + // RB end } s_alttab_disabled = true; } @@ -76,7 +83,13 @@ static void WIN_EnableAltTab() { BOOL old; - SystemParametersInfo( SPI_SCREENSAVERRUNNING, 0, &old, 0 ); + // RB begin +#if defined(__MINGW32__) + SystemParametersInfo( SPI_GETSCREENSAVEACTIVE, 1, &old, 0 ); +#else + SystemParametersInfo( SPI_SCREENSAVERRUNNING, 1, &old, 0 ); +#endif + // RB end } s_alttab_disabled = false; @@ -459,6 +472,10 @@ LONG WINAPI MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) } case WM_XBUTTONDOWN: { + // RB begin +#if defined(__MINGW32__) + Sys_QueEvent( SE_KEY, K_MOUSE4, 1, 0, NULL, 0 ); +#else int button = GET_XBUTTON_WPARAM( wParam ); if( button == 1 ) { @@ -468,10 +485,16 @@ LONG WINAPI MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { Sys_QueEvent( SE_KEY, K_MOUSE5, 1, 0, NULL, 0 ); } +#endif + // RB end return 0; } case WM_XBUTTONUP: { + // RB begin +#if defined(__MINGW32__) + Sys_QueEvent( SE_KEY, K_MOUSE4, 0, 0, NULL, 0 ); +#else int button = GET_XBUTTON_WPARAM( wParam ); if( button == 1 ) { @@ -481,6 +504,8 @@ LONG WINAPI MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { Sys_QueEvent( SE_KEY, K_MOUSE5, 0, 0, NULL, 0 ); } +#endif + // RB end return 0; } case WM_MOUSEWHEEL: