2003-02-15 22:16:14 +00:00
|
|
|
// ******************************************************************
|
|
|
|
// *
|
|
|
|
// * .,-::::: .,:: .::::::::. .,:: .:
|
|
|
|
// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;;
|
|
|
|
// * [[[ '[[,,[[' [[[__[[\. '[[,,[['
|
|
|
|
// * $$$ Y$$$P $$""""Y$$ Y$$$P
|
|
|
|
// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
|
|
|
|
// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
|
|
|
|
// *
|
2003-03-27 06:23:58 +00:00
|
|
|
// * Cxbx->Win32->CxbxKrnl->EmuD3D.cpp
|
2003-02-15 22:16:14 +00:00
|
|
|
// *
|
|
|
|
// * 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 <caustik@caustik.com>
|
|
|
|
// *
|
|
|
|
// * All rights reserved
|
|
|
|
// *
|
2003-03-07 22:01:44 +00:00
|
|
|
// ******************************************************************
|
|
|
|
#define _CXBXKRNL_INTERNAL
|
2003-04-02 02:23:30 +00:00
|
|
|
#define _XBOXKRNL_LOCAL_
|
|
|
|
|
|
|
|
// ******************************************************************
|
|
|
|
// * prevent name collisions
|
|
|
|
// ******************************************************************
|
|
|
|
namespace xboxkrnl
|
|
|
|
{
|
|
|
|
#include <xboxkrnl/xboxkrnl.h>
|
|
|
|
};
|
|
|
|
|
2003-03-27 06:23:58 +00:00
|
|
|
#include "Emu.h"
|
2003-04-02 02:23:30 +00:00
|
|
|
#include "EmuFS.h"
|
|
|
|
#include "EmuDInput.h"
|
2003-02-15 22:16:14 +00:00
|
|
|
|
2003-03-07 22:01:44 +00:00
|
|
|
// ******************************************************************
|
|
|
|
// * prevent name collisions
|
|
|
|
// ******************************************************************
|
2003-04-02 02:23:30 +00:00
|
|
|
namespace xd3d8
|
2003-02-21 00:07:28 +00:00
|
|
|
{
|
2003-04-02 02:23:30 +00:00
|
|
|
#include "xd3d8.h"
|
|
|
|
};
|
2003-02-21 00:07:28 +00:00
|
|
|
|
2003-04-02 02:23:30 +00:00
|
|
|
#include "EmuD3D8.h"
|
2003-03-04 07:05:25 +00:00
|
|
|
#include "ResCxbxDll.h"
|
|
|
|
|
2003-04-02 02:23:30 +00:00
|
|
|
#include <process.h>
|
|
|
|
#include <locale.h>
|
2003-02-15 22:16:14 +00:00
|
|
|
|
|
|
|
// ******************************************************************
|
|
|
|
// * globals
|
|
|
|
// ******************************************************************
|
2003-04-02 02:23:30 +00:00
|
|
|
xd3d8::LPDIRECT3D8 g_pD3D8 = NULL; // Direct3D8
|
|
|
|
xd3d8::LPDIRECT3DDEVICE8 g_pD3D8Device = NULL; // Direct3D8 Device
|
|
|
|
Xbe::Header *g_XbeHeader = NULL; // XbeHeader
|
|
|
|
uint32 g_XbeHeaderSize = 0; // XbeHeaderSize
|
2003-04-26 08:57:51 +00:00
|
|
|
HWND g_hEmuWindow = NULL; // Rendering Window
|
2003-04-02 02:23:30 +00:00
|
|
|
xd3d8::D3DCAPS8 g_D3DCaps; // Direct3D8 Caps
|
2003-04-26 23:10:35 +00:00
|
|
|
volatile bool g_ThreadInitialized = false;
|
2003-04-26 04:32:46 +00:00
|
|
|
HBRUSH g_hBgBrush = NULL; // Background Brush
|
2003-02-15 22:16:14 +00:00
|
|
|
|
|
|
|
// ******************************************************************
|
2003-03-23 22:24:41 +00:00
|
|
|
// * statics
|
2003-02-15 22:16:14 +00:00
|
|
|
// ******************************************************************
|
2003-03-27 06:23:58 +00:00
|
|
|
static LRESULT WINAPI EmuMsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
|
|
|
static void EmuRenderWindow(PVOID);
|
2003-02-15 22:16:14 +00:00
|
|
|
|
|
|
|
// ******************************************************************
|
2003-04-16 19:06:20 +00:00
|
|
|
// * func: EmuD3DInit
|
2003-02-15 22:16:14 +00:00
|
|
|
// ******************************************************************
|
2003-04-16 19:06:20 +00:00
|
|
|
VOID EmuD3DInit(Xbe::Header *XbeHeader, uint32 XbeHeaderSize)
|
2003-02-21 00:07:28 +00:00
|
|
|
{
|
2003-03-21 03:30:00 +00:00
|
|
|
// ******************************************************************
|
|
|
|
// * store XbeHeader and XbeHeaderSize for further use
|
|
|
|
// ******************************************************************
|
|
|
|
{
|
|
|
|
g_XbeHeader = XbeHeader;
|
|
|
|
g_XbeHeaderSize = XbeHeaderSize;
|
|
|
|
}
|
|
|
|
|
2003-04-16 19:06:20 +00:00
|
|
|
g_ThreadInitialized = false;
|
|
|
|
|
2003-02-21 00:07:28 +00:00
|
|
|
// ******************************************************************
|
|
|
|
// * spark up a new thread to handle window message processing
|
|
|
|
// ******************************************************************
|
|
|
|
{
|
2003-03-27 06:23:58 +00:00
|
|
|
_beginthread(EmuRenderWindow, 0, NULL);
|
2003-02-21 00:07:28 +00:00
|
|
|
|
2003-04-15 08:08:53 +00:00
|
|
|
while(!g_ThreadInitialized)
|
2003-03-07 07:38:26 +00:00
|
|
|
Sleep(10);
|
2003-04-26 23:10:35 +00:00
|
|
|
|
|
|
|
Sleep(50);
|
2003-02-21 00:07:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ******************************************************************
|
2003-04-01 02:47:38 +00:00
|
|
|
// * create Direct3D8 and retrieve caps
|
2003-02-21 00:07:28 +00:00
|
|
|
// ******************************************************************
|
|
|
|
{
|
2003-04-02 02:23:30 +00:00
|
|
|
using namespace xd3d8;
|
2003-04-08 03:34:05 +00:00
|
|
|
|
2003-02-21 00:07:28 +00:00
|
|
|
// xbox Direct3DCreate8 returns "1" always, so we need our own ptr
|
|
|
|
g_pD3D8 = Direct3DCreate8(D3D_SDK_VERSION);
|
2003-04-01 02:47:38 +00:00
|
|
|
|
2003-04-26 04:32:46 +00:00
|
|
|
if(g_pD3D8 == NULL)
|
|
|
|
EmuCleanup("Could not initialize Direct3D!");
|
|
|
|
|
2003-04-01 02:47:38 +00:00
|
|
|
g_pD3D8->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &g_D3DCaps);
|
2003-02-21 00:07:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-16 19:06:20 +00:00
|
|
|
// ******************************************************************
|
|
|
|
// * func: EmuD3DCleanup
|
|
|
|
// ******************************************************************
|
|
|
|
VOID EmuD3DCleanup()
|
|
|
|
{
|
|
|
|
EmuDInputCleanup();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-02-21 00:07:28 +00:00
|
|
|
// ******************************************************************
|
2003-03-27 06:23:58 +00:00
|
|
|
// * func: EmuRenderWindow
|
2003-02-21 00:07:28 +00:00
|
|
|
// ******************************************************************
|
2003-03-27 06:23:58 +00:00
|
|
|
void EmuRenderWindow(PVOID)
|
2003-02-15 22:16:14 +00:00
|
|
|
{
|
|
|
|
// ******************************************************************
|
|
|
|
// * register window class
|
|
|
|
// ******************************************************************
|
|
|
|
{
|
2003-04-06 20:07:36 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
HMODULE hCxbxDll = GetModuleHandle("CxbxKrnl.dll");
|
|
|
|
#else
|
2003-03-04 07:05:25 +00:00
|
|
|
HMODULE hCxbxDll = GetModuleHandle("Cxbx.dll");
|
2003-04-06 20:07:36 +00:00
|
|
|
#endif
|
2003-03-04 07:05:25 +00:00
|
|
|
|
2003-04-26 04:32:46 +00:00
|
|
|
LOGBRUSH logBrush = {BS_SOLID, RGB(0,0,0)};
|
|
|
|
|
|
|
|
g_hBgBrush = CreateBrushIndirect(&logBrush);
|
|
|
|
|
2003-02-15 22:16:14 +00:00
|
|
|
WNDCLASSEX wc =
|
|
|
|
{
|
|
|
|
sizeof(WNDCLASSEX),
|
|
|
|
CS_CLASSDC,
|
2003-03-27 06:23:58 +00:00
|
|
|
EmuMsgProc,
|
2003-02-15 22:16:14 +00:00
|
|
|
0, 0, GetModuleHandle(NULL),
|
2003-04-17 01:32:51 +00:00
|
|
|
LoadIcon(hCxbxDll, MAKEINTRESOURCE(IDI_CXBX)),
|
|
|
|
LoadCursor(NULL, IDC_ARROW),
|
2003-04-26 04:32:46 +00:00
|
|
|
(HBRUSH)(g_hBgBrush), NULL,
|
2003-02-15 22:16:14 +00:00
|
|
|
"CxbxRender",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
RegisterClassEx(&wc);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ******************************************************************
|
|
|
|
// * create the window
|
|
|
|
// ******************************************************************
|
|
|
|
{
|
2003-03-21 03:30:00 +00:00
|
|
|
char AsciiTitle[50];
|
|
|
|
|
|
|
|
// ******************************************************************
|
|
|
|
// * retrieve xbe title (if possible)
|
|
|
|
// ******************************************************************
|
|
|
|
{
|
|
|
|
char tAsciiTitle[40] = "Unknown";
|
|
|
|
|
|
|
|
uint32 CertAddr = g_XbeHeader->dwCertificateAddr - g_XbeHeader->dwBaseAddr;
|
|
|
|
|
|
|
|
if(CertAddr + 0x0C + 40 < g_XbeHeaderSize)
|
|
|
|
{
|
|
|
|
Xbe::Certificate *XbeCert = (Xbe::Certificate*)((uint32)g_XbeHeader + CertAddr);
|
|
|
|
|
|
|
|
setlocale( LC_ALL, "English" );
|
|
|
|
|
|
|
|
wcstombs(tAsciiTitle, XbeCert->wszTitleName, 40);
|
|
|
|
}
|
|
|
|
|
2003-04-08 03:34:05 +00:00
|
|
|
sprintf(AsciiTitle, "Cxbx : Emulating %s", tAsciiTitle);
|
2003-03-21 03:30:00 +00:00
|
|
|
}
|
|
|
|
|
2003-04-26 08:57:51 +00:00
|
|
|
g_hEmuWindow = CreateWindow
|
2003-02-15 22:16:14 +00:00
|
|
|
(
|
2003-03-21 03:30:00 +00:00
|
|
|
"CxbxRender", AsciiTitle,
|
2003-02-15 22:16:14 +00:00
|
|
|
WS_OVERLAPPEDWINDOW, 100, 100, 640, 480,
|
|
|
|
GetDesktopWindow(), NULL, GetModuleHandle(NULL), NULL
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ******************************************************************
|
|
|
|
// * display the window
|
|
|
|
// ******************************************************************
|
|
|
|
{
|
2003-04-26 08:57:51 +00:00
|
|
|
ShowWindow(g_hEmuWindow, SW_SHOWDEFAULT);
|
|
|
|
UpdateWindow(g_hEmuWindow);
|
2003-02-19 20:53:33 +00:00
|
|
|
}
|
|
|
|
|
2003-03-23 22:24:41 +00:00
|
|
|
// ******************************************************************
|
|
|
|
// * initialize direct input
|
|
|
|
// ******************************************************************
|
2003-04-26 04:32:46 +00:00
|
|
|
if(!EmuDInputInit())
|
|
|
|
EmuCleanup("Could not initialize DirectInput!");
|
2003-03-23 22:24:41 +00:00
|
|
|
|
2003-02-22 07:49:02 +00:00
|
|
|
// ******************************************************************
|
|
|
|
// * message processing loop
|
|
|
|
// ******************************************************************
|
|
|
|
{
|
|
|
|
MSG msg;
|
2003-02-15 22:16:14 +00:00
|
|
|
|
2003-02-22 07:49:02 +00:00
|
|
|
ZeroMemory(&msg, sizeof(msg));
|
2003-02-21 00:07:28 +00:00
|
|
|
|
2003-02-22 07:49:02 +00:00
|
|
|
while(msg.message != WM_QUIT)
|
2003-02-21 00:07:28 +00:00
|
|
|
{
|
2003-04-26 23:10:35 +00:00
|
|
|
if(PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
|
2003-02-22 07:49:02 +00:00
|
|
|
{
|
2003-04-18 23:44:36 +00:00
|
|
|
g_ThreadInitialized = true;
|
|
|
|
|
2003-02-22 07:49:02 +00:00
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Sleep(10);
|
2003-02-21 00:07:28 +00:00
|
|
|
}
|
2003-02-15 22:16:14 +00:00
|
|
|
|
2003-04-26 04:32:46 +00:00
|
|
|
EmuCleanup(NULL);
|
2003-02-22 07:49:02 +00:00
|
|
|
}
|
2003-02-15 22:16:14 +00:00
|
|
|
}
|
|
|
|
|
2003-02-21 04:51:03 +00:00
|
|
|
// ******************************************************************
|
2003-03-27 06:23:58 +00:00
|
|
|
// * func: EmuMsgProc
|
2003-02-21 04:51:03 +00:00
|
|
|
// ******************************************************************
|
2003-03-27 06:23:58 +00:00
|
|
|
LRESULT WINAPI EmuMsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
2003-02-21 04:51:03 +00:00
|
|
|
{
|
|
|
|
switch(msg)
|
|
|
|
{
|
|
|
|
case WM_DESTROY:
|
2003-04-26 04:32:46 +00:00
|
|
|
DeleteObject(g_hBgBrush);
|
2003-02-21 04:51:03 +00:00
|
|
|
PostQuitMessage(0);
|
|
|
|
return 0;
|
2003-03-04 07:48:23 +00:00
|
|
|
|
2003-03-09 09:17:07 +00:00
|
|
|
case WM_KEYDOWN:
|
2003-04-16 19:06:20 +00:00
|
|
|
if(wParam == VK_ESCAPE)
|
|
|
|
PostMessage(hWnd, WM_CLOSE, 0, 0);
|
2003-03-09 09:17:07 +00:00
|
|
|
break;
|
|
|
|
|
2003-03-04 07:48:23 +00:00
|
|
|
case WM_CLOSE:
|
|
|
|
DestroyWindow(hWnd);
|
|
|
|
break;
|
2003-04-26 23:10:35 +00:00
|
|
|
|
|
|
|
/*
|
2003-03-23 22:24:41 +00:00
|
|
|
case WM_SETCURSOR:
|
|
|
|
SetCursor(NULL);
|
2003-04-26 23:10:35 +00:00
|
|
|
return 0;
|
|
|
|
*/
|
2003-04-16 19:06:20 +00:00
|
|
|
default:
|
|
|
|
return DefWindowProc(hWnd, msg, wParam, lParam);
|
2003-02-21 04:51:03 +00:00
|
|
|
}
|
|
|
|
|
2003-04-16 19:06:20 +00:00
|
|
|
return 0;
|
2003-02-21 04:51:03 +00:00
|
|
|
}
|
|
|
|
|
2003-02-15 22:16:14 +00:00
|
|
|
// ******************************************************************
|
2003-03-27 06:23:58 +00:00
|
|
|
// * func: EmuIDirect3D8_CreateDevice
|
2003-02-15 22:16:14 +00:00
|
|
|
// ******************************************************************
|
2003-04-02 02:23:30 +00:00
|
|
|
HRESULT WINAPI xd3d8::EmuIDirect3D8_CreateDevice
|
2003-02-15 22:16:14 +00:00
|
|
|
(
|
|
|
|
UINT Adapter,
|
|
|
|
D3DDEVTYPE DeviceType,
|
|
|
|
HWND hFocusWindow,
|
|
|
|
DWORD BehaviorFlags,
|
|
|
|
D3DPRESENT_PARAMETERS *pPresentationParameters,
|
|
|
|
IDirect3DDevice8 **ppReturnedDeviceInterface
|
|
|
|
)
|
|
|
|
{
|
2003-03-27 06:23:58 +00:00
|
|
|
EmuSwapFS(); // Win2k/XP FS
|
2003-02-19 20:53:33 +00:00
|
|
|
|
|
|
|
// ******************************************************************
|
|
|
|
// * debug trace
|
|
|
|
// ******************************************************************
|
|
|
|
#ifdef _DEBUG_TRACE
|
|
|
|
{
|
2003-03-27 06:23:58 +00:00
|
|
|
printf("EmuD3D8 (0x%.08X): EmuIDirect3D8_CreateDevice\n"
|
2003-02-19 20:53:33 +00:00
|
|
|
"(\n"
|
|
|
|
" Adapter : 0x%.08X\n"
|
|
|
|
" DeviceType : 0x%.08X\n"
|
|
|
|
" hFocusWindow : 0x%.08X\n"
|
|
|
|
" BehaviorFlags : 0x%.08X\n"
|
|
|
|
" pPresentationParameters : 0x%.08X\n"
|
|
|
|
" ppReturnedDeviceInterface : 0x%.08X\n"
|
|
|
|
");\n",
|
|
|
|
GetCurrentThreadId(), Adapter, DeviceType, hFocusWindow,
|
|
|
|
BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// ******************************************************************
|
|
|
|
// * make adjustments to parameters to make sense with windows d3d
|
|
|
|
// ******************************************************************
|
|
|
|
{
|
2003-03-27 03:52:19 +00:00
|
|
|
/*
|
|
|
|
printf("BackBufferWidth : %d\n", pPresentationParameters->BackBufferWidth);
|
|
|
|
printf("BackBufferHeight : %d\n", pPresentationParameters->BackBufferHeight);
|
|
|
|
printf("BackBufferFormat : %d\n", pPresentationParameters->BackBufferFormat);
|
|
|
|
printf("BackBufferCount : %d\n", pPresentationParameters->BackBufferCount);
|
|
|
|
printf("EnableAutoDepthStencil : %d\n", pPresentationParameters->EnableAutoDepthStencil);
|
|
|
|
printf("AutoDepthStencilFormat : %d\n", pPresentationParameters->AutoDepthStencilFormat);
|
|
|
|
printf("SwapEffect : %d\n", pPresentationParameters->SwapEffect);
|
|
|
|
*/
|
|
|
|
|
2003-02-19 20:53:33 +00:00
|
|
|
Adapter = D3DADAPTER_DEFAULT;
|
|
|
|
|
2003-03-24 07:17:33 +00:00
|
|
|
pPresentationParameters->Windowed = TRUE;
|
2003-02-19 20:53:33 +00:00
|
|
|
|
2003-02-23 08:01:01 +00:00
|
|
|
// TODO: More intelligently set this only when the game wants it
|
2003-03-27 05:56:08 +00:00
|
|
|
//pPresentationParameters->SwapEffect = D3DSWAPEFFECT_COPY_VSYNC;
|
2003-02-23 08:01:01 +00:00
|
|
|
|
2003-04-26 08:57:51 +00:00
|
|
|
hFocusWindow = g_hEmuWindow;
|
2003-02-19 20:53:33 +00:00
|
|
|
|
2003-02-22 07:49:02 +00:00
|
|
|
// TODO: Use lookup table that is dependant on library version
|
|
|
|
{
|
2003-04-01 02:47:38 +00:00
|
|
|
// Xbox DirectX #defines are different from Win32 DirectX
|
2003-02-22 07:49:02 +00:00
|
|
|
if(pPresentationParameters->BackBufferFormat == 0x07)
|
|
|
|
pPresentationParameters->BackBufferFormat = D3DFMT_X8R8G8B8;
|
2003-03-27 03:52:19 +00:00
|
|
|
else if(pPresentationParameters->BackBufferFormat == 0x06)
|
|
|
|
pPresentationParameters->BackBufferFormat = D3DFMT_A8R8G8B8;
|
2003-02-19 20:53:33 +00:00
|
|
|
|
2003-04-01 02:47:38 +00:00
|
|
|
// Xbox DirectX #defines are different from Win32 DirectX
|
2003-02-22 07:49:02 +00:00
|
|
|
if(pPresentationParameters->AutoDepthStencilFormat == 0x2A)
|
|
|
|
pPresentationParameters->AutoDepthStencilFormat = D3DFMT_D24S8;
|
|
|
|
}
|
2003-02-19 20:53:33 +00:00
|
|
|
}
|
|
|
|
|
2003-02-20 08:07:52 +00:00
|
|
|
// ******************************************************************
|
|
|
|
// * TODO: Query for Software Vertex Processing abilities!!
|
|
|
|
// ******************************************************************
|
2003-02-22 07:49:02 +00:00
|
|
|
BehaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
|
2003-02-20 08:07:52 +00:00
|
|
|
|
2003-02-19 20:53:33 +00:00
|
|
|
// ******************************************************************
|
|
|
|
// * redirect to windows d3d
|
|
|
|
// ******************************************************************
|
2003-02-20 08:07:52 +00:00
|
|
|
HRESULT ret = g_pD3D8->CreateDevice
|
2003-02-19 20:53:33 +00:00
|
|
|
(
|
|
|
|
Adapter,
|
|
|
|
DeviceType,
|
|
|
|
hFocusWindow,
|
2003-02-22 07:49:02 +00:00
|
|
|
BehaviorFlags,
|
2003-02-19 20:53:33 +00:00
|
|
|
pPresentationParameters,
|
|
|
|
ppReturnedDeviceInterface
|
|
|
|
);
|
|
|
|
|
2003-02-20 08:07:52 +00:00
|
|
|
// ******************************************************************
|
|
|
|
// * it is necessary to store this pointer globally for emulation
|
|
|
|
// ******************************************************************
|
2003-02-22 07:49:02 +00:00
|
|
|
g_pD3D8Device = *ppReturnedDeviceInterface;
|
2003-02-20 08:07:52 +00:00
|
|
|
|
2003-03-27 06:23:58 +00:00
|
|
|
EmuSwapFS(); // XBox FS
|
2003-02-19 20:53:33 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ******************************************************************
|
2003-03-27 06:23:58 +00:00
|
|
|
// * func: EmuIDirect3DDevice8_Clear
|
2003-02-19 20:53:33 +00:00
|
|
|
// ******************************************************************
|
2003-04-02 02:23:30 +00:00
|
|
|
HRESULT WINAPI xd3d8::EmuIDirect3DDevice8_Clear
|
2003-02-19 20:53:33 +00:00
|
|
|
(
|
|
|
|
DWORD Count,
|
|
|
|
CONST D3DRECT *pRects,
|
|
|
|
DWORD Flags,
|
|
|
|
D3DCOLOR Color,
|
|
|
|
float Z,
|
|
|
|
DWORD Stencil
|
|
|
|
)
|
|
|
|
{
|
2003-03-27 06:23:58 +00:00
|
|
|
EmuSwapFS(); // Win2k/XP FS
|
2003-02-19 20:53:33 +00:00
|
|
|
|
|
|
|
// ******************************************************************
|
|
|
|
// * debug trace
|
|
|
|
// ******************************************************************
|
|
|
|
#ifdef _DEBUG_TRACE
|
|
|
|
{
|
2003-03-27 06:23:58 +00:00
|
|
|
printf("EmuD3D8 (0x%.08X): EmuIDirect3DDevice8_Clear\n"
|
2003-02-19 20:53:33 +00:00
|
|
|
"(\n"
|
|
|
|
" Count : 0x%.08X\n"
|
|
|
|
" pRects : 0x%.08X\n"
|
|
|
|
" Flags : 0x%.08X\n"
|
|
|
|
" Color : 0x%.08X\n"
|
|
|
|
" Z : 0x%.08X\n"
|
|
|
|
" Stencil : 0x%.08X\n"
|
|
|
|
");\n",
|
|
|
|
GetCurrentThreadId(), Count, pRects, Flags,
|
|
|
|
Color, Z, Stencil);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// ******************************************************************
|
|
|
|
// * make adjustments to parameters to make sense with windows d3d
|
|
|
|
// ******************************************************************
|
|
|
|
{
|
2003-02-21 20:33:21 +00:00
|
|
|
// TODO: D3DCLEAR_TARGET_A, *R, *G, *B don't exist on windows
|
2003-02-22 07:49:02 +00:00
|
|
|
// TODO: Use lookup table that is dependant on library version
|
2003-02-20 21:42:39 +00:00
|
|
|
// Tricky MS randomizing .h #defines :[
|
2003-02-22 07:49:02 +00:00
|
|
|
DWORD newFlags = 0;
|
2003-02-20 08:07:52 +00:00
|
|
|
|
2003-02-22 07:49:02 +00:00
|
|
|
if(Flags & 0x000000f0l)
|
|
|
|
newFlags |= D3DCLEAR_TARGET;
|
2003-02-20 08:07:52 +00:00
|
|
|
|
2003-02-22 07:49:02 +00:00
|
|
|
if(Flags & 0x00000001l)
|
|
|
|
newFlags |= D3DCLEAR_ZBUFFER;
|
2003-02-20 08:07:52 +00:00
|
|
|
|
2003-02-22 07:49:02 +00:00
|
|
|
if(Flags & 0x00000002l)
|
|
|
|
newFlags |= D3DCLEAR_STENCIL;
|
2003-02-20 08:07:52 +00:00
|
|
|
|
2003-02-22 07:49:02 +00:00
|
|
|
Flags = newFlags;
|
2003-02-19 20:53:33 +00:00
|
|
|
}
|
|
|
|
|
2003-02-20 08:07:52 +00:00
|
|
|
HRESULT ret = g_pD3D8Device->Clear(Count, pRects, Flags, Color, Z, Stencil);
|
2003-02-19 20:53:33 +00:00
|
|
|
|
2003-03-27 06:23:58 +00:00
|
|
|
EmuSwapFS(); // XBox FS
|
2003-02-19 20:53:33 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2003-02-21 00:07:28 +00:00
|
|
|
|
|
|
|
// ******************************************************************
|
2003-03-27 06:23:58 +00:00
|
|
|
// * func: EmuIDirect3DDevice8_Swap
|
2003-02-21 00:07:28 +00:00
|
|
|
// ******************************************************************
|
2003-04-02 02:23:30 +00:00
|
|
|
HRESULT WINAPI xd3d8::EmuIDirect3DDevice8_Swap
|
2003-02-21 00:07:28 +00:00
|
|
|
(
|
|
|
|
DWORD Flags
|
|
|
|
)
|
|
|
|
{
|
2003-03-27 06:23:58 +00:00
|
|
|
EmuSwapFS(); // Win2k/XP FS
|
2003-02-21 00:07:28 +00:00
|
|
|
|
|
|
|
// ******************************************************************
|
|
|
|
// * debug trace
|
|
|
|
// ******************************************************************
|
|
|
|
#ifdef _DEBUG_TRACE
|
|
|
|
{
|
2003-03-27 06:23:58 +00:00
|
|
|
printf("EmuD3D8 (0x%.08X): EmuIDirect3DDevice8_Swap\n"
|
2003-02-21 00:07:28 +00:00
|
|
|
"(\n"
|
|
|
|
" Flags : 0x%.08X\n"
|
|
|
|
");\n",
|
|
|
|
GetCurrentThreadId(), Flags);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// TODO: Ensure this flag is always the same across library versions
|
|
|
|
if(Flags != 0)
|
2003-03-27 06:23:58 +00:00
|
|
|
EmuPanic();
|
2003-02-21 00:07:28 +00:00
|
|
|
|
|
|
|
// Swap(0) is equivalent to present(0,0,0,0)
|
|
|
|
HRESULT ret = g_pD3D8Device->Present(0, 0, 0, 0);
|
|
|
|
|
2003-03-27 06:23:58 +00:00
|
|
|
EmuSwapFS(); // XBox FS
|
2003-02-21 00:07:28 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|