diff --git a/Cxbx.opt b/Cxbx.opt index 4f7bdd37e..5d3b2ce41 100644 Binary files a/Cxbx.opt and b/Cxbx.opt differ diff --git a/CxbxKrnl.dsp b/CxbxKrnl.dsp index c21c7fef0..3f3094d04 100644 --- a/CxbxKrnl.dsp +++ b/CxbxKrnl.dsp @@ -43,7 +43,7 @@ RSC=rc.exe # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CXBXKRNL_EXPORTS" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GX /O2 /I "Include" /I "Include/Core/" /I "Include/Win32/" /I "Include/Win32/Cxbx" /I "Include/Win32/CxbxKrnl" /I "Include/Win32/CxbxKrnl/HLEDataBase" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CXBXKRNL_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /O2 /I "Include" /I "Include/Core/" /I "Include/Win32/" /I "Include/Win32/Cxbx" /I "Include/Win32/CxbxKrnl" /I "Include/Win32/CxbxKrnl/HLEDataBase" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CXBXKRNL_EXPORTS" /YX /FD /c # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x409 /d "NDEBUG" @@ -53,8 +53,8 @@ BSC32=bscmake.exe # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 -# ADD LINK32 ws2_32.lib dsound.lib winmm.lib ddraw.lib d3dx8.lib d3d8.lib dinput8.lib dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /map /machine:I386 /out:"Bin/Cxbx.dll" /libpath:"Lib" -# SUBTRACT LINK32 /profile /pdb:none /debug +# ADD LINK32 ws2_32.lib dsound.lib winmm.lib ddraw.lib d3dx8.lib d3d8.lib dinput8.lib dxguid.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /pdb:none /machine:I386 /out:"Bin/Cxbx.dll" /libpath:"Lib" +# SUBTRACT LINK32 /profile /map /debug !ELSEIF "$(CFG)" == "CxbxKrnl - Win32 Debug" @@ -326,6 +326,10 @@ SOURCE=.\Include\Win32\CxbxKrnl\OOVPA.h # End Source File # Begin Source File +SOURCE=.\Include\Win32\CxbxKrnl\ResourceTracker.h +# End Source File +# Begin Source File + SOURCE=.\Include\Win32\XBController.h # End Source File # Begin Source File @@ -571,6 +575,10 @@ SOURCE=.\Source\Win32\Mutex.cpp # End Source File # Begin Source File +SOURCE=.\Source\Win32\CxbxKrnl\ResourceTracker.cpp +# End Source File +# Begin Source File + SOURCE=.\Source\Win32\XBController.cpp # End Source File # Begin Source File diff --git a/Include/Cxbx.h b/Include/Cxbx.h index 76640a74c..d977fe969 100644 --- a/Include/Cxbx.h +++ b/Include/Cxbx.h @@ -54,14 +54,15 @@ typedef signed char sint08; typedef signed short sint16; typedef signed long sint32; -// define this to track vertex buffers for debugging purposes -#define _DEBUG_TRACK_VB +// define this to track resources for debugging purposes +//#define _DEBUG_TRACK_VB // Vertex Buffers +//#define _DEBUG_TRACK_PB // Push Buffers // define this to trace intercepted function calls -#define _DEBUG_TRACE +//#define _DEBUG_TRACE // define this to trace warnings -#define _DEBUG_WARNINGS +//#define _DEBUG_WARNINGS // version information #ifndef _DEBUG_TRACE diff --git a/Include/Win32/CxbxKrnl/EmuD3D8/VertexBuffer.h b/Include/Win32/CxbxKrnl/EmuD3D8/VertexBuffer.h index d4b719f59..431baf892 100644 --- a/Include/Win32/CxbxKrnl/EmuD3D8/VertexBuffer.h +++ b/Include/Win32/CxbxKrnl/EmuD3D8/VertexBuffer.h @@ -36,43 +36,6 @@ #include "Cxbx.h" -#ifdef _DEBUG_TRACK_VB - -struct VBNode -{ - XTL::IDirect3DVertexBuffer8 *vb; - VBNode *next; -}; - -extern bool g_bVBSkipStream; - -extern class VBTracker -{ - public: - VBTracker() : m_head(0), m_tail(0) {} - ~VBTracker(); - - // insert a ptr - void insert(XTL::IDirect3DVertexBuffer8 *pVB); - - // remove a ptr - void remove(XTL::IDirect3DVertexBuffer8 *pVB); - - // check for existance of ptr - bool exists(XTL::IDirect3DVertexBuffer8 *pVB); - - // for traversal - VBNode *getHead() { return m_head; } - - private: - // list of "live" vertex buffers for debugging purposes - VBNode *m_head; - VBNode *m_tail; -} -g_VBTrackTotal, g_VBTrackDisable; - -#endif - // fixup xbox extensions to be compatible with PC direct3d extern UINT EmuFixupVerticesA ( diff --git a/Include/Win32/CxbxKrnl/EmuD3D8Types.h b/Include/Win32/CxbxKrnl/EmuD3D8Types.h index 0949f9e6b..d5e014734 100644 --- a/Include/Win32/CxbxKrnl/EmuD3D8Types.h +++ b/Include/Win32/CxbxKrnl/EmuD3D8Types.h @@ -186,6 +186,7 @@ struct X_D3DResource #define X_D3DRESOURCE_DATA_FLAG_SURFACE 0xEFFFFFFF #define X_D3DRESOURCE_DATA_FLAG_YUVSURF 0xDFFFFFFF #define X_D3DRESOURCE_DATA_FLAG_D3DREND 0xCFFFFFFF // D3D Render Target +#define X_D3DRESOURCE_DATA_FLAG_D3DSTEN 0xBFFFFFFF // D3D Stencil Surface // special resource lock flags #define X_D3DRESOURCE_LOCK_FLAG_NOSIZE 0xEFFFFFFF diff --git a/Include/Win32/CxbxKrnl/ResourceTracker.h b/Include/Win32/CxbxKrnl/ResourceTracker.h new file mode 100644 index 000000000..682c64f64 --- /dev/null +++ b/Include/Win32/CxbxKrnl/ResourceTracker.h @@ -0,0 +1,75 @@ +// ****************************************************************** +// * +// * .,-::::: .,:: .::::::::. .,:: .: +// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;; +// * [[[ '[[,,[[' [[[__[[\. '[[,,[[' +// * $$$ Y$$$P $$""""Y$$ Y$$$P +// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo, +// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm, +// * +// * Cxbx->Win32->CxbxKrnl->ResourceTracker.h +// * +// * This file is part of the Cxbx project. +// * +// * Cxbx and Cxbe are free software; you can redistribute them +// * and/or modify them under the terms of the GNU General Public +// * License as published by the Free Software Foundation; either +// * version 2 of the license, or (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have recieved a copy of the GNU General Public License +// * along with this program; see the file COPYING. +// * If not, write to the Free Software Foundation, Inc., +// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA. +// * +// * (c) 2002-2003 Aaron Robinson +// * +// * All rights reserved +// * +// ****************************************************************** +#ifndef RESOURCETRACKER_H +#define RESOURCETRACKER_H + +#include "Cxbx.h" +#include "Mutex.h" + +extern bool g_bVBSkipStream; +extern bool g_bPBSkipPusher; + +extern class ResourceTracker : public Mutex +{ + public: + ResourceTracker() : m_head(0), m_tail(0) {}; + ~ResourceTracker(); + + // insert a ptr + void insert(void *pResource); + + // remove a ptr + void remove(void *pResource); + + // check for existance of ptr + bool exists(void *pResource); + + // for traversal + struct RTNode *getHead() { return m_head; } + + private: + // list of "live" vertex buffers for debugging purposes + struct RTNode *m_head; + struct RTNode *m_tail; +} +g_VBTrackTotal, g_VBTrackDisable, +g_PBTrackTotal, g_PBTrackDisable; + +struct RTNode +{ + void *pResource; + RTNode *pNext; +}; + +#endif diff --git a/Include/Win32/Mutex.h b/Include/Win32/Mutex.h index 819dccd45..dbd331641 100644 --- a/Include/Win32/Mutex.h +++ b/Include/Win32/Mutex.h @@ -36,31 +36,16 @@ #include -// ****************************************************************** -// * Mutex object (intended to be inherited from) -// ****************************************************************** +// mutex object (intended to be inherited from) class Mutex { public: - // ****************************************************************** - // * Constructor - // ****************************************************************** Mutex(); - // ****************************************************************** - // * Lock critical section - // ****************************************************************** void Lock(); - - // ****************************************************************** - // * Unlock critical section - // ****************************************************************** void Unlock(); private: - // ****************************************************************** - // * Critical section - // ****************************************************************** LONG m_MutexLock; // Mutex lock LONG m_OwnerProcess; // Current owner process (or zero) LONG m_OwnerThread; // Current owner thread diff --git a/Source/Win32/CxbxKrnl/DbgConsole.cpp b/Source/Win32/CxbxKrnl/DbgConsole.cpp index f89a46f4c..c44764052 100644 --- a/Source/Win32/CxbxKrnl/DbgConsole.cpp +++ b/Source/Win32/CxbxKrnl/DbgConsole.cpp @@ -37,6 +37,7 @@ #include "Emu.h" #include "DbgConsole.h" +#include "ResourceTracker.h" #include @@ -115,40 +116,50 @@ void DbgConsole::Reset() } #ifdef _DEBUG_TRACK_VB -static void EnableVB(int n, bool enable) +static void EnableTracker(ResourceTracker &trackTotal, ResourceTracker &trackDisable, int a, int b, bool enable) { - using namespace XTL; - int v=0; - VBNode *cur = g_VBTrackTotal.getHead(); + trackTotal.Lock(); - for(v=0;vnext == NULL)) + if(cur == NULL || (cur->pNext == NULL)) break; - cur = cur->next; + cur = cur->pNext; } - if(n == v && (cur != NULL) && (cur->next != NULL)) + if((a == v) && (cur != NULL) && (cur->pNext != NULL)) { - if(enable) + for(;a<=b;a++) { - g_VBTrackDisable.remove(cur->vb); - } - else - { - g_VBTrackDisable.insert(cur->vb); - } + if((cur == NULL) || (cur->pNext == NULL)) + break; - printf("CxbxDbg: %.02d (0x%.08X) %s\n", n, cur->vb, enable ? "enabled" : "disabled"); + if(enable) + { + trackDisable.remove(cur->pResource); + } + else + { + trackDisable.insert(cur->pResource); + } + + printf("CxbxDbg: %.02d (0x%.08X) %s\n", a, cur->pResource, enable ? "enabled" : "disabled"); + + cur = cur->pNext; + } } else { printf("CxbxDbg: # out of range\n"); } + trackTotal.Unlock(); + return; } #endif @@ -159,6 +170,8 @@ void DbgConsole::ParseCommand() char szCmd[32]; + szCmd[0] = '\0'; + sscanf(m_szInput, "%s", szCmd); // TODO: as command list grows, turn into static string/ptr lookup @@ -168,14 +181,19 @@ void DbgConsole::ParseCommand() printf("CxbxDbg: \n"); printf("CxbxDbg: Cxbx Debug Command List:\n"); printf("CxbxDbg: \n"); - printf("CxbxDbg: HELP (H)\n"); - printf("CxbxDbg: QUIT (Q or EXIT)\n"); - printf("CxbxDbg: TRACE (T)\n"); - printf("CxbxDbg: ListVB (LVB)\n"); - printf("CxbxDbg: DisableVB # (DVB #)\n"); - printf("CxbxDbg: EnableVB # (EVB #)\n"); + printf("CxbxDbg: Help [H] : Show Command List\n"); + printf("CxbxDbg: Quit/Exit [Q] : Stop Emulation\n"); + printf("CxbxDbg: Trace [T] : Toggle Debug Trace\n"); + printf("CxbxDbg: ListVB [LVB] : List Active Vertex Buffers\n"); + printf("CxbxDbg: DisableVB [DVB #] : Disable Active Vertex Buffer(s)\n"); + printf("CxbxDbg: EnableVB [EVB #] : Enable Active Vertex Buffer(s)\n"); + printf("CxbxDbg: ListPB [LPB] : List Active Push Buffers\n"); + printf("CxbxDbg: DisablePB [DPB #] : Disable Active Push Buffer(s)\n"); + printf("CxbxDbg: EnablePB [EPB #] : Enable Active Push Buffer(s)\n"); printf("CxbxDbg: CLS\n"); printf("CxbxDbg: \n"); + printf("CxbxDbg: # denotes parameter of form [#] or [#-#]\n"); + printf("CxbxDbg: \n"); } else if(stricmp(szCmd, "q") == 0 || stricmp(szCmd, "quit") == 0 || stricmp(szCmd, "exit") == 0) { @@ -191,20 +209,22 @@ void DbgConsole::ParseCommand() { #ifdef _DEBUG_TRACK_VB { - using namespace XTL; - int v=0; - VBNode *cur = g_VBTrackTotal.getHead(); + g_VBTrackTotal.Lock(); - while(cur != NULL && cur->next != NULL) + RTNode *cur = g_VBTrackTotal.getHead(); + + while(cur != NULL && cur->pNext != NULL) { - bool enabled = !g_VBTrackDisable.exists(cur->vb); + bool enabled = !g_VBTrackDisable.exists(cur->pResource); - printf("CxbxDbg: %.02d : 0x%.08X (%s)\n", v++, cur->vb, enabled ? "enabled" : "disabled"); + printf("CxbxDbg: %.02d : 0x%.08X (%s)\n", v++, cur->pResource, enabled ? "enabled" : "disabled"); - cur = cur->next; + cur = cur->pNext; } + + g_VBTrackTotal.Unlock(); } #else printf("CxbxDbg: _DEBUG_TRACK_VB is not defined!\n"); @@ -214,13 +234,17 @@ void DbgConsole::ParseCommand() { #ifdef _DEBUG_TRACK_VB { - using namespace XTL; + int n=0, m=0; - int n=0; - - if(sscanf(m_szInput, "%*s %d", &n) == 1) + int c = sscanf(m_szInput, "%*s %d-%d", &n, &m); + + if(c == 1) { - EnableVB(n, false); + EnableTracker(g_VBTrackTotal, g_VBTrackDisable, n, n, false); + } + else if(c == 2) + { + EnableTracker(g_VBTrackTotal, g_VBTrackDisable, n, m, false); } else { @@ -235,13 +259,17 @@ void DbgConsole::ParseCommand() { #ifdef _DEBUG_TRACK_VB { - using namespace XTL; + int n=0, m=0; - int n=0; - - if(sscanf(m_szInput, "%*s %d", &n) == 1) + int c = sscanf(m_szInput, "%*s %d-%d", &n, &m); + + if(c == 1) { - EnableVB(n, true); + EnableTracker(g_VBTrackTotal, g_VBTrackDisable, n, n, true); + } + else if(c == 2) + { + EnableTracker(g_VBTrackTotal, g_VBTrackDisable, n, m, true); } else { @@ -252,6 +280,81 @@ void DbgConsole::ParseCommand() printf("CxbxDbg: _DEBUG_TRACK_VB is not defined!\n"); #endif } + else if(stricmp(szCmd, "lpb") == 0 || stricmp(szCmd, "ListPB") == 0) + { + #ifdef _DEBUG_TRACK_PB + { + int v=0; + + g_PBTrackTotal.Lock(); + + RTNode *cur = g_PBTrackTotal.getHead(); + + while(cur != NULL && cur->pNext != NULL) + { + bool enabled = !g_PBTrackDisable.exists(cur->pResource); + + printf("CxbxDbg: %.02d : 0x%.08X (%s)\n", v++, cur->pResource, enabled ? "enabled" : "disabled"); + + cur = cur->pNext; + } + + g_PBTrackTotal.Unlock(); + } + #else + printf("CxbxDbg: _DEBUG_TRACK_PB is not defined!\n"); + #endif + } + else if(stricmp(szCmd, "dpb") == 0 || stricmp(szCmd, "DisablePB") == 0) + { + #ifdef _DEBUG_TRACK_PB + { + int n=0, m=0; + + int c = sscanf(m_szInput, "%*s %d-%d", &n, &m); + + if(c == 1) + { + EnableTracker(g_PBTrackTotal, g_PBTrackDisable, n, n, false); + } + else if(c == 2) + { + EnableTracker(g_PBTrackTotal, g_PBTrackDisable, n, m, false); + } + else + { + printf("CxbxDbg: Syntax Incorrect (dpb #)\n"); + } + } + #else + printf("CxbxDbg: _DEBUG_TRACK_PB is not defined!\n"); + #endif + } + else if(stricmp(szCmd, "epb") == 0 || stricmp(szCmd, "EnablePB") == 0) + { + #ifdef _DEBUG_TRACK_PB + { + int n=0, m=0; + + int c = sscanf(m_szInput, "%*s %d-%d", &n, &m); + + if(c == 1) + { + EnableTracker(g_PBTrackTotal, g_PBTrackDisable, n, n, true); + } + else if(c == 2) + { + EnableTracker(g_PBTrackTotal, g_PBTrackDisable, n, m, true); + } + else + { + printf("CxbxDbg: Syntax Incorrect (dpb #)\n"); + } + } + #else + printf("CxbxDbg: _DEBUG_TRACK_PB is not defined!\n"); + #endif + } else if(stricmp(szCmd, "cls") == 0) { // clear screen using system call diff --git a/Source/Win32/CxbxKrnl/EmuD3D8.cpp b/Source/Win32/CxbxKrnl/EmuD3D8.cpp index 08bfefc2b..59b434a3a 100644 --- a/Source/Win32/CxbxKrnl/EmuD3D8.cpp +++ b/Source/Win32/CxbxKrnl/EmuD3D8.cpp @@ -44,6 +44,7 @@ namespace xboxkrnl #include "EmuFS.h" #include "EmuShared.h" #include "DbgConsole.h" +#include "ResourceTracker.h" // prevent name collisions namespace XTL @@ -873,6 +874,8 @@ static DWORD WINAPI EmuCreateDeviceProxy(LPVOID) // update z-stencil surface cache g_pCachedZStencilSurface = new XTL::X_D3DSurface(); + g_pCachedZStencilSurface->Common = 0; + g_pCachedZStencilSurface->Data = X_D3DRESOURCE_DATA_FLAG_D3DSTEN; g_pD3DDevice8->GetDepthStencilSurface(&g_pCachedZStencilSurface->EmuSurface8); // begin scene @@ -936,7 +939,7 @@ static void EmuVerifyResourceIsRegistered(XTL::X_D3DResource *pResource) return; // Already "Registered" implicitly - if(pResource->Data == X_D3DRESOURCE_DATA_FLAG_D3DREND) + if((pResource->Data == X_D3DRESOURCE_DATA_FLAG_D3DREND) || (pResource->Data == X_D3DRESOURCE_DATA_FLAG_D3DSTEN)) return; int v=0; @@ -1985,8 +1988,7 @@ XTL::X_D3DSurface * WINAPI XTL::EmuIDirect3DDevice8_GetDepthStencilSurface2() { EmuSwapFS(); // Win2k/XP FS - DbgPrintf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_GetDepthStencilSurface2()\n", - GetCurrentThreadId()); + DbgPrintf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_GetDepthStencilSurface2()\n", GetCurrentThreadId()); IDirect3DSurface8 *pSurface8 = g_pCachedZStencilSurface->EmuSurface8; @@ -3113,7 +3115,7 @@ static void EmuFlushD3DIVB() HRESULT hRet = S_OK; #ifdef _DEBUG_TRACK_VB - if(!XTL::g_bVBSkipStream) + if(!g_bVBSkipStream) { #endif @@ -4089,12 +4091,24 @@ ULONG WINAPI XTL::EmuIDirect3DResource8_Release } } + #ifdef _DEBUG_TRACE_VB + D3DRESOURCETYPE Type = pResource8->GetType(); + #endif + uRet = pResource8->Release(); if(uRet == 0) { DbgPrintf("EmuIDirect3DResource8_Release (0x%X): Cleaned up a Resource!\n", GetCurrentThreadId()); + #ifdef _DEBUG_TRACE_VB + if(Type == D3DRTYPE_VERTEXBUFFER) + { + g_VBTrackTotal.remove(pResource8); + g_VBTrackDisable.remove(pResource8); + } + #endif + delete pThis; } } @@ -6227,17 +6241,24 @@ VOID WINAPI XTL::EmuIDirect3DDevice8_DrawVertices uint32 nStride = EmuFixupVerticesA(PrimitiveType, PrimitiveCount, pOrigVertexBuffer8, pHackVertexBuffer8, StartVertex, 0, 0, 0); #ifdef _DEBUG_TRACK_VB - if(!g_bVBSkipStream) + if(g_bVBSkipStream) + { + g_pD3DDevice8->DrawPrimitive + ( + PCPrimitiveType, + StartVertex, + 0 + ); + } + else { #endif - - g_pD3DDevice8->DrawPrimitive - ( - PCPrimitiveType, - StartVertex, - PrimitiveCount - ); - + g_pD3DDevice8->DrawPrimitive + ( + PCPrimitiveType, + StartVertex, + PrimitiveCount + ); #ifdef _DEBUG_TRACK_VB } #endif diff --git a/Source/Win32/CxbxKrnl/EmuD3D8/PushBuffer.cpp b/Source/Win32/CxbxKrnl/EmuD3D8/PushBuffer.cpp index 11d82b3d8..c80e5f90d 100644 --- a/Source/Win32/CxbxKrnl/EmuD3D8/PushBuffer.cpp +++ b/Source/Win32/CxbxKrnl/EmuD3D8/PushBuffer.cpp @@ -35,6 +35,7 @@ #define _XBOXKRNL_DEFEXTRN_ #include "Emu.h" +#include "ResourceTracker.h" // prevent name collisions namespace XTL @@ -109,6 +110,10 @@ void XTL::EmuExecutePushBuffer pIndexData = pdwPushData; + #ifdef _DEBUG_TRACK_PB + g_PBTrackTotal.insert(pIndexData); + #endif + pdwPushData += dwCount - (bInc ? 0 : 1); // perform rendering @@ -135,10 +140,19 @@ void XTL::EmuExecutePushBuffer { g_pD3DDevice8->SetIndices(pIndexBuffer, 0); + #ifdef _DEBUG_TRACK_PB + if(!g_PBTrackDisable.exists(pIndexData)) + { + #endif + g_pD3DDevice8->DrawIndexedPrimitive ( PCPrimitiveType, 0, dwCount*2, 0, EmuD3DVertex2PrimitiveCount(XBPrimitiveType, dwCount*2) ); + + #ifdef _DEBUG_TRACK_PB + } + #endif } // cleanup diff --git a/Source/Win32/CxbxKrnl/EmuD3D8/VertexBuffer.cpp b/Source/Win32/CxbxKrnl/EmuD3D8/VertexBuffer.cpp index f98349ff5..58fde5c57 100644 --- a/Source/Win32/CxbxKrnl/EmuD3D8/VertexBuffer.cpp +++ b/Source/Win32/CxbxKrnl/EmuD3D8/VertexBuffer.cpp @@ -45,105 +45,6 @@ namespace XTL extern XTL::LPDIRECT3DDEVICE8 g_pD3DDevice8; // Direct3D8 Device -#ifdef _DEBUG_TRACK_VB - -bool XTL::g_bVBSkipStream = false; - -XTL::VBTracker XTL::g_VBTrackTotal, XTL::g_VBTrackDisable; - -XTL::VBTracker::~VBTracker() -{ - VBNode *cur = m_head; - - while(cur != NULL) - { - VBNode *tmp = cur->next; - - delete cur; - - cur = tmp; - } -} - -void XTL::VBTracker::insert(IDirect3DVertexBuffer8 *pVB) -{ - if(exists(pVB)) - return; - - if(m_head == 0) - { - m_tail = m_head = new VBNode(); - m_tail->vb = 0; - m_tail->next = 0; - } - - m_tail->vb = pVB; - - m_tail->next = new VBNode(); - - m_tail = m_tail->next; - - m_tail->vb = 0; - m_tail->next = 0; - - return; -} - -void XTL::VBTracker::remove(IDirect3DVertexBuffer8 *pVB) -{ - VBNode *pre = 0; - VBNode *cur = m_head; - - while(cur != NULL) - { - if(cur->vb == pVB) - { - if(pre != 0) - { - pre->next = cur->next; - } - else - { - m_head = cur->next; - - if(m_head->next == 0) - { - delete m_head; - - m_head = 0; - m_tail = 0; - } - } - - delete cur; - - return; - } - - pre = cur; - cur = cur->next; - } - - return; -} - -bool XTL::VBTracker::exists(IDirect3DVertexBuffer8 *pVB) -{ - VBNode *cur = m_head; - - while(cur != NULL) - { - if(cur->vb == pVB) - return true; - - cur = cur->next; - } - - return false; -} - -#endif // _DEBUG_TRACK_VB - // fixup xbox extensions to be compatible with PC direct3d UINT XTL::EmuFixupVerticesA ( diff --git a/Source/Win32/CxbxKrnl/EmuD3D8/VertexShader.cpp b/Source/Win32/CxbxKrnl/EmuD3D8/VertexShader.cpp index 5764be0a8..d345d514a 100644 --- a/Source/Win32/CxbxKrnl/EmuD3D8/VertexShader.cpp +++ b/Source/Win32/CxbxKrnl/EmuD3D8/VertexShader.cpp @@ -45,8 +45,6 @@ namespace XTL extern XTL::LPDIRECT3DDEVICE8 g_pD3DDevice8; // Direct3D8 Device -#include - // **************************************************************************** // * Vertex shader function recompiler // **************************************************************************** @@ -1463,7 +1461,7 @@ static DWORD VshConvertToken_CONSTMEM(DWORD *pToken) //pToken = D3DVSD_CONST(ConstantAddress, Count); - for (int i = 0; i < Count; i++) + for (uint i = 0; i < Count; i++) { DbgVshPrintf("\t0x%08X,\n", pToken); } diff --git a/Source/Win32/CxbxKrnl/EmuKrnl.cpp b/Source/Win32/CxbxKrnl/EmuKrnl.cpp index dbe810567..b13b2607b 100644 --- a/Source/Win32/CxbxKrnl/EmuKrnl.cpp +++ b/Source/Win32/CxbxKrnl/EmuKrnl.cpp @@ -850,7 +850,13 @@ XBSYSAPI EXPORTNUM(171) VOID NTAPI xboxkrnl::MmFreeContiguousMemory } if(BaseAddress != &xLaunchDataPage) + { free(BaseAddress); + } + else + { + DbgPrintf("Ignored MmFreeContiguousMemory(&xLaunchDataPage)\n"); + } EmuSwapFS(); // Xbox FS diff --git a/Source/Win32/CxbxKrnl/ResourceTracker.cpp b/Source/Win32/CxbxKrnl/ResourceTracker.cpp new file mode 100644 index 000000000..8b795e083 --- /dev/null +++ b/Source/Win32/CxbxKrnl/ResourceTracker.cpp @@ -0,0 +1,153 @@ +// ****************************************************************** +// * +// * .,-::::: .,:: .::::::::. .,:: .: +// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;; +// * [[[ '[[,,[[' [[[__[[\. '[[,,[[' +// * $$$ Y$$$P $$""""Y$$ Y$$$P +// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo, +// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm, +// * +// * Cxbx->Win32->CxbxKrnl->ResourceTracker.cpp +// * +// * This file is part of the Cxbx project. +// * +// * Cxbx and Cxbe are free software; you can redistribute them +// * and/or modify them under the terms of the GNU General Public +// * License as published by the Free Software Foundation; either +// * version 2 of the license, or (at your option) any later version. +// * +// * This program is distributed in the hope that it will be useful, +// * but WITHOUT ANY WARRANTY; without even the implied warranty of +// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// * GNU General Public License for more details. +// * +// * You should have recieved a copy of the GNU General Public License +// * along with this program; see the file COPYING. +// * If not, write to the Free Software Foundation, Inc., +// * 59 Temple Place - Suite 330, Bostom, MA 02111-1307, USA. +// * +// * (c) 2002-2003 Aaron Robinson +// * +// * All rights reserved +// * +// ****************************************************************** +#include "ResourceTracker.h" + +// exported globals +bool g_bVBSkipStream = false; +bool g_bVBSkipPusher = false; +ResourceTracker g_VBTrackTotal; +ResourceTracker g_VBTrackDisable; +ResourceTracker g_PBTrackTotal; +ResourceTracker g_PBTrackDisable; + +ResourceTracker::~ResourceTracker() +{ + RTNode *cur = m_head; + + while(cur != 0) + { + RTNode *tmp = cur->pNext; + + delete cur; + + cur = tmp; + } +} + +void ResourceTracker::insert(void *pResource) +{ + this->Lock(); + + if(exists(pResource)) + { + this->Unlock(); + return; + } + + if(m_head == 0) + { + m_tail = m_head = new RTNode(); + m_tail->pResource = 0; + m_tail->pNext = 0; + } + + m_tail->pResource = pResource; + + m_tail->pNext = new RTNode(); + + m_tail = m_tail->pNext; + + m_tail->pResource = 0; + m_tail->pNext = 0; + + this->Unlock(); + + return; +} + +void ResourceTracker::remove(void *pResource) +{ + this->Lock(); + + RTNode *pre = 0; + RTNode *cur = m_head; + + while(cur != 0) + { + if(cur->pResource == pResource) + { + if(pre != 0) + { + pre->pNext = cur->pNext; + } + else + { + m_head = cur->pNext; + + if(m_head->pNext == 0) + { + delete m_head; + + m_head = 0; + m_tail = 0; + } + } + + delete cur; + + this->Unlock(); + + return; + } + + pre = cur; + cur = cur->pNext; + } + + this->Unlock(); + + return; +} + +bool ResourceTracker::exists(void *pResource) +{ + this->Lock(); + + RTNode *cur = m_head; + + while(cur != 0) + { + if(cur->pResource == pResource) + { + this->Unlock(); + return true; + } + + cur = cur->pNext; + } + + this->Unlock(); + + return false; +}