This commit is contained in:
x1nixmzeng 2018-02-01 20:58:01 +00:00
commit f57a74334f
58 changed files with 6411 additions and 4810 deletions

View File

@ -171,6 +171,8 @@
<BaseAddress>0x10000</BaseAddress>
<FixedBaseAddress>true</FixedBaseAddress>
<LargeAddressAware>true</LargeAddressAware>
<StackReserveSize>65536</StackReserveSize>
<StackCommitSize>65536</StackCommitSize>
</Link>
<Bscmake>
<SuppressStartupBanner>true</SuppressStartupBanner>
@ -188,10 +190,11 @@
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\..\src\Common\Win32\Threads.h" />
<ClInclude Include="..\..\src\Common\CxbxDebugger.h" />
<ClInclude Include="..\..\src\Common\Win32\XBAudio.h" />
<ClInclude Include="..\..\src\Common\XADPCM.h" />
<ClInclude Include="..\..\src\CxbxKrnl\EEPROMDevice.h" />
<ClInclude Include="..\..\src\Common\XbePrinter.h" />
<ClInclude Include="..\..\src\CxbxKrnl\EmuD3D8Logging.h" />
<ClInclude Include="..\..\import\stb\stb_image.h" />
<ClInclude Include="..\..\src\Common\EmuEEPROM.h" />
@ -218,8 +221,6 @@
<ClInclude Include="..\..\src\CxbxKrnl\EmuFS.h" />
<ClInclude Include="..\..\src\CxbxKrnl\EmuKrnlLogging.h" />
<ClInclude Include="..\..\src\CxbxKrnl\EmuNtDll.h" />
<ClInclude Include="..\..\src\CxbxKrnl\EmuNV2A.h" />
<ClInclude Include="..\..\src\CxbxKrnl\EmuNVNet.h" />
<ClInclude Include="..\..\src\CxbxKrnl\EmuSha.h" />
<ClInclude Include="..\..\src\CxbxKrnl\EmuX86.h" />
<ClInclude Include="..\..\src\CxbxKrnl\EmuXactEng.h" />
@ -231,20 +232,12 @@
<ClInclude Include="..\..\src\CxbxKrnl\HLEDataBase.h" />
<ClInclude Include="..\..\src\CxbxKrnl\HLEDataBase\D3D8.OOVPA.h" />
<ClInclude Include="..\..\src\CxbxKrnl\HLEIntercept.h" />
<ClInclude Include="..\..\src\CxbxKrnl\LED.h" />
<ClInclude Include="..\..\src\CxbxKrnl\LibRc4.h" />
<ClInclude Include="..\..\src\CxbxKrnl\nv2a_int.h" />
<ClInclude Include="..\..\src\CxbxKrnl\OOVPA.h" />
<ClInclude Include="..\..\src\CxbxKrnl\PhysicalMemory.h" />
<ClInclude Include="..\..\src\CxbxKrnl\PCIBus.h" />
<ClInclude Include="..\..\src\CxbxKrnl\PCIDevice.h" />
<ClInclude Include="..\..\src\CxbxKrnl\SMCDevice.h" />
<ClInclude Include="..\..\src\CxbxKrnl\ReservedMemory.h" />
<ClInclude Include="..\..\src\CxbxKrnl\ResourceTracker.h" />
<ClInclude Include="..\..\src\CxbxKrnl\VMManager.h" />
<ClInclude Include="..\..\src\CxbxKrnl\SMBus.h" />
<ClInclude Include="..\..\src\CxbxKrnl\SMDevice.h" />
<ClInclude Include="..\..\src\CxbxKrnl\Xbox.h" />
<ClInclude Include="..\..\src\CxbxVersion.h" />
<ClInclude Include="..\..\src\Cxbx\DlgAbout.h" />
<ClInclude Include="..\..\src\Cxbx\DlgAudioConfig.h" />
@ -260,6 +253,19 @@
<ClInclude Include="..\..\src\Common\Win32\XBController.h" />
<ClInclude Include="..\..\src\Common\Xbe.h" />
<ClInclude Include="..\..\src\Common\Win32\XBVideo.h" />
<ClInclude Include="..\..\src\devices\EEPROMDevice.h" />
<ClInclude Include="..\..\src\devices\EmuNVNet.h" />
<ClInclude Include="..\..\src\devices\LED.h" />
<ClInclude Include="..\..\src\devices\PCIBus.h" />
<ClInclude Include="..\..\src\devices\PCIDevice.h" />
<ClInclude Include="..\..\src\devices\SMBus.h" />
<ClInclude Include="..\..\src\devices\SMCDevice.h" />
<ClInclude Include="..\..\src\devices\SMDevice.h" />
<ClInclude Include="..\..\src\devices\video\EmuNV2A.h" />
<ClInclude Include="..\..\src\devices\video\nv2a.h" />
<ClInclude Include="..\..\src\devices\video\nv2a_int.h" />
<ClInclude Include="..\..\src\devices\video\vga.h" />
<ClInclude Include="..\..\src\devices\Xbox.h" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\CONTRIBUTORS" />
@ -286,7 +292,6 @@
<None Include="..\..\src\CxbxKrnl\HLEDataBase\D3D8.1.0.5344.inl" />
<None Include="..\..\src\CxbxKrnl\HLEDataBase\D3D8.1.0.5455.inl" />
<None Include="..\..\src\CxbxKrnl\HLEDataBase\D3D8.1.0.5558.inl" />
<None Include="..\..\src\CxbxKrnl\HLEDataBase\D3D8.1.0.5659.inl" />
<None Include="..\..\src\CxbxKrnl\HLEDataBase\D3D8.1.0.5788.inl" />
<None Include="..\..\src\CxbxKrnl\HLEDataBase\D3D8.1.0.5849.inl" />
<None Include="..\..\src\CxbxKrnl\HLEDataBase\D3D8.OOVPA.inl" />
@ -359,9 +364,10 @@
</ResourceCompile>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\Common\Win32\Threads.cpp" />
<ClCompile Include="..\..\src\Common\CxbxDebugger.cpp" />
<ClCompile Include="..\..\src\Common\Win32\XBAudio.cpp" />
<ClCompile Include="..\..\src\CxbxKrnl\EEPROMDevice.cpp" />
<ClCompile Include="..\..\src\Common\XbePrinter.cpp" />
<ClCompile Include="..\..\src\CxbxKrnl\EmuD3D8Logging.cpp" />
<ClCompile Include="..\..\src\Common\EmuEEPROM.cpp" />
<ClCompile Include="..\..\src\Common\Logging.cpp" />
@ -481,8 +487,6 @@
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="..\..\src\CxbxKrnl\EmuNV2A.cpp" />
<ClCompile Include="..\..\src\CxbxKrnl\EmuNVNet.cpp" />
<ClCompile Include="..\..\src\CxbxKrnl\EmuSha.cpp" />
<ClCompile Include="..\..\src\CxbxKrnl\EmuX86.cpp" />
<ClCompile Include="..\..\src\CxbxKrnl\EmuXactEng.cpp" />
@ -525,18 +529,12 @@
</ClCompile>
<ClCompile Include="..\..\src\CxbxKrnl\LibRc4.cpp" />
<ClCompile Include="..\..\src\CxbxKrnl\PhysicalMemory.cpp" />
<ClCompile Include="..\..\src\CxbxKrnl\PCIBus.cpp" />
<ClCompile Include="..\..\src\CxbxKrnl\PCIDevice.cpp" />
<ClCompile Include="..\..\src\CxbxKrnl\SMCDevice.cpp" />
<ClCompile Include="..\..\src\CxbxKrnl\ResourceTracker.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="..\..\src\CxbxKrnl\SMBus.cpp" />
<ClCompile Include="..\..\src\CxbxKrnl\SMDevice.cpp" />
<ClCompile Include="..\..\src\CxbxKrnl\Xbox.cpp" />
<ClCompile Include="..\..\src\CxbxKrnl\VMManager.cpp" />
<ClCompile Include="..\..\src\Cxbx\DlgAbout.cpp" />
<ClCompile Include="..\..\src\Cxbx\DlgAudioConfig.cpp" />
@ -600,6 +598,16 @@
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="..\..\src\devices\EEPROMDevice.cpp" />
<ClCompile Include="..\..\src\devices\EmuNVNet.cpp" />
<ClCompile Include="..\..\src\devices\PCIBus.cpp" />
<ClCompile Include="..\..\src\devices\PCIDevice.cpp" />
<ClCompile Include="..\..\src\devices\SMBus.cpp" />
<ClCompile Include="..\..\src\devices\SMCDevice.cpp" />
<ClCompile Include="..\..\src\devices\SMDevice.cpp" />
<ClCompile Include="..\..\src\devices\video\EmuNV2A.cpp" />
<ClCompile Include="..\..\src\devices\video\nv2a.cpp" />
<ClCompile Include="..\..\src\devices\Xbox.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="subhook.vcxproj">

View File

@ -196,39 +196,48 @@
<ClCompile Include="..\..\src\CxbxKrnl\VMManager.cpp">
<Filter>Emulator</Filter>
</ClCompile>
<ClCompile Include="..\..\src\CxbxKrnl\EmuNV2A.cpp">
<ClCompile Include="..\..\src\CxbxKrnl\EmuX86.cpp">
<Filter>Hardware</Filter>
</ClCompile>
<ClCompile Include="..\..\src\CxbxKrnl\EmuNVNet.cpp">
<ClCompile Include="..\..\src\devices\EEPROMDevice.cpp">
<Filter>Hardware</Filter>
</ClCompile>
<ClCompile Include="..\..\src\CxbxKrnl\PCIBus.cpp">
<ClCompile Include="..\..\src\devices\PCIBus.cpp">
<Filter>Hardware</Filter>
</ClCompile>
<ClCompile Include="..\..\src\CxbxKrnl\PCIDevice.cpp">
<ClCompile Include="..\..\src\devices\PCIDevice.cpp">
<Filter>Hardware</Filter>
</ClCompile>
<ClCompile Include="..\..\src\CxbxKrnl\SMBus.cpp">
<ClCompile Include="..\..\src\devices\SMBus.cpp">
<Filter>Hardware</Filter>
</ClCompile>
<ClCompile Include="..\..\src\CxbxKrnl\SMDevice.cpp">
<ClCompile Include="..\..\src\devices\SMCDevice.cpp">
<Filter>Hardware</Filter>
</ClCompile>
<ClCompile Include="..\..\src\CxbxKrnl\EEPROMDevice.cpp">
<ClCompile Include="..\..\src\devices\SMDevice.cpp">
<Filter>Hardware</Filter>
</ClCompile>
<ClCompile Include="..\..\src\devices\video\nv2a.cpp">
<Filter>Hardware</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Common\CxbxDebugger.cpp">
<Filter>Shared</Filter>
</ClCompile>
<ClCompile Include="..\..\src\CxbxKrnl\SMCDevice.cpp">
<ClCompile Include="..\..\src\devices\Xbox.cpp">
<Filter>Hardware</Filter>
</ClCompile>
<ClCompile Include="..\..\src\CxbxKrnl\EmuX86.cpp">
<ClCompile Include="..\..\src\devices\EmuNVNet.cpp">
<Filter>Hardware</Filter>
</ClCompile>
<ClCompile Include="..\..\src\CxbxKrnl\Xbox.cpp">
<ClCompile Include="..\..\src\devices\video\EmuNV2A.cpp">
<Filter>Hardware</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Common\XbePrinter.cpp">
<Filter>Shared</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Common\Win32\Threads.cpp">
<Filter>Shared</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\Cxbx\DlgControllerConfig.h">
@ -354,9 +363,6 @@
<ClInclude Include="..\..\src\Common\Logging.h">
<Filter>Emulator</Filter>
</ClInclude>
<ClInclude Include="..\..\src\CxbxKrnl\nv2a_int.h">
<Filter>Emulator</Filter>
</ClInclude>
<ClInclude Include="..\..\src\CxbxKrnl\OOVPA.h">
<Filter>Emulator</Filter>
</ClInclude>
@ -405,48 +411,63 @@
<ClInclude Include="..\..\src\CxbxKrnl\HLEDataBase\D3D8.OOVPA.h">
<Filter>HLEDatabase\D3D8</Filter>
</ClInclude>
<ClInclude Include="..\..\src\CxbxKrnl\EmuNV2A.h">
<Filter>Hardware</Filter>
</ClInclude>
<ClInclude Include="..\..\src\CxbxKrnl\EmuNVNet.h">
<Filter>Hardware</Filter>
</ClInclude>
<ClInclude Include="..\..\src\CxbxKrnl\PCIBus.h">
<Filter>Hardware</Filter>
</ClInclude>
<ClInclude Include="..\..\src\CxbxKrnl\PCIDevice.h">
<Filter>Hardware</Filter>
</ClInclude>
<ClInclude Include="..\..\src\CxbxKrnl\SMBus.h">
<Filter>Hardware</Filter>
</ClInclude>
<ClInclude Include="..\..\src\CxbxKrnl\SMDevice.h">
<Filter>Hardware</Filter>
</ClInclude>
<ClInclude Include="..\..\src\CxbxKrnl\EEPROMDevice.h">
<Filter>Hardware</Filter>
</ClInclude>
<ClInclude Include="..\..\src\CxbxKrnl\SMCDevice.h">
<Filter>Hardware</Filter>
</ClInclude>
<ClInclude Include="..\..\src\CxbxKrnl\PhysicalMemory.h">
<Filter>Emulator</Filter>
</ClInclude>
<ClInclude Include="..\..\src\CxbxKrnl\VMManager.h">
<Filter>Emulator</Filter>
</ClInclude>
<ClInclude Include="..\..\src\CxbxKrnl\LED.h">
<Filter>Hardware</Filter>
</ClInclude>
<ClInclude Include="..\..\src\CxbxKrnl\EmuX86.h">
<Filter>Hardware</Filter>
</ClInclude>
<ClInclude Include="..\..\src\devices\EEPROMDevice.h">
<Filter>Hardware</Filter>
</ClInclude>
<ClInclude Include="..\..\src\devices\PCIBus.h">
<Filter>Hardware</Filter>
</ClInclude>
<ClInclude Include="..\..\src\devices\PCIDevice.h">
<Filter>Hardware</Filter>
</ClInclude>
<ClInclude Include="..\..\src\devices\SMBus.h">
<Filter>Hardware</Filter>
</ClInclude>
<ClInclude Include="..\..\src\devices\SMCDevice.h">
<Filter>Hardware</Filter>
</ClInclude>
<ClInclude Include="..\..\src\devices\SMDevice.h">
<Filter>Hardware</Filter>
</ClInclude>
<ClInclude Include="..\..\src\devices\video\nv2a.h">
<Filter>Hardware</Filter>
</ClInclude>
<ClInclude Include="..\..\src\devices\LED.h">
<Filter>Hardware</Filter>
</ClInclude>
<ClInclude Include="..\..\src\devices\Xbox.h">
<Filter>Hardware</Filter>
</ClInclude>
<ClInclude Include="..\..\src\devices\EmuNVNet.h">
<Filter>Hardware</Filter>
</ClInclude>
<ClInclude Include="..\..\src\devices\video\EmuNV2A.h">
<Filter>Hardware</Filter>
</ClInclude>
<ClInclude Include="..\..\src\devices\video\nv2a_int.h">
<Filter>Hardware</Filter>
</ClCompile>
<ClInclude Include="..\..\src\Common\CxbxDebugger.h">
<Filter>Shared</Filter>
</ClInclude>
<ClInclude Include="..\..\src\CxbxKrnl\Xbox.h">
<ClInclude Include="..\..\src\devices\video\vga.h">
<Filter>Hardware</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Common\XbePrinter.h">
<Filter>Shared</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Common\Win32\Threads.h">
<Filter>Shared</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\resource\Splash.jpg">
@ -536,9 +557,6 @@
<None Include="..\..\src\CxbxKrnl\HLEDataBase\D3D8.1.0.5558.inl">
<Filter>HLEDatabase\D3D8</Filter>
</None>
<None Include="..\..\src\CxbxKrnl\HLEDataBase\D3D8.1.0.5659.inl">
<Filter>HLEDatabase\D3D8</Filter>
</None>
<None Include="..\..\src\CxbxKrnl\HLEDataBase\D3D8.1.0.5788.inl">
<Filter>HLEDatabase\D3D8</Filter>
</None>

View File

@ -84,7 +84,7 @@ typedef VOID (*PHAL_SHUTDOWN_NOTIFICATION)(
IN struct _HAL_SHUTDOWN_REGISTRATION *ShutdownRegistration
);
typedef struct {
typedef struct _HAL_SHUTDOWN_REGISTRATION {
PHAL_SHUTDOWN_NOTIFICATION NotificationRoutine;
LONG Priority;
LIST_ENTRY ListEntry;

View File

@ -400,6 +400,46 @@ typedef struct _LIST_ENTRY
}
LIST_ENTRY, *PLIST_ENTRY;
// See the links below for the details about the kernel structure LIST_ENTRY and the related functions
// https://www.codeproject.com/Articles/800404/Understanding-LIST-ENTRY-Lists-and-Its-Importance
// https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/singly-and-doubly-linked-lists
#define LIST_ENTRY_INITIALIZE_HEAD(ListHead) xboxkrnl::LIST_ENTRY ListHead = { &ListHead, &ListHead }
#define LIST_ENTRY_ACCESS_RECORD(address, type, field) \
((type*)((UCHAR*)(address) - (ULONG)(&((type*)0)->field)))
#define LIST_ENTRY_INSERT_HEAD(ListHead, Entry) {\
xboxkrnl::PLIST_ENTRY Flink;\
Flink = ListHead->Flink;\
(Entry)->Flink = Flink;\
(Entry)->Blink = ListHead;\
Flink->Blink = Entry;\
ListHead->Flink = Entry;\
}
#define LIST_ENTRY_INSERT_TAIL(ListHead, Entry) {\
xboxkrnl::PLIST_ENTRY Blink;\
Blink = ListHead->Blink;\
(Entry)->Flink = ListHead;\
(Entry)->Blink = Blink;\
Blink->Flink = Entry;\
ListHead->Blink = Entry;\
}
#define LIST_ENTRY_REMOVE(Entry) {\
xboxkrnl::PLIST_ENTRY ExFlink;\
xboxkrnl::PLIST_ENTRY ExBlink;\
ExFlink = (Entry)->Flink;\
ExBlink = (Entry)->Blink;\
ExFlink->Blink = ExBlink;\
ExBlink->Flink = ExFlink;\
}
#define LIST_ENTRY_REMOVE_AT_HEAD(ListHead) \
(ListHead)->Flink;\
LIST_ENTRY_REMOVE((ListHead)->Flink)
typedef struct _SINGLE_LIST_ENTRY {
struct _SINGLE_LIST_ENTRY *Next;
} SINGLE_LIST_ENTRY, *PSINGLE_LIST_ENTRY, SLIST_ENTRY, *PSLIST_ENTRY;
@ -1271,6 +1311,19 @@ typedef struct _LAUNCH_DATA_PAGE
}
LAUNCH_DATA_PAGE, *PLAUNCH_DATA_PAGE;
// ******************************************************************
// * DASH_LAUNCH_DATA
// ******************************************************************
typedef struct _DASH_LAUNCH_DATA
{
DWORD dwReason;
DWORD dwContext;
DWORD dwParameter1;
DWORD dwParameter2;
BYTE Reserved[3072 - 16];
}
DASH_LAUNCH_DATA, *PDASH_LAUNCH_DATA;
// ******************************************************************
// * DISPATCHER_HEADER
// ******************************************************************
@ -2183,6 +2236,44 @@ typedef struct _XBOX_EEPROM
}
XBOX_EEPROM;
// ******************************************************************
// * XBOX_UEM_INFO
// ******************************************************************
typedef struct _XBOX_UEM_INFO
{
UCHAR ErrorCode;
UCHAR Reserved;
USHORT History;
}
XBOX_UEM_INFO;
// ******************************************************************
// * Xbox UEM (fatal error) codes
// ******************************************************************
#define FATAL_ERROR_NONE 0x00
#define FATAL_ERROR_CORE_DIGITAL 0x01
#define FATAL_ERROR_BAD_EEPROM 0x02
#define FATAL_ERROR_UNUSED1 0x03
#define FATAL_ERROR_BAD_RAM 0x04
#define FATAL_ERROR_HDD_NOT_LOCKED 0x05
#define FATAL_ERROR_HDD_CANNOT_UNLOCK 0x06
#define FATAL_ERROR_HDD_TIMEOUT 0x07
#define FATAL_ERROR_HDD_NOT_FOUND 0x08
#define FATAL_ERROR_HDD_BAD_CONFIG 0x09
#define FATAL_ERROR_DVD_TIMEOUT 0x0A
#define FATAL_ERROR_DVD_NOT_FOUND 0x0B
#define FATAL_ERROR_DVD_BAD_CONFIG 0x0C
#define FATAL_ERROR_XBE_DASH_GENERIC 0x0D
#define FATAL_ERROR_XBE_DASH_ERROR 0x0E
#define FATAL_ERROR_UNUSED2 0x0F
#define FATAL_ERROR_XBE_DASH_SETTINGS 0x10
#define FATAL_ERROR_UNUSED3 0x11
#define FATAL_ERROR_UNUSED4 0x12
#define FATAL_ERROR_UNUSED5 0x13
#define FATAL_ERROR_XBE_DASH_X2_PASS 0x14
#define FATAL_ERROR_REBOOT_ROUTINE 0x15
#define FATAL_ERROR_RESERVED 0xFF
// ******************************************************************
// * TIME_FIELDS
// ******************************************************************

Binary file not shown.

View File

@ -136,7 +136,7 @@ void EmuShared::Cleanup()
EmuShared::EmuShared()
{
Load();
m_bMultiXbe = false;
m_bKeQuickReboot = false;
m_bDebugging = false;
m_LaunchDataPAddress = NULL;
}

View File

@ -0,0 +1,76 @@
// ******************************************************************
// *
// * .,-::::: .,:: .::::::::. .,:: .:
// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;;
// * [[[ '[[,,[[' [[[__[[\. '[[,,[['
// * $$$ Y$$$P $$""""Y$$ Y$$$P
// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
// *
// * Cxbx->Win32->Threads.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 <caustik@caustik.com>
// *
// * All rights reserved
// *
// ******************************************************************
#include <windows.h>
#include "Threads.h"
// Exception structure and method from:
// https://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
const DWORD MS_VC_EXCEPTION = 0x406D1388;
#pragma pack(push,8)
typedef struct tagTHREADNAME_INFO
{
DWORD dwType; // Must be 0x1000.
LPCSTR szName; // Pointer to name (in user addr space).
DWORD dwThreadID; // Thread ID (-1=caller thread).
DWORD dwFlags; // Reserved for future use, must be zero.
} THREADNAME_INFO;
#pragma pack(pop)
void SetThreadName(DWORD dwThreadID, const char* szThreadName)
{
if (!IsDebuggerPresent())
return;
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = szThreadName;
info.dwThreadID = dwThreadID;
info.dwFlags = 0;
#pragma warning(push)
#pragma warning(disable: 6320 6322)
__try {
RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR*)&info);
}
__except (EXCEPTION_EXECUTE_HANDLER) {
}
#pragma warning(pop)
}
void SetCurrentThreadName(const char* szThreadName)
{
SetThreadName(GetCurrentThreadId(), szThreadName);
}

View File

@ -0,0 +1,37 @@
// ******************************************************************
// *
// * .,-::::: .,:: .::::::::. .,:: .:
// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;;
// * [[[ '[[,,[[' [[[__[[\. '[[,,[['
// * $$$ Y$$$P $$""""Y$$ Y$$$P
// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
// *
// * Cxbx->Win32->Threads.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 <caustik@caustik.com>
// *
// * All rights reserved
// *
// ******************************************************************
#pragma once
void SetCurrentThreadName(const char* szThreadName);

View File

@ -33,20 +33,28 @@
// * All rights reserved
// *
// ******************************************************************
#define _XBOXKRNL_DEFEXTRN_
// prevent name collisions
namespace xboxkrnl
{
#include <xboxkrnl/xboxkrnl.h>
};
#include "Xbe.h"
#include "CxbxVersion.h"
#include "CxbxUtil.h"
#include "CxbxUtil.h" // For RoundUp
#include <experimental/filesystem> // filesystem related functions available on C++ 17
#include <locale> // For ctime
#include "devices\LED.h" // For LED::Sequence
#include "CxbxKrnl/CxbxKrnl.h" // For CxbxKrnlPrintUEM
#include "CxbxKrnl/EmuShared.h" // Include this to avoid including EmuXapi.h and EmuD3D8.h
namespace fs = std::experimental::filesystem;
#include <memory.h>
#include <clocale>
#include <cstdlib>
#include <cstring>
#include <ctime>
#define PAGE_SIZE 0x1000
// construct via Xbe file
Xbe::Xbe(const char *x_szFilename)
Xbe::Xbe(const char *x_szFilename, bool bFromGUI)
{
char szBuffer[MAX_PATH];
@ -59,8 +67,38 @@ Xbe::Xbe(const char *x_szFilename)
// verify Xbe file was opened successfully
if(XbeFile == 0)
{
SetFatalError("Could not open Xbe file.");
return;
using namespace fs; // limit its scope inside here
std::string XbeName = path(x_szFilename).filename().string(); // recover the xbe name
// NOTE: the check for the existence of the child window is necessary because the user could have previously loaded the dashboard,
// removed/changed the path and attempt to load it again from the recent list, which will crash CxbxInitWindow below
// Note that GetHwnd(), CxbxKrnl_hEmuParent and HalReturnToFirmware are all not suitable here for various reasons
if (XbeName.compare(std::string("xboxdash.xbe")) == 0 && !bFromGUI)
{
// The dashboard could not be found on partition2. This is a fatal error on the Xbox so we display the UEM. The
// error code is different if we have a launch data page
XTL::CxbxInitWindow(false);
ULONG FatalErrorCode = FATAL_ERROR_XBE_DASH_GENERIC;
if (xboxkrnl::LaunchDataPage && xboxkrnl::LaunchDataPage->Header.dwLaunchDataType == LDT_FROM_DASHBOARD)
{
xboxkrnl::PDASH_LAUNCH_DATA pLaunchDashboard = (xboxkrnl::PDASH_LAUNCH_DATA)&(xboxkrnl::LaunchDataPage->LaunchData[0]);
FatalErrorCode += pLaunchDashboard->dwReason;
}
SetLEDSequence(0xE1); // green, red, red, red
CxbxKrnlPrintUEM(FatalErrorCode); // won't return
// TODO: FATAL_ERROR_XBE_DASH_X2_PASS (requires DVD drive authentication emulation...)
}
else
{
// Report which xbe could not be found
SetFatalError(std::string("Could not open the Xbe file ") + XbeName);
return;
}
}
printf("OK\n");
@ -548,281 +586,6 @@ static char *BetterTime(uint32 x_timeDate)
return x_ctime;
}
// dump Xbe information to text file
void Xbe::DumpInformation(FILE *x_file)
{
if(HasError())
return;
fprintf(x_file, "XBE information generated by Cxbx-Reloaded (Version " _CXBX_VERSION ")\n");
fprintf(x_file, "\n");
fprintf(x_file, "Title identified as \"%s\"\n", m_szAsciiTitle);
fprintf(x_file, "\n");
fprintf(x_file, "Dumping XBE file header...\n");
fprintf(x_file, "\n");
fprintf(x_file, "Magic Number : XBEH\n");
// print digital signature
{
fprintf(x_file, "Digitial Signature : <Hex Dump>");
for(int y=0;y<16;y++)
{
fprintf(x_file, "\n ");
for(int x=0;x<16;x++)
fprintf(x_file, "%.02X", m_Header.pbDigitalSignature[y*16+x]);
}
fprintf(x_file, "\n </Hex Dump>\n");
}
fprintf(x_file, "Base Address : 0x%.08X\n", m_Header.dwBaseAddr);
fprintf(x_file, "Size of Headers : 0x%.08X\n", m_Header.dwSizeofHeaders);
fprintf(x_file, "Size of Image : 0x%.08X\n", m_Header.dwSizeofImage);
fprintf(x_file, "Size of Image Header : 0x%.08X\n", m_Header.dwSizeofImageHeader);
fprintf(x_file, "TimeDate Stamp : 0x%.08X (%s)\n", m_Header.dwTimeDate, BetterTime(m_Header.dwTimeDate));
fprintf(x_file, "Certificate Address : 0x%.08X\n", m_Header.dwCertificateAddr);
fprintf(x_file, "Number of Sections : 0x%.08X\n", m_Header.dwSections);
fprintf(x_file, "Section Headers Address : 0x%.08X\n", m_Header.dwSectionHeadersAddr);
// print init flags
{
fprintf(x_file, "Init Flags : 0x%.08X ", m_Header.dwInitFlags_value);
if(m_Header.dwInitFlags.bMountUtilityDrive)
fprintf(x_file, "[Mount Utility Drive] ");
if(m_Header.dwInitFlags.bFormatUtilityDrive)
fprintf(x_file, "[Format Utility Drive] ");
if(m_Header.dwInitFlags.bLimit64MB)
fprintf(x_file, "[Limit Devkit Run Time Memory to 64MB] ");
if(!m_Header.dwInitFlags.bDontSetupHarddisk)
fprintf(x_file, "[Setup Harddisk] ");
fprintf(x_file, "\n");
}
char AsciiFilename[40];
setlocale( LC_ALL, "English" );
const wchar_t *wszFilename = (const wchar_t *)GetAddr(m_Header.dwDebugUnicodeFilenameAddr);
if(wszFilename != NULL)
wcstombs(AsciiFilename, wszFilename, 40);
else
AsciiFilename[0] = '\0';
fprintf(x_file, "Entry Point : 0x%.08X (Retail: 0x%.08X, Debug: 0x%.08X)\n", m_Header.dwEntryAddr, m_Header.dwEntryAddr ^ XOR_EP_RETAIL, m_Header.dwEntryAddr ^ XOR_EP_DEBUG);
fprintf(x_file, "TLS Address : 0x%.08X\n", m_Header.dwTLSAddr);
fprintf(x_file, "(PE) Stack Commit : 0x%.08X\n", m_Header.dwPeStackCommit);
fprintf(x_file, "(PE) Heap Reserve : 0x%.08X\n", m_Header.dwPeHeapReserve);
fprintf(x_file, "(PE) Heap Commit : 0x%.08X\n", m_Header.dwPeHeapCommit);
fprintf(x_file, "(PE) Base Address : 0x%.08X\n", m_Header.dwPeBaseAddr);
fprintf(x_file, "(PE) Size of Image : 0x%.08X\n", m_Header.dwPeSizeofImage);
fprintf(x_file, "(PE) Checksum : 0x%.08X\n", m_Header.dwPeChecksum);
fprintf(x_file, "(PE) TimeDate Stamp : 0x%.08X (%s)\n", m_Header.dwPeTimeDate, BetterTime(m_Header.dwPeTimeDate));
fprintf(x_file, "Debug Pathname Address : 0x%.08X (\"%s\")\n", m_Header.dwDebugPathnameAddr, GetAddr(m_Header.dwDebugPathnameAddr));
fprintf(x_file, "Debug Filename Address : 0x%.08X (\"%s\")\n", m_Header.dwDebugFilenameAddr, GetAddr(m_Header.dwDebugFilenameAddr));
fprintf(x_file, "Debug Unicode filename Address : 0x%.08X (L\"%s\")\n", m_Header.dwDebugUnicodeFilenameAddr, AsciiFilename);
fprintf(x_file, "Kernel Image Thunk Address : 0x%.08X (Retail: 0x%.08X, Debug: 0x%.08X)\n", m_Header.dwKernelImageThunkAddr, m_Header.dwKernelImageThunkAddr ^ XOR_KT_RETAIL, m_Header.dwKernelImageThunkAddr ^ XOR_KT_DEBUG);
fprintf(x_file, "NonKernel Import Dir Address : 0x%.08X\n", m_Header.dwNonKernelImportDirAddr);
fprintf(x_file, "Library Versions : 0x%.08X\n", m_Header.dwLibraryVersions);
fprintf(x_file, "Library Versions Address : 0x%.08X\n", m_Header.dwLibraryVersionsAddr);
fprintf(x_file, "Kernel Library Version Address : 0x%.08X\n", m_Header.dwKernelLibraryVersionAddr);
fprintf(x_file, "XAPI Library Version Address : 0x%.08X\n", m_Header.dwXAPILibraryVersionAddr);
fprintf(x_file, "Logo Bitmap Address : 0x%.08X\n", m_Header.dwLogoBitmapAddr);
fprintf(x_file, "Logo Bitmap Size : 0x%.08X\n", m_Header.dwSizeofLogoBitmap);
fprintf(x_file, "\n");
fprintf(x_file, "Dumping XBE Certificate...\n");
fprintf(x_file, "\n");
fprintf(x_file, "Size of Certificate : 0x%.08X\n", m_Certificate.dwSize);
fprintf(x_file, "TimeDate Stamp : 0x%.08X (%s)\n", m_Certificate.dwTimeDate, BetterTime(m_Certificate.dwTimeDate));
fprintf(x_file, "Title ID : 0x%.08X\n", m_Certificate.dwTitleId);
fprintf(x_file, "Title : L\"%s\"\n", m_szAsciiTitle);
// print alternate title IDs
{
fprintf(x_file, "Alternate Titles IDs : ");
for(int v=0;v<0x10;v++)
{
if(v != 0)
fprintf(x_file, " ");
fprintf(x_file, "0x%.08X", m_Certificate.dwAlternateTitleId[v]);
if(v != 0x0F)
fprintf(x_file, "\n");
}
fprintf(x_file, "\n");
}
fprintf(x_file, "Allowed Media : 0x%.08X (%s)\n", m_Certificate.dwAllowedMedia, AllowedMediaToString().c_str());
fprintf(x_file, "Game Region : 0x%.08X (%s)\n", m_Certificate.dwGameRegion, GameRegionToString());
fprintf(x_file, "Game Ratings : 0x%.08X\n", m_Certificate.dwGameRatings);
fprintf(x_file, "Disk Number : 0x%.08X\n", m_Certificate.dwDiskNumber);
fprintf(x_file, "Version : 0x%.08X\n", m_Certificate.dwVersion);
// print LAN key
{
fprintf(x_file, "LAN Key : ");
for(int x=0;x<16;x++)
fprintf(x_file, "%.02X", m_Certificate.bzLanKey[x]);
fprintf(x_file, "\n");
}
// print signature key
{
fprintf(x_file, "Signature Key : ");
for(int x=0;x<16;x++)
fprintf(x_file, "%.02X", m_Certificate.bzSignatureKey[x]);
fprintf(x_file, "\n");
}
// print alternate signature keys
{
fprintf(x_file, "Title Alternate Signature Keys : <Hex Dump>");
for(int y=0;y<16;y++)
{
fprintf(x_file, "\n ");
for(int x=0;x<16;x++)
fprintf(x_file, "%.02X", m_Certificate.bzTitleAlternateSignatureKey[y][x]);
}
fprintf(x_file, "\n </Hex Dump>\n");
}
fprintf(x_file, "\n");
fprintf(x_file, "Dumping XBE Section Headers...\n");
fprintf(x_file, "\n");
// print section headers
{
for(uint32 v=0;v<m_Header.dwSections;v++)
{
fprintf(x_file, "Section Name : 0x%.08X (\"%s\")\n", m_SectionHeader[v].dwSectionNameAddr, m_szSectionName[v]);
// print flags
{
fprintf(x_file, "Flags : 0x%.08X ", m_SectionHeader[v].dwFlags_value);
if(m_SectionHeader[v].dwFlags.bWritable)
fprintf(x_file, "(Writable) ");
if(m_SectionHeader[v].dwFlags.bPreload)
fprintf(x_file, "(Preload) ");
if(m_SectionHeader[v].dwFlags.bExecutable)
fprintf(x_file, "(Executable) ");
if(m_SectionHeader[v].dwFlags.bInsertedFile)
fprintf(x_file, "(Inserted File) ");
if(m_SectionHeader[v].dwFlags.bHeadPageRO)
fprintf(x_file, "(Head Page RO) ");
if(m_SectionHeader[v].dwFlags.bTailPageRO)
fprintf(x_file, "(Tail Page RO) ");
fprintf(x_file, "\n");
}
fprintf(x_file, "Virtual Address : 0x%.08X\n", m_SectionHeader[v].dwVirtualAddr);
fprintf(x_file, "Virtual Size : 0x%.08X\n", m_SectionHeader[v].dwVirtualSize);
fprintf(x_file, "Raw Address : 0x%.08X\n", m_SectionHeader[v].dwRawAddr);
fprintf(x_file, "Size of Raw : 0x%.08X\n", m_SectionHeader[v].dwSizeofRaw);
fprintf(x_file, "Section Name Address : 0x%.08X\n", m_SectionHeader[v].dwSectionNameAddr);
fprintf(x_file, "Section Reference Count : 0x%.08X\n", m_SectionHeader[v].dwSectionRefCount);
fprintf(x_file, "Head Shared Reference Count Addr : 0x%.08X\n", m_SectionHeader[v].dwHeadSharedRefCountAddr);
fprintf(x_file, "Tail Shared Reference Count Addr : 0x%.08X\n", m_SectionHeader[v].dwTailSharedRefCountAddr);
// print section digest
{
fprintf(x_file, "Section Digest : ");
for(int s=0;s<20;s++)
fprintf(x_file, "%.02X", m_SectionHeader[v].bzSectionDigest[s]);
fprintf(x_file, "\n");
}
fprintf(x_file, "\n");
}
}
fprintf(x_file, "Dumping XBE Library Versions...\n");
fprintf(x_file, "\n");
// print library versions
{
if(m_LibraryVersion == 0 || m_Header.dwLibraryVersions == 0)
{
fprintf(x_file, "(This XBE contains no Library Versions)\n");
fprintf(x_file, "\n");
}
else
{
for(uint32 v=0;v<m_Header.dwLibraryVersions;v++)
{
char tmp[9];
for(uint32 c=0;c<8;c++)
tmp[c] = m_LibraryVersion[v].szName[c];
tmp[8] = '\0';
fprintf(x_file, "Library Name : %s\n", tmp);
fprintf(x_file, "Version : %d.%d.%d\n", m_LibraryVersion[v].wMajorVersion, m_LibraryVersion[v].wMinorVersion, m_LibraryVersion[v].wBuildVersion);
// print flags
{
fprintf(x_file, "Flags : 0x%.04X ", m_LibraryVersion[v].wFlags_value);
fprintf(x_file, "QFEVersion : 0x%.04X, ", m_LibraryVersion[v].wFlags.QFEVersion);
if(m_LibraryVersion[v].wFlags.bDebugBuild)
fprintf(x_file, "Debug, ");
else
fprintf(x_file, "Retail, ");
switch(m_LibraryVersion[v].wFlags.Approved)
{
case 0:
fprintf(x_file, "Unapproved");
break;
case 1:
fprintf(x_file, "Possibly Approved");
break;
case 2:
fprintf(x_file, "Approved");
break;
}
fprintf(x_file, "\n");
}
fprintf(x_file, "\n");
}
}
}
fprintf(x_file, "Dumping XBE TLS...\n");
fprintf(x_file, "\n");
// print thread local storage
if(m_TLS != 0)
{
fprintf(x_file, "Data Start Address : 0x%.08X\n", m_TLS->dwDataStartAddr);
fprintf(x_file, "Data End Address : 0x%.08X\n", m_TLS->dwDataEndAddr);
fprintf(x_file, "TLS Index Address : 0x%.08X\n", m_TLS->dwTLSIndexAddr);
fprintf(x_file, "TLS Callback Address : 0x%.08X\n", m_TLS->dwTLSCallbackAddr);
fprintf(x_file, "Size of Zero Fill : 0x%.08X\n", m_TLS->dwSizeofZeroFill);
fprintf(x_file, "Characteristics : 0x%.08X\n", m_TLS->dwCharacteristics);
}
else
{
fprintf(x_file, "(This XBE contains no TLS)\n");
}
}
// import logo bitmap from raw monochrome data
void Xbe::ImportLogoBitmap(const uint08 x_Gray[100*17])
{
@ -1037,42 +800,7 @@ const char *Xbe::GameRegionToString()
return Region_text[index];
}
std::string Xbe::AllowedMediaToString()
const wchar_t *Xbe::GetUnicodeFilenameAddr()
{
const uint32 dwAllowedMedia = m_Certificate.dwAllowedMedia;
std::string text = "Media Types:";
if(dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_MEDIA_MASK) {
if(dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_HARD_DISK)
text.append(" HARD_DISK");
if(dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_DVD_X2)
text.append(" DVD_X2");
if(dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_DVD_CD)
text.append(" DVD_CD");
if(dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_CD)
text.append(" CD");
if(dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_DVD_5_RO)
text.append(" DVD_5_RO");
if(dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_DVD_9_RO)
text.append(" DVD_9_RO");
if(dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_DVD_5_RW)
text.append(" DVD_5_RW");
if(dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_DVD_9_RW)
text.append(" DVD_9_RW");
if(dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_DONGLE)
text.append(" DONGLE");
if(dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_MEDIA_BOARD)
text.append(" BOARD");
if((dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_MEDIA_MASK) >= (XBEIMAGE_MEDIA_TYPE_MEDIA_BOARD * 2))
text.append(" UNKNOWN");
}
if(dwAllowedMedia & ~XBEIMAGE_MEDIA_TYPE_MEDIA_MASK) {
text.append(" NONSECURE");
if(dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_NONSECURE_HARD_DISK)
text.append(" HARD_DISK");
if(dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_NONSECURE_MODE)
text.append(" MODE");
}
return text;
return (const wchar_t *)GetAddr(m_Header.dwDebugUnicodeFilenameAddr);
}

View File

@ -51,7 +51,7 @@ class Xbe : public Error
{
public:
// construct via Xbe file
Xbe(const char *x_szFilename);
Xbe(const char *x_szFilename, bool bFromGUI);
// deconstructor
~Xbe();
@ -62,8 +62,7 @@ class Xbe : public Error
// export to Xbe file
void Export(const char *x_szXbeFilename);
// dump Xbe information to text file
void DumpInformation(FILE *x_file);
std::string DumpInformation();
// import logo bitmap from raw monochrome data
void ImportLogoBitmap(const uint08 x_Gray[100*17]);
@ -158,6 +157,7 @@ class Xbe : public Error
uint32 dwOriginalCertificateSize; // 0x01D0 - Original Certificate Size?
uint32 dwOnlineService; // 0x01D4 - Online Service ID
uint32 dwSecurityFlags; // 0x01D8 - Extra Security Flags
uint08 bzCodeEncKey[16]; // 0x01DC - Code Encryption Key?
}
#include "AlignPosfix1.h"
m_Certificate;
@ -255,17 +255,17 @@ class Xbe : public Error
// retrieve thread local storage index address
uint32 *GetTLSIndex() { if(m_TLS == 0) return 0; else return (uint32*)GetAddr(m_TLS->dwTLSIndexAddr); }
// return a modifiable pointer inside this structure that corresponds to a virtual address
uint08 *GetAddr(uint32 x_dwVirtualAddress);
const wchar_t *GetUnicodeFilenameAddr();
private:
// constructor initialization
void ConstructorInit();
// return a modifiable pointer inside this structure that corresponds to a virtual address
uint08 *GetAddr(uint32 x_dwVirtualAddress);
// return a modifiable pointer to logo bitmap data
uint08 *GetLogoBitmap(uint32 x_dwSize);
std::string AllowedMediaToString();
// used to encode/decode logo bitmap data
union LogoRLE

540
src/Common/XbePrinter.cpp Normal file
View File

@ -0,0 +1,540 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
// ******************************************************************
// *
// * .,-::::: .,:: .::::::::. .,:: .:
// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;;
// * [[[ '[[,,[[' [[[__[[\. '[[,,[['
// * $$$ Y$$$P $$""""Y$$ Y$$$P
// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
// *
// * Cxbx->Common->Xbe.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 <caustik@caustik.com>
// *
// * All rights reserved
// *
// ******************************************************************
#include "XbePrinter.h"
#include "CxbxVersion.h" // For _CXBX_VERSION
#include <locale> // For ctime
#include <codecvt> // For std::codecvt_utf8<>
#include <sstream> // For std::stringstream
#include <iomanip> // For std::setfill, std::uppercase, std::hex
// better time
static char *BetterTime(uint32 x_timeDate)
{
time_t x_time = x_timeDate;
char *x_ctime = ctime(&x_time);
int v=0;
for(v=0;x_ctime[v] != '\n';v++);
x_ctime[v] = '\0';
return x_ctime;
}
std::string DumpInformation(Xbe* Xbe_object)
{
if(Xbe_object->HasError()) {
return "ERROR";
}
XbePrinter printer(Xbe_object);
return printer.GenXbeInfo();
}
#define SSTREAM_SET_HEX(stream_name) stream_name << std::setfill('0') << std::uppercase << std::hex;
XbePrinter::XbePrinter(Xbe* Xbe_object)
{
Xbe_to_print = Xbe_object;
Xbe_header = &(Xbe_object->m_Header);
Xbe_certificate = &(Xbe_object->m_Certificate);
}
std::string XbePrinter::GenXbeInfo()
{
std::string info;
info.append(GenDumpHeader());
info.append(GenXbeHeaderInfo());
info.append(GenXbeCertificateInfo());
info.append(GenSectionInfo());
info.append(GenLibraryVersions());
info.append(GenTLS());
return info;
}
std::string XbePrinter::GenHexRow(
uint08 *signature, const uint08 row, const uint08 row_size
)
{
const uint16 offset = row * row_size;
std::stringstream text;
SSTREAM_SET_HEX(text);
for(uint08 x = 0; x < row_size; x++) {
text << std::setw(2) << static_cast<unsigned>(signature[offset + x]);
}
return text.str();
}
// https://stackoverflow.com/questions/4786292/converting-unicode-strings-and-vice-versa
std::string XbePrinter::utf8_to_ascii(const wchar_t* utf8_string)
{
std::wstring_convert<std::codecvt_utf8<wchar_t>> utf8_to_ascii;
const std::wstring utf8_filename(utf8_string);
return utf8_to_ascii.to_bytes(utf8_filename);
}
std::string XbePrinter::AllowedMediaToString()
{
const uint32 dwAllowedMedia = Xbe_certificate->dwAllowedMedia;
std::string text = "Media Types:";
if(dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_MEDIA_MASK) {
if(dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_HARD_DISK)
text.append(" HARD_DISK");
if(dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_DVD_X2)
text.append(" DVD_X2");
if(dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_DVD_CD)
text.append(" DVD_CD");
if(dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_CD)
text.append(" CD");
if(dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_DVD_5_RO)
text.append(" DVD_5_RO");
if(dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_DVD_9_RO)
text.append(" DVD_9_RO");
if(dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_DVD_5_RW)
text.append(" DVD_5_RW");
if(dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_DVD_9_RW)
text.append(" DVD_9_RW");
if(dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_DONGLE)
text.append(" DONGLE");
if(dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_MEDIA_BOARD)
text.append(" BOARD");
if((dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_MEDIA_MASK) >= (XBEIMAGE_MEDIA_TYPE_MEDIA_BOARD * 2))
text.append(" UNKNOWN");
}
if(dwAllowedMedia & ~XBEIMAGE_MEDIA_TYPE_MEDIA_MASK) {
text.append(" NONSECURE");
if(dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_NONSECURE_HARD_DISK)
text.append(" HARD_DISK");
if(dwAllowedMedia & XBEIMAGE_MEDIA_TYPE_NONSECURE_MODE)
text.append(" MODE");
}
return text;
}
std::string XbePrinter::GameRatingToString()
{
std::string text;
// Info from: http://xboxdevwiki.net/EEPROM
switch(Xbe_certificate->dwGameRatings) {
case 0x0:
text.append("(RP) Rating Pending");
break;
case 0x1:
text.append("(AO) Adults Only");
break;
case 0x2:
text.append("(M) Mature");
break;
case 0x3:
text.append("(T) Teen");
break;
case 0x4:
text.append("(E) Everyone");
break;
case 0x5:
text.append("(K-A) Kids to Adults");
break;
case 0x6:
text.append("(EC) Early Childhood");
break;
default:
text.append("ERROR: no rating");
break;
}
return text;
}
std::string XbePrinter::GenDumpHeader()
{
std::string text;
text.append("XBE information generated by Cxbx-Reloaded (Version " _CXBX_VERSION ")\n\n");
text.append("Title identified as \"");
text.append(Xbe_to_print->m_szAsciiTitle);
text.append("\"\n\n");
text.append("Dumping XBE file header...\n\n");
text.append("Magic Number : XBEH\n");
return text;
}
std::string XbePrinter::GenXbeHeaderInfo()
{
std::string text;
text.append(GenDigitalSignature());
text.append(GenGeneralHeaderInfo1());
text.append(GenInitFlags());
text.append(GenGeneralHeaderInfo2());
return text;
}
std::string XbePrinter::GenDigitalSignature()
{
const uint08 row_size = 16;
std::string text;
text.append("Digital Signature : <Hex Dump>");
for(int row = 0; row < 16; row++) {
text.append("\n ");
text.append(GenHexRow(&(Xbe_header->pbDigitalSignature[0]), row, row_size));
}
text.append("\n </Hex Dump>\n");
return text;
}
std::string XbePrinter::GenGeneralHeaderInfo1()
{
std::stringstream text;
SSTREAM_SET_HEX(text);
text << "Base Address : 0x" << std::setw(8) << Xbe_header->dwBaseAddr << "\n";
text << "Size of Headers : 0x" << std::setw(8) << Xbe_header->dwSizeofHeaders << "\n";
text << "Size of Image : 0x" << std::setw(8) << Xbe_header->dwSizeofImage << "\n";
text << "Size of Image Header : 0x" << std::setw(8) << Xbe_header->dwSizeofImageHeader << "\n";
text << "TimeDate Stamp : 0x" << std::setw(8) << Xbe_header->dwTimeDate << " (" << BetterTime(Xbe_header->dwTimeDate) << ")\n";
text << "Certificate Address : 0x" << std::setw(8) << Xbe_header->dwCertificateAddr << "\n";
text << "Number of Sections : 0x" << std::setw(8) << Xbe_header->dwSections << "\n";
text << "Section Headers Address : 0x" << std::setw(8) << Xbe_header->dwSectionHeadersAddr << "\n";
return text.str();
}
std::string XbePrinter::GenInitFlags()
{
std::stringstream text;
SSTREAM_SET_HEX(text);
text << "Init Flags : 0x" << std::setw(8) << Xbe_header->dwInitFlags_value << " ";
if(Xbe_header->dwInitFlags.bMountUtilityDrive) {
text << "[Mount Utility Drive] ";
}
if(Xbe_header->dwInitFlags.bFormatUtilityDrive) {
text << "[Format Utility Drive] ";
}
if(Xbe_header->dwInitFlags.bLimit64MB) {
text << "[Limit Devkit Run Time Memory to 64MB] ";
}
if(!Xbe_header->dwInitFlags.bDontSetupHarddisk) {
text << "[Setup Harddisk] ";
}
text << "\n";
return text.str();
}
std::string XbePrinter::GenGeneralHeaderInfo2()
{
const uint32 retail_entry_point = Xbe_header->dwEntryAddr ^ XOR_EP_RETAIL;
const uint32 debug_entry_point = Xbe_header->dwEntryAddr ^ XOR_EP_DEBUG;
const uint32 retail_thunk_addr = Xbe_header->dwKernelImageThunkAddr ^ XOR_KT_RETAIL;
const uint32 debug_thunk_addr = Xbe_header->dwKernelImageThunkAddr ^ XOR_KT_DEBUG;
const std::string AsciiFilename = utf8_to_ascii(Xbe_to_print->GetUnicodeFilenameAddr());
std::stringstream text;
SSTREAM_SET_HEX(text);
text << "Entry Point : 0x" << std::setw(8) << Xbe_header->dwEntryAddr << " (Retail: 0x" << std::setw(8) << retail_entry_point << ", Debug: 0x" << std::setw(8) << debug_entry_point << ")\n";
text << "TLS Address : 0x" << std::setw(8) << Xbe_header->dwTLSAddr << "\n";
text << "(PE) Stack Commit : 0x" << std::setw(8) << Xbe_header->dwPeStackCommit << "\n";
text << "(PE) Heap Reserve : 0x" << std::setw(8) << Xbe_header->dwPeHeapReserve << "\n";
text << "(PE) Heap Commit : 0x" << std::setw(8) << Xbe_header->dwPeHeapCommit << "\n";
text << "(PE) Base Address : 0x" << std::setw(8) << Xbe_header->dwPeBaseAddr << "\n";
text << "(PE) Size of Image : 0x" << std::setw(8) << Xbe_header->dwPeSizeofImage << "\n";
text << "(PE) Checksum : 0x" << std::setw(8) << Xbe_header->dwPeChecksum << "\n";
text << "(PE) TimeDate Stamp : 0x" << std::setw(8) << Xbe_header->dwPeTimeDate << " (" << BetterTime(Xbe_header->dwPeTimeDate) << ")\n";
text << "Debug Pathname Address : 0x" << std::setw(8) << Xbe_header->dwDebugPathnameAddr << " (\"" << Xbe_to_print->GetAddr(Xbe_header->dwDebugPathnameAddr) << "\")\n";
text << "Debug Filename Address : 0x" << std::setw(8) << Xbe_header->dwDebugFilenameAddr << " (\"" << Xbe_to_print->GetAddr(Xbe_header->dwDebugFilenameAddr) << "\")\n";
text << "Debug Unicode filename Address : 0x" << std::setw(8) << Xbe_header->dwDebugUnicodeFilenameAddr << " (L\"" << AsciiFilename << "\")\n";
text << "Kernel Image Thunk Address : 0x" << std::setw(8) << Xbe_header->dwKernelImageThunkAddr << " (Retail: 0x" << std::setw(8) << retail_thunk_addr << ", Debug: 0x" << std::setw(8) << debug_thunk_addr << ")\n";
text << "NonKernel Import Dir Address : 0x" << std::setw(8) << Xbe_header->dwNonKernelImportDirAddr << "\n";
text << "Library Versions : 0x" << std::setw(8) << Xbe_header->dwLibraryVersions << "\n";
text << "Library Versions Address : 0x" << std::setw(8) << Xbe_header->dwLibraryVersionsAddr << "\n";
text << "Kernel Library Version Address : 0x" << std::setw(8) << Xbe_header->dwKernelLibraryVersionAddr << "\n";
text << "XAPI Library Version Address : 0x" << std::setw(8) << Xbe_header->dwXAPILibraryVersionAddr << "\n";
text << "Logo Bitmap Address : 0x" << std::setw(8) << Xbe_header->dwLogoBitmapAddr << "\n";
text << "Logo Bitmap Size : 0x" << std::setw(8) << Xbe_header->dwSizeofLogoBitmap << "\n\n";
return text.str();
}
std::string XbePrinter::GenXbeCertificateInfo()
{
std::string text;
text.append(GenCertificateHeader());
text.append(GenAlternateTitleIDs());
text.append(GenMediaInfo());
text.append(GenLANKey());
text.append(GenSignatureKey());
text.append(GenAlternateSignatureKeys());
text.append(GenExtraInfo());
return text;
}
std::string XbePrinter::GenCertificateHeader()
{
std::stringstream text;
SSTREAM_SET_HEX(text);
text << "Dumping XBE Certificate...\n\n";
text << "Size of Certificate : 0x" << std::setw(8) << Xbe_certificate->dwSize << "\n";
text << "TimeDate Stamp : 0x" << std::setw(8) << Xbe_certificate->dwTimeDate << " (" << BetterTime(Xbe_certificate->dwTimeDate) << ")\n";
text << "Title ID : 0x" << std::setw(8) << Xbe_certificate->dwTitleId << "\n";
text << "Title : L\"" << Xbe_to_print->m_szAsciiTitle << "\"\n";
return text.str();
}
std::string XbePrinter::GenAlternateTitleIDs()
{
std::stringstream text;
SSTREAM_SET_HEX(text);
text << "Alternate Titles IDs : ";
for(int v = 0; v < 0x10; v++) {
if(v != 0) {
text << " ";
}
text << "0x" << std::setw(8) << Xbe_certificate->dwAlternateTitleId[v];
if(v != 0x0F) {
text << "\n";
}
}
text << "\n";
return text.str();
}
std::string XbePrinter::GenMediaInfo()
{
std::stringstream text;
SSTREAM_SET_HEX(text);
text << "Allowed Media : 0x" << std::setw(8) << Xbe_certificate->dwAllowedMedia << " (" << AllowedMediaToString() << ")\n";
text << "Game Region : 0x" << std::setw(8) << Xbe_certificate->dwGameRegion << " (" << Xbe_to_print->GameRegionToString() << ")\n";
text << "Game Ratings : 0x" << std::setw(8) << Xbe_certificate->dwGameRatings << " (" << GameRatingToString() << ")\n";
text << "Disk Number : 0x" << std::setw(8) << Xbe_certificate->dwDiskNumber << "\n";
text << "Version : 0x" << std::setw(8) << Xbe_certificate->dwVersion << "\n";
return text.str();
}
std::string XbePrinter::GenLANKey()
{
const uint08 row = 0;
const uint08 row_size = 16;
std::string text;
text.append("LAN Key : ");
text.append(GenHexRow(&(Xbe_certificate->bzLanKey[0]), row, row_size));
text.append("\n");
return text;
}
std::string XbePrinter::GenSignatureKey()
{
const uint08 row = 0;
const uint08 row_size = 16;
std::string text;
text.append("Signature Key : ");
text.append(GenHexRow(&(Xbe_certificate->bzSignatureKey[0]), row, row_size));
text.append("\n");
return text;
}
std::string XbePrinter::GenAlternateSignatureKeys()
{
const uint08 row = 0;
const uint08 row_size = 16;
std::string text;
text.append("Title Alternate Signature Keys : <Hex Dump>");
for(int row = 0; row < 16; row++)
{
text.append("\n ");
text.append(GenHexRow(&(Xbe_certificate->bzTitleAlternateSignatureKey[0][0]), row, row_size));
}
text.append("\n </Hex Dump>\n");
return text;
}
std::string XbePrinter::GenExtraInfo()
{
std::stringstream text;
if (Xbe_certificate->dwSize >= 0x1EC)
{
SSTREAM_SET_HEX(text);
text << "Original Certificate Size : 0x" << std::setw(8) << Xbe_certificate->dwOriginalCertificateSize << "\n";
text << "Online Service ID : 0x" << std::setw(8) << Xbe_certificate->dwOnlineService << "\n";
text << "Extra Security Flags : 0x" << std::setw(8) << Xbe_certificate->dwSecurityFlags << "\n";
text << "Code Encryption Key : ";
text << GenHexRow(&(Xbe_certificate->bzCodeEncKey[0]), 0, 16) << "\n";
}
return text.str();
}
std::string XbePrinter::GenSectionInfo()
{
std::string text;
text.append("\nDumping XBE Section Headers...\n\n");
text.append(GenSectionHeaders());
return text;
}
std::string XbePrinter::GenSectionHeaders()
{
std::stringstream text;
SSTREAM_SET_HEX(text);
for(uint32 v=0; v < Xbe_header->dwSections; v++) {
text << "Section Name : 0x" << std::setw(8) << Xbe_to_print->m_SectionHeader[v].dwSectionNameAddr << " (\"" << Xbe_to_print->m_szSectionName[v] << "\")\n";
text << GenSectionFlags(Xbe_to_print->m_SectionHeader[v]);
text << "Virtual Address : 0x" << std::setw(8) << Xbe_to_print->m_SectionHeader[v].dwVirtualAddr << "\n";
text << "Virtual Size : 0x" << std::setw(8) << Xbe_to_print->m_SectionHeader[v].dwVirtualSize << "\n";
text << "Raw Address : 0x" << std::setw(8) << Xbe_to_print->m_SectionHeader[v].dwRawAddr << "\n";
text << "Size of Raw : 0x" << std::setw(8) << Xbe_to_print->m_SectionHeader[v].dwSizeofRaw << "\n";
text << "Section Name Address : 0x" << std::setw(8) << Xbe_to_print->m_SectionHeader[v].dwSectionNameAddr << "\n";
text << "Section Reference Count : 0x" << std::setw(8) << Xbe_to_print->m_SectionHeader[v].dwSectionRefCount << "\n";
text << "Head Shared Reference Count Addr : 0x" << std::setw(8) << Xbe_to_print->m_SectionHeader[v].dwHeadSharedRefCountAddr << "\n";
text << "Tail Shared Reference Count Addr : 0x" << std::setw(8) << Xbe_to_print->m_SectionHeader[v].dwTailSharedRefCountAddr << "\n";
text << GenSectionDigest(Xbe_to_print->m_SectionHeader[v]) << "\n";
}
return text.str();
}
std::string XbePrinter::GenSectionFlags(Xbe::SectionHeader section_header)
{
std::stringstream text;
SSTREAM_SET_HEX(text);
text << "Flags : 0x" << std::setw(8) << section_header.dwFlags_value << " ";
if(section_header.dwFlags.bWritable) {
text << "(Writable) ";
}
if(section_header.dwFlags.bPreload) {
text << "(Preload) ";
}
if(section_header.dwFlags.bExecutable) {
text << "(Executable) ";
}
if(section_header.dwFlags.bInsertedFile) {
text << "(Inserted File) ";
}
if(section_header.dwFlags.bHeadPageRO) {
text << "(Head Page RO) ";
}
if(section_header.dwFlags.bTailPageRO) {
text << "(Tail Page RO) ";
}
text << "\n";
return text.str();
}
std::string XbePrinter::GenSectionDigest(Xbe::SectionHeader section_header)
{
std::string text;
text.append("Section Digest : ");
text.append(GenHexRow(&section_header.bzSectionDigest[0], 0, 20));
text.append("\n");
return text;
}
std::string XbePrinter::GenLibraryVersions()
{
std::stringstream text;
text << "Dumping XBE Library Versions...\n\n";
if(Xbe_to_print->m_LibraryVersion == 0 || Xbe_header->dwLibraryVersions == 0) {
text << "(This XBE contains no Library Versions)\n\n";
}
else {
for(uint32 v = 0; v < Xbe_header->dwLibraryVersions; v++) {
char libname[9];
for(uint32 c=0;c<8;c++) {
libname[c] = Xbe_to_print->m_LibraryVersion[v].szName[c];
}
libname[8] = '\0';
text << "Library Name : " << libname << "\n";
text << "Version : "
<< Xbe_to_print->m_LibraryVersion[v].wMajorVersion << "."
<< Xbe_to_print->m_LibraryVersion[v].wMinorVersion << "."
<< Xbe_to_print->m_LibraryVersion[v].wBuildVersion << "\n";
text << GenLibraryFlags(Xbe_to_print->m_LibraryVersion[v]);
text << "\n";
}
}
return text.str();
}
std::string XbePrinter::GenLibraryFlags(Xbe::LibraryVersion libver)
{
std::stringstream text;
SSTREAM_SET_HEX(text);
text << "Flags : 0x" << std::setw(4) << libver.wFlags_value << " ";
text << "QFEVersion : 0x" << std::setw(4) << libver.wFlags.QFEVersion << ", ";
if(libver.wFlags.bDebugBuild) {
text << "Debug, ";
}
else {
text << "Retail, ";
}
switch(libver.wFlags.Approved) {
case 0:
text << "Unapproved";
break;
case 1:
text << "Possibly Approved";
break;
case 2:
text << "Approved";
break;
}
text << "\n";
return text.str();
}
std::string XbePrinter::GenTLS()
{
std::stringstream text;
SSTREAM_SET_HEX(text);
Xbe::TLS *local_TLS = Xbe_to_print->m_TLS;
text << "Dumping XBE TLS...\n\n";
// print thread local storage
if(local_TLS != 0) {
text << "Data Start Address : 0x" << std::setw(8) << local_TLS->dwDataStartAddr << "\n";
text << "Data End Address : 0x" << std::setw(8) << local_TLS->dwDataEndAddr << "\n";
text << "TLS Index Address : 0x" << std::setw(8) << local_TLS->dwTLSIndexAddr << "\n";
text << "TLS Callback Address : 0x" << std::setw(8) << local_TLS->dwTLSCallbackAddr << "\n";
text << "Size of Zero Fill : 0x" << std::setw(8) << local_TLS->dwSizeofZeroFill << "\n";
text << "Characteristics : 0x" << std::setw(8) << local_TLS->dwCharacteristics << "\n";
}
else {
text << "(This XBE contains no TLS)\n";
}
return text.str();
}

88
src/Common/XbePrinter.h Normal file
View File

@ -0,0 +1,88 @@
// ******************************************************************
// *
// * .,-::::: .,:: .::::::::. .,:: .:
// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;;
// * [[[ '[[,,[[' [[[__[[\. '[[,,[['
// * $$$ Y$$$P $$""""Y$$ Y$$$P
// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
// *
// * Cxbx->Common->XbePrinter.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 <caustik@caustik.com>
// *
// * All rights reserved
// *
// ******************************************************************
#ifndef XBE_PRINTER_H
#define XBE_PRINTER_H
#include "Common/Error.h"
#include "Common/Xbe.h"
#include <cstdio>
extern std::string DumpInformation(Xbe* Xbe_object);
class XbePrinter
{
public:
XbePrinter(Xbe*);
std::string GenXbeInfo();
private:
Xbe *Xbe_to_print;
Xbe::Header *Xbe_header;
Xbe::Certificate *Xbe_certificate;
std::string GenHexRow(uint08*, const uint08, const uint08);
std::string utf8_to_ascii(const wchar_t*);
std::string AllowedMediaToString();
std::string GameRatingToString();
std::string GenDumpHeader();
std::string GenXbeHeaderInfo();
std::string GenDigitalSignature();
std::string GenGeneralHeaderInfo1();
std::string GenInitFlags();
std::string GenGeneralHeaderInfo2();
std::string GenXbeCertificateInfo();
std::string GenCertificateHeader();
std::string GenAlternateTitleIDs();
std::string GenMediaInfo();
std::string GenLANKey();
std::string GenSignatureKey();
std::string GenAlternateSignatureKeys();
std::string GenExtraInfo();
std::string GenSectionInfo();
std::string GenSectionHeaders();
std::string GenSectionFlags(Xbe::SectionHeader);
std::string GenSectionDigest(Xbe::SectionHeader);
std::string GenLibraryVersions();
std::string GenLibraryFlags(Xbe::LibraryVersion);
std::string GenTLS();
};
#endif // XBE_PRINTER_H

View File

@ -143,4 +143,11 @@ extern volatile bool g_bPrintfOn;
#define DbgPrintf null_func
#endif
#if WIN32
#include "Win32\Threads.h"
#define CxbxSetThreadName(Name) SetCurrentThreadName(Name)
#else
#define CxbxSetThreadName(Name)
#endif
#endif

View File

@ -15,6 +15,7 @@
#define IDD_ABOUT 119
#define IDR_CONTRIBUTORS 121
#define IDR_COPYING 122
#define IDS_UEM 123
#define IDC_SET_X 1000
#define IDC_SET_Y 1001
#define IDC_SET_A 1002

View File

@ -38,6 +38,7 @@
#include "DlgControllerConfig.h"
#include "DlgVideoConfig.h"
#include "DlgAudioConfig.h"
#include "Common/XbePrinter.h" // For DumpInformation
#include "CxbxKrnl/EmuShared.h"
#include "ResCxbx.h"
#include "CxbxVersion.h"
@ -47,6 +48,8 @@
#include <io.h>
#include <sstream> // for std::stringstream
#include <fstream>
#include <iostream>
#include "CxbxKrnl/xxhash32.h" // for XXHash32::hash
#define XBOX_LED_FLASH_PERIOD 176 // if you know a more accurate value, put it here
@ -175,13 +178,13 @@ WndMain::WndMain(HINSTANCE x_hInstance) :
dwType = REG_SZ; dwSize = MAX_PATH; ULONG lErrCodeCxbxDebugFilename;
lErrCodeCxbxDebugFilename = RegQueryValueEx(hKey, "CxbxDebugFilename", NULL, &dwType, (PBYTE)m_CxbxDebugFilename, &dwSize);
if (lErrCodeCxbxDebugFilename != ERROR_SUCCESS) {
m_CxbxDebugFilename = "";
m_CxbxDebugFilename[0] = '\0';
}
dwType = REG_SZ; dwSize = MAX_PATH; LONG lErrCodeKrnlDebugFilename;
lErrCodeKrnlDebugFilename = RegQueryValueEx(hKey, "KrnlDebugFilename", NULL, &dwType, (PBYTE)m_KrnlDebugFilename, &dwSize);
if (lErrCodeKrnlDebugFilename != ERROR_SUCCESS) {
m_KrnlDebugFilename = "";
m_KrnlDebugFilename[0] = '\0';
}
// Prevent using an incorrect path from the registry if the debug folders have been moved
@ -375,14 +378,14 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP
m_yBmp = GetSystemMetrics(SM_CYMENUCHECK);
m_LedDC = CreateCompatibleDC(hDC);
m_LedBmp = CreateCompatibleBitmap(hDC, m_xBmp, m_yBmp);
m_BrushBlack = CreateSolidBrush(RGB(0, 0, 0));
m_BrushRed = CreateSolidBrush(RGB(255, 0, 0));
m_BrushGreen = CreateSolidBrush(RGB(0, 255, 0));
m_BrushOrange = CreateSolidBrush(RGB(255, 165, 0));
m_PenBlack = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
m_PenRed = CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
m_PenGreen = CreatePen(PS_SOLID, 1, RGB(0, 255, 0));
m_PenOrange = CreatePen(PS_SOLID, 1, RGB(255, 165, 0));
m_Brushes[XBOX_LED_COLOUR_OFF] = CreateSolidBrush(RGB(0, 0, 0));
m_Brushes[XBOX_LED_COLOUR_GREEN] = CreateSolidBrush(RGB(0, 255, 0));
m_Brushes[XBOX_LED_COLOUR_RED] = CreateSolidBrush(RGB(255, 0, 0));
m_Brushes[XBOX_LED_COLOUR_ORANGE] = CreateSolidBrush(RGB(255, 165, 0));
m_Pens[XBOX_LED_COLOUR_OFF] = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
m_Pens[XBOX_LED_COLOUR_GREEN] = CreatePen(PS_SOLID, 1, RGB(0, 255, 0));
m_Pens[XBOX_LED_COLOUR_RED] = CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
m_Pens[XBOX_LED_COLOUR_ORANGE] = CreatePen(PS_SOLID, 1, RGB(255, 165, 0));
DrawLedBitmap(hwnd, true);
}
@ -470,11 +473,9 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP
if (m_hwndChild == NULL) {
float fps = 0;
float mspf = 0;
bool LedHasChanged = false;
int LedSequence[4] = { XBOX_LED_COLOUR_GREEN, XBOX_LED_COLOUR_GREEN, XBOX_LED_COLOUR_GREEN, XBOX_LED_COLOUR_GREEN };
g_EmuShared->SetCurrentMSpF(&mspf);
g_EmuShared->SetCurrentFPS(&fps);
g_EmuShared->SetLedStatus(&LedHasChanged);
g_EmuShared->SetLedSequence(LedSequence);
SetTimer(hwnd, TIMERID_FPS, 1000, (TIMERPROC)NULL);
SetTimer(hwnd, TIMERID_LED, XBOX_LED_FLASH_PERIOD, (TIMERPROC)NULL);
@ -1006,56 +1007,43 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP
// dump xbe information to file
{
FILE *TxtFile = fopen(ofn.lpstrFile, "wt");
// verify file was opened
if (TxtFile == 0)
MessageBox(m_hwnd, "Could not open text file.", "Cxbx-Reloaded", MB_ICONSTOP | MB_OK);
else
{
m_Xbe->DumpInformation(TxtFile);
fclose(TxtFile);
if (m_Xbe->HasError())
{
MessageBox(m_hwnd, m_Xbe->GetError().c_str(), "Cxbx-Reloaded", MB_ICONSTOP | MB_OK);
}
else
{
char buffer[255];
sprintf(buffer, "%s's .xbe info was successfully dumped.", m_Xbe->m_szAsciiTitle);
printf("WndMain: %s\n", buffer);
MessageBox(m_hwnd, buffer, "Cxbx-Reloaded", MB_ICONINFORMATION | MB_OK);
}
}
std::string Xbe_info = DumpInformation(m_Xbe);
if (m_Xbe->HasError()) {
MessageBox(m_hwnd, m_Xbe->GetError().c_str(), "Cxbx-Reloaded", MB_ICONSTOP | MB_OK);
}
else {
std::ofstream Xbe_dump_file(ofn.lpstrFile);
if(Xbe_dump_file.is_open()) {
Xbe_dump_file << Xbe_info;
Xbe_dump_file.close();
char buffer[255];
sprintf(buffer, "%s's .xbe info was successfully dumped.", m_Xbe->m_szAsciiTitle);
printf("WndMain: %s\n", buffer);
MessageBox(m_hwnd, buffer, "Cxbx-Reloaded", MB_ICONINFORMATION | MB_OK);
}
else {
MessageBox(m_hwnd, "Could not open Xbe text file.", "Cxbx-Reloaded", MB_ICONSTOP | MB_OK);
}
}
}
}
}
break;
case ID_EDIT_DUMPXBEINFOTO_DEBUGCONSOLE:
{
// dump xbe information to debug console
m_Xbe->DumpInformation(stdout);
if (m_Xbe->HasError())
{
MessageBox(m_hwnd, m_Xbe->GetError().c_str(), "Cxbx-Reloaded", MB_ICONSTOP | MB_OK);
}
else
{
char buffer[255];
sprintf(buffer, "%s's .xbe info was successfully dumped.", m_Xbe->m_szAsciiTitle);
printf("WndMain: %s\n", buffer);
}
}
break;
case ID_EDIT_DUMPXBEINFOTO_DEBUGCONSOLE:
{
std::string Xbe_info = DumpInformation(m_Xbe);
if (m_Xbe->HasError()) {
MessageBox(m_hwnd, m_Xbe->GetError().c_str(), "Cxbx-Reloaded", MB_ICONSTOP | MB_OK);
}
else {
std::cout << Xbe_info;
char buffer[255];
sprintf(buffer, "%s's .xbe info was successfully dumped to console.", m_Xbe->m_szAsciiTitle);
printf("WndMain: %s\n", buffer);
}
}
break;
case ID_SETTINGS_CONFIG_CONTROLLER:
ShowControllerConfig(hwnd);
@ -1315,21 +1303,21 @@ LRESULT CALLBACK WndMain::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lP
DeleteObject(m_LedBmp);
DeleteObject(m_BrushBlack);
DeleteObject(m_Brushes[XBOX_LED_COLOUR_OFF]);
DeleteObject(m_BrushRed);
DeleteObject(m_Brushes[XBOX_LED_COLOUR_GREEN]);
DeleteObject(m_BrushGreen);
DeleteObject(m_Brushes[XBOX_LED_COLOUR_RED]);
DeleteObject(m_BrushOrange);
DeleteObject(m_Brushes[XBOX_LED_COLOUR_ORANGE]);
DeleteObject(m_PenBlack);
DeleteObject(m_Pens[XBOX_LED_COLOUR_OFF]);
DeleteObject(m_PenRed);
DeleteObject(m_Pens[XBOX_LED_COLOUR_GREEN]);
DeleteObject(m_PenGreen);
DeleteObject(m_Pens[XBOX_LED_COLOUR_RED]);
DeleteObject(m_PenOrange);
DeleteObject(m_Pens[XBOX_LED_COLOUR_ORANGE]);
ReleaseDC(hwnd, hDC);
@ -1811,7 +1799,7 @@ void WndMain::OpenXbe(const char *x_filename)
strcpy(m_XbeFilename, x_filename);
m_Xbe = new Xbe(m_XbeFilename);
m_Xbe = new Xbe(m_XbeFilename, true);
if(m_Xbe->HasError())
{
@ -2094,6 +2082,8 @@ void WndMain::StopEmulation()
// wrapper function to call CrashMonitor
DWORD WINAPI WndMain::CrashMonitorWrapper(LPVOID lpVoid)
{
CxbxSetThreadName("Cxbx Crash Monitor");
static_cast<WndMain*>(lpVoid)->CrashMonitor();
return 0;
}
@ -2101,12 +2091,12 @@ DWORD WINAPI WndMain::CrashMonitorWrapper(LPVOID lpVoid)
// monitor for crashes
void WndMain::CrashMonitor()
{
bool bMultiXbe;
bool bQuickReboot;
HANDLE hCrashMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, "CrashMutex");
DWORD state = WaitForSingleObject(hCrashMutex, INFINITE);
g_EmuShared->GetMultiXbeFlag(&bMultiXbe);
g_EmuShared->GetQuickRebootFlag(&bQuickReboot);
if (state == WAIT_OBJECT_0) // StopEmulation
{
@ -2114,7 +2104,7 @@ void WndMain::CrashMonitor()
return;
}
if (state == WAIT_ABANDONED && !bMultiXbe) // that's a crash
if (state == WAIT_ABANDONED && !bQuickReboot) // that's a crash
{
CloseHandle(hCrashMutex);
if (m_bIsStarted) // that's a hard crash, Dr Watson is invoked
@ -2133,8 +2123,8 @@ void WndMain::CrashMonitor()
// multi-xbe
// destroy this thread and start a new one
CloseHandle(hCrashMutex);
bMultiXbe = false;
g_EmuShared->SetMultiXbeFlag(&bMultiXbe);
bQuickReboot = false;
g_EmuShared->SetQuickRebootFlag(&bQuickReboot);
return;
}
@ -2143,88 +2133,38 @@ void WndMain::CrashMonitor()
void WndMain::DrawLedBitmap(HWND hwnd, bool bdefault)
{
HMENU hMenu = GetMenu(hwnd);
if (bdefault) // draw default black bitmap
{
SelectObject(m_LedDC, m_BrushBlack);
SelectObject(m_LedDC, m_PenBlack);
m_OriLed = (HBITMAP)SelectObject(m_LedDC, m_LedBmp);
Rectangle(m_LedDC, 0, 0, m_xBmp, m_yBmp);
m_LedBmp = (HBITMAP)SelectObject(m_LedDC, m_OriLed);
MENUITEMINFO mii;
mii.cbSize = sizeof(mii);
mii.fMask = MIIM_BITMAP | MIIM_FTYPE;
mii.fType = MFT_RIGHTJUSTIFY;
mii.hbmpItem = m_LedBmp;
SetMenuItemInfo(hMenu, ID_LED, FALSE, &mii);
DrawMenuBar(hwnd);
int ActiveLEDColor;
// When so requested, or when not emulating, draw a black bitmap
if (bdefault || !m_bIsStarted) {
ActiveLEDColor = XBOX_LED_COLOUR_OFF;
}
else // draw colored bitmap
{
else { // draw colored bitmap
int LedSequence[4] = { XBOX_LED_COLOUR_OFF, XBOX_LED_COLOUR_OFF, XBOX_LED_COLOUR_OFF, XBOX_LED_COLOUR_OFF };
static int LedSequenceOffset = 0;
bool bLedHasChanged;
int LedSequence[4];
g_EmuShared->GetLedStatus(&bLedHasChanged);
g_EmuShared->GetLedSequence(LedSequence);
if (bLedHasChanged)
{
LedSequenceOffset = 0;
bLedHasChanged = false;
g_EmuShared->SetLedStatus(&bLedHasChanged);
}
m_OriLed = (HBITMAP)SelectObject(m_LedDC, m_LedBmp);
Rectangle(m_LedDC, 0, 0, m_xBmp, m_yBmp);
MENUITEMINFO mii;
mii.cbSize = sizeof(mii);
mii.fMask = MIIM_BITMAP | MIIM_FTYPE;
mii.fType = MFT_RIGHTJUSTIFY;
mii.hbmpItem = m_LedBmp;
switch (LedSequence[LedSequenceOffset])
{
case XBOX_LED_COLOUR_RED:
{
SelectObject(m_LedDC, m_BrushRed);
SelectObject(m_LedDC, m_PenRed);
}
break;
case XBOX_LED_COLOUR_GREEN:
{
SelectObject(m_LedDC, m_BrushGreen);
SelectObject(m_LedDC, m_PenGreen);
}
break;
case XBOX_LED_COLOUR_ORANGE:
{
SelectObject(m_LedDC, m_BrushOrange);
SelectObject(m_LedDC, m_PenOrange);
}
break;
case XBOX_LED_COLOUR_OFF:
{
SelectObject(m_LedDC, m_BrushBlack);
SelectObject(m_LedDC, m_PenBlack);
}
break;
}
m_LedBmp = (HBITMAP)SelectObject(m_LedDC, m_OriLed);
if (LedSequenceOffset == 3)
{
LedSequenceOffset = 0;
}
else
{
++LedSequenceOffset;
}
SetMenuItemInfo(hMenu, ID_LED, FALSE, &mii);
DrawMenuBar(hwnd);
// Select active color and cycle through all 4 phases in the sequence
ActiveLEDColor = LedSequence[LedSequenceOffset & 3];
++LedSequenceOffset;
}
SelectObject(m_LedDC, m_Brushes[ActiveLEDColor]);
SelectObject(m_LedDC, m_Pens[ActiveLEDColor]);
m_OriLed = (HBITMAP)SelectObject(m_LedDC, m_LedBmp);
Rectangle(m_LedDC, 0, 0, m_xBmp, m_yBmp);
m_LedBmp = (HBITMAP)SelectObject(m_LedDC, m_OriLed);
MENUITEMINFO mii = { 0 };
mii.cbSize = sizeof(mii);
mii.fMask = MIIM_FTYPE | MIIM_BITMAP;
mii.fType = MFT_RIGHTJUSTIFY;
mii.hbmpItem = m_LedBmp;
SetMenuItemInfo(hMenu, ID_LED, FALSE, &mii);
DrawMenuBar(hwnd);
return;
}

View File

@ -151,14 +151,8 @@ class WndMain : public Wnd
HBITMAP m_LogoBmp;
HBITMAP m_GameLogoBMP;
HBITMAP m_LedBmp;
HBRUSH m_BrushBlack;
HBRUSH m_BrushRed;
HBRUSH m_BrushGreen;
HBRUSH m_BrushOrange;
HPEN m_PenBlack;
HPEN m_PenRed;
HPEN m_PenGreen;
HPEN m_PenOrange;
HBRUSH m_Brushes[4];
HPEN m_Pens[4];
int m_xBmp, m_yBmp;
// ******************************************************************

View File

@ -51,7 +51,6 @@ namespace xboxkrnl
#include "EmuEEPROM.h" // For CxbxRestoreEEPROM, EEPROM, XboxFactoryGameRegion
#include "EmuKrnl.h"
#include "EmuShared.h"
#include "EmuNV2A.h" // For InitOpenGLContext
#include "HLEIntercept.h"
#include "ReservedMemory.h" // For virtual_memory_placeholder
#include "VMManager.h"
@ -64,8 +63,10 @@ namespace xboxkrnl
#include <time.h> // For time()
#include <sstream> // For std::ostringstream
#include "Xbox.h" // For InitXboxHardware()
#include "EEPROMDevice.h" // For g_EEPROM
#include "devices\EEPROMDevice.h" // For g_EEPROM
#include "devices\video\EmuNV2A.h" // For InitOpenGLContext
#include "devices\Xbox.h" // For InitXboxHardware()
#include "devices\LED.h" // For LED::Sequence
/* prevent name collisions */
namespace NtDll
@ -106,6 +107,9 @@ DWORD_PTR g_CPUOthers = 0;
HANDLE g_CurrentProcessHandle = 0; // Set in CxbxKrnlMain
bool g_IsWine = false;
bool g_CxbxPrintUEM = false;
ULONG g_CxbxFatalErrorCode = FATAL_ERROR_NONE;
// Define function located in EmuXApi so we can call it from here
void SetupXboxDeviceTypes();
@ -497,6 +501,8 @@ void PrintCurrentConfigurationLog()
static unsigned int WINAPI CxbxKrnlInterruptThread(PVOID param)
{
CxbxSetThreadName("CxbxKrnl Interrupts");
// Make sure Xbox1 code runs on one core :
InitXboxThread(g_CPUXbox);
@ -516,6 +522,11 @@ static unsigned int WINAPI CxbxKrnlInterruptThread(PVOID param)
void CxbxKrnlMain(int argc, char* argv[])
{
// Treat this instance as the Xbox runtime entry point XBOXStartup()
// This is defined in OpenXDK:
// import/OpenXDK/include/xhal/xhal.h
CxbxSetThreadName("Cxbx XBOXStartup");
// Skip '/load' switch
// Get XBE Name :
std::string xbePath = argv[2];
@ -568,6 +579,9 @@ void CxbxKrnlMain(int argc, char* argv[])
}
}
// We must save this handle now to keep the child window working in the case we need to display the UEM
CxbxKrnl_hEmuParent = IsWindow(hWnd) ? hWnd : NULL;
g_CurrentProcessHandle = GetCurrentProcess(); // OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
// Write a header to the log
@ -597,6 +611,7 @@ void CxbxKrnlMain(int argc, char* argv[])
g_IsWine = true;
}
}
// Now we got the arguments, start by initializing the Xbox memory map :
// PrepareXBoxMemoryMap()
{
@ -667,7 +682,7 @@ void CxbxKrnlMain(int argc, char* argv[])
{
// Load Xbe (this one will reside above WinMain's virtual_memory_placeholder)
g_EmuShared->SetXbePath(xbePath.c_str());
CxbxKrnl_Xbe = new Xbe(xbePath.c_str()); // TODO : Instead of using the Xbe class, port Dxbx _ReadXbeBlock()
CxbxKrnl_Xbe = new Xbe(xbePath.c_str(), false); // TODO : Instead of using the Xbe class, port Dxbx _ReadXbeBlock()
if (CxbxKrnl_Xbe->HasFatalError()) {
CxbxKrnlCleanup(CxbxKrnl_Xbe->GetError().c_str());
@ -749,7 +764,6 @@ void CxbxKrnlMain(int argc, char* argv[])
EntryPoint ^= XOR_EP_KEY[g_XbeType];
// Launch XBE
CxbxKrnlInit(
hWnd,
XbeTlsData,
XbeTls,
CxbxKrnl_Xbe->m_LibraryVersion,
@ -799,7 +813,6 @@ void LoadXboxKeys(std::string path)
__declspec(noreturn) void CxbxKrnlInit
(
HWND hwndParent,
void *pTLSData,
Xbe::TLS *pTLS,
Xbe::LibraryVersion *pLibraryVersion,
@ -813,7 +826,6 @@ __declspec(noreturn) void CxbxKrnlInit
CxbxKrnl_TLS = pTLS;
CxbxKrnl_TLSData = pTLSData;
CxbxKrnl_XbeHeader = pXbeHeader;
CxbxKrnl_hEmuParent = IsWindow(hwndParent) ? hwndParent : NULL;
CxbxKrnl_DebugMode = DbgMode;
CxbxKrnl_DebugFileName = (char*)szDebugFilename;
@ -846,7 +858,7 @@ __declspec(noreturn) void CxbxKrnlInit
" pXBEHeaderSize : 0x%.08X\n"
" Entry : 0x%.08X\n"
");\n",
GetCurrentThreadId(), hwndParent, pTLSData, pTLS, pLibraryVersion, DbgMode, szDebugFilename, pXbeHeader, dwXbeHeaderSize, Entry);
GetCurrentThreadId(), CxbxKrnl_hEmuParent, pTLSData, pTLS, pLibraryVersion, DbgMode, szDebugFilename, pXbeHeader, dwXbeHeaderSize, Entry);
#else
printf("[0x%X] INIT: Debug Trace Disabled.\n", GetCurrentThreadId());
#endif
@ -1017,7 +1029,23 @@ __declspec(noreturn) void CxbxKrnlInit
// initialize graphics
DbgPrintf("INIT: Initializing render window.\n");
XTL::CxbxInitWindow(pXbeHeader, dwXbeHeaderSize);
XTL::CxbxInitWindow(true);
// Now process the boot flags to see if there are any special conditions to handle
int BootFlags = 0;
g_EmuShared->GetBootFlags(&BootFlags);
if (BootFlags & BOOT_EJECT_PENDING) {} // TODO
if (BootFlags & BOOT_FATAL_ERROR)
{
// If we are here it means we have been rebooted to display the fatal error screen. The error code is set
// to 0x15 and the led flashes with the sequence green, red, red, red
SetLEDSequence(0xE1);
CxbxKrnlPrintUEM(FATAL_ERROR_REBOOT_ROUTINE); // won't return
}
if (BootFlags & BOOT_SKIP_ANIMATION) {} // TODO
if (BootFlags & BOOT_RUN_DASHBOARD) {} // TODO
XTL::CxbxInitAudio();
@ -1030,9 +1058,6 @@ __declspec(noreturn) void CxbxKrnlInit
// Now the hardware devices exist, couple the EEPROM buffer to it's device
g_EEPROM->SetEEPROM((uint8_t*)EEPROM);
// Always initialise NV2A: We may need it for disabled HLE patches too!
EmuNV2A_Init();
if (bLLE_GPU)
{
DbgPrintf("INIT: Initializing OpenGL.\n");
@ -1282,6 +1307,63 @@ void CxbxKrnlResume()
g_bEmuSuspended = false;
}
void CxbxKrnlShutDown()
{
if (CxbxKrnl_hEmuParent != NULL)
SendMessage(CxbxKrnl_hEmuParent, WM_PARENTNOTIFY, WM_DESTROY, 0);
EmuShared::Cleanup();
TerminateProcess(g_CurrentProcessHandle, 0);
}
void CxbxKrnlPrintUEM(ULONG ErrorCode)
{
ULONG Type;
xboxkrnl::XBOX_EEPROM Eeprom;
ULONG ResultSize;
int BootFlags;
g_EmuShared->GetBootFlags(&BootFlags);
BootFlags &= ~BOOT_FATAL_ERROR; // clear the fatal error flag to avoid looping here endlessly
g_EmuShared->SetBootFlags(&BootFlags);
NTSTATUS status = xboxkrnl::ExQueryNonVolatileSetting(xboxkrnl::XC_MAX_ALL, &Type, &Eeprom, sizeof(Eeprom), &ResultSize);
if (status == STATUS_SUCCESS)
{
xboxkrnl::XBOX_UEM_INFO* UEMInfo = (xboxkrnl::XBOX_UEM_INFO*)&(Eeprom.UEMInfo[0]);
if (UEMInfo->ErrorCode == FATAL_ERROR_NONE)
{
// ergo720: the Xbox sets the error code and displays the UEM only for non-manufacturing xbe's (it power cycles
// otherwise). Considering that this flag can be easily tampered with in the xbe and the typical end user of cxbx
// can't fix the cause of the fatal error, I decided to always display it anyway.
UEMInfo->ErrorCode = (UCHAR)ErrorCode;
UEMInfo->History |= (1 << (ErrorCode - 5));
}
else {
UEMInfo->ErrorCode = FATAL_ERROR_NONE;
}
xboxkrnl::ExSaveNonVolatileSetting(xboxkrnl::XC_MAX_ALL, Type, &Eeprom, sizeof(Eeprom));
}
else {
CxbxKrnlCleanup("Could not display the fatal error screen");
}
if (g_bIsChihiro)
{
// The Chihiro doesn't display the UEM
CxbxKrnlCleanup("The running Chihiro xbe has encountered a fatal error and needs to close");
}
g_CxbxFatalErrorCode = ErrorCode;
g_CxbxPrintUEM = true; // print the UEM
// Sleep forever to prevent continuing the initialization
Sleep(INFINITE);
}
__declspec(noreturn) void CxbxKrnlTerminateThread()
{
TerminateThread(GetCurrentThread(), 0);

View File

@ -152,6 +152,14 @@ extern "C" {
#define VECTOR2IRQ(vector) ((vector)-IRQ_BASE)
#define VECTOR2IRQL(vector) (PROFILE_LEVEL - VECTOR2IRQ(vector))
// Kernel boot flags
enum {
BOOT_EJECT_PENDING = 1 << 0,
BOOT_FATAL_ERROR = 1 << 1,
BOOT_SKIP_ANIMATION = 1 << 2,
BOOT_RUN_DASHBOARD = 1 << 3,
};
void CxbxPopupMessage(const char *message, ...);
#define LOG_TEST_CASE(message) do { static bool bPopupShown = false; \
@ -169,7 +177,7 @@ bool CxbxKrnlVerifyVersion(const char *szVersion);
void CxbxKrnlMain(int argc, char* argv[]);
/*! initialize emulation */
__declspec(noreturn) void CxbxKrnlInit(HWND hwndParent, void *pTLSData, Xbe::TLS *pTLS, Xbe::LibraryVersion *LibraryVersion, DebugMode DbgMode, const char *szDebugFilename, Xbe::Header *XbeHeader, uint32 XbeHeaderSize, void (*Entry)());
__declspec(noreturn) void CxbxKrnlInit(void *pTLSData, Xbe::TLS *pTLS, Xbe::LibraryVersion *LibraryVersion, DebugMode DbgMode, const char *szDebugFilename, Xbe::Header *XbeHeader, uint32 XbeHeaderSize, void (*Entry)());
/*! cleanup emulation */
__declspec(noreturn) void CxbxKrnlCleanup(const char *szErrorMessage, ...);
@ -183,6 +191,12 @@ void CxbxKrnlSuspend();
/*! resume emulation */
void CxbxKrnlResume();
/*! terminate gracefully the emulation */
void CxbxKrnlShutDown();
/*! display the fatal error message*/
void CxbxKrnlPrintUEM(ULONG ErrorCode);
/*! terminate the calling thread */
__declspec(noreturn) void CxbxKrnlTerminateThread();
@ -205,6 +219,9 @@ extern uint32 CxbxKrnl_KernelThunkTable[379];
extern bool g_IsWine;
extern bool g_CxbxPrintUEM;
extern ULONG g_CxbxFatalErrorCode;
void InitXboxThread(DWORD_PTR cores);
/*! thread local storage structure */

View File

@ -57,6 +57,7 @@ namespace xboxkrnl
#include "Logging.h"
#include "EmuD3D8Logging.h"
#include "HLEIntercept.h" // for bLLE_GPU
#include "Cxbx\\ResCxbx.h"
#include <assert.h>
#include <process.h>
@ -97,8 +98,6 @@ static XTL::DDCAPS g_DriverCaps = { 0 };
static DWORD g_dwOverlayW = 640; // Cached Overlay Width
static DWORD g_dwOverlayH = 480; // Cached Overlay Height
static DWORD g_dwOverlayP = 640; // Cached Overlay Pitch
static Xbe::Header *g_XbeHeader = NULL; // XbeHeader
static uint32 g_XbeHeaderSize = 0; // XbeHeaderSize
static HBRUSH g_hBgBrush = NULL; // Background Brush
static volatile bool g_bRenderWindowActive = false;
static XBVideo g_XBVideo;
@ -394,7 +393,7 @@ const char *CxbxGetErrorDescription(HRESULT hResult)
case DDERR_NOTLOCKED: return "An attempt was made to unlock a surface that was not locked.";
case DDERR_NOTPAGELOCKED: return "An attempt was made to page-unlock a surface with no outstanding page locks.";
case DDERR_NOTPALETTIZED: return "The surface being used is not a palette-based surface.";
case DDERR_NOVSYNCHW: return "There is no hardware support for vertical blank–synchronized operations.";
case DDERR_NOVSYNCHW: return "There is no hardware support for vertical blanksynchronized operations.";
case DDERR_NOZBUFFERHW: return "The operation to create a z-buffer in display memory or to perform a blit, using a z-buffer cannot be carried out because there is no hardware support for z-buffers.";
case DDERR_NOZOVERLAYHW: return "The overlay surfaces cannot be z-layered, based on the z-order because the hardware does not support z-ordering of overlays.";
case DDERR_OUTOFCAPS: return "The hardware needed for the requested operation has already been allocated.";
@ -452,18 +451,15 @@ const char *D3DErrorString(HRESULT hResult)
return buffer;
}
VOID XTL::CxbxInitWindow(Xbe::Header *XbeHeader, uint32 XbeHeaderSize)
VOID XTL::CxbxInitWindow(bool bFullInit)
{
g_EmuShared->GetXBVideo(&g_XBVideo);
if(g_XBVideo.GetFullscreen())
CxbxKrnl_hEmuParent = NULL;
// cache XbeHeader and size of XbeHeader
g_XbeHeader = XbeHeader;
g_XbeHeaderSize = XbeHeaderSize;
// create timing thread
if (bFullInit)
{
DWORD dwThreadId;
@ -499,7 +495,8 @@ VOID XTL::CxbxInitWindow(Xbe::Header *XbeHeader, uint32 XbeHeaderSize)
// Ported from Dxbx :
// If possible, assign this thread to another core than the one that runs Xbox1 code :
SetThreadAffinityMask(hRenderWindowThread, g_CPUOthers);
if (bFullInit)
SetThreadAffinityMask(hRenderWindowThread, g_CPUOthers);
while(!g_bRenderWindowActive)
SwitchToThread();
@ -510,6 +507,70 @@ VOID XTL::CxbxInitWindow(Xbe::Header *XbeHeader, uint32 XbeHeaderSize)
SetFocus(g_hEmuWindow);
}
void DrawUEM(HWND hWnd)
{
// Draw the universal error message (UEM)
// See http://xboxdevwiki.net/Fatal_Error
// Only call this from WM_PAINT message!
PAINTSTRUCT ps;
BeginPaint(hWnd, &ps);
HDC hDC = GetDC(hWnd);
HDC hMemDC = CreateCompatibleDC(hDC);
HBITMAP hUEMBmp = CreateCompatibleBitmap(hDC, 640, 480);
HBITMAP hOriUEMBmp = (HBITMAP)SelectObject(hMemDC, hUEMBmp);
int nHeight = -MulDiv(8, GetDeviceCaps(hMemDC, LOGPIXELSY), 72);
HFONT hFont = CreateFont(nHeight, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_ROMAN, "Verdana");
HGDIOBJ tmpObj = SelectObject(hMemDC, hFont);
SetBkColor(hMemDC, RGB(0, 0, 0));
SetTextColor(hMemDC, RGB(0, 204, 0));
wchar_t buff[500];
LoadStringW(GetModuleHandle(NULL), IDS_UEM, buff, sizeof(buff) / sizeof(wchar_t));
std::wstring wstr(buff);
// Unfortunately, DrawTextW doesn't support vertical alignemnt, so we have to do the calculation
// ourselves. See here: https://social.msdn.microsoft.com/Forums/vstudio/en-US/abd89aae-16a0-41c6-8db6-b119ea90b42a/win32-drawtext-how-center-in-vertical-with-new-lines-and-tabs?forum=vclanguage
RECT rect = { 0, 0, 640, 480 };
RECT textrect = { 0, 0, 640, 480 };
DrawTextW(hMemDC, wstr.c_str(), wstr.length(), &textrect, DT_CALCRECT);
rect.top = (rect.bottom - textrect.bottom) / 2;
DrawTextW(hMemDC, wstr.c_str(), wstr.length(), &rect, DT_CENTER);
// Draw the Xbox error code
SetTextColor(hMemDC, RGB(255, 255, 255));
std::string err_str(std::to_string(g_CxbxFatalErrorCode));
rect.left = 20;
DrawText(hMemDC, err_str.c_str(), err_str.length(), &rect, DT_LEFT);
GetClientRect(hWnd, &rect);
SetStretchBltMode(hDC, COLORONCOLOR);
StretchBlt(hDC, rect.left, rect.top, rect.right, rect.bottom, hMemDC, 0, 0, 640, 480, SRCCOPY);
SelectObject(hMemDC, hOriUEMBmp);
SelectObject(hDC, tmpObj);
DeleteObject(hUEMBmp);
DeleteObject(hFont);
DeleteObject(hMemDC);
if (hDC != NULL)
ReleaseDC(hWnd, hDC);
EndPaint(hWnd, &ps);
}
inline DWORD GetXboxCommonResourceType(const XTL::X_D3DResource *pXboxResource)
{
// Don't pass in unassigned Xbox resources
@ -1169,6 +1230,8 @@ static BOOL WINAPI EmuEnumDisplayDevices(GUID FAR *lpGUID, LPSTR lpDriverDescrip
// window message processing thread
static DWORD WINAPI EmuRenderWindow(LPVOID lpVoid)
{
CxbxSetThreadName("Cxbx Render Window");
// register window class
{
LOGBRUSH logBrush = {BS_SOLID, RGB(0,0,0)};
@ -1191,13 +1254,13 @@ static DWORD WINAPI EmuRenderWindow(LPVOID lpVoid)
RegisterClassEx(&wc);
}
bool bMultiXbe;
g_EmuShared->GetMultiXbeFlag(&bMultiXbe);
bool bQuickReboot;
g_EmuShared->GetQuickRebootFlag(&bQuickReboot);
// precaution for multi-xbe titles in the case CrashMonitor has still not destoyed the previous mutex
while (bMultiXbe)
while (bQuickReboot)
{
g_EmuShared->GetMultiXbeFlag(&bMultiXbe);
g_EmuShared->GetQuickRebootFlag(&bQuickReboot);
}
HANDLE hCrashMutex = CreateMutex(NULL, TRUE, "CrashMutex");
@ -1365,6 +1428,15 @@ static LRESULT WINAPI EmuMsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPar
}
break;
case WM_PAINT:
{
if (g_CxbxPrintUEM)
{
DrawUEM(hWnd);
}
}
break;
case WM_SYSKEYDOWN:
{
if(wParam == VK_RETURN)
@ -1502,6 +1574,8 @@ std::chrono::time_point<std::chrono::steady_clock, std::chrono::duration<double,
// timing thread procedure
static DWORD WINAPI EmuUpdateTickCount(LPVOID)
{
CxbxSetThreadName("Cxbx Timing Thread");
// since callbacks come from here
InitXboxThread(g_CPUOthers); // avoid Xbox1 core for lowest possible latency
@ -1602,6 +1676,8 @@ static DWORD WINAPI EmuCreateDeviceProxy(LPVOID)
{
LOG_FUNC();
CxbxSetThreadName("Cxbx CreateDevice Proxy");
DbgPrintf("EmuD3D8: CreateDevice proxy thread is running.\n");
while(true)
@ -2742,6 +2818,8 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SelectVertexShader)
LOG_FUNC_END;
HRESULT hRet;
g_CurrentVertexShader = Handle;
if(VshHandleIsVertexShader(Handle))
{
@ -4676,11 +4754,6 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_Begin)
g_IVBPrimitiveType = PrimitiveType;
if(g_IVBTable == nullptr)
{
g_IVBTable = (struct XTL::_D3DIVB*)g_VMManager.Allocate(sizeof(XTL::_D3DIVB)*IVB_TABLE_SIZE);
}
g_IVBTblOffs = 0;
g_IVBFVF = 0;
@ -4901,7 +4974,7 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_SetVertexData4f)
}
default:
CxbxKrnlCleanup("Unknown IVB Register : %d", Register);
EmuWarning("Unknown IVB Register : %d", Register);
}
}
@ -8967,7 +9040,36 @@ VOID WINAPI XTL::EMUPATCH(D3DDevice_LoadVertexShaderProgram)
LOG_FUNC_ARG(Address)
LOG_FUNC_END;
LOG_UNIMPLEMENTED();
// NOTE: Azurik needs this to work, but this implementation makes
// Sonic Heroes (E3 Demo) run slower and look a bit worse. An investigation
// may be necessary...
#if 1
DWORD Handle = g_CurrentVertexShader;
// TODO: Cache vertex shaders? Azurik overwrites the same vertex shader
// slot over and over again with many different vertex shaders per frame...
if( VshHandleIsVertexShader(Handle) )
{
X_D3DVertexShader *pD3DVertexShader = (X_D3DVertexShader *)(Handle & 0x7FFFFFFF);
VERTEX_SHADER *pVertexShader = (VERTEX_SHADER *)pD3DVertexShader->Handle;
// Save the contents of the existing vertex shader program
DWORD* pDeclaration = (DWORD*) malloc( pVertexShader->DeclarationSize );
memmove( pDeclaration, pVertexShader->pDeclaration, pVertexShader->DeclarationSize );
// Delete the vertex shader
EMUPATCH(D3DDevice_DeleteVertexShader)(Handle);
// Re-create the vertex shader with the new code
HRESULT hr = EMUPATCH(D3DDevice_CreateVertexShader)( pDeclaration, pFunction, &Handle, 0 );
free(pDeclaration);
if( FAILED( hr ) )
CxbxKrnlCleanup( "Error re-creating vertex shader!" );
EMUPATCH(D3DDevice_LoadVertexShader)(Handle, Address);
EMUPATCH(D3DDevice_SelectVertexShader)(Handle, Address);
}
#endif
}
// ******************************************************************
@ -9842,7 +9944,7 @@ HRESULT WINAPI XTL::EMUPATCH(D3DDevice_PersistDisplay)()
// ******************************************************************
DWORD WINAPI XTL::EMUPATCH(D3D_CMiniport_GetDisplayCapabilities)()
{
FUNC_EXPORTS
//FUNC_EXPORTS
LOG_FUNC();

View File

@ -43,7 +43,7 @@
#include <ddraw.h>
// initialize render window
extern VOID CxbxInitWindow(Xbe::Header *XbeHeader, uint32 XbeHeaderSize);
extern VOID CxbxInitWindow(bool bFullInit);
extern VOID CxbxSetPixelContainerHeader
(

7
src/CxbxKrnl/EmuD3D8/Convert.h Normal file → Executable file
View File

@ -36,7 +36,12 @@
#include "CxbxKrnl.h"
//#define OLD_COLOR_CONVERSION
// It's a real shame but the new conversion code needs to be disable for now
// it causes crashes and other issues in titles using palletted textures
// It seems draw time conversion is really required before this can function
// correctly.
#define OLD_COLOR_CONVERSION
// simple render state encoding lookup table
#define X_D3DRSSE_UNK 0x7fffffff

2
src/CxbxKrnl/EmuD3D8/VertexBuffer.cpp Normal file → Executable file
View File

@ -53,7 +53,7 @@
XTL::DWORD *XTL::g_pIVBVertexBuffer = nullptr;
XTL::X_D3DPRIMITIVETYPE XTL::g_IVBPrimitiveType = XTL::X_D3DPT_INVALID;
UINT XTL::g_IVBTblOffs = 0;
struct XTL::_D3DIVB *XTL::g_IVBTable = nullptr;
struct XTL::_D3DIVB XTL::g_IVBTable[IVB_TABLE_SIZE];
extern DWORD XTL::g_IVBFVF = 0;
extern XTL::X_D3DVertexBuffer *g_pVertexBuffer = NULL;

12
src/CxbxKrnl/EmuD3D8/VertexBuffer.h Normal file → Executable file
View File

@ -130,12 +130,13 @@ extern DWORD *g_pIVBVertexBuffer;
extern X_D3DPRIMITIVETYPE g_IVBPrimitiveType;
extern DWORD g_IVBFVF;
#define IVB_TABLE_SIZE 1024
#define IVB_BUFFER_SIZE sizeof(_D3DIVB)*1024
#define IVB_TABLE_SIZE 4096 // This should be more than enough. Tweak as necessary if it overflows or the resulting VertexBuffer fails to allocate
#define IVB_BUFFER_SIZE sizeof(_D3DIVB) * IVB_TABLE_SIZE
// TODO : Enlarge IVB_TABLE_SIZE and IVB_BUFFER_SIZE
// TODO : Calculate IVB_BUFFER_SIZE using sizeof(DWORD)
extern struct _D3DIVB
struct _D3DIVB
{
XTL::D3DXVECTOR3 Position; // Position
FLOAT Rhw; // Rhw
@ -147,8 +148,9 @@ extern struct _D3DIVB
XTL::D3DXVECTOR2 TexCoord2; // TexCoord2
XTL::D3DXVECTOR2 TexCoord3; // TexCoord3
XTL::D3DXVECTOR2 TexCoord4; // TexCoord4
}
*g_IVBTable;
};
extern _D3DIVB g_IVBTable[IVB_TABLE_SIZE];
extern UINT g_IVBTblOffs;

View File

@ -2194,6 +2194,12 @@ extern HRESULT XTL::EmuRecompileVshFunction
// The size of the shader is
*pOriginalSize = (DWORD)pToken - (DWORD)pFunction;
// Do not attempt to compile empty shaders
if (pShader->IntermediateCount == 0) {
EmuWarning("Skipped empty Pixel Shader");
return STATUS_INVALID_PARAMETER;
}
char* pShaderDisassembly = (char*)malloc(pShader->IntermediateCount * 100); // Should be plenty
DbgVshPrintf("-- Before conversion --\n");
VshWriteShader(pShader, pShaderDisassembly, FALSE);

View File

@ -135,7 +135,6 @@ XTL::X_XFileMediaObject::_vtbl XTL::X_XFileMediaObject::vtbl =
&XTL::EMUPATCH(XFileMediaObject_DoWork), // 0x24
};
/* NOTE: SUCCEEDED define is only checking for is equal or greater than zero value.
And FAILED check for less than zero value. Since DS_OK is only 0 base on DirectSound documentation,
there is chance of failure which contain value greater than 0.
@ -3345,7 +3344,7 @@ HRESULT WINAPI XTL::EMUPATCH(XFileCreateMediaObjectEx)
HANDLE hFile,
OUT void** ppMediaObject)
{
FUNC_EXPORTS;
//FUNC_EXPORTS;
enterCriticalSection;
@ -3370,7 +3369,7 @@ HRESULT WINAPI XTL::EMUPATCH(XWaveFileCreateMediaObject)
LPCWAVEFORMATEX* ppwfxFormat,
OUT void** ppMediaObject) //XFileMediaObject, include XMediaObject interface
{
FUNC_EXPORTS;
//FUNC_EXPORTS;
enterCriticalSection;
@ -3590,7 +3589,7 @@ HRESULT WINAPI XTL::EMUPATCH(XFileCreateMediaObjectAsync)
DWORD dwMaxPackets,
OUT void** ppMediaObject)
{
FUNC_EXPORTS;
//FUNC_EXPORTS;
enterCriticalSection;
@ -3619,7 +3618,7 @@ HRESULT WINAPI XTL::EMUPATCH(XFileMediaObject_Seek)
DWORD dwOrigin,
LPDWORD pdwAbsolute)
{
FUNC_EXPORTS;
//FUNC_EXPORTS;
enterCriticalSection;
@ -3642,7 +3641,7 @@ HRESULT WINAPI XTL::EMUPATCH(XFileMediaObject_Seek)
// ******************************************************************
VOID WINAPI XTL::EMUPATCH(XFileMediaObject_DoWork)(X_XFileMediaObject* pThis)
{
FUNC_EXPORTS;
//FUNC_EXPORTS;
enterCriticalSection;
@ -3661,7 +3660,7 @@ HRESULT WINAPI XTL::EMUPATCH(XFileMediaObject_GetStatus)
X_XFileMediaObject* pThis,
OUT LPDWORD pdwStatus)
{
FUNC_EXPORTS;
//FUNC_EXPORTS;
enterCriticalSection;
@ -3685,7 +3684,7 @@ HRESULT WINAPI XTL::EMUPATCH(XFileMediaObject_GetInfo)
X_XFileMediaObject* pThis,
OUT XMEDIAINFO* pInfo)
{
FUNC_EXPORTS;
//FUNC_EXPORTS;
enterCriticalSection;
@ -3710,7 +3709,7 @@ HRESULT WINAPI XTL::EMUPATCH(XFileMediaObject_Process)
LPXMEDIAPACKET pInputBuffer,
LPXMEDIAPACKET pOutputBuffer)
{
FUNC_EXPORTS;
//FUNC_EXPORTS;
enterCriticalSection;
@ -3734,7 +3733,7 @@ ULONG WINAPI XTL::EMUPATCH(XFileMediaObject_AddRef)
(
X_XFileMediaObject* pThis)
{
FUNC_EXPORTS;
//FUNC_EXPORTS;
enterCriticalSection;
@ -3758,7 +3757,7 @@ ULONG WINAPI XTL::EMUPATCH(XFileMediaObject_Release)
(
X_XFileMediaObject* pThis)
{
FUNC_EXPORTS;
//FUNC_EXPORTS;
enterCriticalSection;
@ -3785,7 +3784,7 @@ HRESULT WINAPI XTL::EMUPATCH(XFileMediaObject_Discontinuity)
(
X_XFileMediaObject *pThis)
{
FUNC_EXPORTS;
//FUNC_EXPORTS;
enterCriticalSection;
@ -3908,7 +3907,7 @@ HRESULT WINAPI XTL::EMUPATCH(XFileCreateMediaObject)
DWORD dwFlagsAndAttributes,
OUT void** ppMediaObject)
{
FUNC_EXPORTS;
//FUNC_EXPORTS;
enterCriticalSection;
@ -3937,7 +3936,7 @@ HRESULT WINAPI XTL::EMUPATCH(XWaveFileCreateMediaObjectEx)
HANDLE hFile,
OUT void** ppMediaObject) //XWaveFileMediaObject, include XFileMediaObject and XMediaObject interfaces
{
FUNC_EXPORTS;
//FUNC_EXPORTS;
enterCriticalSection;

View File

@ -331,6 +331,16 @@ void copy_string_to_PSTRING_to(std::string const & src, const xboxkrnl::PSTRING
memcpy(dest->Buffer, src.c_str(), dest->Length);
}
void replace_all(std::string& str, const std::string& from, const std::string& to) {
if(from.empty())
return;
size_t start_pos = 0;
while((start_pos = str.find(from, start_pos)) != std::string::npos) {
str.replace(start_pos, from.length(), to);
start_pos += to.length(); // In case 'to' contains 'from', like replacing 'x' with 'yx'
}
}
NTSTATUS CxbxConvertFilePath(
std::string RelativeXboxPath,
OUT std::wstring &RelativeHostPath,
@ -423,6 +433,9 @@ NTSTATUS CxbxConvertFilePath(
HostPath.append(1, '\\');
}
// Lastly, remove any '\\' sequences in the string (this should fix the problem with Azurik game saves)
replace_all( RelativePath, "\\\\", "\\" );
if (g_bPrintfOn) {
DbgPrintf("FILE: %s Corrected path...\n", aFileAPIName.c_str());
printf(" Org:\"%s\"\n", OriginalPath.c_str());

View File

@ -51,11 +51,11 @@ namespace xboxkrnl
#include "Emu.h" // For EmuWarning()
#include "EmuKrnl.h"
#include "EmuX86.h" // HalReadWritePciSpace needs this
#include "SMBus.h" // For g_SMBus
#include "EmuEEPROM.h" // For EEPROM
#include "SMCDevice.h" // For SMC_COMMAND_SCRATCH
#include "EmuShared.h"
#include "EmuFile.h" // For FindNtSymbolicLinkObjectByDriveLetter
#include "Common\EmuEEPROM.h" // For EEPROM
#include "devices\SMBus.h" // For g_SMBus
#include "devices\SMCDevice.h" // For SMC_COMMAND_SCRATCH
#include <algorithm> // for std::replace
#include <locale>
@ -70,6 +70,14 @@ namespace NtDll
static DWORD EmuSoftwareInterrupRequestRegister = 0;
HalSystemInterrupt HalSystemInterrupts[MAX_BUS_INTERRUPT_LEVEL + 1];
// variables used by the SMC to know a reset / shutdown is pending
uint8_t ResetOrShutdownCommandCode = 0;
uint32_t ResetOrShutdownDataValue = 0;
// global list of routines executed during a reboot
LIST_ENTRY_INITIALIZE_HEAD(ShutdownRoutineList);
// ******************************************************************
// * 0x0009 - HalReadSMCTrayState()
// ******************************************************************
@ -372,9 +380,46 @@ XBSYSAPI EXPORTNUM(47) xboxkrnl::VOID NTAPI xboxkrnl::HalRegisterShutdownNotific
LOG_FUNC_BEGIN
LOG_FUNC_ARG(ShutdownRegistration)
LOG_FUNC_ARG(Register)
LOG_FUNC_END;
LOG_FUNC_END;
LOG_UNIMPLEMENTED();
PLIST_ENTRY ListEntry;
KIRQL OldIrql;
OldIrql = KeRaiseIrqlToDpcLevel();
if (Register)
{
ListEntry = ShutdownRoutineList.Flink;
while (ListEntry != &ShutdownRoutineList)
{
if (ShutdownRegistration->Priority > LIST_ENTRY_ACCESS_RECORD(ListEntry, HAL_SHUTDOWN_REGISTRATION, ListEntry)->Priority)
{
LIST_ENTRY_INSERT_TAIL(ListEntry, &ShutdownRegistration->ListEntry)
break;
}
ListEntry = ListEntry->Flink;
}
if (ListEntry == &ShutdownRoutineList)
{
LIST_ENTRY_INSERT_TAIL(ListEntry, &ShutdownRegistration->ListEntry)
}
}
else
{
ListEntry = ShutdownRoutineList.Flink;
while (ListEntry != &ShutdownRoutineList)
{
if (ShutdownRegistration == LIST_ENTRY_ACCESS_RECORD(ListEntry, HAL_SHUTDOWN_REGISTRATION, ListEntry))
{
LIST_ENTRY_REMOVE(&ShutdownRegistration->ListEntry)
break;
}
ListEntry = ListEntry->Flink;
}
}
KfLowerIrql(OldIrql);
}
// ******************************************************************
@ -422,6 +467,35 @@ XBSYSAPI EXPORTNUM(49) xboxkrnl::VOID DECLSPEC_NORETURN NTAPI xboxkrnl::HalRetur
// Commented out because XLaunchNewImage is disabled!
// MmPersistContiguousMemory((PVOID)xboxkrnl::LaunchDataPage, sizeof(LAUNCH_DATA_PAGE), TRUE);
{
// ergo720: I tested this with Tenchu and Dead or Alive Ultimate, both of which register a single shutdown
// routine with HalRegisterShutdownNotification. The routines are correctly registered but when invoked they
// cause a crash. It's because these routines are registered by and act upon the Xbox hardware, most of it
// is not LLEd enough and so, until then, we don't try to execute the shutdown routines
#if 0
KIRQL OldIrql;
PLIST_ENTRY ListEntry;
PHAL_SHUTDOWN_REGISTRATION ShutdownRegistration;
while (true)
{
OldIrql = KeRaiseIrqlToDpcLevel();
ListEntry = LIST_ENTRY_REMOVE_AT_HEAD(&ShutdownRoutineList)
KfLowerIrql(OldIrql);
if (ListEntry == &ShutdownRoutineList)
break;
ShutdownRegistration = LIST_ENTRY_ACCESS_RECORD(ListEntry, HAL_SHUTDOWN_REGISTRATION, ListEntry);
ShutdownRegistration->NotificationRoutine(ShutdownRegistration);
}
#endif
}
std::string TitlePath = xboxkrnl::LaunchDataPage->Header.szLaunchPath;
char szWorkingDirectoy[MAX_PATH];
@ -468,8 +542,8 @@ XBSYSAPI EXPORTNUM(49) xboxkrnl::VOID DECLSPEC_NORETURN NTAPI xboxkrnl::HalRetur
// Relaunch Cxbx, to load another Xbe
{
bool bMultiXbe = true;
g_EmuShared->SetMultiXbeFlag(&bMultiXbe);
bool bQuickReboot = true;
g_EmuShared->SetQuickRebootFlag(&bQuickReboot);
char szArgsBuffer[4096];
@ -490,8 +564,25 @@ XBSYSAPI EXPORTNUM(49) xboxkrnl::VOID DECLSPEC_NORETURN NTAPI xboxkrnl::HalRetur
break;
case ReturnFirmwareFatal:
CxbxPopupMessage("Emulated Xbox hit a fatal error (might be called by XapiBootToDash from within dashboard)");
{
// NOTE: the error code is displayed by ExDisplayFatalError by other code paths so we need to change our corresponding
// paths if we want to emulate all the possible fatal errors
xboxkrnl::HalWriteSMBusValue(SMBUS_SMC_SLAVE_ADDRESS, SMC_COMMAND_SCRATCH, 0, SMC_SCRATCH_DISPLAY_FATAL_ERROR);
char szArgsBuffer[4096];
char szWorkingDirectoy[MAX_PATH];
bool bQuickReboot = true;
g_EmuShared->SetQuickRebootFlag(&bQuickReboot);
g_EmuShared->GetXbePath(szWorkingDirectoy);
snprintf(szArgsBuffer, 4096, "/load \"%s\" %u %d \"%s\"", szWorkingDirectoy, CxbxKrnl_hEmuParent, CxbxKrnl_DebugMode, CxbxKrnl_DebugFileName.c_str());
if ((int)ShellExecute(NULL, "open", szFilePath_CxbxReloaded_Exe, szArgsBuffer, szWorkingDirectoy, SW_SHOWDEFAULT) <= 32)
{
int BootFlags = 0;
g_EmuShared->SetBootFlags(&BootFlags); // clear all boot flags in the case of failure
CxbxKrnlCleanup("Could not reboot");
}
break;
}
case ReturnFirmwareAll:
LOG_UNIMPLEMENTED();
@ -684,9 +775,11 @@ XBSYSAPI EXPORTNUM(358) xboxkrnl::BOOLEAN NTAPI xboxkrnl::HalIsResetOrShutdownPe
{
LOG_FUNC();
LOG_UNIMPLEMENTED();
BOOLEAN ret = FALSE;
RETURN(FALSE);
if (ResetOrShutdownCommandCode != 0) { ret = TRUE; }
RETURN(ret);
}
// ******************************************************************
@ -698,8 +791,10 @@ XBSYSAPI EXPORTNUM(360) xboxkrnl::NTSTATUS NTAPI xboxkrnl::HalInitiateShutdown
)
{
LOG_FUNC();
LOG_UNIMPLEMENTED();
ResetOrShutdownCommandCode = SMC_COMMAND_RESET;
ResetOrShutdownDataValue = SMC_RESET_ASSERT_SHUTDOWN;
xboxkrnl::HalWriteSMBusValue(SMBUS_SMC_SLAVE_ADDRESS, ResetOrShutdownCommandCode, 0, ResetOrShutdownDataValue);
RETURN(S_OK);
}

View File

@ -271,6 +271,8 @@ DWORD ExecuteDpcQueue()
DWORD __stdcall EmuThreadDpcHandler(LPVOID lpVoid)
{
CxbxSetThreadName("DPC Handler");
DbgPrintf("KRNL: DPC thread is running\n");
// Make sure DPC callbacks run on the same core as the one that runs Xbox1 code :

View File

@ -114,6 +114,8 @@ static unsigned int WINAPI PCSTProxy
IN PVOID Parameter
)
{
CxbxSetThreadName("PsCreateSystemThread Proxy");
PCSTProxyParam *iPCSTProxyParam = (PCSTProxyParam*)Parameter;
PVOID StartRoutine = iPCSTProxyParam->StartRoutine;

View File

@ -107,6 +107,12 @@ class EmuShared : public Mutex
void GetFlagsLLE( int *flags) { Lock(); *flags = m_FlagsLLE; Unlock(); }
void SetFlagsLLE(const int *flags) { Lock(); m_FlagsLLE = *flags; Unlock(); }
// ******************************************************************
// * Boot flag Accessors
// ******************************************************************
void GetBootFlags(int *value) { Lock(); *value = m_BootFlags; Unlock(); }
void SetBootFlags(int *value) { Lock(); m_BootFlags = *value; Unlock(); }
// ******************************************************************
// * XInput Flag Accessors
// ******************************************************************
@ -132,10 +138,10 @@ class EmuShared : public Mutex
void SetCurrentFPS(float *value) { Lock(); m_FPS = *value; Unlock(); }
// ******************************************************************
// * MultiXbe flag Accessors
// * Kernel quick reboot flag Accessors
// ******************************************************************
void GetMultiXbeFlag(bool *value) { Lock(); *value = m_bMultiXbe; Unlock(); }
void SetMultiXbeFlag(bool *value) { Lock(); m_bMultiXbe = *value; Unlock(); }
void GetQuickRebootFlag(bool *value) { Lock(); *value = m_bKeQuickReboot; Unlock(); }
void SetQuickRebootFlag(bool *value) { Lock(); m_bKeQuickReboot = *value; Unlock(); }
// ******************************************************************
// * Debugging flag Accessors
@ -152,8 +158,6 @@ class EmuShared : public Mutex
// ******************************************************************
// * Xbox LED values Accessors
// ******************************************************************
void GetLedStatus(bool *value) { Lock(); *value = m_bLedHasChanged; Unlock(); }
void SetLedStatus(bool *value) { Lock(); m_bLedHasChanged = *value; Unlock(); }
void GetLedSequence(int *value)
{
Lock();
@ -188,15 +192,15 @@ class EmuShared : public Mutex
XBVideo m_XBVideo;
XBAudio m_XBAudio;
char m_XbePath[MAX_PATH];
int m_BootFlags;
int m_FlagsLLE;
int m_XInputEnabled;
int m_DisablePixelShaders;
float m_MSpF;
float m_FPS;
bool m_bMultiXbe;
bool m_bKeQuickReboot;
bool m_bDebugging;
PAddr m_LaunchDataPAddress;
bool m_bLedHasChanged;
int m_LedSequence[4];
};

View File

@ -47,14 +47,12 @@
#include "mnemonics.h"
#include "CxbxKrnl.h"
#include "Emu.h"
#include "Emu.h" // For EmuWarning
#include "EmuX86.h"
#include "EmuNV2A.h"
#include "EmuNVNet.h"
#include "HLEIntercept.h" // for bLLE_GPU
#include <assert.h>
#include "PCIBus.h"
#include "devices\PCIBus.h"
//
// Read & write handlers handlers for I/O
@ -177,11 +175,7 @@ uint32_t EmuX86_Read(xbaddr addr, int size)
uint32_t value;
if (addr >= NV2A_ADDR && addr < NV2A_ADDR + NV2A_SIZE) {
// Access NV2A regardless weither HLE is disabled or not (ignoring bLLE_GPU)
value = EmuNV2A_Read(addr - NV2A_ADDR, size);
// Note : EmuNV2A_Read does it's own logging
} else if (addr >= XBOX_FLASH_ROM_BASE) { // 0xFFF00000 - 0xFFFFFFF
if (addr >= XBOX_FLASH_ROM_BASE) { // 0xFFF00000 - 0xFFFFFFF
value = EmuFlash_Read32(addr - XBOX_FLASH_ROM_BASE); // TODO : Make flash access size-aware
} else {
// Pass the Read to the PCI Bus, this will handle devices with BARs set to MMIO addresses
@ -211,13 +205,6 @@ void EmuX86_Write(xbaddr addr, uint32_t value, int size)
return;
}
if (addr >= NV2A_ADDR && addr < NV2A_ADDR + NV2A_SIZE) {
// Access NV2A regardless weither HLE is disabled or not (ignoring bLLE_GPU)
EmuNV2A_Write(addr - NV2A_ADDR, value, size);
// Note : EmuNV2A_Write does it's own logging
return;
}
if (addr >= XBOX_FLASH_ROM_BASE) { // 0xFFF00000 - 0xFFFFFFF
EmuWarning("EmuX86_Write(0x%08X, 0x%08X) [FLASH_ROM]", addr, value);
return;

View File

@ -1,328 +0,0 @@
// ******************************************************************
// *
// * .,-::::: .,:: .::::::::. .,:: .:
// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;;
// * [[[ '[[,,[[' [[[__[[\. '[[,,[['
// * $$$ Y$$$P $$""""Y$$ Y$$$P
// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
// *
// * Cxbx->Win32->CxbxKrnl->HLEDataBase->D3D8.1.0.5659.inl
// *
// * 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) 2017 jarupxx
// *
// * All rights reserved
// *
// ******************************************************************
// ******************************************************************
// * D3DDevice_SetMaterial
// ******************************************************************
OOVPA_NO_XREF(D3DDevice_SetMaterial, 5659, 11)
{ 0x04, 0x08 },
{ 0x0C, 0x81 },
{ 0x0D, 0xC7 },
{ 0x0E, 0x00 },
{ 0x0F, 0x0F },
{ 0x10, 0x00 },
{ 0x16, 0x00 },
{ 0x1F, 0x81 },
{ 0x22, 0x90 },
{ 0x2C, 0x5E },
{ 0x2E, 0x04 },
OOVPA_END;
// ******************************************************************
// * D3DDevice_GetMaterial
// ******************************************************************
OOVPA_NO_XREF(D3DDevice_GetMaterial, 5659, 8)
{ 0x05, 0x56 },
{ 0x06, 0x57 },
{ 0x0A, 0x0C },
{ 0x0D, 0x00 },
{ 0x0E, 0x0F },
{ 0x12, 0x11 },
{ 0x16, 0xF3 },
{ 0x1A, 0xC2 },
OOVPA_END;
// ******************************************************************
// * D3DDevice_AddRef
// ******************************************************************
OOVPA_NO_XREF(D3DDevice_AddRef, 5659, 10)
// D3DDevice_AddRef+0x00 : mov eax, [addr]
{ 0x00, 0xA1 },
// D3DDevice_AddRef+0x05 : mov ecx, [eax+0x0938]
{ 0x05, 0x8B },
{ 0x06, 0x88 },
{ 0x07, 0x38 },
{ 0x08, 0x09 },
// D3DDevice_AddRef+0x0B : inc ecx
{ 0x0B, 0x41 },
// D3DDevice_AddRef+0x0C : mov [eax+0x0938], ecx
{ 0x0C, 0x89 },
{ 0x0D, 0x88 },
{ 0x0E, 0x38 },
{ 0x0F, 0x09 },
OOVPA_END;
// ******************************************************************
// * D3DDevice_SetBackMaterial
// ******************************************************************
OOVPA_NO_XREF(D3DDevice_SetBackMaterial, 5659, 11)
{ 0x04, 0x08 },
{ 0x0C, 0x81 },
{ 0x0D, 0xC7 },
{ 0x0E, 0x44 },
{ 0x0F, 0x0F },
{ 0x10, 0x00 },
{ 0x16, 0x00 },
{ 0x1F, 0x81 },
{ 0x22, 0x90 },
{ 0x2C, 0x5E },
{ 0x2E, 0x04 },
OOVPA_END;
// ******************************************************************
// * D3DDevice_GetBackMaterial
// ******************************************************************
OOVPA_NO_XREF(D3DDevice_GetBackMaterial, 5659, 8)
{ 0x05, 0x56 },
{ 0x06, 0x57 },
{ 0x0A, 0x0C },
{ 0x0D, 0x44 },
{ 0x0E, 0x0F },
{ 0x12, 0x11 },
{ 0x16, 0xF3 },
{ 0x1A, 0xC2 },
OOVPA_END;
// ******************************************************************
// * D3DDevice_SetVerticalBlankCallback
// ******************************************************************
OOVPA_XREF(D3DDevice_SetVerticalBlankCallback, 5659, 1+12,
XRefNoSaveIndex,
XRefOne)
XREF_ENTRY( 0x06, XREF_D3DDEVICE ), // Derived
// D3DDevice_SetVerticalBlankCallback+0x00 : mov eax, [esp+0x04]
{ 0x00, 0x8B },
{ 0x01, 0x44 },
{ 0x02, 0x24 },
{ 0x03, 0x04 },
// D3DDevice_SetVerticalBlankCallback+0x04 : mov ecx, [addr]
{ 0x04, 0x8B },
{ 0x05, 0x0D },
// D3DDevice_SetVerticalBlankCallback+0x0A : mov [ecx+0x1DB4], eax
{ 0x0A, 0x89 },
{ 0x0B, 0x81 },
{ 0x0C, 0xB8 }, // B4 vs B8
{ 0x0D, 0x1D },
// D3DDevice_SetVerticalBlankCallback+0x10 : retn 0x04
{ 0x10, 0xC2 },
{ 0x11, 0x04 },
OOVPA_END;
// ******************************************************************
// * D3DDevice_SetSwapCallback
// ******************************************************************
OOVPA_NO_XREF(D3DDevice_SetSwapCallback, 5659, 12)
// D3DDevice_SetSwapCallback+0x00 : mov eax, [esp+0x04]
{ 0x00, 0x8B },
{ 0x01, 0x44 },
{ 0x02, 0x24 },
{ 0x03, 0x04 },
// D3DDevice_SetSwapCallback+0x04 : mov ecx, [addr]
{ 0x04, 0x8B },
{ 0x05, 0x0D },
// D3DDevice_SetSwapCallback+0x0A : mov [ecx+0x1DB4], eax
{ 0x0A, 0x89 },
{ 0x0B, 0x81 },
{ 0x0C, 0xB4 }, // B4 vs B8
{ 0x0D, 0x1D },
// D3DDevice_SetSwapCallback+0x10 : retn 0x04
{ 0x10, 0xC2 },
{ 0x11, 0x04 },
OOVPA_END;
// ******************************************************************
// * D3DDevice_GetVertexShader
// ******************************************************************
OOVPA_NO_XREF(D3DDevice_GetVertexShader, 5659, 16)
{ 0x00, 0xA1 },
{ 0x05, 0x8B },
{ 0x06, 0x88 },
{ 0x07, 0x98 },
{ 0x08, 0x07 },
{ 0x09, 0x00 },
{ 0x0A, 0x00 },
{ 0x0B, 0x8B },
{ 0x0C, 0x54 },
{ 0x0D, 0x24 },
{ 0x0E, 0x04 },
{ 0x0F, 0x89 },
{ 0x10, 0x0A },
{ 0x11, 0xC2 },
{ 0x12, 0x04 },
{ 0x13, 0x00 },
OOVPA_END;
// ******************************************************************
// * D3DDevice_GetPixelShader
// ******************************************************************
OOVPA_NO_XREF(D3DDevice_GetPixelShader, 5659, 16)
{ 0x00, 0xA1 },
{ 0x05, 0x8B },
{ 0x06, 0x88 },
{ 0x07, 0x84 },
{ 0x08, 0x07 },
{ 0x09, 0x00 },
{ 0x0A, 0x00 },
{ 0x0B, 0x8B },
{ 0x0C, 0x54 },
{ 0x0D, 0x24 },
{ 0x0E, 0x04 },
{ 0x0F, 0x89 },
{ 0x10, 0x0A },
{ 0x11, 0xC2 },
{ 0x12, 0x04 },
{ 0x13, 0x00 },
OOVPA_END;
// ******************************************************************
// * D3DDevice_BlockUntilVerticalBlank
// ******************************************************************
OOVPA_NO_XREF(D3DDevice_BlockUntilVerticalBlank, 5659, 11)
// D3DDevice_BlockUntilVerticalBlank+0x05 : push 0; push 0; push 1
{ 0x05, 0x6A },
{ 0x06, 0x00 },
{ 0x07, 0x6A },
{ 0x08, 0x00 },
{ 0x09, 0x6A },
{ 0x0A, 0x01 },
// D3DDevice_BlockUntilVerticalBlank+0x17 : add eax, 0x1DBC
{ 0x17, 0x05 },
{ 0x18, 0xBC },
{ 0x19, 0x1D },
// D3DDevice_BlockUntilVerticalBlank+0x1D : call [KrnlImport]
{ 0x1D, 0xFF },
// D3DDevice_BlockUntilVerticalBlank+0x23 : retn
{ 0x23, 0xC3 },
OOVPA_END;
// ******************************************************************
// * D3DDevice_GetShaderConstantMode
// ******************************************************************
OOVPA_NO_XREF(D3DDevice_GetShaderConstantMode, 5659, 16)
{ 0x00, 0xA1 },
{ 0x05, 0x8B },
{ 0x06, 0x88 },
{ 0x07, 0x28 },
{ 0x08, 0x19 },
{ 0x09, 0x00 },
{ 0x0A, 0x00 },
{ 0x0B, 0x8B },
{ 0x0C, 0x54 },
{ 0x0D, 0x24 },
{ 0x0E, 0x04 },
{ 0x0F, 0x89 },
{ 0x10, 0x0A },
{ 0x11, 0xC2 },
{ 0x12, 0x04 },
{ 0x13, 0x00 },
OOVPA_END;
// ******************************************************************
// * D3DDevice_GetTexture, named with 2 suffix to match EMUPATCH(D3DDevice_GetTexture2)
// ******************************************************************
#ifndef WIP_LessVertexPatching
OOVPA_NO_XREF(D3DDevice_GetTexture2, 5659, 23) // Up to 5849
#else
OOVPA_XREF(D3DDevice_GetTexture2, 5659, 1+23, // Up to 5849
XRefNoSaveIndex,
XRefOne)
XREF_ENTRY( 0x0E, XREF_OFFSET_D3DDEVICE_M_TEXTURES ), // Derived
#endif
{ 0x00, 0x8B },
{ 0x01, 0x44 },
{ 0x02, 0x24 },
{ 0x03, 0x04 },
{ 0x04, 0x8B },
{ 0x05, 0x0D },
{ 0x0A, 0x56 },
{ 0x0B, 0x8D },
{ 0x0C, 0xB4 },
{ 0x0D, 0x81 },
{ 0x0E, 0x88 }, // GetTexture2 880F vs GetPalette2 980F
{ 0x0F, 0x0F },
{ 0x10, 0x00 },
{ 0x11, 0x00 },
{ 0x12, 0x8B },
{ 0x13, 0x06 },
{ 0x14, 0x85 },
{ 0x15, 0xC0 },
{ 0x16, 0x74 },
{ 0x18, 0x50 },
{ 0x19, 0xE8 },
{ 0x1E, 0x8B },
{ 0x1F, 0x06 },
// { 0x21, 0xC2 },
OOVPA_END;

View File

@ -56,3 +56,298 @@ OOVPA_XREF(D3D_RecordStateBlock, 5788, 10,
{ 0xD7, 0x0C },
{ 0xD8, 0x01 },
OOVPA_END;
// ******************************************************************
// * D3DDevice_SetMaterial
// ******************************************************************
OOVPA_NO_XREF(D3DDevice_SetMaterial, 5788, 11)
{ 0x04, 0x08 },
{ 0x0C, 0x81 },
{ 0x0D, 0xC7 },
{ 0x0E, 0x00 },
{ 0x0F, 0x0F },
{ 0x10, 0x00 },
{ 0x16, 0x00 },
{ 0x1F, 0x81 },
{ 0x22, 0x90 },
{ 0x2C, 0x5E },
{ 0x2E, 0x04 },
OOVPA_END;
// ******************************************************************
// * D3DDevice_GetMaterial
// ******************************************************************
OOVPA_NO_XREF(D3DDevice_GetMaterial, 5788, 8)
{ 0x05, 0x56 },
{ 0x06, 0x57 },
{ 0x0A, 0x0C },
{ 0x0D, 0x00 },
{ 0x0E, 0x0F },
{ 0x12, 0x11 },
{ 0x16, 0xF3 },
{ 0x1A, 0xC2 },
OOVPA_END;
// ******************************************************************
// * D3DDevice_AddRef
// ******************************************************************
OOVPA_NO_XREF(D3DDevice_AddRef, 5788, 10)
// D3DDevice_AddRef+0x00 : mov eax, [addr]
{ 0x00, 0xA1 },
// D3DDevice_AddRef+0x05 : mov ecx, [eax+0x0938]
{ 0x05, 0x8B },
{ 0x06, 0x88 },
{ 0x07, 0x38 },
{ 0x08, 0x09 },
// D3DDevice_AddRef+0x0B : inc ecx
{ 0x0B, 0x41 },
// D3DDevice_AddRef+0x0C : mov [eax+0x0938], ecx
{ 0x0C, 0x89 },
{ 0x0D, 0x88 },
{ 0x0E, 0x38 },
{ 0x0F, 0x09 },
OOVPA_END;
// ******************************************************************
// * D3DDevice_SetBackMaterial
// ******************************************************************
OOVPA_NO_XREF(D3DDevice_SetBackMaterial, 5788, 11)
{ 0x04, 0x08 },
{ 0x0C, 0x81 },
{ 0x0D, 0xC7 },
{ 0x0E, 0x44 },
{ 0x0F, 0x0F },
{ 0x10, 0x00 },
{ 0x16, 0x00 },
{ 0x1F, 0x81 },
{ 0x22, 0x90 },
{ 0x2C, 0x5E },
{ 0x2E, 0x04 },
OOVPA_END;
// ******************************************************************
// * D3DDevice_GetBackMaterial
// ******************************************************************
OOVPA_NO_XREF(D3DDevice_GetBackMaterial, 5788, 8)
{ 0x05, 0x56 },
{ 0x06, 0x57 },
{ 0x0A, 0x0C },
{ 0x0D, 0x44 },
{ 0x0E, 0x0F },
{ 0x12, 0x11 },
{ 0x16, 0xF3 },
{ 0x1A, 0xC2 },
OOVPA_END;
// ******************************************************************
// * D3DDevice_SetVerticalBlankCallback
// ******************************************************************
OOVPA_XREF(D3DDevice_SetVerticalBlankCallback, 5788, 1+12,
XRefNoSaveIndex,
XRefOne)
XREF_ENTRY( 0x06, XREF_D3DDEVICE ), // Derived
// D3DDevice_SetVerticalBlankCallback+0x00 : mov eax, [esp+0x04]
{ 0x00, 0x8B },
{ 0x01, 0x44 },
{ 0x02, 0x24 },
{ 0x03, 0x04 },
// D3DDevice_SetVerticalBlankCallback+0x04 : mov ecx, [addr]
{ 0x04, 0x8B },
{ 0x05, 0x0D },
// D3DDevice_SetVerticalBlankCallback+0x0A : mov [ecx+0x1DB4], eax
{ 0x0A, 0x89 },
{ 0x0B, 0x81 },
{ 0x0C, 0xB8 }, // B4 vs B8
{ 0x0D, 0x1D },
// D3DDevice_SetVerticalBlankCallback+0x10 : retn 0x04
{ 0x10, 0xC2 },
{ 0x11, 0x04 },
OOVPA_END;
// ******************************************************************
// * D3DDevice_SetSwapCallback
// ******************************************************************
OOVPA_NO_XREF(D3DDevice_SetSwapCallback, 5788, 12)
// D3DDevice_SetSwapCallback+0x00 : mov eax, [esp+0x04]
{ 0x00, 0x8B },
{ 0x01, 0x44 },
{ 0x02, 0x24 },
{ 0x03, 0x04 },
// D3DDevice_SetSwapCallback+0x04 : mov ecx, [addr]
{ 0x04, 0x8B },
{ 0x05, 0x0D },
// D3DDevice_SetSwapCallback+0x0A : mov [ecx+0x1DB4], eax
{ 0x0A, 0x89 },
{ 0x0B, 0x81 },
{ 0x0C, 0xB4 }, // B4 vs B8
{ 0x0D, 0x1D },
// D3DDevice_SetSwapCallback+0x10 : retn 0x04
{ 0x10, 0xC2 },
{ 0x11, 0x04 },
OOVPA_END;
// ******************************************************************
// * D3DDevice_GetVertexShader
// ******************************************************************
OOVPA_NO_XREF(D3DDevice_GetVertexShader, 5788, 16)
{ 0x00, 0xA1 },
{ 0x05, 0x8B },
{ 0x06, 0x88 },
{ 0x07, 0x98 },
{ 0x08, 0x07 },
{ 0x09, 0x00 },
{ 0x0A, 0x00 },
{ 0x0B, 0x8B },
{ 0x0C, 0x54 },
{ 0x0D, 0x24 },
{ 0x0E, 0x04 },
{ 0x0F, 0x89 },
{ 0x10, 0x0A },
{ 0x11, 0xC2 },
{ 0x12, 0x04 },
{ 0x13, 0x00 },
OOVPA_END;
// ******************************************************************
// * D3DDevice_GetPixelShader
// ******************************************************************
OOVPA_NO_XREF(D3DDevice_GetPixelShader, 5788, 16)
{ 0x00, 0xA1 },
{ 0x05, 0x8B },
{ 0x06, 0x88 },
{ 0x07, 0x84 },
{ 0x08, 0x07 },
{ 0x09, 0x00 },
{ 0x0A, 0x00 },
{ 0x0B, 0x8B },
{ 0x0C, 0x54 },
{ 0x0D, 0x24 },
{ 0x0E, 0x04 },
{ 0x0F, 0x89 },
{ 0x10, 0x0A },
{ 0x11, 0xC2 },
{ 0x12, 0x04 },
{ 0x13, 0x00 },
OOVPA_END;
// ******************************************************************
// * D3DDevice_BlockUntilVerticalBlank
// ******************************************************************
OOVPA_NO_XREF(D3DDevice_BlockUntilVerticalBlank, 5788, 11)
// D3DDevice_BlockUntilVerticalBlank+0x05 : push 0; push 0; push 1
{ 0x05, 0x6A },
{ 0x06, 0x00 },
{ 0x07, 0x6A },
{ 0x08, 0x00 },
{ 0x09, 0x6A },
{ 0x0A, 0x01 },
// D3DDevice_BlockUntilVerticalBlank+0x17 : add eax, 0x1DBC
{ 0x17, 0x05 },
{ 0x18, 0xBC },
{ 0x19, 0x1D },
// D3DDevice_BlockUntilVerticalBlank+0x1D : call [KrnlImport]
{ 0x1D, 0xFF },
// D3DDevice_BlockUntilVerticalBlank+0x23 : retn
{ 0x23, 0xC3 },
OOVPA_END;
// ******************************************************************
// * D3DDevice_GetShaderConstantMode
// ******************************************************************
OOVPA_NO_XREF(D3DDevice_GetShaderConstantMode, 5788, 16)
{ 0x00, 0xA1 },
{ 0x05, 0x8B },
{ 0x06, 0x88 },
{ 0x07, 0x28 },
{ 0x08, 0x19 },
{ 0x09, 0x00 },
{ 0x0A, 0x00 },
{ 0x0B, 0x8B },
{ 0x0C, 0x54 },
{ 0x0D, 0x24 },
{ 0x0E, 0x04 },
{ 0x0F, 0x89 },
{ 0x10, 0x0A },
{ 0x11, 0xC2 },
{ 0x12, 0x04 },
{ 0x13, 0x00 },
OOVPA_END;
// ******************************************************************
// * D3DDevice_GetTexture, named with 2 suffix to match EMUPATCH(D3DDevice_GetTexture2)
// ******************************************************************
#ifndef WIP_LessVertexPatching
OOVPA_NO_XREF(D3DDevice_GetTexture2, 5788, 23) // Up to 5849
#else
OOVPA_XREF(D3DDevice_GetTexture2, 5788, 1+23, // Up to 5849
XRefNoSaveIndex,
XRefOne)
XREF_ENTRY( 0x0E, XREF_OFFSET_D3DDEVICE_M_TEXTURES ), // Derived
#endif
{ 0x00, 0x8B },
{ 0x01, 0x44 },
{ 0x02, 0x24 },
{ 0x03, 0x04 },
{ 0x04, 0x8B },
{ 0x05, 0x0D },
{ 0x0A, 0x56 },
{ 0x0B, 0x8D },
{ 0x0C, 0xB4 },
{ 0x0D, 0x81 },
{ 0x0E, 0x88 }, // GetTexture2 880F vs GetPalette2 980F
{ 0x0F, 0x0F },
{ 0x10, 0x00 },
{ 0x11, 0x00 },
{ 0x12, 0x8B },
{ 0x13, 0x06 },
{ 0x14, 0x85 },
{ 0x15, 0xC0 },
{ 0x16, 0x74 },
{ 0x18, 0x50 },
{ 0x19, 0xE8 },
{ 0x1E, 0x8B },
{ 0x1F, 0x06 },
// { 0x21, 0xC2 },
OOVPA_END;

View File

@ -53,9 +53,11 @@
// * [5233] Evil Dead | 100% | have 208/230 library.
// * [5344] Gladius DEMO | 100% | have 202/229 library.
// * [5455] Dinosaur Hunting | 100% | have 207/229 library.
// * [5558] NHL HITZ Pro 2004 | 100% | have 218/229 library.
// * [5659] Midway Arcade Treasures Paperboy | 100% | have 212/229 library.
// * [5788] Digimon Battle Chronicle | 100% | have 210/229 library.
// * [5558] NHL HITZ Pro 2004 | 100% | have 218/230 library.
// * [5558] XIII | 100% | With Intergrated Hotfixes. have 209/230 library.
// * [5659] NFL Blitz Pro | 100% | have 208/230 library.
// * [5659] Midway Arcade Treasures Paperboy | 100% | With Intergrated Hotfixes. have 212/230 library.
// * [5788] Digimon Battle Chronicle | 100% | have 210/230 library.
// * [5849] Nickelodeon Tak 2 | 100% | have 210/229 library.
// TODO: Known D3D8 OOVPA issue list
@ -181,7 +183,6 @@
#include "D3D8.1.0.5344.inl"
#include "D3D8.1.0.5455.inl"
#include "D3D8.1.0.5558.inl"
#include "D3D8.1.0.5659.inl"
#include "D3D8.1.0.5788.inl"
#include "D3D8.1.0.5849.inl"
@ -198,7 +199,7 @@ OOVPATable D3D8_OOVPAV2[] = {
REGISTER_OOVPAS(D3DCubeTexture_GetCubeMapSurface, PATCH, 3911, 4627), // Called D3DCubeTexture_GetCubeMapSurface2 (from 4627's comment) NOTE: Use D3DCubeTexture_GetCubeMapSurface2 for 4627 and above
REGISTER_OOVPAS(D3DCubeTexture_GetCubeMapSurface2, PATCH, 4627),
REGISTER_OOVPAS(D3DCubeTexture_LockRect, PATCH, 3911), // Just calls Lock2DSurface (from 4134, 4432's comment)
REGISTER_OOVPAS(D3DDevice_AddRef, PATCH, 3911, 4039, 4134, 4242, 4627, 5028, 5344, 5558, 5659),
REGISTER_OOVPAS(D3DDevice_AddRef, PATCH, 3911, 4039, 4134, 4242, 4627, 5028, 5344, 5558, 5788),
REGISTER_OOVPAS(D3DDevice_ApplyStateBlock, PATCH, 3911, 4627),
REGISTER_OOVPAS(D3DDevice_Begin, PATCH, 3911, 4039),
REGISTER_OOVPAS(D3DDevice_BeginPush, PATCH, 4134, 4627, 5028),
@ -207,7 +208,7 @@ OOVPATable D3D8_OOVPAV2[] = {
REGISTER_OOVPAS(D3DDevice_BeginStateBlock, PATCH, 3911, 4134),
REGISTER_OOVPAS(D3DDevice_BeginVisibilityTest, PATCH, 3911, 4034),
REGISTER_OOVPAS(D3DDevice_BlockOnFence, PATCH, 3911),
REGISTER_OOVPAS(D3DDevice_BlockUntilVerticalBlank, PATCH, 3911, 4034, 4134, 4242, 4432, 4627, 5028, 5233, 5344, 5455, 5558, 5659),
REGISTER_OOVPAS(D3DDevice_BlockUntilVerticalBlank, PATCH, 3911, 4034, 4134, 4242, 4432, 4627, 5028, 5233, 5344, 5455, 5558, 5788),
REGISTER_OOVPAS(D3DDevice_CaptureStateBlock, PATCH, 3911, 4134),
REGISTER_OOVPAS(D3DDevice_Clear, PATCH, 3911, 4034),
REGISTER_OOVPAS(D3DDevice_CopyRects, PATCH, 3911, 4034, 4627, 5120),
@ -244,7 +245,7 @@ OOVPATable D3D8_OOVPAV2[] = {
REGISTER_OOVPAS(D3DDevice_FlushVertexCache, PATCH, 3911, 4134),
REGISTER_OOVPAS(D3DDevice_GetBackBuffer, PATCH, 3911, 4034, 4134, 4627), // Called D3DDevice_GetBackBuffer2 (from 4627's comment) NOTE: Use D3DDevice_GetBackBuffer2 for 4627 and above
REGISTER_OOVPAS(D3DDevice_GetBackBuffer2, PATCH, 4627), // 5233 (from 5344's comment)
REGISTER_OOVPAS(D3DDevice_GetBackMaterial, PATCH, 3911, 4134, 4627, 5344, 5558, 5659),
REGISTER_OOVPAS(D3DDevice_GetBackMaterial, PATCH, 3911, 4134, 4627, 5344, 5558, 5788),
REGISTER_OOVPAS(D3DDevice_GetCreationParameters, PATCH, 3911),
REGISTER_OOVPAS(D3DDevice_GetDepthStencilSurface, PATCH, 3911, 4627), // Called D3DDevice_GetDepthStencilSurface2 (from 4627's comment) NOTE: Use D3DDevice_GetDepthStencilSurface2 for 4627 and above
REGISTER_OOVPAS(D3DDevice_GetDepthStencilSurface2, PATCH, 4627),
@ -254,22 +255,22 @@ OOVPATable D3D8_OOVPAV2[] = {
REGISTER_OOVPAS(D3DDevice_GetGammaRamp, PATCH, 3911),
REGISTER_OOVPAS(D3DDevice_GetLight, PATCH, 3911),
REGISTER_OOVPAS(D3DDevice_GetLightEnable, PATCH, 3911, 5344),
REGISTER_OOVPAS(D3DDevice_GetMaterial, PATCH, 3911, 4134, 4627, 5344, 5558, 5659),
REGISTER_OOVPAS(D3DDevice_GetMaterial, PATCH, 3911, 4134, 4627, 5344, 5558, 5788),
REGISTER_OOVPAS(D3DDevice_GetModelView, PATCH, 3911, 4134),
REGISTER_OOVPAS(D3DDevice_GetOverlayUpdateStatus, PATCH, 3911),
REGISTER_OOVPAS(D3DDevice_GetPersistedSurface2, PATCH, 4928), // For only on Unreal Championship (from 4627's comment)
REGISTER_OOVPAS(D3DDevice_GetPixelShader, PATCH, 3911, 4039, 4134, 5028, 5558, 5659),
REGISTER_OOVPAS(D3DDevice_GetPixelShader, PATCH, 3911, 4039, 4134, 5028, 5558, 5788),
REGISTER_OOVPAS(D3DDevice_GetProjectionViewportMatrix, PATCH, 3911, 4134, 4627, 5344, 5558), // For 5455 (from 5558's comment)
REGISTER_OOVPAS(D3DDevice_GetPushBufferOffset, PATCH, 3911, 4627),//TODO 4831 (from 4627's comment)
REGISTER_OOVPAS(D3DDevice_GetRenderTarget, PATCH, 3911, 4627), // Called D3DDevice_GetRenderTarget2 (from 4627's comment) NOTE: Use D3DDevice_GetRenderTarget2 for 4627 and above
REGISTER_OOVPAS(D3DDevice_GetRenderTarget2, PATCH, 4627),
REGISTER_OOVPAS(D3DDevice_GetScissors, PATCH, 3911),
REGISTER_OOVPAS(D3DDevice_GetShaderConstantMode, PATCH, 3911, 4134, 4627, 5028, 5344, 5558, 5659),
REGISTER_OOVPAS(D3DDevice_GetShaderConstantMode, PATCH, 3911, 4134, 4627, 5028, 5344, 5558, 5788),
REGISTER_OOVPAS(D3DDevice_GetStreamSource2, PATCH, 4627),
REGISTER_OOVPAS(D3DDevice_GetTexture2, PATCH, 3911, 4134, 4627, 5344, 5558, 5659),
REGISTER_OOVPAS(D3DDevice_GetTexture2, PATCH, 3911, 4134, 4627, 5344, 5558, 5788),
REGISTER_OOVPAS(D3DDevice_GetTile, PATCH, 3911, 5455),
REGISTER_OOVPAS(D3DDevice_GetTransform, PATCH, 3911, 4034),
REGISTER_OOVPAS(D3DDevice_GetVertexShader, PATCH, 3911, 4039, 4134, 5028, 5558, 5659),
REGISTER_OOVPAS(D3DDevice_GetVertexShader, PATCH, 3911, 4039, 4134, 5028, 5558, 5788),
REGISTER_OOVPAS(D3DDevice_GetVertexShaderConstant, PATCH, 3911, 4039, 5028),
REGISTER_OOVPAS(D3DDevice_GetVertexShaderDeclaration, PATCH, 3911),
REGISTER_OOVPAS(D3DDevice_GetVertexShaderFunction, PATCH, 3911),
@ -301,13 +302,13 @@ OOVPATable D3D8_OOVPAV2[] = {
REGISTER_OOVPAS(D3DDevice_SelectVertexShader, PATCH, 3911, 4034, 5455),
REGISTER_OOVPAS(D3DDevice_SelectVertexShaderDirect, PATCH, 4361),
REGISTER_OOVPAS(D3DDevice_SetBackBufferScale, PATCH, 4134),
REGISTER_OOVPAS(D3DDevice_SetBackMaterial, PATCH, 3911, 4134, 4627, 5344, 5558, 5659),
REGISTER_OOVPAS(D3DDevice_SetBackMaterial, PATCH, 3911, 4134, 4627, 5344, 5558, 5788),
REGISTER_OOVPAS(D3DDevice_SetDepthClipPlanes, PATCH, 4432),
REGISTER_OOVPAS(D3DDevice_SetFlickerFilter, PATCH, 3911, 4034, 4134),
REGISTER_OOVPAS(D3DDevice_SetGammaRamp, PATCH, 3911, 4627),
REGISTER_OOVPAS(D3DDevice_SetIndices, UNPATCHED, 3911, 4034),
REGISTER_OOVPAS(D3DDevice_SetLight, PATCH, 3911, 5344),
REGISTER_OOVPAS(D3DDevice_SetMaterial, PATCH, 3911, 4034, 4134, 4627, 5344, 5558, 5659), // Was 4627 (from 5344's comment)
REGISTER_OOVPAS(D3DDevice_SetMaterial, PATCH, 3911, 4034, 4134, 4627, 5344, 5558, 5788), // Was 4627 (from 5344's comment)
REGISTER_OOVPAS(D3DDevice_SetModelView, PATCH, 3911, 4134, 4627),
REGISTER_OOVPAS(D3DDevice_SetPalette, PATCH, 3911, 4034),
REGISTER_OOVPAS(D3DDevice_SetPixelShader, PATCH, 3911, 4034, 4627),
@ -355,7 +356,7 @@ OOVPATable D3D8_OOVPAV2[] = {
REGISTER_OOVPAS(D3DDevice_SetStateVB, UNPATCHED, 3911, 4034, 4134),
REGISTER_OOVPAS(D3DDevice_SetStipple, PATCH, 4627),
REGISTER_OOVPAS(D3DDevice_SetStreamSource, PATCH, 3911, 4034),
REGISTER_OOVPAS(D3DDevice_SetSwapCallback, PATCH, 4134, 4242, 4432, 4627, 5028, 5233, 5344, 5455, 5558, 5659),
REGISTER_OOVPAS(D3DDevice_SetSwapCallback, PATCH, 4134, 4242, 4432, 4627, 5028, 5233, 5344, 5455, 5558, 5788),
REGISTER_OOVPAS(D3DDevice_SetTexture, PATCH, 3911, 4034, 4361, 4831),
REGISTER_OOVPAS(D3DDevice_SetTextureState_BorderColor, PATCH, 3911, 4034),
REGISTER_OOVPAS(D3DDevice_SetTextureState_BumpEnv, PATCH, 3911, 4034),
@ -378,7 +379,7 @@ OOVPATable D3D8_OOVPAV2[] = {
REGISTER_OOVPAS(D3DDevice_SetVertexShaderConstantNotInlineFast, PATCH, 4627),
REGISTER_OOVPAS(D3DDevice_SetVertexShaderInput, PATCH, 3911, 4134),
REGISTER_OOVPAS(D3DDevice_SetVertexShaderInputDirect, PATCH, 4361),
REGISTER_OOVPAS(D3DDevice_SetVerticalBlankCallback, PATCH, 3911, 4039, 4134, 4242, 4432, 4627, 5028, 5233, 5344, 5455, 5558, 5659), // Was 5233 (from 5344's comment)
REGISTER_OOVPAS(D3DDevice_SetVerticalBlankCallback, PATCH, 3911, 4039, 4134, 4242, 4432, 4627, 5028, 5233, 5344, 5455, 5558, 5788), // Was 5233 (from 5344's comment)
REGISTER_OOVPAS(D3DDevice_SetViewport, PATCH, 3911, 4034, 5344, 5455), // Was 5233 (from 5344's comment)
REGISTER_OOVPAS(D3DDevice_Swap, PATCH, 4034, 4531, 4627),
REGISTER_OOVPAS(D3DDevice_SwitchTexture, PATCH, 3911),

View File

@ -374,6 +374,7 @@ void EmuHLEIntercept(Xbe::Header *pXbeHeader)
for(uint32 v=0;v<dwLibraryVersions;v++)
{
uint16 BuildVersion = pLibraryVersion[v].wBuildVersion;
uint16 QFEVersion = pLibraryVersion[v].wFlags.QFEVersion;
if (preserveVersion < BuildVersion) {
preserveVersion = BuildVersion;
@ -403,6 +404,14 @@ void EmuHLEIntercept(Xbe::Header *pXbeHeader)
// Skip scanning for D3D8 symbols when LLE GPU is selected
if (bLLE_GPU)
continue;
// Functions in this library were updated by June 2003 XDK (5558) with Integrated Hotfixes,
// However August 2003 XDK (5659) still uses the old function.
// Please use updated 5788 instead.
if (BuildVersion >= 5558 && BuildVersion <=5659 && QFEVersion > 1) {
EmuWarning("D3D8 version 1.0.%d.%d Title Detected: This game uses an alias version 1.0.5788", BuildVersion, QFEVersion);
BuildVersion = 5788;
}
}
if (strcmp(LibraryName.c_str(), Lib_DSOUND) == 0)
{

View File

@ -48,9 +48,10 @@ namespace xboxkrnl
#include <xboxkrnl/xboxkrnl.h> // For PKINTERRUPT, etc.
};
#include "CxbxKrnl.h"
#include "Emu.h"
#include "EmuKrnl.h"
#include "CxbxKrnl\CxbxKrnl.h"
#include "CxbxKrnl\Emu.h"
#include "CxbxKrnl\EmuKrnl.h"
#include "EmuNVNet.h"
// NVNET Register Definitions

View File

@ -90,3 +90,5 @@ namespace LED {
constexpr Sequence FAST_GREEN_ORANGE = Phase0::Green | Phase1::Orange | Phase2::Green | Phase3::Orange;
}
extern void SetLEDSequence(LED::Sequence aLEDSequence);

View File

@ -41,7 +41,9 @@ namespace xboxkrnl
#include <xboxkrnl/xboxkrnl.h> // For xbox.h:AV_PACK_HDTV
};
#include "EmuShared.h"
#include "CxbxKrnl\CxbxKrnl.h"
#include "CxbxKrnl\EmuShared.h"
#include "SMCDevice.h" // For SMCDevice
#include "LED.h"
@ -50,27 +52,14 @@ void SetLEDSequence(LED::Sequence aLEDSequence)
// See http://xboxdevwiki.net/PIC#The_LED
DbgPrintf("SMC : SetLEDSequence : %u\n", (byte)aLEDSequence);
bool bLedHasChanged = true;
int LedSequence[4] = { XBOX_LED_COLOUR_OFF, XBOX_LED_COLOUR_OFF, XBOX_LED_COLOUR_OFF, XBOX_LED_COLOUR_OFF };
if (aLEDSequence == LED::GREEN) // Automatic solid green color
{
int LedSequence[4] = { XBOX_LED_COLOUR_GREEN, XBOX_LED_COLOUR_GREEN, XBOX_LED_COLOUR_GREEN, XBOX_LED_COLOUR_GREEN };
LedSequence[0] = ((aLEDSequence >> 6) & 2) | ((aLEDSequence >> 3) & 1);
LedSequence[1] = ((aLEDSequence >> 5) & 2) | ((aLEDSequence >> 2) & 1);
LedSequence[2] = ((aLEDSequence >> 4) & 2) | ((aLEDSequence >> 1) & 1);
LedSequence[3] = ((aLEDSequence >> 3) & 2) | ((aLEDSequence >> 0) & 1);
g_EmuShared->SetLedStatus(&bLedHasChanged);
g_EmuShared->SetLedSequence(LedSequence);
}
else // Draw the color represented by the sequence obtained
{
int LedSequence[4] = { XBOX_LED_COLOUR_OFF, XBOX_LED_COLOUR_OFF, XBOX_LED_COLOUR_OFF, XBOX_LED_COLOUR_OFF };
LedSequence[0] = ((aLEDSequence >> 3) & 1) | ((aLEDSequence >> 6) & 2);
LedSequence[1] = ((aLEDSequence >> 2) & 1) | ((aLEDSequence >> 5) & 2);
LedSequence[2] = ((aLEDSequence >> 1) & 1) | ((aLEDSequence >> 4) & 2);
LedSequence[3] = (aLEDSequence & 1) | ((aLEDSequence >> 3) & 2);
g_EmuShared->SetLedStatus(&bLedHasChanged);
g_EmuShared->SetLedSequence(LedSequence);
}
g_EmuShared->SetLedSequence(LedSequence);
}
/* SMCDevice */
@ -119,8 +108,8 @@ uint8_t SMCDevice::ReadByte(uint8_t command)
break;
//0x03 tray state
//#define SMC_COMMAND_AV_PACK 0x04 // A / V Pack state
//0x09 CPU temperature(°C)
//0x0A board temperature(°C)
//0x09 CPU temperature(°C)
//0x0A board temperature(°C)
case 0x0F: // reads scratch register written with 0x0E
return buffer[0x0E];
//0x10 current fan speed(0~50)
@ -164,7 +153,13 @@ void SMCDevice::WriteByte(uint8_t command, uint8_t value)
if (value == 0) // Note : MAME Xbox/Chihiro driver doesn't check for zero
m_PICVersionStringIndex = 0;
return;
//0x02 reset and power off control
case SMC_COMMAND_RESET: //0x02 reset and power off control
// See http://xboxdevwiki.net/PIC#Reset_and_Power_Off
switch (value) {
case SMC_RESET_ASSERT_RESET: return; // TODO
case SMC_RESET_ASSERT_POWERCYCLE: return; // TODO
case SMC_RESET_ASSERT_SHUTDOWN: CxbxKrnlShutDown(); return; // Power off, terminating the emulation
}
//0x05 power fan mode(0 = automatic; 1 = custom speed from reg 0x06)
//0x06 power fan speed(0..~50)
case SMC_COMMAND_LED_MODE: // 0x07 LED mode(0 = automatic; 1 = custom sequence from reg 0x08)
@ -175,9 +170,9 @@ void SMCDevice::WriteByte(uint8_t command, uint8_t value)
// Notes from https://github.com/ergo720/Cxbx-Reloaded/blob/LED/src/CxbxKrnl/EmuKrnlHal.cpp#L572
//
// HalWriteSMBusValue(0x20, 0x08, false, x) and then HalWriteSMBusValue(0x20, 0x07, false, y > 1)
// will cause the led to be solid green, with the next pair of
// will cause the led to be solid green, while the next pair of
// HalWriteSMBusValue with arbitrary y will cause the led to assume the color of the sequence x
// and afterwards this will repeat with whatever y; ntstatus are always 0
// and afterwards this will repeat with whatever y; ntstatus is always 0
//
// TODO : Implement the above, SMB_GLOBAL_STATUS should probably get the GS_PRERR_STS flag. But how?
return;
@ -191,7 +186,21 @@ void SMCDevice::WriteByte(uint8_t command, uint8_t value)
//0x0E another scratch register ? seems like an error code.
//0x19 reset on eject(0 = enable; 1 = disable)
//0x1A interrupt enable(write 0x01 to enable; can't disable once enabled)
//0x1B scratch register for the original kernel
case SMC_COMMAND_SCRATCH: //0x1B scratch register for the original kernel
// See http://xboxdevwiki.net/PIC#Scratch_register_values
switch (value) {
case SMC_SCRATCH_TRAY_EJECT_PENDING: return; // TODO
case SMC_SCRATCH_DISPLAY_FATAL_ERROR:
{
int FatalFlag;
g_EmuShared->GetBootFlags(&FatalFlag);
FatalFlag |= BOOT_FATAL_ERROR;
g_EmuShared->SetBootFlags(&FatalFlag);
break;
}
case SMC_SCRATCH_SHORT_ANIMATION: return; // TODO
case SMC_SCRATCH_DASHBOARD_BOOT: return; // TODO
}
//0x20 response to PIC challenge(written first)
//0x21 response to PIC challenge(written second)
}
@ -214,3 +223,4 @@ void SMCDevice::WriteBlock(uint8_t command, uint8_t* data, int length)
{
// TODO
}

View File

@ -74,7 +74,7 @@
//
//Command Description
//0x01 PIC version string counter reset
//0x02 reset and power off control
#define SMC_COMMAND_RESET 0x02 //0x02 reset and power off control
//0x05 power fan mode(0 = automatic; 1 = custom speed from reg 0x06)
//0x06 power fan speed(0..~50)
#define SMC_COMMAND_LED_MODE 0x07 // LED mode(0 = automatic; 1 = custom sequence from reg 0x08)
@ -83,10 +83,25 @@
//0x0E another scratch register ? seems like an error code.
//0x19 reset on eject(0 = enable; 1 = disable)
//0x1A interrupt enable(write 0x01 to enable; can't disable once enabled)
//0x1B scratch register for the original kernel
#define SMC_COMMAND_SCRATCH 0x1B //0x1B scratch register for the original kernel
//0x20 response to PIC challenge(written first)
//0x21 response to PIC challenge(written second)
//
// Register values for SMC_COMMAND_RESET
//
#define SMC_RESET_ASSERT_RESET 0x01
#define SMC_RESET_ASSERT_POWERCYCLE 0x40
#define SMC_RESET_ASSERT_SHUTDOWN 0x80
//
// Register values for SMC_COMMAND_SCRATCH
//
#define SMC_SCRATCH_TRAY_EJECT_PENDING 0x01
#define SMC_SCRATCH_DISPLAY_FATAL_ERROR 0x02
#define SMC_SCRATCH_SHORT_ANIMATION 0x04
#define SMC_SCRATCH_DASHBOARD_BOOT 0x08
typedef enum { // TODO : Move to it's own file
Revision1_0,
Revision1_1,
@ -112,6 +127,7 @@ public:
void WriteByte(uint8_t command, uint8_t value);
void WriteWord(uint8_t command, uint16_t value);
void WriteBlock(uint8_t command, uint8_t* data, int length);
private:
HardwareModel m_HardwareModel;
int m_PICVersionStringIndex = 0;

View File

@ -40,12 +40,14 @@
#include "SMCDevice.h" // For SMCDevice
#include "EEPROMDevice.h" // For EEPROMDevice
#include "EmuNVNet.h" // For NVNetDevice
#include "devices\video\nv2a.h" // For NV2ADevice
PCIBus* g_PCIBus;
SMBus* g_SMBus;
SMCDevice* g_SMC;
EEPROMDevice* g_EEPROM;
NVNetDevice* g_NVNet;
NV2ADevice* g_NV2A;
#define SMBUS_TV_ENCODER_ID_CONEXANT 0x8A // = Write; Read = 08B
#define SMBUS_TV_ENCODER_ID_FOCUS 0xD4 // = Write; Read = 0D5
@ -57,12 +59,14 @@ void InitXboxHardware()
g_SMC = new SMCDevice(Revision1_1); // TODO : Make configurable
g_EEPROM = new EEPROMDevice();
g_NVNet = new NVNetDevice();
g_NV2A = new NV2ADevice();
g_SMBus->ConnectDevice(SMBUS_SMC_SLAVE_ADDRESS, g_SMC);
g_SMBus->ConnectDevice(SMBUS_EEPROM_ADDRESS, g_EEPROM);
g_PCIBus->ConnectDevice(PCI_DEVID(0, PCI_DEVFN(1, 1)), g_SMBus);
g_PCIBus->ConnectDevice(PCI_DEVID(0, PCI_DEVFN(4, 0)), g_NVNet);
g_PCIBus->ConnectDevice(PCI_DEVID(1, PCI_DEVFN(0, 0)), g_NV2A);
// TODO : Handle other SMBUS Addresses, like PIC_ADDRESS, XCALIBUR_ADDRESS
// Resources : http://pablot.com/misc/fancontroller.cpp

File diff suppressed because it is too large Load Diff

View File

@ -45,7 +45,7 @@
#define NV_PBUS_ADDR 0x00001000
#define NV_PBUS_SIZE 0x001000
#define NV_PFIFO_ADDR 0x00002000
#define NV_PFIFO_SIZE 0x002000
#define _NV_PFIFO_SIZE 0x002000 // Underscore prefix to prevent clash with NV_PFIFO_SIZE
#define NV_PRMA_ADDR 0x00007000
#define NV_PRMA_SIZE 0x001000
#define NV_PVIDEO_ADDR 0x00008000
@ -61,7 +61,7 @@
#define NV_PRMFB_ADDR 0x000A0000
#define NV_PRMFB_SIZE 0x020000
#define NV_PRMVIO_ADDR 0x000C0000
#define NV_PRMVIO_SIZE 0x001000
#define NV_PRMVIO_SIZE 0x008000 // Was 0x001000
#define NV_PFB_ADDR 0x00100000
#define NV_PFB_SIZE 0x001000
#define NV_PSTRAPS_ADDR 0x00101000
@ -79,18 +79,65 @@
#define NV_PRAMIN_ADDR 0x00700000
#define NV_PRAMIN_SIZE 0x100000
#define NV_USER_ADDR 0x00800000
#define NV_USER_SIZE 0x800000
#define NV_USER_SIZE 0x400000
#define NV_UREMAP_ADDR 0x00C00000 // Looks like a mapping of NV_USER_ADDR
#define NV_UREMAP_SIZE 0x400000
typedef volatile DWORD *PPUSH;
typedef struct {
DWORD Ignored[0x10];
DWORD* Put; // On Xbox1, this field is only written to by the CPU (the GPU uses this as a trigger to start executing from the given address)
DWORD* Get; // On Xbox1, this field is only read from by the CPU (the GPU reflects in here where it is/stopped executing)
DWORD Reference; // TODO : xbaddr / void* / DWORD ?
PPUSH Put; // On Xbox1, this field is only written to by the CPU (the GPU uses this as a trigger to start executing from the given address)
PPUSH Get; // On Xbox1, this field is only read from by the CPU (the GPU reflects in here where it is/stopped executing)
PPUSH Reference; // TODO : xbaddr / void* / DWORD ?
DWORD Ignored2[0x7ED];
} Nv2AControlDma;
uint32_t EmuNV2A_Read(xbaddr addr, int size);
void EmuNV2A_Write(xbaddr addr, uint32_t value, int size);
#define PUSH_TYPE_MASK 0x00000002 // 2 bits
#define PUSH_TYPE_SHIFT 0
#define PUSH_TYPE_METHOD 0 // method
#define PUSH_TYPE_JMP_FAR 1 // jump far
#define PUSH_TYPE_CALL_FAR 2 // call far
#define PUSH_TYPE_METHOD_UNUSED 3 // method (unused)
#define PUSH_METHOD_MASK 0x00001FFC // 12 bits
#define PUSH_METHOD_SHIFT 0 // Dxbx note : Not 2, because methods are actually DWORD offsets (and thus defined with increments of 4)
#define PUSH_SUBCH_MASK 0x0000E000 // 3 bits
#define PUSH_SUBCH_SHIFT 13
#define PUSH_COUNT_MASK 0x1FFC0000 // 11 bits
#define PUSH_COUNT_SHIFT 18
#define PUSH_INSTR_MASK 0xE0000000 // 3 bits
#define PUSH_INSTR_SHIFT 29
#define PUSH_INSTR_IMM_INCR 0 // immediate, increment
#define PUSH_INSTR_JMP_NEAR 1 // near jump
#define PUSH_INSTR_IMM_NOINC 2 // immediate, no-increment
#define PUSH_ADDR_FAR_MASK 0xFFFFFFFC // 30 bits
#define PUSH_ADDR_FAR_SHIFT 0
#define PUSH_ADDR_NEAR_MASK 0x1FFFFFFC // 27 bits
#define PUSH_ADDR_NEAR_SHIFT 0 // Cxbx note : Not 2, because methods are actually DWORD offsets (and thus defined with increments of 4)
#define PUSH_TYPE(dwPushCommand) ((dwPushCommand & PUSH_TYPE_MASK) >> PUSH_TYPE_SHIFT)
#define PUSH_METHOD(dwPushCommand) ((dwPushCommand & PUSH_METHOD_MASK) >> PUSH_METHOD_SHIFT)
#define PUSH_SUBCH(dwPushCommand) ((dwPushCommand & PUSH_SUBCH_MASK) >> PUSH_SUBCH_SHIFT)
#define PUSH_COUNT(dwPushCommand) ((dwPushCommand & PUSH_COUNT_MASK) >> PUSH_COUNT_SHIFT)
#define PUSH_INSTR(dwPushCommand) ((dwPushCommand & PUSH_INSTR_MASK) >> PUSH_INSTR_SHIFT)
#define PUSH_ADDR_FAR(dwPushCommand) ((dwPushCommand & PUSH_ADDR_FAR_MASK) >> PUSH_ADDR_FAR_SHIFT)
#define PUSH_ADDR_NEAR(dwPushCommand) ((dwPushCommand & PUSH_ADDR_NEAR_MASK) >> PUSH_ADDR_NEAR_SHIFT)
#define PUSH_METHOD_MAX ((PUSH_METHOD_MASK | 3) >> PUSH_METHOD_SHIFT) // = 8191
#define PUSH_SUBCH_MAX (PUSH_SUBCH_MASK >> PUSH_SUBCH_SHIFT) // = 7
#define PUSH_COUNT_MAX (PUSH_COUNT_MASK >> PUSH_COUNT_SHIFT) // = 2047
// Decode push buffer conmmand (inverse of D3DPUSH_ENCODE)
inline void D3DPUSH_DECODE(const DWORD dwPushCommand, DWORD &dwMethod, DWORD &dwSubCh, DWORD &dwCount)
{
dwMethod = PUSH_METHOD(dwPushCommand);
dwSubCh = PUSH_SUBCH(dwPushCommand);
dwCount = PUSH_COUNT(dwPushCommand);
}
void EmuNV2A_Init();
void InitOpenGLContext();

130
src/devices/video/nv2a.cpp Normal file
View File

@ -0,0 +1,130 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
// ******************************************************************
// *
// * .,-::::: .,:: .::::::::. .,:: .:
// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;;
// * [[[ '[[,,[[' [[[__[[\. '[[,,[['
// * $$$ Y$$$P $$""""Y$$ Y$$$P
// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
// *
// * src->devices->video->nv2a.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) 2017-2018 Luke Usher <luke.usher@outlook.com>
// * (c) 2018 Patrick van Logchem <pvanlogchem@gmail.com>
// *
// * All rights reserved
// *
// ******************************************************************
#define _XBOXKRNL_DEFEXTRN_
#define LOG_PREFIX "NV2A"
#include "CxbxKrnl\CxbxKrnl.h" // For XBOX_MEMORY_SIZE, DWORD, etc
#include "EmuNV2A.h" // For now, use EmuNV2A
#include "nv2a.h"
/* NV2ADevice */
// PCI Device functions
void NV2ADevice::Init()
{
PCIBarRegister r;
// Register Memory bar :
r.Raw.type = PCI_BAR_TYPE_MEMORY;
r.Memory.address = NV2A_ADDR >> 4;
RegisterBAR(0, NV2A_SIZE, r.value);
// Register physical memory on bar 1
r.Memory.address = 0;
RegisterBAR(1, XBOX_MEMORY_SIZE, r.value); // TODO : Read g_PhysicalMemory->Size
/* LukeUsher commented at https://github.com/Cxbx-Reloaded/Cxbx-Reloaded/pull/882#discussion_r162871029
This is not right: I should have done a better review ;)
The starting address here is the physical address in the Xbox memory the VRAM should be placed at,
and should point to the TILED memory region ((0xF0000000 >> 4))
This maps VRAM address 0 to 0xF0000000. (this is what our TILED memory is: VRAM accessed via the GPU device)
*/
m_DeviceId = 0x02A5;
m_VendorId = PCI_VENDOR_ID_NVIDIA;
// For now, forward to EmuNv2A
EmuNV2A_Init();
}
void NV2ADevice::Reset()
{
}
uint32_t NV2ADevice::IORead(int barIndex, uint32_t port, unsigned size)
{
return 0;
}
void NV2ADevice::IOWrite(int barIndex, uint32_t port, uint32_t value, unsigned size)
{
}
uint32_t NV2ADevice::MMIORead(int barIndex, uint32_t addr, unsigned size)
{
switch (barIndex) {
case 0:
uint32_t value;
// For now, forward to EmuNV2A
{
// Access NV2A regardless weither HLE is disabled or not (ignoring bLLE_GPU)
value = EmuNV2A_Read(addr, size);
// Note : EmuNV2A_Read does it's own logging
}
// TODO : call block handler
return value;
case 1:
return 0; // TODO : access physical memory
}
// TODO : Log unexpected bar access
return 0;
}
void NV2ADevice::MMIOWrite(int barIndex, uint32_t addr, uint32_t value, unsigned size)
{
switch (barIndex) {
case 0:
// For now, forward to EmuNV2A
{
// Access NV2A regardless weither HLE is disabled or not (ignoring bLLE_GPU)
EmuNV2A_Write(addr, value, size);
// Note : EmuNV2A_Write does it's own logging
}
// TODO : call block handler
return;
case 1:
// TODO : access physical memory
return;
}
// TODO : Log unexpected bar access
}

54
src/devices/video/nv2a.h Normal file
View File

@ -0,0 +1,54 @@
// ******************************************************************
// *
// * .,-::::: .,:: .::::::::. .,:: .:
// * ,;;;'````' `;;;, .,;; ;;;'';;' `;;;, .,;;
// * [[[ '[[,,[[' [[[__[[\. '[[,,[['
// * $$$ Y$$$P $$""""Y$$ Y$$$P
// * `88bo,__,o, oP"``"Yo, _88o,,od8P oP"``"Yo,
// * "YUMMMMMP",m" "Mm,""YUMMMP" ,m" "Mm,
// *
// * src->devices->video->nv2a.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) 2017-2018 Luke Usher <luke.usher@outlook.com>
// * (c) 2018 Patrick van Logchem <pvanlogchem@gmail.com>
// *
// * All rights reserved
// *
// ******************************************************************
#pragma once
#include "devices\PCIDevice.h" // For PCIDevice
#define NV2A_ADDR 0xFD000000
#define NV2A_SIZE 0x01000000
class NV2ADevice : public PCIDevice {
public:
// PCI Device functions
void Init();
void Reset();
uint32_t IORead(int barIndex, uint32_t port, unsigned size);
void IOWrite(int barIndex, uint32_t port, uint32_t value, unsigned size);
uint32_t MMIORead(int barIndex, uint32_t addr, unsigned size);
void MMIOWrite(int barIndex, uint32_t addr, uint32_t value, unsigned size);
};
extern NV2ADevice* g_NV2A;

View File

@ -1,3 +1,4 @@
// Source : https://github.com/espes/xqemu/blob/xbox/hw/xbox/nv2a_int.h
/*
* QEMU Geforce NV2A internal definitions
*
@ -18,12 +19,38 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#define NV_NUM_BLOCKS 21
#define NV_PMC 0 /* card master control */
#define NV_PBUS 1 /* bus control */
#define NV_PFIFO 2 /* MMIO and DMA FIFO submission to PGRAPH and VPE */
#define NV_PFIFO_CACHE 3
#define NV_PRMA 4 /* access to BAR0/BAR1 from real mode */
#define NV_PVIDEO 5 /* video overlay */
#define NV_PTIMER 6 /* time measurement and time-based alarms */
#define NV_PCOUNTER 7 /* performance monitoring counters */
#define NV_PVPE 8 /* MPEG2 decoding engine */
#define NV_PTV 9 /* TV encoder */
#define NV_PRMFB 10 /* aliases VGA memory window */
#define NV_PRMVIO 11 /* aliases VGA sequencer and graphics controller registers */
#define NV_PFB 12 /* memory interface */
#define NV_PSTRAPS 13 /* straps readout / override */
#define NV_PGRAPH 14 /* accelerated 2d/3d drawing engine */
#define NV_PCRTC 15 /* more CRTC controls */
#define NV_PRMCIO 16 /* aliases VGA CRTC and attribute controller registers */
#define NV_PRAMDAC 17 /* RAMDAC, cursor, and PLL control */
#define NV_PRMDIO 18 /* aliases VGA palette registers */
#define NV_PRAMIN 19 /* RAMIN access */
#define NV_USER 20 /* PFIFO MMIO and DMA submission area */
#define NV_PMC_BOOT_0 0x00000000
#define NV_PMC_BOOT_1 0x00000004
#define NV_PMC_INTR_0 0x00000100
# define NV_PMC_INTR_0_PFIFO (1 << 8)
# define NV_PMC_INTR_0_PGRAPH (1 << 12)
# define NV_PMC_INTR_0_PVIDEO (1 << 16)
# define NV_PMC_INTR_0_PTIMER (1 << 20)
# define NV_PMC_INTR_0_PCRTC (1 << 24)
# define NV_PMC_INTR_0_PCRTC2 (1 << 25)
# define NV_PMC_INTR_0_PBUS (1 << 28)
# define NV_PMC_INTR_0_SOFTWARE (1 << 31)
#define NV_PMC_INTR_EN_0 0x00000140
@ -32,8 +59,16 @@
#define NV_PMC_ENABLE 0x00000200
# define NV_PMC_ENABLE_PFIFO (1 << 8)
# define NV_PMC_ENABLE_PGRAPH (1 << 12)
# define NV_PMC_ENABLE_PFB (1 << 20)
# define NV_PMC_ENABLE_PCRTC (1 << 24)
# define NV_PMC_ENABLE_PCRTC2 (1 << 25)
# define NV_PMC_ENABLE_PVIDEO (1 << 28)
#define NV_PBUS_FBIO_RAM 0x00000218
# define NV_PBUS_FBIO_RAM_TYPE 0x00000100
# define NV_PBUS_FBIO_RAM_TYPE_DDR (0 << 8)
# define NV_PBUS_FBIO_RAM_TYPE_SDR (1 << 8)
/* These map approximately to the pci registers */
#define NV_PBUS_PCI_NV_0 0x00000800
# define NV_PBUS_PCI_NV_0_VENDOR_ID 0x0000FFFF
@ -65,6 +100,9 @@
#define NV_PBUS_PCI_NV_26 0x00000868
#define NV_PFIFO_DELAY_0 0x00000040
#define NV_PFIFO_DMA_TIMESLICE 0x00000044
#define NV_PFIFO_TIMESLICE 0x0000004C
#define NV_PFIFO_INTR_0 0x00000100
# define NV_PFIFO_INTR_0_CACHE_ERROR (1 << 0)
# define NV_PFIFO_INTR_0_RUNOUT (1 << 4)
@ -82,21 +120,37 @@
# define NV_PFIFO_INTR_EN_0_SEMAPHORE (1 << 20)
# define NV_PFIFO_INTR_EN_0_ACQUIRE_TIMEOUT (1 << 24)
#define NV_PFIFO_RAMHT 0x00000210
# define NV_PFIFO_RAMHT_BASE_ADDRESS 0x000001F0
# define NV_PFIFO_RAMHT_SIZE 0x00030000
//# define NV_PFIFO_RAMHT_BASE_ADDRESS 0x000001F0
# define NV_PFIFO_RAMHT_BASE_ADDRESS_MASK 0x000001F0
# define NV_PFIFO_RAMHT_BASE_ADDRESS_SHIFT 4
# define NV_PFIFO_RAMHT_BASE_ADDRESS_MOVE 12
//# define NV_PFIFO_RAMHT_SIZE 0x00030000
# define NV_PFIFO_RAMHT_SIZE_MASK 0x00030000
# define NV_PFIFO_RAMHT_SIZE_SHIFT 16
# define NV_PFIFO_RAMHT_SIZE_4K 0
# define NV_PFIFO_RAMHT_SIZE_8K 1
# define NV_PFIFO_RAMHT_SIZE_16K 2
# define NV_PFIFO_RAMHT_SIZE_32K 3
# define NV_PFIFO_RAMHT_SEARCH 0x03000000
//# define NV_PFIFO_RAMHT_SEARCH 0x03000000
# define NV_PFIFO_RAMHT_SEARCH_MASK 0x03000000
# define NV_PFIFO_RAMHT_SEARCH_SHIFT 24
# define NV_PFIFO_RAMHT_SEARCH_16 0
# define NV_PFIFO_RAMHT_SEARCH_32 1
# define NV_PFIFO_RAMHT_SEARCH_64 2
# define NV_PFIFO_RAMHT_SEARCH_128 3
#define NV_PFIFO_RAMFC 0x00000214
# define NV_PFIFO_RAMFC_BASE_ADDRESS1 0x000001FC
# define NV_PFIFO_RAMFC_SIZE 0x00010000
# define NV_PFIFO_RAMFC_BASE_ADDRESS2 0x00FE0000
//# define NV_PFIFO_RAMFC_BASE_ADDRESS1 0x000001FC
# define NV_PFIFO_RAMFC_BASE_ADDRESS1_MASK 0x000001FC
# define NV_PFIFO_RAMFC_BASE_ADDRESS1_SHIFT 2
# define NV_PFIFO_RAMFC_BASE_ADDRESS1_MOVE 10
//# define NV_PFIFO_RAMFC_SIZE 0x00010000
# define NV_PFIFO_RAMFC_SIZE_MASK 0x00010000
# define NV_PFIFO_RAMFC_SIZE_1K 0x00000000
# define NV_PFIFO_RAMFC_SIZE_2K 0x00010000
//# define NV_PFIFO_RAMFC_BASE_ADDRESS2 0x00FE0000
# define NV_PFIFO_RAMFC_BASE_ADDRESS2_MASK 0x00FE0000
# define NV_PFIFO_RAMFC_BASE_ADDRESS2_SHIFT 17
# define NV_PFIFO_RAMFC_BASE_ADDRESS2_MOVE 10
#define NV_PFIFO_RAMRO 0x00000218
# define NV_PFIFO_RAMRO_BASE_ADDRESS 0x000001FE
# define NV_PFIFO_RAMRO_SIZE 0x00010000
@ -104,13 +158,21 @@
# define NV_PFIFO_RUNOUT_STATUS_RANOUT (1 << 0)
# define NV_PFIFO_RUNOUT_STATUS_LOW_MARK (1 << 4)
# define NV_PFIFO_RUNOUT_STATUS_HIGH_MARK (1 << 8)
#define NV_PFIFO_RUNOUT_PUT_ADDRESS 0x00000410
#define NV_PFIFO_RUNOUT_GET_ADDRESS 0x00000420
#define NV_PFIFO_CACHES 0x00000500
#define NV_PFIFO_MODE 0x00000504
#define NV_PFIFO_DMA 0x00000508
#define NV_PFIFO_SIZE 0x0000050C
#define NV_PFIFO_CACHE0_PUSH0 0x00001000
#define NV_PFIFO_CACHE0_PULL0 0x00001050
#define NV_PFIFO_CACHE0_HASH 0x00001058
#define NV_PFIFO_CACHE1_PUSH0 0x00001200
# define NV_PFIFO_CACHE1_PUSH0_ACCESS (1 << 0)
#define NV_PFIFO_CACHE1_PUSH1 0x00001204
# define NV_PFIFO_CACHE1_PUSH1_CHID 0x0000001F
# define NV_PFIFO_CACHE1_PUSH1_MODE 0x00000100
#define NV_PFIFO_CACHE1_PUT 0x00001210
#define NV_PFIFO_CACHE1_STATUS 0x00001214
# define NV_PFIFO_CACHE1_STATUS_LOW_MARK (1 << 4)
# define NV_PFIFO_CACHE1_STATUS_HIGH_MARK (1 << 8)
@ -137,14 +199,26 @@
# define NV_PFIFO_CACHE1_DMA_STATE_ERROR_RESERVED_CMD 4
# define NV_PFIFO_CACHE1_DMA_STATE_ERROR_PROTECTION 6
#define NV_PFIFO_CACHE1_DMA_INSTANCE 0x0000122C
# define NV_PFIFO_CACHE1_DMA_INSTANCE_ADDRESS 0x0000FFFF
//# define NV_PFIFO_CACHE1_DMA_INSTANCE_ADDRESS 0x0000FFFF
# define NV_PFIFO_CACHE1_DMA_INSTANCE_ADDRESS_MASK 0x0000FFFF
# define NV_PFIFO_CACHE1_DMA_INSTANCE_ADDRESS_SHIFT 0
# define NV_PFIFO_CACHE1_DMA_INSTANCE_ADDRESS_MOVE 4
#define NV_PFIFO_CACHE1_DMA_CTL 0x00001230
#define NV_PFIFO_CACHE1_DMA_PUT 0x00001240
#define NV_PFIFO_CACHE1_DMA_GET 0x00001244
#define NV_PFIFO_CACHE1_REF 0x00001248
#define NV_PFIFO_CACHE1_DMA_SUBROUTINE 0x0000124C
# define NV_PFIFO_CACHE1_DMA_SUBROUTINE_RETURN_OFFSET 0x1FFFFFFC
# define NV_PFIFO_CACHE1_DMA_SUBROUTINE_STATE (1 << 0)
#define NV_PFIFO_CACHE1_PULL0 0x00001250
# define NV_PFIFO_CACHE1_PULL0_ACCESS (1 << 0)
#define NV_PFIFO_CACHE1_PULL1 0x00001254
#define NV_PFIFO_CACHE1_HASH 0x00001258
#define NV_PFIFO_CACHE1_ACQUIRE_0 0x00001260
#define NV_PFIFO_CACHE1_ACQUIRE_1 0x00001264
#define NV_PFIFO_CACHE1_ACQUIRE_2 0x00001268
#define NV_PFIFO_CACHE1_SEMAPHORE 0x0000126C
#define NV_PFIFO_CACHE1_GET 0x00001270
#define NV_PFIFO_CACHE1_ENGINE 0x00001280
#define NV_PFIFO_CACHE1_DMA_DCOUNT 0x000012A0
# define NV_PFIFO_CACHE1_DMA_DCOUNT_VALUE 0x00001FFC
@ -154,6 +228,13 @@
#define NV_PFIFO_CACHE1_DMA_DATA_SHADOW 0x000012AC
#define NV_PGRAPH_DEBUG_0 0x00000080
#define NV_PGRAPH_DEBUG_1 0x00000084
#define NV_PGRAPH_DEBUG_3 0x0000008C
#define NV_PGRAPH_DEBUG_4 0x00000090
#define NV_PGRAPH_DEBUG_5 0x00000094
#define NV_PGRAPH_DEBUG_8 0x00000098
#define NV_PGRAPH_DEBUG_9 0x0000009C
#define NV_PGRAPH_INTR 0x00000100
# define NV_PGRAPH_INTR_NOTIFY (1 << 0)
# define NV_PGRAPH_INTR_MISSING_HW (1 << 4)
@ -212,6 +293,10 @@
# define NV_PGRAPH_CTX_SWITCH1_CONTEXT_BETA1 (1 << 29)
# define NV_PGRAPH_CTX_SWITCH1_CONTEXT_BETA4 (1 << 30)
# define NV_PGRAPH_CTX_SWITCH1_VOLATILE_RESET (1 << 31)
#define NV_PGRAPH_CTX_SWITCH2 0x00000150
#define NV_PGRAPH_CTX_SWITCH3 0x00000154
#define NV_PGRAPH_CTX_SWITCH4 0x00000158
#define NV_PGRAPH_STATUS 0x00000700
#define NV_PGRAPH_TRAPPED_ADDR 0x00000704
# define NV_PGRAPH_TRAPPED_ADDR_MTHD 0x00001FFF
# define NV_PGRAPH_TRAPPED_ADDR_SUBCH 0x00070000
@ -227,6 +312,9 @@
# define NV_PGRAPH_INCREMENT_READ_3D (1 << 1)
#define NV_PGRAPH_FIFO 0x00000720
# define NV_PGRAPH_FIFO_ACCESS (1 << 0)
#define NV_PGRAPH_RDI_INDEX 0x00000750
#define NV_PGRAPH_RDI_DATA 0x00000754
#define NV_PGRAPH_FFINTFC_ST2 0x00000764
#define NV_PGRAPH_CHANNEL_CTX_TABLE 0x00000780
# define NV_PGRAPH_CHANNEL_CTX_TABLE_INST 0x0000FFFF
#define NV_PGRAPH_CHANNEL_CTX_POINTER 0x00000784
@ -234,6 +322,18 @@
#define NV_PGRAPH_CHANNEL_CTX_TRIGGER 0x00000788
# define NV_PGRAPH_CHANNEL_CTX_TRIGGER_READ_IN (1 << 0)
# define NV_PGRAPH_CHANNEL_CTX_TRIGGER_WRITE_OUT (1 << 1)
#define NV_PGRAPH_DEBUG_2 0x00000880
#define NV_PGRAPH_TTILE(i) 0x00000900 + (i * 0x10)
#define NV_PGRAPH_TLIMIT(i) 0x00000904 + (i * 0x10)
#define NV_PGRAPH_TSIZE(i) 0x00000908 + (i * 0x10)
#define NV_PGRAPH_TSTATUS(i) 0x0000090C + (i * 0x10)
#define NV_PGRAPH_ZCOMP(i) 0x00000980 + (i * 4)
#define NV_PGRAPH_ZCOMP_OFFSET 0x000009A0
#define NV_PGRAPH_FBCFG0 0x000009A4
#define NV_PGRAPH_FBCFG1 0x000009A8
#define NV_PGRAPH_DEBUG_6 0x00000B80
#define NV_PGRAPH_DEBUG_7 0x00000B84
#define NV_PGRAPH_DEBUG_10 0x00000B88
#define NV_PGRAPH_CSV0_D 0x00000FB4
# define NV_PGRAPH_CSV0_D_LIGHTS 0x0000FFFF
# define NV_PGRAPH_CSV0_D_LIGHT0 0x00000003
@ -544,6 +644,8 @@
#define NV_PCRTC_CONFIG 0x00000804
#define NV_PVIDEO_DEBUG_2 0x00000088
#define NV_PVIDEO_DEBUG_3 0x0000008C
#define NV_PVIDEO_INTR 0x00000100
# define NV_PVIDEO_INTR_BUFFER_0 (1 << 0)
# define NV_PVIDEO_INTR_BUFFER_1 (1 << 4)
@ -554,26 +656,26 @@
# define NV_PVIDEO_BUFFER_0_USE (1 << 0)
# define NV_PVIDEO_BUFFER_1_USE (1 << 4)
#define NV_PVIDEO_STOP 0x00000704
#define NV_PVIDEO_BASE 0x00000900
#define NV_PVIDEO_LIMIT 0x00000908
#define NV_PVIDEO_LUMINANCE 0x00000910
#define NV_PVIDEO_CHROMINANCE 0x00000918
#define NV_PVIDEO_OFFSET 0x00000920
#define NV_PVIDEO_SIZE_IN 0x00000928
#define NV_PVIDEO_BASE(i) 0x00000900 + (i * 4)
#define NV_PVIDEO_LIMIT(i) 0x00000908 + (i * 4)
#define NV_PVIDEO_LUMINANCE(i) 0x00000910 + (i * 4)
#define NV_PVIDEO_CHROMINANCE(i) 0x00000918 + (i * 4)
#define NV_PVIDEO_OFFSET(i) 0x00000920 + (i * 4)
#define NV_PVIDEO_SIZE_IN(i) 0x00000928 + (i * 4)
# define NV_PVIDEO_SIZE_IN_WIDTH 0x000007FF
# define NV_PVIDEO_SIZE_IN_HEIGHT 0x07FF0000
#define NV_PVIDEO_POINT_IN 0x00000930
#define NV_PVIDEO_POINT_IN(i) 0x00000930 + (i * 4)
# define NV_PVIDEO_POINT_IN_S 0x00007FFF
# define NV_PVIDEO_POINT_IN_T 0xFFFE0000
#define NV_PVIDEO_DS_DX 0x00000938
#define NV_PVIDEO_DT_DY 0x00000940
#define NV_PVIDEO_POINT_OUT 0x00000948
#define NV_PVIDEO_DS_DX(i) 0x00000938 + (i * 4)
#define NV_PVIDEO_DT_DY(i) 0x00000940 + (i * 4)
#define NV_PVIDEO_POINT_OUT(i) 0x00000948 + (i * 4)
# define NV_PVIDEO_POINT_OUT_X 0x00000FFF
# define NV_PVIDEO_POINT_OUT_Y 0x0FFF0000
#define NV_PVIDEO_SIZE_OUT 0x00000950
#define NV_PVIDEO_SIZE_OUT(i) 0x00000950 + (i * 4)
# define NV_PVIDEO_SIZE_OUT_WIDTH 0x00000FFF
# define NV_PVIDEO_SIZE_OUT_HEIGHT 0x0FFF0000
#define NV_PVIDEO_FORMAT 0x00000958
#define NV_PVIDEO_FORMAT(i) 0x00000958 + (i * 4)
# define NV_PVIDEO_FORMAT_PITCH 0x00001FFF
# define NV_PVIDEO_FORMAT_COLOR 0x00030000
# define NV_PVIDEO_FORMAT_COLOR_LE_CR8YB8CB8YA8 1
@ -594,6 +696,7 @@
#define NV_PFB_DEBUG_0 0x00000080
#define NV_PFB_CFG0 0x00000200
# define NV_PFB_CFG0_PART 0x00000003
#define NV_PFB_CFG1 0x00000204
#define NV_PFB_CSTATUS 0x0000020C
#define NV_PFB_REFCTRL 0x00000210
#define NV_PFB_NVM 0x00000214 // NV_PFB_NVM_MODE_DISABLE
@ -602,17 +705,18 @@
#define NV_PFB_TIMING0 0x00000220
#define NV_PFB_TIMING1 0x00000224
#define NV_PFB_TIMING2 0x00000228
#define NV_PFB_TILE 0x00000240
#define NV_PFB_TLIMIT 0x00000244
#define NV_PFB_TSIZE 0x00000248
#define NV_PFB_TSTATUS 0x0000024C
#define NV_PFB_TILE(i) 0x00000240 + (i * 0x10)
#define NV_PFB_TLIMIT(i) 0x00000244 + (i * 0x10)
#define NV_PFB_TSIZE(i) 0x00000248 + (i * 0x10)
#define NV_PFB_TSTATUS(i) 0x0000024C + (i * 0x10)
#define NV_PFB_MRS 0x000002C0
#define NV_PFB_EMRS 0x000002C4
#define NV_PFB_MRS_EXT 0x000002C8
#define NV_PFB_EMRS_EXT 0x000002CC
#define NV_PFB_REF 0x000002D0
#define NV_PFB_PRE 0x000002D4
#define NV_PFB_ZCOMP 0x00000300
#define NV_PFB_ZCOMP(i) 0x00000300 + (i * 4)
#define NV_PFB_ZCOMP_OFFSET 0x00000324
#define NV_PFB_ARB_PREDIVIDER 0x00000328
#define NV_PFB_ARB_TIMEOUT 0x0000032C
#define NV_PFB_ARB_XFER_REM 0x00000334
@ -632,6 +736,10 @@
#define NV_PFB_CPU_RRQ 0x00000420
#define NV_PFB_BYPASS 0x00000424
#define NV_PRAMIN_DMA_CLASS(i) 0x00000000 + (i * 0x10)
#define NV_PRAMIN_DMA_LIMIT(i) 0x00000004 + (i * 0x10)
#define NV_PRAMIN_DMA_START(i) 0x00000008 + (i * 0x10)
#define NV_PRAMIN_DMA_ADDRESS(i) 0x0000000C + (i * 0x10)
#define NV_PRAMDAC_NVPLL_COEFF 0x00000500
# define NV_PRAMDAC_NVPLL_COEFF_MDIV 0x000000FF
@ -704,7 +812,7 @@
# define NV062_SET_CONTEXT_DMA_IMAGE_DESTIN 0x00000188
# define NV062_SET_COLOR_FORMAT 0x00000300
# define NV062_SET_COLOR_FORMAT_LE_Y8 0x01
# define NV062_SET_COLOR_FORMAT_LE_R5G6B5 0x04
# define NV062_SET_COLOR_FORMAT_LE_R5G6B5 0x04
# define NV062_SET_COLOR_FORMAT_LE_A8R8G8B8 0x0A
# define NV062_SET_PITCH 0x00000304
# define NV062_SET_OFFSET_SOURCE 0x00000308
@ -773,8 +881,84 @@
# define NV097_SET_SURFACE_COLOR_OFFSET 0x00000210
# define NV097_SET_SURFACE_ZETA_OFFSET 0x00000214
# define NV097_SET_COMBINER_ALPHA_ICW 0x00000260
# define NV097_SET_COMBINER_ALPHA_ICW_A_MAP 0xE0000000
# define NV097_SET_COMBINER_ALPHA_ICW_A_MAP_UNSIGNED_IDENTITY 0
# define NV097_SET_COMBINER_ALPHA_ICW_A_MAP_UNSIGNED_INVERT 1
# define NV097_SET_COMBINER_ALPHA_ICW_A_MAP_EXPAND_NORMAL 2
# define NV097_SET_COMBINER_ALPHA_ICW_A_MAP_EXPAND_NEGATE 3
# define NV097_SET_COMBINER_ALPHA_ICW_A_MAP_HALFBIAS_NORMAL 4
# define NV097_SET_COMBINER_ALPHA_ICW_A_MAP_HALFBIAS_NEGATE 5
# define NV097_SET_COMBINER_ALPHA_ICW_A_MAP_SIGNED_IDENTITY 6
# define NV097_SET_COMBINER_ALPHA_ICW_A_MAP_SIGNED_NEGATE 7
# define NV097_SET_COMBINER_ALPHA_ICW_A_ALPHA (1<<28)
# define NV097_SET_COMBINER_ALPHA_ICW_A_SOURCE 0x0F000000
# define NV097_SET_COMBINER_ALPHA_ICW_B_MAP 0x00E00000
# define NV097_SET_COMBINER_ALPHA_ICW_B_MAP_UNSIGNED_IDENTITY 0
# define NV097_SET_COMBINER_ALPHA_ICW_B_MAP_UNSIGNED_INVERT 1
# define NV097_SET_COMBINER_ALPHA_ICW_B_MAP_EXPAND_NORMAL 2
# define NV097_SET_COMBINER_ALPHA_ICW_B_MAP_EXPAND_NEGATE 3
# define NV097_SET_COMBINER_ALPHA_ICW_B_MAP_HALFBIAS_NORMAL 4
# define NV097_SET_COMBINER_ALPHA_ICW_B_MAP_HALFBIAS_NEGATE 5
# define NV097_SET_COMBINER_ALPHA_ICW_B_MAP_SIGNED_IDENTITY 6
# define NV097_SET_COMBINER_ALPHA_ICW_B_MAP_SIGNED_NEGATE 7
# define NV097_SET_COMBINER_ALPHA_ICW_B_ALPHA (1<<20)
# define NV097_SET_COMBINER_ALPHA_ICW_B_SOURCE 0x000F0000
# define NV097_SET_COMBINER_ALPHA_ICW_C_MAP 0x0000E000
# define NV097_SET_COMBINER_ALPHA_ICW_C_MAP_UNSIGNED_IDENTITY 0
# define NV097_SET_COMBINER_ALPHA_ICW_C_MAP_UNSIGNED_INVERT 1
# define NV097_SET_COMBINER_ALPHA_ICW_C_MAP_EXPAND_NORMAL 2
# define NV097_SET_COMBINER_ALPHA_ICW_C_MAP_EXPAND_NEGATE 3
# define NV097_SET_COMBINER_ALPHA_ICW_C_MAP_HALFBIAS_NORMAL 4
# define NV097_SET_COMBINER_ALPHA_ICW_C_MAP_HALFBIAS_NEGATE 5
# define NV097_SET_COMBINER_ALPHA_ICW_C_MAP_SIGNED_IDENTITY 6
# define NV097_SET_COMBINER_ALPHA_ICW_C_MAP_SIGNED_NEGATE 7
# define NV097_SET_COMBINER_ALPHA_ICW_C_ALPHA (1<<12)
# define NV097_SET_COMBINER_ALPHA_ICW_C_SOURCE 0x00000F00
# define NV097_SET_COMBINER_ALPHA_ICW_D_MAP 0x000000E0
# define NV097_SET_COMBINER_ALPHA_ICW_D_MAP_UNSIGNED_IDENTITY 0
# define NV097_SET_COMBINER_ALPHA_ICW_D_MAP_UNSIGNED_INVERT 1
# define NV097_SET_COMBINER_ALPHA_ICW_D_MAP_EXPAND_NORMAL 2
# define NV097_SET_COMBINER_ALPHA_ICW_D_MAP_EXPAND_NEGATE 3
# define NV097_SET_COMBINER_ALPHA_ICW_D_MAP_HALFBIAS_NORMAL 4
# define NV097_SET_COMBINER_ALPHA_ICW_D_MAP_HALFBIAS_NEGATE 5
# define NV097_SET_COMBINER_ALPHA_ICW_D_MAP_SIGNED_IDENTITY 6
# define NV097_SET_COMBINER_ALPHA_ICW_D_MAP_SIGNED_NEGATE 7
# define NV097_SET_COMBINER_ALPHA_ICW_D_ALPHA (1<<4)
# define NV097_SET_COMBINER_ALPHA_ICW_D_SOURCE 0x0000000F
# define NV097_SET_COMBINER_SPECULAR_FOG_CW0 0x00000288
# define NV097_SET_COMBINER_SPECULAR_FOG_CW0_A_INVERSE 0xE0000000
# define NV097_SET_COMBINER_SPECULAR_FOG_CW0_A_ALPHA (1<<28)
# define NV097_SET_COMBINER_SPECULAR_FOG_CW0_A_SOURCE 0x0F000000
# define NV097_SET_COMBINER_SPECULAR_FOG_CW0_A_SOURCE_REG_SPECLIT 0xE
# define NV097_SET_COMBINER_SPECULAR_FOG_CW0_A_SOURCE_REG_EF_PROD 0xF
# define NV097_SET_COMBINER_SPECULAR_FOG_CW0_B_INVERSE 0x00E00000
# define NV097_SET_COMBINER_SPECULAR_FOG_CW0_B_ALPHA (1<<20)
# define NV097_SET_COMBINER_SPECULAR_FOG_CW0_B_SOURCE 0x000F0000
# define NV097_SET_COMBINER_SPECULAR_FOG_CW0_B_SOURCE_REG_SPECLIT 0xE
# define NV097_SET_COMBINER_SPECULAR_FOG_CW0_B_SOURCE_REG_EF_PROD 0xF
# define NV097_SET_COMBINER_SPECULAR_FOG_CW0_C_INVERSE 0x0000E000
# define NV097_SET_COMBINER_SPECULAR_FOG_CW0_C_ALPHA (1<<12)
# define NV097_SET_COMBINER_SPECULAR_FOG_CW0_C_SOURCE 0x00000F00
# define NV097_SET_COMBINER_SPECULAR_FOG_CW0_C_SOURCE_REG_SPECLIT 0xE
# define NV097_SET_COMBINER_SPECULAR_FOG_CW0_C_SOURCE_REG_EF_PROD 0xF
# define NV097_SET_COMBINER_SPECULAR_FOG_CW0_D_INVERSE 0x000000E0
# define NV097_SET_COMBINER_SPECULAR_FOG_CW0_D_ALPHA (1<<4)
# define NV097_SET_COMBINER_SPECULAR_FOG_CW0_D_SOURCE 0x0000000F
# define NV097_SET_COMBINER_SPECULAR_FOG_CW0_D_SOURCE_REG_SPECLIT 0xE
# define NV097_SET_COMBINER_SPECULAR_FOG_CW0_D_SOURCE_REG_EF_PROD 0xF
# define NV097_SET_COMBINER_SPECULAR_FOG_CW1 0x0000028C
# define NV097_SET_COMBINER_SPECULAR_FOG_CW1_E_INVERSE 0xE0000000
# define NV097_SET_COMBINER_SPECULAR_FOG_CW1_E_ALPHA (1<<28)
# define NV097_SET_COMBINER_SPECULAR_FOG_CW1_E_SOURCE 0x0F000000
# define NV097_SET_COMBINER_SPECULAR_FOG_CW1_F_INVERSE 0x00E00000
# define NV097_SET_COMBINER_SPECULAR_FOG_CW1_F_ALPHA (1<<20)
# define NV097_SET_COMBINER_SPECULAR_FOG_CW1_F_SOURCE 0x000F0000
# define NV097_SET_COMBINER_SPECULAR_FOG_CW1_G_INVERSE 0x0000E000
# define NV097_SET_COMBINER_SPECULAR_FOG_CW1_G_ALPHA (1<<12)
# define NV097_SET_COMBINER_SPECULAR_FOG_CW1_G_SOURCE 0x00000F00
# define NV097_SET_COMBINER_SPECULAR_FOG_CW1_SPECULAR_CLAMP (1<<7)
# define NV097_SET_COMBINER_SPECULAR_FOG_CW1_SPECULAR_ADD_INVERT_R5 (1<<6)
# define NV097_SET_COMBINER_SPECULAR_FOG_CW1_SPECULAR_ADD_INVERT_R12 0x0000003F
# define NV097_SET_CONTROL0 0x00000290
# define NV097_SET_CONTROL0_STENCIL_WRITE_ENABLE (1 << 0)
# define NV097_SET_CONTROL0_Z_FORMAT (1 << 12)
@ -928,13 +1112,37 @@
# define NV097_SET_TEXGEN_VIEW_MODEL_LOCAL_VIEWER 0
# define NV097_SET_TEXGEN_VIEW_MODEL_INFINITE_VIEWER 1
# define NV097_SET_FOG_PLANE 0x000009D0
# define NV097_SET_FLAT_SHADE_OP 0x000009FC
# define NV097_SET_SCENE_AMBIENT_COLOR 0x00000A10
# define NV097_SET_VIEWPORT_OFFSET 0x00000A20
# define NV097_SET_EYE_POSITION 0x00000A50
# define NV097_SET_COMBINER_FACTOR0 0x00000A60
# define NV097_SET_COMBINER_FACTOR1 0x00000A80
# define NV097_SET_COMBINER_ALPHA_OCW 0x00000AA0
# define NV097_SET_COMBINER_ALPHA_OCW_OP 0xFFFF8000
# define NV097_SET_COMBINER_ALPHA_OCW_OP_NOSHIFT 0
# define NV097_SET_COMBINER_ALPHA_OCW_OP_NOSHIFT_BIAS 1
# define NV097_SET_COMBINER_ALPHA_OCW_OP_SHIFTLEFTBY1 2
# define NV097_SET_COMBINER_ALPHA_OCW_OP_SHIFTLEFTBY1_BIAS 3
# define NV097_SET_COMBINER_ALPHA_OCW_OP_SHIFTLEFTBY2 4
# define NV097_SET_COMBINER_ALPHA_OCW_OP_SHIFTRIGHTBY1 6
# define NV097_SET_COMBINER_ALPHA_OCW_MUX_ENABLE (1<<14)
# define NV097_SET_COMBINER_ALPHA_OCW_SUM_DST 0x00000F00
# define NV097_SET_COMBINER_ALPHA_OCW_AB_DST 0x000000F0
# define NV097_SET_COMBINER_ALPHA_OCW_CD_DST 0x0000000F
# define NV097_SET_COMBINER_COLOR_ICW 0x00000AC0
# define NV097_SET_COMBINER_COLOR_ICW_A_MAP 0xE0000000
# define NV097_SET_COMBINER_COLOR_ICW_A_ALPHA (1<<28)
# define NV097_SET_COMBINER_COLOR_ICW_A_SOURCE 0x0F000000
# define NV097_SET_COMBINER_COLOR_ICW_B_MAP 0x00E00000
# define NV097_SET_COMBINER_COLOR_ICW_B_ALPHA (1<<20)
# define NV097_SET_COMBINER_COLOR_ICW_B_SOURCE 0x000F0000
# define NV097_SET_COMBINER_COLOR_ICW_C_MAP 0x0000E000
# define NV097_SET_COMBINER_COLOR_ICW_C_ALPHA (1<<12)
# define NV097_SET_COMBINER_COLOR_ICW_C_SOURCE 0x00000F00
# define NV097_SET_COMBINER_COLOR_ICW_D_MAP 0x000000E0
# define NV097_SET_COMBINER_COLOR_ICW_D_ALPHA (1<<4)
# define NV097_SET_COMBINER_COLOR_ICW_D_SOURCE 0x0000000F
# define NV097_SET_VIEWPORT_SCALE 0x00000AF0
# define NV097_SET_TRANSFORM_PROGRAM 0x00000B00
# define NV097_SET_TRANSFORM_CONSTANT 0x00000B80
@ -1081,6 +1289,8 @@
# define NV097_SET_TEXTURE_SET_BUMP_ENV_OFFSET 0x00001B3C
# define NV097_SET_SEMAPHORE_OFFSET 0x00001D6C
# define NV097_BACK_END_WRITE_SEMAPHORE_RELEASE 0x00001D70
# define NV097_SET_ZMIN_MAX_CONTROL 0x00001D78
# define NV097_SET_COMPRESS_ZBUFFER_EN 0x00001D80
# define NV097_SET_ZSTENCIL_CLEAR_VALUE 0x00001D8C
# define NV097_SET_COLOR_CLEAR_VALUE 0x00001D90
# define NV097_CLEAR_SURFACE 0x00001D94
@ -1095,13 +1305,118 @@
# define NV097_SET_CLEAR_RECT_VERTICAL 0x00001D9C
# define NV097_SET_SPECULAR_FOG_FACTOR 0x00001E20
# define NV097_SET_COMBINER_COLOR_OCW 0x00001E40
# define NV097_SET_COMBINER_COLOR_OCW_BLUETOALPHA_AB 0xFFF80000
# define NV097_SET_COMBINER_COLOR_OCW_BLUETOALPHA_AB_DISABLE 0
# define NV097_SET_COMBINER_COLOR_OCW_BLUETOALPHA_AB_AB_DST_ENABLE 1
# define NV097_SET_COMBINER_COLOR_OCW_BLUETOALPHA_CD (1<<18)
# define NV097_SET_COMBINER_COLOR_OCW_BLUETOALPHA_CD_DISABLE 0
# define NV097_SET_COMBINER_COLOR_OCW_BLUETOALPHA_CD_CD_DST_ENABLE 1
# define NV097_SET_COMBINER_COLOR_OCW_OP 0x00038000
# define NV097_SET_COMBINER_COLOR_OCW_OP_NOSHIFT 0
# define NV097_SET_COMBINER_COLOR_OCW_OP_NOSHIFT_BIAS 1
# define NV097_SET_COMBINER_COLOR_OCW_OP_SHIFTLEFTBY1 2
# define NV097_SET_COMBINER_COLOR_OCW_OP_SHIFTLEFTBY1_BIAS 3
# define NV097_SET_COMBINER_COLOR_OCW_OP_SHIFTLEFTBY2 4
# define NV097_SET_COMBINER_COLOR_OCW_OP_SHIFTRIGHTBY1 6
# define NV097_SET_COMBINER_COLOR_OCW_MUX_ENABLE (1 << 14)
# define NV097_SET_COMBINER_COLOR_OCW_AB_DOT_ENABLE (1 << 13)
# define NV097_SET_COMBINER_COLOR_OCW_CD_DOT_ENABLE (1<<12)
# define NV097_SET_COMBINER_COLOR_OCW_SUM_DST 0x00000F00
# define NV097_SET_COMBINER_COLOR_OCW_AB_DST 0x000000F0
# define NV097_SET_COMBINER_COLOR_OCW_CD_DST 0x0000000F
# define NV097_SET_COMBINER_CONTROL 0x00001E60
# define NV097_SET_COMBINER_CONTROL_ITERATION_COUNT 0x000000FF
# define NV097_SET_COMBINER_CONTROL_ITERATION_COUNT_ONE 1
# define NV097_SET_COMBINER_CONTROL_ITERATION_COUNT_TWO 2
# define NV097_SET_COMBINER_CONTROL_ITERATION_COUNT_THREE 3
# define NV097_SET_COMBINER_CONTROL_ITERATION_COUNT_FOUR 4
# define NV097_SET_COMBINER_CONTROL_ITERATION_COUNT_FIVE 5
# define NV097_SET_COMBINER_CONTROL_ITERATION_COUNT_SIX 6
# define NV097_SET_COMBINER_CONTROL_ITERATION_COUNT_SEVEN 7
# define NV097_SET_COMBINER_CONTROL_ITERATION_COUNT_EIGHT 8
# define NV097_SET_COMBINER_CONTROL_MUX_SELECT 0x00000F00
# define NV097_SET_COMBINER_CONTROL_MUX_SELECT_LSB 0
# define NV097_SET_COMBINER_CONTROL_MUX_SELECT_MSB 1
# define NV097_SET_COMBINER_CONTROL_FACTOR0 0x0000F000
# define NV097_SET_COMBINER_CONTROL_FACTOR0_SAME_FACTOR_ALL 0
# define NV097_SET_COMBINER_CONTROL_FACTOR0_EACH_STAGE 1
# define NV097_SET_COMBINER_CONTROL_FACTOR1 0xFFFF0000
# define NV097_SET_COMBINER_CONTROL_FACTOR1_SAME_FACTOR_ALL 0
# define NV097_SET_COMBINER_CONTROL_FACTOR1_EACH_STAGE 1
# define NV097_SET_SHADOW_ZSLOPE_THRESHOLD 0x00001E68
# define NV097_SET_SHADER_STAGE_PROGRAM 0x00001E70
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE0 0x0000001F
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE0_PROGRAM_NONE 0
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE0_2D_PROJECTIVE 1
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE0_3D_PROJECTIVE 2
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE0_CUBE_MAP 3
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE0_PASS_THROUGH 4
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE0_CLIP_PLANE 5
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE1 0x000003E0
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE1_PROGRAM_NONE 0x00
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE1_2D_PROJECTIVE 0x01
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE1_3D_PROJECTIVE 0x02
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE1_CUBE_MAP 0x03
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE1_PASS_THROUGH 0x04
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE1_CLIP_PLANE 0x05
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE1_BUMPENVMAP 0x06
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE1_BUMPENVMAP_LUMINANCE 0x07
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE1_DEPENDENT_AR 0x0F
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE1_DEPENDENT_GB 0x10
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE1_DOT_PRODUCT 0x11
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE2 0x00007C00
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE2_PROGRAM_NONE 0x00
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE2_2D_PROJECTIVE 0x01
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE2_3D_PROJECTIVE 0x02
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE2_CUBE_MAP 0x03
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE2_PASS_THROUGH 0x04
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE2_CLIP_PLANE 0x05
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE2_BUMPENVMAP 0x06
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE2_BUMPENVMAP_LUMINANCE 0x07
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE2_BRDF 0x08
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE2_DOT_ST 0x09
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE2_DOT_ZW 0x0A
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE2_DOT_REFLECT_DIFFUSE 0x0B
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE2_DEPENDENT_AR 0x0F
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE2_DEPENDENT_GB 0x10
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE2_DOT_PRODUCT 0x11
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE3 0x000F8000
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE3_PROGRAM_NONE 0x00
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE3_2D_PROJECTIVE 0x01
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE3_3D_PROJECTIVE 0x02
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE3_CUBE_MAP 0x03
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE3_PASS_THROUGH 0x04
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE3_CLIP_PLANE 0x05
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE3_BUMPENVMAP 0x06
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE3_BUMPENVMAP_LUMINANCE 0x07
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE3_BRDF 0x08
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE3_DOT_ST 0x09
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE3_DOT_ZW 0x0A
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE3_DOT_REFLECT_SPECULAR 0x0C
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE3_DOT_STR_3D 0x0D
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE3_DOT_STR_CUBE 0x0E
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE3_DEPENDENT_AR 0x0F
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE3_DEPENDENT_GB 0x10
# define NV097_SET_SHADER_STAGE_PROGRAM_STAGE3_DOT_REFLECT_SPECULAR_CONST 0x12
# define NV097_SET_SHADER_OTHER_STAGE_INPUT 0x00001E78
# define NV097_SET_SHADER_OTHER_STAGE_INPUT_STAGE1 0x0000FFFF
# define NV097_SET_SHADER_OTHER_STAGE_INPUT_STAGE1_INSTAGE_0 0
# define NV097_SET_SHADER_OTHER_STAGE_INPUT_STAGE2 0x000F0000
# define NV097_SET_SHADER_OTHER_STAGE_INPUT_STAGE2_INSTAGE_0 0
# define NV097_SET_SHADER_OTHER_STAGE_INPUT_STAGE2_INSTAGE_1 1
# define NV097_SET_SHADER_OTHER_STAGE_INPUT_STAGE3 0x00F00000
# define NV097_SET_SHADER_OTHER_STAGE_INPUT_STAGE3_INSTAGE_0 0
# define NV097_SET_SHADER_OTHER_STAGE_INPUT_STAGE3_INSTAGE_1 1
# define NV097_SET_SHADER_OTHER_STAGE_INPUT_STAGE3_INSTAGE_2 2
# define NV097_SET_TRANSFORM_DATA 0x00001E80
# define NV097_LAUNCH_TRANSFORM_PROGRAM 0x00001E90
# define NV097_SET_TRANSFORM_EXECUTION_MODE 0x00001E94
# define NV097_SET_TRANSFORM_EXECUTION_MODE_MODE 0x00000003
# define NV097_SET_TRANSFORM_EXECUTION_MODE_MODE_FIXED 0
# define NV097_SET_TRANSFORM_EXECUTION_MODE_MODE_PROGRAM 2
# define NV097_SET_TRANSFORM_EXECUTION_MODE_RANGE_MODE 0xFFFFFFFC
# define NV097_SET_TRANSFORM_EXECUTION_MODE_RANGE_MODE_USER 0
# define NV097_SET_TRANSFORM_EXECUTION_MODE_RANGE_MODE_PRIV 1
# define NV097_SET_TRANSFORM_PROGRAM_CXT_WRITE_EN 0x00001E98
# define NV097_SET_TRANSFORM_PROGRAM_LOAD 0x00001E9C
# define NV097_SET_TRANSFORM_PROGRAM_START 0x00001EA0