diff --git a/Doc/Todo.txt b/Doc/Todo.txt index e7f8a381e..fd27e22ae 100644 --- a/Doc/Todo.txt +++ b/Doc/Todo.txt @@ -1,11 +1,15 @@ -Cxbx Todo: +Cxbx Todo (* denotes high priority) - Retail Games! + * Verify TLS stability and correctness + + * 3D Textured Demo + + * Retail Games (esp. XDK 4361) + + * Certain SetRenderState's simply update a global..have Cxbx use these Perfect the timing on KeTickCount - Certain SetRenderState's simply update a global..have Cxbx use these - Some sort of delete-after-emulation type of functionality? Use SetDataFormat instead of parsing device input by hand? diff --git a/Include/Cxbx.h b/Include/Cxbx.h index dcd847182..43a04a562 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/Emu.h b/Include/Win32/CxbxKrnl/Emu.h index 484f2fab7..8b7c9f100 100644 --- a/Include/Win32/CxbxKrnl/Emu.h +++ b/Include/Win32/CxbxKrnl/Emu.h @@ -49,6 +49,11 @@ extern "C" CXBXKRNL_API void NTAPI EmuNoFunc(); // ****************************************************************** extern "C" CXBXKRNL_API void NTAPI EmuInit(void *pTLSData, Xbe::TLS *pTLS, Xbe::LibraryVersion *LibraryVersion, DebugMode DbgMode, char *szDebugFilename, Xbe::Header *XbeHeader, uint32 XbeHeaderSize, void (*Entry)()); +// ****************************************************************** +// * func: EmuCleanThread +// ****************************************************************** +extern "C" CXBXKRNL_API void NTAPI EmuCleanThread(); + // ****************************************************************** // * func: EmuCleanup // ****************************************************************** diff --git a/Source/Win32/CxbxKrnl/Emu.cpp b/Source/Win32/CxbxKrnl/Emu.cpp index 92cf450ee..a542bd3d4 100644 --- a/Source/Win32/CxbxKrnl/Emu.cpp +++ b/Source/Win32/CxbxKrnl/Emu.cpp @@ -91,7 +91,7 @@ extern "C" CXBXKRNL_API void NTAPI EmuNoFunc() // ****************************************************************** // * func: EmuCleanThread // ****************************************************************** -static void EmuCleanThread() +extern "C" CXBXKRNL_API void NTAPI EmuCleanThread() { if(EmuIsXboxFS()) EmuSwapFS(); // Win2k/XP FS diff --git a/Source/Win32/CxbxKrnl/EmuD3D8.cpp b/Source/Win32/CxbxKrnl/EmuD3D8.cpp index e8dba3a11..90ed85251 100644 --- a/Source/Win32/CxbxKrnl/EmuD3D8.cpp +++ b/Source/Win32/CxbxKrnl/EmuD3D8.cpp @@ -161,13 +161,8 @@ DWORD WINAPI EmuUpdateTickCount(LPVOID) { while(true) { - LARGE_INTEGER PerformanceCount; - - QueryPerformanceCounter(&PerformanceCount); - - xboxkrnl::KeTickCount = PerformanceCount.LowPart / 3000; - - Sleep(10); + xboxkrnl::KeTickCount = GetTickCount(); + Sleep(1); } } diff --git a/Source/Win32/CxbxKrnl/EmuFS.cpp b/Source/Win32/CxbxKrnl/EmuFS.cpp index 6d66a6cc1..b5fd8e0ad 100644 --- a/Source/Win32/CxbxKrnl/EmuFS.cpp +++ b/Source/Win32/CxbxKrnl/EmuFS.cpp @@ -65,25 +65,41 @@ void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData) NT_TIB *OrgNtTib; xboxkrnl::KPCR *NewPcr; - uint16 NewFS = -1, OrgFS = -1; + uint08 *pNewTLS = NULL; + + uint16 NewFS = -1, OrgFS = -1; + + // ****************************************************************** + // * Copy Global TLS to Local + // ****************************************************************** + { + uint32 dwSize = RoundUp(pTLS->dwDataEndAddr - pTLS->dwDataStartAddr, 0x04); + + if(dwSize == 0) + pNewTLS = 0; + else + pNewTLS = new uint08[dwSize]; + + memcpy(pNewTLS, pTLSData, dwSize); + } // ****************************************************************** // * Dump Raw TLS data // ****************************************************************** { #ifdef _DEBUG_TRACE - printf("CxbxKrnl (0x%.08X) : Dumping TLS Raw Data... \n 0x%.08X: ", GetCurrentThreadId(), pTLSData); + printf("CxbxKrnl (0x%.08X) : Dumping TLS Raw Data... \n 0x%.08X: ", GetCurrentThreadId(), pNewTLS); - uint32 stop = (pTLS->dwDataEndAddr - pTLS->dwDataStartAddr); + uint32 stop = pTLS->dwDataEndAddr - pTLS->dwDataStartAddr; for(uint32 v=0;vPrcb = &NewPcr->PrcbData; - NewPcr->PrcbData.CurrentThread->TlsData = (void*)pTLSData; + NewPcr->PrcbData.CurrentThread->TlsData = (void*)pNewTLS; } // ****************************************************************** @@ -156,7 +172,8 @@ void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData) *(uint32*)pTLS->dwTLSIndexAddr = 0; // dword @ pTLSData := pTLSData - *(void**)pTLSData = pTLSData; + if(pNewTLS != 0) + *(void**)pNewTLS = pNewTLS; } // ****************************************************************** @@ -184,7 +201,7 @@ void EmuGenerateFS(Xbe::TLS *pTLS, void *pTLSData) { __asm { - mov eax, pTLSData + mov eax, pNewTLS mov fs:[0x04], eax } } @@ -216,7 +233,21 @@ void EmuCleanupFS() if(wSwapFS == 0) return; - // TODO: Cleanup TLS data (after it's implemented) + if(!EmuIsXboxFS()) + EmuSwapFS(); // Xbox FS + + uint08 *pTLSData = NULL; + + __asm + { + mov eax, fs:[0x04] + mov pTLSData, eax + } + + EmuSwapFS(); // Win2k/XP FS + + if(pTLSData != 0) + delete[] pTLSData; EmuDeallocateLDT(wSwapFS); } \ No newline at end of file diff --git a/Source/Win32/CxbxKrnl/EmuKrnl.cpp b/Source/Win32/CxbxKrnl/EmuKrnl.cpp index 7e1b31307..5c02ed37b 100644 --- a/Source/Win32/CxbxKrnl/EmuKrnl.cpp +++ b/Source/Win32/CxbxKrnl/EmuKrnl.cpp @@ -143,9 +143,7 @@ callComplete: EmuSwapFS(); // Win2k/XP FS - MessageBox(NULL, "Thread is all done.", "Cxbx", MB_OK); - - EmuCleanupFS(); + EmuCleanThread(); return 0; }