From 69ed0614c9c3ef5e77a44ef71f033955ede72535 Mon Sep 17 00:00:00 2001 From: Aaron Robinson Date: Sat, 26 Apr 2003 04:32:46 +0000 Subject: [PATCH] Cleaning up. --- Cxbx.dsp | 2 +- Doc/Todo.txt | 2 ++ Include/Win32/CxbxKrnl/Emu.h | 2 +- Include/Win32/CxbxKrnl/EmuDInput.h | 2 +- Include/Win32/CxbxKrnl/EmuKrnl.h | 10 +++++++ Source/Win32/CxbxKrnl/Emu.cpp | 41 +++++++++++++++++++++++++---- Source/Win32/CxbxKrnl/EmuD3D8.cpp | 16 ++++++++--- Source/Win32/CxbxKrnl/EmuDInput.cpp | 14 ++++++++-- Source/Win32/CxbxKrnl/EmuKrnl.cpp | 13 +++++++++ Source/Win32/CxbxKrnl/EmuXapi.cpp | 2 +- 10 files changed, 90 insertions(+), 14 deletions(-) diff --git a/Cxbx.dsp b/Cxbx.dsp index fedcdc70b..93899db57 100644 --- a/Cxbx.dsp +++ b/Cxbx.dsp @@ -1,5 +1,5 @@ # Microsoft Developer Studio Project File - Name="Cxbx" - 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) Application" 0x0101 diff --git a/Doc/Todo.txt b/Doc/Todo.txt index 712f73443..344908e17 100644 --- a/Doc/Todo.txt +++ b/Doc/Todo.txt @@ -1,5 +1,7 @@ Cxbx Todo: + Some sort of delete-after-emulation type of functionality? + Use SetDataFormat instead of parsing device input by hand? Batch config all buttons (should be very easy..just click one by one) diff --git a/Include/Win32/CxbxKrnl/Emu.h b/Include/Win32/CxbxKrnl/Emu.h index c68e66f0e..dc7a9b521 100644 --- a/Include/Win32/CxbxKrnl/Emu.h +++ b/Include/Win32/CxbxKrnl/Emu.h @@ -52,7 +52,7 @@ extern "C" CXBXKRNL_API void NTAPI EmuInit(uint32 TlsAdjust, Xbe::LibraryVersion // ****************************************************************** // * func: EmuCleanup // ****************************************************************** -extern "C" CXBXKRNL_API void NTAPI EmuCleanup(); +extern "C" CXBXKRNL_API void NTAPI EmuCleanup(const char *szErrorMessage); // ****************************************************************** // * func: EmuPanic diff --git a/Include/Win32/CxbxKrnl/EmuDInput.h b/Include/Win32/CxbxKrnl/EmuDInput.h index fbd1a8bd6..6fb962ed5 100644 --- a/Include/Win32/CxbxKrnl/EmuDInput.h +++ b/Include/Win32/CxbxKrnl/EmuDInput.h @@ -45,7 +45,7 @@ namespace xapi // ****************************************************************** // * func: EmuDInputInit // ****************************************************************** -extern void EmuDInputInit(); +extern bool EmuDInputInit(); // ****************************************************************** // * func: EmuDInputCleanup diff --git a/Include/Win32/CxbxKrnl/EmuKrnl.h b/Include/Win32/CxbxKrnl/EmuKrnl.h index 814d28c57..29a41c2d6 100644 --- a/Include/Win32/CxbxKrnl/EmuKrnl.h +++ b/Include/Win32/CxbxKrnl/EmuKrnl.h @@ -34,5 +34,15 @@ #ifndef EMUKRNL_H #define EMUKRNL_H +// ****************************************************************** +// * Linked list of threads +// ****************************************************************** +struct ThreadList +{ + static ThreadList *pHead; + + HANDLE hThread; + ThreadList *pNext; +}; #endif diff --git a/Source/Win32/CxbxKrnl/Emu.cpp b/Source/Win32/CxbxKrnl/Emu.cpp index 708ca4ec7..9f85542aa 100644 --- a/Source/Win32/CxbxKrnl/Emu.cpp +++ b/Source/Win32/CxbxKrnl/Emu.cpp @@ -45,6 +45,7 @@ namespace xboxkrnl #include "Emu.h" #include "EmuFS.h" #include "EmuD3D8.h" +#include "EmuKrnl.h" #include "EmuShared.h" #include "HLEDataBase.h" @@ -255,22 +256,52 @@ extern "C" CXBXKRNL_API void NTAPI EmuInit(uint32 TlsAdjust, Xbe::LibraryVersion fflush(stdout); - while(true) - Sleep(1000); - return; } // ****************************************************************** // * func: EmuCleanup // ****************************************************************** -extern "C" CXBXKRNL_API void NTAPI EmuCleanup() +extern "C" CXBXKRNL_API void NTAPI EmuCleanup(const char *szErrorMessage) { if(EmuIsXboxFS()) EmuSwapFS(); // Win2k/XP FS + // ****************************************************************** + // * Suspend all Threads + // ****************************************************************** + while(true) + { + ThreadList *tl = ThreadList::pHead; + + if(tl == NULL) + break; + + SuspendThread(tl->hThread); + + ThreadList::pHead = tl->pNext; + + delete tl; + } + + // ****************************************************************** + // * Print out ErrorMessage (if exists) + // ****************************************************************** + if(szErrorMessage != NULL) + { + char buffer[255]; + + sprintf(buffer, "CxbxKrnl: Recieved Exception \"%s\"\n", szErrorMessage); + + printf("%s", buffer); + + MessageBox(NULL, buffer, "CxbxKrnl", MB_OK | MB_ICONEXCLAMATION); + } + // EmuD3DCleanup(); + printf("CxbxKrnl: Terminating Process\n"); + ExitProcess(0); return; @@ -293,7 +324,7 @@ extern "C" CXBXKRNL_API void NTAPI EmuPanic() MessageBox(NULL, "Kernel Panic! Process will now terminate.", "CxbxKrnl", MB_OK | MB_ICONEXCLAMATION); #endif - EmuCleanup(); + EmuCleanup("Kernel Panic!"); EmuSwapFS(); // XBox FS } diff --git a/Source/Win32/CxbxKrnl/EmuD3D8.cpp b/Source/Win32/CxbxKrnl/EmuD3D8.cpp index 92d6d3b98..e060675b5 100644 --- a/Source/Win32/CxbxKrnl/EmuD3D8.cpp +++ b/Source/Win32/CxbxKrnl/EmuD3D8.cpp @@ -70,6 +70,7 @@ uint32 g_XbeHeaderSize = 0; // XbeHeaderSize HWND g_EmuWindow = NULL; // Rendering Window xd3d8::D3DCAPS8 g_D3DCaps; // Direct3D8 Caps bool g_ThreadInitialized = false; +HBRUSH g_hBgBrush = NULL; // Background Brush // ****************************************************************** // * statics @@ -111,6 +112,9 @@ VOID EmuD3DInit(Xbe::Header *XbeHeader, uint32 XbeHeaderSize) // xbox Direct3DCreate8 returns "1" always, so we need our own ptr g_pD3D8 = Direct3DCreate8(D3D_SDK_VERSION); + if(g_pD3D8 == NULL) + EmuCleanup("Could not initialize Direct3D!"); + g_pD3D8->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &g_D3DCaps); } } @@ -140,6 +144,10 @@ void EmuRenderWindow(PVOID) HMODULE hCxbxDll = GetModuleHandle("Cxbx.dll"); #endif + LOGBRUSH logBrush = {BS_SOLID, RGB(0,0,0)}; + + g_hBgBrush = CreateBrushIndirect(&logBrush); + WNDCLASSEX wc = { sizeof(WNDCLASSEX), @@ -148,7 +156,7 @@ void EmuRenderWindow(PVOID) 0, 0, GetModuleHandle(NULL), LoadIcon(hCxbxDll, MAKEINTRESOURCE(IDI_CXBX)), LoadCursor(NULL, IDC_ARROW), - (HBRUSH)(COLOR_APPWORKSPACE + 1), NULL, + (HBRUSH)(g_hBgBrush), NULL, "CxbxRender", NULL }; @@ -201,7 +209,8 @@ void EmuRenderWindow(PVOID) // ****************************************************************** // * initialize direct input // ****************************************************************** - EmuDInputInit(); + if(!EmuDInputInit()) + EmuCleanup("Could not initialize DirectInput!"); // ****************************************************************** // * message processing loop @@ -224,7 +233,7 @@ void EmuRenderWindow(PVOID) Sleep(10); } - EmuCleanup(); + EmuCleanup(NULL); } } @@ -236,6 +245,7 @@ LRESULT WINAPI EmuMsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) switch(msg) { case WM_DESTROY: + DeleteObject(g_hBgBrush); PostQuitMessage(0); return 0; diff --git a/Source/Win32/CxbxKrnl/EmuDInput.cpp b/Source/Win32/CxbxKrnl/EmuDInput.cpp index d322a8985..7de755923 100644 --- a/Source/Win32/CxbxKrnl/EmuDInput.cpp +++ b/Source/Win32/CxbxKrnl/EmuDInput.cpp @@ -57,13 +57,16 @@ namespace xapi // ****************************************************************** // * func: EmuDInputInit // ****************************************************************** -void EmuDInputInit() +bool EmuDInputInit() { g_EmuShared->GetXBController(&g_XBController); g_XBController.ListenBegin(g_EmuWindow); - return; + if(g_XBController.GetError()) + return false; + + return true; } // ****************************************************************** @@ -72,6 +75,9 @@ void EmuDInputInit() void EmuDInputCleanup() { g_XBController.ListenEnd(); + + if(g_XBController.GetError()) + MessageBox(NULL, g_XBController.GetError(), "Cxbx [*UNHANDLED!*]", MB_OK); // TODO: Handle this! } // ****************************************************************** @@ -80,5 +86,9 @@ void EmuDInputCleanup() void EmuDInputPoll(xapi::PXINPUT_STATE Controller) { g_XBController.ListenPoll(Controller); + + if(g_XBController.GetError()) + MessageBox(NULL, g_XBController.GetError(), "Cxbx [*UNHANDLED!*]", MB_OK); // TODO: Handle this! + return; } \ No newline at end of file diff --git a/Source/Win32/CxbxKrnl/EmuKrnl.cpp b/Source/Win32/CxbxKrnl/EmuKrnl.cpp index a579ec296..6af52b9a2 100644 --- a/Source/Win32/CxbxKrnl/EmuKrnl.cpp +++ b/Source/Win32/CxbxKrnl/EmuKrnl.cpp @@ -55,6 +55,12 @@ namespace xntdll #include "Emu.h" #include "EmuFS.h" #include "EmuFile.h" +#include "EmuKrnl.h" + +// ****************************************************************** +// * Globals +// ****************************************************************** +ThreadList *ThreadList::pHead = new ThreadList; // ****************************************************************** // * Loaded at run-time to avoid linker conflicts @@ -91,6 +97,13 @@ static DWORD WINAPI PCSTProxy IN PVOID Parameter ) { + ThreadList *tl = ThreadList::pHead; + + tl->hThread = GetCurrentThread(); + tl->pNext = new ThreadList; + tl->pNext->pNext = NULL; + tl->pHead = tl->pNext; + PCSTProxyParam *iPCSTProxyParam = (PCSTProxyParam*)Parameter; uint32 StartContext1 = (uint32)iPCSTProxyParam->StartContext1; diff --git a/Source/Win32/CxbxKrnl/EmuXapi.cpp b/Source/Win32/CxbxKrnl/EmuXapi.cpp index a584ed810..bbb751043 100644 --- a/Source/Win32/CxbxKrnl/EmuXapi.cpp +++ b/Source/Win32/CxbxKrnl/EmuXapi.cpp @@ -445,7 +445,7 @@ VOID WINAPI xapi::EmuXapiBootDash(DWORD UnknownA, DWORD UnknownB, DWORD UnknownC } #endif - MessageBox(NULL, "Warning: XBE has terminated unexpectedly.\n\nThis process might not terminate elegantly.", "Cxbx", MB_OK); + MessageBox(NULL, "EmuXapiBootDash (Emulation can not continue).", "Cxbx", MB_OK | MB_ICONSTOP); ExitProcess(0);