diff --git a/Doc/Todo.txt b/Doc/Todo.txt index 4b7bddecf..e7f8a381e 100644 --- a/Doc/Todo.txt +++ b/Doc/Todo.txt @@ -2,12 +2,10 @@ Cxbx Todo: Retail Games! - Hijack TLS init function, prepare using our own rules. + Perfect the timing on KeTickCount Certain SetRenderState's simply update a global..have Cxbx use these - Fix TLS (Just do it by hand, forget using Win32 TLS) - Some sort of delete-after-emulation type of functionality? Use SetDataFormat instead of parsing device input by hand? diff --git a/Include/Win32/CxbxKrnl/EmuXapi.h b/Include/Win32/CxbxKrnl/EmuXapi.h index 692da991d..8e9dcf45b 100644 --- a/Include/Win32/CxbxKrnl/EmuXapi.h +++ b/Include/Win32/CxbxKrnl/EmuXapi.h @@ -276,6 +276,15 @@ BOOL WINAPI EmuCloseHandle // ****************************************************************** VOID WINAPI EmuXapiInitProcess(); +// ****************************************************************** +// * func: EmuXapiThreadStartup +// ****************************************************************** +VOID WINAPI EmuXapiThreadStartup +( + DWORD dwDummy1, + DWORD dwDummy2 +); + /* Too High Level! // ****************************************************************** // * func: XapiSetupPerTitleDriveLetters diff --git a/Source/Win32/Cxbx/EmuExe.cpp b/Source/Win32/Cxbx/EmuExe.cpp index c875749ae..5531827c9 100644 --- a/Source/Win32/Cxbx/EmuExe.cpp +++ b/Source/Win32/Cxbx/EmuExe.cpp @@ -516,8 +516,8 @@ EmuExe::EmuExe(Xbe *x_Xbe, DebugMode x_debug_mode, char *x_debug_filename) : Exe { memcpy(pWriteCursor, x_Xbe->m_TLS, sizeof(Xbe::TLS)); pWriteCursor += sizeof(Xbe::TLS); - memcpy(pWriteCursor, x_Xbe->GetTLSData(), (x_Xbe->m_TLS->dwDataEndAddr - x_Xbe->m_TLS->dwDataStartAddr)); - pWriteCursor += (x_Xbe->m_TLS->dwDataEndAddr - x_Xbe->m_TLS->dwDataStartAddr); + memcpy(pWriteCursor, x_Xbe->GetTLSData(), RoundUp(x_Xbe->m_TLS->dwDataEndAddr - x_Xbe->m_TLS->dwDataStartAddr, 0x04)); + pWriteCursor += RoundUp(x_Xbe->m_TLS->dwDataEndAddr - x_Xbe->m_TLS->dwDataStartAddr, 0x04); } // ****************************************************************** @@ -571,7 +571,7 @@ EmuExe::EmuExe(Xbe *x_Xbe, DebugMode x_debug_mode, char *x_debug_filename) : Exe if(x_Xbe->m_TLS != 0) { *(uint32 *)((uint32)m_bzSection[i] + 41) = WriteCursor; - WriteCursor += (x_Xbe->m_TLS->dwDataEndAddr - x_Xbe->m_TLS->dwDataStartAddr); + WriteCursor += RoundUp(x_Xbe->m_TLS->dwDataEndAddr - x_Xbe->m_TLS->dwDataStartAddr, 0x04); } else { diff --git a/Source/Win32/CxbxKrnl/Emu.cpp b/Source/Win32/CxbxKrnl/Emu.cpp index f03ca6dfc..92cf450ee 100644 --- a/Source/Win32/CxbxKrnl/Emu.cpp +++ b/Source/Win32/CxbxKrnl/Emu.cpp @@ -308,8 +308,6 @@ 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 8c6d306bd..e8dba3a11 100644 --- a/Source/Win32/CxbxKrnl/EmuD3D8.cpp +++ b/Source/Win32/CxbxKrnl/EmuD3D8.cpp @@ -364,7 +364,7 @@ HRESULT WINAPI xd3d8::EmuIDirect3D8_CreateDevice Adapter = D3DADAPTER_DEFAULT; -// pPresentationParameters->Windowed = TRUE; + pPresentationParameters->Windowed = TRUE; // TODO: More intelligently set this only when the game wants it // pPresentationParameters->SwapEffect = D3DSWAPEFFECT_COPY_VSYNC; diff --git a/Source/Win32/CxbxKrnl/EmuFS.cpp b/Source/Win32/CxbxKrnl/EmuFS.cpp index 7bcfaab48..6d66a6cc1 100644 --- a/Source/Win32/CxbxKrnl/EmuFS.cpp +++ b/Source/Win32/CxbxKrnl/EmuFS.cpp @@ -148,6 +148,17 @@ void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData) NewPcr->PrcbData.CurrentThread->TlsData = (void*)pTLSData; } + // ****************************************************************** + // * Prepare TLS + // ****************************************************************** + { + // TLS Index Address := 0 + *(uint32*)pTLS->dwTLSIndexAddr = 0; + + // dword @ pTLSData := pTLSData + *(void**)pTLSData = pTLSData; + } + // ****************************************************************** // * Swap into the "NewFS" // ****************************************************************** diff --git a/Source/Win32/CxbxKrnl/EmuXapi.cpp b/Source/Win32/CxbxKrnl/EmuXapi.cpp index 1c02bb08a..470549924 100644 --- a/Source/Win32/CxbxKrnl/EmuXapi.cpp +++ b/Source/Win32/CxbxKrnl/EmuXapi.cpp @@ -290,6 +290,43 @@ VOID WINAPI xapi::EmuXapiInitProcess() return; } + +// ****************************************************************** +// * func: EmuXapiThreadStartup +// ****************************************************************** +VOID WINAPI xapi::EmuXapiThreadStartup +( + DWORD dwDummy1, + DWORD dwDummy2 +) +{ + EmuSwapFS(); // Win2k/XP FS + + // ****************************************************************** + // * debug trace + // ****************************************************************** + #ifdef _DEBUG_TRACE + { + printf("EmuXapi (0x%.08X): EmuXapiThreadStartup\n" + "(\n" + " dwDummy1 : 0x%.08X\n" + " dwDummy2 : 0x%.08X\n" + ");\n", + GetCurrentThreadId(), dwDummy1, dwDummy2); + } + #endif + + EmuSwapFS(); // XBox FS + + __asm + { + push dwDummy2 + call dwDummy1 + } + + return; +} + /* Too High Level! // ****************************************************************** // * func: XapiSetupPerTitleDriveLetters diff --git a/Source/Win32/CxbxKrnl/Xapi.1.0.4361.inl b/Source/Win32/CxbxKrnl/Xapi.1.0.4361.inl index 4bda367df..7b2ea6e45 100644 --- a/Source/Win32/CxbxKrnl/Xapi.1.0.4361.inl +++ b/Source/Win32/CxbxKrnl/Xapi.1.0.4361.inl @@ -250,6 +250,38 @@ SOOVPA<7> XapiInitProcess_1_0_4361 = } }; + +// ****************************************************************** +// * XapiThreadStartup +// ****************************************************************** +SOOVPA<10> XapiThreadStartup_1_0_4361 = +{ + 0, // Large == 0 + 10, // Count == 10 + + { + // XapiThreadStartup+0x00 : push 0x18 + { 0x00, 0x6A }, // (Offset,Value)-Pair #1 + { 0x01, 0x18 }, // (Offset,Value)-Pair #2 + + // XapiThreadStartup+0x10 : mov eax, fs:[0x28] + { 0x10, 0x64 }, // (Offset,Value)-Pair #3 + { 0x11, 0xA1 }, // (Offset,Value)-Pair #4 + { 0x12, 0x28 }, // (Offset,Value)-Pair #5 + + // XapiThreadStartup+0x3F : repe movsd + { 0x3F, 0xF3 }, // (Offset,Value)-Pair #6 + { 0x40, 0xA5 }, // (Offset,Value)-Pair #7 + + // XapiThreadStartup+0x7C : jmp +0x0C + { 0x7C, 0xEB }, // (Offset,Value)-Pair #8 + { 0x7D, 0x0C }, // (Offset,Value)-Pair #9 + + // XapiThreadStartup+0x86 : retn + { 0x86, 0xC3 }, // (Offset,Value)-Pair #10 + } +}; + // ****************************************************************** // * XapiSetupPerTitleDriveLetters // ****************************************************************** @@ -370,6 +402,16 @@ OOVPATable XAPI_1_0_4361[] = #endif }, //*/ + // XapiThreadStartup + { + (OOVPA*)&XapiThreadStartup_1_0_4361, + + xapi::EmuXapiThreadStartup, + + #ifdef _DEBUG_TRACE + "XapiThreadStartup" + #endif + }, /* Too High Level // XapiSetupPerTitleDriveLetters {