diff --git a/CxbxKrnl.dsp b/CxbxKrnl.dsp index 16aa52593..a7cb0c94f 100644 --- a/CxbxKrnl.dsp +++ b/CxbxKrnl.dsp @@ -1,5 +1,5 @@ # Microsoft Developer Studio Project File - Name="CxbxKrnl" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# Microsoft Developer Studio Generated Build File, Format Version 60000 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 @@ -53,7 +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 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:"Bin/CxbxKrnl.pdb" /map:"Bin/CxbxKrnl.map" /debug /machine:I386 /nodefaultlib:"lbc" /out:"Bin/Cxbx.dll" /libpath:"Lib" +# ADD LINK32 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 /debug /machine:I386 /nodefaultlib:"lbc" /out:"Bin/Cxbx.dll" /libpath:"Lib" +# SUBTRACT LINK32 /pdb:none !ELSEIF "$(CFG)" == "CxbxKrnl - Win32 Debug" @@ -213,6 +214,10 @@ SOURCE=.\Include\Win32\CxbxKrnl\ResCxbxDll.h # End Source File # Begin Source File +SOURCE=.\Include\Win32\CxbxKrnl\ThreadList.h +# End Source File +# Begin Source File + SOURCE=.\Include\Win32\CxbxKrnl\Xapi.1.0.3911.h # End Source File # Begin Source File @@ -325,6 +330,10 @@ SOURCE=.\Source\Win32\Mutex.cpp # End Source File # Begin Source File +SOURCE=.\Source\Win32\CxbxKrnl\ThreadList.cpp +# End Source File +# Begin Source File + SOURCE=.\Source\Win32\CxbxKrnl\Xapi.1.0.3911.inl # End Source File # Begin Source File diff --git a/Doc/Changelog.txt b/Doc/Changelog.txt index 650ac23f0..aca23cc9f 100644 --- a/Doc/Changelog.txt +++ b/Doc/Changelog.txt @@ -5,24 +5,23 @@ version: 0.7.0 (??/??/??) - Added Controller Input and Configuration! -- __declspec(thread) style TLS is working!! - - Added Recent Xbe/Exe file menus +- Support __declspec(thread) style TLS ouch!! :) + +- Fixed GUI color issues + - Massive code re-organization. -- Lots of random optimizations +- Sooo many random optimizations - Went lower level with certain components of - emulation. This should allow progress to move - faster, ironically. + emulation. Progress should speed up. - Some Xbe parsing and debug output fixes. You should now be able to deal with the slightly odd Linux Xbe files. -- Fixed GUI color issues - - Much better emulation exception handling version: 0.6.0-pre12 (02/23/03) diff --git a/Doc/Todo.txt b/Doc/Todo.txt index 344908e17..2b0d203da 100644 --- a/Doc/Todo.txt +++ b/Doc/Todo.txt @@ -1,5 +1,7 @@ Cxbx Todo: + Phase out EmuPanic() (EmuCleanup is good) + 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 c651cc067..dcd847182 100644 --- a/Include/Cxbx.h +++ b/Include/Cxbx.h @@ -61,7 +61,7 @@ typedef signed long sint32; // ****************************************************************** // * Version information // ****************************************************************** -#define _CXBX_VERSION "0.7.0-pre1" +#define _CXBX_VERSION "0.7.0-pre2" // ****************************************************************** // * Define this to trace intercepted function calls diff --git a/Include/Win32/CxbxKrnl/EmuKrnl.h b/Include/Win32/CxbxKrnl/EmuKrnl.h index e18246883..c073a4a5a 100644 --- a/Include/Win32/CxbxKrnl/EmuKrnl.h +++ b/Include/Win32/CxbxKrnl/EmuKrnl.h @@ -34,32 +34,4 @@ #ifndef EMUKRNL_H #define EMUKRNL_H -// ****************************************************************** -// * Linked list of threads -// ****************************************************************** -struct ThreadList -{ - static void Insert(HANDLE hThread, DWORD hThreadId) - { - ThreadList *tl = ThreadList::pHead; - - tl->hThread = hThread; - tl->dwThreadId = GetCurrentThreadId(); - tl->pNext = new ThreadList; - tl->pNext->hThread = NULL; - tl->pNext->dwThreadId = 0; - tl->pNext->pNext = NULL; - - ThreadList::pHead = tl->pNext; - } - - static ThreadList *pHead; - static ThreadList *pFirst; - - HANDLE hThread; - DWORD dwThreadId; - - ThreadList *pNext; -}; - #endif diff --git a/Include/Win32/CxbxKrnl/ThreadList.h b/Include/Win32/CxbxKrnl/ThreadList.h new file mode 100644 index 000000000..225777ec2 --- /dev/null +++ b/Include/Win32/CxbxKrnl/ThreadList.h @@ -0,0 +1,56 @@ +// ****************************************************************** +// * +// * .,-::::: .,:: .::::::::. .,:: .: +// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;; +// * [[[ '[[,,[[' [[[__[[\. '[[,,[[' +// * $$$ Y$$$P $$""""Y$$ Y$$$P +// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo, +// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm, +// * +// * Cxbx->Win32->CxbxKrnl->ThreadList.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 THREADLIST_H +#define THREADLIST_H + +#include + +// ****************************************************************** +// * Linked list of threads +// ****************************************************************** +struct ThreadList +{ + static void Insert(HANDLE hThread, DWORD hThreadId); + static void Remove(DWORD hThreadId); + + static ThreadList *pHead; + static ThreadList *pFirst; + + HANDLE hThread; + DWORD dwThreadId; + + ThreadList *pNext; +}; + +#endif diff --git a/Source/Win32/CxbxKrnl/Emu.cpp b/Source/Win32/CxbxKrnl/Emu.cpp index 34ee69424..7e6875a74 100644 --- a/Source/Win32/CxbxKrnl/Emu.cpp +++ b/Source/Win32/CxbxKrnl/Emu.cpp @@ -47,6 +47,7 @@ namespace xboxkrnl #include "EmuD3D8.h" #include "EmuKrnl.h" #include "EmuShared.h" +#include "ThreadList.h" #include "HLEDataBase.h" // ****************************************************************** @@ -401,13 +402,6 @@ extern "C" CXBXKRNL_API void NTAPI EmuPanic() printf("Emu (0x%.08X): EmuPanic()\n", GetCurrentThreadId()); -#ifdef _DEBUG_TRACE - MessageBox(NULL, "Kernel Panic! Process will now terminate.\n\n" - "Check debug traces for hints on the cause of this crash.", "CxbxKrnl", MB_OK | MB_ICONEXCLAMATION); -#else - MessageBox(NULL, "Kernel Panic! Process will now terminate.", "CxbxKrnl", MB_OK | MB_ICONEXCLAMATION); -#endif - EmuCleanup("Kernel Panic!"); EmuSwapFS(); // XBox FS @@ -611,11 +605,13 @@ int ExitException(LPEXCEPTION_POINTERS e) printf("\n"); } + MessageBox(NULL, "Warning: Could not safely terminate process!", "Cxbx", MB_OK); + count++; if(count > 1) { - MessageBox(NULL, "Warning: Could not safely terminate process!", "Cxbx", MB_OK); + MessageBox(NULL, "Warning: Multiple Problems!", "Cxbx", MB_OK); return EXCEPTION_CONTINUE_SEARCH; } diff --git a/Source/Win32/CxbxKrnl/EmuFS.cpp b/Source/Win32/CxbxKrnl/EmuFS.cpp index a93bbda82..c9910480b 100644 --- a/Source/Win32/CxbxKrnl/EmuFS.cpp +++ b/Source/Win32/CxbxKrnl/EmuFS.cpp @@ -108,7 +108,7 @@ void EmuGenerateFS(int TlsAdjust) tlsExData->wSwapFS = NewFS; tlsExData->bIsXboxFS = false; - tlsExData->dwSizeOfOrgTLS = (TlsAdjust == -1) ? -1 : 0x18 + TlsAdjust; + tlsExData->dwSizeOfOrgTLS = (TlsAdjust == -1) ? 0 : 0x18 + TlsAdjust; tlsExData->pOrgTLS = (void*)new char[tlsExData->dwSizeOfOrgTLS]; memcpy(tlsExData->pOrgTLS, TLSPtr, tlsExData->dwSizeOfOrgTLS); @@ -217,7 +217,6 @@ void EmuCleanupFS() } memcpy(TLSPtr, tlsExData->pOrgTLS, tlsExData->dwSizeOfOrgTLS); - } if(tlsExData->wSwapFS != 0) diff --git a/Source/Win32/CxbxKrnl/EmuKrnl.cpp b/Source/Win32/CxbxKrnl/EmuKrnl.cpp index bf673d6e8..07e8e29b2 100644 --- a/Source/Win32/CxbxKrnl/EmuKrnl.cpp +++ b/Source/Win32/CxbxKrnl/EmuKrnl.cpp @@ -56,12 +56,7 @@ namespace xntdll #include "EmuFS.h" #include "EmuFile.h" #include "EmuKrnl.h" - -// ****************************************************************** -// * Globals -// ****************************************************************** -ThreadList *ThreadList::pFirst = new ThreadList; -ThreadList *ThreadList::pHead = ThreadList::pFirst; +#include "ThreadList.h" // ****************************************************************** // * Loaded at run-time to avoid linker conflicts @@ -159,6 +154,10 @@ static DWORD WINAPI PCSTProxy callComplete: + EmuSwapFS(); // Win2k/XP FS + + MessageBox(NULL, "Thread is all done.", "Cxbx", MB_OK); + EmuCleanupFS(); return 0; @@ -811,6 +810,42 @@ XBSYSAPI EXPORTNUM(255) NTSTATUS NTAPI xboxkrnl::PsCreateSystemThreadEx return STATUS_SUCCESS; } +// ****************************************************************** +// * PsTerminateSystemThread +// ****************************************************************** +XBSYSAPI EXPORTNUM(258) VOID NTAPI xboxkrnl::PsTerminateSystemThread(IN NTSTATUS ExitStatus) +{ + EmuSwapFS(); // Win2k/XP FS + + // ****************************************************************** + // * debug trace + // ****************************************************************** + #ifdef _DEBUG_TRACE + { + printf("EmuKrnl (0x%.08X): PsTerminateSystemThread\n" + "(\n" + " ExitStatus : 0x%.08X\n" + ");\n", + GetCurrentThreadId(), ExitStatus); + } + #endif + + // ****************************************************************** + // * Remove this thread handle + // ****************************************************************** + { + DWORD hThreadId = GetCurrentThreadId(); + + ThreadList::Remove(hThreadId); + } + + ExitThread(ExitStatus); + + EmuSwapFS(); // Xbox FS + + return; +} + // ****************************************************************** // * 0x0115 RtlEnterCriticalSection // ****************************************************************** diff --git a/Source/Win32/CxbxKrnl/KernelThunk.cpp b/Source/Win32/CxbxKrnl/KernelThunk.cpp index 3892b144d..8d4fc2803 100644 --- a/Source/Win32/CxbxKrnl/KernelThunk.cpp +++ b/Source/Win32/CxbxKrnl/KernelThunk.cpp @@ -43,6 +43,7 @@ namespace xboxkrnl }; #include "Cxbx.h" +#include "Emu.h" // ****************************************************************** // * NOTE: @@ -56,8 +57,8 @@ namespace xboxkrnl // * option "#define PANIC(numb) cxbx_panic" // * // ****************************************************************** -//#define PANIC(numb) EmuPanic -#define PANIC(numb) numb +#define PANIC(numb) EmuPanic +//#define PANIC(numb) numb // ****************************************************************** // * KernelThunkTable @@ -322,7 +323,7 @@ extern "C" CXBXKRNL_API uint32 KernelThunkTable[367] = (uint32)&xboxkrnl::PsCreateSystemThreadEx, // 0x00FF (255) (uint32)PANIC(0x0100), // 0x0100 (256) (uint32)PANIC(0x0101), // 0x0101 (257) - (uint32)PANIC(0x0102), // 0x0102 (258) + (uint32)&xboxkrnl::PsTerminateSystemThread, // 0x0102 (258) (uint32)PANIC(0x0103), // 0x0103 (259) (uint32)PANIC(0x0104), // 0x0104 (260) (uint32)PANIC(0x0105), // 0x0105 (261) diff --git a/Source/Win32/CxbxKrnl/ThreadList.cpp b/Source/Win32/CxbxKrnl/ThreadList.cpp new file mode 100644 index 000000000..acffe0b25 --- /dev/null +++ b/Source/Win32/CxbxKrnl/ThreadList.cpp @@ -0,0 +1,65 @@ +// ****************************************************************** +// * +// * .,-::::: .,:: .::::::::. .,:: .: +// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;; +// * [[[ '[[,,[[' [[[__[[\. '[[,,[[' +// * $$$ Y$$$P $$""""Y$$ Y$$$P +// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo, +// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm, +// * +// * Cxbx->Win32->CxbxKrnl->ThreadList.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 "ThreadList.h" + +// ****************************************************************** +// * Static +// ****************************************************************** +ThreadList *ThreadList::pFirst = new ThreadList; +ThreadList *ThreadList::pHead = ThreadList::pFirst; + +// ****************************************************************** +// * ThreadList::Insert +// ****************************************************************** +void ThreadList::Insert(HANDLE hThread, DWORD hThreadId) +{ + ThreadList *tl = ThreadList::pHead; + + tl->hThread = hThread; + tl->dwThreadId = GetCurrentThreadId(); + tl->pNext = new ThreadList; + tl->pNext->hThread = NULL; + tl->pNext->dwThreadId = 0; + tl->pNext->pNext = NULL; + + ThreadList::pHead = tl->pNext; +} + +// ****************************************************************** +// * ThreadList::Remove +// ****************************************************************** +void ThreadList::Remove(DWORD hThreadId) +{ + // TODO! (Make this a mutex though!) +}