Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

softdrv.c File Reference

#include <Windows.h>
#include <Assert.h>
#include <stdio.h>
#include <mmsystem.h>
#include <math.h>
#include "SoftDrv.h"
#include "System.h"
#include "DCommon.h"
#include "Sal.h"
#include "Register.h"
#include "Scene.h"
#include "Render.h"
#include "dmodes.h"

Go to the source code of this file.

Defines

#define CPUID   _asm _emit 0fh _asm _emit 0a2h

Typedefs

typedef unsigned __int64 QWORD

Functions

BOOL DRIVERCC EnumSubDrivers (DRV_ENUM_DRV_CB *Cb, void *Context)
BOOL DRIVERCC EnumModes (S32 Driver, char *DriverName, DRV_ENUM_MODES_CB *Cb, void *Context)
BOOL DRIVERCC SetDrvRenderState (S32 State, U32 Flag)
BOOL DRIVERCC GetDrvRenderState (S32 State, U32 *Flag)
BOOL DRIVERCC EnumPixelFormats (DRV_ENUM_PFORMAT_CB *Cb, void *Context)
BOOL DRIVERCC ScreenShot (const char *Name)
U32 GetCPUIDEAX (U32 funcNum)
U32 GetCPUIDEDX (U32 funcNum)
U32 GetCPUIDString (U32 funcNum, char *szId)
void GetCPUIDStringAMD (U32 funcNum, char *szId)
void GetCPUInfo (void)
void SetupMiscConstants (void)
BOOL DRIVERCC DrvInit (DRV_DriverHook *Hook)
BOOL DRIVERCC DrvShutdown (void)
void DRIVERCC ErrorBox (char *Str)
BOOL DRIVERCC SetGamma (geFloat Gamma)
BOOL DRIVERCC GetGamma (geFloat *Gamma)
geBoolean DRIVERCC DrvUpdateWindow (void)
geBoolean DRIVERCC Drv_SetFogEnable (geBoolean Enable, geFloat r, geFloat g, geFloat b, geFloat Start, geFloat End)
DllExport BOOL DriverHook (DRV_Driver **Driver)
void SetLastDrvError (S32 Error, char *ErrorStr)
void Test_CPU_bits (void)
void ErrorPrintf (char *text,...)
void DumpErrorLogToFile (char *fname)

Variables

DRV_CacheInfo CacheInfo
VidEnumInfo VidInfo [16]
VidEnumInfoVInfo
VidModeListcmode
DRV_Window ClientWindow = { 0 }
CPUInfo ProcessorInfo = { 0 }
int NumDevices = 0
S32 LastError
char LastErrorStr [200]
__int64 QZBufferPrec = 0
__int64 QFixedScale = 0
__int64 QFixedScale16 = 0
__int64 Q128 = 0
double Magic
double MipMagic
double MipMagic2
DRV_Driver SOFTDRV
DRV_EngineSettings EngineSettings
int Flag_CPUID = FALSE
int Flag_RDTSC = FALSE
char buffer [32768]
char buf3 [4096]


Define Documentation

#define CPUID   _asm _emit 0fh _asm _emit 0a2h
 

Definition at line 58 of file softdrv.c.

Referenced by CPUInfo_GetCPUIDEAX(), CPUInfo_GetCPUIDEDX(), CPUInfo_GetCPUIDString(), GetCPUIDEAX(), GetCPUIDEDX(), GetCPUIDString(), GetCPUIDStringAMD(), and Test_CPU_bits().


Typedef Documentation

typedef unsigned __int64 QWORD
 

Definition at line 56 of file softdrv.c.


Function Documentation

DllExport BOOL DriverHook DRV_Driver **  Driver  ) 
 

Definition at line 326 of file softdrv.c.

References DRV_EngineSettings::CanSupportFlags, DllExport, DRV_ERROR_NONE, DRV_PREFERENCE_DRAW_WALPHA_IN_BSP, DRV_PREFERENCE_NO_MIRRORS, DRV_SUPPORT_ALPHA, DRV_SUPPORT_COLORKEY, DRV_Driver::EngineSettings, EngineSettings, LastErrorStr, DRV_Driver::LastErrorStr, DRV_EngineSettings::PreferenceFlags, SetLastDrvError(), SOFTDRV, and TRUE.

00327 {
00328         EngineSettings.CanSupportFlags = (DRV_SUPPORT_ALPHA|DRV_SUPPORT_COLORKEY);
00329         EngineSettings.PreferenceFlags = (DRV_PREFERENCE_NO_MIRRORS | DRV_PREFERENCE_DRAW_WALPHA_IN_BSP);
00330 
00331         SOFTDRV.EngineSettings = &EngineSettings;
00332 
00333         *Driver = &SOFTDRV;
00334 
00335         // Make sure the error string ptr is not null, or invalid!!!
00336         SOFTDRV.LastErrorStr = LastErrorStr;
00337 
00338         SetLastDrvError(DRV_ERROR_NONE, "SOFT_DRV:  No error.");
00339 
00340         return TRUE;
00341 }

geBoolean DRIVERCC Drv_SetFogEnable geBoolean  Enable,
geFloat  r,
geFloat  g,
geFloat  b,
geFloat  Start,
geFloat  End
 

Definition at line 255 of file softdrv.c.

References DRIVERCC, GE_FALSE, geBoolean, and r.

00256 {
00257         Enable,r,g,b,Start,End;
00258         return GE_FALSE;
00259 }

BOOL DRIVERCC DrvInit DRV_DriverHook Hook  ) 
 

Definition at line 98 of file softdrv.c.

References tagRECT::bottom, VidEnumInfoTag::bpp, bWindowed, ClientWindow, cmode, DoDDrawInit(), DoEnumeration(), DoModeEnumeration(), DRV_DriverHook::Driver, DRIVERCC, DRV_ERROR_INIT_ERROR, DRV_ERROR_NONE, DumpErrorLogToFile(), FALSE, GetCPUInfo(), CPUInfoTag::Has3DNow, DRV_DriverHook::Height, DRV_Window::Height, DRV_DriverHook::hWnd, tagRECT::left, DRV_DriverHook::Mode, VidEnumInfoTag::NumVidModes, DRV_Window::PixelPitch, ProcessorInfo, tagRECT::right, SAL_set_display_mode(), SAL_set_main_window(), SAL_startup(), SAL_WINDOW, SetDDrawMode(), SetLastDrvError(), SetupMiscConstants(), STRETCHMODE, SysInit(), tagRECT::top, TRUE, VidInfo, VidEnumInfoTag::VidModes, VInfo, DRV_DriverHook::Width, and DRV_Window::Width.

00099 {
00100         RECT    window_rect;    //for resetting (thanks mike!)
00101         BOOL    result;
00102 
00103         VInfo           =&VidInfo[Hook->Driver];
00104         VInfo->bpp      =16;
00105 
00106         GetCPUInfo();
00107 
00108         window_rect.left = -1;
00109         window_rect.top = -1;
00110         window_rect.right = -1;
00111         window_rect.bottom = -1;
00112                 
00113         SetLastError( ERROR_SUCCESS );
00114 
00115         DoEnumeration(VInfo);
00116         DoModeEnumeration(VInfo);
00117 
00118         //check for windowed mode
00119         if(Hook->Mode==VInfo->NumVidModes)
00120         {
00121                 bWindowed       =TRUE;
00122 
00123                 if (!SAL_startup(FALSE))
00124                 {
00125                         SetLastDrvError(DRV_ERROR_INIT_ERROR, "SOFT_DrvInit:  Could not initialize SAL.");
00126                         DumpErrorLogToFile("softdrv.log");
00127                         return FALSE;
00128                 }
00129 
00130                 result = GetClientRect(Hook->hWnd, &window_rect);
00131                 if( !result || window_rect.right == -1 || window_rect.bottom == -1 )
00132                 {
00133                         // This means you probably passed in an illegal hwnd.
00134                         int err = GetLastError();
00135                         assert( result );
00136                         DumpErrorLogToFile("softdrv.log");
00137                         return FALSE;
00138                 }
00139 
00140                 SAL_set_main_window(Hook->hWnd);
00141                 ClientWindow.Width  = (window_rect.right  - window_rect.left);
00142                 ClientWindow.Height = (window_rect.bottom - window_rect.top);
00143 
00144                 assert( ClientWindow.Width > 0 );
00145                 assert( ClientWindow.Height > 0 );
00146 
00147                 if(ProcessorInfo.Has3DNow)
00148                 {
00149                         if(!SAL_set_display_mode(ClientWindow.Width,
00150                                                                         ClientWindow.Height,
00151                                                                         32,
00152                                                                         SAL_WINDOW,
00153                                                                         TRUE))
00154                         {
00155                                 SetLastDrvError(DRV_ERROR_INIT_ERROR, "SOFT_DrvInit:  Could not set display mode.");
00156                                 DumpErrorLogToFile("softdrv.log");
00157                                 return  FALSE;
00158                         }
00159                 }
00160                 else
00161                 {
00162                         if(!SAL_set_display_mode(ClientWindow.Width,
00163                                                                         ClientWindow.Height,
00164                                                                         16,
00165                                                                         SAL_WINDOW,
00166                                                                         TRUE))
00167                         {
00168                                 SetLastDrvError(DRV_ERROR_INIT_ERROR, "SOFT_DrvInit:  Could not set display mode.");
00169                                 DumpErrorLogToFile("softdrv.log");
00170                                 return  FALSE;
00171                         }
00172                 }
00173         }
00174         else
00175         {
00176                 if(!DoDDrawInit(Hook->hWnd, VInfo))
00177                 {
00178                         DumpErrorLogToFile("softdrv.log");
00179                         return  FALSE;
00180                 }
00181                 ClientWindow.Width = Hook->Width;
00182                 ClientWindow.Height = Hook->Height;
00183                 if(VInfo->VidModes[Hook->Mode].flags & STRETCHMODE)
00184                 {
00185                         if(VInfo->VidModes[Hook->Mode].width > 640)
00186                         {
00187 //                              ClientWindow.Width      =640;
00188 //                              ClientWindow.Height     =(((geFloat)ClientWindow.Width)/(geFloat)Hook->Width)*(geFloat)Hook->Height;
00189                         }
00190                 }
00191 
00192                 if(!SetDDrawMode(Hook->Mode, VInfo))
00193                 {
00194                         return  FALSE;
00195                 }
00196                 ClientWindow.PixelPitch =VInfo->VidModes[Hook->Mode].pitch>>2;
00197                 cmode   =&VInfo->VidModes[Hook->Mode];
00198         }
00199 
00200         if(!SysInit())
00201         {       // LastDriverError should be set in here...
00202                 DumpErrorLogToFile("softdrv.log");
00203                 return  FALSE;          // so just return false, and assume it's set
00204         }
00205 
00206         SetLastDrvError(DRV_ERROR_NONE, "SOFT_DrvInit:  No error.");
00207         SetupMiscConstants();
00208 
00209         return  TRUE;
00210 }

BOOL DRIVERCC DrvShutdown void   ) 
 

Definition at line 212 of file softdrv.c.

References bWindowed, DRIVERCC, DumpErrorLogToFile(), FreeDDraw(), geBoolean, GMain_Shutdown(), SAL_shutdown(), SysShutdown(), TRUE, and VInfo.

00213 {
00214         SysShutdown();
00215 
00216         if(bWindowed)
00217         {
00218                 SAL_shutdown();
00219         }
00220         else
00221         {
00222                 FreeDDraw(VInfo);
00223         }
00224 
00225         DumpErrorLogToFile("softdrv.log");
00226 
00227         return  TRUE;
00228 }

geBoolean DRIVERCC DrvUpdateWindow void   ) 
 

Definition at line 250 of file softdrv.c.

References DRIVERCC, GE_TRUE, and geBoolean.

00251 {
00252         return  GE_TRUE;
00253 }

void DumpErrorLogToFile char *  fname  ) 
 

Definition at line 821 of file softdrv.c.

References buffer.

Referenced by BeginScene(), DrvInit(), DrvShutdown(), and ErrorBox().

00822 {
00823         FILE            *f;
00824         SYSTEMTIME      Time;
00825 
00826         f       =fopen(fname, "a+t");
00827 
00828         if(f)
00829         {
00830                 GetSystemTime(&Time);
00831 
00832                 fprintf(f,"=================================================================\n");
00833                 fprintf(f,"Time: %2i:%2i:%2i\n", Time.wHour, Time.wMinute, Time.wSecond);
00834                 fprintf(f,"Date: %2i-%2i-%4i\n", Time.wMonth, Time.wDay, Time.wYear);
00835 
00836                 fwrite(buffer, 1, strlen(buffer), f);
00837                 fclose(f);
00838         }
00839 }

BOOL DRIVERCC EnumModes S32  Driver,
char *  DriverName,
DRV_ENUM_MODES_CB Cb,
void *  Context
 

Definition at line 394 of file softdrv.c.

References tagRECT::bottom, VidModeListTag::bpp, VidEnumInfoTag::bpp, DoModeEnumeration(), DRIVERCC, VidModeListTag::flags, GetCPUInfo(), CPUInfoTag::Has3DNow, VidModeListTag::height, tagRECT::left, MODEXMODE, NumDevices, VidEnumInfoTag::NumVidModes, ProcessorInfo, tagRECT::right, STRETCHMODE, tagRECT::top, TRUE, VidInfo, VidEnumInfoTag::VidModes, VInfo, and VidModeListTag::width.

00395 {
00396         int             i;
00397         RECT    window_rect;    //for resetting (thanks mike!)
00398         char    szTemp[256];
00399 
00400         window_rect.left = -1;
00401         window_rect.top = -1;
00402         window_rect.right = -1;
00403         window_rect.bottom = -1;
00404                 
00405         SetLastError( ERROR_SUCCESS );
00406         VInfo           =&VidInfo[Driver];
00407         VInfo->bpp      =16;
00408 
00409         GetCPUInfo();
00410         if (!ProcessorInfo.Has3DNow)
00411                 return TRUE;
00412                 
00413         if(NumDevices)
00414         {
00415                 DoModeEnumeration(VInfo);
00416         }
00417 
00418         for(i=0;i < VInfo->NumVidModes;i++)
00419         {
00420                 if(VInfo->VidModes[i].flags & MODEXMODE)
00421                 {
00422                         sprintf(szTemp, "%dx%dx%d ModeX", VInfo->VidModes[i].width, VInfo->VidModes[i].height, VInfo->VidModes[i].bpp);
00423                         if(ProcessorInfo.Has3DNow)
00424                         {
00425                                 //strcat(szTemp, " 3DNow!");
00426                         }
00427                         Cb(i, szTemp, VInfo->VidModes[i].width, VInfo->VidModes[i].height, Context);
00428                 }
00429                 else if(VInfo->VidModes[i].flags & STRETCHMODE)
00430                 {
00431                         sprintf(szTemp, "%dx%dx%d Stretched", VInfo->VidModes[i].width, VInfo->VidModes[i].height, VInfo->VidModes[i].bpp);
00432                         if(ProcessorInfo.Has3DNow)
00433                         {
00434                                 //strcat(szTemp, " 3DNow!");
00435                         }
00436                         Cb(i, szTemp, VInfo->VidModes[i].width, VInfo->VidModes[i].height, Context);
00437                 }
00438                 else
00439                 {
00440                         sprintf(szTemp, "%dx%dx%d", VInfo->VidModes[i].width, VInfo->VidModes[i].height, VInfo->VidModes[i].bpp);
00441                         if(ProcessorInfo.Has3DNow)
00442                         {
00443                                 //strcat(szTemp, " 3DNow!");
00444                         }
00445                         Cb(i, szTemp, VInfo->VidModes[i].width, VInfo->VidModes[i].height, Context);
00446                 }
00447         }
00448         Cb(i, "Window Mode", -1, -1, Context);
00449 
00450         SetLastError( ERROR_SUCCESS );
00451 
00452         return TRUE;
00453 }

BOOL DRIVERCC EnumPixelFormats DRV_ENUM_PFORMAT_CB Cb,
void *  Context
 

Definition at line 98 of file D3ddrv7x.cpp.

References AppInfo, App_Info::ddsd, App_Info::ddSurfFormat, App_Info::ddTexFormat, DRIVERCC, geRDriver_PixelFormat::Flags, GE_PIXELFORMAT_16BIT_1555_ARGB, GE_PIXELFORMAT_16BIT_4444_ARGB, GE_PIXELFORMAT_16BIT_555_RGB, GE_PIXELFORMAT_16BIT_565_RGB, GE_PIXELFORMAT_24BIT_RGB, GE_PIXELFORMAT_32BIT_ARGB, GE_PIXELFORMAT_32BIT_XRGB, GE_TRUE, geBoolean, gePixelFormat, int32, geRDriver_PixelFormat::PixelFormat, PixelFormat, RDRIVER_PF_2D, RDRIVER_PF_3D, RDRIVER_PF_CAN_DO_COLORKEY, RDRIVER_PF_COMBINE_LIGHTMAP, RDRIVER_PF_LIGHTMAP, TRUE, and uint32.

00099 {
00100         int32                   i;
00101         gePixelFormat   Format3d, Format2d;
00102         uint32                  CurrentBpp;
00103 
00104         CurrentBpp = AppInfo.ddsd.ddpfPixelFormat.dwRGBBitCount;
00105 
00106         // Setup the 2d surface format
00107         if (CurrentBpp == 32 && AppInfo.ddSurfFormat.ddpfPixelFormat.dwRGBAlphaBitMask == 0xff000000)
00108                 Format2d = GE_PIXELFORMAT_32BIT_ARGB;
00109         else if (CurrentBpp == 32 && AppInfo.ddSurfFormat.ddpfPixelFormat.dwBBitMask == 0xff)
00110                 Format2d = GE_PIXELFORMAT_32BIT_XRGB;
00111         else if (CurrentBpp == 24 && AppInfo.ddSurfFormat.ddpfPixelFormat.dwBBitMask == 0xff)
00112                 Format2d = GE_PIXELFORMAT_24BIT_RGB;
00113         else if (AppInfo.ddSurfFormat.ddpfPixelFormat.dwGBitMask == (31<<5))
00114                 Format2d = GE_PIXELFORMAT_16BIT_555_RGB;
00115         else
00116                 Format2d = GE_PIXELFORMAT_16BIT_565_RGB;
00117 
00118         // Setup the 3d (Texture) format
00119         if (AppInfo.ddTexFormat.ddpfPixelFormat.dwGBitMask == (31<<5))
00120                 Format3d = GE_PIXELFORMAT_16BIT_555_RGB;
00121         else
00122                 Format3d = GE_PIXELFORMAT_16BIT_565_RGB;
00123 
00124 
00125         // Create the surface formats now
00126         PixelFormat[0].PixelFormat = Format3d;                                                  // 3d 565/555 surface
00127         PixelFormat[0].Flags = RDRIVER_PF_3D | RDRIVER_PF_COMBINE_LIGHTMAP;
00128                 
00129         PixelFormat[1].PixelFormat = GE_PIXELFORMAT_16BIT_4444_ARGB;    // 3d 4444 surface
00130         PixelFormat[1].Flags = RDRIVER_PF_3D | RDRIVER_PF_COMBINE_LIGHTMAP;
00131 
00132         PixelFormat[2].PixelFormat = Format2d;                                                  // 2d 565/555 surface
00133         PixelFormat[2].Flags = RDRIVER_PF_2D | RDRIVER_PF_CAN_DO_COLORKEY;
00134 
00135         PixelFormat[3].PixelFormat = Format3d;                                                  // Lightmap 565/555 surface
00136         PixelFormat[3].Flags = RDRIVER_PF_LIGHTMAP;
00137 
00138         PixelFormat[4].PixelFormat = GE_PIXELFORMAT_16BIT_1555_ARGB;    
00139         PixelFormat[4].Flags = RDRIVER_PF_3D | RDRIVER_PF_COMBINE_LIGHTMAP;
00140 
00141         // Then hand them off to the caller
00142         for (i=0; i<5; i++)
00143         {
00144                 if (!Cb(&PixelFormat[i], Context))
00145                         return GE_TRUE;
00146         }
00147 
00148         return TRUE;
00149 }

BOOL DRIVERCC EnumSubDrivers DRV_ENUM_DRV_CB Cb,
void *  Context
 

Definition at line 131 of file GlideDrv.c.

References DRIVERCC, DRV_VMAJS, DRV_VMINS, g_BoardInfo, GE_TRUE, geBoolean, GMain_GetBoardInfo(), and GMain_BoardInfo::MainRam.

00132 {
00133         // Initialize the Glide library 
00134         grGlideInit();
00135 
00136         // Get the info about this board
00137         if (!GMain_GetBoardInfo(&g_BoardInfo))
00138                 return GE_TRUE;
00139 
00140         if (g_BoardInfo.MainRam == 0)
00141                 return GE_TRUE;                         // No modes, so don't return any drivers
00142 
00143         if (!Cb(0, "Glide Driver v"DRV_VMAJS"."DRV_VMINS".", Context))
00144                 return GE_TRUE;
00145 
00146         // Shutdown Glide library
00147         grGlideShutdown();
00148 
00149         return GE_TRUE;
00150 }

void DRIVERCC ErrorBox char *  Str  ) 
 

Definition at line 230 of file softdrv.c.

References DRIVERCC, DrvShutdown(), and DumpErrorLogToFile().

00231 {
00232         DrvShutdown();
00233         DumpErrorLogToFile("softdrv.log");
00234 }

void ErrorPrintf char *  text,
... 
 

Definition at line 810 of file softdrv.c.

References buf3, and buffer.

Referenced by DDrawBlitDecal(), DDrawBlitDecalToFront(), DDrawDriverEnumCallbackEx(), DoDDrawInit(), DoEnumeration(), DoModeEnumeration(), DrvSetActive(), GetCPUInfo(), LockDDrawBackBuffer(), RefreshDDraw(), RestoreAll(), and UnlockDDrawBackBuffer().

00811 {
00812         va_list argptr;
00813 
00814         va_start(argptr,text);
00815         vsprintf(buf3, text,argptr);
00816         va_end(argptr);
00817 
00818         strcat(buffer, buf3);
00819 }

U32 GetCPUIDEAX U32  funcNum  )  [static]
 

Definition at line 617 of file softdrv.c.

References CPUID, Flag_CPUID, Test_CPU_bits(), and U32.

Referenced by GetCPUInfo().

00618 {
00619         U32     retval;
00620 
00621         Test_CPU_bits();
00622         if (Flag_CPUID)
00623                 {
00624                         __try
00625                         {
00626                                 _asm
00627                                 {
00628                                         mov     eax,funcNum
00629                                         CPUID
00630                                         mov     retval,eax
00631                                 }
00632                         }__except(EXCEPTION_EXECUTE_HANDLER)
00633                         {
00634                                 retval  =0;
00635                         }
00636                 }
00637         else
00638                 {
00639                         retval = 0;
00640                 }
00641 
00642         return  retval;
00643 }

U32 GetCPUIDEDX U32  funcNum  )  [static]
 

Definition at line 645 of file softdrv.c.

References CPUID, Flag_CPUID, Test_CPU_bits(), and U32.

Referenced by GetCPUInfo().

00646 {
00647         U32     retval;
00648 
00649         Test_CPU_bits();
00650         if (Flag_CPUID)
00651                 {
00652                         __try
00653                         {
00654                                 _asm
00655                                 {
00656                                         mov     eax,funcNum
00657                                         CPUID
00658                                         mov     retval,edx
00659                                 }
00660                         }__except(EXCEPTION_EXECUTE_HANDLER)
00661                         {
00662                                 retval  =0;
00663                         }
00664                 }
00665         else
00666                 {
00667                         retval = 0;
00668                 }
00669         
00670         return  retval;
00671 }

U32 GetCPUIDString U32  funcNum,
char *  szId
[static]
 

Definition at line 673 of file softdrv.c.

References CPUID, Flag_CPUID, Test_CPU_bits(), and U32.

Referenced by GetCPUInfo().

00674 {
00675         U32     retval;
00676 
00677         Test_CPU_bits();
00678         if (Flag_CPUID)
00679                 {
00680                         __try
00681                         {
00682                                 _asm
00683                                 {
00684                                         mov     eax,funcNum
00685                                         CPUID
00686                                         mov     retval,eax
00687                                         mov     eax,szId
00688                                         mov     dword ptr[eax],ebx
00689                                         mov     dword ptr[eax+4],edx
00690                                         mov     dword ptr[eax+8],ecx
00691                                 }
00692                         }__except(EXCEPTION_EXECUTE_HANDLER)
00693                         {
00694                                 retval  =0;
00695                         }
00696                 }
00697         else
00698                 {
00699                         retval = 0;
00700                 }
00701 
00702         return  retval;
00703 }

void GetCPUIDStringAMD U32  funcNum,
char *  szId
[static]
 

Definition at line 705 of file softdrv.c.

References CPUID, Flag_CPUID, Test_CPU_bits(), and U32.

Referenced by GetCPUInfo().

00706 {
00707         U32     retval;
00708         
00709         Test_CPU_bits();
00710         if (Flag_CPUID)
00711                 {
00712                         __try
00713                                 {
00714                                         _asm
00715                                         {
00716                                                 mov eax,funcNum
00717                                                 CPUID
00718                                                 mov     retval,eax
00719                                                 mov     eax,szId
00720                                                 mov     dword ptr[eax+4],ebx
00721                                                 mov     dword ptr[eax+8],ecx
00722                                                 mov     ebx,retval
00723                                                 mov     dword ptr[eax+12],edx
00724                                                 mov     dword ptr[eax],ebx
00725                                         }
00726                                 }__except(EXCEPTION_EXECUTE_HANDLER)
00727                                 {
00728                                         retval  =0;
00729                                 }
00730                 }
00731         else
00732                 {
00733                         retval = 0;
00734                 }
00735 }

void GetCPUInfo void   )  [static]
 

Definition at line 841 of file softdrv.c.

References VidEnumInfoTag::bpp, ErrorPrintf(), FALSE, GetCPUIDEAX(), GetCPUIDEDX(), GetCPUIDString(), GetCPUIDStringAMD(), CPUInfoTag::Has3DNow, CPUInfoTag::HasFCMOV, CPUInfoTag::HasMMX, CPUInfoTag::HasRDTSC, CPUInfoTag::MaxCPUIDVal, NULL, ProcessorInfo, CPUInfoTag::ProcFamily, CPUInfoTag::ProcModel, CPUInfoTag::ProcName, CPUInfoTag::ProcSpeed, CPUInfoTag::ProcStepping, CPUInfoTag::ProcType, TRUE, U32, CPUInfoTag::VendorString, and VInfo.

Referenced by DrvInit(), and EnumModes().

00842 {
00843         memset(&ProcessorInfo, 0, sizeof(ProcessorInfo));
00844 
00845         ProcessorInfo.MaxCPUIDVal               =GetCPUIDString(0, ProcessorInfo.VendorString);
00846         ProcessorInfo.VendorString[13]  =0;
00847         if(strncmp(ProcessorInfo.VendorString, "AuthenticAMD", 12)==0)
00848         {
00849                 U32     TypeFlags       =GetCPUIDEAX(0x80000000);
00850                 if(TypeFlags)   //extended functions supported
00851                 {
00852                         TypeFlags       =GetCPUIDEDX(0x80000001);
00853                         GetCPUIDStringAMD(0x80000002, ProcessorInfo.ProcName);
00854                         GetCPUIDStringAMD(0x80000003, ProcessorInfo.ProcName+16);
00855                         GetCPUIDStringAMD(0x80000004, ProcessorInfo.ProcName+32);
00856                         ErrorPrintf("CPU Family:  %s\n", ProcessorInfo.ProcName);
00857                         ProcessorInfo.HasMMX            =TypeFlags & (1<<23);
00858                         ProcessorInfo.Has3DNow          =TypeFlags & (1<<31);
00859                         ProcessorInfo.HasFCMOV          =TypeFlags & (1<<16);
00860                         ProcessorInfo.HasRDTSC          =TypeFlags & (1<<4);
00861                 }
00862                 else
00863                 {
00864                         U32     TypeFlags                               =GetCPUIDEDX(0x1);
00865                         ProcessorInfo.HasMMX            =TypeFlags & (1<<23);
00866                         ProcessorInfo.HasFCMOV          =((TypeFlags & (1<<15 | 1))==(1<<15 | 1))? TRUE : FALSE;
00867                         ProcessorInfo.HasRDTSC          =TypeFlags & (1<<4);
00868                 }
00869                 TypeFlags                                       =GetCPUIDEAX(1);
00870                 ProcessorInfo.ProcType          =(TypeFlags>>12)&0x3;
00871                 ProcessorInfo.ProcFamily        =(TypeFlags>>8)&0xf;
00872                 ProcessorInfo.ProcModel         =(TypeFlags>>4)&0xf;
00873                 ProcessorInfo.ProcStepping      =(TypeFlags)&0x7;
00874                 //ProcessorInfo.ProcSpeed               =GetProcessorSpeed();
00875         }
00876         else if(strncmp(ProcessorInfo.VendorString, "GenuineIntel", 12)==0)
00877         {
00878                 U32     TypeFlags                               =GetCPUIDEDX(0x1);
00879                 ProcessorInfo.HasMMX            =TypeFlags & (1<<23);
00880                 ProcessorInfo.HasFCMOV          =((TypeFlags & (1<<15 | 1))==(1<<15 | 1))? TRUE : FALSE;
00881                 ProcessorInfo.HasRDTSC          =TypeFlags & (1<<4);
00882 
00883                 TypeFlags                                       =GetCPUIDEAX(1);
00884                 ProcessorInfo.ProcType          =(TypeFlags>>12)&0x3;
00885                 ProcessorInfo.ProcFamily        =(TypeFlags>>8)&0xf;
00886                 ProcessorInfo.ProcModel         =(TypeFlags>>4)&0xf;
00887                 ProcessorInfo.ProcStepping      =(TypeFlags)&0x7;
00888                 //ProcessorInfo.ProcSpeed               =GetProcessorSpeed();
00889 
00890                 ErrorPrintf("CPU Family:  %d\n", ProcessorInfo.ProcFamily);
00891                 ErrorPrintf("CPU Model:  %d\n", ProcessorInfo.ProcModel);
00892         }
00893         else
00894         {
00895                 U32     TypeFlags       =GetCPUIDEAX(0x80000000);
00896                 if(TypeFlags)   //extended functions supported
00897                 {
00898                         TypeFlags       =GetCPUIDEDX(0x80000001);
00899                         GetCPUIDStringAMD(0x80000002, ProcessorInfo.ProcName);
00900                         GetCPUIDStringAMD(0x80000003, ProcessorInfo.ProcName+16);
00901                         GetCPUIDStringAMD(0x80000004, ProcessorInfo.ProcName+32);
00902                         ErrorPrintf("CPU Family:  %s\n", ProcessorInfo.ProcName);
00903                         ProcessorInfo.HasMMX            =TypeFlags & (1<<23);
00904                         ProcessorInfo.Has3DNow          =TypeFlags & (1<<31);
00905                         ProcessorInfo.HasFCMOV          =TypeFlags & (1<<16);
00906                         ProcessorInfo.HasRDTSC          =TypeFlags & (1<<4);
00907                 }
00908                 else
00909                 {
00910                         U32     TypeFlags                               =GetCPUIDEDX(0x1);
00911                         ProcessorInfo.HasMMX            =TypeFlags & (1<<23);
00912                         ProcessorInfo.HasFCMOV          =((TypeFlags & (1<<15 | 1))==(1<<15 | 1))? TRUE : FALSE;
00913                         ProcessorInfo.HasRDTSC          =TypeFlags & (1<<4);
00914                 }
00915                 TypeFlags                                       =GetCPUIDEAX(1);
00916                 ProcessorInfo.ProcType          =(TypeFlags>>12)&0x3;
00917                 ProcessorInfo.ProcFamily        =(TypeFlags>>8)&0xf;
00918                 ProcessorInfo.ProcModel         =(TypeFlags>>4)&0xf;
00919                 ProcessorInfo.ProcStepping      =(TypeFlags)&0x7;
00920                 //ProcessorInfo.ProcSpeed               =GetProcessorSpeed();
00921         }
00922 
00923         ErrorPrintf("CPU Vendor String:  %s\n", ProcessorInfo.VendorString);
00924         ErrorPrintf("Processor Speed:  %d\n", ProcessorInfo.ProcSpeed);
00925         ErrorPrintf("Stepping:  %d\n", ProcessorInfo.ProcStepping);
00926         if(ProcessorInfo.HasMMX)
00927         {
00928                 ErrorPrintf("MMX instructions detected\n");
00929         }
00930         if(ProcessorInfo.Has3DNow)
00931         {
00932                 if (VInfo!=NULL)
00933                 {
00934                         VInfo->bpp      =32;
00935                         ErrorPrintf("3DNow instructions detected\n");
00936                 }
00937         }
00938         if(ProcessorInfo.HasFCMOV)
00939         {
00940                 ErrorPrintf("FCMOV feature detected\n");
00941         }
00942         if(ProcessorInfo.HasRDTSC)
00943         {
00944                 ErrorPrintf("Time Stamp Counter feature detected\n");
00945         }
00946 }

BOOL DRIVERCC GetDrvRenderState S32  State,
U32 Flag
 

Definition at line 573 of file softdrv.c.

References DRIVERCC, and TRUE.

00574 {
00575         *Flag = 0;
00576         return TRUE;
00577 }

BOOL DRIVERCC GetGamma geFloat Gamma  ) 
 

Definition at line 241 of file softdrv.c.

References DRIVERCC, and TRUE.

00242 {
00243         assert(Gamma);
00244 
00245         *Gamma = 1.0f;
00246 
00247         return TRUE;
00248 }

BOOL DRIVERCC ScreenShot const char *  Name  ) 
 

Definition at line 357 of file OGLDrv.c.

00358 {
00359         unsigned char tgaHeader[18];
00360         GLubyte *buffer;
00361         FILE *fp;
00362         char *newName;
00363         int nameLen;
00364 
00365         buffer = (GLubyte *)malloc(sizeof(GLubyte) * ClientWindow.Width * ClientWindow.Height * 3);     
00366 
00367         glFinish();
00368 
00369         glReadPixels(0, 0, ClientWindow.Width, ClientWindow.Height, 
00370                 GL_BGR_EXT, GL_UNSIGNED_BYTE, buffer);
00371  
00372         memset(tgaHeader, 0, sizeof(tgaHeader));
00373         tgaHeader[2] = 2;
00374         tgaHeader[12] = (unsigned char)ClientWindow.Width;
00375         tgaHeader[13] = (unsigned char)((unsigned long)ClientWindow.Width >> 8);
00376         tgaHeader[14] = (unsigned char)ClientWindow.Height;
00377         tgaHeader[15] = (unsigned char)((unsigned long)ClientWindow.Height >> 8);
00378         tgaHeader[16] = 24;
00379  
00380         // Convert the extention (if one exists) to .tga.  They probably expect a .bmp.
00381         newName = strdup(Name);
00382 
00383         nameLen = strlen(newName);
00384 
00385         if(nameLen > 3)
00386         {
00387                 if(newName[nameLen - 4] == '.')
00388                 {
00389                         strcpy(newName + nameLen - 3, "tga");
00390                 }
00391         }
00392 
00393     fp = fopen(newName, "wb");
00394     
00395         free(newName);
00396 
00397         if(fp == NULL) 
00398         {
00399                 free(buffer);
00400         return GE_FALSE;
00401     }
00402  
00403     fwrite(tgaHeader, 1, 18, fp);
00404     fwrite(buffer, 3, ClientWindow.Width * ClientWindow.Height, fp);
00405     fclose(fp);
00406  
00407         free(buffer);
00408         
00409         return GE_TRUE;
00410 }

BOOL DRIVERCC SetDrvRenderState S32  State,
U32  Flag
 

Definition at line 568 of file softdrv.c.

References DRIVERCC, and TRUE.

00569 {
00570         return TRUE;
00571 }

BOOL DRIVERCC SetGamma geFloat  Gamma  ) 
 

Definition at line 236 of file softdrv.c.

References DRIVERCC, and TRUE.

00237 {
00238         return TRUE;
00239 }

void SetLastDrvError S32  Error,
char *  ErrorStr
 

Definition at line 343 of file softdrv.c.

00344 {
00345         LastError = Error;
00346         
00347         if (ErrorStr)
00348         {
00349                 strcpy(LastErrorStr, ErrorStr);
00350         }
00351         else
00352                 LastErrorStr[0] = 0;
00353 
00354         SOFTDRV.LastErrorStr = LastErrorStr;
00355         SOFTDRV.LastError = LastError;
00356 }

void SetupMiscConstants void   ) 
 

Definition at line 76 of file softdrv.c.

References geFloat, Magic, MipMagic, MipMagic2, Q128, QFixedScale, QFixedScale16, QZBufferPrec, and ZBUFFER_PREC.

Referenced by DrvInit().

00077 {
00078         *(((geFloat *)((&QZBufferPrec)))+1)     =-ZBUFFER_PREC;
00079         *((geFloat *)(&QZBufferPrec))                   =-ZBUFFER_PREC;
00080 
00081         *(((geFloat *)((&QFixedScale16)))+1)    =4096.0f;
00082         *((geFloat *)(&QFixedScale16))          =4096.0f;
00083 
00084         *(((geFloat *)((&QFixedScale)))+1)      =65536.0f;
00085         *((geFloat *)(&QFixedScale))                    =65536.0f;
00086 
00087         *((geFloat *)&Q128)                                     =128.0f;
00088         *(((geFloat *)((&Q128)))+1)                     =128.0f;
00089 
00090         Magic           =ldexp(1.5, 60);
00091         MipMagic        =ldexp(1.5, 52-16);
00092         MipMagic2       =ldexp(1.5, 52-12);
00093 }

void Test_CPU_bits void   ) 
 

Definition at line 583 of file softdrv.c.

References CPUID, FALSE, Flag_CPUID, and Flag_RDTSC.

Referenced by CPUInfo_GetCPUIDEAX(), CPUInfo_GetCPUIDEDX(), CPUInfo_GetCPUIDString(), GetCPUIDEAX(), GetCPUIDEDX(), GetCPUIDString(), and GetCPUIDStringAMD().

00584 {
00585         Flag_CPUID = FALSE;
00586         Flag_RDTSC = FALSE;
00587 _asm
00588     {
00589         pushad                    // (1) play nice and save everything
00590     pushfd                    // eax = ebx = extended flags
00591     pop     eax                              
00592     mov     ebx,eax
00593 
00594     xor     eax,200000h       // toggle bit 21
00595 
00596     push    eax               // extended flags = eax
00597         popfd
00598     xor     eax,ebx           // if bit 21 r/w then eax <> 0
00599 
00600     jz      done              // can't toggle id bit (21) no cpuid here
00601     mov     eax,1             // get standard features
00602     mov     Flag_CPUID,eax    // (and set cpuid flag to true)
00603 
00604         CPUID
00605     test    edx,10h           // is rdtsc available?
00606     jz      done
00607 
00608     mov     Flag_RDTSC,1
00609 done:
00610         popad                     // (1) restore everything
00611     }
00612 }


Variable Documentation

char buf3[4096] [static]
 

Definition at line 808 of file softdrv.c.

Referenced by ErrorPrintf().

char buffer[32768] [static]
 

Definition at line 807 of file softdrv.c.

Referenced by DumpErrorLogToFile(), and ErrorPrintf().

DRV_CacheInfo CacheInfo [static]
 

Definition at line 38 of file softdrv.c.

DRV_Window ClientWindow = { 0 }
 

Definition at line 43 of file softdrv.c.

VidModeList* cmode
 

Definition at line 42 of file softdrv.c.

DRV_EngineSettings EngineSettings
 

Definition at line 324 of file softdrv.c.

int Flag_CPUID = FALSE
 

Definition at line 579 of file softdrv.c.

Referenced by CPUInfo_GetCPUIDEAX(), CPUInfo_GetCPUIDEDX(), CPUInfo_GetCPUIDString(), GetCPUIDEAX(), GetCPUIDEDX(), GetCPUIDString(), GetCPUIDStringAMD(), and Test_CPU_bits().

int Flag_RDTSC = FALSE
 

Definition at line 580 of file softdrv.c.

Referenced by Test_CPU_bits().

S32 LastError
 

Definition at line 47 of file softdrv.c.

char LastErrorStr[200]
 

Definition at line 48 of file softdrv.c.

double Magic
 

Definition at line 74 of file softdrv.c.

double MipMagic
 

Definition at line 74 of file softdrv.c.

Referenced by DrawSpan16_8AsmLitX86FPU(), DrawSpan16_AsmGouraudX86FPU(), DrawSpan16_AsmGouraudZBuffer555X86FPU(), DrawSpan16_AsmGouraudZBufferTrans555X86FPU(), DrawSpan16_AsmGouraudZBufferTransX86FPU(), DrawSpan16_AsmGouraudZBufferX86FPU(), DrawSpan16_AsmGouraudZWrite555X86FPU(), DrawSpan16_AsmGouraudZWriteX86FPU(), DrawSpan16_AsmLit555X86FPU(), DrawSpan16_AsmLitX86FPU(), DrawSpan16_AsmLitZBuffer555X86FPU(), DrawSpan16_AsmLitZBufferX86FPU(), DrawSpan16_AsmLitZWrite555X86FPU(), DrawSpan16_AsmLitZWriteX86FPU(), DrawSpan16_AsmX86FPU(), and SetupMiscConstants().

double MipMagic2
 

Definition at line 74 of file softdrv.c.

Referenced by DrawSpan16_8AsmLitX86FPU(), DrawSpan16_AsmGouraudX86FPU(), DrawSpan16_AsmGouraudZBuffer555X86FPU(), DrawSpan16_AsmGouraudZBufferTrans555X86FPU(), DrawSpan16_AsmGouraudZBufferTransX86FPU(), DrawSpan16_AsmGouraudZBufferX86FPU(), DrawSpan16_AsmGouraudZWrite555X86FPU(), DrawSpan16_AsmGouraudZWriteX86FPU(), DrawSpan16_AsmLit555X86FPU(), DrawSpan16_AsmLitX86FPU(), DrawSpan16_AsmLitZBuffer555X86FPU(), DrawSpan16_AsmLitZBufferX86FPU(), DrawSpan16_AsmLitZWrite555X86FPU(), DrawSpan16_AsmLitZWriteX86FPU(), DrawSpan16_AsmX86FPU(), and SetupMiscConstants().

int NumDevices = 0
 

Definition at line 45 of file softdrv.c.

CPUInfo ProcessorInfo = { 0 }
 

Definition at line 44 of file softdrv.c.

__int64 Q128 = 0
 

Definition at line 73 of file softdrv.c.

Referenced by SetupMiscConstants().

__int64 QFixedScale = 0
 

Definition at line 71 of file softdrv.c.

Referenced by SetupMiscConstants().

__int64 QFixedScale16 = 0
 

Definition at line 72 of file softdrv.c.

Referenced by SetupMiscConstants().

__int64 QZBufferPrec = 0
 

Definition at line 70 of file softdrv.c.

Referenced by SetupMiscConstants().

DRV_Driver SOFTDRV
 

Definition at line 261 of file softdrv.c.

Referenced by AddSpanDraw(), DriverHook(), RenderWorldPoly(), SetLastDrvError(), and SoftDrv_LightMapSetupCallback().

VidEnumInfo VidInfo[16] [static]
 

Definition at line 39 of file softdrv.c.

Referenced by DrvInit(), and EnumModes().

VidEnumInfo* VInfo [static]
 

Definition at line 40 of file softdrv.c.

Referenced by DrvInit(), DrvShutdown(), EnumModes(), and GetCPUInfo().


Generated on Tue Sep 30 12:38:06 2003 for GTestAndEngine by doxygen 1.3.2