From 1eaaddb78b35f78208e7a4248ec90068ce38dbc2 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Thu, 12 Jun 2003 02:05:10 +0000 Subject: [PATCH] Yipee --- Doc/Direct3D.txt | 24 ++++ Doc/Todo.txt | 8 ++ Include/Cxbx.h | 2 +- Include/Win32/CxbxKrnl/xd3d8.h | 31 ++++- Include/Win32/CxbxKrnl/xntdll.h | 12 ++ Source/Win32/CxbxKrnl/D3D8.1.0.4361.inl | 76 +++++++++++ Source/Win32/CxbxKrnl/D3D8.1.0.4627.inl | 86 +++++++++++++ Source/Win32/CxbxKrnl/Emu.cpp | 2 + Source/Win32/CxbxKrnl/EmuD3D8.cpp | 160 ++++++++++++++++++++++-- Source/Win32/CxbxKrnl/EmuKrnl.cpp | 41 +++++- Source/Win32/CxbxKrnl/KernelThunk.cpp | 2 +- 11 files changed, 430 insertions(+), 14 deletions(-) create mode 100644 Doc/Direct3D.txt diff --git a/Doc/Direct3D.txt b/Doc/Direct3D.txt new file mode 100644 index 000000000..5e5a7edac --- /dev/null +++ b/Doc/Direct3D.txt @@ -0,0 +1,24 @@ +Direct3D resources are going to be a little bit of a hack. +There is a tough situation, because precompiled resources +(XPR) can be loaded into memory manually by an Xbox Game, +and then "Registered" with pResource->Register(addr); + +This is a problem because we never have an opportunity to +intercept the "this" pointer for this datatype. The base +resource class looks like this: + +DWORD Common; +DWORD Data; +DWORD Lock; + +The first idea is to tuck away the PC Direct3D resource +pointer inside of pResource->Data. The trouble with this +is that some Xbox Games will directly access and modify +this member. + +Another technique is to hide the PC Direct3D resource pointer +inside of the buffer allocated by Data. This could work, as +long as Xbox Games do not access the resource Data after the +initial Register function is called. + +I am currently using the first idea until we run into trouble. diff --git a/Doc/Todo.txt b/Doc/Todo.txt index 424a21850..101a26bba 100644 --- a/Doc/Todo.txt +++ b/Doc/Todo.txt @@ -1,5 +1,13 @@ Cxbx Todo (* denotes high priority) + * When in critical section, do not print debug trace + + * Functions like GetRenderTarget need to return a special temporary + X_D3DSurface that will somehow be cleaned up along with the "real" + X_D3DSurface pointer. Perhaps maintain a cache of all the current + temporary buffers, and whenever a resource has it's final Release(), + go through and check if any other handles reference that resource. + * Register() probably needn't re-unswizzle each time. cache a copy of the address it was registered to (or a global table) and simply update the data pointer to that IDirect3DTexture8 instance. diff --git a/Include/Cxbx.h b/Include/Cxbx.h index 0f655aab8..4298603c4 100644 --- a/Include/Cxbx.h +++ b/Include/Cxbx.h @@ -66,7 +66,7 @@ typedef signed long sint32; // ****************************************************************** // * Define this to trace intercepted function calls // ****************************************************************** -#define _DEBUG_TRACE +//#define _DEBUG_TRACE // ****************************************************************** // * Round up dwValue to nearest multiple of dwMult diff --git a/Include/Win32/CxbxKrnl/xd3d8.h b/Include/Win32/CxbxKrnl/xd3d8.h index 32a638156..8a602c563 100644 --- a/Include/Win32/CxbxKrnl/xd3d8.h +++ b/Include/Win32/CxbxKrnl/xd3d8.h @@ -166,18 +166,17 @@ X_D3DPRESENT_PARAMETERS; struct X_D3DResource { DWORD Common; + DWORD Data; union { - DWORD Data; + DWORD Lock; IDirect3DResource8 *EmuResource8; IDirect3DBaseTexture8 *EmuBaseTexture8; IDirect3DTexture8 *EmuTexture8; IDirect3DSurface8 *EmuSurface8; IDirect3DVertexBuffer8 *EmuVertexBuffer8; }; - - DWORD Lock; }; // ****************************************************************** @@ -298,6 +297,32 @@ HRESULT WINAPI EmuIDirect3D8_GetAdapterDisplayMode X_D3DDISPLAYMODE *pMode ); +// ****************************************************************** +// * func: EmuIDirect3DDevice8_GetRenderTarget +// ****************************************************************** +HRESULT WINAPI EmuIDirect3DDevice8_GetRenderTarget +( + X_D3DSurface **ppRenderTarget +); + +// ****************************************************************** +// * func: EmuIDirect3DDevice8_GetRenderTarget +// ****************************************************************** +X_D3DSurface * WINAPI EmuIDirect3DDevice8_GetRenderTarget2(); + +// ****************************************************************** +// * func: EmuIDirect3DDevice8_GetDepthStencilSurface +// ****************************************************************** +HRESULT WINAPI EmuIDirect3DDevice8_GetDepthStencilSurface +( + X_D3DSurface **ppZStencilSurface +); + +// ****************************************************************** +// * func: EmuIDirect3DDevice8_GetDepthStencilSurface +// ****************************************************************** +X_D3DSurface * WINAPI EmuIDirect3DDevice8_GetDepthStencilSurface2(); + // ****************************************************************** // * func: EmuIDirect3DDevice8_CreateVertexShader // ****************************************************************** diff --git a/Include/Win32/CxbxKrnl/xntdll.h b/Include/Win32/CxbxKrnl/xntdll.h index 549899bef..871f0a877 100644 --- a/Include/Win32/CxbxKrnl/xntdll.h +++ b/Include/Win32/CxbxKrnl/xntdll.h @@ -642,6 +642,18 @@ typedef NTSTATUS (NTAPI *FPTR_NtWriteFile) IN PULONG Key OPTIONAL ); +// ****************************************************************** +// * NtSetInformationFile +// ****************************************************************** +typedef NTSTATUS (NTAPI *FPTR_NtSetInformationFile) +( + IN HANDLE FileHandle, // TODO: correct paramters + OUT PVOID IoStatusBlock, + IN PVOID FileInformation, + IN ULONG Length, + IN ULONG FileInformationClass +); + // ****************************************************************** // * NtQueryInformationFile // ****************************************************************** diff --git a/Source/Win32/CxbxKrnl/D3D8.1.0.4361.inl b/Source/Win32/CxbxKrnl/D3D8.1.0.4361.inl index 1fa67293e..f0060d214 100644 --- a/Source/Win32/CxbxKrnl/D3D8.1.0.4361.inl +++ b/Source/Win32/CxbxKrnl/D3D8.1.0.4361.inl @@ -91,6 +91,62 @@ SOOVPA<13> IDirect3D8_GetAdapterDisplayMode_1_0_4361 = } }; +// ****************************************************************** +// * IDirect3DDevice8_GetRenderTarget +// ****************************************************************** +SOOVPA<9> IDirect3DDevice8_GetRenderTarget_1_0_4361 = +{ + 0, // Large == 0 + 9, // Count == 9 + + { + // IDirect3DDevice8_GetRenderTarget+0x00 : mov eax, [addr] + { 0x00, 0xA1 }, // (Offset,Value)-Pair #1 + + // IDirect3DDevice8_GetRenderTarget+0x05 : mov eax, [eax + 0x2070] + { 0x05, 0x8B }, // (Offset,Value)-Pair #2 + { 0x06, 0x80 }, // (Offset,Value)-Pair #3 + { 0x07, 0x70 }, // (Offset,Value)-Pair #4 + { 0x08, 0x20 }, // (Offset,Value)-Pair #5 + + // IDirect3DDevice8_GetRenderTarget+0x11 : mov [ecx], eax + { 0x11, 0x89 }, // (Offset,Value)-Pair #6 + { 0x12, 0x01 }, // (Offset,Value)-Pair #7 + + // IDirect3DDevice8_GetRenderTarget+0x1D : retn 0x04 + { 0x1D, 0xC2 }, // (Offset,Value)-Pair #8 + { 0x1E, 0x04 }, // (Offset,Value)-Pair #9 + } +}; + +// ****************************************************************** +// * IDirect3DDevice8_GetDepthStencilSurface +// ****************************************************************** +SOOVPA<9> IDirect3DDevice8_GetDepthStencilSurface_1_0_4361 = +{ + 0, // Large == 0 + 9, // Count == 9 + + { + // IDirect3DDevice8_GetDepthStencilSurface+0x00 : mov eax, [addr] + { 0x00, 0xA1 }, // (Offset,Value)-Pair #1 + + // IDirect3DDevice8_GetDepthStencilSurface+0x05 : mov eax, [eax + 0x2074] + { 0x05, 0x8B }, // (Offset,Value)-Pair #2 + { 0x06, 0x80 }, // (Offset,Value)-Pair #3 + { 0x07, 0x74 }, // (Offset,Value)-Pair #4 + { 0x08, 0x20 }, // (Offset,Value)-Pair #5 + + // IDirect3DDevice8_GetDepthStencilSurface+0x11 : mov [ecx], eax + { 0x11, 0x89 }, // (Offset,Value)-Pair #6 + { 0x12, 0x01 }, // (Offset,Value)-Pair #7 + + // IDirect3DDevice8_GetDepthStencilSurface+0x1D : retn 0x04 + { 0x1D, 0xC2 }, // (Offset,Value)-Pair #8 + { 0x1E, 0x04 }, // (Offset,Value)-Pair #9 + } +}; + // ****************************************************************** // * IDirect3DDevice8_CreateVertexShader // ****************************************************************** @@ -989,6 +1045,26 @@ OOVPATable D3D8_1_0_4361[] = "EmuIDirect3D8_GetAdapterDisplayMode" #endif }, + // IDirect3DDevice8::GetRenderTarget + { + (OOVPA*)&IDirect3DDevice8_GetRenderTarget_1_0_4361, + + xd3d8::EmuIDirect3DDevice8_GetRenderTarget, + + #ifdef _DEBUG_TRACE + "EmuIDirect3DDevice8_GetRenderTarget" + #endif + }, + // IDirect3DDevice8::GetDepthStencilSurface + { + (OOVPA*)&IDirect3DDevice8_GetDepthStencilSurface_1_0_4361, + + xd3d8::EmuIDirect3DDevice8_GetDepthStencilSurface, + + #ifdef _DEBUG_TRACE + "EmuIDirect3DDevice8_GetDepthStencilSurface" + #endif + }, // IDirect3DDevice8::CreateVertexShader { (OOVPA*)&IDirect3DDevice8_CreateVertexShader_1_0_4361, diff --git a/Source/Win32/CxbxKrnl/D3D8.1.0.4627.inl b/Source/Win32/CxbxKrnl/D3D8.1.0.4627.inl index 645fe645e..2a1c2b414 100644 --- a/Source/Win32/CxbxKrnl/D3D8.1.0.4627.inl +++ b/Source/Win32/CxbxKrnl/D3D8.1.0.4627.inl @@ -91,6 +91,72 @@ SOOVPA<13> IDirect3D8_GetAdapterDisplayMode_1_0_4627 = } }; +// ****************************************************************** +// * IDirect3DDevice8_GetRenderTarget2 +// ****************************************************************** +SOOVPA<10> IDirect3DDevice8_GetRenderTarget2_1_0_4627 = +{ + 0, // Large == 0 + 10, // Count == 10 + + { + // IDirect3DDevice8_GetRenderTarget2+0x00 : mov eax, [addr] + { 0x00, 0xA1 }, // (Offset,Value)-Pair #1 + + // IDirect3DDevice8_GetRenderTarget2+0x05 : push esi + { 0x05, 0x56 }, // (Offset,Value)-Pair #2 + + // IDirect3DDevice8_GetRenderTarget2+0x06 : mov esi, [eax + 0x21B4] + { 0x06, 0x8B }, // (Offset,Value)-Pair #3 + { 0x07, 0xB0 }, // (Offset,Value)-Pair #4 + { 0x08, 0xB4 }, // (Offset,Value)-Pair #5 + { 0x09, 0x21 }, // (Offset,Value)-Pair #6 + + // IDirect3DDevice8_GetRenderTarget2+0x0E : jz + 0x06 + { 0x0E, 0x74 }, // (Offset,Value)-Pair #7 + { 0x0F, 0x06 }, // (Offset,Value)-Pair #8 + + // IDirect3DDevice8_GetRenderTarget2+0x11 : call [addr] + { 0x11, 0xE8 }, // (Offset,Value)-Pair #9 + + // IDirect3DDevice8_GetRenderTarget2+0x19 : retn + { 0x19, 0xC3 }, // (Offset,Value)-Pair #10 + } +}; + +// ****************************************************************** +// * IDirect3DDevice8_GetDepthStencilSurface2 +// ****************************************************************** +SOOVPA<10> IDirect3DDevice8_GetDepthStencilSurface2_1_0_4627 = +{ + 0, // Large == 0 + 10, // Count == 10 + + { + // IDirect3DDevice8_GetDepthStencilSurface2+0x00 : mov eax, [addr] + { 0x00, 0xA1 }, // (Offset,Value)-Pair #1 + + // IDirect3DDevice8_GetDepthStencilSurface2+0x05 : push esi + { 0x05, 0x56 }, // (Offset,Value)-Pair #2 + + // IDirect3DDevice8_GetDepthStencilSurface2+0x06 : mov esi, [eax + 0x21B8] + { 0x06, 0x8B }, // (Offset,Value)-Pair #3 + { 0x07, 0xB0 }, // (Offset,Value)-Pair #4 + { 0x08, 0xB8 }, // (Offset,Value)-Pair #5 + { 0x09, 0x21 }, // (Offset,Value)-Pair #6 + + // IDirect3DDevice8_GetDepthStencilSurface2+0x0E : jnz +0x04 + { 0x0E, 0x75 }, // (Offset,Value)-Pair #7 + { 0x0F, 0x04 }, // (Offset,Value)-Pair #8 + + // IDirect3DDevice8_GetDepthStencilSurface2+0x15 : call [addr] + { 0x15, 0xE8 }, // (Offset,Value)-Pair #9 + + // IDirect3DDevice8_GetDepthStencilSurface2+0x1D : retn + { 0x1D, 0xC3 }, // (Offset,Value)-Pair #10 + } +}; + // ****************************************************************** // * IDirect3DDevice8_SetVertexShaderConstant // ****************************************************************** @@ -504,6 +570,26 @@ OOVPATable D3D8_1_0_4627[] = "EmuIDirect3D8_GetAdapterDisplayMode" #endif }, + // IDirect3DDevice8::GetRenderTarget2 + { + (OOVPA*)&IDirect3DDevice8_GetRenderTarget2_1_0_4627, + + xd3d8::EmuIDirect3DDevice8_GetRenderTarget2, + + #ifdef _DEBUG_TRACE + "EmuIDirect3DDevice8_GetRenderTarget2" + #endif + }, + // IDirect3DDevice8::GetDepthStencilSurface2 + { + (OOVPA*)&IDirect3DDevice8_GetDepthStencilSurface2_1_0_4627, + + xd3d8::EmuIDirect3DDevice8_GetDepthStencilSurface2, + + #ifdef _DEBUG_TRACE + "EmuIDirect3DDevice8_GetDepthStencilSurface2" + #endif + }, // IDirect3DDevice8::CreateVertexShader (* unchanged since 4361 *) { (OOVPA*)&IDirect3DDevice8_CreateVertexShader_1_0_4361, diff --git a/Source/Win32/CxbxKrnl/Emu.cpp b/Source/Win32/CxbxKrnl/Emu.cpp index 098279e3f..bbf3b1bd4 100644 --- a/Source/Win32/CxbxKrnl/Emu.cpp +++ b/Source/Win32/CxbxKrnl/Emu.cpp @@ -364,6 +364,8 @@ extern "C" CXBXKRNL_API void NTAPI EmuInit { EmuSwapFS(); // XBox FS +// __asm int 3 + Entry(); EmuSwapFS(); // Win2k/XP FS diff --git a/Source/Win32/CxbxKrnl/EmuD3D8.cpp b/Source/Win32/CxbxKrnl/EmuD3D8.cpp index d4262a43f..e92850b0a 100644 --- a/Source/Win32/CxbxKrnl/EmuD3D8.cpp +++ b/Source/Win32/CxbxKrnl/EmuD3D8.cpp @@ -88,14 +88,20 @@ static DWORD WINAPI EmuUpdateTickCount(LPVOID); // ****************************************************************** static xd3d8::LPDIRECT3D8 g_pD3D8 = NULL; // Direct3D8 static xd3d8::LPDIRECT3DDEVICE8 g_pD3DDevice8 = NULL; // Direct3D8 Device -static DWORD g_VertexShaderUsage = 0; // Vertex Shader Usage Param static Xbe::Header *g_XbeHeader = NULL; // XbeHeader static uint32 g_XbeHeaderSize = 0; // XbeHeaderSize static xd3d8::D3DCAPS8 g_D3DCaps; // Direct3D8 Caps static HBRUSH g_hBgBrush = NULL; // Background Brush -static volatile bool g_ThreadInitialized = false; +static volatile bool g_bThreadInitialized = false; static XBVideo g_XBVideo; +// ****************************************************************** +// * Cached Direct3D State Variable(s) +// ****************************************************************** +static xd3d8::X_D3DSurface *g_pCachedRenderTarget = NULL; +static xd3d8::X_D3DSurface *g_pCachedZStencilSurface = NULL; +static DWORD g_dwVertexShaderUsage = 0; + // ****************************************************************** // * EmuD3DDefferedRenderState // ****************************************************************** @@ -114,7 +120,7 @@ VOID EmuD3DInit(Xbe::Header *XbeHeader, uint32 XbeHeaderSize) g_XbeHeader = XbeHeader; g_XbeHeaderSize = XbeHeaderSize; - g_ThreadInitialized = false; + g_bThreadInitialized = false; // ****************************************************************** // * Create a thread dedicated to timing @@ -133,7 +139,7 @@ VOID EmuD3DInit(Xbe::Header *XbeHeader, uint32 XbeHeaderSize) CreateThread(NULL, NULL, EmuRenderWindow, NULL, NULL, &dwThreadId); - while(!g_ThreadInitialized) + while(!g_bThreadInitialized) Sleep(10); Sleep(50); @@ -290,7 +296,7 @@ DWORD WINAPI EmuRenderWindow(LPVOID) { if(PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) { - g_ThreadInitialized = true; + g_bThreadInitialized = true; TranslateMessage(&msg); DispatchMessage(&msg); @@ -399,6 +405,20 @@ HRESULT WINAPI xd3d8::EmuIDirect3D8_CreateDevice // TODO: This should be detected from D3DCAPS8 ? (FrameSkip?) pPresentationParameters->FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; + // TODO: Support Xbox extensions if possible + if(pPresentationParameters->MultiSampleType != 0) + { + printf("Warning: MultiSampleType (0x%.08X) Not Supported!\n", pPresentationParameters->MultiSampleType); + + pPresentationParameters->MultiSampleType = D3DMULTISAMPLE_NONE; + + // TODO: Check card for multisampling abilities +// if(pPresentationParameters->MultiSampleType == 0x00001121) +// pPresentationParameters->MultiSampleType = D3DMULTISAMPLE_2_SAMPLES; +// else +// EmuCleanup("Unknown MultiSampleType (0x%.08X)", pPresentationParameters->MultiSampleType); + } + // ****************************************************************** // * Retrieve Resolution from Configuration // ****************************************************************** @@ -412,6 +432,7 @@ HRESULT WINAPI xd3d8::EmuIDirect3D8_CreateDevice pPresentationParameters->BackBufferFormat = D3DDisplayMode.Format; pPresentationParameters->FullScreen_RefreshRateInHz = 0; + pPresentationParameters->hDeviceWindow = hFocusWindow; } else { @@ -443,7 +464,7 @@ HRESULT WINAPI xd3d8::EmuIDirect3D8_CreateDevice printf("EmuD3D8 (0x%X): Using hardware vertex processing\n", GetCurrentThreadId()); #endif BehaviorFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING; - g_VertexShaderUsage = 0; + g_dwVertexShaderUsage = 0; } else { @@ -451,7 +472,7 @@ HRESULT WINAPI xd3d8::EmuIDirect3D8_CreateDevice printf("EmuD3D8 (0x%X): Using software vertex processing\n", GetCurrentThreadId()); #endif BehaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING; - g_VertexShaderUsage = D3DUSAGE_SOFTWAREPROCESSING; + g_dwVertexShaderUsage = D3DUSAGE_SOFTWAREPROCESSING; } // ****************************************************************** @@ -472,6 +493,17 @@ HRESULT WINAPI xd3d8::EmuIDirect3D8_CreateDevice // ****************************************************************** g_pD3DDevice8 = *ppReturnedDeviceInterface; + // ****************************************************************** + // * Update Caches + // ****************************************************************** + { + g_pCachedRenderTarget = new X_D3DSurface(); + g_pD3DDevice8->GetRenderTarget(&g_pCachedRenderTarget->EmuSurface8); + + g_pCachedZStencilSurface = new X_D3DSurface(); + g_pD3DDevice8->GetDepthStencilSurface(&g_pCachedZStencilSurface->EmuSurface8); + } + // ****************************************************************** // * I guess we have to call this // ****************************************************************** @@ -535,6 +567,118 @@ HRESULT WINAPI xd3d8::EmuIDirect3D8_GetAdapterDisplayMode return hRet; } +// ****************************************************************** +// * func: EmuIDirect3DDevice8_GetRenderTarget +// ****************************************************************** +HRESULT WINAPI xd3d8::EmuIDirect3DDevice8_GetRenderTarget +( + X_D3DSurface **ppRenderTarget +) +{ + // ****************************************************************** + // * debug trace + // ****************************************************************** + #ifdef _DEBUG_TRACE + { + EmuSwapFS(); // Win2k/XP FS + printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_GetRenderTarget\n" + "(\n" + " ppRenderTarget : 0x%.08X\n" + ");\n", + GetCurrentThreadId(), ppRenderTarget); + EmuSwapFS(); // Xbox FS + } + #endif + + IDirect3DSurface8 *pSurface8 = g_pCachedRenderTarget->EmuSurface8; + + pSurface8->AddRef(); + + *ppRenderTarget = g_pCachedRenderTarget; + + return D3D_OK; +} + +// ****************************************************************** +// * func: EmuIDirect3DDevice8_GetRenderTarget2 +// ****************************************************************** +xd3d8::X_D3DSurface * WINAPI xd3d8::EmuIDirect3DDevice8_GetRenderTarget2() +{ + // ****************************************************************** + // * debug trace + // ****************************************************************** + #ifdef _DEBUG_TRACE + { + EmuSwapFS(); // Win2k/XP FS + printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_GetRenderTarget2()\n", + GetCurrentThreadId()); + EmuSwapFS(); // Xbox FS + } + #endif + + IDirect3DSurface8 *pSurface8 = g_pCachedRenderTarget->EmuSurface8; + + pSurface8->AddRef(); + + return g_pCachedRenderTarget; +} + +// ****************************************************************** +// * func: EmuIDirect3DDevice8_GetDepthStencilSurface +// ****************************************************************** +HRESULT WINAPI xd3d8::EmuIDirect3DDevice8_GetDepthStencilSurface +( + X_D3DSurface **ppZStencilSurface +) +{ + // ****************************************************************** + // * debug trace + // ****************************************************************** + #ifdef _DEBUG_TRACE + { + EmuSwapFS(); // Win2k/XP FS + printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_GetDepthStencilSurface\n" + "(\n" + " ppZStencilSurface : 0x%.08X\n" + ");\n", + GetCurrentThreadId(), ppZStencilSurface); + EmuSwapFS(); // Xbox FS + } + #endif + + IDirect3DSurface8 *pSurface8 = g_pCachedZStencilSurface->EmuSurface8; + + pSurface8->AddRef(); + + *ppZStencilSurface = g_pCachedZStencilSurface; + + return D3D_OK; +} + +// ****************************************************************** +// * func: EmuIDirect3DDevice8_GetDepthStencilSurface +// ****************************************************************** +xd3d8::X_D3DSurface * WINAPI xd3d8::EmuIDirect3DDevice8_GetDepthStencilSurface2() +{ + // ****************************************************************** + // * debug trace + // ****************************************************************** + #ifdef _DEBUG_TRACE + { + EmuSwapFS(); // Win2k/XP FS + printf("EmuD3D8 (0x%X): EmuIDirect3DDevice8_GetDepthStencilSurface2()\n", + GetCurrentThreadId()); + EmuSwapFS(); // Xbox FS + } + #endif + + IDirect3DSurface8 *pSurface8 = g_pCachedZStencilSurface->EmuSurface8; + + pSurface8->AddRef(); + + return g_pCachedZStencilSurface; +} + // ****************************************************************** // * func: EmuIDirect3DDevice8_CreateVertexShader // ****************************************************************** @@ -572,7 +716,7 @@ HRESULT WINAPI xd3d8::EmuIDirect3DDevice8_CreateVertexShader pDeclaration, pFunction, pHandle, - g_VertexShaderUsage // TODO: HACK: Xbox has extensions! + g_dwVertexShaderUsage // TODO: HACK: Xbox has extensions! ); // hey look, we lied diff --git a/Source/Win32/CxbxKrnl/EmuKrnl.cpp b/Source/Win32/CxbxKrnl/EmuKrnl.cpp index b0223fc7c..2cc7933b5 100644 --- a/Source/Win32/CxbxKrnl/EmuKrnl.cpp +++ b/Source/Win32/CxbxKrnl/EmuKrnl.cpp @@ -80,6 +80,7 @@ xntdll::FPTR_NtCreateEvent NT_NtCreateEvent = (x xntdll::FPTR_NtCreateFile NT_NtCreateFile = (xntdll::FPTR_NtCreateFile)GetProcAddress(hNtDll, "NtCreateFile"); xntdll::FPTR_NtReadFile NT_NtReadFile = (xntdll::FPTR_NtReadFile)GetProcAddress(hNtDll, "NtReadFile"); xntdll::FPTR_NtWriteFile NT_NtWriteFile = (xntdll::FPTR_NtWriteFile)GetProcAddress(hNtDll, "NtWriteFile"); +xntdll::FPTR_NtSetInformationFile NT_NtSetInformationFile = (xntdll::FPTR_NtSetInformationFile)GetProcAddress(hNtDll, "NtSetInformationFile"); // ****************************************************************** // * (Helper) PCSTProxyParam @@ -1019,6 +1020,43 @@ XBSYSAPI EXPORTNUM(219) NTSTATUS NTAPI xboxkrnl::NtReadFile return ret; } +// ****************************************************************** +// * 0x00E2 - NtSetInformationFile +// ****************************************************************** +XBSYSAPI EXPORTNUM(226) NTSTATUS NTAPI xboxkrnl::NtSetInformationFile +( + IN HANDLE FileHandle, // TODO: correct paramters + OUT PVOID IoStatusBlock, + IN PVOID FileInformation, + IN ULONG Length, + IN ULONG FileInformationClass +) +{ + EmuSwapFS(); // Win2k/XP FS + + // ****************************************************************** + // * debug trace + // ****************************************************************** + #ifdef _DEBUG_TRACE + { + printf("EmuKrnl (0x%X): NtSetInformationFile\n" + "(\n" + " FileHandle : 0x%.08X\n" + " IoStatusBlock : 0x%.08X\n" + " FileInformation : 0x%.08X\n" + " Length : 0x%.08X\n" + " FileInformationClass : 0x%.08X\n" + ");\n", + GetCurrentThreadId(), FileHandle, IoStatusBlock, FileInformation, + Length, FileInformationClass); + } + #endif + + NTSTATUS ret = NT_NtSetInformationFile(FileHandle, IoStatusBlock, FileInformation, Length, FileInformationClass); + + return ret; +} + // ****************************************************************** // * 0x00DA - NtWriteFile // ****************************************************************** @@ -1180,7 +1218,8 @@ XBSYSAPI EXPORTNUM(277) VOID NTAPI xboxkrnl::RtlEnterCriticalSection #endif // This seems redundant, but xbox software doesn't always do it - NT_RtlInitializeCriticalSection((xntdll::_RTL_CRITICAL_SECTION*)CriticalSection); + if(CriticalSection->LockCount == -1) + NT_RtlInitializeCriticalSection((xntdll::_RTL_CRITICAL_SECTION*)CriticalSection); NT_RtlEnterCriticalSection((xntdll::_RTL_CRITICAL_SECTION*)CriticalSection); diff --git a/Source/Win32/CxbxKrnl/KernelThunk.cpp b/Source/Win32/CxbxKrnl/KernelThunk.cpp index f072b76d4..93674ce02 100644 --- a/Source/Win32/CxbxKrnl/KernelThunk.cpp +++ b/Source/Win32/CxbxKrnl/KernelThunk.cpp @@ -291,7 +291,7 @@ extern "C" CXBXKRNL_API uint32 KernelThunkTable[367] = (uint32)PANIC(0x00DF), // 0x00DF (223) (uint32)PANIC(0x00E0), // 0x00E0 (224) (uint32)PANIC(0x00E1), // 0x00E1 (225) - (uint32)PANIC(0x00E2), // 0x00E2 (226) + (uint32)&xboxkrnl::NtSetInformationFile, // 0x00E2 (226) (uint32)PANIC(0x00E3), // 0x00E3 (227) (uint32)PANIC(0x00E4), // 0x00E4 (228) (uint32)PANIC(0x00E5), // 0x00E5 (229)