2023-09-10 08:56:16 -04:00
|
|
|
#include "mxdirect3d.h"
|
2023-10-24 19:38:27 -04:00
|
|
|
|
2023-09-10 08:56:16 -04:00
|
|
|
#include <stdio.h> // for vsprintf
|
|
|
|
|
|
|
|
DECOMP_SIZE_ASSERT(MxDeviceModeFinder, 0xe4);
|
2024-01-01 19:17:38 -05:00
|
|
|
DECOMP_SIZE_ASSERT(MxDirect3D, 0x894);
|
2024-01-03 12:50:25 -05:00
|
|
|
DECOMP_SIZE_ASSERT(MxDevice, 0x1a4);
|
|
|
|
DECOMP_SIZE_ASSERT(MxDisplayMode, 0x0c);
|
2024-01-03 22:03:02 -05:00
|
|
|
DECOMP_SIZE_ASSERT(MxDriver, 0x190);
|
2024-01-01 19:17:38 -05:00
|
|
|
DECOMP_SIZE_ASSERT(MxDeviceEnumerate, 0x14);
|
2023-09-10 08:56:16 -04:00
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1009b0a0
|
2023-09-10 08:56:16 -04:00
|
|
|
MxDirect3D::MxDirect3D()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
this->m_pDirect3d = NULL;
|
|
|
|
this->m_pDirect3dDevice = NULL;
|
2023-12-13 05:48:14 -05:00
|
|
|
this->m_unk0x88c = NULL;
|
2023-10-24 19:38:27 -04:00
|
|
|
this->m_pDeviceModeFinder = NULL;
|
2023-09-10 08:56:16 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1009b140
|
2023-09-10 08:56:16 -04:00
|
|
|
MxDirect3D::~MxDirect3D()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
Destroy();
|
2023-09-10 08:56:16 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1009b1a0
|
2023-09-10 08:56:16 -04:00
|
|
|
BOOL MxDirect3D::Create(
|
2023-10-24 19:38:27 -04:00
|
|
|
HWND hWnd,
|
|
|
|
BOOL fullscreen_1,
|
|
|
|
BOOL surface_fullscreen,
|
|
|
|
BOOL onlySystemMemory,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int bpp,
|
|
|
|
const PALETTEENTRY* pPaletteEntries,
|
|
|
|
int paletteEntryCount
|
|
|
|
)
|
2023-09-10 08:56:16 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
BOOL success = FALSE;
|
|
|
|
|
|
|
|
BOOL ret = MxDirectDraw::Create(
|
|
|
|
hWnd,
|
|
|
|
fullscreen_1,
|
|
|
|
surface_fullscreen,
|
|
|
|
onlySystemMemory,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
bpp,
|
|
|
|
pPaletteEntries,
|
|
|
|
paletteEntryCount
|
|
|
|
);
|
|
|
|
|
|
|
|
if (ret && CreateIDirect3D() && D3DSetMode())
|
|
|
|
success = TRUE;
|
|
|
|
|
|
|
|
if (!success)
|
2023-12-13 05:48:14 -05:00
|
|
|
FUN_1009d920();
|
2023-10-24 19:38:27 -04:00
|
|
|
|
|
|
|
return success;
|
2023-09-10 08:56:16 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1009b210
|
2023-09-10 08:56:16 -04:00
|
|
|
void MxDirect3D::Destroy()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
if (this->m_pDirect3dDevice) {
|
|
|
|
this->m_pDirect3dDevice->Release();
|
|
|
|
this->m_pDirect3dDevice = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this->m_pDirect3d) {
|
|
|
|
this->m_pDirect3d->Release();
|
|
|
|
this->m_pDirect3d = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this->m_pDeviceModeFinder) {
|
|
|
|
delete m_pDeviceModeFinder;
|
|
|
|
this->m_pDeviceModeFinder = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This should get deleted by MxDirectDraw::Destroy
|
|
|
|
if (m_pCurrentDeviceModesList) {
|
|
|
|
// delete m_pCurrentDeviceModesList; // missing?
|
|
|
|
m_pCurrentDeviceModesList = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
MxDirectDraw::Destroy();
|
2023-09-10 08:56:16 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1009b290
|
2024-01-01 19:17:38 -05:00
|
|
|
void MxDirect3D::DestroyButNotDirectDraw()
|
2023-09-10 08:56:16 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
if (this->m_pDirect3dDevice) {
|
|
|
|
this->m_pDirect3dDevice->Release();
|
|
|
|
this->m_pDirect3dDevice = NULL;
|
|
|
|
}
|
|
|
|
if (this->m_pDirect3d) {
|
|
|
|
this->m_pDirect3d->Release();
|
|
|
|
this->m_pDirect3d = NULL;
|
|
|
|
}
|
|
|
|
MxDirectDraw::DestroyButNotDirectDraw();
|
2023-09-10 08:56:16 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1009b2d0
|
2023-09-10 08:56:16 -04:00
|
|
|
BOOL MxDirect3D::CreateIDirect3D()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
MxResult ret = IDirect3D_QueryInterface(m_pDirectDraw, IID_IDirect3D2, (LPVOID*) &m_pDirect3d);
|
2023-09-10 08:56:16 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
if (ret) {
|
|
|
|
Error("Creation of IDirect3D failed", ret);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2023-09-10 08:56:16 -04:00
|
|
|
|
2023-10-24 19:38:27 -04:00
|
|
|
return TRUE;
|
2023-09-10 08:56:16 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// STUB: LEGO1 0x1009b310
|
2023-09-10 08:56:16 -04:00
|
|
|
BOOL MxDirect3D::D3DSetMode()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
// TODO
|
|
|
|
// if (m_pDeviceModeFinder)
|
|
|
|
Error("This device cannot support the current display mode", 0);
|
|
|
|
OutputDebugString("MxDirect3D::D3DSetMode() front lock failed\n");
|
|
|
|
OutputDebugString("MxDirect3D::D3DSetMode() back lock failed\n");
|
|
|
|
return TRUE;
|
2023-09-10 08:56:16 -04:00
|
|
|
}
|
|
|
|
|
2024-01-01 19:17:38 -05:00
|
|
|
// STUB: LEGO1 0x1009b5f0
|
2024-01-03 22:03:02 -05:00
|
|
|
BOOL MxDirect3D::FUN_1009b5f0(MxDeviceEnumerate& p_deviceEnumerator, MxDriver* p_driver, MxDevice* p_device)
|
2024-01-01 19:17:38 -05:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1009b8b0
|
2023-09-10 08:56:16 -04:00
|
|
|
MxDeviceModeFinder::MxDeviceModeFinder()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
memset(this, 0, sizeof(*this));
|
2023-09-10 08:56:16 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1009b8d0
|
2023-09-10 08:56:16 -04:00
|
|
|
MxDeviceModeFinder::~MxDeviceModeFinder()
|
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
if (m_deviceInfo) {
|
|
|
|
delete m_deviceInfo;
|
|
|
|
m_deviceInfo = NULL;
|
|
|
|
}
|
2023-09-10 08:56:16 -04:00
|
|
|
}
|
|
|
|
|
2024-01-03 11:35:55 -05:00
|
|
|
// FUNCTION: LEGO1 0x1009ba80
|
2024-01-03 22:03:02 -05:00
|
|
|
MxDriver::MxDriver(LPGUID p_guid, LPSTR p_driverDesc, LPSTR p_driverName)
|
2024-01-03 11:35:55 -05:00
|
|
|
{
|
|
|
|
m_guid = NULL;
|
|
|
|
m_driverDesc = NULL;
|
|
|
|
m_driverName = NULL;
|
|
|
|
memset(&m_ddCaps, 0, sizeof(m_ddCaps));
|
|
|
|
|
|
|
|
Init(p_guid, p_driverDesc, p_driverName);
|
|
|
|
}
|
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x1009bb80
|
2024-01-03 22:03:02 -05:00
|
|
|
MxDriver::~MxDriver()
|
2024-01-03 11:35:55 -05:00
|
|
|
{
|
|
|
|
if (m_guid)
|
|
|
|
delete m_guid;
|
|
|
|
if (m_driverDesc)
|
|
|
|
delete[] m_driverDesc;
|
|
|
|
if (m_driverName)
|
|
|
|
delete[] m_driverName;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x1009bc30
|
2024-01-03 22:03:02 -05:00
|
|
|
void MxDriver::Init(LPGUID p_guid, LPSTR p_driverDesc, LPSTR p_driverName)
|
2024-01-03 11:35:55 -05:00
|
|
|
{
|
|
|
|
if (m_driverDesc) {
|
|
|
|
delete[] m_driverDesc;
|
|
|
|
m_driverDesc = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_driverName) {
|
|
|
|
delete[] m_driverName;
|
|
|
|
m_driverName = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_guid) {
|
|
|
|
m_guid = new GUID;
|
|
|
|
memcpy(m_guid, p_guid, sizeof(*m_guid));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_driverDesc) {
|
|
|
|
m_driverDesc = new char[strlen(p_driverDesc) + 1];
|
|
|
|
strcpy(m_driverDesc, p_driverDesc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_driverName) {
|
|
|
|
m_driverName = new char[strlen(p_driverName) + 1];
|
|
|
|
strcpy(m_driverName, p_driverName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-03 12:50:25 -05:00
|
|
|
// FUNCTION: LEGO1 0x1009bd20
|
|
|
|
MxDevice::MxDevice(
|
|
|
|
LPGUID p_guid,
|
|
|
|
LPSTR p_deviceDesc,
|
|
|
|
LPSTR p_deviceName,
|
|
|
|
LPD3DDEVICEDESC p_HWDesc,
|
|
|
|
LPD3DDEVICEDESC p_HELDesc
|
|
|
|
)
|
|
|
|
{
|
|
|
|
memset(this, 0, sizeof(*this));
|
|
|
|
|
|
|
|
Init(p_guid, p_deviceDesc, p_deviceName, p_HWDesc, p_HELDesc);
|
|
|
|
}
|
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x1009bd60
|
|
|
|
MxDevice::~MxDevice()
|
|
|
|
{
|
|
|
|
if (m_guid)
|
|
|
|
delete m_guid;
|
|
|
|
if (m_deviceDesc)
|
|
|
|
delete[] m_deviceDesc;
|
|
|
|
if (m_deviceName)
|
|
|
|
delete[] m_deviceName;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x1009bda0
|
|
|
|
void MxDevice::Init(
|
|
|
|
LPGUID p_guid,
|
|
|
|
LPSTR p_deviceDesc,
|
|
|
|
LPSTR p_deviceName,
|
|
|
|
LPD3DDEVICEDESC p_HWDesc,
|
|
|
|
LPD3DDEVICEDESC p_HELDesc
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (m_deviceDesc) {
|
|
|
|
delete[] m_deviceDesc;
|
|
|
|
m_deviceDesc = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_deviceName) {
|
|
|
|
delete[] m_deviceName;
|
|
|
|
m_deviceName = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_guid) {
|
|
|
|
m_guid = new GUID;
|
|
|
|
memcpy(m_guid, p_guid, sizeof(*m_guid));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_deviceDesc) {
|
|
|
|
m_deviceDesc = new char[strlen(p_deviceDesc) + 1];
|
|
|
|
strcpy(m_deviceDesc, p_deviceDesc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_deviceName) {
|
|
|
|
m_deviceName = new char[strlen(p_deviceName) + 1];
|
|
|
|
strcpy(m_deviceName, p_deviceName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_HWDesc)
|
|
|
|
memcpy(&m_HWDesc, p_HWDesc, sizeof(m_HWDesc));
|
|
|
|
|
|
|
|
if (p_HELDesc)
|
|
|
|
memcpy(&m_HELDesc, p_HELDesc, sizeof(m_HELDesc));
|
|
|
|
}
|
|
|
|
|
2024-01-01 19:17:38 -05:00
|
|
|
// FUNCTION: LEGO1 0x1009bec0
|
|
|
|
MxDeviceEnumerate::MxDeviceEnumerate()
|
|
|
|
{
|
2024-01-03 15:53:21 -05:00
|
|
|
m_initialized = FALSE;
|
2024-01-01 19:17:38 -05:00
|
|
|
}
|
|
|
|
|
2024-01-03 11:35:55 -05:00
|
|
|
// FUNCTION: LEGO1 0x1009c070
|
|
|
|
BOOL MxDeviceEnumerate::EnumDirectDrawCallback(LPGUID p_guid, LPSTR p_driverDesc, LPSTR p_driverName)
|
2023-09-10 08:56:16 -04:00
|
|
|
{
|
2024-01-03 22:03:02 -05:00
|
|
|
MxDriver driver(p_guid, p_driverDesc, p_driverName);
|
|
|
|
m_list.push_back(driver);
|
2024-01-03 11:35:55 -05:00
|
|
|
|
|
|
|
// Must be zeroed because held resources are copied by pointer only
|
|
|
|
// and should not be freed at the end of this function
|
2024-01-03 22:03:02 -05:00
|
|
|
driver.m_guid = NULL;
|
|
|
|
driver.m_driverDesc = NULL;
|
|
|
|
driver.m_driverName = NULL;
|
|
|
|
memset(&driver.m_ddCaps, 0, sizeof(driver.m_ddCaps));
|
2024-01-03 11:35:55 -05:00
|
|
|
|
|
|
|
LPDIRECT3D2 lpDirect3d2 = NULL;
|
2024-01-03 12:12:17 -05:00
|
|
|
LPDIRECTDRAW lpDD = NULL;
|
2024-01-03 22:03:02 -05:00
|
|
|
MxDriver& newDevice = m_list.back();
|
2024-01-03 11:35:55 -05:00
|
|
|
HRESULT result = DirectDrawCreate(newDevice.m_guid, &lpDD, NULL);
|
|
|
|
|
|
|
|
if (result != DD_OK)
|
|
|
|
BuildErrorString("DirectDraw Create failed: %s\n", EnumerateErrorToString(result));
|
|
|
|
else {
|
|
|
|
lpDD->EnumDisplayModes(0, NULL, this, DisplayModesEnumerateCallback);
|
|
|
|
newDevice.m_ddCaps.dwSize = sizeof(newDevice.m_ddCaps);
|
|
|
|
result = lpDD->GetCaps(&newDevice.m_ddCaps, NULL);
|
|
|
|
|
|
|
|
if (result != DD_OK)
|
|
|
|
BuildErrorString("GetCaps failed: %s\n", EnumerateErrorToString(result));
|
|
|
|
else {
|
|
|
|
result = lpDD->QueryInterface(IID_IDirect3D2, (LPVOID*) &lpDirect3d2);
|
|
|
|
|
|
|
|
if (result != DD_OK)
|
|
|
|
BuildErrorString("D3D creation failed: %s\n", EnumerateErrorToString(result));
|
|
|
|
else {
|
|
|
|
result = lpDirect3d2->EnumDevices(DevicesEnumerateCallback, this);
|
|
|
|
|
|
|
|
if (result != DD_OK)
|
|
|
|
BuildErrorString("D3D enum devices failed: %s\n", EnumerateErrorToString(result));
|
|
|
|
else {
|
2024-01-03 12:50:25 -05:00
|
|
|
if (newDevice.m_devices.empty()) {
|
2024-01-03 11:35:55 -05:00
|
|
|
m_list.pop_back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-10-24 19:38:27 -04:00
|
|
|
}
|
2024-01-03 11:35:55 -05:00
|
|
|
|
|
|
|
if (lpDirect3d2)
|
|
|
|
lpDirect3d2->Release();
|
|
|
|
|
|
|
|
if (lpDD)
|
|
|
|
lpDD->Release();
|
|
|
|
|
|
|
|
return DDENUMRET_OK;
|
2023-09-10 08:56:16 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1009c4c0
|
2024-01-01 19:17:38 -05:00
|
|
|
void MxDeviceEnumerate::BuildErrorString(const char* p_format, ...)
|
2023-09-10 08:56:16 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
va_list args;
|
|
|
|
char buf[512];
|
|
|
|
|
|
|
|
va_start(args, p_format);
|
|
|
|
vsprintf(buf, p_format, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
OutputDebugString(buf);
|
2023-09-10 08:56:16 -04:00
|
|
|
}
|
|
|
|
|
2024-01-03 12:12:17 -05:00
|
|
|
// FUNCTION: LEGO1 0x1009c4f0
|
|
|
|
HRESULT CALLBACK MxDeviceEnumerate::DisplayModesEnumerateCallback(LPDDSURFACEDESC p_ddsd, LPVOID p_context)
|
2024-01-03 11:35:55 -05:00
|
|
|
{
|
2024-01-03 12:12:17 -05:00
|
|
|
MxDeviceEnumerate* deviceEnumerate = (MxDeviceEnumerate*) p_context;
|
|
|
|
return deviceEnumerate->EnumDisplayModesCallback(p_ddsd);
|
2024-01-03 11:35:55 -05:00
|
|
|
}
|
|
|
|
|
2024-01-03 12:50:25 -05:00
|
|
|
// FUNCTION: LEGO1 0x1009c510
|
2024-01-03 12:12:17 -05:00
|
|
|
HRESULT CALLBACK MxDeviceEnumerate::DevicesEnumerateCallback(
|
2024-01-03 12:50:25 -05:00
|
|
|
LPGUID p_guid,
|
|
|
|
LPSTR p_deviceDesc,
|
|
|
|
LPSTR p_deviceName,
|
|
|
|
LPD3DDEVICEDESC p_HWDesc,
|
|
|
|
LPD3DDEVICEDESC p_HELDesc,
|
2024-01-03 11:35:55 -05:00
|
|
|
LPVOID p_context
|
|
|
|
)
|
|
|
|
{
|
2024-01-03 12:50:25 -05:00
|
|
|
MxDeviceEnumerate* deviceEnumerate = (MxDeviceEnumerate*) p_context;
|
|
|
|
return deviceEnumerate->EnumDevicesCallback(p_guid, p_deviceDesc, p_deviceName, p_HWDesc, p_HELDesc);
|
2024-01-03 11:35:55 -05:00
|
|
|
}
|
|
|
|
|
2024-01-03 12:12:17 -05:00
|
|
|
// FUNCTION: LEGO1 0x1009c540
|
|
|
|
HRESULT MxDeviceEnumerate::EnumDisplayModesCallback(LPDDSURFACEDESC p_ddsd)
|
|
|
|
{
|
2024-01-03 12:50:25 -05:00
|
|
|
MxDisplayMode displayMode;
|
2024-01-03 12:12:17 -05:00
|
|
|
displayMode.m_width = p_ddsd->dwWidth;
|
|
|
|
displayMode.m_height = p_ddsd->dwHeight;
|
|
|
|
displayMode.m_bitsPerPixel = p_ddsd->ddpfPixelFormat.dwRGBBitCount;
|
|
|
|
|
|
|
|
m_list.back().m_displayModes.push_back(displayMode);
|
|
|
|
return DDENUMRET_OK;
|
|
|
|
}
|
|
|
|
|
2024-01-03 12:50:25 -05:00
|
|
|
// FUNCTION: LEGO1 0x1009c5d0
|
|
|
|
HRESULT MxDeviceEnumerate::EnumDevicesCallback(
|
|
|
|
LPGUID p_guid,
|
|
|
|
LPSTR p_deviceDesc,
|
|
|
|
LPSTR p_deviceName,
|
|
|
|
LPD3DDEVICEDESC p_HWDesc,
|
|
|
|
LPD3DDEVICEDESC p_HELDesc
|
|
|
|
)
|
|
|
|
{
|
|
|
|
MxDevice device(p_guid, p_deviceDesc, p_deviceName, p_HWDesc, p_HELDesc);
|
|
|
|
m_list.back().m_devices.push_back(device);
|
|
|
|
memset(&device, 0, sizeof(device));
|
|
|
|
return DDENUMRET_OK;
|
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// FUNCTION: LEGO1 0x1009c6c0
|
2023-12-13 05:48:14 -05:00
|
|
|
MxResult MxDeviceEnumerate::DoEnumerate()
|
2023-09-10 08:56:16 -04:00
|
|
|
{
|
2024-01-03 15:53:21 -05:00
|
|
|
if (m_initialized)
|
2023-10-24 19:38:27 -04:00
|
|
|
return FAILURE;
|
|
|
|
|
2024-01-03 11:35:55 -05:00
|
|
|
HRESULT ret = DirectDrawEnumerate(DirectDrawEnumerateCallback, this);
|
2023-10-24 19:38:27 -04:00
|
|
|
if (ret) {
|
2024-01-01 19:17:38 -05:00
|
|
|
BuildErrorString("DirectDrawEnumerate returned error %s\n", EnumerateErrorToString(ret));
|
2023-10-24 19:38:27 -04:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
2024-01-03 15:53:21 -05:00
|
|
|
m_initialized = TRUE;
|
2023-10-24 19:38:27 -04:00
|
|
|
return SUCCESS;
|
2023-09-10 08:56:16 -04:00
|
|
|
}
|
|
|
|
|
2024-01-02 14:57:30 -05:00
|
|
|
// FUNCTION: LEGO1 0x1009c710
|
2024-01-03 12:12:17 -05:00
|
|
|
BOOL CALLBACK
|
|
|
|
MxDeviceEnumerate::DirectDrawEnumerateCallback(LPGUID p_guid, LPSTR p_driverDesc, LPSTR p_driverName, LPVOID p_context)
|
2023-09-10 08:56:16 -04:00
|
|
|
{
|
2024-01-02 14:57:30 -05:00
|
|
|
MxDeviceEnumerate* deviceEnumerate = (MxDeviceEnumerate*) p_context;
|
2024-01-03 11:35:55 -05:00
|
|
|
return deviceEnumerate->EnumDirectDrawCallback(p_guid, p_driverDesc, p_driverName);
|
2023-09-10 08:56:16 -04:00
|
|
|
}
|
|
|
|
|
2023-12-06 07:10:45 -05:00
|
|
|
// STUB: LEGO1 0x1009c730
|
2023-10-24 19:38:27 -04:00
|
|
|
const char* MxDeviceEnumerate::EnumerateErrorToString(HRESULT p_error)
|
2023-09-10 08:56:16 -04:00
|
|
|
{
|
2023-10-24 19:38:27 -04:00
|
|
|
// TODO: This is a list of error messages, similar to the function in
|
|
|
|
// MxDirectDraw, except that this one now contains the Direct3D errors.
|
|
|
|
// Probably just copied from a sample file in the dx5 sdk.
|
|
|
|
return "";
|
2023-09-10 08:56:16 -04:00
|
|
|
}
|
2024-01-01 19:17:38 -05:00
|
|
|
|
2024-01-03 15:53:21 -05:00
|
|
|
// FUNCTION: LEGO1 0x1009ce60
|
2024-01-01 19:17:38 -05:00
|
|
|
MxS32 MxDeviceEnumerate::ParseDeviceName(const char* p_deviceId)
|
|
|
|
{
|
2024-01-03 15:53:21 -05:00
|
|
|
if (!m_initialized)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
MxS32 num = -1;
|
|
|
|
MxS32 hex[4];
|
|
|
|
|
|
|
|
if (sscanf(p_deviceId, "%d 0x%x 0x%x 0x%x 0x%x", &num, &hex[0], &hex[1], &hex[2], &hex[3]) != 5)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (num < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
GUID guid;
|
|
|
|
memcpy(&guid, hex, sizeof(guid));
|
|
|
|
|
|
|
|
MxS32 result = ProcessDeviceBytes(num, guid);
|
|
|
|
|
|
|
|
if (result < 0)
|
|
|
|
return ProcessDeviceBytes(-1, guid);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x1009cf20
|
2024-01-03 22:03:02 -05:00
|
|
|
MxS32 MxDeviceEnumerate::ProcessDeviceBytes(MxS32 p_deviceNum, GUID& p_guid)
|
2024-01-03 15:53:21 -05:00
|
|
|
{
|
|
|
|
if (!m_initialized)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
MxS32 i = 0;
|
|
|
|
MxS32 j = 0;
|
|
|
|
|
|
|
|
struct GUID4 {
|
|
|
|
MxS32 m_data1;
|
|
|
|
MxS32 m_data2;
|
|
|
|
MxS32 m_data3;
|
|
|
|
MxS32 m_data4;
|
|
|
|
};
|
|
|
|
|
|
|
|
static_assert(sizeof(GUID4) == sizeof(GUID), "Equal size");
|
|
|
|
|
|
|
|
GUID4 deviceGuid;
|
|
|
|
memcpy(&deviceGuid, &p_guid, sizeof(GUID4));
|
|
|
|
|
2024-01-03 22:03:02 -05:00
|
|
|
for (list<MxDriver>::iterator it = m_list.begin(); it != m_list.end(); it++) {
|
|
|
|
if (p_deviceNum >= 0 && p_deviceNum < i)
|
2024-01-03 15:53:21 -05:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
GUID4 compareGuid;
|
2024-01-03 22:03:02 -05:00
|
|
|
MxDriver& driver = *it;
|
|
|
|
for (list<MxDevice>::iterator it2 = driver.m_devices.begin(); it2 != driver.m_devices.end(); it2++) {
|
2024-01-03 15:53:21 -05:00
|
|
|
memcpy(&compareGuid, (*it2).m_guid, sizeof(GUID4));
|
|
|
|
|
|
|
|
if (compareGuid.m_data1 == deviceGuid.m_data1 && compareGuid.m_data2 == deviceGuid.m_data2 &&
|
2024-01-03 22:03:02 -05:00
|
|
|
compareGuid.m_data3 == deviceGuid.m_data3 && compareGuid.m_data4 == deviceGuid.m_data4 &&
|
|
|
|
i == p_deviceNum)
|
2024-01-03 15:53:21 -05:00
|
|
|
return j;
|
|
|
|
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2024-01-01 19:17:38 -05:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2024-01-03 22:03:02 -05:00
|
|
|
// FUNCTION: LEGO1 0x1009d030
|
|
|
|
MxResult MxDeviceEnumerate::GetDevice(MxS32 p_deviceNum, MxDriver*& p_driver, MxDevice*& p_device)
|
2024-01-01 19:17:38 -05:00
|
|
|
{
|
2024-01-03 22:03:02 -05:00
|
|
|
if (p_deviceNum >= 0 && m_initialized) {
|
|
|
|
MxS32 i = 0;
|
|
|
|
|
|
|
|
for (list<MxDriver>::iterator it = m_list.begin(); it != m_list.end(); it++) {
|
|
|
|
p_driver = &*it;
|
|
|
|
|
|
|
|
for (list<MxDevice>::iterator it2 = p_driver->m_devices.begin(); it2 != p_driver->m_devices.end(); it2++) {
|
|
|
|
if (i == p_deviceNum) {
|
|
|
|
p_device = &*it2;
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
2024-01-01 19:17:38 -05:00
|
|
|
return FAILURE;
|
|
|
|
}
|
|
|
|
|
2024-01-03 22:03:02 -05:00
|
|
|
// FUNCTION: LEGO1 0x1009d0d0
|
|
|
|
MxS32 MxDeviceEnumerate::FUN_1009d0d0()
|
2024-01-01 19:17:38 -05:00
|
|
|
{
|
2024-01-03 22:03:02 -05:00
|
|
|
if (!m_initialized)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (m_list.empty())
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
MxS32 i = 0;
|
|
|
|
MxS32 j = 0;
|
|
|
|
MxS32 k = -1;
|
|
|
|
MxU32 und = FUN_1009d1a0();
|
|
|
|
|
|
|
|
for (list<MxDriver>::iterator it = m_list.begin();; it++) {
|
|
|
|
if (it == m_list.end())
|
|
|
|
return k;
|
|
|
|
|
|
|
|
for (list<MxDevice>::iterator it2 = (*it).m_devices.begin(); it2 != (*it).m_devices.end(); it2++) {
|
|
|
|
if ((*it2).m_HWDesc.dcmColorModel)
|
|
|
|
return j;
|
|
|
|
|
|
|
|
if ((und && (*it2).m_HELDesc.dcmColorModel == D3DCOLOR_RGB && i == 0) ||
|
|
|
|
(*it2).m_HELDesc.dcmColorModel == D3DCOLOR_MONO && i == 0 && k < 0)
|
|
|
|
k = j;
|
|
|
|
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
2024-01-01 19:17:38 -05:00
|
|
|
}
|
|
|
|
|
2024-01-03 22:03:02 -05:00
|
|
|
// STUB: LEGO1 0x1009d1a0
|
|
|
|
undefined4 MxDeviceEnumerate::FUN_1009d1a0()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// STUB: LEGO1 0x1009d1e0
|
|
|
|
undefined4 MxDeviceEnumerate::FUN_1009d1e0()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x1009d210
|
2024-01-01 19:17:38 -05:00
|
|
|
MxResult MxDeviceEnumerate::FUN_1009d210()
|
|
|
|
{
|
2024-01-03 22:03:02 -05:00
|
|
|
if (!m_initialized)
|
|
|
|
return FAILURE;
|
|
|
|
|
|
|
|
for (list<MxDriver>::iterator it = m_list.begin(); it != m_list.end();) {
|
|
|
|
MxDriver& driver = *it;
|
|
|
|
|
|
|
|
if (!FUN_1009d370(driver))
|
|
|
|
m_list.erase(it++);
|
|
|
|
else {
|
|
|
|
for (list<MxDevice>::iterator it2 = driver.m_devices.begin(); it2 != driver.m_devices.end();) {
|
|
|
|
MxDevice& device = *it2;
|
|
|
|
|
|
|
|
if (!FUN_1009d3d0(device))
|
|
|
|
driver.m_devices.erase(it2++);
|
|
|
|
else
|
|
|
|
it2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (driver.m_devices.empty())
|
|
|
|
m_list.erase(it++);
|
|
|
|
else
|
|
|
|
it++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_list.empty() ? FAILURE : SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x1009d370
|
|
|
|
MxBool MxDeviceEnumerate::FUN_1009d370(MxDriver& p_driver)
|
|
|
|
{
|
|
|
|
for (list<MxDisplayMode>::iterator it = p_driver.m_displayModes.begin(); it != p_driver.m_displayModes.end();
|
|
|
|
it++) {
|
|
|
|
if ((*it).m_width == 640 && (*it).m_height == 480) {
|
|
|
|
if ((*it).m_bitsPerPixel == 8 || (*it).m_bitsPerPixel == 16)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FUNCTION: LEGO1 0x1009d3d0
|
|
|
|
MxBool MxDeviceEnumerate::FUN_1009d3d0(MxDevice& p_device)
|
|
|
|
{
|
|
|
|
if (m_list.size() <= 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (p_device.m_HWDesc.dcmColorModel)
|
|
|
|
return p_device.m_HWDesc.dwDeviceZBufferBitDepth & DDBD_16 && p_device.m_HWDesc.dpcTriCaps.dwTextureCaps & 1;
|
|
|
|
|
|
|
|
for (list<MxDevice>::iterator it = m_list.front().m_devices.begin(); it != m_list.front().m_devices.end(); it++) {
|
|
|
|
if ((&*it) == &p_device)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
2024-01-01 19:17:38 -05:00
|
|
|
}
|